在ArcGIS Server地图输出中包含用户自己添加的标注

内容摘要
ArcGIS Server中提供了把地图文件输出成图片保存的接口,除了地图服务中已有的要素外,用户可能还会在地图上添加一些自定义的标注,比如鼠标操作添加的点、线、多边形、文字甚至图片。文章介绍了如何在输出保存的图片中保存用户自定义的标注。
过程描述
     ArcGIS Server中提供了把地图文件输出成图片保存的接口,除了地图服务中已有的要素外,用户可能还会在地图上添加一些自定义的标注,比如鼠标操作添加的点、线、多边形、文字甚至图片。在地图输出的时候,这部分内容如何保留下来呢?
     在地图上添加自定义标注,最常用的方法是用com.esri.adf.web.data.WebGraphics.addGraphics(GraphicElement elem),但是这个方法添加的标注在输出地图的时候没法直接使用。我们可以先看一看地图输出的接口:
      com.esri.arcgisws.MapServerPort.exportMapImage(com.esri.arcgisws.MapDescription mapDescription, com.esri.arcgisws.ImageDescription imageDescription)
   
其中ImageDescription设置了图片输出的参数,包括ImageType(图片格式与返回类型:MIMEData or URL)和ImageDisplay(图片分辨率、高度、宽度等);MapDescription设置了地图的参数,包括图层、输出范围以及自定义内容(CustomGraphics),这里的自定义内容指的就是用户在地图上添加的自定义标注。
     因此,如果想在地图输出时包含用户自定义的标注,最好是使用MapDescription的接口来添加这些标注,添加的方法与WebGraphics大同小异,下面是一段使用MapDescription添加一个标注的代码:
        //get the mapResource so we can get to the MapDescription
        AGSMapResource mapResource = (AGSMapResource) webContext.getResources().get("ags0");       
        AGSMapFunctionality mapFunctionality = (AGSMapFunctionality) mapResource.getFunctionality("map");
        MapDescription mapDescription = mapFunctionality.getMapDescription();
       
        //Get any existing graphic elements from the map description
        GraphicElement[] existingElements = mapDescription.getCustomGraphics();
       
        GraphicElement[] graphicElements = null;
        if(existingElements == null){
            graphicElements = new GraphicElement[1];
        } else {
            //there were already graphic elements so we need to copy them to our array
            graphicElements = new GraphicElement[existingElements.length + 1];
            System.arraycopy(existingElements, 0, graphicElements, 0, existingElements.length );
        }
       
        //make a marker element and set it's properties
        MarkerElement markerElement = new MarkerElement();
        PointN pointN = new PointN(point.getX(), point.getY(), null, null, null, null);
        markerElement.setPoint(pointN);
       
        //make a marker symbol for the element
        SimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbol();   
        markerSymbol.setSize(15.0);
        markerSymbol.setStyle(EsriSimpleMarkerStyle.esriSMSCircle);
        RgbColor color = new RgbColor();
        color.setAlphaValue(new UnsignedByte(255));
        color.setBlue(new UnsignedByte(0));
        color.setRed(new UnsignedByte(255));
        color.setGreen(new UnsignedByte(0));
        markerSymbol.setColor(color);
        markerSymbol.setOutlineColor(color);
       
        markerElement.setSymbol(markerSymbol);
       
        //add the markerElement to the array of graphicElements
        graphicElements[graphicElements.length-1] = markerElement;
       
        //set the custom graphics, this is a remote call
        mapDescription.setCustomGraphics(graphicElements);
       最后,如果要输出地图,只需要从MapFunctionality里取出MapDescription就可以了。

转载于:https://www.cnblogs.com/flystreet/archive/2008/06/15/1222606.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值