ArcIMS 开发学习笔记(一)
最近在公司做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 + distancePerPixel * upperHeight;
??????????? double mapMinY = miny - distancePerPixel * upperHeight;
?????????
???????????? //將地圖的全圖范圍傳遞到客戶端
??????????? request.setAttribute("fullMinX", new Double(extent.getMinX()));
??????????? request.setAttribute("fullMinY", new Double(mapMinY));
??????????? request.setAttribute("fullMaxX", new Double(extent.getMaxX()));
??????????? request.setAttribute("fullMaxY", new Double(mapMaxY));
??????????? //將地圖的當前范圍傳遞到客戶端
??????????? request.setAttribute("minX", new Double(extent.getMinX()));
??????????? request.setAttribute("minY", new Double(mapMinY));
??????????? request.setAttribute("maxX", new Double(extent.getMaxX()));
??????????? request.setAttribute("maxY", new Double(mapMaxY));
???????????
??????????? //告知客戶端這是在初始化地圖
??????????? request.setAttribute("initMap", "true");
?????????? //獲取地圖圖片的 mapUrl和圖例了legendurl
??????????? request.setAttribute("mapUrl", map.getMapOutput().getURL());
??????????? request.setAttribute("legendUrl", map.getLegend().getLegendOutput()
??????????????????? .getURL());?
?????????? //將Map對象放入Session中,以后在這個對話中一直使用這個map對象來生成地圖
??????????? request.getSession().setAttribute("map", map);
??????????? request.getSession().setAttribute("fullExtent", extent);
?? }
catch(){}
??????? return mapping.findForward("ConetentFrame");//將網頁重定向到ConetentFrame
??????? ConetentFrame對應的content.jsp里面只需要寫一個form,對應這個Action類InitMap
就可以初始化地圖并獲取相關的參數。
在content.jsp中,獲取地圖的參數,并賦給客戶端。
<script language="JavaScript" type="text/javascript">
?? var m = parent.mapFrame;? //
<%
//初始化地圖時,獲得地圖的初始化的全圖范圍
if (initMap != null){
%>??
???
??? m.fullMinX = <%=(Double)request.getAttribute("fullMinX")%>;
??? m.fullMinY = <%=(Double)request.getAttribute("fullMinY")%>;
??? m.fullMaxX = <%=(Double)request.getAttribute("fullMaxX")%>;
??? m.fullMaxY = <%=(Double)request.getAttribute("fullMaxY")%>;
??? m.fullOVLeft = m.fullMinX;
??? m.fullOVRight = m.fullMaxX;
??? m.fullOVTop = m.fullMaxY;
??? m.fullOVBottom = m.fullMinY;
??? m.fullOVWidth = Math.abs(m.fullOVRight - m.fullOVLeft);
??? m.fullOVHeight = Math.abs(m.fullOVTop - m.fullOVBottom);
<%
}
轉載于:https://www.cnblogs.com/TonyWu/archive/2005/10/15/255373.html
總結
以上是生活随笔為你收集整理的ArcIMS 开发学习笔记(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【NOI 2011】阿狸的打字机
- 下一篇: SQL语句恢复数据库时一直显示“正在还原