AnsweredAssumed Answered

How do I plot a point returned from QueryTask with dojo???

Question asked by lgoens on Feb 18, 2015
Latest reply on Feb 18, 2015 by lgoens

I need some direction on how I should approach my widget. The basic function of the widget is to display order information. Each order will consist of 2 items (loaded into a tab control), an overview and an order instruction. This information is contained in two individual html pages - one page for overview and one for the instruction. In my widget.js, I am populating a ContentPane within a tab control (in widget.html) with the contents of the overview.html and instruction.html files from my Orders directory. My tab control works great with two tabs (overview \ instruction).

 

My question now is, within the instruction.html file that is loaded into the instruction tab, I'd like to place a button control / dijit that runs a simple querytask to fetch the site/location of where an order's work needs to be performed and then plot it on the map within the application that contains my widget. I am executing the querytask and receiving the results back (within instruction.html - NOT widget.html/js) - how do I plot this on the application's map?

 

How do I access the application's map when I'm querying from a file that didn't create the map?

 

I DO know the map container's id and am ok hardcoding that into the instruction.html page as the map div's id will never change... if I can access it this way somehow.

 

Here is my button code from instruction.html. I'm completely new to dojo so please call me out on anything wildly out of convention:

<button data-dojo-type="dijit/form/Button" type="button">
    Zoom to Site

    <script type="dojo/on" data-dojo-event="click" data-dojo-args="evt">
    
        require([
        "dojo/ready",
        "esri/tasks/query",
        "esri/tasks/QueryTask",
        "esri/map",
        "esri/graphic",
        "esri/layers/GraphicsLayer",
        "esri/symbols/SimpleMarkerSymbol"
        ], function(ready,
        Query,
        QueryTask,
        Map,
        Graphic,
        GraphicsLayer,
        SimpleMarkerSymbol) {
        ready(function() {
        
        var queryTask = new QueryTask(<URL REMOVED>);
        var query = new Query();
        query.returnGeometry = true;
        query.where = "OBJECTID = 696";

        queryTask.execute(query, showResults);
        });

        function showResults(results) {
            
            alert("show results called");
            
            //Here is where i'm uncertain of how to plot the result on the applications map... 
            //The application's map div id is "map"

            //From here down does not work and where I need help@ as I'm guessing :( 
            var appMap = dojo.byId("map"); 

            appMap.graphics.clear();

            var serviceLocationGraphicsLayer = new GraphicsLayer();
            var markerSymbol = new SimpleMarkerSymbol();
            markerSymbol.setPath("M16,3.5c-4.142,0-7.5,3.358-7.5,7.5c0,4.143,7.5,18.121,7.5,18.121S23.5,15.143,23.5,11C23.5,6.858,20.143,3.5,16,3.5z M16,14.584c-1.979,0-3.584-1.604-3.584-3.584S14.021,7.416,16,7.416S19.584,9.021,19.584,11S17.979,14.584,16,14.584z");
            markerSymbol.setColor("00FF00");

            var resultCount = results.features.length;
            for (var i = 0; i < resultCount; i++) {
                var graphic = results.features[i];
                graphic.setSymbol(markerSymbol);

                serviceLocationGraphicsLayer.add(graphic);
            }

             appMap.addLayer(serviceLocationGraphicsLayer);
        };
    });
</script>

Outcomes