MediaWiki:Wikiminiatlas.js: Difference between revisions
(add translations) |
(add support for areas in KML files) |
||
Line 232: | Line 232: | ||
} | } | ||
mes.postMessage( JSON.stringify(clist), document.location.protocol+'//toolserver.org' ); | mes.postMessage( JSON.stringify(clist), document.location.protocol+'//toolserver.org' ); | ||
if( kml !== null | if( kml !== null ) { | ||
mes.postMessage( JSON.stringify(kml), document.location.protocol+'//toolserver.org' ); | mes.postMessage( JSON.stringify(kml), document.location.protocol+'//toolserver.org' ); | ||
} | } | ||
Line 386: | Line 386: | ||
(function(){ | (function(){ | ||
var i,l = $('table.metadata').find('a'),s=wgPageName+'/KML&action=raw' | var i,l = $('table.metadata').find('a'),s=wgPageName+'/KML&action=raw' | ||
,alat=0,alon=0,np=0 | |||
,la1,la2,lo1,lo2,ex,ey; | ,la1,la2,lo1,lo2,ex,ey; | ||
for( i = 0; i < l.length; ++i ) { | for( i = 0; i < l.length; ++i ) { | ||
Line 394: | Line 394: | ||
dataType: 'xml', | dataType: 'xml', | ||
success: function(xml){ | success: function(xml){ | ||
function processCoords(t) { | |||
var way = [], c, p = t.split(' '), i, lat, lon; | |||
var way=[] | |||
for( i=0; i<p.length; ++i ) { | for( i=0; i<p.length; ++i ) { | ||
c=p[i].split(','); | c=p[i].split(','); | ||
Line 402: | Line 401: | ||
lat = parseFloat(c[1]); | lat = parseFloat(c[1]); | ||
lon = parseFloat(c[0]); | lon = parseFloat(c[0]); | ||
way.push( { lat: lat, lon: lon } ); | way.push( { lat: lat, lon: lon } ); | ||
// determine extent of way | // determine extent of way | ||
if( | if( la1===undefined || lat<la1 ) { la1=lat; } | ||
if( | if( lo1===undefined || lon<lo1 ) { lo1=lon; } | ||
if( | if( la2===undefined || lat>la2 ) { la2=lat; } | ||
if( | if( lo2===undefined || lon>lo2 ) { lo2=lon; } | ||
} | } | ||
} | } | ||
return way; | |||
} | |||
// initialize transfer datastructure | |||
kml = { ways: [], areas: [] }; | |||
window.kmldata = xml; // DEBUG! | |||
// ways | |||
$(xml).find('LineString>coordinates').each(function(){ | |||
var way = processCoords( $(this).text() ); | |||
if( way.length > 0 ) { kml.ways.push(way); } | if( way.length > 0 ) { kml.ways.push(way); } | ||
}); | }); | ||
// areas | |||
$(xml).find('Polygon').each(function(){ | |||
var area={inner:[],outer:[]},i,j,c; | |||
// outer boundary | |||
$(this).find('outerBoundaryIs>LinearRing>coordinates').each(function(){ | |||
var way = processCoords( $(this).text() ); | |||
if( way.length > 0 ) { area.outer.push(way); } | |||
}); | |||
// inner boundary (holes in the polygon) | |||
$(this).find('innerBoundaryIs>LinearRing>coordinates').each(function(){ | |||
var way = processCoords( $(this).text() ); | |||
if( way.length > 0 ) { area.inner.push(way); } | |||
}); | |||
// only add if we have an outer boundary | |||
if( area.outer.length>0 ) { kml.areas.push(area); } | |||
}); | |||
window.kml = kml; // DEBUG! | |||
// already got a request message | // already got a request message | ||
if( mes !== null && kml.ways.length > 0) { | if( mes !== null && kml.ways.length > 0) { | ||
mes.postMessage( JSON.stringify(kml), document.location.protocol+'//toolserver.org' ); | mes.postMessage( JSON.stringify(kml), document.location.protocol+'//toolserver.org' ); | ||
} | } | ||
// insert blue globe | // insert blue globe | ||
if( coord_list.length == 0 ) { | if( coord_list.length == 0 ) { | ||
// determine center | // determine center | ||
alat = (la1+la2)/2; | |||
alon = (lo1+lo2)/2; | |||
//determine zoomfactor | //determine zoomfactor |