Adding markers to a Leaflet map using coordinates retrieved from a Supabase database - a step-by-step guide

I am looking to incorporate markers on a map using coordinates stored in a Supabase database column.

Below is my Vue code:

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

In the 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: [],
  }),
 }

When I output the markers, the result is:

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

The error message states: "latlng is Null"

Answer №1

The issue lies within the Vue reactivity system itself.

When fetching new markers, Vue is unable to recognize them. For more information, you can refer to the Vue documentation here.

To resolve this, simply utilize either Vue.set or .splice

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

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Selenium webdriver to assign a JSON object to a paragraph element

What is the correct way to insert a JSON object into a p tag inside an iframe? I attempted the following approach but it displayed the text "[object Object]" rather than the actual content of the object... This is my implemented code: var arrJSON = [ ...

Step-by-step guide on redirecting to a different page following a successful POST API call using Jquery

I have the code below in my JavaScript file. $scope.addLookupAction = function () { $("#importForm").attr("action", 'xyz.com'); success:function(response) { $log.info("Redirecting to lookup home page"); ...

Refreshing div with updated form/content using jQuery and AJAX

Is it possible to use jQuery/AJAX functions to replace a form (or any content) with another form when a button is clicked, without reloading the page? Essentially creating a multi-part form dynamically. Can I achieve this with the following code snippet? ...

Linked selection options for state, city, and postal code

I have set up a cascading dropdown list - State -> City -> Pincode . Instead of fetching data from the database, I am using JSON. The dropdown functions smoothly on the local server, but experiences slowness on the web server. Here is a snippet of ...

Tips for verifying the data passed to a Vue component

Creating a subclassed Vue component can be done in the following way: let myApp = new MyApp({ el: '#app', data: { message: 'Hello Vue!', seconds: 0 }, created() { setInterval(() => { ...

What is the best way to show distinct items and their frequencies from an array of objects in Vue.js/JavaScript?

I have been developing an inventory management application using Vuejs, and I am facing a JavaScript-related challenge in my project. The issue revolves around handling data that includes user information retrieved from a form, as well as static categories ...

What is the best way to iterate through an array and dynamically output the values?

I am facing an issue with a function that retrieves values from an array, and I wish to dynamically return these values. const AvailableUserRoles = [ { label: 'Administrator', value: 1 }, { label: 'Count', value: ...

Is it possible for my website to send an email without the need for a script to be executed?

Looking to include a contact page on my website, but struggling with limitations imposed due to hosting on a secure school server that restricts script execution. Wondering if there's a workaround that would allow for email sending on the client side ...

Steps for creating an HTML report using Intern JS

Our team relies on intern JS for automating functional tests, however we are facing difficulty in generating an html report. I attempted to use locvhtml as suggested by the Intern documentation (https://theintern.github.io/intern/#reporter-lcov), but unfo ...

What is the best way to establish a header in the login route that allows the browser to remember the user's login status?

I have successfully implemented a user login backend and everything seems to be working fine. However, when I try to access a user detail after logging in, I am faced with an authorization issue preventing me from exploring other routes. How can I store th ...

React is having trouble loading the page and is displaying the message "Please enable JavaScript to use this application."

Following a tutorial at https://learn.microsoft.com/en-us/learn/modules/build-web-api-minimal-spa/5-exercise-create-api Everything was going smoothly until I reached this step: Add the following proxy entry to package.json: "proxy": "http:/ ...

Adjustable progress bar length calculated from data retrieved through Vue2 getter and styled with SCSS

Does anyone know how to dynamically adjust the length of a progress bar in SCSS using @keyframes? I am trying to pull the value from getters (getTasksFulfilmentRate) and update the progress bar every time the value changes. My main concern is how to effici ...

Creating a nx workspace for vanilla JavaScript (Error: module 'typescript' not found) - Step-by-step guide

Looking to set up a new workspace for plain React applications. How can I do it? Create Workspace npx create-nx-workspace@latest # version 15.2.1 # style: package-based # distributed caching: NO Installing the react-package npm install -D @nrwl/react Cr ...

Developing an identical design and layout but utilizing a distinct domain name for the company

After being given the task of creating a website identical to an existing one with a different domain name on WordPress, I proposed using the parent HTML source code or cloning it to speed up the project. The client agreed, explaining that starting from sc ...

Choose the appropriate data type for the class variable (for example, fArr = Uint32Array)

const functionArray: Function = Uint32Array; new fArr(5); The code snippet above is functioning properly. However, TypeScript is throwing a TS2351 error: "This expression is not constructable. Type 'Function' has no construct signatures". I wo ...

What sets Fetch Promise apart in terms of delivery success?

Struggling with using strapi in my project, as the fetch function returns a promise instead of JSON data This is my code : const [products, setProducts] = useState([]); useEffect(() => { (async () => { try { l ...

implementing a dropzone feature in Vue using Laravel Mix for image uploads

Currently, I am working on a Single Page Application (SPA) using vue.js and Dropzone for uploading images. Despite having the correct path, the images are not appearing, and I'm unsure of the reason why! view image description here as seen in the scre ...

What methods are available for transferring information between nodejs and puppeteer?

Recently, I developed a nodejs application that kicks off from index.js. Within index.js, puppeteer is launched and bot.js is injected into a headless-api page using the addScriptTag function. In my implementation, index.js sets a cookie to pass initial v ...

Could someone provide a detailed explanation of exhaustMap in the context of Angular using rxjs?

import { HttpHandler, HttpInterceptor, HttpParams, HttpRequest, } from '@angular/common/http'; import { Injectable } from '@core/services/auth.service'; import { exhaustMap, take } from 'rxjs/operators'; import { Authe ...

Threejs file exporter from Blender generating corrupted files

My Blender model seems to be causing issues: After using the threejs exporter in Blender 2.7, the exported json file contains numerous null or 0 values: { "metadata": { "formatVersion" : 3.1, "generatedBy" : "Blender 2.7 Exporter", ...