[OpenLayers-Users] Is it possible to make the geometry persist event the measure control is cancdled?
maven apache
apachemaven0 at gmail.com
Sat Jun 1 22:23:00 PDT 2013
This is the core codes:
*
(function() {
function application() {
}
application.prototype = {
init : function() {
this.mmap = new OpenLayers.Map("map");
this.drawLayer = new OpenLayers.Layer.Vector("drawfeature", {
displayInLayerSwitcher : this.overlayDisplayInLayerSwitcher
});
var measureControls = {
distance : new
OpenLayers.Control.Measure(OpenLayers.Handler.Path, opts),
area : new
OpenLayers.Control.Measure(OpenLayers.Handler.Polygon, opts)
};
for ( var key in measureControls) {
var c = measureControls[key];
c.events.on({
"measure" : this.handleMeasurements,
"measurepartial" : this.handleMeasurements,
scope : this
});
map.addControl(c);
}
this.measureControls = measureControls;
// init the event handler
$(".maptool span").click(function() {
if ($(this).data("control")) {
var controlName = $(this).data("control");// distance or
// area
var control = that.measureControls[controlName];
if (control) {
control.activate();
}
}
});
},
handleMeasurements : function(event) {
var geometry = event.geometry;
var units = event.units;
var order = event.order;
var measure = event.measure;
var out = "";
if (order == 1) {
out += "measure: " + measure.toFixed(3) + " " + units;
} else {
out += "measure: " + measure.toFixed(3) + " " + units +
"<sup>2</" + "sup>";
}
if (this.measurePopup) {
this.mmap.removePopup(this.measurePopup);
} else {
var cps = geometry.getCentroid();
var pos = new OpenLayers.LonLat(cps.x, cps.y);
this.measurePopup = new OpenLayers.Popup("xx", pos, new
OpenLayers.Size(80, 20), out, true);
this.mmap.addPopup(this.measurePopup);
}
if (event.type == "measure") {
// the measurement is completed, then tried to clone the
geometry and add it to the darwlayer
this.drawLayer.addFeatures(geometry.clone());
*
* //deactivate the control, then use can drag-pan the map
normally
*
* event.object.deactivate();
}
}
}
var app = new application();
window.app = app.app;
})();
window.onload = function() {
window.app && window.app.init();
}*
2013/6/1 Vince Lotito <vince at vvl.com>
> Send code sample...
>
> Sent from my iPad
>
> On Jun 1, 2013, at 9:10 AM, "maven apache" <apachemaven0 at gmail.com> wrote:
>
> IN fact, I have tried that, but it does not work. I have
> created a vector layer, in the measure event, I get the geometry,
> clone it, add it to the layer using the addfeature method, but, it
> does not worked as expected.
>
> reply by my HTC phone, sorry for my spell.
>
> 在 2013年6月1日星期六,Vince Lotito <vince at vvl.com> 写道:
> >
> > In your measure control tap into the measure event, from there grab the
> geometry and clone it into a vector layer.... You'll also have to create a
> text label at the centroid with the actual measurement.
> >
> > Vince
> >
> >
> > Sent from my iPad
> >
> > On Jun 1, 2013, at 5:15 AM, "maven apache" <apachemaven0 at gmail.com>
> wrote:
> >
> >> Hi:
> >>
> >> I am using the Measure Control in OpenLayers.
> >>
> >> And I want to keep the geometry presisit in the map when one measure
> completed.
> >>
> >> I know there is a property named "persisit" to make the geomery visible
> after the measure completed, but once the cancel is called for the control
> or the deactivate of the handler is called, the geometry will disappeared.
> This is not what I want.
> >>
> >> So I wonder if my requirement is possible?
> >> _______________________________________________
> >> Users mailing list
> >> Users at lists.osgeo.org
> >> http://lists.osgeo.org/mailman/listinfo/openlayers-users
> >
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130602/c14af834/attachment.html>
More information about the Users
mailing list