Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
Recibiendo el error 'Rechazo de promesa no manejado'

Recibo este error al crear una línea de seguimiento en vivo en mi mapa de MapBox.

Tengo que usar la misma API en otro lugar de este archivo. Supongo que ese es el problema ... ¿Hay alguna manera de resolver esto?

Error -

 Error: There is already a source with this ID at i.addSource (mapbox-gl.js?e192:33) at r.addSource (mapbox-gl.js?e192:33) at VueComponent._callee5$ (Dashboard.vue?98fa:142) at tryCatch (runtime.js?96cf:45) at Generator.invoke [as _invoke] (runtime.js?96cf:271) at Generator.prototype.<computed> [as next] (runtime.js?96cf:97) at asyncGeneratorStep (asyncToGenerator.js?3b8d:5) at _next (asyncToGenerator.js?3b8d:27)

llamada montada -

 mounted() { this.createMap(); window.setInterval(() => { this.getLocation() }, 500) },

Primera llamada a la API -

 async getLocation() { const res = await getLocations() this.center = [res.data[0].longitude,res.data[0].latitude]; // Reverse Geocoding using MapBox API axios.get(`https://api.mapbox.com/geocoding/v5/mapbox.places/${this.center}.json?access_token=${this.access_token}`) .then(async (response) => { this.loading = false; this.lat = response.data.query[1].toFixed(6); this.lng = response.data.query[0].toFixed(6); this.place_name = response.data.features[0].place_name; this.uncertainty_radius = res.data[0].uncertaintyRadiusInMeters; this.map.flyTo({center: [this.lng, this.lat], zoom: 16.5}); }); await this.mapMarker(); await this.targetTrackingLine() },

Esta es mi siguiente función de línea:

 async targetTrackingLine() { if (this.lng !== "0.000000" && this.lng !== "") { const response = await fetch( `https://api.mapbox.com/geocoding/v5/mapbox.places/${this.center}.json?access_token=${this.access_token}` ); const data = await response.json(); // save full coordinate list for later const coordinates = data.query; console.log(coordinates) // start by showing just the first coordinate data.query.coordinates = [coordinates[0]]; // add it to the map this.map.addSource('trace', {type: 'geojson', data: data}); this.map.addLayer({ 'id': 'trace', 'type': 'line', 'source': 'trace', 'paint': { 'line-color': '#000', 'line-width': 4 } }); // on a regular basis, add more coordinates from the saved list and update the map let i = 0; const timer = setInterval(() => { if (i < coordinates.length) { data.query.coordinates.push(coordinates[i]); this.map.getSource('trace').setData(data); i++; } else { window.clearInterval(timer); } }, 10); } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El siguiente código crea una nueva identificación para pasar a map.addSource cada vez que se llama a targetTrackingLine :

 let targetTrackingCalls = 0; async targetTrackingLine() { const sourceId = "trace" + ++targetTrackingCalls; // unique per call //... source lines this.map.addSource(sourceId, {type: 'geojson', data: data}); //... in timer callback; this.map.getSource(sourceId).setData(data); //... }

El uso de una identificación única debería evitar el error generado por addSource , suponiendo siempre data son un objeto geojason válido según la especificación de MapBox

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!