如何解决从Mapbox的geojson文件中获取geojson数据以供标记
基本上,我正在向我的Mapbox地图添加标记,但我希望该过程是自动的。
我能够对数据库中的geojson文件进行编码,但仍然无法将该数据传递到mapbox标记中。
这是我的代码:
var Markersgeojson = {
type: 'FeatureCollection',features: [{
type: 'Feature',geometry: {
type: 'Point',coordinates: [35.5099,33.8962]
},properties: {
title: 'Gemmayze Holding',description: '#3'
}
},{
type: 'Feature',coordinates: [35.5107,33.8952]
},properties: {
title: 'Mar Mkhayel Residence',description: '#4'
}
}]
};
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 to the map
new mapboxgl.Marker(el)
.setLngLat(marker.geometry.coordinates)
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);
});
是否可以将变量Markersgeojson分配给我的geojson文件的数据?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。