ArcGIS Server 专题图的实现

测试完毕.地图服务是用ArcGis自带的USA.mxd.还留有的问题就是不能清除,需要重启服务清除。

专题地图:是突出反映一种或几种主题要素的地图,地图的主题要素是根据专门用途的需要确定的,它们应表达的详细,其它的地理要素则根据表达主题的需要作为地理基础选绘。
http://blog.csdn.net/mader/archive/2008/10/16/3084501.aspx
http://webgis.xdz.com.cn/


近日研究了在ArcGIS Server web adf (9.2)专题图实现,整理如下: (以柱状图为例,饼状图和直方图类似),希望对大家有所帮助!
package com.esri.webadf.sample;

import java.util.List;
import com.esri.adf.web.ags.data.AGSLocalMapResource;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebLayerInfo;
import com.esri.adf.web.data.query.WebQuery;
import com.esri.adf.web.faces.event.MapEvent;
import com.esri.arcgis.carto.ChartRenderer;
import com.esri.arcgis.carto.FeatureLayer;
import com.esri.arcgis.carto.ILayer;
import com.esri.arcgis.carto.IRendererFields;
import com.esri.arcgis.carto.MapServer;
import com.esri.arcgis.display.BarChartSymbol;
import com.esri.arcgis.display.IChartSymbol;
import com.esri.arcgis.display.ILineSymbol;
import com.esri.arcgis.display.IMarkerSymbol;
import com.esri.arcgis.display.IRgbColor;
import com.esri.arcgis.display.ISymbolArray;
import com.esri.arcgis.display.RgbColor;
import com.esri.arcgis.display.SimpleFillSymbol;
import com.esri.arcgis.display.SimpleLineSymbol;
import com.esri.arcgis.geodatabase.ICursor;
import com.esri.arcgis.geodatabase.IRowBuffer;
import com.esri.arcgis.geodatabase.QueryFilter;


public class BarChart {

	private WebContext webContext = null;

	public WebContext getWebContext() {
		return webContext;
	}

	public void setWebContext(WebContext webContext) {
		this.webContext = webContext;
	}

	public void createBarChart(MapEvent event) {

		
		try {
			//得到制作专题图的图层ID
			//		  。。。。。。。。。。
			WebQuery query = event.getWebContext().getWebQuery();
			List<WebLayerInfo> layerList = query.getQueryLayers();
			for(int i=0;i<layerList.size();i++){
				WebLayerInfo info = layerList.get(i);
				info.getName();
			}
			int layerID = 3;

			//得到专题图分析元素的属性名称列表
			String[] fieldName = new String[2];
			fieldName[0] = "POP1990";
			fieldName[1] = "POP1999";

			//得到专题图分析的图层对象(FeatureLayer)
			AGSLocalMapResource res = (AGSLocalMapResource) this.webContext.getResources().get("ags1");
			MapServer mapServer = res.getLocalMapServer();
			ILayer fiLayer;
			fiLayer = mapServer.getLayer(mapServer.getMapName(0), layerID);
			FeatureLayer fLayer = (FeatureLayer) fiLayer;

			//创建ChartRenderer对象  注意:在web adf中创建AO对象用AGSLocalMapResource对象的createArcObject(String)方法
			ChartRenderer chartRender = (ChartRenderer) res.createArcObject(ChartRenderer.getClsid());

			//在IRendererFileds中指定柱状图各列显示字段值   
			IRendererFields rendererFields = chartRender;
			rendererFields.addField(fieldName[0], null);
			rendererFields.setFieldAlias(0, rendererFields.getField(0));
			rendererFields.addField(fieldName[1], null);
			rendererFields.setFieldAlias(1, rendererFields.getField(1));

			//查出各元素指定属性最大值  必须的
			QueryFilter queryFilter = (QueryFilter) res.createArcObject(QueryFilter.getClsid());
			queryFilter.addField(fieldName[0]);
			queryFilter.addField(fieldName[1]);
			ICursor cursor = fLayer.ITable_search(queryFilter, true);
			int numFields = 2; //柱状图列的个数
			int[] fieldIndecies = new int[numFields];
			fieldIndecies[0] = fLayer.findField(fieldName[0]);
			fieldIndecies[1] = fLayer.findField(fieldName[1]);
			double maxValue = 0;
			boolean firstValue = true;
			IRowBuffer row = cursor.nextRow();
			while (row != null) {
				for (int fieldIndex = 0; fieldIndex < numFields; fieldIndex++) {
					double fieldValue = Double.parseDouble(row.getValue(
							fieldIndecies[fieldIndex]).toString());
					if (firstValue) {
						maxValue = fieldValue;
						firstValue = false;
					}
					if (fieldValue > maxValue)
						maxValue = fieldValue;
				}
				row = cursor.nextRow();
			}

			//实例化图表对象
			BarChartSymbol barChartSymbol = (BarChartSymbol) res.createArcObject(BarChartSymbol.getClsid());

			IChartSymbol chartSymbol = barChartSymbol;
			barChartSymbol.setWidth(10);
			IMarkerSymbol markerSymbol = barChartSymbol;
			chartSymbol.setMaxValue(maxValue);
			markerSymbol.setSize(60);

			//设置柱状图每列填充颜色及线颜色
			SimpleFillSymbol fillSymbol1 = (SimpleFillSymbol) res.createArcObject(SimpleFillSymbol.getClsid());
			IRgbColor rgbColor1 = (IRgbColor) res.createArcObject(RgbColor.getClsid());

			rgbColor1.setRed(255);
			rgbColor1.setGreen(0);
			rgbColor1.setBlue(0);
			rgbColor1.setUseWindowsDithering(true);

			ILineSymbol ilinesym1 = (ILineSymbol) res.createArcObject(SimpleLineSymbol.getClsid());
			ilinesym1.setColor(rgbColor1);
			ilinesym1.setWidth(1);
			fillSymbol1.setOutline(ilinesym1);

			fillSymbol1.setColor(rgbColor1);
			barChartSymbol.addSymbol(fillSymbol1);

			SimpleFillSymbol fillSymbol2 = (SimpleFillSymbol) res.createArcObject(SimpleFillSymbol.getClsid());

			IRgbColor rgbColor2 = (RgbColor) res.createArcObject(RgbColor.getClsid());

			rgbColor2.setRed(238);
			rgbColor2.setGreen(195);
			rgbColor2.setBlue(235);
			rgbColor2.setUseWindowsDithering(true);

			ILineSymbol ilinesym2 = (ILineSymbol) res.createArcObject(SimpleLineSymbol.getClsid());
			ilinesym2.setColor(rgbColor2);
			ilinesym2.setWidth(1);
			fillSymbol2.setOutline(ilinesym2);
			fillSymbol2.setColor(rgbColor2);
			barChartSymbol.addSymbol(fillSymbol2);

			chartRender.setChartSymbolByRef(chartSymbol);
			chartRender.setUseOverposter(false);
			//设置FeatureRenderer ChartRenderer对象
			fLayer.setRendererByRef(chartRender);
			//刷新地图显示图表
//			map1.refresh();
			this.webContext.refresh();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}



到此完成柱状专题图实现

你可能感兴趣的:(Web,.net,Yahoo,Blog)