Zoom to geoprocessor result

2638
7
08-18-2015 07:16 AM
DavidChevrier
Occasional Contributor II

Hi,

   This should be pretty easy, but I've tried a bunch of stuff and cant get it to work.  How do I zoom to the newly outputted feature layer created by a geoprocessing service I create.  Here is the code for I use to create it.  I've tried the commented out method for setting the map's extent with the test1 and test2 variables, but it doesn't work.

Thanks,

-dave

function gpJobComplete(jobinfo) {

  //get the result map service layer and add to map

  gp.getResultImageLayer(jobinfo.jobId, null, null, function (layer) {

    layer.setOpacity(0.7);

    layer.id = "Created Mammal Data";

    map.addLayers([layer]);

  });

  // var zoomLayer = map.getLayer('Created Mammal Data');

  // var test1 = webMercatorUtils.geographicToWebMercator(zoomLayer.fullExtent);

  // var test2 = zoomLayer.fullExtent;

  // map.setExtent(test1, true);

  map.on("layers-add-result", function (evtObj) {

    domUtils.show(dom.byId('legendWrapper'));

      if (!legend) {

        var layerInfo = array.map(evtObj.layers, function (layer, index) {

          return {

            layer: layer.layer,

            title: layer.layer.name

          };

        });

       

        legend = new Legend({

          map: map,

          layerInfos: layerInfo

        }, "legendWrapper");

        legend.startup();

      }

    });

  }

0 Kudos
7 Replies
TimWitt2
MVP Alum

You could do something like this:

   function zoomToData (featureLayer) {
      // Zoom to the collective extent of the data
      var multipoint = new Multipoint(map.spatialReference);
      arrayUtils.forEach(featureLayer.graphics, function (graphic) {
        var geometry = graphic.geometry;
        if (geometry) {
          multipoint.addPoint({
            x: geometry.x,
            y: geometry.y
          });
        }
      });

      if (multipoint.points.length > 0) {
        map.setExtent(multipoint.getExtent().expand(1.25), true);
      }
    }

Tim

0 Kudos
DavidChevrier
Occasional Contributor II

Hmm.... this is failing with a weird "typeerror: d is not a function".  My guess is this is because I don't have a required statement.  This is just part of a big project, so here are the ones I have.  Am I missing one?

require(["dojo/dom",

                 "dojo/_base/array",

                 "dojo/date/locale",

                 "dijit/registry",

                 "esri/domUtils",

                 "esri/map",

                 "esri/dijit/Scalebar",

                 "esri/dijit/OverviewMap",

                 "esri/graphic",

                 "esri/layers/ArcGISDynamicMapServiceLayer",

                 "esri/layers/GraphicsLayer",

                 "esri/layers/FeatureLayer",

                 "esri/tasks/Geoprocessor",

                 "esri/tasks/FeatureSet",

                 "esri/dijit/Legend",

                 "dojo/parser",

                 "esri/symbols/SimpleFillSymbol",

                 "esri/symbols/SimpleLineSymbol",

                 "esri/SpatialReference",

                 "esri/dijit/PopupTemplate",

                 "esri/renderers/smartMapping",

                 "dojo/dom-construct",

                 "dojo/data/ItemFileReadStore",

                 "dijit/form/FilteringSelect",

                 "esri/graphicsUtils",

                 "esri/Color",

                 "dijit/layout/BorderContainer",

                 "dijit/layout/ContentPane",

                 "dijit/layout/AccordionContainer",

                 "esri/geometry/webMercatorUtils",

                 "esri/geometry/Geometry",

                 "dijit/form/Select",

                 "dijit/Dialog",

                 "dijit/form/Button",

                 "dijit/form/DateTextBox",

                 "dojo/domReady!"],

                 function (dom,

                           arrayUtils,

                           locale,

                           registry,

                           domUtils,

                           Map,

                           Scalebar,

                           OverviewMap,

                           Graphic,

                           ArcGISDynamicMapServiceLayer,

                           GraphicsLayer,

                           FeatureLayer,

                           Geoprocessor,

                           FeatureSet,

                           Legend,

                           parser,

                           SimpleFillSymbol,

                           SimpleLineSymbol,

                           SpatialReference,

                           PopupTemplate,

                           smartMapping,

                           domConstruct,

                           ItemFileReadStore,

                           FilteringSelect,

                           graphicsUtils,

                           Color,

                           BorderContainer,

                           ContentPane,

                           AccordionContainer,

                           webMercatorUtils,

                           Geometry) {

0 Kudos
TimWitt2
MVP Alum

"esri/geometry/Multipoint" is missing

0 Kudos
DavidChevrier
Occasional Contributor II

Ah, I was forgetting that, but it still didn't work.  But I know why, it isn't a feature layer that is being returned, rather a ArcGISDynamicMayServiceLayer.  Any idea how to zoom to that?

0 Kudos
TerryGustafson
Occasional Contributor II

Tim,

How did you determine he was missing the "esri/geometry/Multipoint" requirement?

0 Kudos
TimWitt2
MVP Alum

Terry,

The code that I posted needed "esri/geometry/Multipoint"

var multipoint = new Multipoint(map.spatialReference);

and once he posted his 2nd post I went through the list and looked if he has it already included in his current code.

DavidChevrier
Occasional Contributor II

Yes.  But I've decided to take the results and turn them into a featurelayer instead.  So I'm able to zoom using

var graphicsExtent = graphicsUtils.graphicsExtent(features);

map.setExtent(graphicsExtent);

0 Kudos