Archive for August, 2008
Click here to see the example and then we’ll discuss the code used to create this simple application. As I mentioned above the data for this application was pulled from an ArcGIS Server map service provided by ESRI, and the graphic point was generated based on an address that was geocoded by the Google Maps API. If you’d like to see the code simply right click the page and then select View Page Source.
Step 1: Reference the Google Maps API
Before creating an instance of the Google Maps API geocoding object (GClientGeocoder) you must provide a reference to the API. This is accomplished as follows:
Note: You must have a Google Maps API key to access objects within the API.
Step 2: Create an Instance of GClientGeocoder
The GClientGeocoder class from the Google Maps API can be used to geocode addresses, and an instance of this class is created as follows:
Step 3: Call the getLatLng( ) method on GClientGeocoder
The getLatLng( ) method on GClientGeocoder accepts an address as the first parameter, and the second parameter is a callback function that will be run when data is returned from the method. A point object will be passed into the callback function. If the geocode of an address was successful this point will have geometry (x,y coordinates), and in the event that the object was not geocoded the point object will be null. Notice that in this case we’ve hard-coded an address that will be input into the getLatLng( ) method. This of course wouldn’t be acceptable in a real application, but the point here is simply to show how the objects work.
Step 4: Create ESRI Point, Symbol, and Graphic Objects
Step 5: Add the Graphic to the Display
In the code sample above, the map.graphics.add(pointGraphic) method adds our newly created graphic to the graphic list for the application. Any number of graphics of various types can be placed into this graphic list and each object is drawn on the display.
If you’d like more information on how to create ArcGIS Server and Google Maps applications with their respective APIs you might want to consider our upcoming course which still has 4 seats available. Contact eric at geospatialtraining.com for more information.Read Full Post | Make a Comment ( None so far )
If you’d like to see the full length syllabus for our upcoming instructor guided course, “Building Web 2.0 Mapping Applications with ArcGIS Server and Google Maps” please it can be found here. Additional details regarding the class can be found in the post below.Read Full Post | Make a Comment ( None so far )
The first session of this course will be delivered via the web starting October 20th and ending November 21st. Save 15% ($100) on this course when you register before September 5th.
This is an instructor guided course taught in a Virtual GIS Classroom using the same technologies implemented by colleges and universities around the world to deliver Internet based courses. Our new Virtual GIS Classroom blends the best of instructor led and e-learning formats into a new instructor led web based format that allows for more interactivity between the instructor and student, and between students.
This is an Internet delivered course that allows you to proceed through the materials at your own pace. There is NOT any particular time when you must be logged into the course. However, you will have access to the course instructor via chat sessions, discussion boards, and by phone.
- Web 2.0 Concepts Applied to GIS
- Basic ArcGIS Server Concepts
- Programming the Google Maps API
- Integrating ArcGIS Server with Google Maps
To obtain a full length syllabus for the course please contact eric at geospatialtraining.com
Who Should Attend?
This course is geared toward all levels of GIS professionals who need to create Rich Internet GIS Applications. No programming experience is necessary though it is helpful to have some knowledge and or experience of programming concepts.
We have room for a minimum of 4 students and a maximum of 12 students.
October 20th – November 21st – 2008
For more information please contact GeoSpatial Training Services at 210-260-4992 or eric at geospatialtraining.comRead Full Post | Make a Comment ( None so far )
Adding Event Listeners
Removing Event Listeners
You should always remove listeners when your application is being closed to avoid memory leaks. This can be accomplished through the use of the Map.onUnload event in conjunction with dojo.disconnect. The onUnload event is fired when the map is closed, and dojo.disconnect removes the connect between an event and the method being referenced.
Commonly Used Events
The Map object currently has 27 events that can be initiated including onClick, onExtentChange, onLayerAdd, onLoad, onMouseDrag, onMouseWheel, onZoom, onPan and many others. I should point out that it is not necessary to write listener code functions for every single event that can be triggered. You only write event handlers for those events that are necessary for your application. When an event is triggered for which you have not registered and written a handler, the event is simply ignored in the application. Several other objects provide important events including the Layer, GraphicsLayer, and InfoWindow.
In the event that you are using more than one service, the default extent will be the initial extent of the base map or first layer added.
Setting the Initial Extent
There are several options for setting the initial map extent through your code. The easiest way to do so is through the constructor for the map. The constructor for the Map object takes a required parameter which points to <div> element on your page, and an options parameter which can contain the initial extent of the map as well as other options such as the layer used to initialize the map, the inclusion of navigation controls, and others. Click here to see a full description of the available options that can be included in the constructor.
For instance, the following code snippet shows how you can accomplish setting the extent through the constructor. To set the initial extent of the map you will need to know the min and max x and y values of the extent.
You can also accomplish the same task but in a slightly different manner through the use of the setExtent method on Map as you see in the code example below.
You could also set each property of the extent separately.
Setting the Initial Extent when using Multiple Services
If you’re using multiple map services in your application, the default extent will be the initial extent of the base layer. If you know the extent you’d like to use ahead of time then you can include the extent in the map constructor as we’ve shown above. However, at times you will either not know the extent ahead of time or you may want to use the extent of a secondary layer. For instance, if you’re using a map service that shows the extent of the world as your base layer, and a second map service with your local data you’d probably want to set the extent of your application to that of your local data. The code example below from ESRI shows how this can be accomplished through the fullExtent property found on ArcGISMapServiceLayer.
Getting the Current Extent
You can obtain the current map extent through the read-only Map.extent property or through the use of events. The later method for returning the current map extent is through the use of Map events, and specifically the “onExtentChange” event. The topic of events requires a fair amount of explanation so I will save this for my next post, but for now here is an example which uses the “onExtentChange” event to return the current map extent which is then displayed in a <div> tag below the map.
- Create a <div> element to hold the map
- Initialize the map ojbect from the dojo.addOnLoad method
Obviously you’ll also want to add some layers to your map and this can be accomplished through either the ArcGISTiledMapServiceLayer or ArcGISDynamicMapServiceLayer. Below you’ll see how code examples for both types of layer.
The result of these few simple lines of code can be viewed here. I’d like to point out two additional things that you may have noticed. First, we did not specify any code to add map navigation controls or functionality. This is because the navigation tools are built into the API including a zoom control slider and the ability to use your mouse and keyboard for panning and zooming. I should also point out that it is not necessary to have ArcGIS Server loaded on your server. You simply need access to an existing map service somewhere on the web. In this case, we’re accessing web mapping services provided by one of ESRI’s sample ArcGIS Servers.
My first session this morning was “Framework for Building GIS Web Applications” with Clint Brown – Director of Software Products, ESRI.
“Everyone including your Grandma is using Google Earth so now you can finally explain what you do to family and friends and they’ll actually understand what you mean.”
So true. I’ve been trying to explain what I do to friends and family for the past 15 years and it wasn’t until Google Earth that the light actually turned on for them. Though it was a funny and applicable quote for most people, Clint went on to make an even more important point when he stated that
“Consumer maps like Google Earth/Google Maps and Virutal Earth have defined a new user experience and GIS applications will have to support this.” The expectations for GIS web applications have indeed changed as a result of these technologies. Given that these consumer products have essentially changed the way we think about how web based mapping applications should look and function, how should ESRI users go about creating similar types of applications? Clint described a four step framework for creating these Web 2.0 GIS applications to meet these requirements.
1. GIS Applications
- The programming is much simpler
- It doesn’t require any additional technology on the web application server. You simply need access to published web mapping applications somewhere on the web. Of course for most organizations this will mean that you do need to purchase ArcGIS Server. However, the point is a good one in that you can mashup the mapping services provided by your organization with other existing map services elsewhere on the web.
Of course technology does not exist in a vacuum and your web GIS application will only be useful to users if you meet their needs. Before building your application you need to identify your audience and the work tasks that they need to perform. You also need to identify the key information products that should be provided by the application.
2. Digital Base Map
In terms of the digital base map, the “consumer” mapping applications are essentially built using one map for each map scale. So, as you zoom in and out on the map, the application is toggling between the various base map versions. To simulate these various base maps in your web mapping application you will need to create group layers in the ArcMap table of contents. Each group layer should contain whatever information you want to represent at a specific scale. These layers will then turn on/off in your application as the user zooms in and out. As Clint mentioned, this is “really quite simple”. Assuming that you know how to create group layers in ArcMap containing your data and know how to set map scale drawing parameters you should be able to create these base layers easily. The prerequisite to that is obviously that you have obtained the data that you need to create the base map.
The other point that Clint made regarding your digital base map is that you don’t have to build it all. You should build maps for your area of interest or organizational responsibility and then take advantage of existing base maps such as ArcGIS Online, Google/Virtual Earth, and other GIS departments. Build the data for your area of interest and then leverage what already exists. Basically this is mashing up data from multiple providers for creating your digital base map data.
Finally, you will need to provide the ability to toggle between various basemap types. For example, in Google Maps you can toggle between vector maps, imagery, and hybrid. Your users will want to do this so make sure make sure you take the time to create the various base map types.
3. Define and Create Operational Map Layers
Operational map layers are non-base map layers that support the functionality provided by your application. Examples would include working layers, sensor feeds and observations, query results, and the results of analytical models created through geoprocessing tasks. Alternative ways to add operational information to your map applications include creating a map service for your operational layer, working with feature queries and the assignment of symbology.
4. Tasks and Tools in Your GIS Application
The final component of the framework is to add tools to work with your operational information. One of the most common tools is the Locator which allows your users to search for place names, addresses, points of interest, etc. The consumer mapping applications are really good at this, and you should plan to add this functionality. Additional tools include the use of map layers as interactive reports through popup description balloons, the ability to query, graph, report and visualize data that supports your map layers, and various tasks including geoprocessing models, queries, and other programs that your users might execute to generate a result.
Finally, Clint recommend a few final steps for implementing your application including the following:
- Plan for Hosting Strategies
- Test and refine your application, services, and contents
- Develop a strategy to maintain your website and content
In summary, Clint gave a really good fundamental overview of a development framework for building your Web 2.0 GIS applications. I was particulary pleased to see that ESRI has embraced the ease of use and capabilities provided by “consumer” mapping applications and extended it to include advanced GIS analysis and geoprocessing.Read Full Post | Make a Comment ( None so far )
It’s always good to be back in San Diego for the annual ESRI International User Conference! Getting out of the 100 degree heat of south Texas for a week is a bonus as well. I’ve always been impressed by the energy and focus of the conference, and this year is no different. I’ll be blogging this week on some of the more interesting developments to come out of the conference.
Later this week I’ll post some code examples that show you how easy it is to create these applications. For now, back to the opening session. Jack has made his entry!Read Full Post | Make a Comment ( None so far )