Benutzer:Mps/coordinates.js
aus Wikipedia, der freien Enzyklopädie
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
- Opera: Strg+F5
// entnommen aus [[Benutzer:Dschwen/coordinates.js]] (http://de.wikipedia.org/w/index.php?title=Benutzer:Dschwen/coordinates.js&oldid=27146611) mit folgenden Änderungen:
// - Bugfixes, z.B. Nichtfunktion wegen nicht gescapten geschweiften Klammern auf Zeile 293
// - Cookie-Management entfernt, da unnötig
// - optisches: typographische Minuten- und Sekundenzeichen, bedarfsgerechtes Weglassen von Millisekunden und Sekunden
// - Liste der japanischen Präfekturen für region-Parameter
// - Unterstützung für Infoboxen mit den Parametern lat_deg, lat_min, lat_sec, lon_deg, lon_min und lon_sec
// - direkte Koordinateneingabe verbessert und keine Änderungen bei Fehleingabe
// - Unterstützung der neuen Koordinatenvorlage
//
// globals
//
var wpSummary = null;
var optionalBox = null;
var optionalBoxLabel = null;
var optionalNumber = null;
var lat,lon;
var coordArticle = null;
var coordText = null;
var listTemplates = new Array( 'Koordinate_Artikel' );
var listRegions = new Array('',
'Aichi JP-23',
'Akita JP-05',
'Aomori JP-02',
'Chiba JP-12',
'Ehime JP-38',
'Fukui JP-18',
'Fukuoka JP-40',
'Fukushima JP-07',
'Gifu JP-21',
'Gunma JP-10',
'Hiroshima JP-34',
'Hokkaidō JP-01',
'Hyōgo JP-28',
'Ibaraki JP-08',
'Ishikawa JP-17',
'Iwate JP-03',
'Kagawa JP-37',
'Kagoshima JP-46',
'Kanagawa JP-14',
'Kōchi JP-39',
'Kumamoto JP-43',
'Kyōto JP-26',
'Mie JP-24',
'Miyagi JP-04',
'Miyazaki JP-45',
'Nagano JP-20',
'Nagasaki JP-42',
'Nara JP-29',
'Niigata JP-15',
'Ōita JP-44',
'Okayama JP-33',
'Okinawa JP-47',
'Ōsaka JP-27',
'Saga JP-41',
'Saitama JP-11',
'Shiga JP-25',
'Shimane JP-32',
'Shizuoka JP-22',
'Tochigi JP-09',
'Tokushima JP-36',
'Tokio JP-13',
'Tottori JP-31',
'Toyama JP-16',
'Wakayama JP-30',
'Yamagata JP-06',
'Yamaguchi JP-35',
'Yamanashi JP-19',
'Deutschland DE' );
var listTypes = new Array( 'landmark', 'city', 'mountain', 'waterbody', 'isle', 'airport', 'country', 'state', 'adm1st', 'adm2nd' );
var typeSelect = null;
var regionSelect = null;
var editbox = null;
var coordinatebox = null;
//
// Insert the coordinate Form into the edit box.
//
function coordinatesInstall()
{
var i=0;
var saveButton = document.getElementById('wpSave');
if (!saveButton) return;
var container = saveButton.parentNode;
if (container) {
var cleaner = "<br style=\\'clear:both;\\' />";
CoordinatesHTML = '<div style="border: 1px solid gray; padding: 3px; margin-top: 2px; margin-bottom:2px;" >'
CoordinatesHTML += '<input type="button" value="Google-Maps-Link oder Koordinate mit Sekundenangabe einfügen" onclick="interpretCoordinates();" /> ';
CoordinatesHTML += '<input type="text" size="80" id="CoordinateBox" onfocus="showDetails()" />';
CoordinatesHTML += '<div id="CoordinateDetails" style="margin-top: 2px; position: relative"><a href="#" onclick="hideDetails()" style="position:absolute; bottom:3px; right:3px; font-size:50%">schließen</a>';
CoordinatesHTML += '<label for="CheckBoxArticle">Artikel</label> <input type="checkbox" name="CheckBoxArticle" value="CheckBoxArticle" id="CheckBoxArticle" title="Artikelkoordinate" /> ';
CoordinatesHTML += '<label for="CheckBoxText">Text</label> <input type="checkbox" name="CheckBoxText" value="CheckBoxText" id="CheckBoxText" title="Fließtextkoordinate" /> ';
CoordinatesHTML += '<label for="CoordinateRegion">Region:</label> <select title="Region" id="CoordinateRegion">';
for (i=0; i<listRegions.length; ++i) {
CoordinatesHTML += '<option value="'+listRegions[i]+'">'+listRegions[i]+'</option>';
}
CoordinatesHTML += '</select> <label for="CoordinateType">Typ:</label> <select onchange="toggleOptional()" title="Typ (bitte angeben)" id="CoordinateType">';
for (i=0; i<listTypes.length; ++i) {
CoordinatesHTML += '<option value="'+listTypes[i]+'">'+listTypes[i]+'</option>';
}
CoordinatesHTML += '</select> <label for="CoordinateDimNumber">Durchmesser des <a href="/wiki/Umkreis" title="Umkreis">Umkreises</a> in Meter:</label> <input type="text" size="10" id="CoordinateDimNumber" /> <span id="CoordinateBoxOptional" style="visibility: hidden"><label for="CoordinateNumber" id="CoordinateBoxOptionalLabel"></label> <input type="text" size="9" id="CoordinateNumber" /></span></div></div>';
container.innerHTML = container.innerHTML + CoordinatesHTML;
wpSummary = document.getElementById('wpSummary');
optionalBox = document.getElementById('CoordinateBoxOptional');
optionalBoxLabel = document.getElementById('CoordinateBoxOptionalLabel');
optionalNumber = document.getElementById('CoordinateNumber');
detailBox = document.getElementById('CoordinateDetails');
dimNumber = document.getElementById('CoordinateDimNumber');
typeSelect = document.getElementById('CoordinateType');
regionSelect = document.getElementById('CoordinateRegion');
coordArticle = document.getElementById('CheckBoxArticle');
coordText = document.getElementById('CheckBoxText');
hideDetails();
editbox = document.getElementById('wpTextbox1');
coordinatebox = document.getElementById('CoordinateBox');
// suche nach boilerplate text: Koordinaten 38,18° Nord, 122,26° West
var boilerplate_filter = /Koordinaten.* ([^°]+)° (Nord|Süd), ([^°]+)° (West|Ost)/;
var result;
if( result = boilerplate_filter.exec(editbox.value) )
{
lat = result[1].replace(/,/, ".");
if( result[2] == 'Süd' ) lat*=-1;
lon = result[3].replace(/,/, ".");
if( result[4] == 'West' ) lon*=-1;
coordinatebox.value = 'boilerplate:'+lat+','+lon;
showDetails();
}
boilerplate_filter = / ([0-9.,]+) Einwohner/;
if( result = boilerplate_filter.exec(editbox.value) )
{
optionalNumber.value = result[1].replace(/[,\.]/, "");
typeSelect.selectedIndex = 1;
toggleOptional();
}
}
}
function toggleOptional()
{
optionalBox.style.visibility="hidden";
if(typeSelect.value == 'city')
{
optionalBoxLabel.innerHTML='Einwohnerzahl:';
optionalBox.style.visibility="visible";
}
if(typeSelect.value == 'mountain')
{
optionalBoxLabel.innerHTML='Höhe (in Meter):';
optionalBox.style.visibility="visible";
}
}
function hideDetails()
{
//detailBox.style.visibility="hidden";
detailBox.style.display="none";
return false;
}
function showDetails()
{
//detailBox.style.visibility="visible";
detailBox.style.display="block";
}
//
// Hook up installation function
//
$(coordinatesInstall);
//
// Coordinate interpretation
//
function interpretCoordinates()
{
var coordinate1 = coordinatebox.value;
var coordinate2 = '';
var from_ll, result;
var coord_filter = /http:\/\/www\.google\.([a-zA-Z]+)\/maps/;
var latlon = new Array;
// magic!
if(coordinate1.substr(0,19)=='http://maps.google.' || coord_filter.test(coordinate1) )
{
var llidx = coordinate1.indexOf("&ll=");
if (llidx == -1) llidx = coordinate1.indexOf("?ll=");
if (llidx != -1) from_ll = coordinate1.substr(llidx+4);
var ampers = from_ll.indexOf('&');
if(ampers==-1)
{
latlon = from_ll.split(",");
}
else
{
latlon = (from_ll.substr(0,ampers)).split(",");
}
} else
//http://tools.wikimedia.de/~magnus/geo/geohack.php?params=39_18_S_175_35_E_type:mountain_region:NZ
if(coordinate1.substr(0,49)=='http://tools.wikimedia.de/~magnus/geo/geohack.php')
{
latlon = from_ll.split(",");
} else
// gefundene boilerplate daten
if( coordinate1.substr(0,12) == 'boilerplate:' )
{
from_ll = coordinate1.substr(12);
latlon = from_ll.split(",");
} else
//31°46'14.44"N ; 35°14'5.88"E
{
coord_filter = /([\d.,]+)°\s*([\d.,]+)['`′]\s*([\d.,]+)["″]\s*([nNsS])\s*[;,]?\s*([\d.,]+)°\s*([\d.,]+)['`′]\s*([\d.,]+)["″]\s*([oOwWeE])/;
if( result = coord_filter.exec(coordinate1 ) )
{
latlon[0] = result[1]*1.0 + result[2]/60.0 + result[3]/3600.0;
if( result[4]=='s' || result[4]=='S' ) latlon[0] *= -1.0;
latlon[1] = result[5]*1.0 + result[6]/60.0 + result[7]/3600.0;
if( result[8]=='w' || result[8]=='W' ) latlon[1] *= -1.0;
} else return;
}
var mark_ns = 'N';
var mark_ew = 'E';
var mark_ew_d = 'O';
lat = latlon[0];
lon = latlon[1];
if(lat<0) { lat*=-1; mark_ns='S'; }
if(lon<0) { lon*=-1; mark_ew='W'; mark_ew_d='W';}
var lat_m = (( lat - Math.floor(lat) ) * 60.0);
var lon_m = (( lon - Math.floor(lon) ) * 60.0);
var lat_s = ( lat_m - Math.floor(lat_m) ) * 60.0;
var lon_s = ( lon_m - Math.floor(lon_m) ) * 60.0;
var slat_m = Math.floor(lat_m).toString();
var slon_m = Math.floor(lon_m).toString();
if (slat_m.length == 1) slat_m = '0' + slat_m;
if (slon_m.length == 1) slon_m = '0' + slon_m;
var slat_s = "";
var slon_s = "";
if ((lat_s != 0) || (lon_s != 0))
{
slat_s = lat_s.toFixed(2);
slon_s = lon_s.toFixed(2);
if (slat_s.length < 5) slat_s = '0' + slat_s;
if (slon_s.length < 5) slon_s = '0' + slon_s;
// wenn beide _visuell_ keine Nachkommastellen aufweisen, diese Nullen entfernen
var slat_s_delim_pos = slat_s.indexOf('.00');
var slon_s_delim_pos = slon_s.indexOf('.00');
if ((slat_s_delim_pos >= 0) && (slon_s_delim_pos >= 0))
{
slat_s = slat_s.substr(0, slat_s_delim_pos);
slon_s = slon_s.substr(0, slon_s_delim_pos);
}
}
var infoBoxRegEx = /(\|\s*lat_deg\s*=\s*)[0-9]+(\s*\|\s*lat_min\s*=\s*)[0-9]+(\s*\|\s*lat_sec\s*=\s*)[0-9.]*(\s*\|\s*lon_deg\s*=\s*)[0-9]+(\s*\|\s*lon_min\s*=\s*)[0-9]+(\s*\|\s*lon_sec\s*=\s*)[0-9.]*/;
if (editbox.value.match(infoBoxRegEx))
{
editbox.value = editbox.value.replace(infoBoxRegEx,
"$1" + Math.floor(lat) + "$2" + slat_m + "$3" + slat_s +
"$4" + Math.floor(lon) + "$5" + slon_m + "$6" + slon_s);
}
else
{
coordinate2 = '{{Coordinate';
if (coordText.checked == true)
{
if (coordArticle.checked == true) coordinate2 += '|article=/';
coordinate2 += '|text=/';
}
coordinate2 += '|NS='+lat+'|EW='+lon+'|type='+typeSelect.value;
if (typeSelect.value=='city' && optionalNumber.value!='')
{
coordinate2 += '|pop='+optionalNumber.value;
}
if (typeSelect.value=='mountain' && optionalNumber.value!='')
{
coordinate2 += '|elevation='+optionalNumber.value;
}
if( regionSelect.value!='')
{
var regionWords = regionSelect.value.split(" ");
coordinate2 += '|region='+regionWords[regionWords.length - 1];
}
if (dimNumber.value != '')
{
coordinate2 += '|dim=' + dimNumber.value;
}
if (coordText.checked == true)
{
coordinate2 += '|name=';
}
coordinate2 += '}}';
// Koordinatenvorlage hinzufügen
editbox.value += coordinate2;
if (wpSummary.value == "") wpSummary.value = "Geokoordinaten eingefügt";
}
}