Zoom to Issues

1385
12
Jump to solution
04-04-2017 06:51 AM
jaykapalczynski
Frequent Contributor

I included the relevant code I think for this issue....

I have my Map

I am setting the spatial reference of the query results

Using the results to create a new graphics Layer

The Graphics are located in the correct position so that works fine... 

BUT when the below runs it zooms off the coast of Africa.  I know this is a Spatial Reference issue but not sure where and how to set it...

Thoughts?

var extGraphics = graphicsUtils.graphicsExtent(map.graphics.graphics);
map.setExtent(extGraphics);

    //SET THE MAP
    var map = new Map("map", {
        basemap: "dark-gray",
        center: [-79.665, 37.629],
        zoom: 8,
        logo: false,
        showLabels: true
    });


      // QUERY FOR County and Squad
      var queryTask = new QueryTask("https://vafwisdev.dgif.virginia.gov/arcgis/rest/services/Projects/Summons/FeatureServer/5");
      var query = new Query();
       query.outSpatialReference = {wkid: 4326}; //4326 //102100 //3857
       query.returnGeometry = true;

/// SNIP

      var countiesGraphicsLayer = new GraphicsLayer({opacity:0.75});

      //This is the click event for the graphics on the map
      countiesGraphicsLayer.on("click", selectGrid);
      map.addLayer(countiesGraphicsLayer);

/// SNIP

        arrayUtils.map(results.features, function(feature) {
          feature.setSymbol(symbol);
          feature.setInfoTemplate(infoTemplate);
          countiesGraphicsLayer.add(feature);
           
          var featureAttributes = feature.attributes;
          for (var attr in featureAttributes) {
            resultItems.push("<b>" + attr + ":</b>  " + featureAttributes[attr] + "<br>");
          }
          resultItems.push("<br>");
        });
        dom.byId(ActivePane).innerHTML = resultItems.join("");

          var extGraphics = graphicsUtils.graphicsExtent(map.graphics.graphics);  
        map.setExtent(extGraphics); ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

/// SNIP‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Jay,

   Your next issue is this line:

var extGraphics = graphicsUtils.graphicsExtent(map.graphics.graphics);

you are not adding your results to map.graphics anymore:

var extGraphics = graphicsUtils.graphicsExtent(countiesGraphicsLayer.graphics);

View solution in original post

0 Kudos
12 Replies
RobertScheitlin__GISP
MVP Emeritus

Jay,

   You are using an esri basmap which is in WKID 102100 but when you query your map service you are setting the out spatial reference to WKID 4326. That would cause your issue.

you should use:

query.outSpatialReference = map.spatialReference;
0 Kudos
jaykapalczynski
Frequent Contributor

If I do this

query.outSpatialReference = map.spatialReference;

and may map looks like this:

var map = new Map("map", {
basemap: "dark-gray",
center: [-79.665, 37.629],
zoom: 8,
logo: false,
showLabels: true
});

Now its not only zooming to Africa but drawing the graphics there....tried clearing my cache etc...

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   Your next issue is this line:

var extGraphics = graphicsUtils.graphicsExtent(map.graphics.graphics);

you are not adding your results to map.graphics anymore:

var extGraphics = graphicsUtils.graphicsExtent(countiesGraphicsLayer.graphics);
0 Kudos
jaykapalczynski
Frequent Contributor

I got it to work but ONLY by setting it this way.

query.outSpatialReference = {wkid: 102100};

if I use this is does not work.

query.outSpatialReference = map.spatialReference;

0 Kudos
jaykapalczynski
Frequent Contributor

Its working but zooming in a bit much....can I back off the zoom a little bit to include all the graphics?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Strange indeed. Working off the code I provided in your previous question I had no problem using 

query.outSpatialReference = map.spatialReference;

and 

var extGraphics = graphicsUtils.graphicsExtent(countiesGraphicsLayer.graphics);
0 Kudos
jaykapalczynski
Frequent Contributor

think its working now...ONE second.....Thanks Again dude....BRB

0 Kudos
jaykapalczynski
Frequent Contributor

seems to be working now....but still have to set the spatial reference to

query.outSpatialReference = {wkid: 102100};

instead of query.outSpatialReference = map.spatialReference;

Last question....is there a way to set the extent but then back off a bit....it zooms fine but a little to close for my liking...can I back off a fraction or some setting.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Jay,

   Just use:

map.setExtent(extGraphics.expand(1.2));