{"version":3,"file":"MapBoundsReceiver.vue.mjs","sources":["../../lib/map/MapBoundsReceiver.vue"],"sourcesContent":["<!-- MAP component that receives bounds -->\n\n<template>\n  <div :id=\"mapContainerId\" ref=\"mapref\" style=\"z-index:0\"></div>\n</template>\n\n<script>\n  import {\n    isNil,\n    isArray,\n    isString,\n    isNumber,\n  } from 'lodash';\n  import { mapActions, mapGetters } from 'vuex';\n  import Leaflet from 'leaflet';\n\n  export default {\n    name: 'MapBoundsReceiver',\n    data() {\n      return {\n        map: {},\n        useAnimation: this.$env.content.maps.useAnimation,\n        urlTemplate: this.$env.content.maps.urlTemplate,\n        options: this.$env.content.maps.options,\n        attributionPosition: this.$env.content.maps.receiver.attributionPosition,\n        bounds: this.startBounds,\n      };\n    },\n    props: {\n      startBounds: {\n        type: Array,\n      },\n      height: {\n        type: String,\n      },\n      width: {\n        type: String,\n      },\n      mapContainerId: {\n        type: String,\n      },\n      boundsId: {\n        required: true,\n      },\n    },\n    computed: {\n      ...mapGetters('geo', [\n        'getGeoBoundsById',\n      ]),\n      geoStateBoundsWatcher() {\n        return this.getGeoBoundsById(this.boundsId);\n      },\n    },\n    methods: {\n      ...mapActions('geo', [\n        'setGeoBoundsForId',\n        'setHoldedGeoBoundsForId',\n        'resetGeoBoundsForId',\n      ]),\n      isNil,\n      isArray,\n      isString,\n      isNumber,\n      initBounds() {\n        let isInvalid = true;\n        const bounds = this.$route.query.bounds;\n        if (!isNil(bounds) && isArray(bounds) && bounds.length === 2) {\n          if (isString(bounds[0]) && isString(bounds[1])) {\n            bounds[0] = bounds[0].split(',');\n            bounds[1] = bounds[1].split(',');\n          }\n          if ((isArray(bounds[0]) && bounds[0].length === 2)\n            && (isArray(bounds[1]) && bounds[1].length === 2)) {\n            if (isNumber(this.isFloat(bounds[0][0]))\n              && isNumber(this.isFloat(bounds[0][1]))\n              && isNumber(this.isFloat(bounds[1][0]))\n              && isNumber(this.isFloat(bounds[1][1]))) {\n              isInvalid = false;\n            }\n          }\n        }\n        if (isInvalid) {\n          // Remove bounds url query params if format is not valid\n          if (this.$route.query.bounds) {\n            this.bounds = undefined;\n            this.$router.replace({ query: Object.assign({}, this.$route.query, { bounds: this.bounds }) });\n          }\n        } else {\n          this.bounds = bounds;\n        }\n      },\n      initMap() {\n        // Init Map\n        const map = Leaflet.map(this.mapContainerId, {\n          editable: true,\n          attributionControl: false,\n        }).fitBounds(this.bounds);\n\n        Leaflet.control.attribution({\n          position: this.attributionPosition,\n        }).addTo(map);\n\n        // Get Tiles\n        Leaflet.tileLayer(this.urlTemplate, this.options).addTo(map);\n\n        this.$refs.mapref.style.height = this.height;\n        this.$refs.mapref.style.width = this.width;\n        map.invalidateSize();\n        map.setZoom(map.getBoundsZoom(this.bounds));\n        return map;\n      },\n      isFloat(value) {\n        if (/^(-|\\+)?([0-9]+(\\.[0-9]+)?|Infinity)$/.test(value)) return Number(value);\n        return NaN;\n      },\n      resetBounds() {\n        if (this.useAnimation) this.map.flyToBounds(this.bounds, this.map.getBoundsZoom(this.bounds));\n        else this.map.fitBounds(this.bounds, this.map.getBoundsZoom(this.bounds));\n      },\n    },\n    filters: {},\n    watch: {\n      height: {\n        handler(height) {\n          this.$refs.mapref.style.height = height;\n          this.map.invalidateSize();\n        },\n      },\n      width: {\n        handler(width) {\n          this.$refs.mapref.style.width = width;\n          this.map.invalidateSize();\n        },\n      },\n      geoStateBoundsWatcher: {\n        deep: true,\n        handler(bounds) {\n          if (!bounds) {\n            if (this.useAnimation) this.map.flyToBounds(this.bounds, this.map.getBoundsZoom(this.bounds));\n            else this.map.fitBounds(this.bounds, this.map.getBoundsZoom(this.bounds));\n          } else {\n            this.bounds = bounds;\n            const b1 = Leaflet.latLng(bounds[0][0], bounds[0][1]);\n            const b2 = Leaflet.latLng(bounds[1][0], bounds[1][1]);\n            const b = Leaflet.latLngBounds(b2, b1);\n            if (this.useAnimation) this.map.flyToBounds(b, this.map.getBoundsZoom(b));\n            else this.map.fitBounds(b, this.map.getBoundsZoom(b));\n          }\n        },\n      },\n    },\n    created() {\n      this.initBounds();\n    },\n    mounted() {\n      this.map = this.initMap();\n      this.map.on('resize', () => {\n        this.map.invalidateSize();\n        this.resetBounds();\n      });\n    },\n  };\n</script>\n\n<style lang=\"scss\" scoped>\n</style>\n<style lang=\"scss\">\n  @import '~leaflet/dist/leaflet.css';\n\n  .leaflet-zoom-anim .leaflet-zoom-animated {\n    will-change: unset !important;\n  }\n</style>\n"],"names":["_sfc_main","mapGetters","mapActions","isNil","isArray","isString","isNumber","isInvalid","bounds","map","Leaflet","value","height","width","b1","b2","b","_createElementBlock","$props"],"mappings":";;;;;;AAgBE,MAAKA,IAAU;AAAA,EACb,MAAM;AAAA,EACN,OAAO;AACL,WAAO;AAAA,MACL,KAAK,CAAE;AAAA,MACP,cAAc,KAAK,KAAK,QAAQ,KAAK;AAAA,MACrC,aAAa,KAAK,KAAK,QAAQ,KAAK;AAAA,MACpC,SAAS,KAAK,KAAK,QAAQ,KAAK;AAAA,MAChC,qBAAqB,KAAK,KAAK,QAAQ,KAAK,SAAS;AAAA,MACrD,QAAQ,KAAK;AAAA;EAEhB;AAAA,EACD,OAAO;AAAA,IACL,aAAa;AAAA,MACX,MAAM;AAAA,IACP;AAAA,IACD,QAAQ;AAAA,MACN,MAAM;AAAA,IACP;AAAA,IACD,OAAO;AAAA,MACL,MAAM;AAAA,IACP;AAAA,IACD,gBAAgB;AAAA,MACd,MAAM;AAAA,IACP;AAAA,IACD,UAAU;AAAA,MACR,UAAU;AAAA,IACX;AAAA,EACF;AAAA,EACD,UAAU;AAAA,IACR,GAAGC,EAAW,OAAO;AAAA,MACnB;AAAA,IACF,CAAC;AAAA,IACD,wBAAwB;AACtB,aAAO,KAAK,iBAAiB,KAAK,QAAQ;AAAA,IAC3C;AAAA,EACF;AAAA,EACD,SAAS;AAAA,IACP,GAAGC,EAAW,OAAO;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACD,OAAAC;AAAA,IACA,SAAAC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