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));

 

转载于:https://www.cnblogs.com/dwf07223/archive/2013/04/17/3026922.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值