Select to view content in your preferred language

Extract data AMD widget

1624
5
03-21-2014 10:17 AM
AlexGole1
New Contributor II
Hi,
I was wondering if anybody had samples/examples on how to implement this widget. I am already using this script which works well but I would like to customize it so the users can extract data by a specific extent (chosen county, parcel unit ect...)
Thank you,
Alex
0 Kudos
5 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Alex,

Take a look at this thread.  There is an example where you can select a graphic and export it to a shapefile through the infoWindow.
0 Kudos
WhereMatters
Occasional Contributor

Hi Jake,

I am not able to click on the link you mention in your reply to Alex. I tried viewing this in the latest version of Chrome as well as IE 11 and the links are just not clickable although they look like links, i mean they are blue (or greyish blue, cant really tell)  in color. Can you please provide the full link?

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Hi Anand,

Looks like the migration to GeoNET broke some hyperlinks.  Below is the code:

<!DOCTYPE html>

<html>

  <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <!--The viewport meta tag is used to improve the presentation and behavior of the samples

      on iOS devices-->

    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">

    <title></title>

    <link rel="stylesheet" href="http://js.arcgis.com/3.8/js/esri/css/esri.css">

    <style>

      html, body, #mapDiv {

        padding:0;

        margin:0;

        height:100%;

      }

     

      #loading {

        display: none;

        vertical-align: middle;

      }

    </style>

    <script src="http://js.arcgis.com/3.8/"></script>

    <script>

      var map, featureLayer, gp;

      require([

        "esri/map", "esri/config", "esri/layers/FeatureLayer", "esri/InfoTemplate", "esri/tasks/FeatureSet", "esri/geometry/Extent",

        "esri/layers/GraphicsLayer", "esri/tasks/Geoprocessor",

        "dijit/form/Button", "dojo/parser", "dijit/registry", "dojo/dom", "dojo/on", "dojo/dom-style", "dojo/domReady!"

      ], function(

        Map, esriConfig, FeatureLayer, InfoTemplate, FeatureSet, Extent,

        GraphicsLayer, Geoprocessor,

        Button, parser, registry, dom, on, domStyle

      ) {

         

        parser.parse();   

       

        esriConfig.defaults.io.proxyUrl = "proxy.ashx";

       

        var loading = dom.byId("loading");  

       

        map = new Map("mapDiv", {

          basemap: "streets",

          center: [-117.1625, 32.7150],

          zoom: 13

        });

       

        var infoTemplate = new InfoTemplate("Details", "<tr>OBJECTID: <td>${objectid}</tr></td><br><br><button id='button' dojoType='dijit.form.Button'>Export</button>");

       

        featureLayer = new FeatureLayer("http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/Incident_Data_Extraction...",{

            mode: FeatureLayer.MODE_ONDEMAND,

            infoTemplate: infoTemplate,

            outFields: ["*"]

        });               

        map.addLayer(featureLayer);  

       

        gp = new Geoprocessor("http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/HomelandSecurity/Incident_Data_Extraction...");

                gp.setOutSpatialReference({

                    wkid : 102100

        });

       

        on(map.infoWindow, "show", function(){

          on(dom.byId("button"), "click", extractData);

        })

       

        function pointToExtent(map, pointX, pointY, tolerance){

            var xmin = pointX - tolerance;

            var ymin = pointY - tolerance;

            var xmax = pointX + tolerance;

            var ymax = pointY + tolerance;

           

            return new Extent(xmin, ymin, xmax, ymax, map.spatialReference)

        }

       

        function extractData() {           

            var extent = pointToExtent(map, map.graphics.graphics[0].geometry.x, map.graphics.graphics[0].geometry.y, 10);

            map.graphics.add(extent);

           

            var featureSet = new FeatureSet();

            var features = [];

            features.push(map.graphics.graphics[0]);

            featureSet.features = features;

            var params = {

                "Layers_to_Clip" : ["Incident Areas"],

                "Area_of_Interest" : featureSet,

                "Feature_Format" : "Shapefile - SHP - .shp"

            }; 

                  

           

            domStyle.set(loading, "display", "inline-block");

            gp.submitJob(params, completeCallback, statusCallback, function(error) {

                alert(error);

                domStyle.set(loading, "display", "none");

            });

        }

        function completeCallback(jobInfo){

          if ( jobInfo.jobStatus !== "esriJobFailed" ) {

            gp.getResultData(jobInfo.jobId, "Output_Zip_File", downloadFile);

          }

        }

        function statusCallback(jobInfo) {

          var status = jobInfo.jobStatus;

          if ( status === "esriJobFailed" ) {

            alert(status);

            domStyle.set("loading", "display", "none");

          }

          else if (status === "esriJobSucceeded"){

            domStyle.set("loading", "display", "none");

          }

        }

        function downloadFile(outputFile){                        

          var theurl = outputFile.value.url;

          window.location = theurl;

        }

      });

    </script>

  </head> 

  <body>   

    <div id="mapDiv">

        <img id="loading" src="images/loading.gif">

    </div>   

  </body>

</html>

0 Kudos
WhereMatters
Occasional Contributor

Thanks Jake this helps.

Can you please take a look at a related question I posted and let me know if you have any ideas/suggestions?

https://community.esri.com/message/397744?sr=search&searchId=f7f71b54-ca93-49f3-893b-8a8a41937623&se...

0 Kudos
AlexGole1
New Contributor II
Hi Alex,

Take a look at this thread.  There is an example where you can select a graphic and export it to a shapefile through the infoWindow.


That is a great script I will add this to my web map app. I would also need to be able to export data by a simple definition query. For instance, I have a Feature layer containing the wildfires areas(polys) that has one field called county. I would love users to be able to extract data by a simple field SQl query. For instance:  if "county" = "Alameda" then export to shp. Any ideas on how to proceed for such a task?
Thank you,
Alex
0 Kudos