鹰眼实现 各位大虾: 怎样才能实现一幅图形的漫游功能(鹰眼),用c#实现!感激! 备注:不用AE 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我书上正好有4.12 实例14:鹰眼图的实现鹰眼图的实现能使电子地图在功能及界面上锦上添花,各种媒体上都有一些介绍,下面介绍用C#实现的鹰眼图功能。4.12.1 程序实现//初始时,产生鹰眼图矩形框绘画层private void mapsmall(){if (!File.Exists(@appDirectory+"\\mapSmall.tab")) m_Layer=mapSmall.Layers.CreateLayer("RectLayer",@appDirectory+"\\mapSmall.tab",1,32,mapSmall.NumericCoordSys);else m_Layer = mapSmall.Layers.Add(@appDirectory+"\\mapSmall.tab",1); m_Layer.Editable=true; mapSmall.Layers.InsertionLayer=m_Layer;}private void axMap1_MapViewChanged(object sender, System.EventArgs e){ if(mapSmall==null) return; MapXLib.Feature tempFea; MapXLib.Feature m_Fea; MapXLib.FeatureFactory feaFact; feaFact=mapSmall.FeatureFactory; MapXLib.Points tempPnts=new MapXLib.PointsClass(); MapXLib.Style tempStyle=new MapXLib.StyleClass(); MapXLib.Features ftrs; ftrs=m_Layer.AllFeatures; double MapX=0,mapY=0,mapWidth=0,mapHeight=0,MapX1=0,mapY1=0; float screenX,screenY,screenWidth,screenHeight,screenX1,screenY1; screenX=axMap2.Bounds.X; screenY=axMap2.Bounds.Y; screenWidth=axMap2.Bounds.Width; screenHeight=axMap2.Bounds.Height; screenX1=screenX+screenWidth; screenY1=screenY+screenHeight; axMap2.ConvertCoord(ref screenX,ref screenY,ref MapX,ref mapY,MapXLib.ConversionConstants.miScreenToMap); axMap2.ConvertCoord(ref screenX1,ref screenY1,ref MapX1,ref mapY1,MapXLib.ConversionConstants.miScreenToMap); mapWidth=MapX1-MapX; mapHeight=mapY1-mapY; if (ftrs.Count==0) { tempStyle.RegionPattern=MapXLib.FillPatternConstants.miPatternNoFill; tempStyle.RegionColor=(uint)MapXLib.ColorConstants.miColorRed; tempStyle.RegionBorderColor=255; MapXLib.Points pts=new MapXLib.PointsClass(); pts.AddXY(MapX,mapY,1); pts.AddXY(MapX+mapWidth,mapY,2); pts.AddXY(MapX+mapWidth,mapY+mapHeight,3); pts.AddXY(MapX,mapY+mapHeight,4); tempFea = feaFact.CreateRegion(pts,tempStyle); m_Fea = m_Layer.AddFeature(tempFea,new MapXLib.RowValuesClass()); m_Layer.Refresh(); mapSmall.AutoRedraw = true; } else { m_Fea=ftrs._Item(1); m_Fea.Parts._Item(1).RemoveAll(); m_Fea.Parts._Item(1).AddXY(MapX,mapY,1); m_Fea.Parts._Item(1).AddXY(MapX+mapWidth,mapY,2); m_Fea.Parts._Item(1).AddXY(MapX+mapWidth,mapY+mapHeight,3); m_Fea.Parts._Item(1).AddXY(MapX,mapY+mapHeight,4); m_Fea.Update(true,new MapXLib.RowValuesClass()); m_Layer.Refresh(); mapSmall.AutoRedraw = true; }}void axMap2_MouseDownEvent(object sender,AxMapXLib.CMapXEvents_MouseDownEvent e){ if(mapLarge==null)return; double MapX=0; double MapY=0; axMap2.ConvertCoord(ref e.x,ref e.y,ref MapX,ref MapY,MapXLib.ConversionConstants.miScreenToMap); mapLarge.CenterX=MapX; mapLarge.CenterY=MapY;}4.12.3程序说明(1)由主图视图改变影响鹰眼图矩形框的重绘,代码实现在主图的viewchanged事件中。(2)在鹰眼图中单击鼠标,把单击处的位置点作为主图的中心点重绘主图。代码实现在鹰眼图的mousedownevent事件中。(3)M_layer为鹰眼图中绘制矩形框的图层。(4)mapSmall代表鹰眼图控件,mapLarge代表主图控件。(5)主图与鹰眼图同步的关键是主图的可视区域地理范围与鹰眼图的矩形框所包含的地理范围一样。 首先得到主图的Boundsr的各个顶点的屏幕坐标用函数axMap1.ConvertCoord()将bounds的各顶点屏幕坐标转化为地理坐标。最后在鹰眼图中根据主图中各顶点的地理坐标画出矩形区域。(6)注意convertCoord()函数的用法, 请参考相关资料,注意其中第五个参数的用法。请读者仔细领会其中的机理。本例子只给了视图范围同步问题,没有给出编辑同步问题,即在主图中增加一个图元,在鹰眼图中同步增加一个点。留给读者自己练习,相信一定不会难住聪明的读者。 2楼的是MapInfo的组件MapX,比之于ArcGIS之ArcEngine,是一样的。楼主可能要找不基于商业GIS组件的,那找找SharpMap之类的吧另外,楼主你要看的图,是什么格式,矢量数据总有个数据结构吧。(应该不是说栅格的)如果你要自定格式,要持久化,要检索,要渲染..... 关于flash,急!!!!! 网页执行BAT,无反应 搜索txt 文件中的文字(网址 等)有返回值 C#中使用Direct3D的Texture的问题,高手帮忙! vs2012运行windowsphone8时缺少heyper-v组件??急求 C#如何监测系统有无操作。 求大神,如何用C#随机建立数学表达式如:3+sinT+lnT+10,T为整形变量,并对其进行求值? 大家有没有下面的源码? 请问如何创建一个框架式的WEB窗体 (我没编写过论坛)找了很久都没看见有介绍用C#编写论坛的资料。 关于大量事件(event)的优化 ComBoBox问题
鹰眼图的实现能使电子地图在功能及界面上锦上添花,各种媒体上都有一些介绍,下面介绍用C#实现的鹰眼图功能。
4.12.1 程序实现
//初始时,产生鹰眼图矩形框绘画层
private void mapsmall()
{
if (!File.Exists(@appDirectory+"\\mapSmall.tab"))
m_Layer=mapSmall.Layers.CreateLayer("RectLayer",@appDirectory+
"\\mapSmall.tab",1,32,mapSmall.NumericCoordSys);
else
m_Layer = mapSmall.Layers.Add(@appDirectory+"\\mapSmall.tab",1);
m_Layer.Editable=true;
mapSmall.Layers.InsertionLayer=m_Layer;
}
private void axMap1_MapViewChanged(object sender, System.EventArgs e)
{
if(mapSmall==null) return;
MapXLib.Feature tempFea;
MapXLib.Feature m_Fea;
MapXLib.FeatureFactory feaFact;
feaFact=mapSmall.FeatureFactory;
MapXLib.Points tempPnts=new MapXLib.PointsClass();
MapXLib.Style tempStyle=new MapXLib.StyleClass();
MapXLib.Features ftrs;
ftrs=m_Layer.AllFeatures;
double MapX=0,mapY=0,mapWidth=0,mapHeight=0,MapX1=0,mapY1=0;
float screenX,screenY,screenWidth,screenHeight,screenX1,screenY1;
screenX=axMap2.Bounds.X;
screenY=axMap2.Bounds.Y;
screenWidth=axMap2.Bounds.Width;
screenHeight=axMap2.Bounds.Height;
screenX1=screenX+screenWidth;
screenY1=screenY+screenHeight;
axMap2.ConvertCoord(ref screenX,ref screenY,ref MapX,ref mapY,
MapXLib.ConversionConstants.miScreenToMap);
axMap2.ConvertCoord(ref screenX1,ref screenY1,ref MapX1,ref mapY1,
MapXLib.ConversionConstants.miScreenToMap);
mapWidth=MapX1-MapX;
mapHeight=mapY1-mapY;
if (ftrs.Count==0)
{ tempStyle.RegionPattern=MapXLib.FillPatternConstants.miPatternNoFill; tempStyle.RegionColor=(uint)MapXLib.ColorConstants.miColorRed;
tempStyle.RegionBorderColor=255;
MapXLib.Points pts=new MapXLib.PointsClass();
pts.AddXY(MapX,mapY,1);
pts.AddXY(MapX+mapWidth,mapY,2);
pts.AddXY(MapX+mapWidth,mapY+mapHeight,3);
pts.AddXY(MapX,mapY+mapHeight,4);
tempFea = feaFact.CreateRegion(pts,tempStyle);
m_Fea = m_Layer.AddFeature(tempFea,new MapXLib.RowValuesClass());
m_Layer.Refresh();
mapSmall.AutoRedraw = true;
}
else
{
m_Fea=ftrs._Item(1);
m_Fea.Parts._Item(1).RemoveAll();
m_Fea.Parts._Item(1).AddXY(MapX,mapY,1);
m_Fea.Parts._Item(1).AddXY(MapX+mapWidth,mapY,2);
m_Fea.Parts._Item(1).AddXY(MapX+mapWidth,mapY+mapHeight,3);
m_Fea.Parts._Item(1).AddXY(MapX,mapY+mapHeight,4);
m_Fea.Update(true,new MapXLib.RowValuesClass());
m_Layer.Refresh();
mapSmall.AutoRedraw = true;
}
}
void axMap2_MouseDownEvent(object sender,AxMapXLib.CMapXEvents_MouseDownEvent e)
{
if(mapLarge==null)return;
double MapX=0;
double MapY=0;
axMap2.ConvertCoord(ref e.x,ref e.y,ref MapX,ref MapY,
MapXLib.ConversionConstants.miScreenToMap);
mapLarge.CenterX=MapX;
mapLarge.CenterY=MapY;
}
4.12.3程序说明
(1)由主图视图改变影响鹰眼图矩形框的重绘,代码实现在主图的viewchanged事件中。
(2)在鹰眼图中单击鼠标,把单击处的位置点作为主图的中心点重绘主图。代码实现在鹰眼图的mousedownevent事件中。
(3)M_layer为鹰眼图中绘制矩形框的图层。
(4)mapSmall代表鹰眼图控件,mapLarge代表主图控件。
(5)主图与鹰眼图同步的关键是主图的可视区域地理范围与鹰眼图的矩形框所包含的地理范围一样。
首先得到主图的Boundsr的各个顶点的屏幕坐标用函数axMap1.ConvertCoord()将bounds的各顶点屏幕坐标转化为地理坐标。最后在鹰眼图中根据主图中各顶点的地理坐标画出矩形区域。
(6)注意convertCoord()函数的用法, 请参考相关资料,注意其中第五个参数的用法。
请读者仔细领会其中的机理。本例子只给了视图范围同步问题,没有给出编辑同步问题,即在主图中增加一个图元,在鹰眼图中同步增加一个点。留给读者自己练习,相信一定不会难住聪明的读者。
楼主可能要找不基于商业GIS组件的,那找找SharpMap之类的吧
另外,楼主你要看的图,是什么格式,矢量数据总有个数据结构吧。(应该不是说栅格的)
如果你要自定格式,要持久化,要检索,要渲染.....