[OpenLayers-Users] identifying map regions/features on the client side

Christopher Schmidt crschmidt at metacarta.com
Fri Apr 11 11:16:56 EDT 2008


On Fri, Apr 11, 2008 at 04:09:35PM +0100, Graham Carlyle wrote:
> So I'm thinking a new layer type might provide this which would use much
> the same info as a vector layer uses (GML, KML etc.) but instead of
> rendering this vector info it would provide methods to identify the
> feature at an x,y location.

You don't even need a layer.

1. When your application loads, load your country data into the client,
   using Format.GML, Format.GeoJSON, etc. Even in relatively slow browsers,
   this is probably only a few seconds of time.

2. When a user hovers, do a:
 
  var selectedCountry = null;  
  var g = new OpenLayers.Geometry.Point(x, y);
  for (var i=0; i < myFeatureList.length; i++) {
     if (myFeatureList[i].geometry.intersects(g)) {
        selectedCountry = myFeatureList[i].attributes.country_code;
     }
  }

Then display your information.  

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list