diff --git a/web/client/components/map/openlayers/__tests__/Layer-test.jsx b/web/client/components/map/openlayers/__tests__/Layer-test.jsx index 092bb13d7e..1fb06f4a59 100644 --- a/web/client/components/map/openlayers/__tests__/Layer-test.jsx +++ b/web/client/components/map/openlayers/__tests__/Layer-test.jsx @@ -387,6 +387,44 @@ describe('Openlayers layer', () => { expect(map.getLayers().getLength()).toBe(1); }); + it('creates a vector layer specifying the feature CRS for openlayers map', () => { + var options = { + crs: 'EPSG:4326', + features: { + 'type': 'FeatureCollection', + 'crs': { + 'type': 'name', + 'properties': { + 'name': 'EPSG:4326' + } + }, + 'featureCrs': 'EPSG:3857', + 'features': [ + { + 'type': 'Feature', + 'geometry': { + 'type': 'Polygon', + 'coordinates': [[ + [1447153.3803125600, 5311971.8469454700], + [1669792.3618991000, 5311971.8469454700], + [1669792.3618991000, 5465442.1833227500], + [1447153.3803125600, 5465442.1833227500] + ]] + } + } + ] + } + }; + // create layers + var layer = ReactDOM.render( + , document.getElementById("container")); + + expect(layer).toExist(); + // count layers + expect(map.getLayers().getLength()).toBe(1); + }); + it('change layer visibility for Google Layer', () => { var google = { maps: { diff --git a/web/client/components/map/openlayers/plugins/VectorLayer.js b/web/client/components/map/openlayers/plugins/VectorLayer.js index 6e833856d5..ecbfadca1c 100644 --- a/web/client/components/map/openlayers/plugins/VectorLayer.js +++ b/web/client/components/map/openlayers/plugins/VectorLayer.js @@ -107,13 +107,17 @@ var styleFunction = function(feature) { Layers.registerType('vector', { create: (options) => { let features; + let featuresCrs = options.featuresCrs || 'EPSG:4326'; + let layerCrs = options.crs || 'EPSG:3857'; if (options.features) { let featureCollection = options.features; if (Array.isArray(options.features)) { featureCollection = { "type": "FeatureCollection", features: featureCollection}; } features = (new ol.format.GeoJSON()).readFeatures(featureCollection); - features.forEach((f) => f.getGeometry().transform('EPSG:4326', options.crs || 'EPSG:3857')); + if (featuresCrs !== layerCrs) { + features.forEach((f) => f.getGeometry().transform(featuresCrs, layerCrs)); + } } const source = new ol.source.Vector({