-
Notifications
You must be signed in to change notification settings - Fork 2
/
gmaps.html
140 lines (126 loc) · 5.2 KB
/
gmaps.html
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Earth V3</title>
<style type="text/css">
body {
font-size: 83%;
}
#map {
height: 500px;
width:50%;
float:left;
}
#earth {
height: 500px;
width:49%;
float:left;
}
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript" src="https://www.google.com/jsapi">
</script>
<script type="text/javascript" src="src/googleearth.js">
</script>
<script type="text/javascript">
google.load('earth', '1');
var map;
var googleEarth;
function init(){
map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(41.8397, -87.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
try {
googleEarth = new GoogleEarth(map, document.getElementById('earth'));
}
catch (e) {
alert(e);
return;
}
google.maps.event.addListenerOnce(map, 'tilesloaded', function(){
addOverlays();
googleEarth.map_.setMapTypeId( GoogleEarth.MAP_TYPE_ID );
});
}
function addInfowindow(marker, infowindow){
google.maps.event.addListener(marker, 'click', function(){
infowindow.open(map, marker);
});
}
function getRandomLatLng(){
var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();
var latLng = new google.maps.LatLng(southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random());
return latLng;
}
function addOverlays(){
// Add some markers
for (var i = 0; i < 5; i++) {
var marker = new google.maps.Marker({
position: getRandomLatLng(),
draggable: true,
title: 'this is a marker',
icon: 'http://code.google.com/apis/maps/documentation/javascript/examples/images/beachflag.png'
});
infowindow = new google.maps.InfoWindow({
content: 'This is the infowindow for a marker'
});
addInfowindow(marker, infowindow);
marker.setMap(map);
}
// Add a polyline
var polyOptions = {
strokeWeight: 9,
strokeColor: "#FFCC30"
}
polyline = new google.maps.Polyline(polyOptions);
polyline.setMap(map);
for (var i = 0; i < 2; i++) {
polyline.getPath().push(getRandomLatLng());
}
// Add a polygon
polyOptions.fillColor = "#FF0000";
polygon = new google.maps.Polygon(polyOptions);
polygon.setMap(map);
for (var i = 0; i < 3; i++) {
polygon.getPath().push(getRandomLatLng());
}
// Add a circle
circle = new google.maps.Circle(polyOptions);
circle.setMap(map);
circle.setCenter(getRandomLatLng());
circle.setRadius(9000);
// Add a rectangle
rectangle = new google.maps.Rectangle();
rectangle.setMap(map);
rectangle.setBounds(map.getBounds());
// Add a kml layer
var ctaLayer = new google.maps.KmlLayer("http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml", {
preserveViewport: true
});
ctaLayer.setMap(map);
// Add a groundoverlay
var imageBounds = new google.maps.LatLngBounds();
imageBounds.extend(getRandomLatLng())
imageBounds.extend(getRandomLatLng());
var oldmap = new google.maps.GroundOverlay("http://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg", imageBounds);
oldmap.setMap(map);
}
google.maps.event.addDomListener(window, 'load', init);
</script>
</head>
<body>
<h1>Earth V3</h1>
<div id="map">
</div>
<div id="earth">
</div>
</body>
</html>