Trying to Use Custom Address Locator in ArcGIS Online Application

3709
13
Jump to solution
08-12-2014 07:30 AM
ChrisSergent
Regular Contributor III

Here is the code that we have with our address locator. What do we need to do to get it to work?

<!DOCTYPE html>

<html>

<head>

<title></title>   <!-- Define the versions of IE that will be used to render the page. See Microsoft documentation for details. Optional. -->

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta charset="utf-8">

<!-- Responsive -->

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

<meta name="mobile-web-app-capable" content="yes">

<meta name="apple-mobile-web-app-capable" content="yes">

<meta name="apple-mobile-web-app-status-bar-style" content="default">

<!-- End Responsive -->

<!-- Use protocol relative urls that way if the browser is viewing the page via HTTPS the js/css file will be requested using the HTTPS protocol -->

<link rel="stylesheet" href="https://community.esri.com//js.arcgis.com/3.10/js/esri/css/calcite/calcite.css">

<link rel="stylesheet" href="https://community.esri.com//js.arcgis.com/3.10/js/esri/css/esri.css">

<!-- Load any application specific styles -->

<link rel="stylesheet" href="css/styles.css">

<!--[if IE 8]>

<link rel="stylesheet" href="css/ie.css">

<![endif]-->

</head>

<body class="calcite app-loading no-touch">

<!-- Loading Indicator -->

<div class="loading-indicator">

<div class="loading-message" id="loading_message"></div>

</div>

<!-- Map -->

<!-- The ArcGIS API for JavaScript provides bidirectional support. When viewing the application in an right to left (rtl) language like Hebrew and Arabic the map needs to remain in left-to-right (ltr) mode. Specify this by setting the dir attribute on the div to ltr. -->

<div id="mapDiv" dir="ltr"></div>

<!-- Panel Content -->

<div id="panelContent">

<div id="panelPages"></div>

</div>

<!-- Panel Top -->

<div id="panelTop" class="bg rounded shadow">

<!-- Panel Title -->

<div id="panelTitle">

<div class="fc" id="panelText">

</div>

<div id="panelSearch">

<div id="panelGeocoder"></div>

</div>

<div id="panelMenu" class="icon-menu icon-color"></div>

</div>

<!-- Panel Tools -->

<div id="panelTools">

<!--Tools are created programatically-->

</div>

</div>

<script type="text/javascript">

var package_path = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/'));

var dojoConfig = {

// The locationPath logic below may look confusing but all its doing is

// enabling us to load the api from a CDN and load local modules from the correct location.

packages : [{

name : "application",

location : package_path + '/js'

}, {

name : "config",

location : package_path + '/config'

}]

};

</script>

<script type="text/javascript" src="//js.arcgis.com/3.10/"></script>

<script type="text/javascript">

require(["application/template", "application/main"], function(Template, Main) {

// create the template. This will take care of all the logic required for template applications

var myTemplate = new Template();

var myApp = new Main();

myTemplate.startup().then(function(config) {

myApp.startup(config);

}, function(error) {

// something went wrong. Let's report it.

myApp.reportError(error);

});

});

</script>

<script type="text/javascript">

var map;

var locatorUrl = "http://maps.decaturil.gov/arcgis/rest/services/Public/WebAddressLocator/GeocodeServer";

var myGeocoders = [{

url: locatorUrl,

singleLineFieldName: "SingleLine",

name: "Enter Address"

}];

geocoder = new Geocoder({

map: map,

autoComplete: true,

arcgisGeocoder: false,

geocoders: myGeocoders

},"search");

geocoder.startup();

</script>

</body>

  </html>

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor

If you aren't using the Esri world geocoder and your custom locator then auto complete won't be enabled. To enable it edit the main.js file and at approximately line 301 you'll see code like this:

            var options = {

                map: this.map,

                autoNavigate: false,

                theme: "simpleGeocoder",

                autoComplete:hasEsri

            }

Modify the line with autoComplete: hasEsri to be autoComplete: true

View solution in original post

13 Replies
RobertScheitlin__GISP
MVP Emeritus

Chris,

   Your locator service has the single field name of "Single Line Input" and your code has it as "SingleLine" right now.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Chris,

  Sorry I did not notice all the other issues in your code...

Here is a sample using your geocode service:

<!DOCTYPE html>

<html>

  <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">

    <title>Geocoder Widget</title>

    <link rel="stylesheet" href="http://js.arcgis.com/3.10/js/esri/css/esri.css">

    <style>

      html, body, #map {

        height:100%;

        width:100%;

        margin:0;

        padding:0;

      }

      body {

        background-color:#FFF;

        overflow:hidden;

        font-family:"Trebuchet MS";

      }

      #search {

        display: block;

        position: absolute;

        z-index: 2;

        top: 20px;

        left: 75px;

      }

    </style>

    <script src="http://js.arcgis.com/3.10/"></script>

    <script>

      var map;

      var geocoder;

      var locatorUrl = "http://maps.decaturil.gov/arcgis/rest/services/Public/WebAddressLocator/GeocodeServer";

      require([

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

      ], function(

        Map, Geocoder

      ) {

        map = new Map("map",{

          basemap: "topo",

          center: [-117.19,34.05], // lon, lat

          zoom: 13

        });

       

        var myGeocoders = [{

          url: locatorUrl,

          name: "Enter Address",

          singleLineFieldName: "Single Line Input",

          outfields: "*"

        }];

        geocoder = new Geocoder({

          map: map,

          autoComplete: true,

          arcgisGeocoder: false,

          geocoders: myGeocoders

        },"search");

        geocoder.startup();

      });

    </script>

  </head>

  <body>

    <div id="search"></div>

    <div id="map"></div>

  </body>

</html>

0 Kudos
ChrisSergent
Regular Contributor III

I posted the wrong code, but posted an update.

0 Kudos
KyleBelott
Occasional Contributor

Chris,

Should your geocoder DOMNode parameter be "panelSearch" or "panelGeocoder" instead of "search"?

0 Kudos
ChrisSergent
Regular Contributor III

I posted the wrong code but I posted an update.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Chris,

  You still have the same issue with not having all the options provided in your myGeocoders object.

     var myGeocoders = [{

        url: locatorUrl,

        name: "Enter Address",

        singleLineFieldName: "Single Line Input",

        outfields: "*"

      }];

But the fact that I can not take your code and run it without significant error, does not allow me to debug it very well. Maybe you can provide the styles.css and any significant /js files.

0 Kudos
ChrisSergent
Regular Contributor III

This actually should have been the code that is not working:

<!DOCTYPE html>

<html>

  <head>

  <title></title> <!-- Define the versions of IE that will be used to render the page. See Microsoft documentation for details. Optional. -->

  

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

  <meta charset="utf-8">

  <!-- Responsive -->

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

  <meta name="mobile-web-app-capable" content="yes">

  <meta name="apple-mobile-web-app-capable" content="yes">

  <meta name="apple-mobile-web-app-status-bar-style" content="default">

  <!-- End Responsive -->

  <!-- Use protocol relative urls that way if the browser is viewing the page via HTTPS the js/css file will be requested using the HTTPS protocol -->

  <link rel="stylesheet" href="https://community.esri.com//js.arcgis.com/3.10/js/esri/css/calcite/calcite.css">

  <link rel="stylesheet"  href="https://community.esri.com//js.arcgis.com/3.10/js/esri/css/esri.css">

  <!-- Load any application specific styles -->

  <link rel="stylesheet" href="css/styles.css">

  <!--[if IE 8]>

  <link rel="stylesheet" href="css/ie.css">

  <![endif]-->

  </head>

  <body class="calcite app-loading no-touch">

  <!-- Loading Indicator -->

  <div class="loading-indicator">

  <div class="loading-message" id="loading_message"></div>

  </div>

  <!-- Map -->

  <!-- The ArcGIS API for JavaScript provides bidirectional support.  When viewing the application in an right to left (rtl) language like Hebrew and Arabic the map needs to remain in left-to-right (ltr) mode. Specify this by setting the dir attribute on the div to ltr. -->

  <div id="mapDiv" dir="ltr"></div>

  <!-- Panel Content -->

  <div id="panelContent">

  <div id="panelPages"></div>

  </div>

  <!-- Panel Top -->

  <div id="panelTop" class="bg rounded shadow">

  <!-- Panel Title -->

  <div id="panelTitle">

  <div class="fc" id="panelText">

  </div>

  <div id="panelSearch">

  <div id="panelGeocoder"></div>

  </div>

  <div id="panelMenu" class="icon-menu icon-color"></div>

  </div>

  <!-- Panel Tools -->

  <div id="panelTools">

  <!--Tools are created programatically-->

  </div>

  </div>

  <script type="text/javascript">

         var package_path = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/'));

         var dojoConfig = {

            // The locationPath logic below may look confusing but all its doing is

            // enabling us to load the api from a CDN and load local modules from the correct location.

            packages : [{

               name : "application",

               location : package_path + '/js'

            }, {

               name : "config",

               location : package_path + '/config'

            }]

         };

  </script>

  <script type="text/javascript" src="//js.arcgis.com/3.10/"></script>

  <script type="text/javascript">

         require(["application/template", "application/main"], function(Template, Main) {

            // create the template. This will take care of all the logic required for template applications

            var myTemplate = new Template();

            var myApp = new Main();

            myTemplate.startup().then(function(config) {

               myApp.startup(config);

            }, function(error) {

               // something went wrong. Let's report it.

               myApp.reportError(error);

            });

         });

  </script>

     <script>

      var map;

      var geocoder;

      var locatorUrl = "http://maps.decaturil.gov/arcgis/rest/services/Public/WebAddressLocator/GeocodeServer";

      require([

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

      ], function(

        Map, Geocoder

      ) {

        map = new Map("mapDiv",{

          basemap: "topo",

          center: [-117.19,34.05], // lon, lat

          zoom: 13

        });

       

        var myGeocoders = [{

          url: locatorUrl,

          name: "LocateValveByAssetID"

        }];

        geocoder = new Geocoder({

          map: map,

          autoComplete: true,

          arcgisGeocoder: false,

          geocoders: myGeocoders,

          value: "146317"

        },"search");

        geocoder.startup();

      });

    </script>

  </body>

</html>

0 Kudos
KellyHutchins
Esri Frequent Contributor

Looks like you are using code from one of the Online templates - I think maybe Panels? If so then you shouldn't have to add the locator its already included in the application. If you want to update the template to use your locator you'll need to edit the commonConfig.js file to add your locator info. You'll also want to set queryForOrg to false. Here's an example of an updated config file:

define(

[],

function() {

  var config = {

    bingMapsKey:"",  

    units: null,

    helperServices: {

       geometry:{

        url: location.protocol + "//utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"

       },

       printTask: {

        url: location.protocol + "//utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"

       },

       elevationSync:{

         url: location.protocol + "//elevation.arcgis.com/arcgis/rest/services/Tools/ElevationSync/GPServer"

       },

       geocode: [{

        url: location.protocol + "//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"

       },{

        url: "http://maps.decaturil.gov/arcgis/rest/services/Public/WebAddressLocator/GeocodeServer",

        singleLineFieldName: "Single Line Input",

        name: "DecaturLocator",

        placefinding:true

       }]

    },

    queryForOrg: false

};

 

  // could use a has() test to optionally populate some global

  // property so that the stuff defined is in some global identifier

  //

  // instead, just populate a global, will need to remove the next line when

  // when we remove support for loading modules with dojo.require

  // which will be when we move to Dojo 2.0

  commonConfig = config;

  // instead of using a global, this should probably be added to some namespace...

  // do the templates have a common namespace that they use?

  return config; 

});

ChrisSergent
Regular Contributor III

Kelly,

That works, but the autocomplete does not. I thought I would need to add a block for a new Geocoder, but that does not seem to be working.

Here is my modified commonConfig.js file. Do you know what I need to do?

define(

[],

function() {

var config = {

bingMapsKey:"",

units: null,

helperServices: {

geometry:{

url: location.protocol + "//maps.decaturil.gov/arcgis/rest/services/Utilities/Geometry/GeometryServer"

},

printTask: ,

elevationSync:,

geocode: []

},

queryForOrg: false

};

// could use a has() test to optionally populate some global

// property so that the stuff defined is in some global identifier

//

// instead, just populate a global, will need to remove the next line when

// when we remove support for loading modules with dojo.require

// which will be when we move to Dojo 2.0

commonConfig = config;

// instead of using a global, this should probably be added to some namespace...

// do the templates have a common namespace that they use?

return config;

});

0 Kudos