//放大的代码:

   private void MapZoomIn(NameValueCollection queryString)
{
mapObj map = Session["MapServer_MAP"] as mapObj;
PointF pointFLeftBottom = new PointF(float.Parse(queryString["Left"]), float.Parse(queryString["Bottom"]));
PointF pointFRightTop = new PointF(float.Parse(queryString["Right"]), float.Parse(queryString["Top"]));
rectObj rect = map.extent;
rectObj rbox = new rectObj(pointFLeftBottom.X,pointFLeftBottom.Y,pointFRightTop.X,pointFRightTop.Y,);
map.zoomRectangle(rbox, map.width, map.height, rect, null);
Session.Remove("MapServer_MAP");
Session["MapServer_MAP"] = map; } //缩小的代码:
private void MapZoomOut(NameValueCollection queryString)
{
mapObj map = Session["MapServer_MAP"] as mapObj;
PointF pointFLeftBottom = new PointF(float.Parse(queryString["Left"]), float.Parse(queryString["Bottom"]));
PointF pointFRightTop = new PointF(float.Parse(queryString["Right"]), float.Parse(queryString["Top"]));
PointF pointFCenter = new PointF((pointFLeftBottom.X + pointFRightTop.X) / , (pointFLeftBottom.Y + pointFRightTop.Y) / );
double ratio = 0.0;
double ratioX = (pointFRightTop.X - pointFLeftBottom.X) * 1.0 / map.width;
double ratioY = (pointFLeftBottom.Y - pointFRightTop.Y) * 1.0 / map.height;
if (ratioX > ratioY)
{
ratio = ratioX;
}
else
{
ratio = ratioY;
}
map.zoomPoint(-((int)( / ratio)), new pointObj(pointFCenter.X, pointFCenter.Y, , ), map.width, map.height, map.extent, null);
rectObj rectExtent = map.extent;
double mapNewCenterX=(pointFCenter.X - 0.0) / map.width * (rectExtent.maxx - rectExtent.minx) + rectExtent.minx;
double mapNewCenterY=(pointFCenter.Y - 0.0) / map.height * (rectExtent.maxy - rectExtent.miny) + rectExtent.miny; double minx = mapNewCenterX - (rectExtent.maxx - rectExtent.minx) / ratio / ;
double maxx = mapNewCenterX + (rectExtent.maxx - rectExtent.minx) / ratio / ;
double miny = mapNewCenterY - (rectExtent.maxy - rectExtent.miny) / ratio / ;
double maxy = mapNewCenterY + (rectExtent.maxy - rectExtent.miny) / ratio / ;
rectObj rectNewExtent = new rectObj(minx, miny, maxx, maxy, );
Session.Remove("MapServer_MAP");
Session["MapServer_MAP"] = map;
} //平移的代码: private void MapPan(NameValueCollection queryString)
{
mapObj map = Session["MapServer_MAP"] as mapObj;
PointF pointFFirst = new PointF(float.Parse(queryString["FirstX"]), float.Parse(queryString["FirstY"]));
PointF pointFSecond = new PointF(float.Parse(queryString["SecondX"]), float.Parse(queryString["SecondY"]));
System.Drawing.PointF pointFCenter = new PointF(map.width / - (pointFSecond.X - pointFFirst.X), map.height / - (pointFSecond.Y - pointFFirst.Y));
map.zoomPoint(, new pointObj(pointFCenter.X, pointFCenter.Y, , ), map.width, map.height, map.extent, null);
Session.Remove("MapServer_MAP");
Session["MapServer_MAP"] = map;
} //全图显示的代码:
private void MapFullExtent(NameValueCollection queryString)
{
mapObj map = Session["MapServer_MAP"] as mapObj;
rectObj rectOriginalExtent = Session["MapServer_OriginalExtent"] as rectObj;
map.extent = rectOriginalExtent;
Session.Remove("MapServer_MAP");
Session["MapServer_MAP"] = map;
} //属性查询的代码:
private void MapAttributeQuery(NameValueCollection queryString, out string responseXML)
{
mapObj map = Session["MapServer_MAP"] as mapObj;
layerObj layer = null;
string layerName = queryString["LayerName"];
string value = queryString["Value"];
layer = map.getLayerByName(layerName);
String attributeQueryString = "((\"[NAME]\" == '" + value + "') AND (\"[SHAPE_Area]\" > " + "'10'" + "))";
Console.WriteLine("queryString="+queryString);
String path = Server.MapPath("");
Console.WriteLine("path: " + path);
layer.status = ;
layer.queryByAttributes(map, "NAME", attributeQueryString, );
layer.open();
resultCacheObj resultCache = layer.getResults();
int numresults=resultCache.numresults;
string imagePath = GenerateMap();
StringBuilder resultsXML = new StringBuilder("");
resultsXML.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
resultsXML.Append("<map>");
resultsXML.Append("<mapInfo>");
resultsXML.Append("<mapPath>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(imagePath);
resultsXML.Append("]]>");
resultsXML.Append("</mapPath>");
resultsXML.Append("</mapInfo>");
for(int j=; j<numresults; j++)
{
resultCacheMemberObj resultCacheMember=resultCache.getResult(j);
resultCacheMember = layer.getResult(j);
layer.open();
shapeObj shapeResult = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POLYGON);
layer.getShape(shapeResult, resultCacheMember.tileindex,resultCacheMember.shapeindex);
layer.open(); resultsXML.Append("<feature>");
resultsXML.Append("<objectID>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(shapeResult.getValue());
resultsXML.Append("]]>");
resultsXML.Append("</objectID>"); resultsXML.Append("<name>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(shapeResult.getValue());
resultsXML.Append("]]>");
resultsXML.Append("</name>"); resultsXML.Append("<area>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(shapeResult.getValue());
resultsXML.Append("]]>");
resultsXML.Append("</area>");
resultsXML.Append("</feature>");
}
layer.close();
resultsXML.Append("</map>");
Session.Remove("MapServer_MAP");
Session["MapServer_MAP"] = map;
responseXML = resultsXML.ToString();
} //空间查询的代码: private void MapSpatialQuery(NameValueCollection queryString, out string responseXML)
{
mapObj map = Session["MapServer_MAP"] as mapObj;
layerObj layer = null;
for (int i = ; i < map.numlayers; i++)
{
layer = map.getLayer(i);
layer.opacity = ;
System.Diagnostics.Debug.WriteLine("LayerName= " + layer.name + " FeatureCount= " + layer.maxfeatures);
layer.status = (int)mapscript.MS_ON; } string layerName = queryString["LayerName"];
string value = queryString["Value"];
layer = map.getLayerByName(layerName);
PointF pointFLeftBottom = new PointF(float.Parse(queryString["Left"]), float.Parse(queryString["Bottom"]));
PointF pointFRightTop = new PointF(float.Parse(queryString["Right"]), float.Parse(queryString["Top"]));
pointObj pointMapLeftBottom = Pixel2Point(map, pointFLeftBottom.X, pointFLeftBottom.Y);
pointObj pointMapRightTop = Pixel2Point(map, pointFRightTop.X, pointFRightTop.Y);
rectObj rectSpatialQuery = new rectObj(pointMapLeftBottom.x, pointMapLeftBottom.y, pointMapRightTop.x, pointMapRightTop.y, ); layer.status = (int)mapscript.MS_ON;
layer.queryByRect(map, rectSpatialQuery); layer.open();
resultCacheObj resultCache = layer.getResults();
int numresults = resultCache.numresults;
string imagePath = GenerateMap();
StringBuilder resultsXML = new StringBuilder("");
resultsXML.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
resultsXML.Append("<map>");
resultsXML.Append("<mapInfo>");
resultsXML.Append("<mapPath>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(imagePath);
resultsXML.Append("]]>");
resultsXML.Append("</mapPath>");
resultsXML.Append("</mapInfo>");
for (int j = ; j < numresults; j++)
{
resultCacheMemberObj resultCacheMember = resultCache.getResult(j);
resultCacheMember = layer.getResult(j);
layer.open();
shapeObj shapeResult = new shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_POLYGON);
layer.getShape(shapeResult, resultCacheMember.tileindex, resultCacheMember.shapeindex);
layer.open(); resultsXML.Append("<feature>");
resultsXML.Append("<objectID>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(shapeResult.getValue());
resultsXML.Append("]]>");
resultsXML.Append("</objectID>"); resultsXML.Append("<name>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(shapeResult.getValue());
resultsXML.Append("]]>");
resultsXML.Append("</name>"); resultsXML.Append("<area>");
resultsXML.Append("<![CDATA[");
resultsXML.Append(shapeResult.getValue());
resultsXML.Append("]]>");
resultsXML.Append("</area>");
resultsXML.Append("</feature>");
}
layer.close();
resultsXML.Append("</map>");
Session.Remove("MapServer_MAP");
Session["MapServer_MAP"] = map;
responseXML = resultsXML.ToString();
System.Diagnostics.Debug.WriteLine(responseXML);
}

C#+MapServer相关代码的更多相关文章

  1. [ARM] Cortex-M Startup.s启动文件相关代码解释

    1. 定义一个段名为CSTACK, 这里: NOROOT表示如何定义的段没有被关联,那么同意会被优化掉,如果不想被优化掉就使用ROOT. 后面的括号里数字表示如下: (1):这个段是2的1次方即2字节 ...

  2. Kafka Producer相关代码分析【转】

    来源:https://www.zybuluo.com/jewes/note/63925 @jewes 2015-01-17 20:36 字数 1967 阅读 1093 Kafka Producer相关 ...

  3. 命令行方式使用abator.jar生成ibatis相关代码和sql语句xml文件

    最近接手一个老项目,使用的是数据库是sql server 2008,框架是springmvc + spring + ibatis,老项目是使用abator插件生成的相关代码,现在需要增加新功能,要添加 ...

  4. myBatis自动生成相关代码文件配置(Maven)

    pom.xml文件添加配置 <build> <finalName>generator</finalName> <plugins> <!-- mav ...

  5. 临时2级页表的初始化过程 head_32.S 相关代码解释

    page_pde_offset = (__PAGE_OFFSET >> 20); /* __PAGE_OFFSET是0xc0000000,page_pde_offset = 3072 = ...

  6. 使用Mybatis Generator自动生成Mybatis相关代码

    本文将简要介绍怎样利用Mybatis Generator自动生成Mybatis的相关代码: 一.构建一个环境: 1. 首先创建一个表: CREATE TABLE pet (name VARCHAR(2 ...

  7. K:树、二叉树与森林之间的转换及其相关代码实现

    相关介绍:  二叉树是树的一种特殊形态,在二叉树中一个节点至多有左.右两个子节点,而在树中一个节点可以包含任意数目的子节点,对于森林,其是多棵树所组成的一个整体,树与树之间彼此相互独立,互不干扰,但其 ...

  8. js 横屏 竖屏 相关代码 与知识点

    <!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...

  9. 转:关于Latent Dirichlet Allocation及Hierarchical LDA模型的必读文章和相关代码

    关于Latent Dirichlet Allocation及Hierarchical LDA模型的必读文章和相关代码 转: http://andyliuxs.iteye.com/blog/105174 ...

随机推荐

  1. Spring中AOP切面编程学习笔记

    注解方式实现aop我们主要分为如下几个步骤: 1.在切面类(为切点服务的类)前用@Aspect注释修饰,声明为一个切面类. 2.用@Pointcut注释声明一个切点,目的是为了告诉切面,谁是它的服务对 ...

  2. 【.NET 4.5】新增的 Prefer 32-bit target platform

    这本来是一个很小的feature并且也没有什么模糊的地方,关键是VS把这个设置成了默认值,当默认为Any CPU的时候,application会被编译成32-bit mode. 下边是我遇到的问题,在 ...

  3. Java之Socket网络编程实践

    转自:http://my.oschina.net/leejun2005/blog/104955#comments 一.TCP/IP协议 既然是网络编程,涉及几个系统之间的交互,那么首先要考虑的是如何准 ...

  4. Spring Security构建Rest服务-1000-使用SpringSocial开发第三方登录之大白话OAuth协议

    OAuth协议简介 OAuth协议要解决的问题    OAuth协议中的各种角色 OAuth协议运行流程 OAuth协议,在网上也看了一些资料,意思就是给你颁发一个临时的通行证,你拿着这个通行证可以访 ...

  5. inline-block各浏览器兼容以及水平间隙问题解决方案

    inline-block属性 This value causes an element to generate a block box, which itself is flowed as a sin ...

  6. notepad++中设置python运行

    1. Notepad++ ->"运行"菜单->"运行"按钮 2. 在弹出的窗口内输入以下命令: cmd /k python "$(FULL ...

  7. Oracle 相关查询

    --创建用户 create user zzg identified by zzg123; --修改用户的密码 alter user zzg identified by unis; --所有用户所在的表 ...

  8. springcloud-05-ribbon中不使用eureka

    ribbon在有eureka的情况下, 可以不使用eureka, 挺简单, 直接上代码 application.xml server: port: spring: # 设置eureka中注册的名称, ...

  9. ruby楼层排序问题

    求教楼层排序问题 要求正确楼层排序为: B2,B1,1F,2F,3F...10F,11F 现有这13个无序的楼层 怎么排列成上面的格式? 求教 luikore 1楼 , 19小时前 1人喜欢 sort ...

  10. Cookie的格式及组成、页面间传参实例

    做项目需要页面间参数传递,搜索了一下网上的回复,发现可以用cookie解决,借此学习cookie的格式及组成: Cookie由变量名和值组成,类似Javascript变量.其属性里既有标准的Cooki ...