`
lorry1113
  • 浏览: 256670 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

arcobjects 图例

    博客分类:
  • GIS
J# 
阅读更多
public void exportLegend(IServerContext serverContext, IMapServer pMapServer ){
	    try
	    { 
	        IMapServerObjects mapServerObjects = (IMapServerObjects)pMapServer; 
	        IMap map = (IMap)mapServerObjects.getMap(pMapServer.getDefaultMapName());
	        
	        UID uid = (UID)serverContext.createObject("esriSystem.UID");
            	uid.setValue("esriCarto.Legend");
            ILegend legend1 = (ILegend) map.createMapSurround(uid, null );
            		legend1.setTitle("图例");
            for(int i=0; i<legend1.getItemCount();i++){
	        	ILegendItem lItem = legend1.getItem(i);
	        	ILayer layer = lItem.getLayer();
	        	//过滤掉标注点图层
	        	if(layer.getName().indexOf("标注点")>-1){
	        		legend1.removeItem(i);
	        	}	      
            }
           
	        
	        //获取该地图的layout对象 
	        IMapServerLayout layout = (IMapServerLayout)pMapServer; 
	        //设置图片类型
	        IImageType it = (IImageType)serverContext.createObject("esriCarto.ImageType");
	                   it.setFormat(esriImageFormat.esriImagePNG32) ;
	                   it.setReturnType(esriImageReturnType.esriImageReturnURL); 
	        //设置图片显示大小
	        IImageDisplay idisp = (IImageDisplay)serverContext.createObject("esriCarto.ImageDisplay");
	                      idisp.setHeight(1000);
	                      idisp.setWidth(400);
	                      idisp.setDeviceResolution(150);//DPI 每个英寸上所能印刷的网点数(Dot Per Inch)。
	                      //设置图片显示大小
	        IImageDisplay idisp1 = (IImageDisplay)serverContext.createObject("esriCarto.ImageDisplay");
	                      idisp1.setHeight(0);
	                      idisp1.setWidth(0);
	                      idisp1.setDeviceResolution(150);//DPI 每个英寸上所能印刷的网点数(Dot Per Inch)
	        //图片描述
	        IImageDescription pID = (IImageDescription)serverContext.createObject("esriCarto.ImageDescription");
	        				  pID.setDisplay(idisp1);
	        				  pID.setType(it); 
	        //设置图例
	        ILegend legend = (ILegend)serverContext.createObject("esriCarto.Legend");
	        for(int i=0; i<legend.getItemCount();i++){
	        	ILegendItem lItem = legend.getItem(i);
	        	ILayer layer = lItem.getLayer();
	        	System.out.println(layer.getName());
	        }
	        legend.setTitle("图例") ; 

	        IMapServerInfo pMapServerInfo = pMapServer.getServerInfo(pMapServer.getDefaultMapName());
	        IMapDescription pMD = pMapServerInfo.getDefaultMapDescription();
	       /* IMapLayerInfos mapLayerInfos = pMapServerInfo.getMapLayerInfos();
	        for(int j=0; j<mapLayerInfos.getCount();j++){
	        	IMapLayerInfo layerInfo = mapLayerInfos.getElement(j);
	        	System.out.println(layerInfo.getName());
	        	System.out.println("---------------------------------");
	        }*/
	        IImageResult img = layout.exportLegend(legend1, pMD, idisp, null, pID);
	        //释放ServerContext
	        serverContext = null;
	        System.out.println(img.getURL());
	    }catch (AutomationException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics