Turning on Layer after URL query is executed

468
1
Jump to solution
03-19-2018 04:36 AM
by Anonymous User
Not applicable

Howdy!

So I'm interested in turning on a layer after a feature is queried by a URL parameter. As an example, if you hit this URL:

ArcGIS Web Application 

The app executes the query just fine (woohoo), but since that layer is not turned on by default, the actual symbol is not drawn, which will likely be confusing for end-users. 

I imagine this is as simple as calling the showLayers function of the LayerList widget, but I'm still getting my feet under me in this capacity. 

Any insight would be appreciated!

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Andrew,

   In your apps jimu/MapUrlParamsHandler.js in the queryFeature function you just need to turn on your layer (lines 26 and 31).

  function queryFeature(queryObject, map){
    /************************
    ?query=<layerName/layerId, fieldName, fieldValue>
    ?query=<layerName/layerId, whereClause>
    *************************/
    //?query=Cities,pop>1000&level=10
    //?query=Cities,city_name,Rome&level=10
    var queryArray = queryObject.query.split(";");
    if (queryArray.length === 1) {
      queryArray = queryObject.query.split(",");
    }

    if(queryArray.length !== 2 && queryArray.length !== 3){
      console.error('query URL parameter is not correct.');
      return;
    }

    var layerNameOrId = queryArray[0];
    //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{
            layer2.layerInfo.setTopLayerVisible(true); 
            selectFeatures(map, layer2, queryArray);
          }
        });
      }else{
        layer.layerInfo.setTopLayerVisible(true);
        selectFeatures(map, layer, queryArray);
      }
    });
  }

View solution in original post

1 Reply
RobertScheitlin__GISP
MVP Emeritus

Andrew,

   In your apps jimu/MapUrlParamsHandler.js in the queryFeature function you just need to turn on your layer (lines 26 and 31).

  function queryFeature(queryObject, map){
    /************************
    ?query=<layerName/layerId, fieldName, fieldValue>
    ?query=<layerName/layerId, whereClause>
    *************************/
    //?query=Cities,pop>1000&level=10
    //?query=Cities,city_name,Rome&level=10
    var queryArray = queryObject.query.split(";");
    if (queryArray.length === 1) {
      queryArray = queryObject.query.split(",");
    }

    if(queryArray.length !== 2 && queryArray.length !== 3){
      console.error('query URL parameter is not correct.');
      return;
    }

    var layerNameOrId = queryArray[0];
    //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{
            layer2.layerInfo.setTopLayerVisible(true); 
            selectFeatures(map, layer2, queryArray);
          }
        });
      }else{
        layer.layerInfo.setTopLayerVisible(true);
        selectFeatures(map, layer, queryArray);
      }
    });
  }