remove prev layes

parent ec886ca4
......@@ -94,7 +94,7 @@ OpenStreetMapsClass.prototype.addPolygon = function(coords)
polyCoords.push(ol.proj.fromLonLat([parseFloat(c[0]), parseFloat(c[1])], 'EPSG:3857', 'EPSG:4326'));
}
//todo: remove older features in map, if there is a feature
// remove previous layers
this.vectorLayer.getSource().clear();
// create feature
......
......@@ -89,10 +89,16 @@ function sidtMap(divID, lng, lat, z)
var self = this;
this.features = new ol.Collection();
this.interaction = new ol.interaction.Draw({features: this.features,type: "Polygon"});
this.tempFeature = null;
var style = new ol.style.Style({stroke: new ol.style.Stroke({color: 'rgba(0,0,100,0.8)', width: 2}),
fill: new ol.style.Fill({ color: 'rgba(0,100,200,0.5)'}) });
var style = new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0,0,100,0.8)',
width: 2
}),
fill: new ol.style.Fill({
color: 'rgba(0,100,200,0.5)'
})
});
this.map.on("moveend",function(e){self.onMapMove(e)});
this.map.on("pointerdrag",function(e){self.onDrag(e)});
......@@ -104,26 +110,21 @@ sidtMap.prototype = Object.create( OpenStreetMapsClass.prototype );
sidtMap.prototype.addInteraction = function()
{
var self = this;
this.interaction = new ol.interaction.Draw({
source:this.vectorLayer.getSource(),
features: this.features,
type: "Polygon"
});
this.interaction.on("drawend",function(e){
document.getElementById("id_polygon").value =e.feature.getGeometry().clone().transform( 'EPSG:3857', 'EPSG:4326').getCoordinates();
});
self.tempFeature=e.feature;
}
);
this.interaction.on("drawstart",function(e){
if(self.tempFeature!=null)
{
self.vectorLayer.getSource().removeFeature(self.tempFeature);
}
}
self.vectorLayer.getSource().clear();
});
);
this.map.addInteraction(this.interaction);
}
//------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment