version as used after the move to new hardware in september 2022
[osmrrze.git] / cgis / osm-map.pl
index d154ff945fba13b98cd78b002d9dcf353b43e138..f4d50f0039ec5b2953c857c7f398e30303ba5133 100755 (executable)
@@ -5,6 +5,9 @@
 # The file from which we get the Template for Openlayers?
 $openlayerstemplate = '/var/www/index.openlayers.html';
 
+# The file from which we get the Template for Openlayers?
+$leaflettemplate = '/var/www/index.leaflet.html';
+
 # Your should not need to change anything below this line
 # ----------------------------------------------------------------------------
 
@@ -14,24 +17,66 @@ use CGI qw/escape unescape escapeHTML unescapeHTML/;
 print("Content-type: text/html\n\n");
 my $lon = -999.0;
 my $lat = -999.0;
+my $mlon = -999.0;
+my $mlat = -999.0;
 my $zoom = -1;
+my $baselayer = undef;
 if (defined(param('lon'))) {
-  $lon = param('lon');
+  $lon = param('lon') || '';
   unless ($lon =~ m/^-{0,1}\d+\.\d+$/) { $lon = -999.0; }
   if (($lon < -180.0) || ($lon > 180.0)) { $lon = -999.0; }
 }
 if (defined(param('lat'))) {
-  $lat = param('lat');
+  $lat = param('lat') || '';
   unless ($lat =~ m/^-{0,1}\d+\.\d+$/) { $lat = -999.0; }
   if (($lat < -90.0) || ($lat > 90.0)) { $lat = -999.0; }
 }
+if (defined(param('mlon'))) {
+  $mlon = param('mlon') || '';
+  unless ($mlon =~ m/^-{0,1}\d+\.\d+$/) { $mlon = -999.0; }
+  if (($mlon < -180.0) || ($mlon > 180.0)) { $mlon = -999.0; }
+}
+if (defined(param('mlat'))) {
+  $mlat = param('mlat') || '';
+  unless ($mlat =~ m/^-{0,1}\d+\.\d+$/) { $mlat = -999.0; }
+  if (($mlat < -90.0) || ($mlat > 90.0)) { $mlat = -999.0; }
+}
 if (defined(param('zoom'))) {
-  $zoom = param('zoom');
+  $zoom = param('zoom') || '';
   unless ($zoom =~ m/^\d+$/) { $zoom = -1; }
   if (($zoom < 0) || ($zoom > 30)) { $lat = -1; }
 }
+if (defined(param('layers'))) {
+  # Mapping for Openlayers Permalinks
+  my @layerlist = ('osmde', 'osmorg', 'osmorglowzoom', 'luftbilderl');
+  my $layers = param('layers') || '';
+  $layers .= '       '; # Just append spaces so we do not get warnings if the string was too short.
+  my $i;
+  for ($i = 0; $i < int(@layerlist); $i++) {
+    if (substr($layers, $i, 1) eq 'B') { # This is our baselayer
+      $baselayer = $layerlist[$i];
+    }
+  }
+}
+if (defined(param('layer'))) {
+  # Mapping for Leaflet Permalinks
+  my $layers = param('layer') || '';
+  if ($layers eq 'RRZE tileserver osm.de style tiles') { $baselayer = 'osmde'; }
+  if ($layers eq 'RRZE tileserver osm.org style tiles') { $baselayer = 'osmorg'; }
+  if ($layers eq 'RRZE tileserver osm.org style with different lowzoom tiles') { $baselayer = 'osmorglowzoom'; }
+  if ($layers eq 'Luftbild Erlangen') { $baselayer = 'luftbilderl'; }
+}
+# If mlon/mlat is defined but lon/lat isn't, use mlat/mlon as center pos.
+if (($lon == -999.0) && ($lat == -999.0)) {
+  if ($mlat != -999.0) { $lat = $mlat; }
+  if ($mlon != -999.0) { $lon = $mlon; }
+}
+$mytemplate = $openlayerstemplate; # Openlayers
+if ($0 =~ m/-leaflet/) {
+  $mytemplate = $leaflettemplate; # leaflet
+}
 my $OLF;
-unless (open($OLF, '<' . $openlayerstemplate)) {
+unless (open($OLF, '<' . $mytemplate)) {
   print("Sorry, failed to read my map template.\n"); exit(0);
 }
 while ($ll = <$OLF>) {
@@ -44,11 +89,21 @@ while ($ll = <$OLF>) {
   if ($lat >= -90.0) {
     $ll =~ s/var\s+lat\s*=\s*-{0,1}\d+\.\d+;/var lat = $lat;/;
   }
+  # In any case, because the script understands the "invalid" value!
+  $ll =~ s/var\s+mlon\s*=\s*-{0,1}\d+\.\d+;/var mlon = $mlon;/;
+  $ll =~ s/var\s+mlat\s*=\s*-{0,1}\d+\.\d+;/var mlat = $mlat;/;
   if ($zoom >= 0) {
     $ll =~ s/var\s+zoom\s*=\s*\d+;/var zoom = $zoom;/;
   }
   if (($lon >= -180.0) && ($lat >= -180.0) && ($zoom >= 0)) { # All values required in that case
-    $ll =~ s!<img src="(.*?)/staticmaplite\?.*?size=([^"&]+).*?"!<img src="$1/staticmaplite?center=$lat,$lon&zoom=$zoom&size=$2"!;
+    my $rest = '';
+    if (defined($baselayer)) {
+      $rest .= '&maptype=' . $baselayer;
+    }
+    if (($mlon != -999.0) && ($mlat != -999.0)) {
+      $rest .= "&markers=$mlat,$mlon,ol-marker";
+    }
+    $ll =~ s!<img src="(.*?)/staticmaplite\?.*?size=([^"&]+).*?"!<img src="$1/staticmaplite?center=$lat,$lon&zoom=$zoom&size=$2$rest"!;
   }
   print($ll);
 }
This page took 0.063204 seconds and 4 git commands to generate.