﻿<?xml version="1.0" encoding="UTF-8" ?>
<Module>

 <ModulePrefs title="VolksNav(c) in Bavaria" 
             description="The building of the Bavarian Parliament can be the world\'s first one with natural indoor and outdoor orientation"
              author="Henrique Koehler"
             author_email="volksnav@volksnav.de"
             screenshot= "http://www.volksnav.de/mapplet/SnapShot.jpg" 
             thumbnail="http://www.volksnav.de/mapplet/tn_smileyGrid.jpg"  
             height="150">

    <Require feature="sharedmap" />
    <Require feature="setprefs" />
  </ModulePrefs>
  
<UserPref  name="zoomState"   default_value="8"  datatype="hidden"/>

  <Content type="html">  <![CDATA[

    <script>

       var div1 = document.createElement('DIV');
       div1.innerHTML = '<h4>This building can be the world\'s first one with natural indoor and <br>outdoor orientation acc. to www.volksnav.com/Maximilianeum</h4>';
       var div2 = document.createElement('DIV');
       div2.innerHTML = '<h4>The logical address StatusQuo(c) MUN m3:1 r14 base on the Marienplatz<br>(m0) and harmonize with codes for crossings, stop points etc.</h4>';
       var div3 = document.createElement('DIV');
       div3.innerHTML = '<h4>"m12" is the direction from "m0" to north, "m3" to<br>east, etc. This divides the city into 12 "hour" sectors</h4>';
       var div4 = document.createElement('DIV');
       div4.innerHTML = '<h4>The m-sectors are divided in "distance-minutes".<br>"m3:1" is 1 x 100m "later" than "m3"</h4>';
       var div5 = document.createElement('DIV');
       div5.innerHTML = '<h4>The radius is the distance to "m0" in steps of<br>100m. "r14" means "14 x 100m from m0"</h4>';
       var div6 = document.createElement('DIV');
       div6.innerHTML = '<h4>The division of the horizon in 12 directions can also be used indoor</h4>';

       var tab1 = new GInfoWindowTab('Maximilianeum', div1);
 
       kenn="Munich"

       var poleLat= ( 48 + 8 / 60 + 13 / 3600);
      var poleLon= (11  + 34 / 60 + 31 / 3600);
     
       var map = new GMap2();
      var position_marker = null;

      var ullat=48 + 8/60 + 8.5/3600;
      var ullon= 11 + 35/60 + 37/3600;

     var centro = new GLatLng(ullat+0.0008, ullon+0.001);

      map.setCenter(centro, 16);

        showTabs();
        overlayIndoor();

     var prefs = new _IG_Prefs(__MODULE_ID__);
     var message = document.getElementById("message");
 
          GEvent.addListener(map, "click", showPosition);

   function overlayIndoor(){
      var boundaries = new GLatLngBounds(new GLatLng(ullat,ullon), 
new GLatLng(ullat+.00135 , ullon + .0018));
      var oldmap = new GGroundOverlay("http://www.volksnav.de/Maximilianeum/Maximilianeum.png", boundaries);
 
     map.addOverlay(oldmap);
   }

     function resetCounter(){
       prefs.set("zoomState = ", 0);
       map.clearOverlays();
         zoom=12       
         drawGrid();
     }

     function incrementZoom() {
       var zoomState = prefs.getInt("zoomState");
       prefs.set("zoomState", zoomState + 1);

          map.clearOverlays();
          zoom=11
          drawGrid();
      }

function drawGrid () {

         overlayIndoor();

         var cosR =  Math.sin(poleLat*Math.atan(1) / 45)*Math.sin(poleLat * Math.atan(1) / 45) + Math.cos(poleLat*Math.atan(1) / 45)*Math.cos(poleLat * Math.atan(1) / 45) * Math.cos(( Math.atan(1) / 45));
         map.setCenter(centro, zoom);

           var points = [];
        for (var k = 1; k < 3; k++) {
 
         if(zoom < 11.5) {  var fator= 5  }//zoom/2.2  
         else {var fator=2} 

           var Ry = fator * 0.009 * k 
           var Rx = fator * k / (Math.round(10*(Math.atan(-cosR / Math.sqrt(-cosR * cosR + 1)) + 2 * Math.atan(1))  * 45 * 111.18/ Math.atan(1) )/10) ;

           for (var i = 0; i < 73; i++) {
 
             var winkel= 360/72*Math.PI*i/180;
             var WoLat = poleLat + Ry * Math.cos(winkel);
             var WoLon = poleLon + Rx * Math.sin(winkel);
  
             points.push(new GLatLng(WoLat ,WoLon ));
           }
        }      // var k

    map.addOverlay(new GPolyline(points, "#ff0000", 2, 0.7));

   var radioy = fator * 0.009*3
   var radiox = fator *3 / (Math.round(10*(Math.atan(-cosR / Math.sqrt(-cosR * cosR + 1)) + 2 * Math.atan(1))  * 45 * 111.18/ Math.atan(1) )/10) ;

   var polyline = new GPolyline([ new GLatLng(poleLat + radioy, poleLon),  new GLatLng(poleLat-radioy, poleLon) ], "#ff0000", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat + Math.sqrt(3)*radioy/2, poleLon + radiox/2), new GLatLng(poleLat - Math.sqrt(3)*radioy/2, poleLon - radiox/2) ], "#ff0000", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([ new GLatLng(poleLat + radioy/2, poleLon + radiox*0.866),new GLatLng(poleLat - radioy/2, poleLon - radiox*0.866) ], "#ff0000", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat , poleLon + radiox),new GLatLng(poleLat, poleLon-radiox)], "#ff0000", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat-radioy/2 , poleLon + radiox*.866),new GLatLng(poleLat+radioy/2 , poleLon - radiox*.866)], "#ff0000",1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat-radioy*.866 , poleLon + radiox*.5),new GLatLng(poleLat+radioy*.866 , poleLon - radiox*.5)], "#ff0000", 1, 1);   map.addOverlay(polyline);


   var polyline = new GPolyline([ new GLatLng(poleLat+ .96*radioy, poleLon+radiox*.5/3),new GLatLng(poleLat + Math.sqrt(3)*radioy/2/3, poleLon + radiox/2/3)   ], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([ new GLatLng(poleLat+ .92*radioy, poleLon+radiox/3),new GLatLng(poleLat + Math.sqrt(3)*radioy/3, poleLon + radiox/3)   ], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([ new GLatLng(poleLat - .96 *radioy, poleLon-radiox*.5/3),new GLatLng(poleLat - Math.sqrt(3)*radioy/2/3, poleLon - radiox/2/3)   ], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([ new GLatLng(poleLat - .92 *radioy, poleLon-radiox/3),new GLatLng(poleLat - Math.sqrt(3)*radioy/3, poleLon - radiox/3)   ], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat-radioy/6, poleLon+radiox*.866/3),new GLatLng(poleLat-radioy/6 , poleLon + radiox*.96)], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat-radioy/3, poleLon+radiox*.866*2/3),new GLatLng(poleLat-radioy/3 , poleLon + radiox*.92)], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat+radioy/6, poleLon-radiox*.866/3),new GLatLng(poleLat+radioy/6 , poleLon - radiox*.96)], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat+radioy/3, poleLon-radiox*.866*2/3),new GLatLng(poleLat+radioy/3 , poleLon - radiox*.92)], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([ new GLatLng(poleLat+ radioy/6, poleLon+radiox*.866/3),new GLatLng(poleLat + .76 * radioy, poleLon + radiox * 0.64) ], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([ new GLatLng(poleLat+ radioy/3, poleLon+radiox*2*.866/3),new GLatLng(poleLat + .65 * radioy, poleLon + radiox*0.77) ], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([ new GLatLng(poleLat- radioy/6, poleLon-radiox*.866/3),new GLatLng(poleLat - .76 *radioy, poleLon - radiox*0.64) ], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([ new GLatLng(poleLat- radioy/3, poleLon-radiox*2*.866/3),new GLatLng(poleLat - .65 * radioy, poleLon - radiox*0.77) ], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat, poleLon+radiox/3),new GLatLng(poleLat + radioy*.35, poleLon + radiox*.92) ], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat, poleLon+ 2* radiox / 3),new GLatLng(poleLat + radioy*.17, poleLon + radiox*.97) ], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat, poleLon - radiox/3),new GLatLng(poleLat - radioy*.35, poleLon - radiox*.93) ], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat, poleLon - 2* radiox / 3),new GLatLng(poleLat - radioy*.17, poleLon - radiox*.97) ], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat-radioy*.866/3, poleLon + radiox/6),new GLatLng(poleLat-radioy*.64 , poleLon + .76* radiox)], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat-radioy*2*.866/3, poleLon + radiox/3),new GLatLng(poleLat-radioy*.77 , poleLon + .65 * radiox)], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat+radioy*.866/3, poleLon - radiox/6),new GLatLng(poleLat+radioy*.64 , poleLon -  .76 * radiox )], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat+radioy*2*.866/3, poleLon - radiox/3),new GLatLng(poleLat+radioy*.77 , poleLon - .65 * radiox )], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat-radioy/3, poleLon),new GLatLng(poleLat-radioy*.93 , poleLon+radiox*.35)], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat-radioy*2/3, poleLon),new GLatLng(poleLat-radioy*.97 , poleLon+radiox*.17)], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat+radioy/3, poleLon),new GLatLng(poleLat+radioy * .93 , poleLon - radiox*.35)], "#0000ff", 1, 1);   map.addOverlay(polyline);
   var polyline = new GPolyline([new GLatLng(poleLat+radioy*2/3, poleLon),new GLatLng(poleLat+radioy * .97 , poleLon - radiox*.17)], "#0000ff", 1, 1);   map.addOverlay(polyline);

  var points = [];
  var i=0;  points.push(new GLatLng(poleLat - radioy * .287, poleLon - radiox * .166));
      i=1 ; points.push(new GLatLng(poleLat - radioy *.44, poleLon - radiox *.255));
      i=2;points.push(new GLatLng(poleLat - radioy *.42, poleLon - radiox *.3));
      i=3 ; points.push(new GLatLng(poleLat - radioy *.397, poleLon - radiox *.33));
      i=4;points.push(new GLatLng(poleLat - radioy *.38, poleLon - radiox *.35));
      i=5; points.push(new GLatLng(poleLat - radioy * .33, poleLon - radiox * .385));
      i=6;  points.push(new GLatLng(poleLat - radioy * .167, poleLon - radiox * .29));
      i=7;points.push(new GLatLng(poleLat - radioy *.208, poleLon - radiox *.26));
      i=8;  points.push(new GLatLng(poleLat - radioy * .23, poleLon - radiox * .242));
      i=9;points.push(new GLatLng(poleLat - radioy *.266, poleLon - radiox *.2));
  points.push(points[0]);   

  map.addOverlay(new GPolygon(points, "#ff0000", 0, 0.7, "#000fff", 0.2));

   var tinyIcon = new GIcon();

  if (zoom < 11.5) { tinyIcon.image = "http://www.volksnav.de/mapplet/r50.ico";}
  else  { tinyIcon.image = "http://www.volksnav.de/mapplet/r20.ico";}

   tinyIcon.iconSize = new GSize(25, 25);
   tinyIcon.iconAnchor = new GPoint(10, 10);

    var winkelR= 15*Math.PI/180;
    var WoLatR = poleLat - Ry * Math.cos(winkelR)/2;
    var WoLonR = poleLon - Rx * Math.sin(winkelR)/2;
    var pontoR = new GLatLng(WoLatR,WoLonR);

   map.addOverlay(new GMarker(pontoR, {icon:tinyIcon}));

   if(zoom < 11.5) {tinyIcon.image = "http://www.volksnav.de/mapplet/M25.ico";}
   else {tinyIcon.image = "http://www.volksnav.de/mapplet/M10.ico";}
   
    tinyIcon.iconSize = new GSize(25, 25);
   tinyIcon.iconAnchor = new GPoint(10, 10);

    var WoLatM = poleLat - Ry /1.5;
    var WoLonM = poleLon - Rx /4;
    var pontoM = new GLatLng(WoLatM,WoLonM);

   map.addOverlay(new GMarker(pontoM, {icon:tinyIcon}));

  }  // function drawGrid


function showTabs(){
       var tab2 = new GInfoWindowTab('address', div2);
       var tab3 = new GInfoWindowTab('hour/sector', div3);
       var tab4 = new GInfoWindowTab('minutes', div4);
       var tab5 = new GInfoWindowTab('radius', div5);
       var tab6 = new GInfoWindowTab('indoor', div6);

       map.openInfoWindowTabs(centro, [tab1, tab2,tab3, tab4, tab5, tab6])
}

function showPosition(marker, point) {

    if (typeof(point) == "undefined" || point == null) {
      return;
    }
    if (position_marker != null) {
      map.removeOverlay(position_marker);
    }
        position_marker = new GMarker(point);

   var cosR =  Math.sin(poleLat*Math.atan(1) / 45)*Math.sin(poleLat * Math.atan(1) / 45) + Math.cos(poleLat*Math.atan(1) / 45)*Math.cos(poleLat * Math.atan(1) / 45) * Math.cos(( Math.atan(1) / 45));
   var coordy = (point.lat().toString() - poleLat) * 1111.8; 
   var coordx = (point.lng().toString() - poleLon) * Math.round(10*(Math.atan(-cosR / Math.sqrt(-cosR * cosR + 1)) + 2 * Math.atan(1))  * 45 * 1111.8/ Math.atan(1) )/10 ;
   var  hipotenusa = Math.round( Math.sqrt(coordx * coordx + coordy * coordy) );
   var verhaeltnis = Math.abs(coordy)/Math.abs(coordx);

   if (verhaeltnis>=1.73 && coordx>0 && coordy>0) { HH=12; HM=Math.round(coordx); }
   else if (verhaeltnis < .577 && coordx>0 && coordy>0)  { HH=2; HM=Math.round( Math.abs(0.5 * coordx) - Math.abs(0.866 * coordy)); }
   else if (verhaeltnis<1.73 &&verhaeltnis>.577 && coordx>0 && coordy>0) { HH=1; HM=Math.round(Math.abs(0.866 * coordx) - Math.abs(0.5 * coordy)); }
   else if (verhaeltnis>=1.73 && coordx>0 && coordy<0) { HH=5; HM=Math.round(Math.abs(0.5 * coordy) - Math.abs(0.866 * coordx)); }
   else if (verhaeltnis<.577 && coordx>0 && coordy<0) { HH=3; HM=Math.round(Math.abs( coordy)); }
   else if (verhaeltnis<1.73 &&verhaeltnis>.577 && coordx>0 && coordy<0) { HH=4; HM=Math.round(Math.abs(0.866 * coordy) - Math.abs(0.5 * coordx)); }
   else if (verhaeltnis>=1.73 && coordx<0 && coordy<0) { HH=6; HM=Math.round(Math.abs(coordx)); }
   else if (verhaeltnis<.577 && coordx<0 && coordy<0) { HH=8; HM=Math.round(Math.abs(0.5 * coordx) - Math.abs(0.866 * coordy)); }
   else if (verhaeltnis<1.73 &&verhaeltnis>.577 && coordx<0 && coordy<0) { HH=7; HM=Math.round(Math.abs(0.866 * coordx) - Math.abs(0.5 * coordy)); }
   else if (verhaeltnis>=1.73 && coordx<0 && coordy>0) { HH=11; HM=Math.round(Math.abs(0.5 * coordy) - Math.abs(0.866 * coordx)); }
   else if (verhaeltnis<.577 && coordx<0 && coordy>0) { HH=9; HM=Math.round(Math.abs(coordy)); }
   else if (verhaeltnis<1.73 &&verhaeltnis>.577 && coordx<0 && coordy>0) { HH=10; HM=Math.round(Math.abs(0.866 * coordy) - Math.abs(0.5 * coordx)); }

    map.addOverlay(position_marker);

     if ( hipotenusa<= 100) {
         if ( HM > 0 && HM >= hipotenusa/2 && HH<12) { HH=HH+1; var posmsg = "StatusQuo(c) " + kenn + " m"+ HH + "   r" + hipotenusa + "<br>\n"; }
         else if ( (HM > 0 && HM >= hipotenusa/2) && (HH=12)) { HH=1; var posmsg = "StatusQuo(c) " + kenn + " m"+ HH + "   r" + hipotenusa + "<br>\n"; }
         else if ( HM > 0 && HM < hipotenusa/2) { var posmsg = "StatusQuo(c) "+ kenn +" m" + HH +  ":" + HM +"   r" + hipotenusa + "<br>\n"; }
         else if ( HM<1 ){ var posmsg = "StatusQuo(c) " + kenn + " m"+ HH + "   r" + hipotenusa + "<br>\n"; } 
     } 
     else if (hipotenusa >100) {
       var posmsg = "Radius > 10km! With this simplified conversion, the<br>\n";
        posmsg += "position codes won't harmonize with navigation devices" ;
     }
          map.openInfoWindowHtml(point, posmsg)
}   

    </script>
        <input type=button value="show grid r50/r100" onClick="incrementZoom();">
        <input type=button value="r20/r40" onClick="resetCounter();">
<font size=-2>VolksNav.com/mapplet
        <br/n>
<font size=3>Click anywhere to know the logical urban or indoor address of that point.<br/n> 
<font size=-1><br/n>
The Munich Orientation Convention quantifies positions in harmony with 
imagination power, cartography, navigation devices and codes for 
crossings, stations, bus stops, bridges etc. The index on map is at the 
same time an intelligent postal code on reality!<br><br/n>After some clicks on map
 on different zoom levels, click the buttons above and see the first ZOOMABLE search 
grid. The grid also shows a very special quad with 2.5 x 2.5 (or 1 x 1) km on sector m7. Like 
parabolic antennas, its bended sides "point" to the urban 
pole. 
        <div id="message" style="margin-top:1em"></span>
Exercise: just using your brain, try to imagine the following route:.....m1 r40 ...to ...m5 r90<hr><font size=-2> This mapplet converts lat/lon 
to StatusQuo(c) on a simplified mode, tolerable for radius < 10 km. For a professioal conversion, see VolksNav.com/mapplet.
         <br>
Copyright 2009 VolksNav(c)  <a href="mailto:volksnav@volksnav.de">Henrique Koehler</a></font>

  ]]>
  </Content>
</Module>