graphics undefined even after update-end fires.

06-17-2014 09:45 AM
New Contributor II
So i've been learning the Javascript API and i've been building a custom page based on several samples. What i'm finding is that I'm obviously not understanding a concept here and it's causing me some problems. The following is a code snip from the page i'm building the entire source can be found at a link at the bottom posted to paste bin.
    var map;
    var currPoint;
            "dijit/form/TextBox", // this we only include to make an example with TextBox
            "dojo/domReady!"], function (Map, arcgisUtils, Legend, Graphic, SimpleLineSymbol, SimpleMarkerSymbol, SimleRenderer,
                                         SimpleFillSymbol, Color, FeatureLayer, Circle, OpenStreetMapLayer, esriRequest, GeometryService,
                                         dom, parser, all,array, HorizontalSlider, HorizontalRule,
                                         HorizontalRuleLabels, TextBox, domConstruct, on, esriConfig) {
                var geometryService,baseGraphics;
                // = "/proxy";
                // = false;
                map = new esri.Map("mapDiv", {
                    center: [-114.0288, 51.0669],
                    zoom: 10

                var osmLayer = new OpenStreetMapLayer({

                geometryService = new GeometryService("");

                var legend = new Legend({
                    map: map,
                    layerInfos: (arcgisUtils.getLegendLayers(map))
                }, "legendDiv");

                var rulesNode = domConstruct.create("div", {}, dom.byId("slider"), "first");
                var sliderRules = new HorizontalRule({
                    container: "topDecoration",
                    count: 6,
                    style: "width: 5px;"
                }, rulesNode);

                // Create the labels
                var labelsNode = domConstruct.create("div", {}, dom.byId("slider"), "first");
                var sliderLabels = new HorizontalRuleLabels({
                    container: "topDecoration",
                    labelStyle: "font-style: italic; font-size: 0.75em",
                    count: 6,
                    labels: [5, 10, 15, 20, 25, 30]
                }, labelsNode);

                var slider = new HorizontalSlider({
                    name: "slider",
                    value: 5,
                    minimum: 5,
                    maximum: 30,
                    intermediateChanges: true,
                    discreteValues: 6,

                    style: "width:300px;",
                    onChange: function (value) {
                        dom.byId("sliderValue").value = value;
                }, "slider");

                var siteValue = dom.byId('drpSite').value;
                var drpSite = dom.byId("drpSite");
                on(drpSite, "change", function (e) {
                    siteValue = dom.byId('drpSite').value;
                var sites = new FeatureLayer("", {
                    mode: FeatureLayer.MODE_ONDEMAND,
                    id: "CalgarySites",
                    name: "Calgary Sites",
                    outFields: ["*"]
                var dt = new FeatureLayer("", {
                    mode: FeatureLayer.MODE_ONDEMAND,
                    id: "DriveTime",
                    name: "Drive Times",

                sites.setDefinitionExpression("NICKNAME='" + siteValue + "'");
                sites.on("update-end", function (evt) {
                    currPoint = new Graphic([0].toJson());
                    dt.setDefinitionExpression("NICKNAME='" + siteValue + "' and ToBreak=" + sliderValue.value);

                dt.on("update-end", function (evt) {
                    var promises = new all({
                        poilist : executeLocalSearch(currPoint)


                function buildMap() {
                    sites.setDefinitionExpression("NICKNAME='" + siteValue + "'");

The error I'm getting is the one listed here.
TypeError: Unable to draw graphic (null):[0] is undefined
currPoint = new Graphic([0].toJson());

my assumption was that when i first getting the error it had to do with the asynchronous nature of the code so i switched to using the update-end on the point layer (sites) figuring that once the update-end fired i should have a graphic with a point. However, the error above seems to imply differently. Any suggestions or help is much appreciated.

full code available here.
0 Kudos
5 Replies
Esri Regular Contributor
It appears to be a scope issue with siteValue and malformed definition expressions.

siteValue appears to be null in certain cases.
I noticed you are treating it like a global... this might not be the best approach for your application.

Also, after fixing your definition expressions, the 'graphic' paramter in executeLocalSearch() still appears to be null, generating the second set of errors.
0 Kudos
New Contributor II
I'm afraid i don't see what's wrong with the definition expression. As for the scope issues, yes that was not my preferred way, and the original code looked quite different but this is what happens when i got frustrated iw as trying anything to make it work.

and the null parameter is where the heart of this problem lies. I'm not sure how it can be null when the point is being returned to the layer.
0 Kudos
Esri Regular Contributor
I'm afraid i don't see what's wrong with the definition expression.

var siteValue = dom.byId('drpSite').value;

In your code, siteValue is null.
When siteValue is null, using this expression will cause an error.

This is not the correct way to get the value from a dom node using DOJO.
If you are stuck using this approach, use dom.byId('drpSite').innerHTML

sites.setDefinitionExpression("NICKNAME='" + siteValue + "'");
dt.setDefinitionExpression("NICKNAME='" + siteValue + "' and ToBreak=" + sliderValue.value);

0 Kudos
MVP Regular Contributor
jon is right

i am guessing drpSite is some type of selectbox.  (especially since you hook an onchange even to it).  It is incorrect to use

you do not want the value of the dom element.  You want the dijit value

you should be using


to get the dijit
0 Kudos
New Contributor II
Yes it is a dropdown, that contians the "nicknames" for the various sites in the area. Ok will have to check this out.
0 Kudos