bing_map.js Example File
webmapview/assets/bing_map.js
var googleMap;
var bingMap;
var markersArray = [];
function initMaps() {
console.log("init BingMaps");
var myLat = 43.449766;
var myLong = -80.406096;
bingMap = new Microsoft.Maps.Map(document.getElementById("map_canvas"), {
credentials : 'Aq19BSd2VjCXz6tNKIolUJs-jyrrWdSHSealOdlKq7jb18l1OSZWzPk3ae2qA5ac',
center : new Microsoft.Maps.Location(myLat, myLong),
zoom : 14,
mapTypeId : Microsoft.Maps.MapTypeId.auto,
enableClickableLogo: false,
enableSearchLogo: false,
showDashboard: false,
showMapTypeSelector: false,
showScalebar: false,
showCopyright : false
});
Microsoft.Maps.Events.addHandler(bingMap, 'viewchange', centerChanged);
Microsoft.Maps.Events.addHandler(bingMap, 'click', clicked);
console.log("Done init BingMaps");
}
function clicked(e) {
var location = bingMap.tryPixelToLocation(new Microsoft.Maps.Point(e.getX(), e.getY()), Microsoft.Maps.PixelReference.page);
navigator.cascades.postMessage("clicked:" + location.latitude + "," + location.longitude + "," + e.pageX + "," + e.pageY);
}
function centerChanged() {
var point = bingMap.tryLocationToPixel(bingMap.getCenter(), Microsoft.Maps.PixelReference.page);
navigator.cascades.postMessage("centerChanged:" + bingMap.getCenter().latitude + "," + bingMap.getCenter().longitude + "," + point.x + "," + point.y);
}
function onMessage(message) {
}
function setZoom(zoomLevel) {
var options = bingMap.getOptions();
options.zoom = zoomLevel;
bingMap.setView(options);
}
function zoomIn() {
setZoom(bingMap.getZoom() + 1);
}
function zoomOut() {
setZoom(bingMap.getZoom() - 1);
}
function setCenter(lat, lon) {
bingMap.setView({center:new Microsoft.Maps.Location(lat, lon)});
}
function setMapTypeId(mapType) {
var options = bingMap.getOptions();
options.mapTypeId = mapType;
bingMap.setView(options);
}
function createPushPin(lat, lon, title, iconpath) {
var pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(lat, lon), {icon:iconpath, height:60, width:60, anchor:new Microsoft.Maps.Point(20,58), draggable: true});
bingMap.entities.push(pin);
Microsoft.Maps.Events.addHandler(pin, 'click', markerClicked);
markersArray.push(pin);
}
function removeAllPins() {
if (markersArray) {
for (i in markersArray) {
bingMap.entities.remove(markersArray[i])
}
}
}
function markerClicked(e) {
var pinLoc = e.target.getLocation();
var point = bingMap.tryLocationToPixel(pinLoc, Microsoft.Maps.PixelReference.page);
navigator.cascades.postMessage("markerClicked:" + pinLoc.latitude + "," + pinLoc.longitude + "," + point.x + "," + point.y);
}