Skip to content

Commit

Permalink
Add map props for disable zoom and drag
Browse files Browse the repository at this point in the history
  • Loading branch information
jlpereira committed Mar 27, 2023
1 parent 5a3b49c commit 724896a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
39 changes: 33 additions & 6 deletions src/components/Map/VMap.global.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ const props = defineProps({
default: false
},
dragging: {
type: Boolean,
default: false
},
zoomAnimate: {
type: Boolean,
default: false
Expand All @@ -52,6 +57,11 @@ const props = defineProps({
default: 18
},
disableZoom: {
type: Boolean,
default: false
},
center: {
type: Array,
default: () => [0, 0]
Expand Down Expand Up @@ -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
Expand All @@ -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',
Expand Down Expand Up @@ -204,7 +231,7 @@ onUnmounted(() => {
observeMap?.disconnect()
})
const setGeoJSON = (geojson) => {
function setGeoJSON(geojson) {
if (geojson) {
L.geoJSON(geojson, {
...geojsonDefaultOptions,
Expand Down
2 changes: 2 additions & 0 deletions src/modules/otus/components/Panel/PanelMap/PanelMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<VMap
ref="map"
class="h-96 max-h-96"
dragging
:zoom="zoom"
:geojson="geojson"
@geojson:ready="isLoading = false"
Expand All @@ -20,6 +21,7 @@
<OtuSearch
v-if="isOtuSearchVisible"
:otu="otu"
:shapes="geojson"
@close="() => (isOtuSearchVisible = false)"
/>
</div>
Expand Down
8 changes: 8 additions & 0 deletions src/modules/otus/components/Search/OtuSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -50,6 +53,11 @@ const props = defineProps({
otu: {
type: Array,
default: () => []
},
shapes: {
type: Object,
default: () => ({})
}
})
Expand Down

0 comments on commit 724896a

Please sign in to comment.