Skip to content

Commit

Permalink
Honour layers.featuresCrs in Feature.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Oct 24, 2016
1 parent e2ef856 commit 8cd7f1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions web/client/components/map/openlayers/Feature.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ let Feature = React.createClass({
properties: React.PropTypes.object,
container: React.PropTypes.object, // TODO it must be a ol.layer.vector (maybe pass the source is more correct here?)
geometry: React.PropTypes.object, // TODO check for geojson format for geometry
msId: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.number])
msId: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.number]),
featuresCrs: React.PropTypes.string
},
getDefaultProps() {
return {
featuresCrs: "EPSG:4326"
};
},
componentDidMount() {
const format = new ol.format.GeoJSON();
const geometry = this.props.geometry && this.props.geometry.coordinates;

if (this.props.container && geometry) {
this._feature = format.readFeatures({type: this.props.type, properties: this.props.properties, geometry: this.props.geometry, id: this.props.msId});
this._feature.forEach((f) => f.getGeometry().transform('EPSG:4326', 'EPSG:3857')); // TODO support map reference system
this._feature.forEach((f) => f.getGeometry().transform(this.props.featuresCrs, 'EPSG:3857'));
this.props.container.getSource().addFeatures(this._feature);
}
},
Expand All @@ -36,7 +42,7 @@ let Feature = React.createClass({

if (newProps.container && geometry) {
this._feature = format.readFeatures({type: newProps.type, properties: newProps.properties, geometry: newProps.geometry, id: this.props.msId});
this._feature.forEach((f) => f.getGeometry().transform('EPSG:4326', 'EPSG:3857')); // TODO support map reference system
this._feature.forEach((f) => f.getGeometry().transform(newProps.featuresCrs, 'EPSG:3857'));
newProps.container.getSource().addFeatures(this._feature);
}
}
Expand Down
1 change: 1 addition & 0 deletions web/client/plugins/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const MapPlugin = React.createClass({
type={feature.type}
geometry={feature.geometry}
msId={feature.id}
featuresCrs={ layer.featuresCrs || 'EPSG:4326' }
// FEATURE STYLE OVERWRITE LAYER STYLE
style={ feature.style || layer.style || null }/>
);
Expand Down

0 comments on commit 8cd7f1b

Please sign in to comment.