Virtual Earth Map in SharePoint Search Results

16 Mar

I often integrate Virtual Earth / Live Maps into MOSS because It’s a relatively easy way to add some interesting and useful interaction without any custom code.

I wanted to share with you the ‘default’ XSL template I typically start from for generating a Virtual Earth Map in my MOSS search results.  From here, I make whatever enhancements or customizations I want, which I’ll describe more in a moment.

The prerequisites here are that you have managed columns with Latitude and Longitude that are coming back in your search results (which means you’ve updated the columns XML to include them on the settings of your search core results webpart)

Here’s an example of the managed columns I’ve got, and will be using — It’s simply an addition of Lat and Lon, and utilization of the existing Title column.  On the right is my updated XML that goes in the columns property of the core results part:

image image

This data could come from a BDC connection to an external data source (e.g. SQL), or you could have a content type or list that has the Lat/Lon information in it.

(If you have a big list or table of data with addresses, and want to generate the coordinates for them, I recommend using this tool: http://www.batchgeocode.com/, You can export your list to excel, save as a delimited format, geocode, and re-import)

So once you have your columns available, this is the base XSL you can put in your core results part to generate a map, and put Push Pins with a popup for the Title at all the correct locations:

 

<a href="/file.axd?file=2009%2f3%2fmaptransform.xsl">maptransform.xsl (2.34 kb)</a><span class="kwrd"></span>

 

The XSL does the following:

  1. Create a div for the map
  2. Includes the Virtual Earth javascript
  3. Write javascript for creating the map, creating a shape array, and pushing the CreateMap function into the body load for sharepoint (_spBodyOnLoadFunctionNames)
  4. Use the XSL to generate a bunch of calls to “Add Shape” based on the search results, to add in all the points.  You could expand this to add any HTML into the pushpin popup, such as content from the result item.

 

You will need to update the Map.LoadMap call to set the zoom level and coordinates to center on (currently its in Redmond, Washington, at a high zoom).

You can build on this using the ability to drag areas of the map to refine search results, or use the built in clustering ability to cluster large groups at different zoom levels.

Good luck!

Tweet about this on TwitterShare on Google+Share on FacebookShare on RedditEmail this to someoneShare on LinkedInShare on StumbleUpon

Leave a Reply

Your email address will not be published. Required fields are marked *