AnsweredAssumed Answered

How do you get view.toGo working??!!

Question asked by flyinb on Mar 2, 2017
Latest reply on Mar 2, 2017 by flyinb

I am performing a query on a featurelayer. The query is returning results (I can see results in the console.log), but when i try to view.toGo(returnedFeature) nothing happens. I have tried fixed Point, and a lot of other things, but nothing seems to work. I have set up a button that when you click it, it does the query.

 

I am using the 4.2 API

 

require([
                    "esri/Map",
                    "esri/views/SceneView",
                    "esri/views/MapView",
                    "esri/layers/FeatureLayer",
                    "esri/tasks/QueryTask",
                    "esri/tasks/support/Query",
                    "esri/geometry/Point",
                    "dojo/on",
                    "dojo/domReady!"
                ],
                function (
                    Map,
                    SceneView,
                    MapView,
                    FeatureLayer,
                    QueryTask,
                    Query,
                    Point,
                    on
                ) {
                    var template = {
                        title: "{Description}",
                        content: "<p>Asset ID:<b>{AssetID}</b></p>" +
                            "<p>Asset Status:<b>{AssetStatus}</b></p>"
                    };
                    var url = "http://tga-app-sandbox.tauranga.govt.nz:6080/arcgis/rest/services/TreeApp/TreeCapture_AllMaintainenceAreas/FeatureServer/1";
                    var featureLayer = new FeatureLayer({
                        url: url,
                        outFields: ["*"],
                        popupTemplate: template
                    });

                    var map = new Map({
                        basemap: "hybrid",
                        spacialReference: featureLayer.spacialReference
                    });

                    var view = new MapView({
                        container: "viewDiv",
                        map: map,
                        zoom: 16,
                        center: [176.2, -37.7],
                        spacialReference: featureLayer.spacialReference
                    });
                   
                    on(dojo.query("#default"), "click", function () {
                        var params = new Query({
                            returnGeometry: true,
                            outFields: ["*"]
                        });
                        params.where = 'AssetID = 141971';
                        var qTask = new QueryTask({
                            url: url
                        });
                        qTask.execute(params)
                            .then(function (response) {
                                if (!response || !response.features) {
                                    console.log("Asset not found.");
                                    return;
                                }
                                console.log(response.features);
                                view.goTo(response.features[0], { zoom: 18 });
                                //view.goTo({
                                //    target: new Point({
                                //        x: response.features[0].geometry.x,
                                //        y: response.features[0].geometry.y,
                                //        spatialReference: response.features[0].geometry.spatialReference
                                //    }), zoom: 18
                                //});
                            })
                            .otherwise(function (err) {
                                console.log(err);
                            });
                    });
                    map.add(featureLayer);
                    view.then(function () {
                        var params = new Query({
                            returnGeometry: true,
                            outFields: ["*"]
                        });
                        params.where = 'AssetID = 115576';
                        var qTask = new QueryTask({
                            url: url
                        });
                        qTask.execute(params)
                            .then(function (response) {
                                if (!response || !response.features) {
                                    console.log("Asset not found.");
                                    return;
                                }
                                console.log(response.features);
                                view.goTo(response.features, {zoom: 5});
                            })
                            .otherwise(function (err) {
                                console.log(err);
                            });
                    }, function(error){
                        console.log( error);
                    });

                });

 

What am i doing wrong? Neither of my view.goTo functions work?!

Outcomes