]>
Commit | Line | Data |
---|---|---|
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; | |
f01e50b1 | 18 | my $baselayer = undef; |
188cb5f8 | 19 | if (defined(param('lon'))) { |
20 | $lon = param('lon'); | |
21 | unless ($lon =~ m/^-{0,1}\d+\.\d+$/) { $lon = -999.0; } | |
22 | if (($lon < -180.0) || ($lon > 180.0)) { $lon = -999.0; } | |
23 | } | |
24 | if (defined(param('lat'))) { | |
25 | $lat = param('lat'); | |
26 | unless ($lat =~ m/^-{0,1}\d+\.\d+$/) { $lat = -999.0; } | |
27 | if (($lat < -90.0) || ($lat > 90.0)) { $lat = -999.0; } | |
28 | } | |
29 | if (defined(param('zoom'))) { | |
30 | $zoom = param('zoom'); | |
31 | unless ($zoom =~ m/^\d+$/) { $zoom = -1; } | |
32 | if (($zoom < 0) || ($zoom > 30)) { $lat = -1; } | |
33 | } | |
f01e50b1 | 34 | if (defined(param('layers'))) { |
35 | my @layerlist = ('osmde', 'osmorg'); | |
36 | my $layers = param('layers'); | |
37 | my $i; | |
38 | for ($i = 0; $i < int(@layerlist); $i++) { | |
39 | if (substr($layers, $i, 1) eq 'B') { # This is our baselayer | |
40 | $baselayer = $layerlist[$i]; | |
41 | } | |
42 | } | |
43 | } | |
188cb5f8 | 44 | my $OLF; |
45 | unless (open($OLF, '<' . $openlayerstemplate)) { | |
46 | print("Sorry, failed to read my map template.\n"); exit(0); | |
47 | } | |
48 | while ($ll = <$OLF>) { | |
49 | # var lon = 11.028847; | |
50 | # var lat = 49.573836; | |
51 | # var zoom = 16; | |
52 | if ($lon >= -180.0) { | |
53 | $ll =~ s/var\s+lon\s*=\s*-{0,1}\d+\.\d+;/var lon = $lon;/; | |
54 | } | |
55 | if ($lat >= -90.0) { | |
56 | $ll =~ s/var\s+lat\s*=\s*-{0,1}\d+\.\d+;/var lat = $lat;/; | |
57 | } | |
58 | if ($zoom >= 0) { | |
59 | $ll =~ s/var\s+zoom\s*=\s*\d+;/var zoom = $zoom;/; | |
60 | } | |
61 | if (($lon >= -180.0) && ($lat >= -180.0) && ($zoom >= 0)) { # All values required in that case | |
f01e50b1 | 62 | my $rest = ''; |
63 | if (defined($baselayer)) { | |
64 | $rest .= '&maptype=' . $baselayer; | |
65 | } | |
66 | $ll =~ s!<img src="(.*?)/staticmaplite\?.*?size=([^"&]+).*?"!<img src="$1/staticmaplite?center=$lat,$lon&zoom=$zoom&size=$2$rest"!; | |
188cb5f8 | 67 | } |
68 | print($ll); | |
69 | } | |
70 | close($OLF); |