I'm trying to add features from a GeoJSON response in openlayers3. Using the default loading method works great:
layer.setSource(new ol.source.Vector({url:url, format:new ol.format.GeoJSON()});
But I need error handling, So I use the response from a standard jquery loader like so:
var features = new ol.format.GeoJSON().readFeatures(response);
layer.setSource(new ol.source.Vector({features:features}));
All the features appear bunched on null island in a sort of a mini-map:
And a closer look reveals the features:
edit:Specifying the data/feature projection doesn't work either.
EDIT: I finally fixed it, Here's the code:
var reader = new ol.format.GeoJSON({
defaultDataProjection:'EPSG:3857',
Projection:'EPSG:3857'
});
layer.getSource().addFeatures(reader.readFeatures(res,{
dataProjection:'EPSG:4326',
featureProjection:'EPSG:3857'
}));
What an absolute nightmare that was.