Select to view content in your preferred language

geocoderOptions param in Directions dijit

2730
2
04-18-2013 06:00 PM
DerekMiller
Deactivated User
Hello all,

Has anyone had success with the geocoderOptions parameter in the Directions dijit constructor?

I configured the object as I do when I use the geocoder dijit, i.e. provide a suffix, search extent, etc. When I use that parameter in the constructor, the origin - destination input elements behave as geocoders. In other words, on entering the from - to strings, the map geocodes the addresses (individually) but doesn't provide directions.

What am I missing?

This works :

var routeUrl = "my routing service url";
var directions = new esri.dijit.Directions({
  map: map,
  routeTaskUrl: routeUrl,
  routeParams: {
    directionsLanguage: "en-US"
  }
}, "directionsPanel");
directions.startup();


This doesn't :
var searchExtent = new esri.geometry.Extent({
    "xmin": -13725568.18,
    "ymin": 5669639.97,
    "xmax": -13587981.53,
    "ymax": 5761364.41,
    "spatialReference": {
        "wkid": 102100
    }
});
var geocoderOptions = {
  autoComplete: true,
  arcgisGeocoder: {
      url: "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer",
      name: "Esri World Geocoder",
      suffix: " Portland, OR",
      searchExtent: searchExtent,
      sourceCountry: "USA"
  }
};
      
var routeUrl = "my route service url";
var directions = new esri.dijit.Directions({
  map: map,
  geocoderOptions: geocoderOptions,
  routeTaskUrl: routeUrl,
  routeParams: {
    directionsLanguage: "en-US"
  }
}, "directionsPanel");
directions.startup();


Thanks for the help! I can provide a repo case via link or JSFiddle if anyone is interested.

Cheers.

- d
0 Kudos
2 Replies
KellyHutchins
Esri Notable Contributor
Derek,

I ran a quick test based on your code snippet and it worked for me. In my test I turned off auto complete because if I left it on and accepted an auto complete suggestion then the search text would have an extra Portland Or appended since you specified the suffix text.

1100 5th Ave Portland, OR, Portland, OR


Test Code:


<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10"
>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Directions Widget</title>
    <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/js/dojo/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/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";
      }

    </style>

    <script>var dojoConfig = { parseOnLoad: true };</script>

    <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.4/"></script>
    <script>
      dojo.require("esri.layout");
      dojo.require("esri.map");
      dojo.require("esri.dijit.Directions");



      function init() {
        //all requests to route.arcgis.com will proxy to the proxyUrl defined in this object.
        esri.addProxyRule({
          urlPrefix: "route.arcgis.com",  
          proxyUrl: "proxy.php"
        });

        var map = new esri.Map("map", {
          basemap: "streets",
          center:[-98.56,39.82],
          zoom: 4
        });
        var extent = new esri.geometry.Extent({
            "xmin": -13725568.18,
            "ymin": 5669639.97,
            "xmax": -13587981.53,
            "ymax": 5761364.41,
            "spatialReference": {
                "wkid": 102100
            }
        });
        var options = {
          autoComplete:false,
          arcgisGeocoder:{
            url: "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer",
            name: "Esri World Geocoder",
            suffix: " Portland, OR",
            sourceCountry: "USA",
            searchExtent: extent

          }
        };

        var directions = new esri.dijit.Directions({
          map: map,
          geocoderOptions: options


        },"dir");

        directions.startup();
      }

      dojo.ready(init);
    </script>
  </head>
  <body class="claro">
    <div data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'headline', gutters:false" style="width:100%;height:100%;">
      <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'right'" style="width:250px;">
        <div id="dir"></div>
      </div>
      <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'" id="map"></div>
   </div>
  </body>
</html>

DerekMiller
Deactivated User
In my test I turned off auto complete because if I left it on and accepted an auto complete suggestion then the search text would have an extra Portland Or appended since you specified the suffix text.


Hi Kelly,

Thanks for the response. I think auto-complete is necessary from a usability perspective. I took your code and enabled auto-complete while disabling the suffix parameter, instead relying on the search extent to limit the candidates returned to the dijit.

This worked. However, it now appears that the text input boxes are acting like geocoders, i.e. the map navigates to the selected candidate from the auto-complete box.

This should be easy to replicate. Thoughts?

Thanks again for the reply.

Cheers.

- d
0 Kudos