Skip to content

Commit

Permalink
Some fixes to ol3 drawsupport replace command (#1755)
Browse files Browse the repository at this point in the history
* Some fixes to ol3 drawsupport replace command

* Fixes indentation
  • Loading branch information
mbarto authored Apr 20, 2017
1 parent 3583fc2 commit a484f44
Showing 1 changed file with 34 additions and 37 deletions.
71 changes: 34 additions & 37 deletions web/client/components/map/openlayers/DrawSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const DrawSupport = React.createClass({
render() {
return null;
},
addLayer: function(newProps) {
addLayer: function(newProps, addInteraction) {
var source;
var vector;
this.geojson = new ol.format.GeoJSON();
Expand Down Expand Up @@ -90,49 +90,46 @@ const DrawSupport = React.createClass({

this.props.map.addLayer(vector);

if (newProps.features && newProps.features > 0) {
for (let i = 0; i < newProps.features.length; i++) {
let feature = newProps.features[i];
if (!(feature instanceof Object)) {
feature = this.geojson.readFeature(newProps.feature);
}
this.drawSource = source;
this.drawLayer = vector;
if (addInteraction) {
this.addDrawInteraction(newProps);
}

source.addFeature(feature);
this.addFeatures(newProps.features || []);
},
addFeatures(features) {
features.forEach((geom) => {
let geometry;

switch (geom.type) {
case "Point": {
geometry = new ol.geom.Point(geom.coordinates); break;
}
case "LineString": {
geometry = new ol.geom.LineString(geom.coordinates); break;
}
case "Polygon": {
geometry = new ol.geom.Polygon(geom.coordinates); break;
}
default: {
geometry = geom.radius && geom.center ?
ol.geom.Polygon.fromCircle(new ol.geom.Circle([geom.center.x, geom.center.y], geom.radius), 100) : new ol.geom.Polygon(geom.coordinates);
}
}
}
const feature = new ol.Feature({
geometry
});

this.drawSource = source;
this.drawLayer = vector;
this.drawSource.addFeature(feature);
});
},
replaceFeatures: function(newProps) {
if (!this.drawLayer) {
this.addLayer(newProps);
this.addLayer(newProps, true);
} else {
newProps.features.map((geom) => {
let geometry;
this.drawSource.clear();

switch (geom.type) {
case "Point": {
geometry = new ol.geom.Point(geom.coordinates); break;
}
case "LineString": {
geometry = new ol.geom.LineString(geom.coordinates); break;
}
case "Polygon": {
geometry = new ol.geom.Polygon(geom.coordinates); break;
}
default: {
geometry = geom.radius && geom.center ?
ol.geom.Polygon.fromCircle(new ol.geom.Circle([geom.center.x, geom.center.y], geom.radius), 100) : new ol.geom.Polygon(geom.coordinates);
}
}
let feature = new ol.Feature({
geometry: geometry
});

this.drawSource.addFeature(feature);
});
this.drawSource.clear();
this.addFeatures(newProps.features || []);
}
},
addDrawInteraction: function(newProps) {
Expand Down

0 comments on commit a484f44

Please sign in to comment.