how to change the zoom scale for the geocoder?

3966
17
Jump to solution
06-09-2015 07:23 AM
Pulaski_AreaGIS
New Contributor

I would like to set the geocoder to zoom to 1:1200.  I think I would change the expand.0.0625 for the Point geometry but I am not sure.

if (feature) {
          var resultGeometry = feature.geometry;
          if (resultGeometry.type === 'point') {
            anchorPoint = resultGeometry;
            zoomExtent = this.map.extent.centerAt(anchorPoint).expand(0.0625);
          } else if (resultGeometry.type === 'polyline') {
            anchorPoint = resultGeometry.getPoint(0, 0);
            zoomExtent = resultGeometry.getExtent().expand(1.1);
          } else if (resultGeometry.type === 'polygon') {
            anchorPoint = resultGeometry.getCentroid();
            zoomExtent = resultGeometry.getExtent().expand(1.1);
          } else if (resultGeometry.type === 'mulitpoint') {
            anchorPoint = resultGeometry.getPoint(0);
            zoomExtent = resultGeometry.getExtent().expand(1.1);
          } else {
            anchorPoint = resultGeometry;
            zoomExtent = this.map.extent;
          }
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Pulaski Area GIS,

  Well this took some figuring....

Make these changes and you should be able to get the point geocode to use a different scale (assuming that 1200 is different from what is already returning, I tested with a larger scale 4513.988705).

in the showResults function (line one is very important):

geocoder.autoNavigate = false;


          if (resultGeometry.type === 'point') {
            anchorPoint = resultGeometry;
            //zoomExtent = this.map.extent.centerAt(anchorPoint).expand(0.0625);
            this.map.setScale(4513.988705);
            this.map.centerAt(anchorPoint);
          }

In the setupInfoWindowAndZoom function change the single line for:

this.map.setExtent(newExtent);

to

        if(geocodeResult.feature && geocodeResult.feature.geometry.type !== 'point'){
          this.map.setExtent(newExtent);
        }

View solution in original post

17 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Pulaski Area GIS,

  change the point logic something like this:

zoomExtent = this.map.extent.centerAt(anchorPoint);

this.map.setScale(1200);

Pulaski_AreaGIS
New Contributor
if (feature) {
          var resultGeometry = feature.geometry;
          if (resultGeometry.type === 'point') {
            anchorPoint = resultGeometry;
            zoomExtent = this.map.extent.centerAt(anchorPoint);this.map.setScale(1200);
          } else if (resultGeometry.type === 'polyline') {
            anchorPoint = resultGeometry.getPoint(0, 0);
            zoomExtent = resultGeometry.getExtent().expand(1.1);
          } else if (resultGeometry.type === 'polygon') {
            anchorPoint = resultGeometry.getCentroid();
            zoomExtent = resultGeometry.getExtent().expand(1.1);
          } else if (resultGeometry.type === 'mulitpoint') {
            anchorPoint = resultGeometry.getPoint(0);
            zoomExtent = resultGeometry.getExtent().expand(1.1);
          } else {
            anchorPoint = resultGeometry;
            zoomExtent = this.map.extent;
          }

I tried this but did get any result in the app.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Pulaski Area GIS,

   Make sure you are changing the widget.js for the Geocoder widget in the particular app you are testing. If you make the change in the client stemapp folder then you will only see the change in a new app.

Pulaski_AreaGIS
New Contributor

I checked that, still see no change in the zoom levels.  Thanks for the help.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Pulaski Area GIS,

  Well this took some figuring....

Make these changes and you should be able to get the point geocode to use a different scale (assuming that 1200 is different from what is already returning, I tested with a larger scale 4513.988705).

in the showResults function (line one is very important):

geocoder.autoNavigate = false;


          if (resultGeometry.type === 'point') {
            anchorPoint = resultGeometry;
            //zoomExtent = this.map.extent.centerAt(anchorPoint).expand(0.0625);
            this.map.setScale(4513.988705);
            this.map.centerAt(anchorPoint);
          }

In the setupInfoWindowAndZoom function change the single line for:

this.map.setExtent(newExtent);

to

        if(geocodeResult.feature && geocodeResult.feature.geometry.type !== 'point'){
          this.map.setExtent(newExtent);
        }
Pulaski_AreaGIS
New Contributor

Robert, 

This worked but the Image is not refreshing on zoom.  Any thoughts?

Thanks

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Pulaski Area GIS,

but the Image is not refreshing on zoom

??? What image?

Are there any errors in the web console?

0 Kudos
Pulaski_AreaGIS
New Contributor

Sorry, the basemap is not refreshing to the new scale.  I have one console error but is was there before, I started this.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Pulaski Area GIS,

   Make sure that you are setting a scale that is equal to one of your maps LODs.