最近在公司做WebGIS项目,感觉很爽快,将学习到的东西整理一下,供大家交流。
1.环境配置
Web服务器:Apache2048
Servlet:Tomcat4129
GIS开发平台:ArcIMS 9.0
Java编译环境:Eclipse
2.上述环境设置好之后,进入ArcIMS开发阶段,主要的工作分三块:java类/jsp/javascript
用Struts 开发实质上将请求和处理完全隔离,jsp网页中只需要写与action对应的form,这些Action
通过struts-config.xml和jsp网页当中的form等对应起来.
下文主要按照功能对代码实现进行研究
初始化地图 InitMap Action:
需要用到的核心类:import com.esri.aims.mtier.io.ConnectionProxy和import com.esri.aims.mtier.model.map.Map
*************代码*********
ConnectionProxy conn = null;
Map map = null;
try {
conn = new ConnectionProxy();
map = new Map();
conn.setHost(host);//ArcIMS服务器的名称或者IP
conn.setConnectionType(connectionType);
conn.setPort(port);//ArcIMS服务器的端口
conn.setService(service);//需要调用的ArcIMS服务器的服务名称
conn.setDisplayMessages(displayMessages);
map.initMap(conn, 0, true, true, true, true);//初始化地图
//地图和图例的风格设置
map.setWidth(width);
map.setHeight(height);
map.getLegend().setFont("宋体");
map.getLegend().setAntialiasing(false);
map.getLegend().setTitle("图例");
map.getLegend().setTitleFontSize(18);
map.getLegend().setLayerFontSize(12);
map.getLegend().setValueFontSize(10);
map.getLegend().setAutoExtend(true);
map.getLegend().setWidth(125);
map.getLegend().setCellSpacing(7);
//获取地图的全图范围和一些参数,并且传送给客户端
Envelope extent = map.getEnvelope();
double minx = extent.getMinX();
double miny = extent.getMinY();
double maxx = extent.getMaxX();
double maxy = extent.getMaxY();
double mapXDistance = maxx - minx;
double mapYDistance = maxy - miny;
double doubleWidth = Double.parseDouble(Long.toString(width));
double doubleHeight = Double.parseDouble(Long.toString(height));
double mapRatio = (maxx - minx) / (maxy-miny);
double windowRatio = doubleWidth / doubleHeight;
double mapHeight = (windowRatio/mapRatio) * doubleHeight;
double upperHeight = (doubleHeight - mapHeight) / 2;
double distancePerPixel = mapXDistance / doubleWidth;
double mapMaxY = maxy