How to correctly get the bounding box using LocationRect.fromLocations() when locations span 180th meridian? var map, MM = Microsoft.Maps; function showMap(m) { var options = { mapTypeId: MM.MapTypeId.road // aerial, // center will be recalculated // zoom will be recalculated }, map1 = new MM.Map(m, options); return map1; } function doubleclickCallback(e) { e.handled = true; var bounds = map.getBounds(); map.setView({ bounds: bounds }); } function init() { var mapDiv = document.getElementById("map1"); map = showMap(mapDiv); MM.Events.addHandler(map, "dblclick", doubleclickCallback); } function monkeyPatchMapMath() { Microsoft.Maps.InternalNamespaceForDelay.MapMath. locationRectToMercatorZoom = function (windowDimensions, bounds) { var ins = Microsoft.Maps.InternalNamespaceForDelay, d = windowDimensions, g = Microsoft.Maps.Globals, n = bounds.getNorth(), s = bounds.getSouth(), e = bounds.getEast(), w = bounds.getWest(), f = ((e+360 - w) % 360)/360, //f = Math.abs(w - e) / 360, u = Math.abs(ins.MercatorCube.latitudeToY(n) - ins.MercatorCube.latitudeToY(s)), r = Math.min(d.width / (g.zoomOriginWidth * f), d.height / (g.zoomOriginWidth * u)); return ins.VectorMath.log2(r); }; } function monkeyPatchFromLocations() { Microsoft.Maps.LocationRect.fromLocations = function () { var com = Microsoft.Maps.InternalNamespaceForDelay.Common, o = com.isArray(arguments[0]) ? arguments[0] : arguments, latMax, latMin, lngMin1, lngMin2, lngMax1, lngMax2, c, lngMin, lngMax, LL, dx1, dx2, pt = Microsoft.Maps.AltitudeReference, s, e, n, f = o.length; while (f--) n = o[f], isFinite(n.latitude) && isFinite(n.longitude) && (latMax = latMax === c ? n.latitude : Math.max(latMax, n.latitude), latMin = latMin === c ? n.latitude : Math.min(latMin, n.latitude), lngMax1 = lngMax1 === c ? n.longitude : Math.max(lngMax1, n.longitude), lngMin1 = lngMin1 === c ? n.longitude : Math.min(lngMin1, n.longitude), LL = n.longitude, (LL < 0) && (LL += 360), lngMax2 = lngMax2 === c ? LL : Math.max(lngMax2, LL), lngMin2 = lngMin2 === c ? LL : Math.min(lngMin2, LL), isFinite(n.altitude) && pt.isValid(n.altitudeReference) && (e = n.altitude, s = n.altitudeReference)); dx1 = lngMax1 - lngMin1, dx2 = lngMax2 - lngMin2, lngMax = (dx1 > dx2) ? lngMax2 : lngMax1, lngMin = (dx1 > dx2) ? lngMin2 : lngMin1; return MM.LocationRect.fromEdges(latMax, lngMin, latMin, lngMax, e, s); }; } monkeyPatchFromLocations(); bounds = Microsoft.Maps.LocationRect.fromLocations(allPoints); monkeyPatchMapMath(); map1.setView({bounds:bounds}); bounds = Microsoft.Maps.LocationRect.fromLocations(allPoints); var viewBoundaries = Microsoft.Maps.LocationRect.fromLocations(polygon.getLocations()); map.setView({ bounds: viewBoundaries }); map.setView({ zoom: 10 }); function doubleclickCallback(e) { e.handled = true; var bounds = map.getBounds(); map.setView({ bounds: bounds }); } MM.Events.addHandler(map, "dblclick", doubleclickCallback); Microsoft.Maps.Events.addHandler(polygon, 'click', doubleclickCallback); function doubleclickCallback(e) { // Now we are getting the boundaries of our polygon var bounds = e.target.getLocations(); map.setView({ bounds: bounds }); map.setView({ zoom: 9}); }