Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
mapbox passing coordinates as variable does not work

It tried to implement the solution to draw a polygon from external data as shown in https://jsfiddle.net/zxaktouy/1/ but I get the error: Input data given to 'frag15' is not a valid GeoJSON object.

My JS-method:

    drawFragment : function(pFRAGMENT) {
        const wPolygon =  pFRAGMENT.coordinates;
        console.log("drawFragment: Coords="+wPolygon);
        wSourceId = "frag"+pFRAGMENT.id;
        wFillId = "fragfill"+pFRAGMENT.id;
        wOutlineId = "fragoutline"+pFRAGMENT.id;
        map.addSource(wSourceId,{
          'type': 'geojson',
          'data': {
            'type': 'Feature',
            'geometry': {
            'type': 'Polygon',
            'coordinates': [ 
wPolygon
 ]
               }
             }
        });
        // Add a new layer to visualize the polygon.
        map.addLayer({
          'id': wFillId,
          'type': 'fill',
          'source': wSourceId, // reference the data source
          'layout': {},
          'paint': {
            'fill-color': '#00ff80', // green color fill
            'fill-opacity': 0.5
          }
        });
        // Add a black outline around the polygon.
        map.addLayer({
          'id': wOutlineId,
          'type': 'line',
          'source': wSourceId,
          'layout': {},
          'paint': {
          'line-color': '#0d0',
          'line-width': 2
          }
        });
    },

And the data passed (perfectly shown via console.log) look like this:

[[8.543590974130666,47.377830192117756],
[8.543641551219707,47.37784384335191],
[8.543634914341965,47.37789513281288],
[8.543582309906242,47.37791046432616],
[8.543590974130666,47.377830192117756]]

when I replace the "wPolygon" just by copy-pasting the data into the code everything works fine.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

After replacing:

const wPolygon =  pFRAGMENT.coordinates;

with

var wPolygon = JSON.parse(pFRAGMENT.coordinates);

it works.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda