Hi, Just remove the line
OpenLayers.Event.stop(e); for all but the 1st layer. Regards, Andreas. cgp wrote: > I have about 10 or more WMS layers that I'm adding to the map. I'm using > GetFeatureInfo to get values for each layer. So I have 10 of these: > ------------------------------------------------------------------------------ > map.events.register('click', map, function (e) { > if (map.layers[layer_index].visibility==true) { > var params = { REQUEST: "GetFeatureInfo", > EXCEPTIONS: > "application/vnd.ogc.se_xml", > BBOX: map.getExtent().toBBOX(), > X: e.xy.x, > Y: e.xy.y, > INFO_FORMAT: 'text/html', > QUERY_LAYERS: > map.layers[layer_index].params.LAYERS, > FEATURE_COUNT: 50, > Styles: '', > Layers: layer_name, > srs: 'EPSG:900913', > WIDTH: map.size.w, > HEIGHT: map.size.h, > format: 'image/png' }; > event = e; > OpenLayers.loadURL("http://app-serv-01-uat/geoserver/wms", > params, this, > setHTML, setHTML); > } > OpenLayers.Event.stop(e); > }); > ------------------------------------------------------------------------------ > > And since I have 10 of those for each of the 10 different layers, my code is > getting too long, messy and unmanageable. I tried to refactor it by creating > a for loop: > > ------------------------------------------------------------------------------ > var layers_names = new > Array('sde:forests','sde:lakes','sde:trails,'sde:boundary','sde:buffallo','sde:fish','sde:birds','sde:picnic_sites','sde:rivers','sde:camping'); > var layer_indices = new Array(5,6,7,8,9,10,11,12,13,14); > > var layer_name; > var layer_index; > > for (var i=0; i<layers_names.length; i++) { > layer_name = layers_names[i]; > layer_index = layer_indices[i]; > > alert(layer_name+" "+layer_index); > > map.events.register('click', map, function (e) { > if (map.layers[layer_index].visibility==true) { > var params = { REQUEST: "GetFeatureInfo", > EXCEPTIONS: > "application/vnd.ogc.se_xml", > BBOX: map.getExtent().toBBOX(), > X: e.xy.x, > Y: e.xy.y, > INFO_FORMAT: 'text/html', > QUERY_LAYERS: > map.layers[layer_index].params.LAYERS, > FEATURE_COUNT: 50, > Styles: '', > Layers: layer_name, > srs: 'EPSG:900913', > WIDTH: map.size.w, > HEIGHT: map.size.h, > format: 'image/png' }; > event = e; > > OpenLayers.loadURL("http://app-serv-01-uat/geoserver/wms", params, this, > setHTML, setHTML); > } > OpenLayers.Event.stop(e); > }); > } > ------------------------------------------------------------------------------ > > My problem with this is that the click event sticks to the last array value > only. In this example, the GetFeatureInfo will only be fired on layer 12, > 'sde:camping'. For the rest of the previous layers, it won't fire at all. I > might be missing something, so can someone help me out? Thank you very much. > -- Andreas Hocevar OpenGeo - http://opengeo.org/ Expert service straight from the developers. _______________________________________________ Users mailing list Users@openlayers.org http://openlayers.org/mailman/listinfo/users