ArcGIS Server 专题图的实现
近日研究了在ArcGIS Server web adf (9.2)专题图实现,整理如下: (以柱状图为例,饼状图和直方图类似),希望对大家有所帮助!
//得到制作专题图的图层ID
。。。。。。。。。。
int layerID=3;
//得到专题图分析元素的属性名称列表
String[] fieldName=new String[2];
fieldName[0]="POP1990";
fieldName[1]="POP1999";
//得到专题图分析的图层对象(FeatureLayer)
AGSLocalMapResource res = (AGSLocalMapResource) this.webContext
.getResources().get("ags0");
MapServer mapServer = res.getLocalMapServer();
ILayer 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.addFieldfieldName[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) {
String fieldvalue = "";
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);
//设置柱状图每列填充颜色及线颜色
ISymbolArray symbolArray = barChartSymbol;
SimpleFillSymbol fillSymbol1 = (SimpleFillSymbol) res.createArcObject(SimpleFillSymbol.getClsid());
IRgbColor rgbColor1 = (RgbColor) 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();
。。。。。。。。。。
int layerID=3;
//得到专题图分析元素的属性名称列表
String[] fieldName=new String[2];
fieldName[0]="POP1990";
fieldName[1]="POP1999";
//得到专题图分析的图层对象(FeatureLayer)
AGSLocalMapResource res = (AGSLocalMapResource) this.webContext
.getResources().get("ags0");
MapServer mapServer = res.getLocalMapServer();
ILayer 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.addFieldfieldName[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) {
String fieldvalue = "";
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);
//设置柱状图每列填充颜色及线颜色
ISymbolArray symbolArray = barChartSymbol;
SimpleFillSymbol fillSymbol1 = (SimpleFillSymbol) res.createArcObject(SimpleFillSymbol.getClsid());
IRgbColor rgbColor1 = (RgbColor) 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();
加油,哥们,现在开始!