[OpenLayers-Users] Understanding layers and popups
Gene Sally
gsally at touchtown.us
Fri Jan 16 09:50:24 EST 2009
Hi,
I've been slogging through getting this to work (my map renders on the page now) and I'm having trouble getting my head around how layers and the click/hover callbacks work. The goal is to get a popup working on arbitrary points added to the map.
I have a map with an Image baselayer and a Vector layer where the features have been added, like so
var newPoint = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point());
var lonlat = map.getLonLatFromPixel(new OpenLayers.Pixel(x,y));
newPoint.geometry.x = lonlat.lon;
newPoint.geometry.y = lonlat.lat;
targetLayer.drawFeature(newPoint, OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {}));
So far so good! The points appear in the targetLayer as expected. (But, when I use the zoom control, they don't zoom with the map, but that's another day's problem...)
I added a OpenLayers.Control.SelectFeature
selectControl = new OpenLayers.Control.SelectFeature(
targetLayer,
{onSelect: onTargetSelect, onUnselect: onTargetUnselect});
selectControl.activate();
map.addControl(selectControl);
When click on a newPoint on the map, the reaction is like I'm selecting the baselayer. What I can't figure out is how to make the targetLayer the active layer, as from reading the mail logs, it appears like the SelectFeature works for the active layer. I've read/reread the sundials.html code (as that's close to the affect I want) and can't figure out what I'm doing wrong.
With Regards,
gene
More information about the Users
mailing list