Ticket #2484 (closed feature: invalid)

Opened 3 years ago

Last modified 3 years ago

Polygon drawn using Measure Control could not be selected

Reported by: cosmos003 Owned by: tschaub
Priority: major Milestone: 2.9 Release
Component: Control.Measure Version: 2.8
Keywords: measure Cc:
State:

Description

Currently, the Polygons drawn by the Measure Control to measure area could not be selected using the SelectFeature tool in order to get the coordinates of the polygon. As the polygons could not be selected, I also could not use the ModifyFeature tool on it. It will be very useful if the abovementioned features can be used on the Polygons drawn by Measure Control. A suggestion is to combine the measure tool with the DrawFeature tool for Polygon so that when one draws a normal Polygon, the area is also calculated and displayed. This Polygon can then be selected to get the coordinates and be modified also.

Attachments

testmeasure.zip Download (113.1 KB) - added by cosmos003 3 years ago.
test file for polygon measurement and selection

Change History

Changed 3 years ago by ahocevar

  • status changed from new to closed
  • resolution set to invalid

You need two configuration options to do exactly what you need:

Make the geometry stay on the layer:  http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/OpenLayers/Control/Measure-js.html#OpenLayers.Control.Measure.persist

Use your own instead of a temporary layer, so you can use SelectFeature/ModifyFeature on it:  http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/OpenLayers/Control/Measure-js.html#OpenLayers.Control.Measure.handlerOptions

handlerOptions: {layer: yourLayer}

Changed 3 years ago by cosmos003

test file for polygon measurement and selection

Changed 3 years ago by cosmos003

  • status changed from closed to reopened
  • resolution invalid deleted

Sorry, I have tried what you mentioned but I still couldn't get it working. Whenever I disabled the measure control and enabled the select feature control, the polygon would disappear. I have attached my test program and here is my code. Please advise. Thank you very much.

mpolygon: new OpenLayers.Control.Measure(

OpenLayers.Handler.Polygon, {

persist: true, handlerOptions: {

layerOptions: {styleMap: styleMap},

layer: aoi

}

}

)

Changed 3 years ago by ahocevar

  • status changed from reopened to closed
  • resolution set to invalid

@cosmos003: This is expected behavior. According to the APIdocs, the sketch geometry will be deleted when the control is deactivated. If you want to modify a measurement sketch, you have several options:

  • Do not deactivate the measure control (not recommended, but possible, because if you activate the SelectFeature control, events won't go through to the Measure control).
  • Go on without the persist option and your own layer, listen to the Measure control's measure event and clone the geometry that the event returns, adding it as a feature to your own layer.
  • use a DrawFeature control instead of Measure. You can always get the length of a geometry using feature.geometry.getLength(); or feature.geometry.getGeodesicLength();. This is what I would do.

Anyway, it does not seem that we need a new feature here, as there are several convenient ways to do what you need. Please leave this ticket closed and discuss this further on the users list, if required.

Changed 3 years ago by ahocevar

I just saw that you are drawing polygons. So you would use feature.geometry.getArea(); or feature.geometry.getGeodesicArea();. And you would call that in a handler for the DrawFeature control's "featureadded" event and the ModifyFeature control's "featuremodified" event.

Changed 3 years ago by cosmos003

Apologies for my poor proficiency in programming and thank you for your patience in answering my query. Can you provide some sample coding on how to access the featureadded and featuremodified event? I have some success in using the property of the DrawFeature (as shown below) but I do not know how to write the code in accessing the events of DrawFeature and ModifyFeature. Please advise.

var drawOptions = {

featureAdded: displayWKT

};

dpolygon: new OpenLayers.Control.DrawFeature(productaoi,

OpenLayers.Handler.Polygon, drawOptions)

Changed 3 years ago by ahocevar

Again, you should ask this on the users list.

Anyway, event names are all lowercase, so it is "featureadded", not "featureAdded".

Note: See TracTickets for help on using tickets.