remove prev layes

parent ec886ca4
...@@ -94,7 +94,7 @@ OpenStreetMapsClass.prototype.addPolygon = function(coords) ...@@ -94,7 +94,7 @@ OpenStreetMapsClass.prototype.addPolygon = function(coords)
polyCoords.push(ol.proj.fromLonLat([parseFloat(c[0]), parseFloat(c[1])], 'EPSG:3857', 'EPSG:4326')); 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(); this.vectorLayer.getSource().clear();
// create feature // create feature
......
...@@ -89,10 +89,16 @@ function sidtMap(divID, lng, lat, z) ...@@ -89,10 +89,16 @@ function sidtMap(divID, lng, lat, z)
var self = this; var self = this;
this.features = new ol.Collection(); this.features = new ol.Collection();
this.interaction = new ol.interaction.Draw({features: this.features,type: "Polygon"}); 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}), var style = new ol.style.Style({
fill: new ol.style.Fill({ color: 'rgba(0,100,200,0.5)'}) }); 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("moveend",function(e){self.onMapMove(e)});
this.map.on("pointerdrag",function(e){self.onDrag(e)}); this.map.on("pointerdrag",function(e){self.onDrag(e)});
...@@ -104,27 +110,22 @@ sidtMap.prototype = Object.create( OpenStreetMapsClass.prototype ); ...@@ -104,27 +110,22 @@ sidtMap.prototype = Object.create( OpenStreetMapsClass.prototype );
sidtMap.prototype.addInteraction = function() sidtMap.prototype.addInteraction = function()
{ {
var self = this; var self = this;
this.interaction = new ol.interaction.Draw({
source:this.vectorLayer.getSource(),
features: this.features,
type: "Polygon"
}); this.interaction = new ol.interaction.Draw({
source:this.vectorLayer.getSource(),
features: this.features,
type: "Polygon"
});
this.interaction.on("drawend",function(e){ this.interaction.on("drawend",function(e){
document.getElementById("id_polygon").value =e.feature.getGeometry().clone().transform( 'EPSG:3857', 'EPSG:4326').getCoordinates(); 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){ this.interaction.on("drawstart",function(e){
if(self.tempFeature!=null) self.vectorLayer.getSource().clear();
{ });
self.vectorLayer.getSource().removeFeature(self.tempFeature);
}
}
); this.map.addInteraction(this.interaction);
this.map.addInteraction(this.interaction);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
sidtMap.prototype.onMousemove = function(e) sidtMap.prototype.onMousemove = function(e)
......
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