gpt4 book ai didi

javascript - 如何在 map 框上显示单个功能弹出窗口

转载 作者:行者123 更新时间:2023-11-28 08:16:58 24 4
gpt4 key购买 nike

我有一张 map 并创建了一个如下所示的要素图层:

window.map = L.mapbox.map('map', 'example.wefk232sm')
.setView([homeLatitude, homeLongitude], initialZoom);

var myLayer = L.mapbox.featureLayer().addTo(map);

// Pass features to the map
myLayer.setGeoJSON(geoJson);

geoJson 对象如下所示:

var geoJson = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {
title: name,
other: "text",
'marker-color': '#54a743',
'stroke': '#428334',
url: link
},
geometry: {
type: 'Point',
coordinates: [longitude, latitude]
}
]
};

我想做的是打开与特定功能相关的弹出窗口,例如geoJson.features[0].properties对象上的name,但我不知道该怎么做。

我可以通过点击访问它:

myLayer.on('click', function(e) {
e.layer.openPopup();
});

Mapbox 版本为 v1.6.2

最佳答案

例如,您应该能够使用以下内容获取 properties.title

myLayer.on('click', function(e) {
var title = e.layer.feature.properties.title;
// do something with the title
});

关于javascript - 如何在 map 框上显示单个功能弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23475115/

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