allow mlat/mlon parameter that draws a marker at the specified location. If lon/lat...
[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
8# Your should not need to change anything below this line
9# ----------------------------------------------------------------------------
10
11use CGI qw(:standard);
12use CGI qw/escape unescape escapeHTML unescapeHTML/;
13
14print("Content-type: text/html\n\n");
15my $lon = -999.0;
16my $lat = -999.0;
f83d1746 17my $mlon = -999.0;
18my $mlat = -999.0;
188cb5f8 19my $zoom = -1;
f01e50b1 20my $baselayer = undef;
188cb5f8 21if (defined(param('lon'))) {
22 $lon = param('lon');
23 unless ($lon =~ m/^-{0,1}\d+\.\d+$/) { $lon = -999.0; }
24 if (($lon < -180.0) || ($lon > 180.0)) { $lon = -999.0; }
25}
26if (defined(param('lat'))) {
27 $lat = param('lat');
28 unless ($lat =~ m/^-{0,1}\d+\.\d+$/) { $lat = -999.0; }
29 if (($lat < -90.0) || ($lat > 90.0)) { $lat = -999.0; }
30}
f83d1746 31if (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; }
35}
36if (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; }
40}
188cb5f8 41if (defined(param('zoom'))) {
42 $zoom = param('zoom');
43 unless ($zoom =~ m/^\d+$/) { $zoom = -1; }
44 if (($zoom < 0) || ($zoom > 30)) { $lat = -1; }
45}
f01e50b1 46if (defined(param('layers'))) {
47 my @layerlist = ('osmde', 'osmorg');
48 my $layers = param('layers');
49 my $i;
50 for ($i = 0; $i < int(@layerlist); $i++) {
51 if (substr($layers, $i, 1) eq 'B') { # This is our baselayer
52 $baselayer = $layerlist[$i];
53 }
54 }
55}
f83d1746 56# If mlon/mlat is defined but lon/lat isn't, use mlat/mlon as center pos.
57if (($lon == -999.0) && ($lat == -999.0)) {
58 if ($mlat != -999.0) { $lat = $mlat; }
59 if ($mlon != -999.0) { $lon = $mlon; }
60}
188cb5f8 61my $OLF;
62unless (open($OLF, '<' . $openlayerstemplate)) {
63 print("Sorry, failed to read my map template.\n"); exit(0);
64}
65while ($ll = <$OLF>) {
66 # var lon = 11.028847;
67 # var lat = 49.573836;
68 # var zoom = 16;
69 if ($lon >= -180.0) {
70 $ll =~ s/var\s+lon\s*=\s*-{0,1}\d+\.\d+;/var lon = $lon;/;
71 }
72 if ($lat >= -90.0) {
73 $ll =~ s/var\s+lat\s*=\s*-{0,1}\d+\.\d+;/var lat = $lat;/;
74 }
f83d1746 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;/;
188cb5f8 78 if ($zoom >= 0) {
79 $ll =~ s/var\s+zoom\s*=\s*\d+;/var zoom = $zoom;/;
80 }
81 if (($lon >= -180.0) && ($lat >= -180.0) && ($zoom >= 0)) { # All values required in that case
f01e50b1 82 my $rest = '';
83 if (defined($baselayer)) {
84 $rest .= '&maptype=' . $baselayer;
85 }
f83d1746 86 if (($mlon != -999.0) && ($mlat != -999.0)) {
87 $rest .= "&markers=$mlat,$mlon,ol-marker";
88 }
f01e50b1 89 $ll =~ s!<img src="(.*?)/staticmaplite\?.*?size=([^"&]+).*?"!<img src="$1/staticmaplite?center=$lat,$lon&zoom=$zoom&size=$2$rest"!;
188cb5f8 90 }
91 print($ll);
92}
93close($OLF);
This page took 0.077744 seconds and 4 git commands to generate.