jablonka.czprosek.czf

czfgmap

Subversion Repositories:
[/] [index.php] - Rev 7 Go to most recent revision

Compare with Previous - Blame - Download


<?php
//<!-- Copyright (C) 2008  Petr Simandl www.simandl.cz                          -->
//<!-- This file is part of CZFGmap.                                            -->
//<!--                                                                          -->
//<!-- CZFGmap 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.                                      -->
//<!--                                                                          -->
//<!-- CZFGmap 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 CZFGmap.  If not, see <http://www.gnu.org/licenses/>.         -->

error_reporting(7);

include("../forum/globalmap.php");

switch (@$_SERVER['SERVER_NAME']) {
    case "connected.czf":
        $GMapKey="ABQIAAAAvGTA14kOdSvtr3t8EjKUdxQ2n1pNbYRLwYPuGT94C-0un95jGhSkgS0a3LnGa2MzRepHicK08lDDmg";
        break;
    case "mapa.prosek.czf":
        $GMapKey="ABQIAAAAlZ9uhPay2OYt2xmaN84g0BTYUdkyQZ68wktXWB9o4y2agzv8zxRyBxtFdIbLe18hmqHTwiWPXl7VxA";
        break;
    default:
        $GMapKey="ABQIAAAAlZ9uhPay2OYt2xmaN84g0BTYUdkyQZ68wktXWB9o4y2agzv8zxRyBxtFdIbLe18hmqHTwiWPXl7VxA";
}

echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>CZFGmap</title>
    <META name="AUTHOR" content="Petr Simandl, www.simandl.cz">
    <META name="LICENSE" content="GNU General Public License">
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link REL="SHORTCUT ICON" HREF="favicon.ico">
    <style type="text/css">
      @import url("http://www.google.com/uds/css/gsearch.css");
      @import url("http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css");
      @import "czfgmap.css";
      }
    </style>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key='.$GMapKey.'"
            type="text/javascript"></script>
    <script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0" type="text/javascript"></script>
    <script src="http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js" type="text/javascript"></script>    
    <script type="text/javascript">

    //### Globalni promenne #################################
    var CurrentDatabase = "czfmutf";
    var NodeLimit = "200";
    var NodeOrder = "ASC";
    var NodeSortBy = "name";
    var Where = "";
    var LoadedNodes = new Array();
    var map;
    var NodeIcon =new Array();
    var DatabaseNodeTables =new Array();
    var AutoFetchMode = true;
    var AutoClearMode = true;
    var NumLoadedNodes = 0;
    var NumAddedNodes = 0;
    var NumLoadedLinks = 0;
    var NumAddedLinks = 0;
    var NumVisibleLinks = 0;
    var NumInVisibleLinks = 0;

    var LinkColType =new Array();
    LinkColType["00000001"] = "#00aa00";
    LinkColType["00000001"] = "#00FF00";
    var LinkColTypeWifiBackbone = "#fafa00";
    LinkColType["00000002"] = "#be0000";
    LinkColType["00000006"] = "#ff5050";
    LinkColType["00000003"] = "#64c8ff";
    LinkColType["00000004"] = "#dc00dc";
    LinkColType["00000007"] = "#c8c8c8";
    LinkColType["00000008"] = "#ffffff";
    LinkColType["00000009"] = "#fa8000";
    LinkColType["00000099"] = "#0000fa";
    var LinkColTypeNA = "#78783c";
    LinkColType["00000005"] = "#00fafa";
    
    //nacteni ikon pro nody
    var NodeType  = [0,1,9,10,98,99];
    var NodeState = [1,9,10,40,79,80,90];
    for (type in NodeType) {
      for (state in NodeState) {
        i = 10000 + NodeType[type]*100 + NodeState[state];
        NodeIcon[i] = new GIcon();
        NodeIcon[i].image = "./images/node/node-" + NodeType[type] + "-" + NodeState[state] + ".png";
        NodeIcon[i].iconSize = new GSize(15,15);
        NodeIcon[i].iconAnchor = new GPoint(7,7);
        NodeIcon[i].shadowSize = new GSize(22,20);
        NodeIcon[i].infoWindowAnchor = new GPoint(5,1);
      }
    }

    //### Uvodni funkce #################################
    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"),{draggableCursor: \'crosshair\', draggingCursor: \'pointer\'});
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GOverviewMapControl());
        map.setCenter(new GLatLng(50.123567, 14.496258), 15);
        map.enableScrollWheelZoom();
        map.addControl(new GScaleControl());
        
        map.addControl(new google.maps.LocalSearch(), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,20)));
        //tohle zajisti znovunacteni nodu po presunu
        GEvent.addListener(map, "moveend", HandleMapMoveEnd);           
        
        //ziskani souradnic po kliknuti
        GEvent.addListener(map, \'click\', function(overlay, point) { if(point) { document.getElementById("NodeCoordinates").innerHTML = (point.y.toFixed(6)+\'x\'+point.x.toFixed(6)); }} );
        
        //tohle zajisti vypis pri startu
        var center = map.getCenter();
        document.getElementById("souradnice").innerHTML = CurrentDatabase + "<br>Souradnice stredu:" + center.toString() + "<br>Rozsah: " + map.getBounds()+"<br>Zvetseni: " + map.getZoom();

        //tohle zajisti prubezny vypis
        GEvent.addListener(map, "moveend", function() {
          var center = map.getCenter();
          document.getElementById("souradnice").innerHTML = CurrentDatabase + " " + map.getBounds().getSouthWest().lat() + "<br>Souradnice stredu: " + center.toString() + "<br>Rozsah: " + map.getBounds()+"<br>Zvetseni: " + map.getZoom();
        });

        document.getElementById("AutoFetchModeCheckButton").checked = true;
        document.getElementById("AutoClearModeCheckButton").checked = true;
        document.getElementById("NodeLimitSelectBox").value = NodeLimit;
        document.getElementById("databaze").innerHTML = CurrentDatabase;

        //prvotni zobrazeni            
          ClearOverlayAndData();
          NodeLayer();

        var pts = new Array();

//      pts.push (new GLatLng(50.120771, 14.486246));
        pts.push (new GLatLng(50.118212, 14.484079));
        pts.push (new GLatLng(50.118707, 14.491160));

        poly = new BDCCPolyline(pts,"#FF0000",3,0.3,"Tohle je pokusny objekt","dash");
 
        map.addOverlay(poly);
        
        GEvent.addListener(poly,"click",function(){alert(poly.tooltip);});
        GEvent.addListener(poly,"mouseover",function(){poly.setOpacity(0.8);});
        GEvent.addListener(poly,"mouseout",function(){poly.setOpacity(0.3);});
      }
    }

    //### Ostatni funkce ###########################

    function NodeLayer() {
        //body se berou z databaze pomoci php skriptu ktery dela jen inteface a generuje xml
        Where = "";
        GDownloadUrl("mapa_genxml.php?db="+CurrentDatabase
                            +"&latmin="+map.getBounds().getSouthWest().lat()
                            +"&latmax="+map.getBounds().getNorthEast().lat()
                            +"&lonmin="+map.getBounds().getSouthWest().lng()
                            +"&lonmax="+map.getBounds().getNorthEast().lng()
                            +"&sortby="+NodeSortBy
                            +"&limit="+NodeLimit
                            +"&order="+NodeOrder
                            +"&where="+Where
                            +"&zoom="+map.getZoom()
                            , function(data) {
          var xml = GXml.parse(data);
          var nodes = xml.documentElement.getElementsByTagName("node");
          for (var i = 0; i < nodes.length; i++) {
            var id = nodes[i].getAttribute("id");
            //zobrazime jen nove nody
            if (! LoadedNodes[id]) {
              var name = nodes[i].getAttribute("name");
              var address = nodes[i].getAttribute("address");
              var type = 10000 + nodes[i].getAttribute("type")*100 + nodes[i].getAttribute("status")*1;
              var point = new GLatLng(parseFloat(nodes[i].getAttribute("lat")),
                                      parseFloat(nodes[i].getAttribute("lng")));
              var marker = CreateMarker(point, name, address, type, id);
              map.addOverlay(marker);
              LoadedNodes[id]=point;
              NumAddedNodes = NumAddedNodes + 1;
            }
          }
          document.getElementById("NumNodes").innerHTML = "Nacteno " + NumAddedNodes + " nodu";

          var links = xml.documentElement.getElementsByTagName("link");
          for (var i = 0; i < links.length; i++) {
            var id1 = links[i].getAttribute("id1");
            var id2 = links[i].getAttribute("id2");
            //nacteme jen pokud jde o novy link
            if (! LoadedLinks[id1+"x"+id2] && ! LoadedLinks[id2+"x"+id1]) {
              var backbone = links[i].getAttribute("backbone");
              var inplanning = links[i].getAttribute("inplanning");
              var type = links[i].getAttribute("type");
              var status = links[i].getAttribute("status");

              //zobrazi se jen pokud jsou k dispozici oba nody
              if ( LoadedNodes[id1] && LoadedNodes[id2]) {
                var LinkSize = (backbone * 2);
                var LinkColBg = "#000000";
                var LinkColBgOpacity = 1;
                var LinkColOpacity = 1;
                var LinkStyle = "solid";

                if (inplanning == 1) {
                    LinkColBgOpacity = 0.1;
                    LinkColOpacity = 0.2;
                    LinkColBg = "#0000FF";
                    LinkStyle = "dash";
                }
//              DebugPrint(":"+ inplanning + ":");

                var Linepts = new Array();
                Linepts = [LoadedNodes[id1],LoadedNodes[id2]];
                LineLength = Math.round(GetLineLength(Linepts[0].lat(), Linepts[0].lng(), Linepts[1].lat(), Linepts[1].lng()));

                var polyOptions = {geodesic:false};
                var polyline = new GPolyline([LoadedNodes[id1],LoadedNodes[id2]], LinkColBg, 3 + LinkSize, LinkColBgOpacity, polyOptions);
                map.addOverlay(polyline);

                var LinkColTypeAct = LinkColTypeNA;
                if ( LinkColType[type]) {
                    LinkColTypeAct = LinkColType[type];
                }

                LoadedLinks[id1+"x"+id2] = new GPolyline([LoadedNodes[id1],LoadedNodes[id2]], LinkColTypeAct, 1 + LinkSize, LinkColOpacity, polyOptions);
                map.addOverlay(LoadedLinks[id1+"x"+id2]);

                NumVisibleLinks = NumVisibleLinks + 1;
              } else {
                //zde se pokusime donahrat nod ktery nam chybi
                
                
                NumInVisibleLinks = NumInVisibleLinks + 1;
              }

//              LoadedLinks[id1+"x"+id2]=polyline;

              NumAddedLinks = NumAddedLinks + 1;
            }
          }
          document.getElementById("NumLinks").innerHTML = "Nacteno " + NumAddedLinks + " linku a zobrazeno "  + NumVisibleLinks + " linku a " + NumInVisibleLinks + " nezobrazeno.";
        });
    }

    //##############################
    function GetLineLength(Lat1, Lon1, Lat2, Lon2) {
        var R = 6371; // km
        var dLat = (Lat2-Lat1) * Math.PI / 180;
        var dLon = (Lon2-Lon1) * Math.PI / 180; 
        var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
                Math.cos(Lat1 * Math.PI / 180) * Math.cos(Lat2 * Math.PI / 180) * 
            Math.sin(dLon/2) * Math.sin(dLon/2);
        var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
        var LineLength = 1000 * R * c;
      return LineLength;
    }

    //##############################
    function HandleMapMoveEnd() {
        if (AutoFetchMode) {
          ClearOverlayAndData();
          FetchOverlayAndData();
        }
          document.getElementById("status").innerHTML = "Po presunu mame celkem " + NumAddedNodes + " nodu";
    }

    //##############################
    function CreateMarker(point, name, address, type, id) {
      var marker = new GMarker(point, {draggable: true, bounce: true, icon: NodeIcon[type]});
      var html = "<b>" + id + " " + name + "</b> <br/>" + address +" <br/>" + type;
      GEvent.addListener(marker, "dragstart", function() {
        map.closeInfoWindow();
      });
      GEvent.addListener(marker, \'click\', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }
    
    //##############################
    function SwitchDatabase(NewDatabase) {
        CurrentDatabase = NewDatabase;
        document.getElementById("souradnice").innerHTML = CurrentDatabase;
        ClearOverlayAndData();
        FetchOverlayAndData();
        document.getElementById("status").innerHTML = "Databaze zmenena na "+CurrentDatabase;
        document.getElementById("databaze").innerHTML = CurrentDatabase;
    }    
    
    //##############################
    function ChangeNodeLimit(NewNodeLimit) {
        NodeLimit = NewNodeLimit;
        FetchOverlayAndData();
        document.getElementById("status").innerHTML = "Limit zmenen na "+NewNodeLimit;
    }    

    //##############################
    function DebugPrint(Text) {
        document.getElementById("debug").innerHTML = document.getElementById("debug").innerHTML + Text;
    }    

    //##############################
    function Fetch() {
        NodeLayer();
        document.getElementById("status").innerHTML = "Nacteno";
    }    

    //##############################
    function FetchOverlayAndData() {
        if (AutoFetchMode) {
            Fetch();
        };
    }

    //##############################
    function ClearOverlayAndData() {
        if (AutoClearMode) {
            Clear();
        };
    }

    //##############################
    function Clear() {
        document.getElementById("status").innerHTML = "Smazano " + NumAddedNodes + " nodu";
        map.clearOverlays();
        LoadedNodes=Array();
        LoadedLinks=Array();
        NumAddedNodes=0;
        document.getElementById("NumNodes").innerHTML = "Nacteno " + NumAddedNodes + " nodu";
        LoadedLinks=Array();
        NumAddedLinks=0;
        NumVisibleLinks=0;
        NumInVisibleLinks=0;
        document.getElementById("NumLinks").innerHTML = "Nacteno " + NumAddedLinks + " linku";
    }

    //##############################
    function ToggleAutoFetchMode(NewAutoFetchMode) {
        AutoFetchMode = NewAutoFetchMode;
        if (AutoFetchMode) {
          document.getElementById("status").innerHTML = "Automaticke nacitani zapnuto.";
        }
        else {
          document.getElementById("status").innerHTML = "Automaticke nacitani vypnuto.";
        }    
    }    
    
    //##############################
    function ToggleAutoClearMode(NewAutoClearMode) {
        AutoClearMode = NewAutoClearMode;
        if (AutoClearMode) {
          document.getElementById("status").innerHTML = "Automaticke mazani zapnuto.";
        }
        else {
          document.getElementById("status").innerHTML = "Automaticke mazani vypnuto.";
        }    
    }    
    
  </script>
  </head>

  <body onload="load()" onunload="GUnload()">
    <table>
    <tr>
    <td>
      <div id="map" style="width: 800px; height: 600px"></div>
    </td>

    <td valign="top">
    <div id="UserInfo">';

    echo "Prihlasen jako:<br>";
    echo $bbuserinfo['username']."&nbsp;";
    echo $bbuserinfo['userid']."&nbsp;";
    echo $bbuserinfo['mapperms']."&nbsp;";
    echo $_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."&nbsp;";

    echo '</div>
    Prepnout databazi:
    <div id="databaze">0</div>
    <input type="button" value="ajax" onClick="SwitchDatabase(\'ajax\');"/>
    <input type="button" value="czfmutf" onClick="SwitchDatabase(\'czfmutf\');"/>
    <input type="button" value="gendb" onClick="SwitchDatabase(\'gendb\');"/>
    <br>
    <div id="NumNodes">0</div>
    <div id="NumLinks">0</div>
    <input type="button" value="Nacist ted" onClick="Fetch();"/>
    <input type="button" value="Smazat ted" onClick="Clear();"/>
    <br>
    Automaticke nacitani:
    <input id="AutoFetchModeCheckButton" type="checkBox" onclick="ToggleAutoFetchMode(this.checked)">
    <br>
    Automaticke mazani:
    <input id="AutoClearModeCheckButton" type="checkBox" onclick="ToggleAutoClearMode(this.checked)">
    <br>
    Limit nodu:
    <select id="NodeLimitSelectBox" onchange="ChangeNodeLimit(this.value)">
        <option value="0">0</option>
        <option value="30" selected="selected">30</option>
        <option value="60">60</option>
        <option value="200">200</option>
        <option value="500">500</option>
        <option value="1000">1000</option>
    </select>

    </td>
    </tr>

    <tr>
    <td colspan=2>

    <div id="debug"></div>
    <div id="status">Hotovo!</div>
    <div id="data"></div>
    <div id="NodeCoordinates">aaa</div>
    <div id="souradnice">Souradnice stredu:<br>Rozsah:<br>Zvetseni:</div>
    <a href="http://code.google.com/apis/maps/documentation/examples/">http://code.google.com/apis/maps/documentation/examples/</a>
    <br>
    <a href="http://code.google.com/apis/kml/documentation/kml_tut.html">http://code.google.com/apis/kml/documentation/kml_tut.html</a>
    <br>
    <a href="http://mapki.com/wiki/Knowledge_Base">http://mapki.com/wiki/Knowledge_Base</a>
    <br>
    <a href="http://www.bdcc.co.uk/Gmaps/BdccGmapBits.htm">http://www.bdcc.co.uk/Gmaps/BdccGmapBits.htm</a>
    <br>
    http://www.czfree.net/forum/showthread.php?postid=197732#post197732
    </td>
    </tr>
    
    <tr>
    <td colspan=2>
    <br>
    CZFGmap (c) Petr Simandl - GNU General Public License
    <br>
    <a href="http://websvn.prosek.czf/">websvn.prosek.czf</a>
    </td>
    </tr>
    
    </table>
    
  </body>
</html>
';
?>

Powered by WebSVN 2.2.1