allow mlat/mlon parameter that draws a marker at the specified location. If lon/lat...
authorosm@osm.rrze <osm@osm.rrze.uni-erlangen.de>
Tue, 4 Dec 2012 09:16:13 +0000 (10:16 +0100)
committerosm@osm.rrze <osm@osm.rrze.uni-erlangen.de>
Tue, 4 Dec 2012 09:16:13 +0000 (10:16 +0100)
cgis/osm-map.pl

index 6ee96e1dd248d447743f5bd51d0c38d26f151492..602efcdec5db406e2ccb6c77aeb1a3f8a3c6f297 100755 (executable)
@@ -14,6 +14,8 @@ use CGI qw/escape unescape escapeHTML unescapeHTML/;
 print("Content-type: text/html\n\n");
 my $lon = -999.0;
 my $lat = -999.0;
 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'))) {
 my $zoom = -1;
 my $baselayer = undef;
 if (defined(param('lon'))) {
@@ -26,6 +28,16 @@ if (defined(param('lat'))) {
   unless ($lat =~ m/^-{0,1}\d+\.\d+$/) { $lat = -999.0; }
   if (($lat < -90.0) || ($lat > 90.0)) { $lat = -999.0; }
 }
   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');
   unless ($zoom =~ m/^\d+$/) { $zoom = -1; }
 if (defined(param('zoom'))) {
   $zoom = param('zoom');
   unless ($zoom =~ m/^\d+$/) { $zoom = -1; }
@@ -41,6 +53,11 @@ if (defined(param('layers'))) {
     }
   }
 }
     }
   }
 }
+# 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; }
+}
 my $OLF;
 unless (open($OLF, '<' . $openlayerstemplate)) {
   print("Sorry, failed to read my map template.\n"); exit(0);
 my $OLF;
 unless (open($OLF, '<' . $openlayerstemplate)) {
   print("Sorry, failed to read my map template.\n"); exit(0);
@@ -55,6 +72,9 @@ while ($ll = <$OLF>) {
   if ($lat >= -90.0) {
     $ll =~ s/var\s+lat\s*=\s*-{0,1}\d+\.\d+;/var lat = $lat;/;
   }
   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 ($zoom >= 0) {
     $ll =~ s/var\s+zoom\s*=\s*\d+;/var zoom = $zoom;/;
   }
@@ -63,6 +83,9 @@ while ($ll = <$OLF>) {
     if (defined($baselayer)) {
       $rest .= '&maptype=' . $baselayer;
     }
     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);
     $ll =~ s!<img src="(.*?)/staticmaplite\?.*?size=([^"&]+).*?"!<img src="$1/staticmaplite?center=$lat,$lon&zoom=$zoom&size=$2$rest"!;
   }
   print($ll);
This page took 0.051117 seconds and 4 git commands to generate.