Changeset 864 for trunk/Modules/Map/MapAPI.php
- Timestamp:
- Nov 10, 2019, 11:32:13 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Map/MapAPI.php
r738 r864 1 1 <?php 2 2 3 class MapApi extends Model 3 class MapMarker 4 { 5 var $Position; 6 var $Text; 7 } 8 9 class MapPolyLine 10 { 11 var $Points = array(); 12 var $Color = 'black'; 13 } 14 15 class Map extends Model 4 16 { 5 17 var $Position; … … 7 19 var $Key; 8 20 var $OnClickObject; 9 var $ShowMarker;10 21 var $MarkerText; 22 var $Markers; 23 var $PolyLines; 11 24 12 25 function __construct($System) … … 17 30 $this->Key = ''; 18 31 $this->ShowMarker = false; 19 $this->MarkerText = ''; 32 $this->Markers = array(); 33 $this->PolyLines = array(); 34 $this->OnClickObject = null; 20 35 } 21 36 … … 26 41 } 27 42 28 class Map ApiGoogle extends MapApi43 class MapGoogle extends Map 29 44 { 30 45 function ShowPage($Page) 31 46 { 32 47 $Page->Load = 'initialize()'; 33 $Page->Unload = 'GUnload()';48 //$Page->Unload = 'google.maps.Unload()'; 34 49 $Page->BasicHTML = true; 35 50 $Page->HideMenu = true; 36 $Output = '<script src="http://maps.google.com/maps?file=api&v=2&sensor=true&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>'; 40 52 $Output .= '<script type="text/javascript"> 41 53 … … 45 57 function initialize() 46 58 { 47 if (GBrowserIsCompatible()) 59 60 61 //if (GBrowserIsCompatible()) 48 62 { 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) 56 77 { 57 if (point) { 78 if (point) 79 { 58 80 set_return(point.lat() + ";" + point.lng(),"'.$this->OnClickObject.'"); 59 81 window.close(); 60 82 } 61 }); 62 } 83 });'; 84 } 85 $Output .= '}'; 63 86 64 87 // 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); 73 95 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 } 77 101 $Output .= '} 78 102 </script>'; … … 82 106 } 83 107 84 class Map ApiSeznam extends MapApi108 class MapSeznam extends Map 85 109 { 86 110 87 111 } 112 113 class 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 © <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 }
Note:
See TracChangeset
for help on using the changeset viewer.