I have a map that displays a KML vector layer with some markers. When you click on the marker, a popup window appears with information. I want to be able to automatically pop up an information window based on the parameter passed to the page. I think I need to do this using getFeaturesByAttribute () to find the name, however the array of functions always seems empty. (Although I can see the contents when I use FireBug)
What do I need to do to get the elements in an array?
The code:
function init()
{
var options = {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
units: "m",
};
map = new OpenLayers.Map('map', options);
var mapnik = new OpenLayers.Layer.OSM("OpenStreetMap");
var gmap = new OpenLayers.Layer.Google("Google", {sphericalMercator:true});
var gsat = new OpenLayers.Layer.Google(
"Google Satellite",
{type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22}
);
groups = new OpenLayers.Layer.Vector("Groups", {
projection: map.displayProjection,
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "http://maps.google.co.uk/maps/ms?msa=0&msid=210450558816094618535.0004bd79ceb30e9acb9da&output=kml",
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true
})
})
});
map.addLayers([mapnik, gmap, gsat, groups]);
select = new OpenLayers.Control.SelectFeature(groups);
groups.events.on({
"featureselected": onFeatureSelect,
"featureunselected": onFeatureUnselect
});
map.addControl(select);
select.activate();
map.addControl(new OpenLayers.Control.LayerSwitcher());
var center = new OpenLayers.LonLat(-2.58789,51.52283).transform(map.displayProjection, map.projection);
var zoom = 12
map.setCenter(center, zoom);
alert(groups.features.length);
}
source
share