add: map clear on empty click

v0.5
rrr-marble 4 years ago
parent f4bda7a837
commit 514707512b

@ -29,8 +29,6 @@ export default {
}); });
const buildMap = () => { const buildMap = () => {
const initialState = { lng: 37.625, lat: 55.751, zoom: 5 };
map.value = markRaw(new maplibregl.Map({ map.value = markRaw(new maplibregl.Map({
container: mapContainer.value, // container id container: mapContainer.value, // container id
// DOCS: https://maplibre.org/maplibre-gl-js-docs/style-spec/ // DOCS: https://maplibre.org/maplibre-gl-js-docs/style-spec/
@ -39,7 +37,7 @@ export default {
sources: {}, sources: {},
layers: [] layers: []
}, },
center: [37.625, 55.751], // starting position [lng, lat] center: [80, 40], // starting position [lng, lat]
zoom: 2, // starting zoom zoom: 2, // starting zoom
maxZoom: 10 maxZoom: 10
})); }));
@ -143,6 +141,34 @@ export default {
context.emit('mapClick', currentFadr); context.emit('mapClick', currentFadr);
}); });
map.value.on('click', (e) => {
console.log(e);
console.log(currentFadr.fadr);
console.log(e.point)
const features = map.value.queryRenderedFeatures(e.point)
console.log(features)
if (!features.length) {
currentFadr["fadr"].forEach((oldFadr) => {
map.value.setFeatureState(
{
source: 'samples',
sourceLayer: 'public.geodata',
id: oldFadr
},
{ beenClicked: false }
);
})
currentFadr["fadr"].length = 0;
console.log("clear fadr");
}
console.log(currentFadr.fadr);
context.emit('mapClick', currentFadr);
});
}; };
const updateSamplesLayer = () => { const updateSamplesLayer = () => {
@ -162,11 +188,11 @@ export default {
'circle-color': [ 'circle-color': [
'case', 'case',
['boolean', ['feature-state', 'beenClicked'], false], ['boolean', ['feature-state', 'beenClicked'], false],
'#ffff00', '#fec44f',
'#1a9641' '#d95f0e'
], ],
'circle-opacity': 0.8, 'circle-opacity': 0.8,
'circle-radius': 16 'circle-radius': 8
}, },
filter: ["match", ["get", "internal_id"], props.idlist, true, false] filter: ["match", ["get", "internal_id"], props.idlist, true, false]
}); });

Loading…
Cancel
Save