gpt4 book ai didi

javascript - 始终显示弹出窗口 map 框

转载 作者:行者123 更新时间:2023-12-02 09:34:19 24 4
gpt4 key购买 nike

我一直在关注本教程 https://docs.mapbox.com/help/tutorials/custom-markers-gl-js/

我的标记显示正常,我可以单击标记来显示弹出窗口,但我希望始终显示弹出窗口。

我已成功修改 CSS,使其不显示箭头和“x/关闭”按钮。

var geojson = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-77.032, 38.913]
},
"properties": {
"title": "Mapbox",
"description": "Washington, D.C."
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-122.414, 37.776]
},
"properties": {
"title": "Mapbox",
"description": "San Francisco, California"
}
}]
};

var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v10',
center: [-96, 37.8],
zoom: 3
});

// add markers to map
geojson.features.forEach(function(marker) {

// create a HTML element for each feature
var el = document.createElement('div');
el.className = 'marker';

// make a marker for each feature and add it to the map
new mapboxgl.Marker(el)
.setLngLat(marker.geometry.coordinates)
.setPopup(new mapboxgl.Popup({offset: 25}) // add popups
.setHTML('<h3>' + marker.properties.title + '</h3><p>' + marker.properties.description + '</p>'))
.addTo(map);
});

有什么想法吗?

最佳答案

I've successfully modified the CSS to not show the arrow and "x / close" button

要隐藏“x”按钮,您还可以使用 closeButton 选项(请参阅 API reference )。

but I would like the popups to always be shown.

使用togglePopup()其中“根据当前状态打开或关闭绑定(bind)的弹出窗口”:

new mapboxgl.Marker(el)
.setLngLat(marker.geometry.coordinates)
.setPopup(new mapboxgl.Popup({closeOnClick: false, closeButton: false}).setText("some text"))
.addTo(map)
.togglePopup();

关于javascript - 始终显示弹出窗口 map 框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56187528/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com