forked from openaustralia/planningalerts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move maps and streetview initialisation to its own js file
- Loading branch information
Showing
2 changed files
with
45 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
function initialiseMaps(latitude, longitude, address) { | ||
var map = new mxn.Mapstraction("map_div","google"); | ||
point = new mxn.LatLonPoint(latitude, longitude); | ||
map.setCenterAndZoom(point,16); | ||
map.addControls({ zoom: 'small' }); | ||
marker = new mxn.Marker(point) | ||
marker.setLabel(address); | ||
map.addMarker(marker); | ||
|
||
// Can't yet figure out how to make the POV point at the marker | ||
var pointToLookAt = new google.maps.LatLng(latitude, longitude); | ||
var myPano = new google.maps.StreetViewPanorama(document.getElementById("pano"), | ||
{position: pointToLookAt, navigationControl: false, addressControl: false, zoom: 0}); | ||
google.maps.event.addListener(myPano, 'position_changed', function() { | ||
// Orient the camera to face the position we're interested in | ||
var angle = computeAngle(pointToLookAt, myPano.getPosition()); | ||
myPano.setPov({heading:angle, pitch:0, zoom:1}); | ||
}); | ||
var panoMarker = new google.maps.Marker({position: pointToLookAt, title: address}); | ||
panoMarker.setMap(myPano); | ||
} | ||
|
||
function computeAngle(endLatLng, startLatLng) { | ||
var DEGREE_PER_RADIAN = 57.2957795; | ||
var RADIAN_PER_DEGREE = 0.017453; | ||
|
||
var dlat = endLatLng.lat() - startLatLng.lat(); | ||
var dlng = endLatLng.lng() - startLatLng.lng(); | ||
// We multiply dlng with cos(endLat), since the two points are very closeby, | ||
// so we assume their cos values are approximately equal. | ||
var yaw = Math.atan2(dlng * Math.cos(endLatLng.lat() * RADIAN_PER_DEGREE), dlat) | ||
* DEGREE_PER_RADIAN; | ||
return wrapAngle(yaw); | ||
} | ||
|
||
function wrapAngle(angle) { | ||
if (angle >= 360) { | ||
angle -= 360; | ||
} else if (angle < 0) { | ||
angle += 360; | ||
} | ||
return angle; | ||
} |