MediaWiki:Wikiminiatlas.js: Difference between revisions

No edit summary
(determine zoomlevel)
Line 18: Line 18:
   flowTextTooltips: false,
   flowTextTooltips: false,
   alwaysTooltips: false,
   alwaysTooltips: false,
   iframeurl : '//toolserver.org/~dschwen/wma/iframe_dev.html',
   iframeurl : '//toolserver.org/~dschwen/wma/iframe.html',
   imgbase  : '//toolserver.org/~dschwen/wma/tiles/',
   imgbase  : '//toolserver.org/~dschwen/wma/tiles/',
   buttonImage: '//upload.wikimedia.org/wikipedia/commons/thumb/5/55/WMA_button2b.png/17px-WMA_button2b.png'
   buttonImage: '//upload.wikimedia.org/wikipedia/commons/thumb/5/55/WMA_button2b.png/17px-WMA_button2b.png'
Line 381: Line 381:
  // also insert globe even if no title coords are given
  // also insert globe even if no title coords are given
  (function(){
  (function(){
  //if( wgPageName !== 'Oklahoma_State_Highway_82' ) { return; }
   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;
    ,lat,lon,alat=0,alon=0,np=0
    ,la1,la2,lo1,lo2,ex,ey;
   for( i = 0; i < l.length; ++i ) {
   for( i = 0; i < l.length; ++i ) {
   if( l[i].href.slice(-s.length) === s ) {
   if( l[i].href.slice(-s.length) === s ) {
Line 397: Line 398:
         lat = parseFloat(c[1]);
         lat = parseFloat(c[1]);
         lon = parseFloat(c[0]);
         lon = parseFloat(c[0]);
         np++; alat+=lat; alon+=lon;
         np++;
         way.push( { lat: lat, lon: lon } );
         way.push( { lat: lat, lon: lon } );
        // determine extent of way
        if( lat<la1 || la1===undefined ) { la1=lat; }
        if( lon<lo1 || lo1===undefined ) { lo1=lon; }
        if( lat>la2 || la2===undefined ) { la2=lat; }
        if( lon>lo2 || lo2===undefined ) { lo2=lon; }
         }
         }
       }
       }
       kml.ways.push(way);
       if( way.length > 0 ) { kml.ways.push(way); }
       });
       });
       // already got a request message
       // already got a request message
Line 409: Line 416:
       // insert blue globe
       // insert blue globe
       if( coord_list.length == 0 ) {
       if( coord_list.length == 0 ) {
       alat/=np; alon/=np;
       // determine center
      np/=2;
      for( i=0; i<kml.ways.length && np>0; ++i ) {
        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
      ex = (la2-la1)/180.0 * 3.0*128;
      ey = (lo2-lo1)/180.0 * 3.0*128; // max extent in degrees, zoom0 has 3*128/180 px/degree
      for( zoomlevel = 0; zoomlevel < 12; ++zoomlevel ) {
        if( ex>config.width/2 || ey>config.height/2 ) break;
        ex *= 2; ey *= 2;
      }
 
      // add mapbutton
       mapbutton = $('<img/>')
       mapbutton = $('<img/>')
         .attr('src', wc.buttonImage)
         .attr('src', wc.buttonImage)
Line 415: Line 441:
           alat + '_' + alon + '_' +
           alat + '_' + alon + '_' +
           wc.width + '_' + wc.height + '_' +
           wc.width + '_' + wc.height + '_' +
           site + '_' + (2) + '_' + language  
           site + '_' + zoomlevel + '_' + language  
         }, showIFrame ); // zoomlevel!
         }, showIFrame ); // zoomlevel!