MediaWiki:Geolinks-US-hoodscale.js
Jump to navigation
Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
Documentation for this user script can be added at MediaWiki:Geolinks-US-hoodscale. |
// Add map service links from [[Template:Geolinks-US-hoodscale]] to [[Template:Location]] and [[Template:Location dec]] on image pages
if (mw.config.get('wgNamespaceNumber') == 6 && mw.config.get('wgAction') == 'view') {
$(document).ready(add_geolinks_US);
}
function walkDOM_uptoTagName(startElement, endElementTagName) {
var el = startElement;
while (el.parentNode) {
el = el.parentNode;
if (el.tagName == endElementTagName)
return el;
}
return false;
}
function walkDOM_righttoTagName(startElement, endElementTagName) {
var el = startElement;
while (el.nextSibling) {
el = el.nextSibling;
if (el.tagName == endElementTagName)
return el;
}
return false;
}
function add_geolinks_US() {
var spans = document.getElementsByTagName('span');
for (var i=0; i<spans.length; i++) {
if (spans[i].className === 'geo') {
var geo = spans[i];
var geospans = geo.getElementsByTagName('span');
var latitude = 0;
var longitude = 0;
if (geospans.length>0) { // location dec
for (var j=0; j<geospans.length; j++) {
if (geospans[j].className == 'latitude') {
latitude = geospans[j].innerHTML;
} else if (geospans[j].className == 'longitude') {
longitude = geospans[j].innerHTML;
}
}
} else { // location
var latlon = geo.innerHTML.split(';');
latitude = latlon[0];
longitude = latlon[1];
}
var geocell = walkDOM_uptoTagName(geo, 'TD');
if (!geocell)
return false;
var nextcell = walkDOM_righttoTagName(geocell, 'TD');
if (!nextcell)
return false;
nextcell.innerHTML += '<ul>\
<li>Street map from <a href="http://mapquest.com/maps/map.adp?latlongtype=decimal&latitude='+latitude+'&longitude='+longitude+'&zoom=7" class="external text">MapQuest</a> or <a href="http://maps.google.com/maps?ll='+latitude+','+longitude+'&spn=0.03,0.045" class="external text">Google Local</a></li>\
<li>Topographic map from <a href="http://topozone.com/map.asp?lat='+latitude+'&lon='+longitude+'&s=50&size=m&datum=nad83" class="external text">TopoZone</a></li>\
<li>Aerial image or topographic map from <a href="http://msrmaps.com/image.aspx?s=13&lon='+longitude+'&lat='+latitude+'&w=2" class="external text">MSR Maps (formerly TerraServer-USA)</a></li>\
<li>Satellite image from <a href="http://maps.google.com/maps?ll='+latitude+','+longitude+'&spn=0.03,0.045&t=k" class="external text">Google Maps</a> or <a href="http://virtualearth.msn.com/default.aspx?cp='+latitude+'|'+longitude+'&style=h&lvl=14&v=1" class="external text">Microsoft Virtual Earth</a> or <a href="http://www.wikimapia.org/maps?ll='+latitude+','+longitude+'&spn=0.03,0.045&t=k" class="external text">WikiMapia</a></li>\
</ul>';
return true;
}
}
return false;
}
// [[Category:Commons geocoding|{{PAGENAME}}]]