BeanShellMapSources

From MOBAC Wiki
Jump to: navigation, search

Example BeanShell map sources

Mars

/*
 Tile script for mars maps (see http://www.uahirise.org/releases/hiwish.php for details)
 May not be very useful for most users but you can at least fetch a large texture from mars...
 reverse engineered with FireBug and TAC Map Evaluator 1.7 beta 8 by Henry T.

 You can choose between 3 different layers (infrared, visible, elevation)

 They use the google technology with some recursive quadtree naming convention for the tiles resulting in longer
 filenames the more you zoom in. Therefore I use a recursive function.
 
 top left: "q"
 top right: "r" 
 bottom right: "s"
 bottom left: "t"
 Heres an example for a 2x2 map (zoom=1)
 [ q  r ]
 [ t  s ]

 Heres an example for a 4x4 map (zoom=2)
 [ qq  qr  rq  rr ]  
 [ qt  qs  rt  rs ]
 [ tq  tr  sq  sr ]
 [ tt  ts  st  ss ]
*/

 tileType = "jpg";
 int w, z0;   // store the map width and zoom level 
 String[] Table = { "q", "r", "t", "s" };

// recursive function for character concatenation
// maybe not too fast but a bit easier to understand
String BuildTileName(int z, int x, int y)
  {
  if(z==0) return "";	

  int w1 = w>>(z0-z);    
  int x1 = ((x%w1)<<1)/w1;
  int y1 = ((y%w1)<<1)/w1;

  String s = Table[(y1<<1) + x1];
  return s + BuildTileName(z-1, x, y);
  }

String getTileUrl( int zoom, int x, int y ) 
  {
  baseUrl = "http://mw1.google.com/mw-planetary/mars/"; 

/* you choose */
  MapType = "infrared";
//  MapType = "visible";
//  MapType = "elevation";
  w = 1<<zoom;
  z0 = zoom;
 
  return baseUrl + MapType + "/t" + BuildTileName(zoom, x, y) + ".jpg";    
}

Kompass.de Online-Karte

/** 
beanshell code to use the online maps form kompass-verlag
(http://www.kompass.de/online-karte.html) in "Mobile Atlas Creator"
(http://mobac.dnsalias.org/)

put it into your "mapsources"-directory...

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>

**/


static import java.lang.Math.*;

name = "Kompass Verlag";

tileType = "png";

tileSize = 256; // optional
minZoom = 6;   // optional
maxZoom = 17;   // optional

/**
This method is called for each tile: 
input parameters for this script: "zoom", "x" and "y"
**/
String getTileUrl( int zoom, int x, int y ) {
return ("http://www.kompass.de/map/koogle.php?LAYERS=koogle&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG:900913&BBOX=" +  mercatorTileEdges(x,y,zoom) +
"&WIDTH=256&HEIGHT=256") ;
} 

numTiles(z){
    return abs(pow(2,z));
}

mercatorToLat(mercatorY){
  return(toDegrees(atan(sinh(mercatorY))));
}

latEdges1(y,z){
  n = numTiles(z);
  unit = 1 / n;
  relY1 = y * unit;
  lat1 = mercatorToLat(PI * (1 - 2 * relY1));
  return lat1;
}

latEdges2(y,z){
  n = numTiles(z);
  unit = 1 / n;
  relY1 = y * unit;
  relY2 = relY1 + unit;
  lat2 = mercatorToLat(PI * (1 - 2 * relY2));
  return lat2;
}

lonEdges1(x,z){
  n = numTiles(z);
  unit = 360 / n;
  lon1 = -180 + x * unit;
  return lon1;
}

lonEdges2(x,z){
  n = numTiles(z);
  unit = 360 / n;
  lon1 = -180 + x * unit;
  lon2 = lon1 + unit;
  return lon2;
}

tileEdges(x,y,z){
  return (latEdges2(y,z) + "," +
   	  lonEdges1(x,z) + "," +
	  latEdges1(y,z) + "," +
	  lonEdges2(x,z));
}

lon2mercator(l){
  return (l * 20037508.34 / 180);
}

lat2mercator(l){
 r = toRadians(l);
 lat = log((1+sin(r)) / (1-sin(r)));
 return (lat * 20037508.34 / 2 / PI);
}

mercatorTileEdges(x,y,z){
  return (lon2mercator(lonEdges1(x,z)) + "," +
          lat2mercator(latEdges2(y,z)) + "," +
	  lon2mercator(lonEdges2(x,z)) + "," +
	  lat2mercator(latEdges1(y,z)));
}

File:Beispiel.jpg