Changeset 864


Ignore:
Timestamp:
Nov 10, 2019, 11:32:13 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Used embedded OpenStreetMaps as google maps v2 API is deprecated and v3 needs billing information.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/IS/IS.php

    r849 r864  
    456456        } else $TabContent .= $this->ShowList($TypeItem['Table'], '`'.
    457457          $TypeItem['Ref'].'`='.$Id, $Item['Caption'],
    458           $TypeItem['Ref'], $Id).'<br/>';       
     458          $TypeItem['Ref'], $Id).'<br/>';
    459459      }
    460460      $I++;
     
    682682    if(defined('NEW_PERMISSION') and !$this->System->User->CheckPermission($this->TableToModule($Table), 'Write'))
    683683      return('Nemáte oprávnění');
    684     $MapApi = new MapApiGoogle($this->System);
    685     $MapApi->Position = array('Lat' => $this->System->Config['Map']['DefaultLatitude'],
     684    $Map = new MapOpenStreetMaps($this->System);
     685    $Map->Position = array('Lat' => $this->System->Config['Map']['DefaultLatitude'],
    686686      'Lng' => $this->System->Config['Map']['DefaultLongitude']);
    687     $MapApi->Zoom = $this->System->Config['Map']['DefaultZoom'];
    688     $MapApi->Key = $this->System->Config['Map']['GoogleMapsApiKey'];
    689     $MapApi->OnClickObject = $_GET['r'];
     687    $Map->Zoom = $this->System->Config['Map']['DefaultZoom'];
     688    $Map->Key = $this->System->Config['Map']['GoogleMapsApiKey'];
     689    $Map->OnClickObject = $_GET['r'];
    690690    //$MapApi->ShowMarker = true;
    691     $Output = $MapApi->ShowPage($this);
     691    $Output = $Map->ShowPage($this);
    692692    return($Output);
    693693  }
  • trunk/Modules/Map/Map.php

    r833 r864  
    88  var $ShortTitle = 'Mapa sítě';
    99  var $ParentClass = 'PagePortal';
    10   var $Load = 'initialize()';
    11   var $Unload = 'GUnload()';
     10  //var $Load = 'initialize()';
     11  //var $Unload = 'GUnload()';
    1212
    1313  function Show()
     
    3030      $DbRow = $DbResult->fetch_assoc();
    3131      $Pos = explode(';', $DbRow['Pos']);
    32       $MapApi = new MapApiGoogle($this->System);
     32      $MapApi = new MapOpenStreetMaps($this->System);
    3333      $MapApi->Position = array('Lat' => $Pos[0], 'Lng' => $Pos[1]);
    3434      $MapApi->Zoom = 18;
    3535      $MapApi->Key = $this->System->Config['Map']['GoogleMapsApiKey'];
    3636      $MapApi->ShowMarker = true;
    37       $MapApi->MarkerText = $DbRow['Name'];
     37      $Marker = new MapMarker();
     38      $Marker->Text = $DbRow['Name'];
     39      $Marker->Position = $MapApi->Position;
     40      $MapApi->Markers[] = $Marker;
    3841      $Output = $MapApi->ShowPage($this);
    3942      return($Output);
     
    4346  function ShowMain()
    4447  {
    45     $Output = '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key='.
    46     $this->System->Config['Map']['GoogleMapsApiKey'].'"
    47     type="text/javascript">
    48   </script>';
    49     $Output .= '<script type="text/javascript">
    50 
    51     var map;
    52     var tinyIcon;
    53 
    54     function initialize()
    55     {
    56 
    57       if (GBrowserIsCompatible())
    58       {
    59         map = new GMap2(document.getElementById("map_canvas"));
    60         map.setMapType(G_SATELLITE_MAP);
    61         map.setCenter(new GLatLng(49.260422, 18.081179), 15);
    62         map.setUIToDefault();
    63         map.addControl(new GOverviewMapControl(new GSize(128, 96)));
    64 
    65 
    66 // Create our "tiny" marker icon
    67 var tinyIcon = new GIcon();
    68 tinyIcon.image = "point.gif";
    69 tinyIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    70 tinyIcon.iconSize = new GSize(10, 10);
    71 tinyIcon.shadowSize = new GSize(10, 10);
    72 tinyIcon.iconAnchor = new GPoint(5, 5);
    73 tinyIcon.infoWindowAnchor = new GPoint(5, 1);
    74 
    75   toggleLabel(\'NetworkLinks\');
    76   toggleLabel(\'NetworkDevices\');';
    77 
    78       $Output .= '
    79        }
    80     }
    81 
    82 function toggleLabel(id)
    83 {
    84   var ele = document.getElementById(id);
    85   ele.checked = !ele.checked;
    86   ele.onclick( );
    87 }
    88 
    89     function UpdateNetworkLinks()
    90     {
    91       if ((document.getElementById("NetworkLinks")).checked == true)
    92       {
    93         NetworkLinks = [';
     48    $Map = new MapOpenStreetMaps($this->System);
     49    $Map->Position = array('Lat' => $this->System->Config['Map']['DefaultLatitude'],
     50      'Lng' => $this->System->Config['Map']['DefaultLongitude']);
     51    $Map->Zoom = $this->System->Config['Map']['DefaultZoom'];
     52    $Map->Key = $this->System->Config['Map']['GoogleMapsApiKey'];
     53    //$Map->OnClickObject = $_GET['r'];
     54    //$MapApi->ShowMarker = true;
     55
     56    $DbResult = $this->Database->query('SELECT GROUP_CONCAT(`NetworkDevice`.`Name` SEPARATOR ",") AS `Name`, '.
     57    '`MapPosition`.`Pos` AS `Pos`, `MapPosition`.`Name` AS `NodeName` '.
     58    'FROM `NetworkDevice` LEFT JOIN `MapPosition` ON `MapPosition`.`Id` = `NetworkDevice`.`MapPosition` '.
     59    'WHERE (`NetworkDevice`.`Used`=1) AND (`NetworkDevice`.`MapPosition` IS NOT NULL) '.
     60    'GROUP BY `NetworkDevice`.`MapPosition`');
     61    while($Device = $DbResult->fetch_assoc())
     62    {
     63      $Pos = explode(';', $Device['Pos']);
     64      $Marker = new MapMarker();
     65      $Marker->Position = array('Lat' => $Pos[0], 'Lng' => $Pos[1]);
     66      $Marker->Text = $Device['NodeName'].': '.$Device['Name'];
     67      $Map->Markers[] = $Marker;
     68    }
     69
    9470    $DbResult = $this->Database->query('SELECT * FROM `NetworkLink` WHERE (`Interface1` <> 0) AND (`Interface2` <> 0)');
    9571    while($Link = $DbResult->fetch_assoc())
     
    10884        $Pos2 = explode(';', $Device2['Pos']);
    10985        if(($Device1['Used'] == 1) and ($Device2['Used'] == 1))
    110           $Output .= 'new GPolyline([new GLatLng('.$Pos1[0].', '.
    111         $Pos1[1].'),new GLatLng('.$Pos2[0].', '.$Pos2[1].')], "#4F4FBF", 3, 0.8), ';
     86        {
     87          $PolyLine = new MapPolyLine();
     88          $PolyLine->Color = '#4F4FBF';
     89          $PolyLine->Points[] = array('Lat' => $Pos1[0], 'Lng' => $Pos1[1]);
     90          $PolyLine->Points[] = array('Lat' => $Pos2[0], 'Lng' => $Pos2[1]);
     91          $Map->PolyLines[] = $PolyLine;
     92        }
     93      }
     94    }
     95
     96    $Output = $Map->ShowPage($this);
     97
     98
     99    /*
     100    $Output = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?key='.
     101    $this->System->Config['Map']['GoogleMapsApiKey'].'"></script>';
     102    $Output .= '<script type="text/javascript">
     103
     104    var map;
     105    var tinyIcon;
     106
     107    function initialize()
     108    {
     109
     110      //if (google.maps.BrowserIsCompatible())
     111      {
     112        map = new google.maps.Map(document.getElementById("map_canvas"));
     113        map.setMapTypeId(\'satellite\');
     114        map.setCenter(new google.maps.LatLng(49.260422, 18.081179), 15);
     115        //map.setUIToDefault();
     116        //map.addControl(new google.maps.OverviewMapControl(new google.maps.Size(128, 96)));
     117
     118
     119// Create our "tiny" marker icon
     120//var tinyIcon = new google.maps.Icon();
     121//tinyIcon.image = "point.gif";
     122//tinyIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
     123//tinyIcon.iconSize = new google.maps.Size(10, 10);
     124//tinyIcon.shadowSize = new google.maps.Size(10, 10);
     125//tinyIcon.iconAnchor = new google.maps.Point(5, 5);
     126//tinyIcon.infoWindowAnchor = new google.maps.Point(5, 1);
     127
     128  toggleLabel(\'NetworkLinks\');
     129  toggleLabel(\'NetworkDevices\');';
     130
     131      $Output .= '
     132       }
     133    }
     134
     135function toggleLabel(id)
     136{
     137  var ele = document.getElementById(id);
     138  ele.checked = !ele.checked;
     139  ele.onclick( );
     140}
     141
     142    function UpdateNetworkLinks()
     143    {
     144      if ((document.getElementById("NetworkLinks")).checked == true)
     145      {
     146        NetworkLinks = [';
     147    $DbResult = $this->Database->query('SELECT * FROM `NetworkLink` WHERE (`Interface1` <> 0) AND (`Interface2` <> 0)');
     148    while($Link = $DbResult->fetch_assoc())
     149    {
     150      $DbResult2 = $this->Database->query('SELECT `NetworkDevice`.`Used`, `MapPosition`.`Pos` FROM `NetworkDevice` '.
     151        'JOIN `MapPosition` ON `MapPosition`.`Id` = `NetworkDevice`.`MapPosition` '.
     152        'WHERE `NetworkDevice`.`Id` = (SELECT `NetworkInterface`.`Device` FROM `NetworkInterface` WHERE `NetworkInterface`.`Id` = '.$Link['Interface1'].')');
     153      $DbResult3 = $this->Database->query('SELECT `NetworkDevice`.`Used`, `MapPosition`.`Pos` FROM `NetworkDevice` '.
     154        'JOIN `MapPosition` ON `MapPosition`.`Id` = `NetworkDevice`.`MapPosition` '.
     155        'WHERE `NetworkDevice`.`Id` = (SELECT `NetworkInterface`.`Device` FROM `NetworkInterface` WHERE `NetworkInterface`.`Id` = '.$Link['Interface2'].')');
     156      if(($DbResult2->num_rows > 0) and ($DbResult3->num_rows > 0))
     157      {
     158        $Device1 = $DbResult2->fetch_assoc();
     159        $Pos1 = explode(';', $Device1['Pos']);
     160        $Device2 = $DbResult3->fetch_assoc();
     161        $Pos2 = explode(';', $Device2['Pos']);
     162        if(($Device1['Used'] == 1) and ($Device2['Used'] == 1))
     163          $Output .= 'new google.maps.Polyline([new google.maps.LatLng('.$Pos1[0].', '.
     164        $Pos1[1].'),new google.maps.LatLng('.$Pos2[0].', '.$Pos2[1].')], "#4F4FBF", 3, 0.8), ';
    112165      }
    113166    }
     
    148201    {
    149202      $Pos = explode(';', $Device['Pos']);
    150       $Output .= 'new GMarker(new GLatLng('.$Pos[0].', '.
    151       $Pos[1].'), {title: "'.$Device['NodeName'].': '.$Device['Name'].'", icon:tinyIcon }), ';
     203      $Output .= 'new google.maps.Marker(new google.maps.LatLng('.$Pos[0].', '.
     204      $Pos[1].'), {title: "'.$Device['NodeName'].': '.$Device['Name'].'", icon:\'point.gif\' }), ';
    152205    }
    153206    $Output .= '];
     
    182235                  </tr>
    183236                </table>';
     237    */
    184238    return($Output);
    185239  }
  • trunk/Modules/Map/MapAPI.php

    r738 r864  
    11<?php
    22
    3 class MapApi extends Model
     3class MapMarker
     4{
     5  var $Position;
     6  var $Text;
     7}
     8
     9class MapPolyLine
     10{
     11  var $Points = array();
     12  var $Color = 'black';
     13}
     14
     15class Map extends Model
    416{
    517  var $Position;
     
    719  var $Key;
    820  var $OnClickObject;
    9   var $ShowMarker;
    1021  var $MarkerText;
     22  var $Markers;
     23  var $PolyLines;
    1124
    1225  function __construct($System)
     
    1730    $this->Key = '';
    1831    $this->ShowMarker = false;
    19     $this->MarkerText = '';
     32    $this->Markers = array();
     33    $this->PolyLines = array();
     34    $this->OnClickObject = null;
    2035  }
    2136
     
    2641}
    2742
    28 class MapApiGoogle extends MapApi
     43class MapGoogle extends Map
    2944{
    3045  function ShowPage($Page)
    3146  {
    3247    $Page->Load = 'initialize()';
    33     $Page->Unload = 'GUnload()';
     48    //$Page->Unload = 'google.maps.Unload()';
    3449    $Page->BasicHTML = true;
    3550    $Page->HideMenu = true;
    36     $Output = '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key='.
    37       $this->Key.'"
    38       type="text/javascript">
    39       </script>';
     51    $Output = '<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key='.$this->Key.'"></script>';
    4052    $Output .= '<script type="text/javascript">
    4153
     
    4557    function initialize()
    4658    {
    47       if (GBrowserIsCompatible())
     59
     60
     61      //if (GBrowserIsCompatible())
    4862      {
    49         map = new GMap2(document.getElementById("map_canvas"));
    50         map.setMapType(G_SATELLITE_MAP);
    51         map.setCenter(new GLatLng('.$this->Position['Lat'].', '.$this->Position['Lng'].'), '.$this->Zoom.');
    52         map.setUIToDefault();
    53         map.addControl(new GOverviewMapControl(new GSize(128, 96)));
    54 
    55         GEvent.addListener(map,"click",function(overlay, point)
     63        map = new google.maps.Map(document.getElementById("map_canvas"));
     64        map.center = {lat: 45.518, lng: -122.672};
     65        map.zoom = 18;
     66        map.heading = 90;
     67        map.tilt = 45;
     68        map.mapTypeId = \'satellite\';
     69        map.zoom = '.$this->Zoom.';
     70        map.setCenter(new google.maps.LatLng('.$this->Position['Lat'].', '.$this->Position['Lng'].'), '.$this->Zoom.');
     71        //map.setUIToDefault();
     72        //map.addControl(new google.maps.OverviewMapControl(new google.maps.Size(128, 96)));
     73        ';
     74    if ($this->OnClickObject != null)
     75    {
     76      $Output .= 'google.maps.event.addListener(map,"click", function(overlay, point)
    5677        {
    57           if (point) {
     78          if (point)
     79          {
    5880            set_return(point.lat() + ";" + point.lng(),"'.$this->OnClickObject.'");
    5981            window.close();
    6082          }
    61         });
    62       }
     83        });';
     84    }
     85    $Output .= '}';
    6386
    6487    // Create our "tiny" marker icon
    65     var tinyIcon = new GIcon();
    66     tinyIcon.image = "'.$this->System->Link('/Modules/Map/point.gif').'";
    67     tinyIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
    68     tinyIcon.iconSize = new GSize(10, 10);
    69     tinyIcon.shadowSize = new GSize(10, 10);
    70     tinyIcon.iconAnchor = new GPoint(5, 5);
    71     tinyIcon.infoWindowAnchor = new GPoint(5, 1);
    72     ';
     88    //var tinyIcon = new google.maps.Icon();
     89    //tinyIcon.image = "'.$this->System->Link('/Modules/Map/point.gif').'";
     90    //tinyIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
     91    //tinyIcon.iconSize = new google.maps.Size(10, 10);
     92    //tinyIcon.shadowSize = new google.maps.Size(10, 10);
     93    //tinyIcon.iconAnchor = new google.maps.Point(5, 5);
     94    //tinyIcon.infoWindowAnchor = new google.maps.Point(5, 1);
    7395
    74     if($this->ShowMarker)
    75       $Output .= 'map.addOverlay(new GMarker(new GLatLng('.$this->Position['Lat'].', '.
    76       $this->Position['Lng'].'), {title: "'.$this->MarkerText.'" }));';
     96    foreach ($this->Markers as $Marker)
     97    {
     98      $Output .= 'map.addOverlay(new google.maps.Marker(new google.maps.LatLng('.$Marker->Position['Lat'].', '.
     99      $Marker->Position['Lng'].'), {title: "'.$Marker->Text.'" }));';
     100    }
    77101    $Output .= '}
    78102    </script>';
     
    82106}
    83107
    84 class MapApiSeznam extends MapApi
     108class MapSeznam extends Map
    85109{
    86110
    87111}
     112
     113class MapOpenStreetMaps extends Map
     114{
     115  function GetPageHeader()
     116  {
     117    $Output = '<link rel="stylesheet" href="https://unpkg.com/leaflet@1.5.1/dist/leaflet.css"
     118    integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
     119    crossorigin=""/>';
     120    $Output .= '<script src="https://unpkg.com/leaflet@1.5.1/dist/leaflet.js"
     121    integrity="sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og=="
     122    crossorigin=""></script>';
     123    return $Output;
     124  }
     125
     126  function ShowPage($Page)
     127  {
     128    $this->System->PageHeaders[] = array($this, 'GetPageHeader');
     129    $Page->Load = 'initialize()';
     130    $Page->BasicHTML = true;
     131    $Page->HideMenu = true;
     132    $Output = '<script type="text/javascript">
     133    function initialize()
     134    {
     135      var mymap = L.map(\'mapid\').setView(['.$this->Position['Lat'].','.$this->Position['Lng'].'], '.$this->Zoom.');
     136      L.tileLayer(\'https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}\', {
     137        attribution: \'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>\',
     138        maxZoom: 18,
     139        id: \'mapbox.streets\',
     140        accessToken: \'pk.eyJ1IjoiY2hyb25vc2N6IiwiYSI6ImNrMnRqMzh3dTByM2czYnB2dnhnaWY0bjMifQ.ONeadi5sPjG5arnvfhxxGQ\'
     141      }).addTo(mymap);
     142    ';
     143
     144    foreach ($this->Markers as $Marker)
     145    {
     146      $Output .= 'var marker = L.marker(['.$Marker->Position['Lat'].', '.$Marker->Position['Lng'].'], { title: \''.$Marker->Text.'\'}).addTo(mymap);
     147      ';
     148    }
     149    foreach ($this->PolyLines as $PolyLine)
     150    {
     151      $Points = array();
     152      foreach ($PolyLine->Points as $Point)
     153        $Points[] = '['.$Point['Lat'].', '.$Point['Lng'].']';
     154      $Output .= 'var latlngs = ['.implode(', ', $Points).'];
     155        var polyline = L.polyline(latlngs, {color: \'red\'}).addTo(mymap);
     156      ';
     157    }
     158    if ($this->OnClickObject != null)
     159    {
     160      $Output .= 'function onMapClick(e)
     161      {
     162          if (e)
     163          {
     164            set_return(e.latlng.lat + ";" + e.latlng.lng,"'.$this->OnClickObject.'");
     165            window.close();
     166          }
     167        }
     168        mymap.on(\'click\', onMapClick);';
     169    }
     170    $Output .= '
     171    }
     172    </script>';
     173    $Output .= '<div id="mapid" style="width: 100%; height: 90%;"></div>';
     174    return $Output;
     175  }
     176}
  • trunk/Packages/Common/Error.php

    r784 r864  
    6363  }
    6464
    65   function ExceptionHandler(Exception $Exception)
     65  function ExceptionHandler(Throwable $Exception)
    6666  {
    6767    $Backtrace = $Exception->getTrace();
Note: See TracChangeset for help on using the changeset viewer.