阅读:3074回复:2
ArcGIS Server 开发初步 -- 显示地图
<P>显示地图</P>
<P> 只能看到图层名,不能看到地图就不是GIS 了。So....,Let's do it!</P> <P> 看程序之前先要学些理论,一下使我从帮助文件整理的,应该不算抄袭吧。<BR> <BR> 访问一张地图及其图层的信息使用IMapServer的GetServerInfo方法,GetServerInfo方法返回 MapServerInfo对象。使用IMapServerInfo接口我们可以访问一个Map(Data Frame)的只读信息。IMapServerInfo提供了访问 MapServer Object 默认状态的方法,诸如地图名称、背景色、地图坐标范围。如果没有改变细粒度的 ArcObjects的状态前,这些信息不会改变,这些ArcObjects是构成map document的基础。<BR> <BR> MapServerInfo对象包含MapDescription对象。使用IMapDescription接口可以访问关于地图的一些设置,这些设置可以在Server Object中进行修改,但构成构成map document的基础的ArcObjects状态并没有改变。</P> <P> MapDescription表示显示地图(draw map)需要设置的地图的参数,我们只要设置此参数就可以在不改变 MapServer中的设置的前提下,画出自己需要的地图。</P> <P> 关系如下图(附图1)</P> <P> map会以image的形式输出(Export),对于输出的图片的属性设置由 ImageDescription对象描述,而ImageDescription又由:ImageType (表示显示图片的种类)和 ImageDisplay(表示显示图片的特征)构成。结构如下图:(附图2)</P> <P><IMG src="http://bbs.esrichina-bj.cn/ESRI/attachments/forumid_25/gif_1_Cf6g0CQrozBu.gif"></P> <P><IMG src="http://bbs.esrichina-bj.cn/ESRI/attachments/forumid_25/gif_2_p0kxWeMhcvf6.gif"> </P> |
|
|
1楼#
发布于:2008-03-25 19:24
<P><FONT face=新宋体>package com.brsc;<BR>import java.io.IOException;<BR>import java.net.UnknownHostException;<BR>import com.esri.arcgis.server.*;<BR>import com.esri.arcgis.system.*;<BR>import com.esri.arcgis.carto.*;<BR>import com.esri.arcgis.interop.AutomationException;<BR>public class ShowMap {<BR>/**<BR> * @param args<BR> */<BR>public static void main(String[] args) {<BR> com.esri.arcgis.system.EngineInitializer.initializeEngine();<BR> new ServerInitializer().initializeServer("california", "arcgismanager", "server");<BR> IServerContext cxt=null;<BR> try {<BR> ServerConnection conn=new ServerConnection();<BR> conn.connect("california");<BR> IServerObjectManager manager=conn.getServerObjectManager();<BR> cxt=manager.createServerContext("usa", "MapServer");<BR> MapServer msr=(MapServer)cxt.getServerObject();<BR> //<BR> System.out.println("dex");<BR> //<BR> IMapServerInfo minfo=msr.getServerInfo(msr.getDefaultMapName());<BR> IMapDescription mdes=minfo.getDefaultMapDescription();<BR> IImageDescription ides=getImageDes(cxt);<BR> //<BR> IMapImage image=msr.exportMapImage(mdes, ides);<BR> System.out.println(image.getURL());<BR> <BR> } catch (UnknownHostException e) {<BR> // TODO Auto-generated catch block<BR> e.printStackTrace();<BR> } catch (IOException e) {<BR> // TODO Auto-generated catch block<BR> e.printStackTrace();<BR> }finally{<BR> try {<BR> cxt.releaseContext();<BR> } catch (AutomationException e) {<BR> e.printStackTrace();<BR> } catch (IOException e) {<BR> e.printStackTrace();<BR> }<BR> }<BR>}<BR>private static IImageDescription getImageDes(IServerContext context){<BR> IImageDescription imageDes=null;<BR> try {<BR> //从现在开始,ServerContext要从COM创建一切<BR> //创建ImageDescription<BR> imageDes=(IImageDescription)context.createObject(ImageDescription.getClsid());<BR> //创建ImageDisplay<BR> IImageDisplay imageDis=<BR> (IImageDisplay)context.createObject(ImageDisplay.getClsid());<BR> //创建ImageType<BR> IImageType imageType=<BR>(IImageType)context.createObject(ImageType.getClsid());<BR> //设定图片的大小(像素)<BR> imageDis.setHeight(600);<BR> imageDis.setWidth(800);<BR> //设定图片的类型,在esriImageFormat中定义<BR> imageType.setFormat(esriImageFormat.esriImageJPG);<BR> //设定Description<BR> imageDes.setDisplay(imageDis);<BR> imageDes.setType(imageType);<BR> } catch (AutomationException e) {<BR> // TODO Auto-generated catch block<BR> e.printStackTrace();<BR> } catch (IOException e) {<BR> // TODO Auto-generated catch block<BR> e.printStackTrace();<BR> }<BR> return imageDes;<BR>}<BR>//private <BR>}</FONT> </P>
|
|
|
2楼#
发布于:2009-10-20 10:32
谢谢了
|
|