forked from ggcity/leaflet-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaflet-map.js
104 lines (90 loc) · 2.62 KB
/
leaflet-map.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { Element as PolymerElement } from '../../@polymer/polymer/polymer-element.js';
import { FlattenedNodesObserver } from '../../@polymer/polymer/lib/utils/flattened-nodes-observer.js';
import { Map } from '../../leaflet/src/map';
import { Attribution } from '../../leaflet/src/control/Control.Attribution.js'
// Need these side effects
import '../../leaflet/src/control';
import '../../leaflet/src/layer';
export class LeafletMap extends PolymerElement {
static get template() {
return `
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<!-- FIXME: Figure out Shadow DOM so this doesn't have to be included here -->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/MarkerCluster.css" media="screen">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/MarkerCluster.Default.css" media="screen">
<style>
#map {
width: 100%;
height: 100%;
@apply (--leaflet-map-component)
}
</style>
<div id="map">
<slot></slot>
</div>
`;
}
static get properties() {
return {
map: {
type: Object,
notify: true
},
latitude: {
type: Number
},
longitude: {
type: Number
},
zoom: {
type: Number
},
minZoom: {
type: Number
},
maxZoom: {
type: Number
},
zoomControl: {
type: Boolean,
value: false
},
attributionPrefix: {
type: String
},
_childrenObserver: Object
}
}
constructor() {
super();
}
connectedCallback() {
super.connectedCallback();
this.map = new Map(this.$.map, {
center: [this.latitude, this.longitude],
zoom: this.zoom,
zoomControl: this.zoomControl,
inertiaDeceleration: 3000,
inertiaMaxSpeed: 3000,
attributionControl: false,
minZoom: this.minZoom,
maxZoom: this.maxZoom,
tapTolerance: 40,
tap: false
});
if (this.attributionPrefix) {
let attrControl = new Attribution({ prefix: this.attributionPrefix });
this.map.addControl(attrControl);
}
// L.marker([this.latitude, this.longitude]).addTo(this.map);
let slot = this.shadowRoot.querySelector('slot');
this._childrenObserver = new FlattenedNodesObserver(slot, this._bindDependencies.bind(this));
}
/* Shitty way of passing value to children */
_bindDependencies({addedNodes}) {
addedNodes.forEach(n => {
n.map = this.map;
});
}
}
customElements.define('leaflet-map', LeafletMap);