2014-07-22 13 views
5

Po dodaniu pacjenta do mojego app angularjs:angularjs Ulotka GetMap() nie działa

<leaflet id="map" defaults="defaults" center="center" bounds="bounds" controls="controls" event-broadcast="events"></leaflet> 

i ustawienie go:

// Initialise the feature group to store editable layers 
var drawnItems = new L.FeatureGroup(); 

// Initialise the draw control 
var drawControl = new L.Control.Draw({ 
    position: 'topright', 
    edit: { 
     featureGroup: drawnItems 
    } 
}); 

// Configure Leaflet 
angular.extend($scope, { 
    defaults: { 
     zoomControlPosition: 'topright', 
     minZoom: 3, 
     tileLayerOptions: { 
      detectRetina: true, 
      reuseTiles: true, 
      attribution: '<a href="http://osm.org">OpenStreetMaps</a>' 
     } 
    }, 
    center: {}, 
    controls: { 
     custom: [drawControl] 
    }, 
    events: { 
     map: { 
      enable: ['click'] 
     } 
    } 
}); 

Po tym kodzie nie dostać ocenianej (brak błąd został wyświetlony):

leafletData.getMap().then(
    function (map) { 
     alert('I have accessed the map.'); 
    } 
); 

To powinno pokazać mi alert od razu, chociaż nic się nie dzieje.

Jeśli opóźnię ten poprzedni kod, na przykład uruchomię go w funkcji kliknięcia przycisku, działa!

Czy ktoś wie, co może być problemem?

Widząc przykład, to powinno działać: https://github.com/tombatossals/angular-leaflet-directive/blob/master/examples/control-draw-example.html

CZĘŚCIOWO SOLVED

Usuwanie ID z leaflet tagu HTML rozwiązał problem. To musi być błąd.

+0

Miałem ten sam problem. Zgłosiłeś to? – schmijos

+0

Tak, zrobiłem to kilka miesięcy temu - nie podjęto jeszcze żadnych działań. – Julius

+0

Masz przekazać identyfikator znacznika do funkcji getMap() w następujący sposób: leafletData.getMap ('theMap'). Then then ... – Dojo

Odpowiedz

16

Masz przekazać id określony w znaczniku <leaflet>, aby uzyskać funkcję getMap().

W twoim przykładzie identyfikator to map. Przekazałbyś to tak:

leafletData.getMap("map").then(
    function (map) { 
     alert('I have accessed the map.'); 
    } 
);