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...
...now properly waits for the default OS map to load before relocating, and plays nicely with Chrome again.
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);
Re: OS Open Data mistakes