ArcIMS
开发学习心得
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(){}
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);
<%
}
<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);
<%
}