首页 > 代码库 > 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图层的坐标系!

ArcGIS for javascript 构建GraphicsLayer