发布网友 发布时间:2022-04-22 03:11
共2个回答
热心网友 时间:2023-05-13 17:26
直接设置给要素:var gra=new esri.Graphic(feature,symbol,attributes,infoTemplate);不用onclick,点击要素的时候就是弹出窗体。也可以设置给图层,点击这个图层的要素都会弹出。var featureLayer=new FeatureLayer(url,{infotemplate:myinfotemplate});
热心网友 时间:2023-05-13 17:26
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));