2017-07-14 1 views
0

Lorsque j'ai besoin d'effacer la couche cartographique sur directionsMise à jour en mettant une nouvelle route ou changer de route en faisant glisser & drop, la fonction map.layers.clear() supprime le ligne de route.Bing Maps v8 - Effacer les calques supprime l'itinéraire polyligne de la vue cartographique

Des idées?

var map = new Microsoft.Maps.Map(document.getElementById('myMap'), { 
    credentials: 'Your Bing Maps Key', 
    center: new Microsoft.Maps.Location(47.606209, -122.332071), 
    zoom: 12 
}); 

addPushpins(); 

Microsoft.Maps.loadModule('Microsoft.Maps.Directions', function() { 
    var directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map); 
    // Set Route Mode to driving 
    directionsManager.setRequestOptions({ routeMode: Microsoft.Maps.Directions.RouteMode.driving }); 
    var waypoint1 = new Microsoft.Maps.Directions.Waypoint({ address: 'Redmond', location: new Microsoft.Maps.Location(47.67683029174805, -122.1099624633789) }); 
    var waypoint2 = new Microsoft.Maps.Directions.Waypoint({ address: 'Seattle', location: new Microsoft.Maps.Location(47.59977722167969, -122.33458709716797) }); 
    directionsManager.addWaypoint(waypoint1); 
    directionsManager.addWaypoint(waypoint2); 
    // Set the element in which the itinerary will be rendered 
    directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('printoutPanel') }); 
    directionsManager.calculateDirections(); 

    Microsoft.Maps.Events.addHandler(directionsManager, 'directionsUpdated', onUpdateDirections); 
}); 

function onUpdateDirections() { 
    map.layers.clear(); 
    addPushpins(); 
} 

function addPushpins() { 
    // Generate an array of 10 random pushpins within current map bounds 
    var pushpins = Microsoft.Maps.TestDataGenerator.getPushpins(10, map.getBounds()); 
    var layer = new Microsoft.Maps.Layer(); 
    layer.add(pushpins); 
    map.layers.insert(layer); 
} 

Répondre

0

Ceci est voulu. Les données de route sont rendues en utilisant une couche propre. Si vous effacez toutes les couches sur la carte, les directions disparaîtront également. Pour vos données, réutilisez une couche comme celle-ci:

var map = new Microsoft.Maps.Map(document.getElementById('myMap'), { 
    credentials: 'Your Bing Maps Key', 
    center: new Microsoft.Maps.Location(47.606209, -122.332071), 
    zoom: 12 
}); 

var layer = new Microsoft.Maps.Layer(); 
map.layers.insert(layer); 

addPushpins(); 

Microsoft.Maps.loadModule('Microsoft.Maps.Directions', function() { 
    var directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map); 
    // Set Route Mode to driving 
    directionsManager.setRequestOptions({ routeMode: Microsoft.Maps.Directions.RouteMode.driving }); 
    var waypoint1 = new Microsoft.Maps.Directions.Waypoint({ address: 'Redmond', location: new Microsoft.Maps.Location(47.67683029174805, -122.1099624633789) }); 
    var waypoint2 = new Microsoft.Maps.Directions.Waypoint({ address: 'Seattle', location: new Microsoft.Maps.Location(47.59977722167969, -122.33458709716797) }); 
    directionsManager.addWaypoint(waypoint1); 
    directionsManager.addWaypoint(waypoint2); 
    // Set the element in which the itinerary will be rendered 
    directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('printoutPanel') }); 
    directionsManager.calculateDirections(); 

    Microsoft.Maps.Events.addHandler(directionsManager, 'directionsUpdated', onUpdateDirections); 
}); 

function onUpdateDirections() { 
    layer.clear(); 
    addPushpins(); 
} 

function addPushpins() { 
    // Generate an array of 10 random pushpins within current map bounds 
    var pushpins = Microsoft.Maps.TestDataGenerator.getPushpins(10, map.getBounds()); 
    layer.add(pushpins); 
}