Location: PHPKode > projects > OpenBizMap > openbizmap/map.php
<!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"/>
    <link rel="stylesheet" type="text/css" href="odb_style.css" media="all" />
    <title>Map</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?php echo file_get_contents($_SERVER["SERVER_NAME"].'.key'); ?>" type="text/javascript"></script>
    <script src="http://www.google.com/uds/api?file=uds.js&amp;v=1.0&amp;source=uds-msw&amp;key=<?php echo file_get_contents($_SERVER["SERVER_NAME"].'.key'); ?>" type="text/javascript"></script>
    <style type="text/css">
    @import url("http://www.google.com/uds/css/gsearch.css");
  </style>

    <!-- Make the document body take up the full screen -->
    <style type="text/css">
      v\:* {behavior:url(#default#VML);}
      html, body {width: 100%; height: 100%}
      body {margin-top: 0px; margin-right: 0px; margin-left: 0px; margin-bottom: 0px}
      div.gsc-clear-button {display: none;}
    </style>

    <script src="http://www.google.com/uds/solutions/mapsearch/gsmapsearch.js?mode=new"  type="text/javascript"></script>

    <script type="text/javascript">
    //<![CDATA[

    <?php //----------------------------------------------------------------------------------------------------------------------------
          echo 'var odb_search = "'.$_GET['odb_search'].'";';
          echo 'var odb_new = "'.$_GET['odb_new'].'";';
          echo 'var odb_geocode = "'.$_GET['odb_geocode'].'";';

          echo 'var odb_map = "'.$_GET['odb_map'].'";';
          echo 'var odb_colorset = "'.$_GET['odb_colorset'].'";';          
          echo 'var odb_value_field_name = "'.$_GET['odb_value_field_name'].'";';
          echo 'var odb_region_field_name = "'.$_GET['odb_region_field_name'].'";';
          echo 'var odb_icon_field_name = "'.$_GET['odb_icon_field_name'].'";';
    ?>

    // Monitor the window resize event and let the map know when it occurs
    if (window.attachEvent) { 
      window.attachEvent("onresize", function() {this.map.onResize()} );
    } else {
      window.addEventListener("resize", function() {this.map.onResize()} , false);
    }

    var map;

    // SEARCH
    var searchQ="";
    var markerObject = null;
    var gotLocSearch = false;
    var t;
    var removeMarkers = false;
    function initSearch() {
          // Create a search control
          searchControl = new GSearchControl();
          var localSearch = new GlocalSearch();
          var searchOptions = new GsearcherOptions();
          var drawOptions = new GdrawOptions();
    
          drawOptions.setInput(document.getElementById("mySearch"));
          searchOptions.setRoot(document.getElementById("hidden")); // set the results to be displayed in a hidden div
          searchOptions.setExpandMode(GSearchControl.EXPAND_MODE_CLOSED); // close the results pane
          searchControl.addSearcher(localSearch, searchOptions); // Add a local searcher
    
          localSearch.setNoHtmlGeneration(); //optimization as we don't use the html
    
          // tell the searcher to draw itself and tell it where to attach
    //      searchControl.draw(document.getElementById("mySearchForm"), drawOptions);
          searchControl.draw(document.getElementById("searchcontrol"));
          // tell the search control what to do when a search returns
          searchControl.setSearchCompleteCallback(this, onSearchComplete);
          searchControl.setSearchStartingCallback(this, onSearchStart);
    }
    
    function onSearchStart(sc, searcher, query) {
      searchQ = query;
      gotLocSearch = false;
      //if (query.toUpperCase().match("PL") == null) {
      //  sc.cancelSearch();
      //  sc.execute(query + " PL");
      //}
    }
    
    function locSearchTimeout() {
      if (!gotLocSearch) {
        alert("Sorry, we could not find anywhere matching your search for: " + searchQ);
        gotLocSearch = true;//prevents multiplpe errors being reported because we had to trigger more than one search
      }
    }
    
    function onSearchComplete(sc, searcher) {
    
          // if we have local search results, put them on the map
          if ( searcher.results && searcher.results.length > 0) {
            var result = searcher.results[0];
            // if this is a local search result, then proceed...
            if (!gotLocSearch && result.GsearchResultClass == GlocalSearch.RESULT_CLASS ) {
              var point = new GLatLng(parseFloat(result.lat), parseFloat(result.lng));
              gotLocSearch = true;
                // remove any existing marker
                if (markerObject != null) {map.removeOverlay(markerObject);}
                markerObject = new GMarker(point, {title:searchQ});
                GEvent.addListener(markerObject, "click", function() {
                  map.removeOverlay(markerObject);
                  markerObject = null;
                });
                map.addOverlay(markerObject);
                map.setCenter(point,7);
            }
          } else {
            setTimeout("locSearchTimeout()", 3000);
          }
    }

    // RECTANGLE
    function Rectangle(bounds, opt_weight, opt_color) {
      this.bounds_ = bounds;
      this.weight_ = opt_weight || 1;
      this.color_ = opt_color || "#ffffff";
    }
    Rectangle.prototype = new GOverlay();
    
    // Creates the DIV representing this rectangle.
    Rectangle.prototype.initialize = function(map) {
      var div = document.createElement("div");//div
      div.style.border = this.weight_ + "px solid " + this.color_;
      div.style.opacity = "1";
      div.style.position = "absolute";
      map.getPane(G_MAP_MAP_PANE).appendChild(div); 
      this.map_ = map;
      this.div_ = div;
    }

    Rectangle.prototype.remove = function() {
      this.div_.parentNode.removeChild(this.div_);
    }

    Rectangle.prototype.copy = function() {
      return new Rectangle(this.bounds_, this.weight_, this.color_,
                          this.backgroundColor_, this.opacity_);
    }

    Rectangle.prototype.redraw = function(force) {
      if (!force) return;
      var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());
      var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());
      this.div_.style.width = Math.abs(c2.x - c1.x) + "px";
      this.div_.style.height = Math.abs(c2.y - c1.y) + "px";
      this.div_.style.left = (Math.min(c2.x, c1.x) - this.weight_) + "px";
      this.div_.style.top = (Math.min(c2.y, c1.y) - this.weight_) + "px";
    }
    //---------------------------------------------

    // REGION
    function Region(image,opacity,bounds) {
      this.image_ = image;
      this.opacity_ = opacity;
      this.bounds_ = bounds;
    }
    Region.prototype = new GOverlay();

    Region.prototype.initialize = function(map) {
      var div = document.createElement("img");
      div.style.opacity = this.opacity_;
      div.style.position = "absolute";
      div.src = this.image_;
      map.getPane(G_MAP_MAP_PANE).appendChild(div);
      this.map_ = map;
      this.div_ = div;
    }

    Region.prototype.remove = function() {
      this.div_.parentNode.removeChild(this.div_);
    }

    Region.prototype.copy = function() {
      return new Region(this.image_);
    }

    Region.prototype.redraw = function(force) {
      if (!force) return;
      
      var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());
      var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());
      this.div_.style.width = (Math.abs(c2.x - c1.x)+1) + "px";
      this.div_.style.height = (Math.abs(c2.y - c1.y)+1) + "px";
      this.div_.style.left = (Math.min(c2.x, c1.x)-1) + "px";
      this.div_.style.top = (Math.min(c2.y, c1.y)-1) + "px";
    }
    //---------------------------------------------

    function load() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));

        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.addControl(new GOverviewMapControl());
      }

      //icons
      var icon = new GIcon();
      icon.image = "http://labs.google.com/ridefinder/images/mm_20_gray.png";
      icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
      icon.iconSize = new GSize(12, 20);
      icon.shadowSize = new GSize(22, 20);
      icon.iconAnchor = new GPoint(6, 20);
      icon.infoWindowAnchor = new GPoint(5, 1);

      var latitude_max=0;
      var latitude_min=100;
      var longitude_max=0;
      var longitude_min=100;

      //Loading data from odb
      GDownloadUrl("index.php?odb_sys=export&odb_search="+odb_search+"+latitude+longitude&odb_opt=geo"+"&odb_icon_field_name="+odb_icon_field_name, function(data, responseCode) {
        //alert(data);
        var xml = GXml.parse(data);

        var agregation_array = new Array();
        var markers = xml.documentElement.getElementsByTagName("geo");
        for (var i = 0; i < markers.length; i++) {
          var latitude = parseFloat(markers[i].getAttribute("latitude"));
          var longitude = parseFloat(markers[i].getAttribute("longitude"));

          if(latitude>latitude_max)
            latitude_max=latitude;

          if(latitude<latitude_min)
            latitude_min=latitude;

          if(longitude>longitude_max)
            longitude_max=longitude;

          if(longitude<longitude_min)
            longitude_min=longitude;

          var point = new GLatLng(latitude,longitude);
          var icon_tmp = new GIcon(icon);
          var color = markers[i].getAttribute("icon");
          if(color==null)
            color='white';
          icon_tmp.image = "http://labs.google.com/ridefinder/images/mm_20_" + color + ".png";;

          if(odb_icon_field_name!='')
          {
            var marker = new GMarker(point,icon_tmp);
            marker.title=markers[i].getAttribute("sysid");
            map.addOverlay(marker);
          }
        }
        
        if(i>0)
        { 
          if(odb_map=='')
          {
            map.setCenter(new GLatLng(latitude_min+((latitude_max-latitude_min)/2), longitude_min+((longitude_max-longitude_min)/2)), 6);
          }

          if(odb_map=='generate')
          {
            map.setCenter(new GLatLng(latitude_min+((latitude_max-latitude_min)/2), longitude_min+((longitude_max-longitude_min)/2)), 6);
            var bounds = new GLatLngBounds(new GLatLng(latitude_min,longitude_min), new GLatLng(latitude_max,longitude_max));
            <?php
              echo 'map.addOverlay(new Region("index.php?odb_run=map&odb_map="+odb_map+"&odb_search="+odb_search+"&odb_region_field_name="+odb_region_field_name+"&odb_value_field_name="+odb_value_field_name+"&odb_colorset="+odb_colorset,".7",bounds));';
            ?>
          }
        }

      });


      if(odb_map!='')
      {
        <?php
          $odb_map=$_GET['odb_map'];
          if($odb_map=='generate')
          {
            echo 'map.setCenter(new GLatLng(52.2413, 19.3798), 2);';
          }
          elseif(file_exists('./maps/'.$odb_map.'.php'))
          {
            include('./maps/'.$odb_map.'.php');
            if($region_latitude_min and $region_latitude_max and $region_longitude_min and $region_longitude_max)
            {
              echo 'var bounds = new GLatLngBounds(new GLatLng('.$region_latitude_min.','.$region_longitude_min.'), new GLatLng('.$region_latitude_max.','.$region_longitude_max.'));';
              echo 'map.setCenter(new GLatLng('.(($region_latitude_min+$region_latitude_max)/2).','.(($region_longitude_min+$region_longitude_max)/2).'), '.$region_map_scale.');';
              echo 'map.addOverlay(new Region("index.php?odb_run=map&odb_map="+odb_map+"&odb_search="+odb_search+"&odb_region_field_name="+odb_region_field_name+"&odb_value_field_name="+odb_value_field_name+"&odb_colorset="+odb_colorset,".7",bounds));';
            }
            else
            {
              echo 'odb_map=""; map.setCenter(new GLatLng(52.2413, 19.3798), 2);';
            }
          }
        ?>
      }
      else
      {
         map.setCenter(new GLatLng(52.2413, 19.3798), 2);
      }
      

      GEvent.addListener(map, "click", function(marker, point) {
        if (marker) {
          //alert(marker.getPoint().lat()+" "+marker.getPoint().lng());
          if(marker.title == "?")
            GDownloadUrl("index.php?odb_onmap=1&odb_popup=1&odb_search=Latitude%3d"+marker.getPoint().lat()+"+Longitude%3d"+marker.getPoint().lng(), function(data, responseCode) { marker.openInfoWindowHtml(data); });
          else
            GDownloadUrl("index.php?odb_onmap=1&odb_popup=1&odb_search=sysId%3d" + marker.title, function(data, responseCode) { marker.openInfoWindowHtml(data); });
        } else {
          if(odb_new != "")
          {
            var marker = new GMarker(point,icon);
            marker.title = "?";
            map.addOverlay(marker);
            //alert(point.lat()+" "+point.lng());
            window.open("./index.php?odb_script=new&odb_group="+odb_new+"&odb_latitude="+point.lat()+"&odb_longitude="+point.lng()+"","geomarker","width=600,height=500,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes");
          }
          if(odb_geocode != "")
          {
            var marker = new GMarker(point,icon);
            marker.title = "?";
            map.addOverlay(marker);
            //alert(point.lat()+" "+point.lng());
            window.location="./index.php?&odb_search=sysId%3d"+odb_geocode+"&odb_latitude="+point.lat()+"&odb_longitude="+point.lng()+"","geomarker";
          }
        }
      });

      //var geoXml = new GGeoXml("http://mapgadgets.googlepages.com/cta.kml");
      //map.setCenter(new GLatLng(41.882853, -87.642059), 11);
      //map.addOverlay(geoXml);

      initSearch();
    }

    //]]>
    </script>
  </head>
  <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 100%; height: 100%;"></div>
    <div id="searchcontrol" style="position:absolute; top:3px; right:200px;">Loading...</div>
    <div id="hidden" style="visibility: hidden; position:absolute; top:26px; right:291px; width:205px; background-color:#fff; opacity:.9;"></div>
    
    
    <?php 
      if($_GET['odb_title'])
      {
        echo '<div style="margin:10px; padding:1px 10px; position:absolute; top:20px; left:50px; color:#000; background-color:#fff; border:#fff 1px solid; opacity:.9"><h1 style="margin:0; padding:0px;">'.$_GET['odb_title'].'</h1></div>';
      }
    ?>
  </body>
</html>
Return current item: OpenBizMap