README minor changes
[GeoTiles] / TESTING_WEB / index.php
1 <?
2
3 $defMap         = [ 
4                         'https://a.tile.openstreetmap.org/',
5                         'https://b.tile.openstreetmap.org/',
6                         'https://b.tile.openstreetmap.de/',
7
8                         'http://tile.thunderforest.com/cycle/',
9                         'http://tile.thunderforest.com/transport/',
10                         'http://tile.thunderforest.com/landscape/',
11
12                         'http://tile.memomaps.de/tilegen/',
13                         'https://tiles.wmflabs.org/hikebike/',
14
15                         'http://tile.stamen.com/toner/',
16                         'http://tile.stamen.com/toner-hybrid/',
17                         'http://tile.stamen.com/toner-labels/',
18                         'http://tile.stamen.com/toner-lines/',
19                         'http://tile.stamen.com/toner-background/',
20                         'http://tile.stamen.com/toner-lite/'
21
22 //                      "https://stamen-tiles.a.ssl.fastly.net/toner/"
23                 ];
24
25 $defLatLon      = [ 50.0740, 14.4505 ];
26 $defZoom        = 10;
27
28 // ---------------------- log proxy ------------------------------------------
29
30 $O_local = false; 
31
32 if ( $_SERVER['SERVER_NAME'] == 'localhost' || $_SERVER['SERVER_NAME'] == '127.0.0.1' || strstr ($_SERVER['SERVER_NAME'], '10.0.0.') ) {  
33         $O_local = true; 
34         ini_set("log_errors", 1);
35         ini_set("error_log", "/tmp/php-error.log");
36 } else {
37         ini_set("log_errors", 1);
38         ini_set("error_log", "../MYLOG/.php-error.log");
39 }
40
41 function myLog( $message, $var = '' ){
42
43         global $globalPHPFile;
44
45         if ( is_array($var) ) $var = print_r( $var, true );
46
47         error_log( '[' . urldecode(getenv('REQUEST_URI')) . '][' . basename($globalPHPFile, '.php') . '] ' . $message . $var );
48 }
49
50 if ( !isset ($_POST[ 'session_test' ]) ) {
51         myLog( "----------- MAIN -------------" );
52         myLog('REQUEST_URI MAIN: ' . $_SERVER['SERVER_NAME']);
53 }
54
55 ini_set('session.cookie_domain', $_SERVER['SERVER_NAME']);
56
57 //------------------------------ url parsing ---------------------------------
58
59 $urlLine        = explode('?', rtrim( getenv('REQUEST_URI') , '/') ); 
60 $url            = explode('/', $urlLine[0] );
61
62 if ( !empty($url[1]) )                          $mapNum         = $url[1]; else $mapNum = 0;
63 if ( !empty($url[2]) )                          $targetLocation = '/maps/' . "$url[2]|$url[3]|$url[4]|$url[5]" . '/'; else $targetLocation = $defMap[ $mapNum ];
64 if ( !empty($url[3]) && !empty($url[4]) )       $targetLatLon   = [ $url[3], $url[4] ]; else $targetLatLon = $defLatLon;
65 if ( !empty($url[5]) )                          $targetZoom     = $url[5]; else $targetZoom = $defZoom;
66
67 myLog('$targetLocation: ', $targetLocation);
68 myLog('$mapNum: ', $mapNum);
69
70 // ---------------------------------------------------------------------------
71
72 exec("ls 'maps/'", $mapList );
73
74 // ---------------------------------------------------------------------------
75
76 ?><html>
77         <head>
78                 <script src="/js/jquery-1.11.0.min.js"></script>
79
80                 <link rel="stylesheet" type="text/css" href="/js/leaflet-0.7.5/leaflet.css" />
81                 <script src="/js/leaflet-0.7.5/leaflet.js"></script>
82
83         </head>
84         
85         <style>
86                 body    { margin: 0; padding: 0 }
87                 #map    { width: 100%; height: 100% }
88                 #debug  { position: fixed; color: #fff; padding: 15px 20px; top: 10; right: 10; width: 300px; height: auto; background: rgba(0,0,0,0.5); border-radius: 15px }
89                 #debug a        { color: #eee; margin-left: -5px; padding: 2px 5px; text-decoration: none; line-height: 25px }
90                 #debug a:hover, .select { background: rgba(1,0,0,0.3); border-radius: 15px; color: white; }
91         </style>
92
93         <body>
94                 <div id="map"><!-- --></div>
95                 <div id="debug">
96 <?
97                 foreach( $mapList as $mapLine ){
98                         $map = explode('|', $mapLine);
99
100                         if ( $url[2] == $map[0] ) $select = 'class="select"'; else $select = ''
101 ?>              
102                         <a href="/<? echo $mapNum ?>/<? echo $map[0]?>/<? echo $map[1]?>/<? echo $map[2]?>/<? echo $map[3]?>" <? echo $select ?>> <?echo $map[0] ?> </a> <br />
103 <?
104                 }
105 ?>
106                         <br />
107 <?
108                 for( $a = 0; $a < count( $defMap ); $a ++ ){
109
110                         if ( $url[1] == $a ) $select = 'class="select"'; else $select = ''
111 ?>
112                         <a href="/<? echo $a ?>/" <? echo $select ?>> <? echo $defMap[ $a ] ?> </a><br />
113 <?
114                 }
115 ?>
116                         <br />
117                         <br />
118
119                         <div id="current"><!-- --></div>
120                         <div id="command"><!-- --></div>
121                 </div>
122         </body>
123
124         <script>
125
126         ml              = console.log;
127
128         defPosition     = <? echo json_encode($targetLatLon) ?>;
129         defMapZoom      = <? echo $targetZoom ?>;
130         mapPath         = '<? echo $targetLocation ?>';
131
132 //      var map = L.map('map', { zoomControl:false, attributionControl:false, fadeAnimation:false, zoomAnimation:false }).setView([ defLat, defLon ], defMapZoom);
133         map = L.map('map').setView( defPosition, defMapZoom);
134
135 //      mapObj = L.tileLayer( 'http://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png');
136         mapObj = L.tileLayer( mapPath + '{z}/{x}/{y}.png');
137
138         map.addLayer( mapObj );
139
140         lat = 0
141         lng = 0
142
143         var cl = 0;
144         var clc = [[0, 0][0, 0]];
145
146         function displayCommand(){
147                 debugTxt = clc[0][0] + ' ' + clc[0][1] + ' ' + clc[1][0] + ' ' + clc[1][1] + ' ' + map.getZoom();
148                 $('#debug #command').html( debugTxt );
149         }
150
151         function displayCurrent(){
152                 debugTxt = lat + ' ' + lng + ' ' + map.getZoom();
153                 $('#debug #current').html( debugTxt );
154         }
155
156         map.addEventListener('click', function(ev) {
157                 lat = Number(ev.latlng.lat).toFixed(5);
158                 lng = Number(ev.latlng.lng).toFixed(5);
159
160                 displayCurrent();
161
162                 clc[ cl ] = [ lat, lng ];
163
164                 if (cl == 1) {
165                         if (rect) map.removeLayer( rect );
166                         var rect = L.rectangle( [clc[0], clc[1]] , {color: 'blue', weight: 1}).addTo(map);      
167                         displayCommand();
168                 }
169
170                 marker = L.marker( ev.latlng,{ draggable: false } ).addTo( map );
171
172                 if (cl < 1) cl++;  else cl = 0;
173                 
174         });
175
176         map.on('zoomend', function() {
177                 displayCurrent();
178         });
179
180         </script>
181 </html>
182
Contact me: dev (at) shalnoff (dot) com
PGP fingerprint: A6B8 3B23 6013 F18A 0C71 198B 83D8 C64D 917A 5717