source: trunk/Modules/Map/MapAPI.php

Last change on this file was 888, checked in by chronos, 4 years ago
  • Modified: More static types added.
File size: 5.3 KB
Line 
1<?php
2
3class MapMarker
4{
5 public array $Position;
6 public string $Text;
7}
8
9class MapPolyLine
10{
11 public array $Points = array();
12 public string $Color = 'black';
13}
14
15class Map extends Model
16{
17 public array $Position;
18 public int $Zoom;
19 public string $Key;
20 public $OnClickObject;
21 public string $MarkerText;
22 public array $Markers;
23 public array $PolyLines;
24
25 function __construct(System $System)
26 {
27 parent::__construct($System);
28 $this->Zoom = 2;
29 $this->Position = array('Lat' => 40.178873, 'Lng' => 65.039062);
30 $this->Key = '';
31 $this->ShowMarker = false;
32 $this->Markers = array();
33 $this->PolyLines = array();
34 $this->OnClickObject = null;
35 }
36
37 function Show(): string
38 {
39 return '';
40 }
41}
42
43class MapGoogle extends Map
44{
45 function ShowPage(Page $Page): string
46 {
47 $Page->Load = 'initialize()';
48 //$Page->Unload = 'google.maps.Unload()';
49 $Page->BasicHTML = true;
50 $Page->HideMenu = true;
51 $Output = '<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key='.$this->Key.'"></script>';
52 $Output .= '<script type="text/javascript">
53
54 var map;
55 var tinyIcon;
56
57 function initialize()
58 {
59
60
61 //if (GBrowserIsCompatible())
62 {
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)
77 {
78 if (point)
79 {
80 set_return (point.lat() + ";" + point.lng(),"'.$this->OnClickObject.'");
81 window.close();
82 }
83 });';
84 }
85 $Output .= '}';
86
87 // Create our "tiny" marker icon
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);
95
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 }
101 $Output .= '}
102 </script>';
103 $Output .= '<div id="map_canvas" style="width: 100%; height: 98%;"></div>';
104 return $Output;
105 }
106}
107
108class MapSeznam extends Map
109{
110
111}
112
113class MapOpenStreetMaps extends Map
114{
115 function GetPageHeader(): string
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 $Page): string
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}
Note: See TracBrowser for help on using the repository browser.