简体   繁体   English

如何使用来自 Supabase 数据库的坐标将标记添加到传单地图?

[英]How to add Markes to a Leaflet-map with coordinates from Supabase database?

I want to add some Markers from coordinates stored in a supabase database colomn.我想从存储在 supabase 数据库列中的坐标中添加一些标记。

Here is my vue code:这是我的vue代码:

<l-marker v-for="(marker, index) in markers" :key="index" ref="markersRef" :lat-lng="marker.position"></l-marker>

I'm script:我是脚本:

  export default {
   async created() {
    const { data: events, error } = await this.$supabase
     .from('events')
     .select('coordinates')
    this.markers = events
    this.loaded = true
    console.log(this.markers)
    
   },
  data: () => ({
   markers: [],
  }),
 }

If I output markes, the result is:如果我 output 标记,结果是:

[
   { "coordinates": "lat: 59.339025, lng: 18.065818" },
   { "coordinates": "lat: 59.923043, lng: 10.752839" }
] 

the error is: "latlng is Null"错误是:“latlng 为空”

Your problem is the Vue reactivity system itself.你的问题是 Vue 反应系统本身。

Vue can't recognize your new markers after fetching them.获取新标记后,Vue 无法识别它们。 You can read about it here in the Vue documentation .您可以在 Vue 文档中阅读有关它的信息

Just use Vue.set or .splice只需使用Vue.set.splice

// Vue.set
Vue.set(this.markes, indexOfItem, newValue)

// Array.prototype.splice
this.markes.splice(indexOfItem, 1, newValue)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM