[OpenLayers-Dev] Feature "select detection" implementation details needed

Tim Schaub noreply at geocartic.com
Wed Jun 6 13:20:25 EDT 2007


bkausbk wrote:
> 
> In my understanding we need to implement a kind of "hittest" which is able to
> detect if a given point is within polygon area. This must be called somewhere in
>    OnMouseOver Handler. The only thing I found was OpenLayer.Geometry.atPoint,
> but since it is calling OpenLayers.Bounds.containsLonLat whereby
> OpenLayer.Bounds only represents rectangular areas this method couldn't be
> responsible for this.
> 

Ok, if you are only talking about detecting the target of mouse events, 
this is well handled already (no need to implement anything new).

The select-feature.html example shows the use of the SelectFeature 
control.  The SelectFeature control can be configured to select a 
feature on "hover" (mousemove) or click.

The SelectFeature control uses the Feature handler.  The Feature handler 
  is responsible for registering for browser events (click, mousemove, 
mousedown, etc).  When these events are triggered, the Feature handler 
checks to see if a vector feature (of the correct type) was the target 
of the event.

The Feature handler uses the OpenLayers.Layer.Vector.getFeatureFromEvent 
method to determine if a feature was the target of a specific browser 
event.  This method is exposed at the layer level, but you don't need to 
worry about it if you are using the Feature handler, the SelectFeature 
control, or something else that uses either one of those.

All that means that the "hittest" that you describe is already 
implemented.  What is missing is a method to determine the nearest 
feature to an event (which would return a feature and the pixel distance 
that separates it from the event) or a method to return all features 
within a specified distance from an event (or pixel location).  Anyway, 
if you want to implement something new, take a hack at one of these.

> 
> What I want to do is extending OpenLayers by a function to detect:

Below, you describe a number of things that would require new geometry 
methods.
> 
> 1. If there are Geometry objects which are intersecting each other

This will require an OpenLayers.Geometry.intersect method which takes a 
geometry and returns the result of any intersection with the instance.

> 2. Which of the polygons are intersecting (overlaping) each other

This could be a method on OpenLayers.Layer.Vector that takes a feature 
and returns a list of features that intersect it (for which 
OpenLayers.Geometry.intersect is non-null).

> 3. Find intersection points of specified polygons

When polygons intersect, the result is one or more points, one or more 
lines, one or more polygons, any combination of the above, or nothing. 
The result of OpenLayers.Geometry.intersect will be a list of geometries.

Again, OpenLayers.Geometry.intersect doesn't exist.  If you are 
interested in working on this (or any of the methods that it will 
require), I'm interested in helping you organize the work.

Tim

> 
> 
> regards
> 
> Benjamin Kalytta
> 
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev




More information about the Dev mailing list