From 724896a6c2bdbb44b45e44e47232863a5f3a021e Mon Sep 17 00:00:00 2001 From: jlpereira Date: Mon, 27 Mar 2023 16:44:10 -0300 Subject: [PATCH] Add map props for disable zoom and drag --- src/components/Map/VMap.global.vue | 39 ++++++++++++++++--- .../components/Panel/PanelMap/PanelMap.vue | 2 + .../otus/components/Search/OtuSearch.vue | 8 ++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/components/Map/VMap.global.vue b/src/components/Map/VMap.global.vue index c7f75e4..e13b525 100644 --- a/src/components/Map/VMap.global.vue +++ b/src/components/Map/VMap.global.vue @@ -32,6 +32,11 @@ const props = defineProps({ default: false }, + dragging: { + type: Boolean, + default: false + }, + zoomAnimate: { type: Boolean, default: false @@ -52,6 +57,11 @@ const props = defineProps({ default: 18 }, + disableZoom: { + type: Boolean, + default: false + }, + center: { type: Array, default: () => [0, 0] @@ -110,14 +120,27 @@ watch( ) onMounted(() => { + const options = { + center: props.center, + zoom: props.zoom, + worldCopyJump: true, + dragging: props.dragging + } + + if (props.disableZoom) { + Object.assign(options, { + scrollWheelZoom: false, + zoomControl: false, + doubleClickZoom: false, + touchZoom: false, + boxZoom: false + }) + } + drawnItems = new L.FeatureGroup() geoJSONGroup = new L.FeatureGroup() - mapObject = L.map(leafletMap.value, { - center: props.center, - zoom: props.zoom, - worldCopyJump: true - }) + mapObject = L.map(leafletMap.value, options) mapObject.pm.setGlobalOptions({ layerGroup: drawnItems @@ -128,6 +151,10 @@ onMounted(() => { mapObject.addLayer(drawnItems) mapObject.addLayer(geoJSONGroup) + if (props.geojson) { + setGeoJSON(props.geojson) + } + if (props.controls) { mapObject.pm.addControls({ position: 'topleft', @@ -204,7 +231,7 @@ onUnmounted(() => { observeMap?.disconnect() }) -const setGeoJSON = (geojson) => { +function setGeoJSON(geojson) { if (geojson) { L.geoJSON(geojson, { ...geojsonDefaultOptions, diff --git a/src/modules/otus/components/Panel/PanelMap/PanelMap.vue b/src/modules/otus/components/Panel/PanelMap/PanelMap.vue index 4045082..3eecb53 100644 --- a/src/modules/otus/components/Panel/PanelMap/PanelMap.vue +++ b/src/modules/otus/components/Panel/PanelMap/PanelMap.vue @@ -5,6 +5,7 @@ diff --git a/src/modules/otus/components/Search/OtuSearch.vue b/src/modules/otus/components/Search/OtuSearch.vue index 96ca565..9a3b942 100644 --- a/src/modules/otus/components/Search/OtuSearch.vue +++ b/src/modules/otus/components/Search/OtuSearch.vue @@ -14,6 +14,9 @@ ref="mapRef" class="w-screen h-screen" controls + disable-zoom + :zoom-bounds="6" + :geojson="shapes" @draw:start="() => (geojson = {})" @add:layer=" ($event) => { @@ -50,6 +53,11 @@ const props = defineProps({ otu: { type: Array, default: () => [] + }, + + shapes: { + type: Object, + default: () => ({}) } })