Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在map of mapbox中单击标记时在地图外的div中显示数据?_Javascript_Mapbox_Mapbox Gl Js_Mapbox Gl_Mapbox Marker - Fatal编程技术网

Javascript 如何在map of mapbox中单击标记时在地图外的div中显示数据?

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

每当在地图上单击一个标记时,我都需要在地图外部的div中显示该标记的数据

我正在尝试使用HTMLDOM元素

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