User:Quarl/coor canonicalize.js

// User:Quarl/coor_canonicalize.js - canonicalizes geographical coordinates

// Example: 59° 55′ N, 10° 44′ E becomes 59.91667°N, 10.73333°W

// requires: wikipage.js, util.js, addlilink.js

// quarl 2006-02-01 initial version

//

coorz = new Object;

var coorz = new autoedit(   'coorz',    'CoorZ', 'ca-coorz', 'Canonicalize geographic coordinates',    'Coor canonicalization');

coorz.buildRegExp = function { var sp = function(s) { return ' *' + s + ' *'; }

var d = sp("(?:°|&deg;)"); var m = sp("(?:′|'|&prime;|&#x2032;)"); var s = sp('(?:″|"|&Prime;|&#x2033;)');

var C = '(-?[0-9.]+)';

var dms = C + d + '(?:' + C + m + '(?:' + C + s + ')?' + ')?';

var all = '\\b' + dms + '\\s*(N|S|[Nn]orth|[Ss]outh)[ \t,]*' + dms + '\\s*(E|W|[Ee]ast|[Ww]est)' + '\\b'; return new RegExp(all); }

coorz.replaceRegExp = function(d, m) { var latitude = [m[1], m[2], m[3]]; var latitude_pole = m[4][0].toUpperCase; var longitude = [m[5], m[6], m[7]]; var longitude_pole = m[8][0].toUpperCase;

if (latitude[2] || longitude[2]) { // dms return ('°N, °W'); } else if (latitude[1] || longitude[1]) { // dm       return ('°N, °W'); } else if (latitude[0] || longitude[0]) { // d       return (''); } else { alert ("## internal error a86f430f-f362-4324-b8ce-df5f84e8f65b"); return null; } }

coorz._load = function { coorz.addTab; }

addOnloadHook(coorz._load);

//