This repository has been archived by the owner on Oct 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trackview.js
213 lines (199 loc) · 7.91 KB
/
trackview.js
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/**
* Track View - custom Google Streetview Panorama server
* Copyright (C) 2011 Mike Cochrane
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Mike Cochrane <[email protected]>
* @copyright 2011 Mike Cochrane <[email protected]>
*
* @license GNU Affero General Public License http://www.gnu.org/licenses/
*/
var panorama;
var map;
function initialize() {
/* Map Style */
var simplifiedMap = [
{
featureType: "transit.station",
elementType: "all",
stylers: [
{ visibility: "off" }
]
},{
featureType: "road.highway",
elementType: "all",
stylers: [
{ visibility: "simplified" },
{ saturation: -99 }
]
},{
featureType: "road",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
},{
featureType: "administrative.land_parcel",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
},{
featureType: "road.arterial",
elementType: "all",
stylers: [
{ visibility: "simplified" },
{ saturation: -99 }
]
},{
featureType: "road.local",
elementType: "all",
stylers: [
{ visibility: "simplified" },
{ invert_lightness: true },
{ saturation: -99 },
{ lightness: 62 }
]
}
];
/* Create Map */
var mapOptions = {
center: new google.maps.LatLng(-36.86392, 174.75748),
zoom: 19,
overviewMapControl: false,
overviewMapControlOptions: {
opened: true
},
mapTypeControlOptions: {
mapTypeIds: ["trackview", google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.TERRAIN]
},
mapTypeId: "trackview"
};
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
map.mapTypes.set('trackview', new google.maps.StyledMapType(simplifiedMap, {name: "Trackview"}));
/* Add trackview provider */
panorama = map.getStreetView();
panorama.registerPanoProvider(getCustomPanorama);
/* Watch for Streetview overlay being added */
google.maps.event.addDomListener(map.overlayMapTypes, 'insert_at', insert_at);
google.maps.event.addDomListener(map.overlayMapTypes, 'remove_at', remove_at);
/* Watch for the panorama links changing */
google.maps.event.addListener(panorama, 'links_changed', links_changed);
/* HACK BECAUSE GOOGLE FORGOT TO BUILD THIS API */
/* Override getPanoramaByLocation to allow pegman to return custom panoramas when dropped */
google.maps.StreetViewService['prototype'].getPanoramaByLocationOrig = google.maps.StreetViewService['prototype'].getPanoramaByLocation;
google.maps.StreetViewService['prototype'].getPanoramaByLocation = function(point, radius, callback) {
var SVParent = this;
$.ajax({
url: "http://beta.trackview.org.nz/getPanoramaByLocation.php",
dataType: 'json',
data: {lat: point.lat(), lng: point.lng(), radius: radius},
success: function(data) {
// TODO: Get trackview and google results and return the closest */
if (data) {
/* Trackview panorama */
data.location.latLng = new google.maps.LatLng(data.location.latLng[0], data.location.latLng[1]);
data.tiles.tileSize = new google.maps.Size(data.tiles.tileSize[0], data.tiles.tileSize[1]);
data.tiles.worldSize = new google.maps.Size(data.tiles.worldSize[0], data.tiles.worldSize[1]);
data.tiles.getTileUrl = getTrackviewPanoTileUrl;
callback(data, google.maps.StreetViewStatus.OK);
} else {
/* Try for Google Street View panorama instead */
return SVParent.getPanoramaByLocationOrig(point, radius, callback);
}
}
});
};
}
/**
* map.overlayMapTypes.insert_at Event Handler
*/
function insert_at(number, mapOverlay) {
if (number == 0) {
/* Streetview overlay was added, add trackview overlay too */
map.overlayMapTypes.insertAt(1,
new google.maps.ImageMapType({
getTileUrl: function(coord, zoom) {
var X = coord.x % (1 << zoom); // wrap
return "http://beta.trackview.org.nz/overlaytile.php?output=overlay&zoom=" + zoom + "&x=" + X + "&y=" + coord.y;
},
tileSize: new google.maps.Size(256, 256),
isPng: true
})
);
}
}
/**
* map.overlayMapTypes.remove_at Event Handler
*/
function remove_at(number, mapOverlay) {
/* Steetview overlay removed, remove trackview too */
if (map.overlayMapTypes.length) {
map.overlayMapTypes.pop();
}
}
/**
* Return the url for a panorama tile
*/
function getTrackviewPanoTileUrl(pano, zoom, tileX, tileY) {
return 'http://beta.trackview.org.nz/tile.php?pano=' + pano + '&zoom=' + zoom + '&x=' + tileX + '&y=' +tileY + '&fmt=jpg';
}
function getCustomPanorama(pano, zoom, tileX, tileY) {
// TODO: pull these from server - hmm async?
if (pano.substring(0, 10) != 'trackview:') {
return null;
}
return {
location: {
pano: pano,
description: "Basque Park",
latLng: new google.maps.LatLng(-36.86392, 174.75748)
},
links: [{
'heading': 40,
'description' : 'Macaulay Street (Google)',
'roadColor' : '#FF0080',
'pano' : 'PRkP18Twk8nx2Sdlm033Nw'
}],
copyright: 'Imagery (c) 2011 MikeNZ',
tiles: {
tileSize: new google.maps.Size(1024, 512),
worldSize: new google.maps.Size(4096, 2048),
centerHeading: 220,
getTileUrl: getTrackviewPanoTileUrl
}
};
}
/**
* panorama.links_changed Event Handler
* Add links to trackview panoramas from Google Street view panoramas
*/
function links_changed() {
if (panorama.getPano().substring(0, 10) == "trackview:") {
/* Local panorama is linked already */
return;
}
/* Get trackview links to Google Street View panoramas */
$.ajax({
url: "http://beta.trackview.org.nz/links.php",
dataType: 'json',
data: {pano: panorama.getPano()},
success: function(data) {
for (i = 0; i < data.length; i++) {
panorama.getLinks().push(data[i]);
}
}
});
}