Dynamic Filter

3628
17
03-26-2017 03:21 AM
AvishaiDemayo
New Contributor II

Hi,

We have an app that was created with webappbuilder 2.2 that only hold one layer.

This layer has 14 polygones and we want to send papramter to the map so it will open with the realvant polygone

instead of creating 14 diffrent apps / maps.

For example - 

http://gisserver/portal/apps/webappviewer/index.html?id=92fa9ecbb5cc433daa7ce8c9fe18cf45&FILTER=MYLA..., Code=1-14 ( 1,2,3...14 )

The same as here Use URL parameters to modify maps—ArcGIS Online Help | ArcGIS  but filter the data.

Hope i make myself clear..

Avishai

0 Kudos
17 Replies
RobertScheitlin__GISP
MVP Emeritus

Avishai,

   This is more involved then a couple of lines of code and a few minutes of development. I don't have time to look into this further right now so you have to take it from here.

0 Kudos
AvishaiDemayo
New Contributor II

Made it ! 10x  

0 Kudos
JTessier
Occasional Contributor II

Any chance you can share your code Avishai?  Or did you post it in GitHub?

0 Kudos
AvishaiDemayo
New Contributor II

iI've posted it in Wai Chan replay

0 Kudos
WaiChan
New Contributor II

Avishai, I am having the same issue you had. How did you solve it?

0 Kudos
AvishaiDemayo
New Contributor II

Go to ..\arcgis-web-appbuilder-2.7\WebAppBuilderForArcGIS\server\apps\xx\jimu

  1. Modify MapUrlParamsHandler.js (make a backup)
  2. Add:
    1. In  mo.postProcessUrlParams = function(urlParams, map) add  if('filter' in urlParams){ setSpecialZoom(urlParams, map);}  
    2.  
    3. 3 functions

function setSpecialZoom(queryObject, map){

    //myZooms is a keyValue string, separated by ; char, key is layerObject Id, values are filters, separated by *

    var myZooms = queryObject.filter.split(";");

    if (myZooms.length < 1) {console.error("No arguments in specialzoom");return;}

    var layersKeyValue = {};

    for (myLayer in myZooms){

                    //iterate over each itemid

                    myLayer =  myZooms[myLayer];

                    layerAndFilter = myLayer.split("*");

                    if (layerAndFilter.length < 2){console.error("LayerObject, ID or filters are missing");return;}

                    var layerFilters = [];

                    layerId = layerAndFilter[0];

                                    for ( i = 1; i < layerAndFilter.length; i++){

                                                    //iterate over each id in item id

                                                    layerFilters = processFilter(layerFilters,layerAndFilter.split("|"));

                                    }             

                                   

                    layersKeyValue[layerId] = layerFilters;  

                    }

    assignFilterPropertiesToLayer(layersKeyValue,map);

    //var valuesForProcess = [myZooms[0]];

    //map.itemInfo.itemData.operationalLayers[0].layerObject.setLayerDefinitions( valuesForProcess);

  }

  function processFilter (layerFilters,myFilters){

  //creates a string structure from all the filters.

    var andString = " AND ";

    var filterCombined = "";

    var layerId = myFilters[0]

    for (j = 1; j < myFilters.length;j++) {

                    currentFilter = myFilters;

    //            currentFilter = "(" + currentFilter + ")";

                    if (filterCombined.length == 0){

                                    filterCombined = currentFilter;

                    }else{

                                    filterCombined = filterCombined + andString + currentFilter;

                    }

    }

    layerFilters[layerId] = filterCombined;

    return layerFilters;

  }

  function assignFilterPropertiesToLayer (layersKeyValue,map){

  //loop over all operational layers and set new filter if necessary

    for (myOperLayer in map.itemInfo.itemData.operationalLayers){

                    myOperLayer = map.itemInfo.itemData.operationalLayers[myOperLayer];

                    if (myOperLayer.id && layersKeyValue[myOperLayer.id]){

                        myOperLayer.layerObject.setLayerDefinitions(layersKeyValue[myOperLayer.id]);

                    }

    } 

}

 

 

How to use in URL  :

Add "filter=" in url

separated by  ;  between Map services

separated by  *  between itemid and id (Service Features in a Map service) separated by  |  between field Values

 

example :

?filter=3fb26b36ed2d43f48c63770fc50bc7f8*0|Unit_Code=26|Measure_Code=285*1|branch_code=26|Measure_Code=285*2|Measure_Code=285;b26b36ed2d43f48c63770fc50bc7f8*0|Unit_Code=26|Measure_Code=285;

                        ITEMID                                                 ID         Field Values

WaiChan
New Contributor II

This is awesome! I am not much of a JavaScript person, but I think I can make heads and tails on your code. Thank you very much!

0 Kudos
SaraAbasi
New Contributor III

Thanks Avishai for sharing the solution, I have few questions:

I cannot locate the function in red  (In  mo.postProcessUrlParams = function(urlParams, map) add  if('filter' in...) 

 

Questions about the url:

Is this number the app id we get from the servce setting? 3fb26b36ed2d43f48c63770fc50bc7f8

Is the numbers 0, 1, 2, indicate th enumber filters on a service?

Where can we identify the extent for the zoom?

What I need to do is to zoom to one project_number (which is the id) out of 100, zoom into that project in some extent and remove anyother project from the map.

Thank you!