您好,以下是通过点击事件获取点位(图层)属性信息的示例:
function query() {
var sqlParam = new ol.supermap.GetFeaturesBySQLParameters({
queryParameter: {
name: "杭州亚运会场馆@hangzhou",
},
datasetNames: ["hangzhou:杭州亚运会场馆"],
toIndex: -1,
});
new ol.supermap.FeatureService(urldata).getFeaturesBySQL(sqlParam, function (serviceResult) {
var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(serviceResult.result.features),
wrapX: false
});
console.log(serviceResult.result.features);
var pointStyle = new ol.style.Style({
image: new ol.style.Circle({
radius: 8,
})
});
var resultLayer = new ol.layer.Vector({
source: vectorSource,
style: pointStyle
});
// map.addLayer(resultLayer);
var select = new ol.interaction.Select();
map.addInteraction(select);
select.on('select', function (e) {
if (e.selected.length > 0) {
var feature = e.selected[0];
var properties = feature.getProperties();
//设置显示的属性信息
content.innerHTML = '场馆名称: ' + properties.名称 + `<br/>` +
"比赛项目: " + properties.项目 + `<br/>` +
"场馆地址:" + properties.地址;
overlay.setPosition(feature.getGeometry().getCoordinates());
}
});
map.addOverlay(overlay);
});
}
query();
希望能够帮助到您!