Skip to content Skip to sidebar Skip to footer

How To Specify The Projection For Geojson In Openlayers3?

My intention is to load GeoJSON data and display it on the map. Coordinates of the features specified in GeoJSON are normal lon/lat. For some reason openlayers is rendering them us

Solution 1:

Just use a featureProjection to read features like:

var vectorSource = new ol.source.Vector({
    features: new ol.format.GeoJSON().readFeatures(geojsonObject,{
        featureProjection: 'EPSG:3857'
    })
});

UPDATE: When reading features from url is even easier, OL makes the conversion internally for you:

var geojson_layer = new ol.layer.Vector({
    source: new ol.source.Vector({
        url: 'file.geojson',
        format: new ol.format.GeoJSON()
    })
});

Demo - http://plnkr.co/edit/GvdVNE?p=preview

Post a Comment for "How To Specify The Projection For Geojson In Openlayers3?"