+
@@ -26,6 +32,7 @@ import { MapService } from '@/Stores/map.service';
import BaseIcon from '@/Components/BaseIcon.vue';
import { mdiPlus, mdiMinus } from '@mdi/js';
+import { Map } from 'leaflet';
@Component({
name: 'zoom-control',
@@ -33,7 +40,7 @@ import { mdiPlus, mdiMinus } from '@mdi/js';
BaseIcon,
},
})
-export default class ZoomControlComponent extends Vue {
+export class ZoomControlComponent extends Vue {
mdiPlus = mdiPlus;
mdiMinus = mdiMinus;
@@ -46,16 +53,23 @@ export default class ZoomControlComponent extends Vue {
@Ref('inputMinus') inputMinus: HTMLButtonElement;
mapService = MapService();
- map;
+ map: Map | null = null;
+ isZoomInDisabled = false;
+ isZoomOutDisabled = false;
- // mounted() {
- // let map = (this.map = this.mapService.getMap(this.mapId));
- // map.on('zoomend zoomlevelschange', this.updateDisabled, this);
- // }
+ mounted() {
+ let map = (this.map = this.mapService.getMap(this.mapId));
+ if (map) {
+ map.on('zoomend zoomlevelschange', this.updateDisabled, this);
+ this.updateDisabled();
+ }
+ }
- // unmounted() {
- // this.map.off('zoomend zoomlevelschange');
- // }
+ unmounted() {
+ if (this.map) {
+ this.map.off('zoomend zoomlevelschange', this.updateDisabled, this);
+ }
+ }
public zoomIn() {
let map = this.mapService.getMap(this.mapId);
@@ -69,44 +83,266 @@ export default class ZoomControlComponent extends Vue {
public updateDisabled() {
let map = this.mapService.getMap(this.mapId);
- // let className = 'leaflet-disabled';
+ if (!map) return;
- this.inputPlus.disabled = false;
- this.inputPlus.setAttribute('aria-disabled', 'false');
+ this.isZoomInDisabled = map.getZoom() >= map.getMaxZoom();
+ this.isZoomOutDisabled = map.getZoom() <= map.getMinZoom();
- this.inputMinus.disabled = false;
- this.inputMinus.setAttribute('aria-disabled', 'false');
-
- if (map.getZoom() === map.getMinZoom()) {
- this.inputMinus.disabled = true;
- this.inputMinus.setAttribute('aria-disabled', 'true');
+ if (this.inputPlus) {
+ this.inputPlus.disabled = this.isZoomInDisabled;
+ this.inputPlus.setAttribute('aria-disabled', this.isZoomInDisabled.toString());
}
- if (map.getZoom() === map.getMaxZoom()) {
- this.inputPlus.disabled = true;
- this.inputPlus.setAttribute('aria-disabled', 'true');
+
+ if (this.inputMinus) {
+ this.inputMinus.disabled = this.isZoomOutDisabled;
+ this.inputMinus.setAttribute('aria-disabled', this.isZoomOutDisabled.toString());
}
}
}
+export default ZoomControlComponent;
-
diff --git a/resources/js/Pages/Map.vue b/resources/js/Pages/Map.vue
index 4c19625..9d599f1 100644
--- a/resources/js/Pages/Map.vue
+++ b/resources/js/Pages/Map.vue
@@ -1,40 +1,15 @@