New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
viewparams missing for getFeatureInfo WMS request #1404
Comments
IMHO this should be up to the application to manage through the use of vendorParams: |
Add viewparams to list of params when building url for getFeatureInfo. This enables requesting getFeatureInfo for WMS layers that are from the database - defined as sql-view layers in geoserver.
Is there not a better way of adding custom properties? If vendorParams isnt an obscure and hidden variable enough - you get code like this when creating a WMS layer: https://gist.github.com/emoen/febc90cb67f3b2a0e7bb Would it not be better to add any parameter to the url - openlayers can provide an error-message based on vendor specific parameters anyway. So then the programmer/user is responsible for adding the correct vendor specific parameters. |
unfortunately there are servers out there that break with extra params that they don't know of |
but is it still not the user/programmers responsibility to format urls that will be parsed by the servers? |
If you define a WMS layer: var felayer = new OpenLayers.Layer.WMS( 'layer name', WMS_SERVER_URL, { layers: "measurements_last_30_days", transparent: true, styles: style, viewparams : 'type:BA' }, { isBaseLayer: false } ); Then all the parameters are automagically added to getMap requests (also viewparams), but viewparams is not added to getFeatureInfo requests. This is strange as they are both part of the WMS specification. You have to add gxp.plugins.WMSGetFeatureInfo.prototype.layerParams = ["viewparams"];to also have that parameter added to getFeatureInfo requests. Which means defining viewparams twice. Why cant viewparams be added to getFeatuerInfo in the same way it is added to getMap requests? |
…fo.layerParams to have it included in getFeatureInfo reqeusts See openlayers ticket: openlayers/openlayers#1404
Hei everybody! Just found this thread. :-) I have the same problem. I have several layers which result in SQL queries to geoserver. The only difference is a 'viewparams' parameter. When displaying the layer the viewparams are added, but getFeatureInfo does not add these params, so the features returned are usually too many. Is there any way to tell getFeatureInfo to append the viewparams from the layer definitions? Regards |
If your not using gxp - and you have added viewparams to your OpenLayers.layer.WMS configuration then you probably need to set vendorParams=viewparams in WMSGetFeatureInfo as Bart mentioned above. I dont think vendorParams should be in WMSGetFeatureInfo as it should be the user/programmers responsibility to format urls correctly for the given WMS server. If the given WMS server doesnt support viewparams then it makes no sense to query that server for a postgis layer. |
Hei and thank you for your reply. When adding viewparams to a WMS layer definition they are added to the query, but when clicking on a feature and then requesting feature info the parameters are not added. In case of GeoServer the default viewparams for that layer are then used, which is not what I want in my case. But how can I add viewparams to specific layers. in WMSGetFeatureInfo? Adapting your example case, I would like features of type:BA and type BB, but not features of type:BC? Not doing anything will return the features of the default type (in case of GeoServer). Will adding type:BA;type:BB return features for layers of both types? I was thinking of addapting the following code
|
you will need to make use of |
That works well when only having ONE layer and adding some parameters to it. But when you have 2 layers which have different viewparams it doesn't. If you specify vendorparams like {viewparams: 'type:A;type:B'} both viewparams are appended but only the last is recognized by geoserver and then applied to both layers, thus returning the same feature info twice. It doesn't help either to change vendorparams to {viewparams:'type: Ä́', viewparams:'type: B'}. It results in only appending the second viewparam to the url with the same result of returning a feature twice. Maybe it's a geoserver issue? |
How does the code for configuring the layer look like? |
I see your point @chris58 you would need vendorParams to be a lookup per layer name or something similar Maybe we should add an extra event here where you could intercept the url and add the params yourself? |
@bartvde, that's the problem. ;-) I haven't figured out how to associate one set of viewParams/vendorParms with layer ONE and another set of params with layer TWO where the layers ONE and TWO have the same basic definition, i.e. @emoen the code looks like
But, maybe it's really a geoserver problem of how to pick up and use the vendorParams in a query. I could add the parameters myself by using beforeGetFeatureInfo() but it's still one call with a list of all layers and all viewParams. |
Hi again, found the solution. Just to round up... ;-) view parameters (geoserver) have to be separated by commas (,) when applying different parameters to several layers (http://docs.geoserver.org/stable/en/user/data/database/sqlview.html?highlight=viewparams). Number of comma separated viewParams must equal number of queried layers. layersToBeQueried = [layerA, layerB, layerC]; controls.push(new OpenLayers.Control.WMSGetFeatureInfo({ Regards |
How does the url that is sent to geoserver look like? Do you send viewparams: 'fartoeystype:1, 2'? So it is creating a list? I worked around the problem of sending a list of values for one viewparams to geoserver;e.g. &VIEWPARAMS=periodname:'M200405 M200505', by creating a stored procedure tokenizes the elements and returns a select. |
In your case the generated viewparams in the getfeatureinfo URL should look like: In my case the generated query to geoserver looks like this The query starts with the two LAYERS which are identical The only difference is the view parameter at the end of the URL The view parameter sets must be separated by commas and equal the number of layers. If a layer needs more than one view parameter the parameters for that layer must be separated by semi colons. The percentage symbol is sent directly to the underlying database, it's an SQL wild card character, in this case 9% means look for everything which starts with a 9. What you have to build up as vendorParams in Control.WMSGetFeatureInfo (for two layers, one view parameter each) looks like The buffer is another vendor parameter special to geoserver, in this case defining a 20 pixel buffer around the click position when searching for features. Regards From: Endre Moen [notifications@github.com] How does the url that is sent to geoserver look like? Do you send viewparams: 'fartoeystype:1, 2'? So it is creating a list? I worked around the problem of sending a list of values for one viewparams to geoserver;e.g. &VIEWPARAMS=periodname:'M200405 M200505', by creating a stored procedure tokenizes the elements and returns a select. � |
So does geoserver generates a query where you have SELECT * FROM ... WHERE ... AND fartoeystype=9% AND fartoeystype=7% AND ...? I needed to generate an SQL that uses OR which is why I did it with a stored procedure: SELECT * FROM ... WHERE ... AND periodname=M200405 OR periodname=M200505 AND ... |
Sorry @emoen for late reply. Saw it first now. :-( Geoserver doesn't generate any AND or OR in an SQL query. It just replaces the text between two percentage signs with the value of the paramter. You could fake it by using a query like Select ... from ... where periodname='%period_1%' or periodname='%period_2%' or periodname='%period_3%' Then your viewparams would be called period_1, period_2, period_3. If you set the default parameter values to something which will never exist in the table, e.g. -1, the query will work with one, two or all three period_X mentioned in the query. If you want to build more complicated selections it could be an idea to use CQL filters instead. Christian |
hi @chris58 , we have probably hijacked this issue... If your using geoserver-sql-view each key,value pair of VIEWPARAMS is matched to a column in a table or view and geoserver generates an sql like this:https://gist.github.com/emoen/8a6e2c2554ba177a26ae Your right, CQL is the way to do it rather than a stored procedure. |
When querying an sql view WMS layer for getFeatureInfo the viewparams is missing.
An example of this:
http://maps.imr.no/geoserver/wms?LAYERS=measurements_last_30_days&QUERY_LAYERS=measurements_last_30_days&STYLES=arcticroos_gtsbathy&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&BBOX=-10707220.5,-2714812.5,10707220.5,2714812.5&FEATURE_COUNT=10&HEIGHT=375&WIDTH=1479&FORMAT=image/png&INFO_FORMAT=application/vnd.ogc.gml&SRS=EPSG:3575&X=665&Y=365
which has been generated by
OpenLayers.Control.WMSGetFeatureInfo.buildWMSOptions()
and the response is:
<wfs:FeatureCollection xmlns="http://www.opengis.net/wfs"
xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://maps.imr.no:80/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd">
gml:boundedBy
gml:nullunknown/gml:null
/gml:boundedBy
/wfs:FeatureCollection
adding viewparams:type=BA returns the expected result:
http://maps.imr.no/geoserver/wms?LAYERS=measurements_last_30_days&QUERY_LAYERS=measurements_last_30_days&STYLES=arcticroos_gtsbathy&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&BBOX=-10707220.5,-2714812.5,10707220.5,2714812.5&FEATURE_COUNT=10&HEIGHT=375&WIDTH=1479&FORMAT=image/png&INFO_FORMAT=application/vnd.ogc.gml&SRS=EPSG:3575&X=665&Y=365&viewparams=type:BA
The text was updated successfully, but these errors were encountered: