fix runtime warnings
[osmrrze.git] / cgis / osm-map.pl
CommitLineData
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
25c0fde3 8# The file from which we get the Template for Openlayers?
9$leaflettemplate = '/var/www/index.leaflet.html';
10
188cb5f8 11# Your should not need to change anything below this line
12# ----------------------------------------------------------------------------
13
14use CGI qw(:standard);
15use CGI qw/escape unescape escapeHTML unescapeHTML/;
16
17print("Content-type: text/html\n\n");
18my $lon = -999.0;
19my $lat = -999.0;
f83d1746 20my $mlon = -999.0;
21my $mlat = -999.0;
188cb5f8 22my $zoom = -1;
f01e50b1 23my $baselayer = undef;
188cb5f8 24if (defined(param('lon'))) {
8c5b52e4 25 $lon = param('lon') || '';
188cb5f8 26 unless ($lon =~ m/^-{0,1}\d+\.\d+$/) { $lon = -999.0; }
27 if (($lon < -180.0) || ($lon > 180.0)) { $lon = -999.0; }
28}
29if (defined(param('lat'))) {
8c5b52e4 30 $lat = param('lat') || '';
188cb5f8 31 unless ($lat =~ m/^-{0,1}\d+\.\d+$/) { $lat = -999.0; }
32 if (($lat < -90.0) || ($lat > 90.0)) { $lat = -999.0; }
33}
f83d1746 34if (defined(param('mlon'))) {
8c5b52e4 35 $mlon = param('mlon') || '';
f83d1746 36 unless ($mlon =~ m/^-{0,1}\d+\.\d+$/) { $mlon = -999.0; }
37 if (($mlon < -180.0) || ($mlon > 180.0)) { $mlon = -999.0; }
38}
39if (defined(param('mlat'))) {
8c5b52e4 40 $mlat = param('mlat') || '';
f83d1746 41 unless ($mlat =~ m/^-{0,1}\d+\.\d+$/) { $mlat = -999.0; }
42 if (($mlat < -90.0) || ($mlat > 90.0)) { $mlat = -999.0; }
43}
188cb5f8 44if (defined(param('zoom'))) {
8c5b52e4 45 $zoom = param('zoom') || '';
188cb5f8 46 unless ($zoom =~ m/^\d+$/) { $zoom = -1; }
47 if (($zoom < 0) || ($zoom > 30)) { $lat = -1; }
48}
f01e50b1 49if (defined(param('layers'))) {
898873d3
UO
50 # Mapping for Openlayers Permalinks
51 my @layerlist = ('osmde', 'osmorg', 'osmorglowzoom', 'luftbilderl');
8c5b52e4
MM
52 my $layers = param('layers') || '';
53 $layers .= ' '; # Just append spaces so we do not get warnings if the string was too short.
f01e50b1 54 my $i;
55 for ($i = 0; $i < int(@layerlist); $i++) {
56 if (substr($layers, $i, 1) eq 'B') { # This is our baselayer
57 $baselayer = $layerlist[$i];
58 }
59 }
60}
898873d3
UO
61if (defined(param('layer'))) {
62 # Mapping for Leaflet Permalinks
8c5b52e4 63 my $layers = param('layer') || '';
898873d3
UO
64 if ($layers eq 'RRZE tileserver osm.de style tiles') { $baselayer = 'osmde'; }
65 if ($layers eq 'RRZE tileserver osm.org style tiles') { $baselayer = 'osmorg'; }
66 if ($layers eq 'RRZE tileserver osm.org style with different lowzoom tiles') { $baselayer = 'osmorglowzoom'; }
67 if ($layers eq 'Luftbild Erlangen') { $baselayer = 'luftbilderl'; }
68}
f83d1746 69# If mlon/mlat is defined but lon/lat isn't, use mlat/mlon as center pos.
70if (($lon == -999.0) && ($lat == -999.0)) {
71 if ($mlat != -999.0) { $lat = $mlat; }
72 if ($mlon != -999.0) { $lon = $mlon; }
73}
25c0fde3 74$mytemplate = $openlayerstemplate; # Openlayers
75if ($0 =~ m/-leaflet/) {
76 $mytemplate = $leaflettemplate; # leaflet
77}
188cb5f8 78my $OLF;
25c0fde3 79unless (open($OLF, '<' . $mytemplate)) {
188cb5f8 80 print("Sorry, failed to read my map template.\n"); exit(0);
81}
82while ($ll = <$OLF>) {
83 # var lon = 11.028847;
84 # var lat = 49.573836;
85 # var zoom = 16;
86 if ($lon >= -180.0) {
87 $ll =~ s/var\s+lon\s*=\s*-{0,1}\d+\.\d+;/var lon = $lon;/;
88 }
89 if ($lat >= -90.0) {
90 $ll =~ s/var\s+lat\s*=\s*-{0,1}\d+\.\d+;/var lat = $lat;/;
91 }
f83d1746 92 # In any case, because the script understands the "invalid" value!
93 $ll =~ s/var\s+mlon\s*=\s*-{0,1}\d+\.\d+;/var mlon = $mlon;/;
94 $ll =~ s/var\s+mlat\s*=\s*-{0,1}\d+\.\d+;/var mlat = $mlat;/;
188cb5f8 95 if ($zoom >= 0) {
96 $ll =~ s/var\s+zoom\s*=\s*\d+;/var zoom = $zoom;/;
97 }
98 if (($lon >= -180.0) && ($lat >= -180.0) && ($zoom >= 0)) { # All values required in that case
f01e50b1 99 my $rest = '';
100 if (defined($baselayer)) {
101 $rest .= '&maptype=' . $baselayer;
102 }
f83d1746 103 if (($mlon != -999.0) && ($mlat != -999.0)) {
104 $rest .= "&markers=$mlat,$mlon,ol-marker";
105 }
f01e50b1 106 $ll =~ s!<img src="(.*?)/staticmaplite\?.*?size=([^"&]+).*?"!<img src="$1/staticmaplite?center=$lat,$lon&zoom=$zoom&size=$2$rest"!;
188cb5f8 107 }
108 print($ll);
109}
110close($OLF);
This page took 0.118379 seconds and 4 git commands to generate.