阅读:2025回复:5
ArcIMS 4.0.1 Java Connector 开发示例
<P align=center><FONT size=3>
<TABLE cellSpacing=6 cellPadding=6 width="100%" border=0> <TR> <TD width="100%"> <P align=center><FONT face=黑体 size=3>ArcIMS 4.0.1 Java Connector </FONT><FONT size=3>开发示例</FONT></P> <HR> </TD></TR> <TR> <TD width="100%"><FONT face=Arial size=3></FONT><FONT size=3> <P align=justify> </P></FONT> <P align=justify><B><FONT size=2>提要:</FONT></B><FONT size=2>本文通过一个简单的例子说明如何使用</FONT><FONT face=Arial size=2>ArcIMS Java Connector</FONT><FONT size=2>的</FONT><FONT face=Arial size=2>Java API</FONT><FONT size=2>,对于</FONT><FONT face=Arial size=2>Tag Lib</FONT><FONT size=2>这种开发方式,本文由于篇幅原因不作介绍。这里假定读者熟悉</FONT><FONT face=Arial size=2>Java</FONT><FONT size=2>的编程语言,熟悉</FONT><FONT face=Arial size=2>JSP(JavaServer Pages)</FONT><FONT size=2>技术,并对</FONT><FONT face=Arial size=2>Web Application</FONT><FONT size=2>的概念比较了解。</FONT></P> <P align=justify> </P> <P align=justify><FONT face=Arial size=2>ArcIMS Java Connector</FONT><FONT size=2>是</FONT><FONT face=Arial size=2>ArcIMS 4.0</FONT><FONT size=2>新引入的一个连接器,有了这个连接器用户就可以开发</FONT><FONT face=Arial size=2>JSP</FONT><FONT size=2>的地图站点。</FONT><FONT face=Arial size=2>JSP</FONT><FONT size=2>有什么好处呢?首先,实现了逻辑和表现的分离,程序员可以把业务逻辑写成</FONT><FONT face=Arial size=2>JavaBean</FONT><FONT size=2>,而页面的开发可以让有经验的页面设计人员去做。其次</FONT><FONT face=Arial size=2>JSP</FONT><FONT size=2>是服务器端程序,所以开发数据库应用或和其他应用交互都比较方便。对于不熟悉</FONT><FONT face=Arial size=2>JAVA</FONT><FONT size=2>的人可以用</FONT><FONT face=Arial size=2>Tab Library</FONT><FONT size=2>开发。</FONT></P> <P align=justify><FONT size=2>下面我们用</FONT><FONT face=Arial size=2>Java Connector</FONT><FONT size=2>实现用属性条件对地物在图上作定位,目的是通过这个例子说明如何使用</FONT><FONT face=Arial size=2>Java Connector</FONT><FONT size=2>。</FONT></P><FONT size=3> <P align=justify> </P></FONT> <P align=justify><FONT size=2>第一步,准备环境。要使用</FONT><FONT face=Arial size=2>Java Connector</FONT><FONT size=2>进行开发,首先要准备</FONT><FONT face=Arial size=2>JSP</FONT><FONT size=2>的运行环境,目前</FONT><FONT face=Arial size=2>JSP</FONT><FONT size=2>的环境分为两类,一类是</FONT><FONT face=Arial size=2>Web Server</FONT><FONT size=2>本身就支持</FONT><FONT face=Arial size=2>Java</FONT><FONT size=2>开发,另一类是</FONT><FONT face=Arial size=2>Web Server</FONT><FONT size=2>本身不支持</FONT><FONT face=Arial size=2>Java</FONT><FONT size=2>,需要安装一个</FONT><FONT face=Arial size=2>Servlet</FONT><FONT size=2>引擎才能支持</FONT><FONT face=Arial size=2>Java</FONT><FONT size=2>开发。前者如</FONT><FONT face=Arial size=2>WebLogic</FONT><FONT size=2>,</FONT><FONT face=Arial size=2>iPlanet</FONT><FONT size=2>等,后者如</FONT><FONT face=Arial size=2>IIS</FONT><FONT size=2>,</FONT><FONT face=Arial size=2>Apache</FONT><FONT size=2>等。后者可选的</FONT><FONT face=Arial size=2>Servlet</FONT><FONT size=2>引擎也有很多,如</FONT><FONT face=Arial size=2>ServletExec ISAPI</FONT><FONT size=2>,</FONT><FONT face=Arial size=2>Tomcat</FONT><FONT size=2>,</FONT><FONT face=Arial size=2>Jrun</FONT><FONT size=2>等。不同的</FONT><FONT face=Arial size=2>Web Server</FONT><FONT size=2>和不同的</FONT><FONT face=Arial size=2>Servlet</FONT><FONT size=2>引擎有不同的设置。这里我们使用</FONT><FONT face=Arial size=2>IIS5.0+ServletExec 4.1.1 ISAPI</FONT><FONT size=2>。假设我们已经安装了</FONT><FONT face=Arial size=2>IIS5.0</FONT><FONT size=2>,然后我们需要安装</FONT><FONT face=Arial size=2>JDK1.4.0</FONT><FONT size=2>,最后我们再安装</FONT><FONT face=Arial size=2>ServletExec 4.1.1 ISAPI</FONT><FONT size=2>。安装完</FONT><FONT face=Arial size=2>ServletExec 4.1.1 ISAPI</FONT><FONT size=2>后我们还需要在它的安装目录上加一个</FONT><FONT face=Arial size=2>internet</FONT><FONT size=2>用户,这样我们就可以通过远程管理</FONT><FONT face=Arial size=2>ServletExec ISAPI</FONT><FONT size=2>了。作完以上步骤我们就完成了环境的准备。</FONT></P><FONT size=3> <P align=justify> </P></FONT> <P align=justify><FONT size=2>第二步,做一个</FONT><FONT face=Arial size=2>Web Application</FONT><FONT size=2>。我们既可以用以前的办法把</FONT><FONT face=Arial size=2>Java Connector</FONT><FONT size=2>类库添加到</FONT><FONT face=Arial size=2>classpath</FONT><FONT size=2>,然后在</FONT><FONT face=Arial size=2>Jsp</FONT><FONT size=2>程序中直接引用的办法,也可以做一个</FONT><FONT face=Arial size=2>Web</FONT><FONT size=2>应用程序。作</FONT><FONT face=Arial size=2>Web</FONT><FONT size=2>应用程序的好处是我们不需要在</FONT><FONT face=Arial size=2>classpath</FONT><FONT size=2>中添加</FONT><FONT face=Arial size=2>Java Connector</FONT><FONT size=2>的类库作为全局设置,每一</FONT><FONT face=Arial size=2>Web Application</FONT><FONT size=2>都有自己的类库,这样当一个系统上有多个</FONT><FONT face=Arial size=2>Web Application</FONT><FONT size=2>的时候系统容易管理。所以我们选择使用</FONT><FONT face=Arial size=2>Web Application</FONT><FONT size=2>。</FONT></P><FONT size=3> <P align=justify> </P></FONT> <P align=justify><FONT size=2>我们先做一个</FONT><FONT face=Arial size=2>Web Application</FONT><FONT size=2>,</FONT><FONT face=Arial size=2>Web Application</FONT><FONT size=2>的目录结构如下</FONT><FONT face=Arial size=2>:</FONT></P> <BLOCKQUOTE><B> <P ><FONT face=Arial size=2>WebAppName </FONT><FONT size=2> </FONT><FONT face=Arial size=2>|_SupportFiles </FONT><FONT size=2> </FONT><FONT face=Arial size=2>|_WEB-INF </FONT><FONT size=2> </FONT><FONT face=Arial size=2>|_classes </FONT><FONT size=2> </FONT><FONT face=Arial size=2>|_lib</FONT></P></B></BLOCKQUOTE> <P ><B><FONT face=Arial size=2>WebAppName</FONT><FONT size=2>:</FONT></B><FONT size=2> <FONT>程序名。在</FONT> </FONT><FONT face=Arial size=2>URL</FONT><FONT size=2><FONT>中直接使用,区分大小写</FONT> <FONT>。</FONT></FONT></P><B> <P align=justify><FONT face=Arial size=2>SupportFiles</FONT><FONT size=2>:</FONT></B><FONT size=2>所有</FONT><FONT face=Arial size=2>JSP</FONT><FONT size=2>页面,风格页,图像,其他需要在</FONT><FONT face=Arial size=2>HTML</FONT><FONT size=2>网页上显示的东西都放在这个目录下。</FONT></P><B> <P align=justify><FONT face=Arial size=2>WEB-INF</FONT></B><FONT face=Arial size=2> </FONT><FONT size=2>目录:其下有两个目录和</FONT><FONT face=Arial size=2>web.xml</FONT><FONT size=2>文件,</FONT><FONT face=Arial size=2>classes </FONT><FONT size=2><FONT>和</FONT> </FONT><FONT face=Arial size=2>lib </FONT><FONT size=2>,</FONT><FONT face=Arial size=2>classes</FONT><FONT size=2>中包含</FONT><FONT face=Arial size=2>Java class</FONT><FONT size=2>文件,如</FONT><FONT face=Arial size=2>JavaBean</FONT><FONT size=2>等。</FONT><FONT face=Arial size=2>Lib</FONT><FONT size=2>目录下存放</FONT><FONT face=Arial size=2>JAR</FONT><FONT size=2>文件,将来</FONT><FONT face=Arial size=2>java connector</FONT><FONT size=2>的类库就放在这里。</FONT><FONT face=Arial size=2>Web.xml</FONT><FONT size=2>是</FONT><FONT face=Arial size=2>Web Application</FONT><FONT size=2>的描述文件。下面是一个</FONT><FONT face=Arial size=2>web.xml</FONT><FONT size=2>文件的例子:</FONT></P> <P align=justify><FONT face=Arial size=2><?xml version="1.0" encoding="UTF-8"?></FONT></P> <P align=justify><FONT face=Arial size=2><!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN' 'http://java.sun.com/j2ee/dtds/web-app_2_2.dtd'></FONT></P> <P align=justify><FONT face=Arial size=2><web-app></FONT></P> <P align=justify><FONT face=Arial size=2> <welcome-file-list></FONT></P> <P align=justify><FONT face=Arial size=2> <welcome-file>index.jsp</welcome-file></FONT></P> <P align=justify><FONT face=Arial size=2> </welcome-file-list></FONT></P> <P align=justify><FONT face=Arial size=2> <taglib></FONT></P> <P align=justify><FONT face=Arial size=2> <taglib-uri>arcims_taglib.tld</taglib-uri></FONT></P> <P align=justify><FONT face=Arial size=2> <taglib-location>/WEB-INF/lib/arcims_taglib.tld</taglib-location></FONT></P> <P align=justify><FONT face=Arial size=2> </taglib></FONT></P> <P align=justify><FONT face=Arial size=2></web-app></FONT></P> <P ><FONT size=2>作完这个目录结构后将</FONT><FONT face=Arial size=2>Java connector</FONT><FONT size=2>的类库拷到</FONT><FONT face=Arial size=2>lib</FONT><FONT size=2>目录下,主要是四个</FONT><FONT face=Arial size=2>jar</FONT><FONT size=2>文件</FONT><FONT><FONT face=Arial size=2>arcims_jconnect.jar</FONT><FONT size=2>,</FONT><FONT face=Arial size=2>jsse.jar</FONT><FONT size=2>,</FONT><FONT face=Arial size=2>jnet.jar</FONT><FONT size=2>,</FONT><FONT face=Arial size=2>jcert.jar</FONT><FONT size=2>。</FONT></FONT></P> <P ><FONT size=2>要使用这个</FONT><FONT face=Arial size=2>Web Application</FONT><FONT size=2>我们需要把它加到运行环境中去,下面我们看看如何在</FONT><FONT face=Arial size=2>ServletExec</FONT><FONT size=2>中加入</FONT><FONT face=Arial size=2>Web Application</FONT><FONT size=2>。</FONT></P> <P align=justify><FONT size=2>进入</FONT><FONT face=Arial size=2>ServletExec</FONT><FONT size=2>的管理界面,在左边</FONT><FONT face=Arial size=2>Web Applications</FONT><FONT size=2>下选择</FONT><FONT face=Arial size=2>manage</FONT><FONT size=2>,在右边显示</FONT><FONT face=Arial size=2>Manage Web Applications</FONT><FONT size=2>页面。点击</FONT><FONT face=Arial size=2>Add Web Application</FONT><FONT size=2>按钮,进入</FONT><FONT face=Arial size=2>Add a Web Application</FONT><FONT size=2>界面:</FONT></P><FONT size=3> <P align=center><IMG src="http://www.esrichina-bj.cn/library/chinanews/image/cn14-xu1.gif" border=0></P></FONT> <P align=justify><FONT size=2>输入需要的信息,点击</FONT><FONT face=Arial size=2>Submit</FONT><FONT size=2>按钮。这时用户如果没有建好相应目录或文件,</FONT><FONT face=Arial size=2>ServletExec</FONT><FONT size=2>将自动为用户建这些目录和</FONT><FONT face=Arial size=2>Web Application</FONT><FONT size=2>描述文件。关闭浏览器窗口完成设置。</FONT></P><FONT size=3> <P align=justify> </P></FONT> <P align=justify><FONT size=2>第三步,开发</FONT><FONT face=Arial size=2>JSP</FONT><FONT size=2>应用。用文本编辑工具新建一个</FONT><FONT face=Arial size=2>jsp</FONT><FONT size=2>程序,存到</FONT><FONT face=Arial size=2>Web Application</FONT><FONT size=2>根目录下。现在这还是一个空的文件。我们要在这个文件中实现从属性查图形,将查到的结果用特定的符号表示出来,并居中放大显示。</FONT></P> <P align=justify><FONT size=2>首先写入连接信息,这里我们将要用到两个</FONT><FONT face=Arial size=2>JavaBean</FONT><FONT size=2>:</FONT><FONT face=Arial size=2>Connection</FONT><FONT size=2>和</FONT><FONT face=Arial size=2>Map</FONT><FONT size=2>。</FONT></P> <P align=justify><FONT face=Arial size=2><jsp:useBean id="connection" class="com.esri.aims.mtier.io.ConnectionProxy" scope="page" /></FONT></P> <P align=justify><FONT face=Arial size=2><jsp:useBean id="map" class="com.esri.aims.mtier.model.map.Map" scope="page" /></FONT></P> <P align=justify><FONT size=2>我们在引入这两个</FONT><FONT face=Arial size=2>JavaBean</FONT><FONT size=2>的同时,生成了</FONT><FONT face=Arial size=2>connection</FONT><FONT size=2>和</FONT><FONT face=Arial size=2>map</FONT><FONT size=2>这两个对象。接着需要设置连接信息,地图显示范围,地图图例等:</FONT></P> <P align=justify><FONT face=Arial size=2><%</FONT></P> <P align=justify><FONT face=Arial size=2>if(connection.getHost() == null){</FONT></P> <P align=justify><FONT face=Arial size=2>connection.setHost("xxh");</FONT></P> <P align=justify><FONT face=Arial size=2>connection.setPort(5300);</FONT></P> <P align=justify><FONT face=Arial size=2>connection.setService("SantaClara");</FONT></P> <P align=justify><FONT face=Arial size=2>map.initMap(connection, 0, false, false, false, false);</FONT></P> <P align=justify><FONT face=Arial size=2>map.setWidth(500);</FONT></P> <P align=justify><FONT face=Arial size=2>map.setHeight(350);</FONT></P> <P align=justify><FONT face=Arial size=2>map.getLegend().setAntialiasing(true);</FONT></P> <P align=justify><FONT face=Arial size=2>map.getLegend().setWidth(200);</FONT></P> <P align=justify><FONT face=Arial size=2>map.getLegend().setHeight(300);</FONT></P> <P align=justify><FONT face=Arial size=2>map.getLegend().setTitle("Legend");</FONT></P> <P align=justify><FONT face=Arial size=2>map.getLegend().setTitleFontSize(12);</FONT></P> <P align=justify><FONT face=Arial size=2>map.getLegend().setFont("</FONT><FONT size=2>黑体</FONT><FONT face=Arial size=2>");</FONT></P> <P align=justify><FONT face=Arial size=2>map.getLegend().setValueFontSize(15);</FONT></P> <P align=justify><FONT face=Arial size=2>map.getLegend().setSwatchHeight(15);</FONT></P> <P align=justify><FONT face=Arial size=2>map.getLegend().setSwatchWidth(15);</FONT></P> <P align=justify><FONT face=Arial size=2>map.getLegend().setLayerFontSize(10);</FONT></P> <P align=justify><FONT face=Arial size=2>map.getLayers().setGeometry(true); //very important</FONT></P> <P align=justify><FONT face=Arial size=2>}</FONT></P> <P align=justify><FONT face=Arial size=2>%></FONT></P> <P align=justify><FONT size=2>下面我们就来看如何用</FONT><FONT face=Arial size=2>java connector</FONT><FONT size=2>实现从属性定位查询,本例的地图服务</FONT><FONT face=Arial size=2>SantaClara</FONT><FONT size=2>中有一个</FONT><FONT face=Arial size=2>hospital</FONT><FONT size=2>图层,我们现在要查询一个叫</FONT><FONT face=Arial size=2><FONT>“</FONT>SOUTH VALLEY HOSPITAL<FONT>”</FONT></FONT><FONT size=2>的医院,把它用蓝色的五角星表示,并居中显示。</FONT></P> <P align=justify><FONT size=2>通过查询</FONT><FONT face=Arial size=2>java connector</FONT><FONT size=2>的</FONT><FONT face=Arial size=2>API</FONT><FONT size=2>参考资料,得知</FONT><FONT face=Arial size=2>map</FONT><FONT size=2>这个</FONT><FONT face=Arial size=2>JavaBean</FONT><FONT size=2>有一个</FONT><FONT face=Arial size=2>public void <B>displayFeatures</B>(<U><FONT color=#0000ff>FeatureLayer</FONT></U></FONT><FONT size=2> </FONT><FONT face=Arial size=2>targetLayer</FONT><FONT size=2>,</FONT><FONT face=Arial size=2><a href="http://java.sun.com/products/jdk/1.2/docs/api/java/lang/String.html" target="_blank" ><U><FONT color=#0000ff>String</FONT></U></A></FONT><FONT size=2> </FONT><FONT face=Arial size=2>expression</FONT><FONT size=2>,</FONT><FONT face=Arial size=2>boolean</FONT><FONT size=2> </FONT><FONT face=Arial size=2>zoomToFeatures</FONT><FONT size=2>,</FONT><FONT face=Arial size=2><a href="http://java.sun.com/products/jdk/1.2/docs/api/java/lang/Object.html" target="_blank" ><U><FONT color=#0000ff>Object</FONT></U></A></FONT><FONT size=2> </FONT><FONT face=Arial size=2>symbolObject)</FONT><FONT size=2>的方法。调用此方法前需要先得到</FONT><FONT face=Arial size=2>hospital</FONT><FONT size=2>层并创建一个蓝色五角星符号,</FONT></P> <P align=justify><FONT face=Arial size=2><%</FONT></P> <P align=justify><FONT face=Arial size=2>FeatureLayer fLayer = null;</FONT></P> <P align=justify><FONT face=Arial size=2>int LayerCount=map.getLayers().getCount();</FONT></P> <P align=justify><FONT face=Arial size=2>for (int k=0;k<LayerCount;k++)</FONT></P> <P align=justify><FONT face=Arial size=2>{</FONT></P> <P align=justify><FONT face=Arial size=2>String LayerName =map.getLayers().item(k).getName();</FONT></P> <P align=justify><FONT face=Arial size=2>if (LayerName.equals("hospital")) {</FONT></P> <P align=justify><FONT face=Arial size=2>fLayer = (FeatureLayer)map.getLayers().item(k);</FONT></P> <P align=justify><FONT face=Arial size=2>}</FONT></P> <P align=justify><FONT face=Arial size=2>}</FONT></P> <P align=justify><FONT face=Arial size=2>SimpleMarkerSymbol sm1 = new SimpleMarkerSymbol();</FONT></P> <P align=justify><FONT face=Arial size=2>sm1.setMarkerType("star");</FONT></P> <P align=justify><FONT face=Arial size=2>sm1.setColor("0,0,255");</FONT></P> <P align=justify><FONT face=Arial size=2>sm1.setWidth(20);</FONT></P> <P align=justify><FONT face=Arial size=2>%></FONT></P> <P align=justify><FONT size=2>这里我们用到了两个类</FONT><FONT face=Arial size=2>FeatureLayer</FONT><FONT size=2>和</FONT><FONT face=Arial size=2>SimpleMarkerSymbol</FONT><FONT size=2>,我们必须在</FONT><FONT face=Arial size=2>JSP</FONT><FONT size=2>页面开头的部分引入这些类。</FONT></P> <P align=justify> </P> <P align=justify><FONT size=2>下面我们就把我们这段程序所需要的类的定义全都加进去:</FONT></P> <P align=justify><FONT face=Arial size=2><%@ page language="java" contentType="text/html;charset=gb2312" %></FONT></P> <P align=justify><FONT face=Arial size=2><%@ page import="com.esri.aims.mtier.io.* " %></FONT></P> <P align=justify><FONT face=Arial size=2><%@ page import="com.esri.aims.mtier.model.map.layer.FeatureLayer" %></FONT></P> <P align=justify><FONT face=Arial size=2><%@ page import="com.esri.aims.mtier.model.map.layer.query.Filter" %></FONT></P> <P align=justify><FONT face=Arial size=2><%@ page import="com.esri.aims.mtier.model.map.layer.FeatureLayer" %></FONT></P> <P align=justify><FONT face=Arial size=2><%@ page import="com.esri.aims.mtier.model.map.layer.query.Geometry" %></FONT></P> <P align=justify><FONT face=Arial size=2><%@ page import="com.esri.aims.mtier.model.acetate.Point" %></FONT></P> <P align=justify><FONT face=Arial size=2><%@ page import="com.esri.aims.mtier.model.map.layer.AcetateLayer" %></FONT></P> <P align=justify><FONT face=Arial size=2><%@ page import="com.esri.aims.mtier.model.acetate.Acetate" %></FONT></P> <P align=justify><FONT face=Arial size=2><%@ page import="com.esri.aims.mtier.model.acetate.Points" %></FONT></P> <P align=justify><FONT face=Arial size=2><%@ page import="com.esri.aims.mtier.model.map.layer.renderer.symbol.SimpleMarkerSymbol" %></FONT></P> <P align=justify><FONT face=Arial size=2><%@ page import="com.esri.aims.mtier.model.util.CoordsToPoints" %></FONT></P> <P align=justify><FONT face=Arial size=2><%@ page import="com.esri.aims.mtier.model.envelope.Envelope" %></FONT></P> <P align=justify><FONT size=2>然后调用</FONT><FONT face=Arial size=2>displayFeatures</FONT><FONT size=2>函数:</FONT></P> <P align=justify><FONT face=Arial size=2><%</FONT></P> <P align=justify><FONT face=Arial size=2>map.displayFeatures(fLayer, <FONT>“</FONT>NAME=’ NAME='SOUTH VALLEY HOSPITAL'’<FONT>”</FONT>false, sm1);</FONT></P> <P align=justify><FONT face=Arial size=2>%></FONT></P> <P align=justify><FONT size=2>注意因为</FONT><FONT face=Arial size=2>hopital</FONT><FONT size=2>是点层,它没有范围(</FONT><FONT face=Arial size=2>Bounding Box</FONT><FONT size=2>),所以我们不能放大到这个点。这就是为什么我们在这里让</FONT><FONT face=Arial size=2>zoomToFeatures</FONT><FONT size=2>的值为</FONT><FONT face=Arial size=2>false</FONT><FONT size=2>的原因。</FONT></P> <P align=justify><FONT size=2>接下来我们把地图和图例用网页的形式输出:</FONT></P> <P align=justify><FONT face=Arial size=2><%</FONT></P> <P align=justify><FONT face=Arial size=2>String mapURL = map.getMapOutput().getURL();</FONT></P> <P align=justify><FONT face=Arial size=2>String legendURL = map.getLegend().getLegendOutput().getURL();</FONT></P> <P align=justify><FONT face=Arial size=2>%></FONT></P> <P align=justify><FONT face=Arial size=2><HTML><HEAD><TITLE>ArcIMS JSP Samples</TITLE></FONT></P> <P align=justify><FONT face=Arial size=2></HEAD><BODY bgcolor="#ffffff"></FONT></P> <P align=justify><FONT face=Arial size=2><table border="1" align="center"></FONT></P> <P align=justify><FONT face=Arial size=2><tr></FONT></P> <P align=justify><FONT face=Arial size=2><td align="center"><input type="image" name="map" src="<%= mapURL %>"></td></FONT></P> <P align=justify><FONT face=Arial size=2><td align="left" rowspan=3><img src="<%= legendURL %>"></td></tr></FONT></P> <P align=justify><FONT face=Arial size=2></tr></FONT></P> <P align=justify><FONT face=Arial size=2></table><center></FONT></P> <P align=justify><FONT face=Arial size=2></BODY></HTML></FONT></P> <P align=justify> </P> <P align=justify><FONT size=2>运行这段程序,结果如下:</FONT></P><FONT size=3> <P align=center><IMG src="http://www.esrichina-bj.cn/library/chinanews/image/cn14-xu2.gif" border=0></P></FONT> <P align=justify><FONT size=2>大家可能注意到</FONT><FONT face=Arial size=2>“SOUTH VALLEY HOSPITAL”</FONT><FONT size=2>已经查到了,并用蓝色的五角星标在图上,但到目前为止还没有居中,所以我们不能用</FONT><FONT face=Arial size=2><FONT>map.displayFeatures(fLayer, “NAME=</FONT>’<FONT>SOUTH VALLEY HOSPITAL</FONT>’<FONT>”false, sm1)</FONT></FONT><FONT size=2>函数。如何做到居中呢?我们通过查询</FONT><FONT><FONT face=Arial size=2>java connector</FONT><FONT size=2>的</FONT><FONT face=Arial size=2>API</FONT><FONT size=2>参考资料,得知</FONT><FONT face=Arial size=2>map</FONT><FONT size=2>这个</FONT><FONT face=Arial size=2>JavaBean</FONT><FONT size=2>有一个</FONT><FONT face=Arial size=2>public void <B>centerAt</B>(double?x,double?y)</FONT><FONT size=2>方法。所以只要我们得到</FONT><FONT face=Arial size=2>“SOUTH VALLEY HOSPITAL”</FONT><FONT size=2>的点位坐标就可以实现居中了,我们用下面的代码先对</FONT><FONT face=Arial size=2>hospital</FONT><FONT size=2>图层实施过滤,然后得到点位坐标:</FONT></FONT></P> <P ><FONT face=Arial size=2>Filter filter = new Filter();</FONT></P> <P ><FONT face=Arial size=2>filter.setGlobalEnvelope(true);</FONT></P> <P ><FONT face=Arial size=2>filter.setBoundingEnvelope(true);</FONT></P> <P ><FONT face=Arial size=2>filter.setWhereExpression("NAME='SOUTH VALLEY HOSPITAL'");</FONT></P> <P ><FONT face=Arial size=2>fLayer.setFilterObject(filter);</FONT></P> <P ><FONT face=Arial size=2>map.refresh(); //YOu must refresh map here!!</FONT></P> <P align=justify><FONT face=Arial size=2>Geometry geom = fLayer.getRecordset().getGeometry(0);</FONT></P> <P align=justify><FONT face=Arial size=2>Point point1= geom.getPointObject(0);</FONT></P> <P align=justify><FONT face=Arial size=2>double x2=point1.getX();</FONT></P> <P align=justify><FONT face=Arial size=2>double y2=point1.getY();</FONT></P> <P align=justify><FONT size=2>由于</FONT><FONT face=Arial size=2>centerAt</FONT><FONT size=2>的参数要求是屏幕坐标,而我们得到的是地理坐标,所以需要转换后使用:</FONT></P> <P align=justify><FONT face=Arial size=2>Point pointPixel = map.fromMapPoint(x2, y2);</FONT></P> <P align=justify><FONT face=Arial size=2>map.centerAt(pointPixel.getX(),pointPixel.getY());</FONT></P> <P align=justify><FONT size=2>但我们又有了一个问题,虽然居中显示了,但并没有用蓝色的五角星表示出来。怎么办?我们有两种办法解决,第一种,我们发现</FONT><FONT face=Arial size=2>displayFeature</FONT><FONT size=2>还有一个不带查询条件的函数,用此函数可以根据过滤结果用定制的符号显示要素。</FONT></P> <P align=justify><FONT face=Arial size=2><% map.displayFeatures(fLayer, false, sm1); %></FONT></P> <P align=justify><FONT size=2>运行程序结果如下:</FONT></P><FONT size=3> <P align=center><IMG src="http://www.esrichina-bj.cn/library/chinanews/image/cn14-xu3.gif" border=0></P></FONT> <P align=justify><FONT size=2>第二种办法,我们可以用</FONT><FONT face=Arial size=2>acetate</FONT><FONT size=2>对象实现标记功能,方法如下:</FONT></P> <P align=justify><FONT face=Arial size=2><%</FONT></P> <P align=justify><FONT face=Arial size=2>//add a Star</FONT></P> <P align=justify><FONT face=Arial size=2>Point po = new Point();</FONT></P> <P align=justify><FONT face=Arial size=2>po.setX(x2);</FONT></P> <P align=justify><FONT face=Arial size=2>po.setY(y2);</FONT></P> <P align=justify><FONT face=Arial size=2>po.setID("Point ");</FONT></P> <P align=justify><FONT face=Arial size=2>po.setName("Pointer");</FONT></P> <P align=justify><FONT face=Arial size=2>po.setSymbol(sm1);</FONT></P> <P align=justify><FONT face=Arial size=2>Acetate ao2 = new Acetate();</FONT></P> <P align=justify><FONT face=Arial size=2>ao2.setAcetateElement(po);</FONT></P> <P align=justify><FONT face=Arial size=2>ao2.setUnits("database");</FONT></P> <BLOCKQUOTE> <P align=justify><FONT face=Arial size=2>AcetateLayer al2 = new AcetateLayer(String.valueOf(map.getLayers().getCount()), null, null);</FONT></P></BLOCKQUOTE> <P align=justify><FONT face=Arial size=2>al2.addAcetate(ao2);</FONT></P> <P align=justify><FONT face=Arial size=2>al2.setVisible(true);</FONT></P> <P align=justify><FONT face=Arial size=2>al2.setName("AcetateLayer2");</FONT></P> <P align=justify><FONT face=Arial size=2>map.getLayers().add(al2);</FONT></P> <P align=justify><FONT face=Arial size=2>%></FONT></P></TD></TR></TABLE></FONT></P> |
|
|
1楼#
发布于:2004-10-14 15:07
这是arcgisworld中的一篇文章
|
|
2楼#
发布于:2004-09-25 10:57
<P>8dong</P>
|
|
|
3楼#
发布于:2004-09-24 16:31
8错,谢谢楼主,继续学习了,呵呵
|
|
4楼#
发布于:2004-09-22 22:30
<P>好!</P><img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em02.gif" />
|
|
5楼#
发布于:2004-09-22 17:21
<P>精华文档,给予奖励。</P><img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em02.gif" />
|
|
|