our cgis
[osmrrze.git] / cgis / osm-map.pl
diff --git a/cgis/osm-map.pl b/cgis/osm-map.pl
new file mode 100755 (executable)
index 0000000..d154ff9
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/perl -w
+
+# OSM Map CGI - creating a HTML page that starts in the right place
+
+# The file from which we get the Template for Openlayers?
+$openlayerstemplate = '/var/www/index.openlayers.html';
+
+# Your should not need to change anything below this line
+# ----------------------------------------------------------------------------
+
+use CGI qw(:standard);
+use CGI qw/escape unescape escapeHTML unescapeHTML/;
+
+print("Content-type: text/html\n\n");
+my $lon = -999.0;
+my $lat = -999.0;
+my $zoom = -1;
+if (defined(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');
+  unless ($lat =~ m/^-{0,1}\d+\.\d+$/) { $lat = -999.0; }
+  if (($lat < -90.0) || ($lat > 90.0)) { $lat = -999.0; }
+}
+if (defined(param('zoom'))) {
+  $zoom = param('zoom');
+  unless ($zoom =~ m/^\d+$/) { $zoom = -1; }
+  if (($zoom < 0) || ($zoom > 30)) { $lat = -1; }
+}
+my $OLF;
+unless (open($OLF, '<' . $openlayerstemplate)) {
+  print("Sorry, failed to read my map template.\n"); exit(0);
+}
+while ($ll = <$OLF>) {
+  #      var lon = 11.028847;
+  #      var lat = 49.573836;
+  #      var zoom = 16;
+  if ($lon >= -180.0) {
+    $ll =~ s/var\s+lon\s*=\s*-{0,1}\d+\.\d+;/var lon = $lon;/;
+  }
+  if ($lat >= -90.0) {
+    $ll =~ s/var\s+lat\s*=\s*-{0,1}\d+\.\d+;/var lat = $lat;/;
+  }
+  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"!;
+  }
+  print($ll);
+}
+close($OLF);
This page took 0.051379 seconds and 4 git commands to generate.