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

208
Views
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 answers
Answer question

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 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!