📄 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 + -