惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
J
Java Code Geeks
雷峰网
雷峰网
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
V
Vulnerabilities – Threatpost
S
Securelist
The Hacker News
The Hacker News
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
G
Google Developers Blog
Hugging Face - Blog
Hugging Face - Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
AI
AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Schneier on Security
Schneier on Security
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
博客园 - 司徒正美
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
U
Unit 42
V
V2EX
V2EX - 技术
V2EX - 技术
L
LINUX DO - 最新话题
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
P
Privacy & Cybersecurity Law Blog
美团技术团队
小众软件
小众软件
F
Fortinet All Blogs

博客园 - 所言非虚

未来谁才是移动互联网的入口? [Oracle]Sqlplus连接成功,但pl/sql连接不成功,提示“ora-12145:无法解析指定的连接标识符” Windows待机、休眠、睡眠的区别以及程序运行策略 [Worldwind]worldwind源码编译 windows server 2008 x64下oracle 10gR2的安装方法 [长期]常见问题收集 最佳编程字体推荐 GDAL问题收集 向量点积与叉积的定义及应用 空间平面法向量求法 【解决】加载图片"内存不足"问题 【原创】随鼠标移动显示地图经纬度 - 所言非虚 - 博客园 【原创】利用ESRI自带的符号库进行符号化 FireFox与IE的兼容 【转】兼容IE和FireFox的鼠标滚轮事件 DIV的精确定位 - 所言非虚 - 博客园 ArcGIS Server开发的一些小经验 ArcSDE C API在.NET中的调用 - 所言非虚 [译]ArcGIS Server Map Service Cache的组织结构
【原创】客户端添加兴趣点,并随地图变化而变化 - 所言非虚 - 博客园
所言非虚 · 2008-05-10 · via 博客园 - 所言非虚

很多时候我们需要在某些图层的点添加一些热点,以供在客户端点击之后显示一些信息或者弹出像Google那样的气泡。
这个热点(兴趣点)在客户端可以用div或者img表示,而且还可以解决在Map控件上显示gif和flash动画的问题。

1 首先在客户端定义好一个div,并将其设置为不可见,位置类型设为绝对。

<div id="Typhoon_GIF" style="position:absolute; visibility:hidden;">
        
<img src="images/taif.gif" />
</div>

2.取得图层中的点的位置,并将其转换为屏幕位置

//取得ArcGIS Server ArcObjects 点
public ESRI.ArcGIS.Geometry.IPoint GetTyphoonPoint(ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceManager MapResourceManager1)
        
{

            ESRI.ArcGIS.Server.IServerContext mapContext 
= GetServerContext(MapResourceManager1);  //取得ServerContext

            ESRI.ArcGIS.Geodatabase.IWorkspaceFactory wsf 
= mapContext.CreateObject("esriDataSourcesFile.ShapefileWorkspaceFactory"as ESRI.ArcGIS.Geodatabase.IWorkspaceFactory;

            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace fws 
= wsf.OpenFromFile("C:\\xiamen\\Typhoon"0as ESRI.ArcGIS.Geodatabase.IFeatureWorkspace ;  //TryCast是不引发异常的类型转换操作
            ESRI.ArcGIS.Geodatabase.IFeatureClass pFC  = fws.OpenFeatureClass("Typhoon");

            ESRI.ArcGIS.Geometry.IPolyline line 
= pFC.GetFeature(0).Shape as ESRI.ArcGIS.Geometry.IPolyline ;

            ESRI.ArcGIS.Geometry.IPoint point 
= line.ToPoint;
            
//mapContext.ReleaseContext()

            
return point;
        }

//将AO点转换为Screen点,Screen点的坐标值是以Map控件的左上角为坐标原点计算的。
public System.Double[] GetTyphoonScreenPoint(ESRI.ArcGIS.ADF.Web.Geometry.Envelope env, ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceManager MapResourceManager1,ESRI.ArcGIS.ADF.Web.UI.WebControls.Map Map1)
        
{
            
//获取图层中的点
            ESRI.ArcGIS.Geometry.IPoint point = GetTyphoonPoint(MapResourceManager1);
            
//转换为ADF的点
            ESRI.ArcGIS.ADF.Web.Geometry.Point  adf_point = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromIPoint(point);

            
            
//转换为屏幕坐标,它是相对与Map的左上角的坐标值
            System.Drawing.Point screen_point = adf_point.ToScreenPoint(env, System.Convert.ToInt32(Map1.Width.Value), System.Convert.ToInt32(Map1.Height.Value));
            Double[] rate 
= { screen_point.X, screen_point.Y };
            
return rate;
        }

3.添加Map控件的ExtentChanged事件代码

//-------------------------------------------------------
    protected void Map1_ExtentChanged(object sender, ESRI.ArcGIS.ADF.Web.UI.WebControls.ExtentEventArgs args)
    
{
        String script;

        Double[] rate 
= util.GetTyphoonScreenPoint(args.NewExtent, MapResourceManager1, Map1);
        
if (rate[0<= 0 || rate[1<= 0)
        
{
            script 
+= "document.getElementById('Typhoon_GIF').style.visibility='hidden';";
        }

        
else 
        
{
            script 
+= "document.getElementById('Typhoon_GIF').style.visibility='visible';showTyphoon(" + rate[0].ToString() + "," + rate[1].ToString() + ");";
        }

        
        ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult s 
= new ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult(nullnull"javascript", script);
        Map1.CallbackResults.Add(s);
    }

4.添加客户端处理代码

function showTyphoon(x,y)
        
{
            
//将坐标值转化为数值型
            var ratex=parseFloat(x);
            var ratey
=parseFloat(y);
            
            var map
=document.getElementById("Map1");
            
            
//Map的位置
            var mapx=getLeft(map);
            var mapy
=getTop(map);
            
            var img
=document.getElementById("Typhoon_GIF");
            
            imgw
=img.clientWidth;
            imgh
=img.clientHeight;
            
            img.style.top
=ratey+mapy-Math.round(imgh/2)+"px";
            img.style.left
=ratex+mapx-Math.round(imgw/2)+"px";
        }

//获取元素的纵坐标
        function getTop(e)
        
{
            var offset
=e.offsetTop;
            
if(e.offsetParent!=null) offset+=getTop(e.offsetParent);
            
return offset;
        }

        
//-----------------------------
        
//获取元素的横坐标
        function getLeft(e)
        
{
            var offset
=e.offsetLeft;
            
if(e.offsetParent!=null) offset+=getLeft(e.offsetParent);
            
return offset;
        }