我完全不知道这一点,提前感谢任何建议!
Here's a link to the map I'm working on。所有功能都正常工作,但我想添加两件事:
为每个功能创建按钮列表
让每个按钮触发以下点击功能到它的相应功能:
map.on('click', function(e) {
var features = map.queryRenderedFeatures(e.point, { layers: ['macgregor'] });
map.flyTo({center: [0, 0], zoom: 2});
map.setLayoutProperty('selectedarea', 'visibility', 'none');
// map.setLayoutProperty('selectedRoad2', 'visibility', 'none');
if (!features.length) {
return;
}
if (typeof map.getLayer('selectedarea') !== "undefined" ){
map.removeLayer('selectedarea');
map.removeSource('selectedarea');
// map.setFilter('MacGregor65_Data_Fills') ;
}
if (features.length) {
var clickedFeature = features[0].geometry;
var lonLatArr = splitLatLon(clickedFeature);
var featureBounds = featureBoundaries(lonLatArr[0], lonLatArr[1]);
map.fitBounds(featureBounds, {padding: 200});
}
var feature = features[0];
// alert(features.length);
//I think you could add the vector tile feature to the map, but I'm more familiar with JSON
console.log(feature.toJSON());
map.addSource('selectedarea', {
"type":"geojson",
"data": feature.toJSON()
});
map.addLayer({
"id": "selectedarea",
"type": "fill",
"source": "selectedarea",
"layout": {
},
"paint": {
"fill-color": "yellow",
"fill-opacity": .2
// "fill-width": 8
}
});
});