Difference between revisions of "Google Maps"
m (→Populating the popup box with data via AJAX) |
(→Retrieving the location data via AJAX: traillocations action) |
||
| Line 18: | Line 18: | ||
== Retrieving the location data via AJAX == | == Retrieving the location data via AJAX == | ||
[[File:AjaxMap - ajax result.jpg|500px]] | [[File:AjaxMap - ajax result.jpg|500px]] | ||
| + | |||
| + | {{code|<php>function onUnknownAction( $action, $article ) { | ||
| + | if( $action == 'traillocations' ) { | ||
| + | global $wgOut; | ||
| + | $wgOut->disable(); | ||
| + | header( 'Content-Type: application/json' ); | ||
| + | $comma = ''; | ||
| + | print "{\n"; | ||
| + | foreach( self::getTrailLocations() as $pos => $trails ) { | ||
| + | print "$comma\"$pos\":[\"" . implode( '","', $trails ) . "\"]\n"; | ||
| + | $comma = ','; | ||
| + | } | ||
| + | print "}\n"; | ||
| + | } | ||
| + | return true; | ||
| + | } | ||
| + | </php> | ||
== Creating a custom popup box using the overlay method == | == Creating a custom popup box using the overlay method == | ||
Revision as of 15:18, 17 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.
Contents
Semantically annotating the infobox template
Retrieving the location data via AJAX
{{code|<php>function onUnknownAction( $action, $article ) { if( $action == 'traillocations' ) { global $wgOut; $wgOut->disable(); header( 'Content-Type: application/json' ); $comma = ; print "{\n"; foreach( self::getTrailLocations() as $pos => $trails ) { print "$comma\"$pos\":[\"" . implode( '","', $trails ) . "\"]\n"; $comma = ','; } print "}\n"; } return true; } </php>




