2019-11-08 19:37:14 +01:00
|
|
|
<template>
|
2020-08-27 15:41:48 +02:00
|
|
|
<div style="display: none">
|
2020-02-18 08:57:00 +01:00
|
|
|
<slot v-if="ready"></slot>
|
|
|
|
</div>
|
2019-11-08 19:37:14 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
/**
|
2020-02-18 08:57:00 +01:00
|
|
|
* Fork of https://github.com/domoritz/leaflet-locatecontrol
|
|
|
|
* to try to trigger location manually (not done ATM)
|
2019-11-08 19:37:14 +01:00
|
|
|
*/
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
import L, { DomEvent } from "leaflet";
|
|
|
|
import { findRealParent, propsBinder } from "vue2-leaflet";
|
|
|
|
import "leaflet.locatecontrol";
|
|
|
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
2019-11-08 19:37:14 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
beforeDestroy() {
|
2020-02-18 08:57:00 +01:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
2019-12-03 11:29:51 +01:00
|
|
|
// @ts-ignore
|
2019-11-08 19:37:14 +01:00
|
|
|
this.parentContainer.removeLayer(this);
|
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class Vue2LeafletLocateControl extends Vue {
|
2020-02-18 08:57:00 +01:00
|
|
|
@Prop({ type: Object, default: () => ({}) }) options!: object;
|
|
|
|
|
2019-11-08 19:37:14 +01:00
|
|
|
@Prop({ type: Boolean, default: true }) visible = true;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
ready = false;
|
|
|
|
|
2019-11-08 19:37:14 +01:00
|
|
|
mapObject!: any;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-11-08 19:37:14 +01:00
|
|
|
parentContainer: any;
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
this.mapObject = L.control.locate(this.options);
|
|
|
|
DomEvent.on(this.mapObject, this.$listeners as any);
|
|
|
|
propsBinder(this, this.mapObject, this.$props);
|
|
|
|
this.ready = true;
|
|
|
|
this.parentContainer = findRealParent(this.$parent);
|
|
|
|
this.mapObject.addTo(this.parentContainer.mapObject, !this.visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
public locate() {
|
|
|
|
this.mapObject.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
2020-02-18 08:57:00 +01:00
|
|
|
@import "~leaflet.locatecontrol/dist/L.Control.Locate.css";
|
2019-11-08 19:37:14 +01:00
|
|
|
</style>
|