Why is locator being assigned to esri.Graphics class

776
5
Jump to solution
09-18-2013 07:17 AM
PLadd
by
Occasional Contributor III
Here's a noodle scratcher that no one seems to have addresses yet in the forum.  My code keeps tripping up when it gets to
locator.on("address-to-location-complete", showResults)


When I step into the code, it shows that locator is being assigned to the esri.Graphics class instead of esri.tasks.Locator class, which is where I would expect it to be assigned, much like it does on this page.

Here's some of the code:
<script src="http://js.arcgis.com/3.6/"></script>    <script> var dojoConfig = { parseOnLoad: true };</script>        <script type="text/javascript">           var map;           var locator;            require(["esri/map", "esri/tasks/locator", "esri/graphic", "esri/InfoTemplate", "esri/symbols/SimpleMarkerSymbol",             "esri/symbols/Font", "esri/symbols/TextSymbol", "dojo/_base/array", "dojo/_base/Color",             "dojo/number", "dojo/parser", "dojo/dom", "dijit/registry", "dijit/form/Button", "dijit/form/Textarea",             "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"],        function (Map, ready, Locator, Graphic, InfoTemplate, SimpleMarkerSymbol, Font, TextSymbol, arrayUtils, Color, number, parser, dom, registry) {            ready(function () {               parser.parser();           });            map = new Map("map", {               basemap: "topo",               center: [-72.7975, 41.5360], // long, lat               zoom: 14,               slider: false           });             locator = new Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");           locator.on("address-to-locations-complete", showResults);   //here declaredClass says esri.Graphics //not esri.tasks.Locator 


What am I missing?
0 Kudos
1 Solution

Accepted Solutions
JeffJacobson
Occasional Contributor III
You are missing "dojo/ready" in your require statement (after "esri/map").

View solution in original post

0 Kudos
5 Replies
JeffJacobson
Occasional Contributor III
You are missing "dojo/ready" in your require statement (after "esri/map").
0 Kudos
PLadd
by
Occasional Contributor III
Wow!  You are absolutely right.  Good call.  Thanks so much.  I never would have picked that out.

Strange, though, that it doesn't appear in the sample code:

require([
        "esri/map", "esri/tasks/locator", "esri/graphic",
        "esri/InfoTemplate", "esri/symbols/SimpleMarkerSymbol",
        "esri/symbols/Font", "esri/symbols/TextSymbol",
        "dojo/_base/array", "dojo/_base/Color",
        "dojo/number", "dojo/parser", "dojo/dom", "dijit/registry",

        "dijit/form/Button", "dijit/form/Textarea",
        "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
0 Kudos
KenBuja
MVP Esteemed Contributor
But the sample code does not include "ready" in the function, either

require([
        "esri/map", "esri/tasks/locator", "esri/graphic",
        "esri/InfoTemplate", "esri/symbols/SimpleMarkerSymbol",
        "esri/symbols/Font", "esri/symbols/TextSymbol",
        "dojo/_base/array", "dojo/_base/Color",
        "dojo/number", "dojo/parser", "dojo/dom", "dijit/registry",

        "dijit/form/Button", "dijit/form/Textarea",
        "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
      ], function(
        Map, Locator, Graphic,
        InfoTemplate, SimpleMarkerSymbol, 
        Font, TextSymbol,
        arrayUtils, Color,
        number, parser, dom, registry
      ) {



Don't forget to click the check mark on Jeff's answer.
0 Kudos
JohnGravois
Frequent Contributor
maybe Patrick already understands this, but i thought i'd belabor the point anyway...

the inclusion of the specific module 'dojo/ready' is not actually resolving this problem, rather correcting the correspondence between the order of the AMD loaded modules and their respective callback function arguments.

because Patrick originally inserted an argument alias into the require callback function called 'ready' directly after 'map', the order of argument aliases was interpreted to equate 'locator' with the graphic module rather than the tasks/locator module.

in short, if you intend to refer to a module with an alias, make sure the alias order corresponds with the module order.  if you don't intend to refer to the module in your code directly, place it later in the list than all named modules (including a space is a good idea too).
0 Kudos
PLadd
by
Occasional Contributor III
Thanks for the input.  I wasn't aware of those issues.
0 Kudos