ArcIMS 开发学习笔记(一)
最近在公司做WebGIS項(xiàng)目,感覺(jué)很爽快,將學(xué)習(xí)到的東西整理一下,供大家交流。
1.環(huán)境配置
??? Web服務(wù)器:Apache2048
??? Servlet:Tomcat4129
??? GIS開(kāi)發(fā)平臺(tái):ArcIMS 9.0
??? Java編譯環(huán)境:Eclipse
2.上述環(huán)境設(shè)置好之后,進(jìn)入ArcIMS開(kāi)發(fā)階段,主要的工作分三塊:java類/jsp/javascript
?? 用Struts 開(kāi)發(fā)實(shí)質(zhì)上將請(qǐng)求和處理完全隔離,jsp網(wǎng)頁(yè)中只需要寫(xiě)與action對(duì)應(yīng)的form,這些Action
?? 通過(guò)struts-config.xml和jsp網(wǎng)頁(yè)當(dāng)中的form等對(duì)應(yīng)起來(lái).
?? 下文主要按照功能對(duì)代碼實(shí)現(xiàn)進(jìn)行研究
?? 初始化地圖 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服務(wù)器的名稱或者IP
??????????? conn.setConnectionType(connectionType);
??????????? conn.setPort(port);//ArcIMS服務(wù)器的端口
??????????? conn.setService(service);//需要調(diào)用的ArcIMS服務(wù)器的服務(wù)名稱
??????????? conn.setDisplayMessages(displayMessages);
??????????? map.initMap(conn, 0, true, true, true, true);//初始化地圖
??????????? //地圖和圖例的風(fēng)格設(shè)置
??????????? 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);
????????? //獲取地圖的全圖范圍和一些參數(shù),并且傳送給客戶端
??????????? 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));
??????????? //將地圖的當(dāng)前范圍傳遞到客戶端
??????????? 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對(duì)象放入Session中,以后在這個(gè)對(duì)話中一直使用這個(gè)map對(duì)象來(lái)生成地圖
??????????? request.getSession().setAttribute("map", map);
??????????? request.getSession().setAttribute("fullExtent", extent);
?? }
catch(){}
??????? return mapping.findForward("ConetentFrame");//將網(wǎng)頁(yè)重定向到ConetentFrame
??????? ConetentFrame對(duì)應(yīng)的content.jsp里面只需要寫(xiě)一個(gè)form,對(duì)應(yīng)這個(gè)Action類InitMap
就可以初始化地圖并獲取相關(guān)的參數(shù)。
在content.jsp中,獲取地圖的參數(shù),并賦給客戶端。
<script language="JavaScript" type="text/javascript">
?? var m = parent.mapFrame;? //
<%
//初始化地圖時(shí),獲得地圖的初始化的全圖范圍
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);
<%
}
轉(zhuǎn)載于:https://www.cnblogs.com/TonyWu/archive/2005/10/15/255373.html
總結(jié)
以上是生活随笔為你收集整理的ArcIMS 开发学习笔记(一)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【NOI 2011】阿狸的打字机
- 下一篇: 30422元素