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 && kml.ways.length > 0 ) {
     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'
     ,lat,lon,alat=0,alon=0,np=0
     ,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){
       kml = { ways: [] };
       function processCoords(t) {
      $(xml).find('LineString>coordinates').each(function(){
       var way = [], c, p = t.split(' '), i, lat, lon;
       var way=[],i,j,c,p=$(this).text().split(' ');
       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]);
        np++;
         way.push( { lat: lat, lon: lon } );
         way.push( { lat: lat, lon: lon } );


         // determine extent of way
         // determine extent of way
         if( lat<la1 || la1===undefined ) { la1=lat; }
         if( la1===undefined || lat<la1 ) { la1=lat; }
         if( lon<lo1 || lo1===undefined ) { lo1=lon; }
         if( lo1===undefined || lon<lo1 ) { lo1=lon; }
         if( lat>la2 || la2===undefined ) { la2=lat; }
         if( la2===undefined || lat>la2 ) { la2=lat; }
         if( lon>lo2 || lo2===undefined ) { lo2=lon; }
         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
       np/=2;
       alat = (la1+la2)/2;
       for( i=0; i<kml.ways.length && np>0; ++i ) {
       alon = (lo1+lo2)/2;
        for( j=0; j<kml.ways[i].length && np>0; ++j ) {
        if( --np <= 0 ) {
          alat = kml.ways[i][j].lat;
          alon = kml.ways[i][j].lon;
        }
        }
      }


       //determine zoomfactor
       //determine zoomfactor