6

When I import the vector it simply does not show in the map. I tried with a raster and it worked fine. I tried now with both KML and GeoJSON and the same thing happen, I can see that it loaded in the Chrome Dev Tool and I can also see the data from there, but not in the map. I using the Vector Layer and the Image Vector Layer as a base.

The projection is EPSG:31982, UTM 22 S - Sirgas 2000

I'm using OpenLayers v5.3

I tried some things that I found in examples online, but none seems to work. Other questions related that did not helped me:

Sample code I'm using:

proj4.defs('EPSG:31982', '+proj=utm +zone=22 +south +ellps=GRS80 +units=m +no_defs');
register(proj4);

var map = new Map({
  layers: [
    new TileLayer({
      source: new OSM()
    }),
    new VectorLayer({
      renderMode: 'image',
      source: new VectorSource({
        url: 'img/estradas.geojson',
        format: new GeoJSON(),
        projection: 'EPSG:31982'
      }),
      style: function(feature) {
        style.getText().setText(feature.get('name'));
        return style;
      }
    })
  ],
  target: 'map',
  view: new View({
    center: transform(getCenter(imageExtent), 'EPSG:31982', 'EPSG:3857'),
    zoom: 13
  })
});
3
  • Please set up a working jsfiddle that illustrates your problem. Commented Jan 21, 2019 at 12:33
  • projection isn't a valid option for VectorSource. If you geojson contains EPSG:31982 coordinates you should replace format: new GeoJSON(), projection: 'EPSG:31982' with format: new GeoJSON({dataProjection: 'EPSG:31982'})
    – Mike
    Commented Jan 21, 2019 at 12:45
  • Worked! Thank you very much. I looked lots of examples and any of them presented this method. The only thing that become different is the vector color, but I think I can change this with the style attribute. If you want to write the answer I can mark as correct :) Commented Jan 21, 2019 at 13:00

1 Answer 1

5

For vector layers the data projection should be specified in the format, not the source:

  source: new VectorSource({
    url: 'img/estradas.geojson',
    format: new GeoJSON({dataProjection: 'EPSG:31982'})
  }),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.