Difference between revisions of "Google Maps"

From Organic Design wiki
(Selecting markers with SMW queries: description)
m (Selecting markers with SMW queries)
Line 80: Line 80:
  
 
== Selecting markers with SMW queries ==
 
== Selecting markers with SMW queries ==
This was achieved by allowing a ''query'' parameter to be added to the ''#ajaxmap'' parser-function that contains a SMW ''#ask'' query (or in fact any other kind of query that produces a list of title links as a result such as DPL). These article titles are then extracted out of the resulting list and included in the ''ajaxmap_opt'' array defined in the JavaScript for that map.
+
[[File:AjaxMaps - query.jpg|500px|left]]This was achieved by allowing a ''query'' parameter to be added to the ''#ajaxmap'' parser-function that contains a SMW ''#ask'' query (or in fact any other kind of query that produces a list of title links as a result such as DPL). These article titles are then extracted out of the resulting list and included in the ''ajaxmap_opt'' array defined in the JavaScript for that map.
  
 
The JavaScript Ajax request then includes these titles in its ''query'' parameter when it asks for the location information. This is not perfect because the list of titles should not have to be sent to and from the client, it would be better for the Ajax request to send just an identifier that the PHP can use to perform the ''#ask'' query then rather than performing it when the parser-function was first expanded.
 
The JavaScript Ajax request then includes these titles in its ''query'' parameter when it asks for the location information. This is not perfect because the list of titles should not have to be sent to and from the client, it would be better for the Ajax request to send just an identifier that the PHP can use to perform the ''#ask'' query then rather than performing it when the parser-function was first expanded.
[[File:AjaxMaps - query.jpg|500px]]
 
  
 
== Finishing up ==
 
== Finishing up ==

Revision as of 20:49, 18 January 2012

This was job which I did at the beginning of 2012 for Trail WIKI, I'm documenting it here because it involved many different interesting aspects and also included some useful information which will help with later jobs.

The wiki contains many pages which represent hiking trails. It uses an infobox template to that various information about each trail such as its distance, elevation and other attributes can be contained in a structured way in the article.

On the main page is a Google map which has markers for all the trails, and when one is clicked a popup is revealed containing a link to the associated trail article.

The client wanted to have this map functionality extended such that the infobox that pops up is customised to the style of the site and contains some of the key information from the trail article's infobox. Also he wanted to use the Semantic Maps extension so that he could have other maps throughout the wiki which shows only very specific sets of markers such as trails with a certain region or above a certain elevation.

Another issue is that the wiki will eventually contain thousands of trails, so the maps need to load the trail location data after the page has loaded, and the popup boxes in the markers need to load their content on-demand too.

Semantically annotating the infobox template

AjaxMap - Pages using coordinates property.jpg     AjaxMap - semantic markers.jpg

Retrieving the location data via AJAX

AjaxMap - ajax result.jpg


<js>$.ajax({

type: 'GET', url: mw.util.wikiScript(), data: { action: 'traillocations' }, dataType: 'json', success: function( data ) { for( i in data ) { var pos = i.split(','); var marker = new google.maps.Marker({ position: new google.maps.LatLng(pos[0], pos[1]), icon: icon, map: map, titles: data[i] }); google.maps.event.addListener( marker, 'click', function() { new InfoBox(this); }); } } });</js>


{{{1}}}

Creating a custom popup box using the overlay method

I started with this script from the exampled in the Google documentation.

AjaxMap - custom-overlay.jpg

Populating the popup box with data via AJAX

AjaxMap - multiple-results-one-location.jpg

{{{1}}}


AjaxMap - icons and data.jpg

Selecting markers with SMW queries

AjaxMaps - query.jpg

This was achieved by allowing a query parameter to be added to the #ajaxmap parser-function that contains a SMW #ask query (or in fact any other kind of query that produces a list of title links as a result such as DPL). These article titles are then extracted out of the resulting list and included in the ajaxmap_opt array defined in the JavaScript for that map.

The JavaScript Ajax request then includes these titles in its query parameter when it asks for the location information. This is not perfect because the list of titles should not have to be sent to and from the client, it would be better for the Ajax request to send just an identifier that the PHP can use to perform the #ask query then rather than performing it when the parser-function was first expanded.

Finishing up

AjaxMap - final result.jpg