AnsweredAssumed Answered

Adding points to map object using dojo xhr.get web service call

Question asked by UnityXP on Sep 16, 2013
Latest reply on Sep 17, 2013 by zj_zou
I would like to add graphics to a map based on data from a web service call. This is the code I have:

var xhrArgs = {
                            url: "/Map/getalerts",
                            handleAs: "json",
                            load: function (track) {
                                var point = new Point(track.Latitude, track.Longitude, new SpatialReference({ wkid: 4326 }));
                                var simpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
                                   new Color([255, 0, 0]), 1),
                                   new Color([0, 255, 0, 0.25]));
                                var graphic = new Graphic(webMercatorUtils.geographicToWebMercator(point), simpleMarkerSymbol,
                                 { 'title': track.FullName, 'content': 'ID: 2<br/>TimeStamp: Some Time<br/>Message Type: Alert' },
                                new InfoTemplate('${title}', '${content}'));

                            error: function (error) {
                                console.log("An unexpected error occurred: " + error);

                        // Call the asynchronous xhrGet
                        var deferred = xhr.get(xhrArgs);

However, when the call returns is no longer in scope and the javascript throws an error about it being undefined.

Does anyone have any idea about how I can get hold of the map object again when the data from the web service call has been returned?