Building a Wildfire Mashup with ArcGIS Server and Google Maps – Post 5 of 5
In the fifth and final installment of our series on building a wildfire mashup with ArcGIS Server and Google Maps we will access the Drive Time geoprocessing task provided on the ESRI Sample Server to create drive time polygons for an address that has been selected on the grid. Please visit the other posts in this series to familiarize yourself with this series.
Section 5: Create Drive Time Polygons for Address
What we’re going to do in this final post is add drive time polygons to the map display when an address is clicked in the Dojo grid.
• Open the GMaps_AGIS_Mashup.htm file found in the C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lab folder. You’ll need to refer back to the first post in this series for details on obtaining the files for this exercise along with directions on setting up the exercise.
• Examine the details of the CreateDriveTimePolygons geoprocessing service
Open a web browser and navigate to: http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Network/ESRI_DriveTime_US/GPServer/CreateDriveTimePolygons
This geoprocessing task accepts an input location in the form of a recordset as well as a string that specifies drive times in minutes. For example, the default drive times are “5 10 15”. This is a string variable with each drive time separated by a space. The maximum drive time is 15 minutes.
• Create a new variable that points to the ESRI Drive Time Geoprocessing task
Add the following line of code to the bottom of the ‘initialize’ function
• In this case we are going to want our drive time polygons to be calculated based on one of the addresses that has been clicked inside the grid. Therefore, we need to set up a listener function on the Grid.onRowMouseDown event. This event will pull the latitude and longitude coordinates from the row that was clicked, and create a new GMarker object using this data. Finally, this marker will be passed into a new function that we’ll create called ‘getDriveTimePolys’ which will actually execute the geoprocessing task on ArcGIS Server. Add the following code block inside the ‘createGrid’ function just below the ‘gridWidget.setStructure(layout);’ line.
From a previous lesson you should recognize that we use dojo.connect to register an event with a listener. In this case we are registering the Grid.onRowMouseDown event to the function you see here. Therefore, each time a user clicks a row in the grid, this function will be executed. Inside this function the latitude and longitude coordinates are pulled from the current row and passed into the GLatLng constructor. The new instance of GLatLng (‘point’) is then used in the constructor for GMarker. Finally, the new instance of GMarker (‘marker’) is passed into the ‘getDriveTimePolys’ function.
• Create the getDriveTimePolys function
Add the following function:
As I already mentioned, a new instance of GMarker is stored in the parameter ‘point’ which is passed into the ‘getDriveTimePolys’ function. Inside this function we first use the MapExtension.removeFromMap method to remove any existing drive time polygons, and then we create two new variables to hold a both a featureset and a feature. The feature object has a geometry which we set using the point which has been passed into the function. This feature is then added to FeatureSet.features which contains an array of feature objects. In this case we only have a single feature. Next, we create a variable called ‘params’ which stores the input parameters that need to be passed into the drive times geoprocessing task. You’ll notice that we are passing in the featureset that contains only our point as well as drive times of 1, 2, and 3 minutes. The final step is to call the ‘execute’ method on our task, passing in the parameters, a flag indicating whether the results should be returned as KML (not in this case since we pass a value of false), and the name of the callback function (addResults) that will be executed when processing has completed.
• Create the addResults function
Add the following function just below the ‘getDriveTimePolys’ function. This function simply takes the result set that is returned by the geoprocessing task and adds it to the map using MapExtension.addToMap.
• Create zoomAddress function
You may have noticed that in the ‘getDriveTimePolys’ function a function called ‘zoomAddress’ is called and the point that was created from the row in the table is passed into this function. The ‘zoomAddress’ function simply recenter the map to this point and zooms in. Add the following code just below the ‘addResults’ function.
• View the current state of the application
Save your file, and point your web browser to http://localhost/lab/GMaps_AGIS_Mashup.htm
You will need to Refresh the screen if your browser is already pointing to this address. Click the ‘Add Witch Fire’ button and wait for the boundaries of the fire to be displayed. Then, click the ‘Add Destroyed Homes’ button. Finally, select a record from the grid that was created. You should see a figure similar to the following:
The next session of our “Building Web 2.0 Mapping Applications with ArcGIS Server and Google Maps” is scheduled for January 12th – February 13th. You can register on our website or by contacting eric at geospatialtraining.com. See the full course syllabus