Skip to content

Commit

Permalink
fix(olHelper): multiple projection support for GeoJSON layers
Browse files Browse the repository at this point in the history
Ensure dataProjection is set when reading GeoJSON features to support projection conversion properly
  • Loading branch information
csnyders committed Jan 29, 2016
1 parent 15f86a5 commit ddeba1f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/services/olHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ angular.module('openlayers-directive').factory('olHelpers', function($q, $log, $
}

var features = geojsonFormat.readFeatures(
source.geojson.object, { featureProjection: projectionToUse });
source.geojson.object, {
featureProjection: projectionToUse,
dataProjection: projectionToUse
});

oSource.addFeatures(features);
}
Expand Down
36 changes: 36 additions & 0 deletions test/unit/layersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,42 @@ describe('Directive: openlayers layers', function() {
expect(geoJsonLayer.getSource().getFeatures().length).not.toBe(0);
});

it('should properly render a GeoJSON layer containing the GeoJSON object with different projections', function() {
scope.geoJsonLayer = {
source: {
type: 'GeoJSON',
geojson: {
object: {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [434179, 122450] // Southampton (UK) in EPSG:27700
}
},
projection: 'EPSG:27700'
}
}
};

var element = angular.element('<openlayers>' +
'<ol-layer ol-layer-properties="geoJsonLayer"></ol-layer>' +
'</openlayers>');
element = $compile(element)(scope);

var layers;
olData.getMap().then(function(olMap) {
layers = olMap.getLayers();
});

scope.$digest();
expect(layers.item(0).getSource() instanceof ol.source.OSM).toBe(true);
expect(layers.getLength()).toBe(2);

var geoJsonLayer = layers.item(1);
expect(geoJsonLayer.getSource() instanceof ol.source.Vector).toBe(true);
expect(geoJsonLayer.getSource().getFeatures().length).not.toBe(0);
});

it('should have one layer if custom-layers is used', function() {
scope.mapbox = {
source: {
Expand Down

0 comments on commit ddeba1f

Please sign in to comment.