Javascript 如何在map of mapbox中单击标记时在地图外的div中显示数据?
每当在地图上单击一个标记时,我都需要在地图外部的div中显示该标记的数据 我正在尝试使用HTMLDOM元素Javascript 如何在map of mapbox中单击标记时在地图外的div中显示数据?,javascript,mapbox,mapbox-gl-js,mapbox-gl,mapbox-marker,Javascript,Mapbox,Mapbox Gl Js,Mapbox Gl,Mapbox Marker,每当在地图上单击一个标记时,我都需要在地图外部的div中显示该标记的数据 我正在尝试使用HTMLDOM元素 map.on('click', 'places', function (e) { var coordinates = e.features[0].geometry.coordinates.slice(); var title = e.features[0].properties.title; var descripti
map.on('click', 'places', function (e) {
var coordinates = e.features[0].geometry.coordinates.slice();
var title = e.features[0].properties.title;
var description = e.features[0].properties.description;
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
var content = '<div><strong>' + feature.properties.title + '</strong>' +
'<p>' + feature.properties.description + '</p></div>';
info.innerHTML = content;
});
map.on('click','places',函数(e){
var coordinates=e.features[0]。geometry.coordinates.slice();
var title=e.features[0]。properties.title;
var description=e.features[0]。properties.description;
而(数学abs(e.lngLat.lng-坐标[0])>180){
坐标[0]+=e.lngLat.lng>坐标[0]?360:-360;
}
var content=''+feature.properties.title+''+
“”+feature.properties.description+””;
info.innerHTML=内容;
});
这是我需要在表中显示信息的地方
<div class="info" id="info" style="color: whitesmoke">
</div>
这是地图组
<div id="map">
</div>
替换此行:
info.innerHTML=内容代码>
这一行:
document.getElementById('info')。innerHTML=content代码>