Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
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 Respostas
Responde à pergunta

0

After replacing:

const wPolygon =  pFRAGMENT.coordinates;

with

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

it works.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda