Nous devons laisser un utilisateur effectuer un panoramique d'une carte dans une limite. Le code suivant illustre un moyen d'accomplir cela en répondant à l'événement viewchangeend. Si la carte a été déplacée hors de la limite, elle réinitialise l'emplacement au dernier emplacement enregistré dans la zone limite.Bing maps - restreindre le panoramique à une zone limite
Cependant, il est nerveux. Et je voudrais qu'il arrête simplement de faire un panoramique une fois la limite atteinte.
Y a-t-il un moyen d'accomplir cela avec les cartes Bing?
var map;
var LastValidLocation, PanningRectLimit;
function GetMap() {
var mapOptions = {
center: new Microsoft.Maps.Location(29.771261, -95.364891),
credentials: 'a valid api key',
disableKeyboardInput: true,
disableScrollWheelZoom: true,
disableStreetside: true,
disableZooming: true,
enableClickableLogo: false,
mapTypeId: Microsoft.Maps.MapTypeId.aerial,
showDashboard: false,
showScalebar: false,
showTermsLink: false,
tileBuffer: 2,
zoom: 10
};
map = new Microsoft.Maps.Map(document.getElementById('myMap'), mapOptions);
var pushpin = new Microsoft.Maps.Pushpin(map.getCenter());
var layer = new Microsoft.Maps.Layer();
layer.add(pushpin);
map.layers.insert(layer);
LastValidLocation = map.getCenter();
PanningRectLimit = Microsoft.Maps.LocationRect.fromCorners(new Microsoft.Maps.Location(29.941359, -95.662621), new Microsoft.Maps.Location(29.583220, -95.077050));
Microsoft.Maps.Events.addHandler(map, 'viewchangestart', function(args) {});
Microsoft.Maps.Events.addHandler(map, 'viewchange', function(args) {});
Microsoft.Maps.Events.addHandler(map, 'viewchangeend', function(args) {
restrictZoom();
});
}
function restrictZoom() {
var CurrentCenter = map.getCenter();
if (PanningRectLimit.contains(CurrentCenter)) {
LastValidLocation = CurrentCenter;
} else {
map.setView({
center: LastValidLocation
});
};
};
$(document).ready(function() {
$('#centerButton').click(function() {
map.setView({
center: new Microsoft.Maps.Location(29.771261, -95.364891)
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://www.bing.com/api/maps/mapcontrol?callback=GetMap"></script>
<div id="myMap" style="width: 800px; height: 600px;"></div>
<button id="centerButton">Center</button>