?? rangedthemetest.java
字號:
package barchant;import java.lang.*;import java.util.*;import java.util.Hashtable;import java.awt.*;import com.mapinfo.mapj.*;import com.mapinfo.graphics.Rendition;import com.mapinfo.graphics.RenditionImpl;import java.util.List;import com.mapinfo.dp.ColumnStatistics;import com.mapinfo.dp.util.Bucketer;import com.mapinfo.dp.util.LinearRenditionSpreader;//import com.mapinfo.dp.analysis.AnalysisTableDescHelper;//import com.mapinfo.legend.AnalysisLayerChartLegend;import javax.swing.*;//import com.mapinfo.mapj.BarChartProperties;import com.mapinfo.beans.vmapj.VisualMapJ;import com.mapinfo.beans.tools.*;import com.mapinfo.theme.RangedTheme;import com.mapinfo.theme.ThemeList;import com.mapinfo.dp.Attribute;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2004</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class RangedThemeTest extends JFrame { public FeatureLayer lyr;//Feature對象用來訪問地圖對象 // public ArrayList cols; public VisualMapJ myMap;//可管理地圖集的各種狀態,并向服務器轉發客戶請求 //public Hashtable ht; public RangedThemeTest() { try{ //指上端的工具欄,工具欄默認包含幾種功能,如果想添加其它功能可以看下面代碼 MapToolBar myMapToolBar=new MapToolBar(); //在工具欄上添加新功能 RadiusSelectionMapTool radTool =new RadiusSelectionMapTool(); //創建地圖 myMap=new VisualMapJ(); myMap.getMapJ().loadMapDefinition("d:\\program files\\MapInfo\\MapXtreme-4.7.0\\examples\\server\\data\\local\\world.mdf"); lyr = (FeatureLayer)myMap.getMapJ().getLayers().getLayer("World Countries"); String colName = "POP_1994";/*以下示例是用顏色漸變自動顯示,所以只定義了兩個Rendition //Rendition類是用來控制圖元顯示,例如是否填充等 Rendition yellow=new RenditionImpl();//RenditionImpl對象用來描述一個圖元,標簽等怎樣顯示 Rendition red=new RenditionImpl(); ColumnStatistics colStats = lyr.fetchColumnStatistics(colName); // Set number of breaks for data,即定義了5個范圍 int numBreaks=5; // Compute the distribution of data with 5 breaks and Equal Ranges //Bucketer類是用于計算在RangedTheme中的斷點,這些斷點被用于構建主題 List rBreaks = (List) Bucketer.computeDistribution(numBreaks,colStats,Bucketer.DISTRIBUTION_TYPE_EQUAL_RANGES); // Set up a red and a yellow rendition and then spread the colors yellow.setValue(Rendition.FILL, Color.yellow); yellow.setValue(Rendition.STROKE_WIDTH, 2); red.setValue(Rendition.FILL, Color.red); red.setValue(Rendition.STROKE_WIDTH, 4); List rends = (List) LinearRenditionSpreader.spread(numBreaks, yellow, red); // Create Theme object *//*下面示例采用手動方式逐個定義*/ Vector rBreaks=new Vector(); //建立3個范圍 rBreaks.addElement(new Attribute(1)); rBreaks.addElement(new Attribute(17661468)); rBreaks.addElement(new Attribute(1136429638)); //為這3個范圍分別創建Rendition Rendition red=new RenditionImpl(); Rendition gray=new RenditionImpl(); Rendition green=new RenditionImpl(); red.setValue(Rendition.FILL, Color.red); red.setValue(Rendition.STROKE_WIDTH, 2); gray.setValue(Rendition.FILL, Color.yellow); gray.setValue(Rendition.STROKE_WIDTH, 2); green.setValue(Rendition.FILL, Color.green); green.setValue(Rendition.STROKE_WIDTH, 2); Vector rends=new Vector(); rends.addElement(red); rends.addElement(gray); rends.addElement(green); RangedTheme rTheme = new RangedTheme(colName, rBreaks, rends, "States by Pop_1994"); // Get ThemeList class object ThemeList tList=lyr.getThemeList(); // Add theme to Layers themeList tList.add(rTheme); //myMap.getMapJ().getLayers().elementAt(1).getThemeList().add(rTheme); //工具欄放上端 this.getContentPane().add(myMapToolBar,BorderLayout.NORTH); //地圖放中間 this.getContentPane().add(myMap,BorderLayout.CENTER); //圖例放右邊 // this.getContentPane().add(legend,BorderLayout.EAST); this.setVisible(true); this.show(); }catch(Exception e){ System.out.println("Error"); e.printStackTrace(); } } public static void main(String args[]){ RangedThemeTest bclr=new RangedThemeTest(); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -