[OpenLayers-Users] Query only in visible layers
Alexandre Dube
adube at mapgears.com
Tue May 5 11:27:22 EDT 2009
Are you using firebug ? If not, you should. It's a great javascript
tool. Put breakpoints where needed and you'll see the functions and
object properties available for what you need.
Since you're starting with OpenLayers, you should try to make the
query work for one layer only ( do no loop in the map layers yet ).
It could looks like this :
if(!event)
return;
if(!layer.getVisibility() || !layer.inRange)
return;
// carry on with your query
Regards,
Alexandre
Ivan Carreira wrote:
> Thanks for the help. I am starting to use openlayers and I do not know
> much about this.
> The idea is:
> -Deactivating a layer in the legend, make the query, and not display
> the popup
> -Activating a layer in the legend, make the query, and not display the
> popup
>
> Being tested with the following:
>
> var showInfo = function(event) {
> var layers = map.layers;
>
> if(event)
> {
> for (var i = 0; i < layers.length; i++) {
>
> if (!layers[i].getVisibility())
>
> {
>
>
> but I do not know how to continue.
>
> Regards,
>
> Iván
>
>
>
>
>
> >
> > Hi,
> >
> > Do you mean visible OpenLayers layers or server side-layers ? Do you
> > use (1) one OL layer per server-side layer or (2) are they all in the
> > same OL layer ?
> >
> > If (1) : loop through your map layers for each visible/inRange layer
> > to get their params.['LAYERS'] property. If they come from the same
> > server, you can merge them in a single request.
> >
> > If (2) : If you use MapServer and you have direct access to the
> > mapfile, you could do the following. Please, anyone correct me if I'm
> > wrong, but I think getfeatureinfo requests are made regardless of a
> > layer's minscaledenom or maxscaledenom property. So you could create a
> > template with leg_layer_minscale and leg_layer_maxscale values to get
> > theses values from the server-side into a javascript array. Also, add
> > the layer name at the same time (because that's the value to be
> added to
> > the query_layers query property). Then, on click, you could loop
> through
> > this array to check that the layers are currently visible (compare with
> > current scale). See that (3) link for more details. Does that make
> sense ?
> >
> > (3) http://mapserver.org/output/html_legend.html
> >
> > Regards,
> >
> > Alexandre
> >
> > Ivan Carreira wrote:
> > > Hi all,
> > >
> > >
> > >
> > > I have a problem.
> > >
> > > I need an expression to limit queries only to the layers that are
> visible at that time on the map.
> > > Queries are displayed via a popup.
> > > The code where queries are made and displayed in the popup is as
> follows:
> > >
> > > var showInfo = function(event) {
> > >
> > > var pixel = event.xy;
> > > var lonlat = this.getLonLatFromPixel(pixel);
> > > var message = null;
> > > var params = {};
> > > params['service'] = 'wms';
> > > params['request'] = 'GetFeatureInfo';
> > > params['version'] = '1.1.1';
> > > params['info_format'] = 'text/plain';
> > > params['srs'] = this.getProjection();
> > > params['bbox'] = this.getExtent().toBBOX(6);
> > > params['width'] = this.getSize().w;
> > > params['height'] = this.getSize().h;
> > > params['feature_count'] = 1;
> > > params['x'] = pixel.x; .
> > > params['y'] = pixel.y;
> > > params['layers'] = 'camino';
> > > params['query_layers'] = 'camino';
> > >
> > > new OpenLayers.Request.GET({
> > > url: server,
> > > async: false,
> > > params: params,
> > > success: function(data) {
> > > message = data.responseText;
> > > }
> > > });
> > >
> > >
> > >
> > > message = getHTML(message);
> > >
> > >
> > > var popup = new OpenLayers.Popup.FramedCloud('popup', lonlat,
> null, message, null, true, null);
> > >
> > > this.addPopup(popup);
> > >
> > > };//End of function showInfo()
> > >
> > > map.events.register('click', map, showInfo);
> > >
> > >
>
> >
>
> ------------------------------------------------------------------------
> Ahora, GRATIS Hotmail en tu móvil ¡Descúbrelo aquí!
> <http://serviciosmoviles.es.msn.com/hotmail.aspx>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
--
Alexandre Dubé
Mapgears
www.mapgears.com
More information about the Users
mailing list