aboutsummaryrefslogtreecommitdiffstats
path: root/elm-mapbox.umd.js.patch
blob: 1a9748cad0068a5d3e2901eb70f98fbc461a58a4 (plain)
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
--- node_modules/elm-mapbox/dist/elm-mapbox.umd.js	1985-10-26 09:15:00.000000000 +0100
+++ elm-mapbox.umd.js	2019-09-12 18:24:24.087505291 +0200
@@ -77,9 +77,16 @@
 	      get mapboxStyle() {
 	        return this._style;
 	      }
-	      set mapboxStyle(value) {
-	        if (this._map) this._map.setStyle(value);
-	        this._style = value;
+	      set mapboxStyle(value)
+	        if (this._map) {
+            // This is a simple check to prevent mapbox from
+            // setting the style over and over agian, otherwise
+            // it may cause errors by using events ...
+            if (JSON.stringify(this._style) != JSON.stringify(value)) {
+              this._map.setStyle(value);
+            }
+          }
+          this._style = value;
 	      }
 
 	      get minZoom() {
@@ -229,7 +236,8 @@
 	            };
 	          } else if (["touchend", "touchmove", "touchcancel"].includes(type)) {
 	            wrapped = e => {
-	              e.features = this._map.queryRenderedFeatures([e.point], {
+                // removed the arrays, caused errors with using touch-events
+	              e.features = this._map.queryRenderedFeatures(e.point, {
 	                layers: this.eventFeaturesLayers,
 	                filter: this.eventFeaturesFilter
 	              });
@@ -304,14 +312,18 @@
 	        );
 	        this._eventRegistrationQueue = {};
 	        options.onMount(this._map, this);
-	        if (commandRegistry[this.id]) {
-	          this._map.on("load", () => {
-	            var cmd;
-	            while ((cmd = commandRegistry[this.id].shift())) {
-	              cmd(this._map);
-	            }
-	          });
-	        }
+          if (commandRegistry[this.id]) {
+            function onStyleData(){
+              if(map.isStyleLoaded()) {
+                var cmd;
+                while ((cmd = commandRegistry[this.id].shift())) {
+                  cmd(this._map);
+                }
+                map.off('data', onStyleData)
+              }
+            };
+            this._map.on("data", onStyleData);
+          }
 	        return this._map;
 	      }
 
@@ -415,6 +427,15 @@
 	              bounds: map.getBounds().toArray()
 	            });
 
+            // use it to get the center and the current zoom-level of the map
+            case "getCenter":
+              return elmApp.ports[options.incomingPort].send({
+                type: "getCenter",
+                id: event.requestId,
+                center: map.getCenter().toArray(),
+                zoom: map.getZoom()
+              });
+
 	          case "queryRenderedFeatures":
 	            return elmApp.ports[options.incomingPort].send({
 	              type: "queryRenderedFeatures",