AnsweredAssumed Answered

Search is not linked to map in ArcGIS API

Question asked by whsgis on May 1, 2015
Latest reply on May 4, 2015 by rscheitlin

I am trying to add this search function to a map:

 

require([

       
"esri/map",
       
"esri/dijit/Search",
       
"dojo/domReady!"

     
], function (Map, Search) {
        
var map = new Map("map", {
            basemap
: "gray",
            center
: [-120.435, 46.159], // lon, lat
            zoom
: 7
        
});

        
var s = new Search({
            map
: map
        
}, "search");
         s
.startup();

     
});

 

Here is the full js:

 

 

 

    var map;

 

 

    require([

      "esri/map",

      "esri/dijit/Search",

      "esri/arcgis/utils",

      "esri/dijit/Legend",

      "esri/layers/ArcGISTiledMapServiceLayer",

      "esri/layers/ArcGISDynamicMapServiceLayer",

      "dojo/dom",

      "dojo/dom-construct",

      "dojo/parser",

      "dojo/_base/array",

      "dijit/form/CheckBox",

      "esri/graphic",

      "esri/symbols/SimpleMarkerSymbol",

      "esri/geometry/screenUtils",

      "dojo/query",

      "dojo/_base/Color",

      "dijit/layout/AccordionContainer",

      "dijit/layout/BorderContainer",

      "dijit/layout/ContentPane",

      "dojo/domReady!"

    ],

   

      function (

        Map, Search, utils, Legend, ArcGISTiledMapServiceLayer, ArcGISDynamicMapServiceLayer,

  dom, domConstruct,

        parser, arrayUtils, CheckBox, Graphic, SimpleMarkerSymbol, screenUtils, query, Color

      ) {

 

 

        parser.parse();

 

  var legendLayers = [];

 

 

  var s = new Search({

            map: map

         }, "search");

         s.startup();

 

 

        map = new Map("map", {

          basemap: "topo",

          center: [10, 23],

          zoom: 2

        });

 

// duplicate this for each layer - use dynamic layer service for those types

 

 

        var LADALandUse = new ArcGISTiledMapServiceLayer("http://tiles.arcgis.com/tiles/HVjI8GKrRtjcQ4Ry/arcgis/rest/services/LADA_Land_Use_Systems/MapServer", {

          id: 'landuse'

        });

 

 

        legendLayers.push({ layer: LADALandUse, title: 'Land Use' });

       

//         to here

 

 

        var WWFTerEco = new ArcGISTiledMapServiceLayer("http://tiles.arcgis.com/tiles/HVjI8GKrRtjcQ4Ry/arcgis/rest/services/LADA_Land_Use_Systems/MapServer", {

          id: 'WWFTerEco'

        });

 

 

        legendLayers.push({ layer: WWFTerEco, title: 'WWF Terrestrial Ecoregion' });

 

 

        var climateLayer = new ArcGISTiledMapServiceLayer("http://tiles.arcgis.com/tiles/HVjI8GKrRtjcQ4Ry/arcgis/rest/services/LADA_Land_Use_Systems/MapServer", {

            id: 'climate'

        });

 

 

        map.on('layers-add-result', function () {

          var legend = new Legend({

            map: map,

            layerInfos: legendLayers

          }, "legendDiv");

          legend.startup();

        });

        legendLayers.push({ layer: climateLayer, title: "Climate" });

       

        map.addLayers([ climateLayer, LADALandUse, WWFTerEco ]); /*add the layer var here*/

 

 

        map.on('layers-add-result', function () {

          //add check boxes

          arrayUtils.forEach(legendLayers, function (layer) {

            var layerName = layer.title;

            var checkBox = new CheckBox({

              name: "checkBox" + layer.layer.id,

              value: layer.layer.id,

              checked: layer.layer.visible

            });

            checkBox.on("change", function () {

              var targetLayer = map.getLayer(this.value);

              targetLayer.setVisibility(!targetLayer.visible);

              this.checked = targetLayer.visible;

            });

 

 

            //add the check box and label to the toc

            domConstruct.place(checkBox.domNode, dom.byId("toggle"), "after");

            var checkLabel = domConstruct.create('label', {

                'for': checkBox.name,

                innerHTML: layerName

              }, checkBox.domNode, "after");

            domConstruct.place("<br />", checkLabel, "after");

          });

        });

      });

 

Any guidance is greatly appreciated.

Outcomes