Filtering a layer

2652
3
04-28-2015 10:33 AM
KellyZiegenfuss2
New Contributor

Does anybody have a good example of filtering a layer based off of a unique id received from a click?

Tags (3)
0 Kudos
3 Replies
RickeyFight
MVP Regular Contributor

Kelly,

I am confused exactly what you are looking for. 

What is being filtered by a click?

Are you looking for related fields?

0 Kudos
KellyZiegenfuss2
New Contributor

Hi Rickey,

Let me explain my exact project. I have a map with points and a layer with the service areas of each point. I want to program it so that when the user clicks a certain point the service area for only that point pops up. Please let me know if you know of a way to do this! Thanks!

0 Kudos
RickeyFight
MVP Regular Contributor

Kelly,

Yes, that makes more sense. Try this JS Bin - Collaborative JavaScript Debugging​, it is not exactly what you are looking for. This script does what you want in reverse.

Try this code. I am not sure what you service areas are but this might work.

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples 
      on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Select with feature layer</title>
    <link rel="stylesheet" href="http://js.arcgis.com/3.12/dijit/themes/tundra/tundra.css">
    <link rel="stylesheet" href="http://js.arcgis.com/3.12/esri/css/esri.css">
    <style>
      html, body, #mapDiv {
        padding: 0;
        margin: 0;
        height: 100%;
      }
      #messages{
        background-color: #fff;
        box-shadow: 0 0 5px #888;
        font-size: 1.1em;
        max-width: 15em;
        padding: 0.5em;
        position: absolute;
        right: 20px;
        top: 20px;
        z-index: 40;
      }
    </style>
    <script src="http://js.arcgis.com/3.12/"></script>
    <script>
      var map;
      require([
        "esri/map", "esri/layers/FeatureLayer", "esri/layers/GraphicsLayer",
        "esri/tasks/query", "esri/geometry/Circle",
        "esri/graphic", "esri/InfoTemplate", "esri/symbols/SimpleMarkerSymbol",
        "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "esri/renderers/SimpleRenderer",
        "esri/config", "esri/Color", "dojo/dom", "dojo/domReady!"
      ], function(
        Map, FeatureLayer, GraphicsLayer,
        Query, Circle,
        Graphic, InfoTemplate, SimpleMarkerSymbol,
        SimpleLineSymbol, SimpleFillSymbol, SimpleRenderer,
        esriConfig, Color, dom
      ) {
        map = new Map("mapDiv", { 
          basemap: "streets",
          center: [-95.249, 38.954],
          zoom: 16,
          slider: true
        });
        
        var censusPoints = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/1",{
          infoTemplate: new InfoTemplate("Block: ${BLOCK}", "${*}"),
          mode: FeatureLayer.MODE_SELECTION,
          outFields: ["POP2000","HOUSEHOLDS","HSE_UNITS", "TRACT", "BLOCK"]
        });
        var censusBlocks = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/0");

        var censusBlocksGL = new GraphicsLayer();
        var bSymbol = new SimpleFillSymbol(
          SimpleFillSymbol.STYLE_SOLID,
          new SimpleLineSymbol(
            SimpleLineSymbol.STYLE_SOLID, 
            new Color([247, 34, 101, 0.9]), 
            1
          ),
          new Color([247, 34, 101, 0.3])
        );
        // selection symbol used to draw the selected census block points within the buffer polygon
        var symbol = new SimpleMarkerSymbol(
          SimpleMarkerSymbol.STYLE_CIRCLE, 
          12, 
          new SimpleLineSymbol(
            SimpleLineSymbol.STYLE_SOLID, 
            new Color([247, 34, 101, 0.9]), 
            1
          ),
          new Color([207, 34, 171, 0.5])
        );
        censusPoints.setSelectionSymbol(symbol); 
               map.addLayers([censusPoints, censusBlocks, censusBlocksGL]);
        
        censusBlocks.on("click", function(e){
            censusBlocksGL.clear();
            //select point features within the clicked census block     
            if(e.graphic && e.graphic.geometry){
                var gra = new Graphic(e.graphic.geometry, bSymbol);
                censusBlocksGL.add(gra);
                var query = new Query();
                query.geometry = e.graphic.geometry;
                censusPoints.selectFeatures(query);
            }
       });
      });
    </script>
  </head>


  <body>
    <span id="messages">Click on the map to select census block points within the group.</span>
    <div id="mapDiv"></div>
  </body>
</html>

If this does not work I might be able to find more examples.