?? createfeature.java
字號(hào):
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;/*該示例演示了怎樣常見圖元,以創(chuàng)建點(diǎn)圖元和圓圖元為例,其他的可參考資料中的例子,注意本例只是響臨時(shí)圖層添加圖元,向數(shù)據(jù)庫(kù)道理應(yīng)一樣*/public class CreateFeature { public MapJ myMap;//可管理地圖集的各種狀態(tài),并向服務(wù)器轉(zhuǎn)發(fā)客戶請(qǐng)求 public FeatureLayer world;//Feature對(duì)象用來(lái)訪問(wèn)地圖對(duì)象 public CreateFeature() { myMap=new MapJ(); // Get Feature Factory referenceFeatureFactory ff = myMap.getFeatureFactory();/*創(chuàng)建點(diǎn) 成功DoublePoint pt = new DoublePoint(-100, 45);Rendition labelRend = null;// 創(chuàng)建 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);//創(chuàng)建該圖元的屬性信息,兩個(gè)屬性,一個(gè)是字符型的,一個(gè)是數(shù)值型的Attribute attrs[] = { new Attribute("Point"), new Attribute(2) };// Make the first Attribute the PrimaryKey將第一個(gè)屬性作為主鍵,即將"point"作為主鍵PrimaryKey key = new PrimaryKey(attrs[0]);*/ /*創(chuàng)建圓*/// 創(chuàng)建屬性數(shù)據(jù)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));// 設(shè)置圓中心位置DoublePoint dp = new DoublePoint(-104, 45);// Create Circular regionint circType=1;int circRadius=25;int circResolution=25;PrimaryKey pkey = new PrimaryKey(att[0]);try{//創(chuàng)建點(diǎn)圖元,需要的信息有點(diǎn)的位置,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//將圖元添加到臨時(shí)圖層,無(wú)論是哪種圖層都需要用DataProvider來(lái)定義,三個(gè)步驟 // 描述數(shù)據(jù)AnnotationTableDescHelper annTDHelper = new AnnotationTableDescHelper("annotations"); //定義數(shù)據(jù)源AnnotationDataProviderHelper annDPHelper = new AnnotationDataProviderHelper();// An Annotation layer requires the use of local memory space, so we create a LocalDataProviderRef //獲取數(shù)據(jù)的方式,本地方式LocalDataProviderRef localDPRef = new LocalDataProviderRef(annDPHelper);// 添加臨時(shí)圖層Layer annotLayer= myMap.getLayers().add(localDPRef, annTDHelper, "Annotations");//在臨時(shí)圖層上添加該點(diǎn)圖元annotLayer.addFeature(point); System.out.println("aaaaaaaaaaaaa");}catch (Exception e){e.printStackTrace();}} public static void main(String args[]){ CreateFeature bclr=new CreateFeature(); }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -