//放大的代码:

   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. 【NOIP2013】 华容道 bfs预处理+bfs

    这一题我们考虑一个最裸的算法: 我们设$dp[i][j][k][l]$表示当前棋子在$(i,j)$且空格在$(k,l)$时的最小步数 然后显然随便转移一下就好了,时间复杂度为$O(q(nm)^2)$. ...

  2. AppScan安全测试入门操作

    appscan:可以对网站等 Web 应用进行自动化的应用安全扫描和测试,也就是经常说的安全测试 工作原理:是通过对web应用进行安全攻击来检查网站是否存在漏洞. 初步了解到的 创建新的扫描-> ...

  3. Visual Studio 中的 Office 和 SharePoint 开发

    MSDN Library 开发工具和语言  Visual Studio 中的 Office 和 SharePoint 开发 https://msdn.microsoft.com/zh-cn/libra ...

  4. 【链表】Odd Even Linked List

    题目: Given a singly linked list, group all odd nodes together followed by the even nodes. Please note ...

  5. 数字和表达式(python)

    >>>2+2 4 >>>1/2#(注:3.0版本之前是这样的,整数除法) >>>1.0/2.0 0.5 >>>1.0/2 0.5 ...

  6. Centos 6.5下的OPENJDK卸载和SUN的JDK安装、环境变量配置

    不多说,直接上干货! 说明 图形界面安装,会自带有Centos6.5自带的OPRNJDK!!! *********************************自带的OPENJDK的卸载****** ...

  7. tomcat启动(五)Catalina分析-service.init

    上篇写到StandardService.init() 这个方法做什么呢?一起来看看. 这个类也是实现了Lifecycle 如图.这个图中i表示Interface接口.如Lifecycle,Contai ...

  8. Spring Boot 不使用默认的 parent,改用自己的项目的 parent

    在初学spring boot时,官方示例中,都是让我们继承一个spring的 spring-boot-starter-parent 这个parent: <parent> <group ...

  9. 表单提交.serialize()方法

    html中<form id="myForm" action="..." method='POST'> <div><input ty ...

  10. jQuery.on() 函数

    1.绑定所有的<p>元素// 为所有P元素分别绑定click事件处理函数handler$("p").on("click", handler); 2. ...