3 # OSM Map CGI - creating a HTML page that starts in the right place
5 # The file from which we get the Template for Openlayers?
6 $openlayerstemplate = '/var/www/index.openlayers.html';
8 # Your should not need to change anything below this line
9 # ----------------------------------------------------------------------------
11 use CGI qw(:standard);
12 use CGI qw/escape unescape escapeHTML unescapeHTML/;
14 print("Content-type: text/html\n\n");
20 my $baselayer = undef;
21 if (defined(param('lon'))) {
23 unless ($lon =~ m/^-{0,1}\d+\.\d+$/) { $lon = -999.0; }
24 if (($lon < -180.0) || ($lon > 180.0)) { $lon = -999.0; }
26 if (defined(param('lat'))) {
28 unless ($lat =~ m/^-{0,1}\d+\.\d+$/) { $lat = -999.0; }
29 if (($lat < -90.0) || ($lat > 90.0)) { $lat = -999.0; }
31 if (defined(param('mlon'))) {
32 $mlon = param('mlon');
33 unless ($mlon =~ m/^-{0,1}\d+\.\d+$/) { $mlon = -999.0; }
34 if (($mlon < -180.0) || ($mlon > 180.0)) { $mlon = -999.0; }
36 if (defined(param('mlat'))) {
37 $mlat = param('mlat');
38 unless ($mlat =~ m/^-{0,1}\d+\.\d+$/) { $mlat = -999.0; }
39 if (($mlat < -90.0) || ($mlat > 90.0)) { $mlat = -999.0; }
41 if (defined(param('zoom'))) {
42 $zoom = param('zoom');
43 unless ($zoom =~ m/^\d+$/) { $zoom = -1; }
44 if (($zoom < 0) || ($zoom > 30)) { $lat = -1; }
46 if (defined(param('layers'))) {
47 my @layerlist = ('osmde', 'osmorg');
48 my $layers = param('layers');
50 for ($i = 0; $i < int(@layerlist); $i++) {
51 if (substr($layers, $i, 1) eq 'B') { # This is our baselayer
52 $baselayer = $layerlist[$i];
56 # If mlon/mlat is defined but lon/lat isn't, use mlat/mlon as center pos.
57 if (($lon == -999.0) && ($lat == -999.0)) {
58 if ($mlat != -999.0) { $lat = $mlat; }
59 if ($mlon != -999.0) { $lon = $mlon; }
62 unless (open($OLF, '<' . $openlayerstemplate)) {
63 print("Sorry, failed to read my map template.\n"); exit(0);
65 while ($ll = <$OLF>) {
66 # var lon = 11.028847;
67 # var lat = 49.573836;
70 $ll =~ s/var\s+lon\s*=\s*-{0,1}\d+\.\d+;/var lon = $lon;/;
73 $ll =~ s/var\s+lat\s*=\s*-{0,1}\d+\.\d+;/var lat = $lat;/;
75 # In any case, because the script understands the "invalid" value!
76 $ll =~ s/var\s+mlon\s*=\s*-{0,1}\d+\.\d+;/var mlon = $mlon;/;
77 $ll =~ s/var\s+mlat\s*=\s*-{0,1}\d+\.\d+;/var mlat = $mlat;/;
79 $ll =~ s/var\s+zoom\s*=\s*\d+;/var zoom = $zoom;/;
81 if (($lon >= -180.0) && ($lat >= -180.0) && ($zoom >= 0)) { # All values required in that case
83 if (defined($baselayer)) {
84 $rest .= '&maptype=' . $baselayer;
86 if (($mlon != -999.0) && ($mlat != -999.0)) {
87 $rest .= "&markers=$mlat,$mlon,ol-marker";
89 $ll =~ s!<img src="(.*?)/staticmaplite\?.*?size=([^"&]+).*?"!<img src="$1/staticmaplite?center=$lat,$lon&zoom=$zoom&size=$2$rest"!;