summaryrefslogtreecommitdiff
path: root/httemplate/view/map.html
blob: 1725fd852db24932d629a072cef958eeb667fc01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<& /elements/header-popup.html, {
     title => '',#$name,
     head  => $head,
     etc   => 'onload="html_googlemaps_initialize()"',
     nobr  => 1,
   }
&>

<% $map_div %>

<%init>

my $name = js_string( scalar($cgi->param('name')) );

my $point = [ map scalar($cgi->param($_)), qw( longitude latitude ) ];

my( $head, $map_div ) = onload_render(
  $name,
  map scalar($cgi->param($_)), qw( lat lon )
);

#false laziness w/Mason.pm
sub js_string {
    my $string = shift;
    $string =~ s/(['\\])/\\$1/g;
    $string =~ s/\r/\\r/g;
    $string =~ s/\n/\\n/g;
    $string = "'". $string. "'";
    return $string;
}

#subroutines below derived from HTML::GoogleMapsV3, but without using
#Geo::Coder::Google or GPS::Point
sub onload_render 
{
##	my $self = shift;
        my( $name, $latitude, $longitude ) = @_;

	#map_canvas { height: 100% }
	
	my $header='
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<style type="text/css">
  		html { height: 100% }
  		body { height: 100%; margin: 0px; padding: 0px }
  		#map_canvas { height: 100% }
	</style>
	<script type="text/javascript" src="https://maps.google.com/maps/api/js?libraries=panoramio,geometry&v=3.4&sensor=false">
	</script>
	<script type="text/javascript">
  	var lengthLine=0;
  	function html_googlemaps_initialize() {
    var latlng = new google.maps.LatLng(' .$latitude . ',' . $longitude . ');
    var myOptions = {
      zoom: 14,
      center: latlng,
      rotateControl: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    
    map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
    
    map.setOptions( {rotateControl : true });
    

	';

##our own hacked in code for displaying a marker at the center
$header .= '
var markerOptions = {
  map: map,
  position: latlng,
  title: '. $name. '
};
var marker = new google.maps.Marker(markerOptions);
';

##	if( defined $self->{polyline} ) {
##		foreach my $polyline ( keys %{$self->{polyline}} ) {
##			$header .= $self->{polyline}->{$polyline} . "\n";
##		}
##	}
	
	$header .= '}
	</script>';
	
	
	#my $div = '<div id="map_canvas" style="width:80%; height:75%"></div>';
	my $div = '<div id="map_canvas" style="width:100%; height:100%"></div>';


	$header .= "<SCRIPT>
	
	panoramioLayer = new google.maps.panoramio.PanoramioLayer();
	
	function panoramioOn(){ 
								panoramioLayer.setMap(map);
	}
	function panoramioOff() {
		panoramioLayer.setMap(null);
	}
	
	function panoramioToggle() {
		if( panoramioLayer.getMap() == null ) {
			panoramioOn(); 
		} else {
			panoramioOff();
		}
	}	
	

		
	</SCRIPT>";

	return ($header,$div)
	
}

</%init>