3

I'm struggling to properly display my GeoJSON data which is being serialized from a GeoDjango model, though hopefully that isn't relevant to the issue at hand.

I copy and pasted a GeoJSON example from the OL4 docs and then tried to add in my own GeoJSON just to try to get it displaying properly but I have so far been unsuccessful.

Here's the broken jsfiddle to show my problem. Where am I going wrong here?

2

There are two issues in your code:

  1. The GeoJSON has an incorrect crs section. Just remove that.
  2. When reading the features, you have to configure {featureProjection: 'EPSG:3857'} for the readFeatures call, to make sure that features are transformed to the view projection.

Note that (2) only applies when you configure the source with features. When you configure it with a url and a format, the features will automatically be transformed to the view projection.

I have updated your JSFiddle: https://jsfiddle.net/oq911uoe/.

|improve this answer|||||
  • Ah thank you! That's interesting though, since the crs section is auto-generated by a Django core method. – TechnoConserve Dec 8 '17 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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