Query URL Parameters Web Appbuilder

4830
8
Jump to solution
05-25-2016 02:47 PM
AdamVellutini
New Contributor III

Hello,

I am working with Web Appbuilder Developers Edition 2.0 and am trying to pass query parameter through a URL to select and zoom to a map feature.  I was able to get that to work with a map service containing only one layer by following the ESRI example query=<layer name>,<field name>,<field value>.

I also have a map service with several grouped layers and I want to query one of those.  The same ESRI help guide states: For  a sublayer in a group of map services, use <layer id_sublayer id>  as the layer id.  This is confusing to me and have tried many different variations but cannot get it to work.

My example is below, where the group layer id = Transportation_9858, the id of the layer (gates) I want to query = 3, followed by the field name, value.  I'm not having any luck with this and wonder if I'm missing something.  The app refreshes and everything come up minus the map.  Feel like I'm close.

https://<portal>/webappbuilder/apps/20?query=Transportation_9858_3,GATEID,44

Does anyone have experience querying a sublayer using this method?  If so I would love to know how you are doing that and what I might be missing.

Thanks in advance!

Adam

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Adam,

I have found several issues with the sublayer query url param.

One the layer you are querying has to be the same WKID as the map or you will see a can not project x to 102100.

Two query normally fails with complex geometry.

I find that I can get more consistent results by adding this line to the MapUrlParamsHandler.js

query.outSpatialReference = map.spatialReference;

Like this:

function selectFeatures(map, layer, queryArray){
    var query = new Query();
    query.outSpatialReference = map.spatialReference;
    var prefix = '';

I have not reported this to Tech support though as I do not use this feature.

View solution in original post

8 Replies
RobertScheitlin__GISP
MVP Emeritus

Adam,

I have found several issues with the sublayer query url param.

One the layer you are querying has to be the same WKID as the map or you will see a can not project x to 102100.

Two query normally fails with complex geometry.

I find that I can get more consistent results by adding this line to the MapUrlParamsHandler.js

query.outSpatialReference = map.spatialReference;

Like this:

function selectFeatures(map, layer, queryArray){
    var query = new Query();
    query.outSpatialReference = map.spatialReference;
    var prefix = '';

I have not reported this to Tech support though as I do not use this feature.

YueWu1
by Esri Regular Contributor
Esri Regular Contributor

Even though this question is answered. I just want to add some comments in case someone else run into this type of issue.

Checked the WAB 2.1 Developer edition file "MapUrlParamsHandler.js" under jumu.js folder

from line 289:

//by name first
 getLayerByNameOrId('name', layerNameOrId, map).then(function(layer){
 if(layer === null){
 getLayerByNameOrId('id', layerNameOrId, map).then(function(layer2){
 if(layer2 === null){
 console.error('Invalid layer name or id.');
 }else{
 selectFeatures(map, layer2, queryArray);
 }
 });
 }else{
 selectFeatures(map, layer, queryArray);
 }
 });
 }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The logic is always prefer the layer' name first and then it's id. Therefore, recommend to put layer's name after 'query='

For example, if you want to query this layer's STATE_NAME = 'Alabama':

Layer: states (ID: 3) 

In your WAB URL you should put like this, because the layer's name is state:

http://localhost/webappbuilder/apps/4/?query=states,STATE_NAME,Alabama 

or

http://localhost/webappbuilder/apps/4/?query=states,STATE_NAME=%27Alabama%27 

Hope this can help.

SuzanneLiebergen1
New Contributor II

This is helpful. Any chance you have advice as to whether or not the zoom level can be changed? I'd like my result to not zoom in quite as far

UWM Transportation Services Map - Lot 7 

0 Kudos
YueWu1
by Esri Regular Contributor
Esri Regular Contributor

This is just a workaround solution, and I am not sure why your application keeps throw out the error:

So technically, you need to go this file:

jimu.js/MapUrlParamsHandler.js

you will see that when geometryType is not Point, then do else { ...}

From line 388, the code logic here is trying to setup the feature's extent (as long as it is not a point feature) as map extent. What you can do here is adding some extra logic to change the map zoom level. For example, set map current Zoom level and dynamically minus one level out, so that the map looks like "zoom-out", for example:

map.setZoom(map.getZoom() - 1);‍‍

Like I said this may not exactly work in your app, however, this should be a breakpoint that you can try to add some code to change the map behavior. 

Hope this can help.

0 Kudos
SuzanneLiebergen1
New Contributor II

Thanks! Thanks for pointing this area of the code out. The suggested solution doesn't work. It zooms the map out by one zoom factor from the default extent and not from the zoomed in alternative of the selected feature.

I'll play around with it.

0 Kudos
YueWu1
by Esri Regular Contributor
Esri Regular Contributor

That's good to know. Well, I assume each time you gonna using the search widget to query all the parking lot. Therefore, same story, you need to go check the widget/Search/widget.js file and add this line of code around line 690:

that.map.setZoom(that.map.getZoom()-1);

This is pretty much the same concept with the previous one. Try this way to see what happened, I think you can make it works.

Best Regards,

Nathan

 

0 Kudos
SuzanneLiebergen1
New Contributor II

Thanks!

I was able to make it work by adding this code below the map.setExtent(resultExtent); line:

0 Kudos
YueWu1
by Esri Regular Contributor
Esri Regular Contributor

Glad to hear that works! Good Job!

0 Kudos