[OpenLayers-Users] ModifyControl Select/Delete Vertex?
Alexandre Dubé
adube at mapgears.com
Thu Feb 28 05:59:58 PST 2013
Sure, I'd be glad to help. What version do you use ?
Alexandre
On 13-02-27 12:36 PM, Robert Smart wrote:
> Hi,
>
> Thanks for a really in depth answer. It really explains it well.
>
> Unfortunately my javascript skills are pretty basic at the moment, so
> a lot of that went over my head!
>
> I like the sound of the vertexselection event on the vector layer
> class. Could you give me a few more hints about how this might work?
>
> Or even better give me an example bit of code :)
>
> We would need to be able to access the vertex index of the selected
> vertex, and i guess there would have to be a method of removing the
> vertex from the feature, which would trigger a redraw of the feature
> on the map.
>
> We would have to also be able to define a style for that selected
> vertex too, and i suppose add some error trap to ensure that we can't
> select a virtual vertex?
>
> Thanks again,
>
> Rob
>
>
>
> On 27 Feb 2013, at 13:51, "Alexandre Dubé" <adube at mapgears.com
> <mailto:adube at mapgears.com>> wrote:
>
>> Hi Rob,
>>
>> This would indeed be a nice feature to have. Looking at the
>> ModifyFeature control, I think this could be easily accomplished with
>> minor modifications.
>>
>> If we look at the ModifyFeature control, it creates a DragFeature
>> control to allow dragging the vertices around. When you "mouse
>> hover" a vertex feature, a callback function is triggered because it
>> was defined here :
>> https://github.com/openlayers/openlayers/blob/master/lib/OpenLayers/Control/ModifyFeature.js#L267
>>
>> That's the callbacks for the OpenLayers.Handler.Feature object the
>> drag control needs to interact with features on the map. The drag
>> control defines its callbacks method in the featureCallbacks object :
>> https://github.com/openlayers/openlayers/blob/master/lib/OpenLayers/Control/DragFeature.js#L119
>>
>> and here's the list of callbacks you can set to a feature handler:
>> click, clickout, over, out, and dblclick.
>> https://github.com/openlayers/openlayers/blob/master/lib/OpenLayers/Handler/Feature.js#L30
>>
>> So, back in the ModifyFeature control, you could add a 'click'
>> callback function just next to the 'over' one. Instead of coding what
>> you want it to do directly in the source, just define an abstract
>> function that needs to be overriden OR you could fire an new vector
>> layer event : vertexselected (which would need to be added to
>> OpenLayer.Layer.Vector).
>>
>> Whoa, sorry for the long reply :) In short, try to create a
>> delegate method or event we could register to to do whatever we
>> wanted on vertex selection.
>>
>> Does that make sense ?
>>
>> HTH,
>>
>> Alexandre
>>
>>
>> On 13-02-26 11:42 AM, Robert Smart wrote:
>>> Hi All,
>>>
>>> I'm trying to port some existing functionality into open layers and
>>> have
>>> managed to get most of it working. I'm just stuck on a seemingly simple
>>> task.
>>>
>>> The current code allows a user to highlight a polygon vertex by
>>> clicking on
>>> it (which changes its colour), so that the user can then press a delete
>>> button to remove the vertex.
>>>
>>> Using the modify control I'm able to display the vertices, and even
>>> delete
>>> them if I click on it and then press 'del' on my keyboard, but this
>>> is not a
>>> great solution as there is no visual clue as to what vertex has been
>>> selected.
>>>
>>> So is there a way to highlight or change the colour of a single
>>> vertex the
>>> user has clicked on? is there then a way to remove that vertex via
>>> code and
>>> have the polygon redraw on the screen to suit?
>>>
>>> I think this would actually be quite useful as a standard feature as
>>> there
>>> are many cases where one might want to select an individual vertex.
>>>
>>> Thanks,
>>>
>>> Rob
>>>
>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>>
>>
>> --
>> Alexandre Dubé
>> Mapgears
>> www.mapgears.com
>> _______________________________________________
>> Users mailing list
>> Users at lists.osgeo.org <mailto:Users at lists.osgeo.org>
>> http://lists.osgeo.org/mailman/listinfo/openlayers-users
--
Alexandre Dubé
Mapgears
www.mapgears.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130228/955920e1/attachment.html>
More information about the Users
mailing list