[GIS] Projection transform in OpenLayers3

javascriptopenlayersproj4js

I am trying to transform a GeoJSON object of a certain transformation (EPSG:28992) into my current map coordinate system (EPSG:4326). I have been trying to do a couple of things but none seem to work. I am currently trying to use proj4.js. A minimal example of my script can be found here:

http://jsfiddle.net/TimLucas/k69ujyev/5/

I am trying to find a method how I can transform my GeoJSON (Layer2) layer into the projection used in my map, as defined per the styles it should show up as green points. It somehow seems to have worked for the other layer (Layer1, red points). I tried to follow the various examples on openlayers.org (which suggest to use proj4.js), but this does not work for some reason. Can you please help me with what I am doing wrong?

Edit: I forgot to mention, the other projection is one that OL supports by default, so the problem here is using external projection systems…

Edit2: Found out that ArcMAP does not export this coord system very well. Changed it to the correct coords by hand but still does not show up, any suggestions? And does anyone have any suggestions on the easiest way to convert ESRI JSON to GeoJSON?

Best Answer

There is nothing wrong with your GeoJSON. You just have to define the default projection and the destination projection in the source for on-the-fly projection. Also, there is no need to save the projection objects in variables, like ProjectionNL, you can use the EPSG code of any projection, after it has been defined by Proj4JS. Of course, you can change up 'EPSG:28992' with ProjectionNL, whichever makes more sense to you.

var Layer2 = new ol.layer.Vector({
    source: new ol.source.GeoJSON({
        object: '{"type":"FeatureCollection",[...]}',
        defaultProjection: 'EPSG:28992',
        projection: 'EPSG:3857'
    }),
    style: styleFunction2
});

The projection property always has to be the destination projection (map projection), while you need to define the source projection in the defaultProjection parameter.