涂煌豪
2022-05-06 98e508d2852896dbde98edcc9ed6d87645a6a230
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
({
    rerender: function (component) {
 
        var nodes = this.superRerender();
 
        // If the Leaflet library is not yet loaded, we can't draw the map: return
        if (!window.L) {
            return nodes;
        }
 
        // Draw the map if it hasn't been drawn yet
        if (!component.map) {
            var mapElement = component.find("map").getElement();
            component.map = L.map(mapElement, {zoomControl: true}).setView([42.356045, -71.085650], 13);
            component.map.scrollWheelZoom.disable();
            window.L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}', {attribution: 'Tiles © Esri'}).addTo(component.map);
        }
 
        var location = component.get('v.location');
 
        if (location && location.lat && location.long) {
            var latLng = [location.lat, location.long];
            if (component.marker) {
                component.marker.setLatLng(latLng);
            } else {
                component.marker = window.L.marker(latLng);
                component.marker.addTo(component.map);
            }
            component.map.setView(latLng);
        }
 
        return nodes;
 
    }
})