ArcGIS JavaScript API 添加点

function ShowStationOnMap(stations) {
  // 清除图中的元素    
  map.graphics.clear();

  // 设置显示中心点及坐标
  var location = new esri.geometry.Point(stations[0].longtitude, stations[0].latitude, map.spatialReference)   map.centerAndZoom(location, 8); // 逐个添加元素 for (var s = 0; s < stations.length; s++) {     var symbol = new esri.symbol.PictureMarkerSymbol(stations[s].imageUrl, 18, 18);     var pt = new esri.geometry.Point(stations[s].longtitude, stations[s].latitude, map.spatialReference)     // 每个元素的属性值
    var attr = { "stationName": stations[s].stationName, "sId": stations[s].sId, "countryName": stations[s].countryName, "projectName": stations[s].projectName,      "buildYear": stations[s].buildYear };     // 点击该元素时的信息窗     var infoTemplate = new esri.InfoTemplate("${stationName}", "站点编号: ${sId}<br/>所属项目: ${projectName} <br/>所属区县: ${countryName}       <br/>建成年份:${buildYear}<div><a href='javascript:ShowDetailStationPanel(" + stations[s].sId + ")'>查看详情</a> </div>");     var graphic = new esri.Graphic(pt, symbol, attr, infoTemplate);
    map.graphics.add(graphic); } }

 

当在外部点击一个点时在地图上显示该数据的信息窗 这里用的是 map.infoWindow 和 infoTemplate 有点区别

var pt = new esri.geometry.Point(data.record.longtitude, data.record.latitude, map.spatialReference)        
var attr = { "stationName": data.record.stationName, "sId": data.record.sId, "countryName": data.record.countryName, "projectName": data.record.projectName,
   "buildYear": data.record.buildYear };
var infoTemplate = new esri.InfoTemplate("${stationName}", "站点编号: ${sId}<br/>所属项目: ${projectName}  <br/>所属区县: ${projectName} <br/>建成年份:
   ${buildYear}<div><a href='javascript:ShowDetailStationPanel(" + data.record.sId + ")'>查看详情</a> </div>");        
var symbol = new esri.symbol.PictureMarkerSymbol(data.record.imageUrl, 18, 18);        
var graphic = new esri.Graphic(pt, symbol, attr, infoTemplate);        
map.infoWindow.setContent(graphic.getContent()); 
map.infoWindow.setTitle(data.record.stationName);        
map.infoWindow.show(pt, map.getInfoWindowAnchor(pt));

 

posted @ 2013-04-17 19:54  沉默的猿  阅读(1867)  评论(0编辑  收藏  举报
AmazingCounters.com
给我写信