Ticket #1904 (closed feature: fixed)

Opened 4 years ago

Last modified 4 years ago

add sketchcomplete and vertexmodified events to vector layers

Reported by: tschaub Owned by: crschmidt
Priority: minor Milestone: 2.8 Release
Component: Layer.Vector Version: 2.7
Keywords: Cc:
State: Complete

Description

The "featureadded" and "featuremodified" events are triggered on the vector layer any time a feature is added (by any means) or modified. It is useful to know when a new feature is drawn on a vector layer. The draw control has a "featureadded" event, but other components do not necessarily have a reference to the draw control. Adding a "sketchcomplete" event lets listeners know when something has drawn a new feature on the layer (and they can keep it from being added if they wish). In addition, the modify feature control lets listeners (of layer events) know when a modification is complete (a vertex is done being dragged). However, there is no notification as a vertex is being dragged. The "vertexmodified" event serves this purpose. It is triggered with each move of a vertex.

Attachments

sketch_events.patch Download (14.1 KB) - added by tschaub 4 years ago.
add sketch/modify related events to the vector layer
sketch_events.2.patch Download (14.1 KB) - added by ahocevar 4 years ago.
same as previous patch, but removed an IE killer comma

Change History

Changed 4 years ago by tschaub

This depends on #1903.

Changed 4 years ago by tschaub

What this patch does:

  1. In ModifyFeature.html, tests are added for the dragVertex method of the modify feature control (there were none before). The tests confirm that the modify feature control triggers the "vertexmodified" event on the layer while dragging simple points or vertices of a more complex geometry.
  1. In DrawFeature.html, tests are added to ensure that the control triggers the "sketchmodified" and "sketchcomplete" events on the destination layer.
  1. In DrawFeature.js, the handler is passed a named "modify" callback that triggers the "sketchmodified" event.
  1. In DrawFeature.js, the drawFeature method triggers the "sketchcomplete" event and only actually adds the new feature to the layer if none of the listeners return false.
  1. In ModifyFeature.js, the drag listener is sent the pixel location which is provided by the drag feature control but was not used here.
  1. In ModifyFeature.js, the dragFeature method triggers the "vertexmodified" event and passes along the pixel location of the drag (lest this be different than the translated vertex position).
  1. In ModifyFeature.js, all temporary features (vertices, virtual vertices, radius handle, origin handle) are given the _sketch property. None of these features should ever be persisted anywhere - and it would have been better design to use a temporary layer for them (but that is a different ticket). So that other components that might be examining features on this layer can know which are real and which are temporary, the _sketch property is provided. Note that this is not deleted because the affected features are never used as real features - they are destroyed by the control.
  1. In Vector.js, the "vertexmodified", "sketchmodified", and "sketchcomplete" events are added to the list of events.

Changed 4 years ago by tschaub

  • state set to Review

All tests pass (in FF3) and relevant examples work (with the patch for #1903 applied previously). Thanks for any review.

Changed 4 years ago by tschaub

add sketch/modify related events to the vector layer

Changed 4 years ago by ahocevar

same as previous patch, but removed an IE killer comma

Changed 4 years ago by ahocevar

  • state changed from Review to Commit

tests/Control/ModifyFeature.html contained a trailing object definition comma. I uploaded a new patch which fixes that. I ran relevant tests in IE7, and they also pass. Please commit.

Changed 4 years ago by tschaub

Thanks for the review - and the comma catch.

Changed 4 years ago by tschaub

  • status changed from new to closed
  • state changed from Commit to Complete
  • resolution set to fixed

(In [8835]) Adding vertexmodified, sketchmodified, and sketchcomplete events to the vector layer. These are triggered by the DrawFeature and ModifyFeature controls and let listeners know about newly drawn features and modified features. r=ahocevar (closes #1904)

Note: See TracTickets for help on using tickets.