Change District Lookup Widget's zoom extent?

1251
5
Jump to solution
09-01-2016 06:24 AM
KevinPiraino3
New Contributor II

Currently I am having an issue configuring a polling place locator app where I need to control the zoom extent of the District Lookup widget. The problem I am running into is that in some areas one polling place serves multiple precincts or districts. This is problematic because when a point is placed inside a district where the polling place resides outside of the district, the default selected zoom extent of the widget only zooms to the extent of the district only. I would like to be able to change this function so that when a point is placed inside a district the default selected zoom extent would always include both the district and the point to which it is related. Thus when a user places a point in a district where a polling place doesn't reside within, the default selected zoom extent would include both the district to which the user the resides as well as the polling place to which they must attend.

If there is a work around for this issue or if I am missing a function outside of the widget that would fix this issue I would greatly appreciate any input.

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Kevin,

I may have figured this out.  I've attached the updated Widget.js file.  I added a couple variables throughout the script and update one of the functions.

_highlightPollingPlacePoint: function (selectedPollingPlace) {
      //Add pollingPlace graphic on graphicLayer
      var highlightGraphic = this._getPointSymbol(
        selectedPollingPlace, this._pollingPlaceLayer);
      this._highlightGraphicsLayer.add(highlightGraphic);
       var xmin = (pollingPlacePt.geometry.x < precinctExtent.xmin) ? pollingPlacePt.geometry.x:precinctExtent.xmin;
       var xmax = (pollingPlacePt.geometry.x > precinctExtent.xmax) ? pollingPlacePt.geometry.x:precinctExtent.xmax;
       var extent = new Extent(xmin, precinctExtent.ymin, xmax, precinctExtent.ymax, new SpatialReference({ wkid:102100 }));
       this.map.setExtent(extent.expand(1.5));
    },‍‍‍‍‍‍‍‍‍‍

The code will compare the Polling Place x coordinate to the Precinct's xmin and xmax.  If it's smaller/larger than the xmin/xmax, it will use the point geometry x coordinate.

View solution in original post

5 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Kevin,

I may have figured this out.  I've attached the updated Widget.js file.  I added a couple variables throughout the script and update one of the functions.

_highlightPollingPlacePoint: function (selectedPollingPlace) {
      //Add pollingPlace graphic on graphicLayer
      var highlightGraphic = this._getPointSymbol(
        selectedPollingPlace, this._pollingPlaceLayer);
      this._highlightGraphicsLayer.add(highlightGraphic);
       var xmin = (pollingPlacePt.geometry.x < precinctExtent.xmin) ? pollingPlacePt.geometry.x:precinctExtent.xmin;
       var xmax = (pollingPlacePt.geometry.x > precinctExtent.xmax) ? pollingPlacePt.geometry.x:precinctExtent.xmax;
       var extent = new Extent(xmin, precinctExtent.ymin, xmax, precinctExtent.ymax, new SpatialReference({ wkid:102100 }));
       this.map.setExtent(extent.expand(1.5));
    },‍‍‍‍‍‍‍‍‍‍

The code will compare the Polling Place x coordinate to the Precinct's xmin and xmax.  If it's smaller/larger than the xmin/xmax, it will use the point geometry x coordinate.

KevinPiraino3
New Contributor II

Thank you Jake for your quick response and the updated widget code. Although I do have one question about implementing this updated widget. Since I am currently using ArcGIS online to host and server this app, how would I go about implementing this updated widget? Would I need to download my current app configuration and replace the District lookup widget with the widget you have provided and then re-upload it to ArcGIS online?

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Yes, you would need to download the application and replace the widjet.js file in the DistrictLookup folder with this one.

Unfortunately, you will not be able to host the application back in ArcGIS Online.  You will need to host the application on a web server.  Once the application is on a web server, you can still reference the app using ArcGIS Online so that it's discoverable within your Organization, but it will still be sitting on the web server.

KevinPiraino3
New Contributor II

Okay, that's what I thought. This may be the route we end up taking to ultimately finish the application.

Thanks again for the help.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Also, if you haven't already, take a look at the Web AppBuilder (Developer Edition).  It allows you to create web applications locally that you can easily customize.

0 Kudos