//放大的代码:

   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. Linux 基础命令 持续更新中...

    1.ls 显示当前文件/文件夹 显示文件大小: ls -lh  显示隐藏文件: ls -a 显示文件详细信息: ls -l (ll)2.pwd 显示当前所在路径 cat 显示当前文件下所有内容3.cd ...

  2. 【11】JMicro微服务-配置管理

    如非授权,禁止用于商业用途,转载请注明出处作者:mynewworldyyl 往下看前,建议完成前面1到10小节 JMicro目前仅支持基于Zookeeper做配置管理,全部配置信息可以在ZK做增删改查 ...

  3. Python中第三方库的安装

    网上的帖子挺多的,教你如何安装,安装第三方工具库的方法总共分为三类:Dos系统下pip命令:安装包下载安装:IDE集成环境下安装(Pycharm,Spyder……) http://www.jiansh ...

  4. SQL中文转拼音

    使用下方的函数.. 忘了从哪抄的了..留存一份 如果只要首字母..建议将数据  Left(tableFiled,1) 后传入函数 如果字段是空或者null, 不会报错..返回空 方法体: SET AN ...

  5. (转)MySQL 加锁处理分析

    MySQL 加锁处理分析 原文:http://hedengcheng.com/?p=771 1    背景    1 1.1    MVCC:Snapshot Read vs Current Read ...

  6. (转)MySQL优化系列

    原文:http://blog.csdn.net/jack__frost/article/details/71194208 数据库,后端开发者必学,而且现在以MySQL居多.这个系列将系统化MySQL一 ...

  7. 解决ssh登陆超时方案

    ssh登陆一般默认3分钟无操作则断开连接,有时候还是很烦的,于是解决这个问题. sudo修改/etc/ssh/sshd_conf文件 #sudo vim /etc/ssh/sshd_config #在 ...

  8. ssh 登录进入 docker container

    1.Container安装ssh服务,博主的linux是centos ① 安装ssh sudo yum install openssh-server #安装ssh服务器 service sshd st ...

  9. centos7的防火墙配置

    centos7 不在使用iptables作为防火墙, 而是使用firewalld规则, 好吃是支持动态更新, 不需要重启服务, 第二个就是加入了zone概念. 所以和centos6在防火墙配置上有很大 ...

  10. Nodejs学习笔记(一)—简介及安装Node.js开发环境

    一.简介 Node.js是让Javascript脱离浏览器运行在服务器的一个平台,不是语言: Node.js采用的Javascript引擎是来自Google Chrome的V8:运行在浏览器外不用考虑 ...