188cb5f8 |
1 | #!/usr/bin/perl -w |
2 | |
3 | # OSM Map CGI - creating a HTML page that starts in the right place |
4 | |
5 | # The file from which we get the Template for Openlayers? |
6 | $openlayerstemplate = '/var/www/index.openlayers.html'; |
7 | |
8 | # Your should not need to change anything below this line |
9 | # ---------------------------------------------------------------------------- |
10 | |
11 | use CGI qw(:standard); |
12 | use CGI qw/escape unescape escapeHTML unescapeHTML/; |
13 | |
14 | print("Content-type: text/html\n\n"); |
15 | my $lon = -999.0; |
16 | my $lat = -999.0; |
17 | my $zoom = -1; |
18 | if (defined(param('lon'))) { |
19 | $lon = param('lon'); |
20 | unless ($lon =~ m/^-{0,1}\d+\.\d+$/) { $lon = -999.0; } |
21 | if (($lon < -180.0) || ($lon > 180.0)) { $lon = -999.0; } |
22 | } |
23 | if (defined(param('lat'))) { |
24 | $lat = param('lat'); |
25 | unless ($lat =~ m/^-{0,1}\d+\.\d+$/) { $lat = -999.0; } |
26 | if (($lat < -90.0) || ($lat > 90.0)) { $lat = -999.0; } |
27 | } |
28 | if (defined(param('zoom'))) { |
29 | $zoom = param('zoom'); |
30 | unless ($zoom =~ m/^\d+$/) { $zoom = -1; } |
31 | if (($zoom < 0) || ($zoom > 30)) { $lat = -1; } |
32 | } |
33 | my $OLF; |
34 | unless (open($OLF, '<' . $openlayerstemplate)) { |
35 | print("Sorry, failed to read my map template.\n"); exit(0); |
36 | } |
37 | while ($ll = <$OLF>) { |
38 | # var lon = 11.028847; |
39 | # var lat = 49.573836; |
40 | # var zoom = 16; |
41 | if ($lon >= -180.0) { |
42 | $ll =~ s/var\s+lon\s*=\s*-{0,1}\d+\.\d+;/var lon = $lon;/; |
43 | } |
44 | if ($lat >= -90.0) { |
45 | $ll =~ s/var\s+lat\s*=\s*-{0,1}\d+\.\d+;/var lat = $lat;/; |
46 | } |
47 | if ($zoom >= 0) { |
48 | $ll =~ s/var\s+zoom\s*=\s*\d+;/var zoom = $zoom;/; |
49 | } |
50 | if (($lon >= -180.0) && ($lat >= -180.0) && ($zoom >= 0)) { # All values required in that case |
51 | $ll =~ s!<img src="(.*?)/staticmaplite\?.*?size=([^"&]+).*?"!<img src="$1/staticmaplite?center=$lat,$lon&zoom=$zoom&size=$2"!; |
52 | } |
53 | print($ll); |
54 | } |
55 | close($OLF); |