GeocachingAustPrint

From GeoWiki
Revision as of 11:46, 16 January 2007 by Zactyl (talk | contribs) (Added download link)
Jump to: navigation, search

printing Geocaching Caches

Currrent the GeoCaching.com website uses MapQuest data which is fine the the US where these maps have good coverage but for us Ozzies, particularly outside the main Citys there the maps are pretty useless


GreaseMonkey

This is an addon to Firefox [GreaseMonkey website]


The Script

This code will replace the MapQuest graphic when viewing Cache data on the Geocaching.com site "when formatted for Print" . ie you have selected the link which formats the page for print friendly output. Install the script as filename : GeocachingAustPrint.user.js (then open with Firefox) or click here.

/*
Geocaching OS Maps - 0.2 14/01/2007
Copyright (c) 2007, Paul Wilson
Released under the GPL http://www.gnu.org/copyleft/gpl.html

This is a Greasemonkey user script, see http://greasemonkey.mozdev.org/.

This substitutes the lame MapQuest map on cache printout mainly for an
OS map (where MapQuest coverage is not that good)


Modified by Paul Wilson 11th Jan 2007 to work for Australian Maps for printing
*/

// ==UserScript==
// @name          GeocachingAustPrint
// @namespace     http://www.geocaching.com.au/
// @description	  Replaces the MapQuest graphic with Google Maps image
// @include       http://www.geocaching.com/seek/cache_details.aspx?pf=y*
// ==/UserScript==

var win=window;
if (unsafeWindow)
{
	win=unsafeWindow;
}


	var LatLon=document.getElementById("LatLon");
	if (LatLon) {
    var coords=LatLon.innerHTML;
	  //GM_log(coords);
	 
	 	var pattern=/([NS])\s*(\d+)[\xb0\s]+(\d+\.\d+)\s+([WE])\s*(\d+)[\xb0\s]+(\d+\.\d+)/i;
	 	//    pattern=/([NS])\s*(\d+)/i;
		var matches=coords.match(pattern);
	  if (matches) {

	     //for (counter = 0; counter < matches.length; counter++) { GM_log("matches="+counter+'.'+matches[counter]);        }
	     
	     latnorth=matches[1]
	     lat1=matches[2]
	     lat2=matches[3]
	     lonwest=matches[4]
	     long1=matches[5]
	     long2=matches[6]
                    	   
      //GM_log( 'Lat:'+latnorth+lat1+' :'+lat2+': - Long:'+lonwest+long1+' '+long2)
      latdir=''
      longdir=''
      if (latnorth == 'S') latdir='-'
      if (lonwest == 'W') longdir='-'
      latdec=Math.round(lat1)+lat2/60
      londec=Math.round(long1)+long2/60
      gmdatalat=latdir+latdec.toFixed(6)
      gmdatalon=longdir+londec.toFixed(6)
      //GM_log( 'Latdec:'+gmdatalat+' LongDec:'+gmdatalon)
      gmx=gmdatalat*Math.pow(10,6)
      gmy=gmdatalon*Math.pow(10,6)
      if (gmx < 0) gmx=gmx+Math.pow(2,32)
      GM_log( 'Latx:'+gmx+' ('+gmdatalat+') Longy:'+gmy+'  ('+gmdatalon+')')
      
	   var LargeMap = document.getElementById("LargeMap");
	   var LargeMapPrint = document.getElementById("LargeMapPrint");

		var mapHTML= '<img src="http://maps.google.com/mapdata?Point=b&Point.latitude_e6=' +gmx +'&Point.longitude_e6='+gmy+'&Point.iconid=15&Point=e&latitude_e6=' +gmx +'&longitude_e6='+gmy+'&zm=2000&w=300&h=280&cc=us&min_priority=1"  BORDER=1 align="right" >';
//		GM_log(mapHTML);
		if (LargeMap)		{
			LargeMap.innerHTML = mapHTML;
			LargeMap.className = "";			
		  }
		else if (LargeMapPrint)		{
			LargeMapPrint.innerHTML = mapHTML;
		  }

      }
    else {
        GM_log('no match on co-ords')
        }
	
	 }