📄 createfeature.java
字号:
package barchant;import java.util.*;import com.mapinfo.dp.*;import com.mapinfo.util.*;import com.mapinfo.graphics.Rendition;import com.mapinfo.graphics.RenditionImpl;import java.awt.*;import com.mapinfo.dp.annotation.*;import com.mapinfo.mapj.*;//VisualMapJ没有FeatureFactoryimport com.mapinfo.dp.util.LocalDataProviderRef;import com.mapinfo.coordsys.LinearUnit;import javax.swing.*;import com.mapinfo.graphics.LocalRenderer;/*该示例演示了怎样常见图元,以创建点图元和圆图元为例,其他的可参考资料中的例子,注意本例只是响临时图层添加图元,向数据库道理应一样*/public class CreateFeature { public MapJ myMap;//可管理地图集的各种状态,并向服务器转发客户请求 public FeatureLayer world;//Feature对象用来访问地图对象 public CreateFeature() { myMap=new MapJ(); // Get Feature Factory referenceFeatureFactory ff = myMap.getFeatureFactory();/*创建点 成功DoublePoint pt = new DoublePoint(-100, 45);Rendition labelRend = null;// 创建 rendition 控制图元的 symbol font, char, size, and color setRendition rend = new RenditionImpl();rend.setValue(Rendition.SYMBOL_MODE, Rendition.SymbolMode.FONT);rend.setValue(Rendition.FONT_FAMILY, "MapInfo Shields");rend.setValue(Rendition.SYMBOL_STRING, "@");rend.setValue(Rendition.FONT_SIZE, 16);rend.setValue(Rendition.SYMBOL_FOREGROUND, Color.blue);//创建该图元的属性信息,两个属性,一个是字符型的,一个是数值型的Attribute attrs[] = { new Attribute("Point"), new Attribute(2) };// Make the first Attribute the PrimaryKey将第一个属性作为主键,即将"point"作为主键PrimaryKey key = new PrimaryKey(attrs[0]);*/ /*创建圆*/// 创建属性数据Attribute att[] = new Attribute[1];att[0] = new Attribute("Feature1");/* This will not work for tab files. For tab files you must use thecom.mapinfo.tab.TABStyleFactory to create an appropriate Rendition object.*///控制图元显示Rendition rend = RenditionImpl.getDefaultRendition();// For circles, specify the edge and fill color.rend.setValue(Rendition.STROKE, Color.cyan);rend.setValue(Rendition.FILL, Color.green);// For points, specify the symbol size, font, and colorrend.setValue(Rendition.SYMBOL_STRING, "@");rend.setValue(Rendition.FONT_SIZE, 16);rend.setValue(Rendition.FONT_FAMILY, "MapInfo Shields");rend.setValue(Rendition.SYMBOL_FOREGROUND, Color.blue);// For lines, specify the line color and widthrend.setValue(Rendition.STROKE, Color.green);rend.setValue(Rendition.STROKE_WIDTH, 4);// For ellipses, specify the fill color and opacityrend.setValue(Rendition.FILL, Color.blue);rend.setValue(Rendition.FILL_OPACITY, new Float(0.40));// 设置圆中心位置DoublePoint dp = new DoublePoint(-104, 45);// Create Circular regionint circType=1;int circRadius=25;int circResolution=25;PrimaryKey pkey = new PrimaryKey(att[0]);try{//创建点图元,需要的信息有点的位置,rendition显示格式,labelrendition,属性,主键 Feature point = ff.createCircularRegion(circType, dp, circRadius,LinearUnit.mile,circResolution, rend,null, att,pkey);// add the Feature to our previously created annotation layer//将图元添加到临时图层,无论是哪种图层都需要用DataProvider来定义,三个步骤 // 描述数据AnnotationTableDescHelper annTDHelper = new AnnotationTableDescHelper("annotations"); //定义数据源AnnotationDataProviderHelper annDPHelper = new AnnotationDataProviderHelper();// An Annotation layer requires the use of local memory space, so we create a LocalDataProviderRef //获取数据的方式,本地方式LocalDataProviderRef localDPRef = new LocalDataProviderRef(annDPHelper);// 添加临时图层Layer annotLayer= myMap.getLayers().add(localDPRef, annTDHelper, "Annotations");//在临时图层上添加该点图元annotLayer.addFeature(point); System.out.println("aaaaaaaaaaaaa");}catch (Exception e){e.printStackTrace();}} public static void main(String args[]){ CreateFeature bclr=new CreateFeature(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -