1. 程式人生 > >ArcGIS for javascript 構建GraphicsLayer

ArcGIS for javascript 構建GraphicsLayer

1)首先獲取平面座標,根據對應的座標系,例項化座標物件,如下:

      var point = new esri.geometry.Point(xpoint,ypoint,new esri.SpatialReference({wkid:4326}));

     wkid後面的值,一定選擇當前GIS對應的座標系標準,不一定是4326!

2)例項化內容模板

    var infoTemplate = new esri.InfoTemplate(content, "<a href='javascript:showDetail()'>檢視詳情</a>"); 

3)例項化圖形符號

    var symbol = new esri.symbol.PictureMarkerSymbol("images/red.png", 25, 25);

4)例項化基本元素

    var graphic = new esri.Graphic(point, symbol, null, infoTemplate);

5)例項化GraphicsLayer

     graphicLayer = new esri.layers.GraphicsLayer();

6)把元素新增到影象層

    graphicLayer.add(graphic);

7)讓當前座標居中

    map.centerAt(point);

注意:有時候居中效果無效,可能是因為Point的第三個座標系引數不對,所以必須先了解GIS圖層的座標系!