通过js api 对一个图层上进行标记点的生成

不需要使用Toolbar。直接使用map的graphics类中的add方法。

  • 例子代码:通过JSON对象方式

 

/** * 在地图上画一个点 * * @param featureSet * @return */ function addPointsToMap() { console.debug("开始画点"); var myPoint = {"geometry":{"x":-104.4140625,"y":69.2578125, "spatialReference":{"wkid":4326}},"attributes":{"XCoord":-104.4140625, "YCoord":69.2578125,"Plant":"Mesa Mint"},"symbol":{"color":[255,0,0,128], "size":12,"angle":0,"xoffset":0,"yoffset":0,"type":"esriSMS", "style":"esriSMSSquare","outline":{"color":[0,0,0,255],"width":1, "type":"esriSLS","style":"esriSLSSolid"}}, "infoTemplate":{'title':'Vernal Pool Locations',"content":'Latitude: ${YCoord} <br/> Longitude: ${XCoord} <br/> Plant Name:${Plant}'}}; //根据一个JSON构建一个Graphic对象 var gra= new esri.Graphic(myPoint); //在当前地图上添加这个图像对象 myMap.graphics.add(gra); //删除这个图像 //myMap.graphics.remove(gra); }  

 

  • 通过编程new 对象方式
    var pt = new esri.geometry.Point(accidents[i].xcoord, accidents[i].ycoord, myMap.spatialReference); var infoTemplate = new esri.InfoTemplate(accidents[i].sgdd, accidents[i].dzzb); var attr = { "XCoord" : accidents[i].xcoord, "YCoord" : accidents[i].ycoord, "Plant" : "Mesa Mint" } var graphic = new esri.Graphic(pt, picSymbol, attr, infoTemplate); // 在当前地图上添加这个图像对象 myMap.graphics.add(graphic);

 

 

api参考

http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jsapi_start.htm#jsapi/map.htm#toMap

 

你可能感兴趣的:(编程,json,api,attributes)