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

216
Visualizações
Can't add a geoJson layer to my Open Layers map

Using Open Layers and leaflet-sidebar-v2, I've added the sidebar to my map, this works. However, I also need to add another layer to my map, this layer will outline each country. I have the coordinates stored in a 'borders.json' file. I'm attempting to use D3.json to to import the border coordinates and then L.geoJson to add the new layer to my map.

I'm currently getting the following error message:

Uncaught TypeError: t.getLayerStatesArray is not a function

Here is the relevant part of my code..

var map = new ol.Map({
  target: "map",
  layers: [
    new ol.layer.Tile({
      source: new ol.source.OSM(),
    }),
  ],
  view: new ol.View({
    center: ol.proj.transform([7, 51.2], "EPSG:4326", "EPSG:3857"),
    zoom: 3,
  }),
});

var sidebar = new ol.control.Sidebar({
  element: "sidebar",
  position: "left",
});
map.addControl(sidebar);

d3.json(("borders.json"), function (json){
    function style(feature) {
        return {
            fillColor: "transparent",
            weight: 1,
            opacity: 0.4,
            color: 'grey',
            fillOpacity: 0.3
        }
    }

    geojson = L.geoJson(json, {
      style: style,
    }).addTo(map);
})

I think I might be adding the geojson layer to my map incorrectly, but I can't figure out what is wrong. I've spent quite a bit of time playing with it, but no luck.

Any helps is appreciated.

Cheers, Beat

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It might be hard to tell what the problem is without knowing other possible relevant parts of your code. I'd start by checking that the contents of borders.json follows valid GeoJSON format.


This is likely unrelated to your question, but is there a reason that you've declared style as a function like function style(feature) { ... }?

It looks like the style attribute of L.geoJson accepts an object rather than a function.

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