Ignore:
Timestamp:
Sep 29, 2013, 2:38:34 PM (11 years ago)
Author:
chronos
Message:
  • Upraveno: Pozice na mapě se nyní uchovávají v databázi v položce typu varchar(255) namísto dvou desetinných míst.
  • Přidáno: Nově lze vybrat při úpravě formuláře polohu přímo v mapě.
  • Upraveno: Akce zobrazení v mapě nyní zobrazuje polohu pomocí google maps.
  • Přidáno: Pro podporu více mapových systémů definována obecná třída MapApi.
File:
1 edited

Legend:

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

    r566 r574  
    11<?php
    22
    3 include_once(dirname(__FILE__).'/../../Common/Global.php');
     3include_once(dirname(__FILE__).'/MapAPI.php');
    44
    55class PageNetworkMap extends Page
     
    1515    if(count($this->System->PathItems) > 1)
    1616    {
    17       if($this->System->PathItems[1] == 'show-position')
    18       {
    19         $DbResult = $this->Database->select('MapPosition', '*', 'Id='.$_GET['i']);
    20         if($DbResult->num_rows > 0)
    21         {
    22           $DbRow = $DbResult->fetch_assoc();
    23           Header('Location: http://www.mapy.cz/#!x='.$DbRow['Longitude'].'&y='.
    24             $DbRow['Latitude'].'&z=17&t=s&l=15&d=user_'.$DbRow['Longitude'].'%2C'.
    25             $DbRow['Latitude'].'%2C'.$DbRow['Name'].'~%0A_1');
    26           return('Přesměrování na http://www.mapy.cz/');
    27         } else return('Položka nenalezena');
    28         return('');
    29       }
     17      if($this->System->PathItems[1] == 'show-position') return($this->ShowPosition());
    3018      else return(PAGE_NOT_FOUND);
    3119    } else return($this->ShowMain());
    3220  }
    3321 
     22  function ShowPosition()
     23  {
     24    $DbResult = $this->Database->select('MapPosition', '*', 'Id='.$_GET['i']);
     25    if($DbResult->num_rows > 0)
     26    {
     27      $DbRow = $DbResult->fetch_assoc();
     28      $Pos = explode(';', $DbRow['Pos']);
     29      $MapApi = new MapApiGoogle($this->System);
     30      $MapApi->Position = array('Lat' => $Pos[0], 'Lng' => $Pos[1]);
     31      $MapApi->Zoom = 18;
     32      $MapApi->Key = $this->System->Config['Map']['GoogleMapsApiKey'];
     33      $MapApi->ShowMarker = true;
     34      $MapApi->MarkerText = $DbRow['Name'];
     35      $Output = $MapApi->ShowPage($this);
     36      return($Output);
     37    } else return('Položka nenalezena');
     38  }
     39 
    3440  function ShowMain()
    3541  {
    36     $Output = '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key='.$this->System->Config['Web']['GoogleMapsApiKey'].'"
     42    $Output = '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key='.
     43    $this->System->Config['Map']['GoogleMapsApiKey'].'"
    3744    type="text/javascript">
    3845  </script>';
     
    6067tinyIcon.shadowSize = new GSize(10, 10);
    6168tinyIcon.iconAnchor = new GPoint(5, 5);
    62 tinyIcon.infoWindowAnchor = new GPoint(5, 1);';
    63    
    64     $Output .= '   
     69tinyIcon.infoWindowAnchor = new GPoint(5, 1);
     70   
     71        toggleLabel(\'NetworkLinks\');
     72        toggleLabel(\'NetworkDevices\');';
     73   
     74            $Output .= '   
    6575       }     
    6676    }
     
    8191    while($Link = $DbResult->fetch_assoc())
    8292    {
    83       $DbResult2 = $this->Database->query('SELECT NetworkDevice.Used, MapPosition.Latitude, MapPosition.Longitude FROM NetworkDevice JOIN MapPosition ON MapPosition.Id = NetworkDevice.MapPosition WHERE NetworkDevice.Id = (SELECT NetworkInterface.Device FROM NetworkInterface WHERE NetworkInterface.Id = '.$Link['Interface1'].')');
    84       $DbResult3 = $this->Database->query('SELECT NetworkDevice.Used, MapPosition.Latitude, MapPosition.Longitude FROM NetworkDevice JOIN MapPosition ON MapPosition.Id = NetworkDevice.MapPosition WHERE NetworkDevice.Id = (SELECT NetworkInterface.Device FROM NetworkInterface WHERE NetworkInterface.Id = '.$Link['Interface2'].')');
     93      $DbResult2 = $this->Database->query('SELECT NetworkDevice.Used, MapPosition.Pos FROM NetworkDevice '.
     94        'JOIN MapPosition ON MapPosition.Id = NetworkDevice.MapPosition '.
     95        'WHERE NetworkDevice.Id = (SELECT NetworkInterface.Device FROM NetworkInterface WHERE NetworkInterface.Id = '.$Link['Interface1'].')');
     96      $DbResult3 = $this->Database->query('SELECT NetworkDevice.Used, MapPosition.Pos FROM NetworkDevice '.
     97        'JOIN MapPosition ON MapPosition.Id = NetworkDevice.MapPosition '.
     98        'WHERE NetworkDevice.Id = (SELECT NetworkInterface.Device FROM NetworkInterface WHERE NetworkInterface.Id = '.$Link['Interface2'].')');
    8599      if(($DbResult2->num_rows > 0) and ($DbResult3->num_rows > 0))
    86100      {
    87101        $Device1 = $DbResult2->fetch_assoc();
     102        $Pos1 = explode(';', $Device1['Pos']);
    88103        $Device2 = $DbResult3->fetch_assoc();
     104        $Pos2 = explode(';', $Device2['Pos']);
    89105        if(($Device1['Used'] == 1) and ($Device2['Used'] == 1))
    90           $Output .= 'new GPolyline([new GLatLng('.$Device1['Latitude'].', '.$Device1['Longitude'].'),new GLatLng('.$Device2['Latitude'].', '.$Device2['Longitude'].')], "#4F4FBF", 3, 0.8), ';
     106          $Output .= 'new GPolyline([new GLatLng('.$Pos1[0].', '.
     107        $Pos1[1].'),new GLatLng('.$Pos2[0].', '.$Pos2[1].')], "#4F4FBF", 3, 0.8), ';
    91108      }
    92109    }
     
    120137
    121138    $DbResult = $this->Database->query('SELECT GROUP_CONCAT(NetworkDevice.Name SEPARATOR ",") AS Name, '.
    122       'MapPosition.Latitude AS Latitude, MapPosition.Longitude AS Longitude, MapPosition.Name AS NodeName '.
     139      'MapPosition.Pos AS Pos, MapPosition.Name AS NodeName '.
    123140      'FROM NetworkDevice LEFT JOIN MapPosition ON MapPosition.Id = NetworkDevice.MapPosition '.
    124141      'WHERE (NetworkDevice.Used=1) AND (NetworkDevice.MapPosition IS NOT NULL) '.
     
    126143    while($Device = $DbResult->fetch_assoc())
    127144    {
    128       $Output .= 'new GMarker(new GLatLng('.$Device['Latitude'].', '.
    129       $Device['Longitude'].'), {title: "'.$Device['NodeName'].': '.$Device['Name'].'", icon:tinyIcon }), ';
     145      $Pos = explode(';', $Device['Pos']);
     146      $Output .= 'new GMarker(new GLatLng('.$Pos[0].', '.
     147      $Pos[1].'), {title: "'.$Device['NodeName'].': '.$Device['Name'].'", icon:tinyIcon }), ';
    130148    }
    131149    $Output .= '];
     
    141159                        NetworkDevices[i] = null;
    142160                }
    143         }
     161        }       
    144162}
    145163
     
    151169    <td style="width: 20%">
    152170    <form>
    153     <input type="checkbox" id="NetworkLinks" onClick="UpdateNetworkLinks();" >
     171    <input type="checkbox" id="NetworkLinks" onClick="UpdateNetworkLinks();">
    154172       <a href="" onClick="toggleLabel(\'NetworkLinks\');return false;">Ukázat spoje</a>
    155173       </input><br />
    156     <input type="checkbox" id="NetworkDevices" onClick="UpdateNetworkDevices();" >
     174    <input type="checkbox" id="NetworkDevices" onClick="UpdateNetworkDevices();">
    157175       <a href="" onClick="toggleLabel(\'NetworkDevices\');return false;">Ukázat zařízení</a>
    158176       </input>
     
    160178                  </tr>
    161179                </table>';
     180    return($Output);
     181  }
     182}
     183
     184class TypeMapPosition extends TypeString
     185{
     186  function OnEdit($Item)
     187  {
     188    $Output = parent::OnEdit($Item);
     189    if($this->FormManager->ShowRelation)
     190      $Output .=  '<img src="'.$this->FormManager->Root.'/images/select.png" alf="Vybrat" language="javascript" '.
     191        'onclick="return popupwindow(&quot;'.$this->FormManager->Root.'/is/?a=mapselect&amp;r='.
     192        $Item['Name'].'&quot;,&quot;test&quot;);" style="cursor:hand;cursor:pointer"/>';
    162193    return($Output);
    163194  }
     
    182213    parent::Start();
    183214    $this->System->Pages['map'] = 'PageNetworkMap';
     215    $this->System->FormManager->Type->RegisterType('MapPosition', 'String', array());
    184216    $this->System->FormManager->RegisterClass('MapPosition', array(
    185217      'Title' => 'Pozice na mapě',
     
    187219      'Items' => array(
    188220        'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
    189         'Latitude' => array('Type' => 'Float', 'Caption' => 'Zeměpisná šířka', 'Default' => '0'),
    190         'Longitude' => array('Type' => 'Float', 'Caption' => 'Zeměpisná výška', 'Default' => '0'),
     221        'Pos' => array('Type' => 'MapPosition', 'Caption' => 'Poloha', 'Default' => '0;0'),
    191222      ),
    192223      'ItemActions' => array(
Note: See TracChangeset for help on using the changeset viewer.