Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating map view/marker with props #336

Open
fbnlsr opened this issue Jul 19, 2023 · 0 comments
Open

Updating map view/marker with props #336

fbnlsr opened this issue Jul 19, 2023 · 0 comments

Comments

@fbnlsr
Copy link

fbnlsr commented Jul 19, 2023

I'm trying to update a map that's inside a component using props. Here's the component:

<template>
  <l-map ref="myMap" style="height: 635px" :zoom="zoom" :center="coords" :options="coords">
    <l-tile-layer :url="url" :attribution="attribution"></l-tile-layer>
    <l-marker :lat-lng="coords"></l-marker>
  </l-map>
</template>

<script lang="ts">
  import { defineComponent } from 'vue'
  import 'leaflet/dist/leaflet.css'
  import { LMap, LTileLayer, LMarker } from '@vue-leaflet/vue-leaflet'

  export default defineComponent({
    name: 'LeafletMap',
    components: {
      LMap,
      LTileLayer,
      LMarker,
    },
    props: {
      coords: {
        type: Array,
        required: true,
      },
    },
    data() {
      return {
        url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
        attribution: '&copy; <a target="_blank" href="http://osm.org/copyright">OpenStreetMap</a> contributors',
        zoom: 15,
        options: { zoomControl: false, maxZoom: 14 },
      }
    },
  })
</script>

The component displays fine, but whenever I update the coords prop (using vue-router), I get an error saying Error: Attempted to load an infinite number of tiles

How could I update the map with the new set of coordinates without having this error thrown?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant