[Script] WMEOpenData v1.32 (20130520)

Moderators: Unholy, krankyd, dmcconachie, The Fej

Re: OS Open Data mistakes

Postby xteejx » Sat Jun 23, 2012 2:21 am

Basically, it would be a bloody great bit of help to reference road names and that kind of thing. :-)

Sent from my GT-I9100P using Tapatalk 2
Area Manager for Kent. Localisation expert and translator for UK English.
Image
UK specific editing: http://www.waze.com/wiki/index.php/United_Kingdom
xteejx
 
Posts: 2337
Joined: Wed Jan 19, 2011 3:17 pm
Location: Sheerness, Kent, UK
Has thanked: 11 times
Been thanked: 15 times

Re: OS Open Data mistakes

Postby Twister_UK » Sat Jun 23, 2012 8:43 am

Ah, so you mean somewhere on the WME display you'd have a button to open up OSMC/OSOD at the same co-ords... In theory it's possible - I haven't delved into the WME code yet to see how easy it'd be to extract the location, but if getting that isn't a complete ballache then it'd be trivial to pass that across to OSMC using its internal permalink feature or to OSOD via my script.


Meanwhile...
Code: Select all
// ==UserScript==
// @name                OS OpenData FullHeight
// @namespace           http://greasemonkey.chizzum.com
// @description           Increases height of map window on OS OpenData site
// @include      http://www.ordnancesurvey.co.uk/oswebsite/opendata/viewer/*
// ==/UserScript==

function resizemap(event)
{
  // resizes map viewport whenever browser window changes size
   var elmModify = document.getElementById("map");
   elmModify.style.height = (window.innerHeight-10)+'px';
   elmModify.style.width = (window.innerWidth-10)+'px';
}

function recentreMap(eastings, northings, zoom)
{
   /*
   Create a proper unsafeWindow object on browsers where it doesn't exist (Chrome, mainly).
   Chrome now defines unsafeWindow, but does not give it the same access to a page's
   javascript that a properly unsafe, unsafeWindow has. This code remedies that.
   
   From: http://stackoverflow.com/questions/1622145/how-can-i-mimic-greasemonkey-firefoxs-unsafewindow-functionality-in-chrome
   */
   var bGreasemonkeyServiceDefined     = false;
   try
   {
      if (typeof Components.interfaces.gmIGreasemonkeyService === "object")
      {
         bGreasemonkeyServiceDefined = true;
      }
   }
   catch (err)
   {
      //Ignore.
   }
   if ( typeof unsafeWindow === "undefined"  ||  ! bGreasemonkeyServiceDefined)
   {
      unsafeWindow    = ( function () {
         var dummyElem   = document.createElement('p');
         dummyElem.setAttribute ('onclick', 'return window;');
         return dummyElem.onclick ();
      } ) ();
   }
   // end of stackoverflow code


   // call the OS provided functions required to point the map at a
   // given grid ref and zoom level
   mymapCenter = new unsafeWindow.OpenSpace.MapPoint(eastings, northings);
   
   // not sure why, but passing zoom directly into setCenter prevents the
   // mouse scrollwheel from zooming in/out of the recentred map...  as a
   // workaround for now, test the value of zoom and use hardcoded calls
   //unsafeWindow.osMap.setCenter(mymapCenter, zoom);
   if(zoom==0)unsafeWindow.osMap.setCenter(mymapCenter, 0);
   if(zoom==1)unsafeWindow.osMap.setCenter(mymapCenter, 1);
   if(zoom==2)unsafeWindow.osMap.setCenter(mymapCenter, 2);
   if(zoom==3)unsafeWindow.osMap.setCenter(mymapCenter, 3);
   if(zoom==4)unsafeWindow.osMap.setCenter(mymapCenter, 4);
   if(zoom==5)unsafeWindow.osMap.setCenter(mymapCenter, 5);
   if(zoom==6)unsafeWindow.osMap.setCenter(mymapCenter, 6);
   if(zoom==7)unsafeWindow.osMap.setCenter(mymapCenter, 7);
   if(zoom==8)unsafeWindow.osMap.setCenter(mymapCenter, 8);
   if(zoom==9)unsafeWindow.osMap.setCenter(mymapCenter, 9);
   if(zoom==10)unsafeWindow.osMap.setCenter(mymapCenter, 10);
}


function checkMapLoaded()
{
   // if the "Powered by OS" logo hasn't loaded in the lower-left corner, we know the original map view
   // is still being rendered by the OpenData code, so wait 100ms and then cbeck for its presence again
   if(document.getElementById('newpoweredby') == null)
   {
      setTimeout(checkMapLoaded,100);
   }
   // once the logo is present, recentre the map view to the desired location and zoom level...
   else
   {
      recentreMap(eastings,northings,zoom);
   }
}

// remove the OS logos from the top...
var elmDeleted = document.getElementById("logos");
elmDeleted.parentNode.removeChild(elmDeleted);

// ...and the huge "about    help    keep in touch" bit from the bottom
var elmDeleted = document.getElementById("sitefooter");
elmDeleted.parentNode.removeChild(elmDeleted);

// reduce the width of the whitespace around the map viewport
var elmModify = document.getElementById("wrapper");
elmModify.style.padding = '4px';

// move the "boundary layers" menu selector into the map viewport
var elmModify = document.getElementById("mapmast");
elmModify.style.height = '0px';
elmModify.style.top = '64px';
elmModify.style.right = '64px';
elmModify.style.zIndex = '2';
// adjust the "boundary layers" border and background colour so it shows up nicely
var elmModify = document.getElementById("mapoptions");
var childModify = elmModify.getElementsByTagName("LI");
childModify[0].style.borderStyle = 'solid';
childModify[0].style.backgroundColor = '#FFFFFF';
childModify[0].style.borderWidth = '1px';

// extract the starting coords/zoom from the url...

var userloc = document.location.href;
upos = userloc.indexOf("?e=");
if(upos != -1)
{
   eastings = userloc.substr(upos+3,6);
   upos = userloc.indexOf("&n=");
   if(upos != -1)
   {
      northings = userloc.substr(upos+3,6);
      upos = userloc.indexOf("&z=");
      if(upos != -1)
      {
         zoom = userloc.substr(upos+3,2);
         //...then recentre the map 1s after the page has loaded
         checkMapLoaded();
      }
   }
}


// re-render the map now we're done removing/adjusting all the original elements...
resizemap();

// and finally add in a hook to the onResize event, to call resizemap() each time the
// browser window changes size
window.addEventListener('resize', resizemap, true);

...now properly waits for the default OS map to load before relocating, and plays nicely with Chrome again.

HTC One X - Android 4.1.1 - Waze 3.6.0.0 - International Server
AM for NW London and the M4-A404-M40 loop - Editing Expert
WME enhancement scripts (WMEOD:URO:LMUR:SRS) @ userscripts.org
Twister_UK
 
Posts: 476
Joined: Sat Jan 07, 2012 3:56 pm
Location: NW London
Has thanked: 19 times
Been thanked: 85 times

Re: OS Open Data mistakes

Postby Dave2084 » Sat Jun 23, 2012 9:30 am

Doesn't seem to work for me ...the window resizes fine but the location and zoom is not being used.

Win 7 x64 & Firefox 13.0.1
iPhone 4S 32GB (Jailed) • iOS 6.1.2 • Waze 3.6.99.9 Beta
Lincolnshire Area Manager • UK Country Administrator • iOS Beta Tester • iPhone Expert
UK WikiUK ForumWaze UK on FacebookBecome a UK Area ManagerWaze Status
Dave2084
Waze Champs
 
Posts: 1544
Joined: Tue Feb 09, 2010 12:58 am
Location: Lincoln, UK
Has thanked: 21 times
Been thanked: 30 times

Re: OS Open Data mistakes

Postby Twister_UK » Sat Jun 23, 2012 9:33 am

Did the previous version (with the hardcoded delay) work OK?

HTC One X - Android 4.1.1 - Waze 3.6.0.0 - International Server
AM for NW London and the M4-A404-M40 loop - Editing Expert
WME enhancement scripts (WMEOD:URO:LMUR:SRS) @ userscripts.org
Twister_UK
 
Posts: 476
Joined: Sat Jan 07, 2012 3:56 pm
Location: NW London
Has thanked: 19 times
Been thanked: 85 times

Re: OS Open Data mistakes

Postby xteejx » Sat Jun 23, 2012 12:10 pm

Cool. I'd imagine grabbing the coords would be simple. Could nick that bit from the other tools. Bear in mind I don't script things so theory is always simple, practical is a little more difficult :-P

Sent from my GT-I9100P using Tapatalk 2
Area Manager for Kent. Localisation expert and translator for UK English.
Image
UK specific editing: http://www.waze.com/wiki/index.php/United_Kingdom
xteejx
 
Posts: 2337
Joined: Wed Jan 19, 2011 3:17 pm
Location: Sheerness, Kent, UK
Has thanked: 11 times
Been thanked: 15 times

Re: OS Open Data mistakes

Postby Dave2084 » Sat Jun 23, 2012 12:43 pm

Twister_UK wrote:Did the previous version (with the hardcoded delay) work OK?


It's OK it's working now, I'd created a new script for this and the original resize one only was running first ... doh!


Would it be possible to send the script lat/long and do a conversion to Easting/Northings?

If so then it's relatively easy to do a bookmarklet that sends the lat/long and zoom from Waze to OS.

For instance the code below when used as a Favourite/bookmark (borrowed from the WME -> Cartouche Bookmarklet):
Code: Select all
javascript:(function(){var%20center_lonlat=new%20OpenLayers.LonLat(wazeMap.center.lon,wazeMap.center.lat);center_lonlat.transform(new%20OpenLayers.Projection("EPSG:900913"),new%20OpenLayers.Projection("EPSG:4326"));window.open('http://www.ordnancesurvey.co.uk/oswebsite/opendata/viewer/?zoom='+(wazeMap.zoom)+'&lon='+center_lonlat.lon+'&lat='+center_lonlat.lat,'OSOpenData');})();


would give you the following link:
http://www.ordnancesurvey.co.uk/oswebsite/opendata/viewer/?zoom=3&lon=-5.4874312735939&lat=50.208929890459

From Here:
https://world.waze.com/editor/?zoom=3&lat=50.20893&lon=-5.48743&layers=BFTFTTTTTTTTTTTFTTTTFT
iPhone 4S 32GB (Jailed) • iOS 6.1.2 • Waze 3.6.99.9 Beta
Lincolnshire Area Manager • UK Country Administrator • iOS Beta Tester • iPhone Expert
UK WikiUK ForumWaze UK on FacebookBecome a UK Area ManagerWaze Status
Dave2084
Waze Champs
 
Posts: 1544
Joined: Tue Feb 09, 2010 12:58 am
Location: Lincoln, UK
Has thanked: 21 times
Been thanked: 30 times

Re: OS Open Data mistakes

Postby Twister_UK » Sat Jun 23, 2012 6:18 pm

Good to hear the revised script is working as expected... I'm now working on another script for adding new links to WME, which will open up OS OpenData or Musical Chairs at the WME location.

HTC One X - Android 4.1.1 - Waze 3.6.0.0 - International Server
AM for NW London and the M4-A404-M40 loop - Editing Expert
WME enhancement scripts (WMEOD:URO:LMUR:SRS) @ userscripts.org
Twister_UK
 
Posts: 476
Joined: Sat Jan 07, 2012 3:56 pm
Location: NW London
Has thanked: 19 times
Been thanked: 85 times

Re: OS Open Data mistakes

Postby Dave2084 » Sat Jun 23, 2012 7:07 pm

Twister_UK wrote:Good to hear the revised script is working as expected... I'm now working on another script for adding new links to WME, which will open up OS OpenData or Musical Chairs at the WME location.


I'll look forward to seeing that!
iPhone 4S 32GB (Jailed) • iOS 6.1.2 • Waze 3.6.99.9 Beta
Lincolnshire Area Manager • UK Country Administrator • iOS Beta Tester • iPhone Expert
UK WikiUK ForumWaze UK on FacebookBecome a UK Area ManagerWaze Status
Dave2084
Waze Champs
 
Posts: 1544
Joined: Tue Feb 09, 2010 12:58 am
Location: Lincoln, UK
Has thanked: 21 times
Been thanked: 30 times

Re: OS Open Data mistakes

Postby Twister_UK » Sat Jun 23, 2012 11:30 pm

For the OS Musical Chairs afficionados, here's a sneak pre-release look at the new script... This version adds a link to OSMC in the lower-right corner of the WME window, between the existing permalink and "Imagery by Bing" elements.

Code: Select all
// ==UserScript==
// @name                WME to OS link
// @namespace           http://greasemonkey.chizzum.com
// @description         Adds link to WME to open up OS Open Data/Musical Chairs sites at same map location
// @include             https://world.waze.com/editor/*
// ==/UserScript==

function processPermalink()
{
   // extract current lat/lon & zoom level from the permalink URL
   var plsrc = document.getElementById("permalink-container").innerHTML;
   var zoompos = plsrc.indexOf("?zoom=");
   var latpos = plsrc.indexOf("&lat=");
   var lonpos = plsrc.indexOf("&lon=");
   var layerpos = plsrc.indexOf("&layers=");
   
   // does the URL contain all three parameters?
   if((zoompos != -1)&&(latpos != -1)&&(lonpos != -1)&&(layerpos != -1))
   {
      // yes, so extract them...
      var zoom = parseInt(plsrc.substr(zoompos+6,latpos-(zoompos+6)));
      var lat = plsrc.substr(latpos+9,lonpos-(latpos+9));
      var lon = plsrc.substr(lonpos+9,layerpos-(lonpos+9));

      // compare the freshly extracted parameters against the persistent copies, and update the
      // links to OSMC & OSOD only if there's a change required - the newly-inserted <a> element
      // can't be clicked on until the insertion process is complete, and if we were to re-insert
      // it every 250ms then it'd spend a lot of its time giving the appearance of being clickable
      // but without actually doing anything...
      if((zoom != sessionStorage.zoom)||(lat != sessionStorage.lat)||(lon != sessionStorage.lon))
      {
         // update the persistent vars with the new position
         sessionStorage.zoom = zoom;
         sessionStorage.lat = lat;
         sessionStorage.lon = lon;

         // translate the zoom level between WME and Musical Chairs
         var mczoom = zoom + 12;
         if(mczoom > 18) mczoom = 18;

         // generate the Musical Chairs URL
         var osmc_url = 'http://ris.dev.openstreetmap.org/oslmusicalchairs/map?zoom='+mczoom+'&lat='+lat+'&lon='+lon+'&layers=B0TT&view_mode=pseudorandom';

         // "borrow" the Bing attribution div to insert the new clicky-links, remembering to maintain the attribution after we're done messing with it!
         document.getElementById("bing-attribution").innerHTML = '- <a href="'+osmc_url+'">OS Musical Chairs</a> - Imagery by Bing';
      }
   }
}

// initialise persistent vars
sessionStorage.zoom = 0;
sessionStorage.lat = '';
sessionStorage.lon = '';

// check for new map co-ords every 250ms
setInterval(processPermalink,250);

HTC One X - Android 4.1.1 - Waze 3.6.0.0 - International Server
AM for NW London and the M4-A404-M40 loop - Editing Expert
WME enhancement scripts (WMEOD:URO:LMUR:SRS) @ userscripts.org
Twister_UK
 
Posts: 476
Joined: Sat Jan 07, 2012 3:56 pm
Location: NW London
Has thanked: 19 times
Been thanked: 85 times

Re: OS Open Data mistakes

Postby Dave2084 » Sun Jun 24, 2012 7:28 am

Looks good, can't wait to get my hands on the Open Data enabled version.

I just added a couple of tweaks; one to open the OSMC link in a new tab and the other to unify the text formatting so that:

"Permalink |- OS Musical Chairs - Imagery by Bing"
Becomes
"Permalink | OS Musical Chairs | Imagery by Bing"

Code: Select all
document.getElementById("bing-attribution").innerHTML = ' <a href="'+osmc_url+'" target=_blank>OS Musical Chairs</a> | Imagery by Bing';
iPhone 4S 32GB (Jailed) • iOS 6.1.2 • Waze 3.6.99.9 Beta
Lincolnshire Area Manager • UK Country Administrator • iOS Beta Tester • iPhone Expert
UK WikiUK ForumWaze UK on FacebookBecome a UK Area ManagerWaze Status
Dave2084
Waze Champs
 
Posts: 1544
Joined: Tue Feb 09, 2010 12:58 am
Location: Lincoln, UK
Has thanked: 21 times
Been thanked: 30 times

PreviousNext

Return to United Kingdom

Who is online

Users browsing this forum: No registered users