@hpcc-js/map 2.77.13 → 2.77.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es6.js CHANGED
@@ -21,8 +21,8 @@ function _mergeNamespaces(n, m) {
21
21
  }
22
22
 
23
23
  var PKG_NAME = "@hpcc-js/map";
24
- var PKG_VERSION = "2.77.13";
25
- var BUILD_VERSION = "2.104.35";
24
+ var PKG_VERSION = "2.77.14";
25
+ var BUILD_VERSION = "2.104.37";
26
26
 
27
27
  /******************************************************************************
28
28
  Copyright (c) Microsoft Corporation.
@@ -8878,447 +8878,449 @@ this._selectedPathOptions&&(e instanceof L.Marker?this._toggleMarkerHighlight(e)
8878
8878
  /***/ }),
8879
8879
 
8880
8880
  /***/ 290:
8881
- /***/ (function(__unused_webpack_module, exports) {
8882
-
8883
- (function (global, factory) {
8884
- factory(exports) ;
8885
- }(this, (function (exports) {
8886
- // Based on https://github.com/shramov/leaflet-plugins
8887
- // GridLayer like https://avinmathew.com/leaflet-and-google-maps/ , but using MutationObserver instead of jQuery
8888
- // 🍂class GridLayer.GoogleMutant
8889
- // 🍂extends GridLayer
8890
-
8891
- var GoogleMutant = L.GridLayer.extend({
8892
- options: {
8893
- minZoom: 0,
8894
- maxZoom: 23,
8895
- tileSize: 256,
8896
- subdomains: 'abc',
8897
- errorTileUrl: '',
8898
- attribution: '', // The mutant container will add its own attribution anyways.
8899
- opacity: 1,
8900
- continuousWorld: false,
8901
- noWrap: false,
8902
- // 🍂option type: String = 'roadmap'
8903
- // Google's map type. Valid values are 'roadmap', 'satellite' or 'terrain'. 'hybrid' is not really supported.
8904
- type: 'roadmap',
8905
- maxNativeZoom: 21
8906
- },
8907
-
8908
- initialize: function (options) {
8909
- L.GridLayer.prototype.initialize.call(this, options);
8910
-
8911
- this._ready = !!window.google && !!window.google.maps && !!window.google.maps.Map;
8912
-
8913
- this._GAPIPromise = this._ready ? Promise.resolve(window.google) : new Promise(function (resolve, reject) {
8914
- var checkCounter = 0;
8915
- var intervalId = null;
8916
- intervalId = setInterval(function () {
8917
- if (checkCounter >= 10) {
8918
- clearInterval(intervalId);
8919
- return reject(new Error('window.google not found after 10 attempts'));
8920
- }
8921
- if (!!window.google && !!window.google.maps && !!window.google.maps.Map) {
8922
- clearInterval(intervalId);
8923
- return resolve(window.google);
8924
- }
8925
- checkCounter++;
8926
- }, 500);
8927
- });
8928
-
8929
- // Couple data structures indexed by tile key
8930
- this._tileCallbacks = {}; // Callbacks for promises for tiles that are expected
8931
- this._freshTiles = {}; // Tiles from the mutant which haven't been requested yet
8932
-
8933
- this._imagesPerTile = (this.options.type === 'hybrid') ? 2 : 1;
8934
- },
8881
+ /***/ (() => {
8935
8882
 
8936
- onAdd: function (map) {
8937
- L.GridLayer.prototype.onAdd.call(this, map);
8938
- this._initMutantContainer();
8883
+ // Based on https://github.com/shramov/leaflet-plugins
8884
+ // GridLayer like https://avinmathew.com/leaflet-and-google-maps/ , but using MutationObserver instead of jQuery
8885
+
8886
+
8887
+ // 🍂class GridLayer.GoogleMutant
8888
+ // 🍂extends GridLayer
8889
+ L.GridLayer.GoogleMutant = L.GridLayer.extend({
8890
+ options: {
8891
+ minZoom: 0,
8892
+ maxZoom: 23,
8893
+ tileSize: 256,
8894
+ subdomains: 'abc',
8895
+ errorTileUrl: '',
8896
+ attribution: '', // The mutant container will add its own attribution anyways.
8897
+ opacity: 1,
8898
+ continuousWorld: false,
8899
+ noWrap: false,
8900
+ // 🍂option type: String = 'roadmap'
8901
+ // Google's map type. Valid values are 'roadmap', 'satellite' or 'terrain'. 'hybrid' is not really supported.
8902
+ type: 'roadmap',
8903
+ maxNativeZoom: 21
8904
+ },
8905
+
8906
+ initialize: function (options) {
8907
+ L.GridLayer.prototype.initialize.call(this, options);
8908
+
8909
+ this._ready = !!window.google && !!window.google.maps && !!window.google.maps.Map;
8910
+
8911
+ this._GAPIPromise = this._ready ? Promise.resolve(window.google) : new Promise(function (resolve, reject) {
8912
+ var checkCounter = 0;
8913
+ var intervalId = null;
8914
+ intervalId = setInterval(function () {
8915
+ if (checkCounter >= 10) {
8916
+ clearInterval(intervalId);
8917
+ return reject(new Error('window.google not found after 10 attempts'));
8918
+ }
8919
+ if (!!window.google && !!window.google.maps && !!window.google.maps.Map) {
8920
+ clearInterval(intervalId);
8921
+ return resolve(window.google);
8922
+ }
8923
+ checkCounter++;
8924
+ }, 500);
8925
+ });
8939
8926
 
8940
- this._GAPIPromise.then(function () {
8941
- this._ready = true;
8942
- this._map = map;
8927
+ // Couple data structures indexed by tile key
8928
+ this._tileCallbacks = {}; // Callbacks for promises for tiles that are expected
8929
+ this._freshTiles = {}; // Tiles from the mutant which haven't been requested yet
8943
8930
 
8944
- this._initMutant();
8931
+ this._imagesPerTile = (this.options.type === 'hybrid') ? 2 : 1;
8932
+ },
8945
8933
 
8946
- map.on('viewreset', this._reset, this);
8947
- map.on('move', this._update, this);
8948
- map.on('zoomend', this._handleZoomAnim, this);
8949
- map.on('resize', this._resize, this);
8934
+ onAdd: function (map) {
8935
+ L.GridLayer.prototype.onAdd.call(this, map);
8936
+ this._initMutantContainer();
8950
8937
 
8951
- //handle layer being added to a map for which there are no Google tiles at the given zoom
8952
- google.maps.event.addListenerOnce(this._mutant, 'idle', function () {
8953
- this._checkZoomLevels();
8954
- this._mutantIsReady = true;
8955
- }.bind(this));
8938
+ this._GAPIPromise.then(function () {
8939
+ this._ready = true;
8940
+ this._map = map;
8956
8941
 
8957
- //20px instead of 1em to avoid a slight overlap with google's attribution
8958
- map._controlCorners.bottomright.style.marginBottom = '20px';
8959
- map._controlCorners.bottomleft.style.marginBottom = '20px';
8942
+ this._initMutant();
8960
8943
 
8961
- this._reset();
8962
- this._update();
8944
+ map.on('viewreset', this._reset, this);
8945
+ map.on('move', this._update, this);
8946
+ map.on('zoomend', this._handleZoomAnim, this);
8947
+ map.on('resize', this._resize, this);
8963
8948
 
8964
- if (this._subLayers) {
8965
- //restore previously added google layers
8966
- for (var layerName in this._subLayers) {
8967
- this._subLayers[layerName].setMap(this._mutant);
8968
- }
8969
- }
8949
+ //handle layer being added to a map for which there are no Google tiles at the given zoom
8950
+ google.maps.event.addListenerOnce(this._mutant, 'idle', function () {
8951
+ this._checkZoomLevels();
8952
+ this._mutantIsReady = true;
8970
8953
  }.bind(this));
8971
- },
8972
8954
 
8973
- onRemove: function (map) {
8974
- L.GridLayer.prototype.onRemove.call(this, map);
8975
- map._container.removeChild(this._mutantContainer);
8976
- this._mutantContainer = undefined;
8977
-
8978
- google.maps.event.clearListeners(map, 'idle');
8979
- google.maps.event.clearListeners(this._mutant, 'idle');
8980
- map.off('viewreset', this._reset, this);
8981
- map.off('move', this._update, this);
8982
- map.off('zoomend', this._handleZoomAnim, this);
8983
- map.off('resize', this._resize, this);
8984
-
8985
- if (map._controlCorners) {
8986
- map._controlCorners.bottomright.style.marginBottom = '0em';
8987
- map._controlCorners.bottomleft.style.marginBottom = '0em';
8988
- }
8989
- },
8955
+ //20px instead of 1em to avoid a slight overlap with google's attribution
8956
+ map._controlCorners.bottomright.style.marginBottom = '20px';
8957
+ map._controlCorners.bottomleft.style.marginBottom = '20px';
8990
8958
 
8991
- getAttribution: function () {
8992
- return this.options.attribution;
8993
- },
8959
+ this._reset();
8960
+ this._update();
8994
8961
 
8995
- setOpacity: function (opacity) {
8996
- this.options.opacity = opacity;
8997
- if (opacity < 1) {
8998
- L.DomUtil.setOpacity(this._mutantContainer, opacity);
8962
+ if (this._subLayers) {
8963
+ //restore previously added google layers
8964
+ for (var layerName in this._subLayers) {
8965
+ this._subLayers[layerName].setMap(this._mutant);
8966
+ }
8999
8967
  }
9000
- },
9001
-
9002
- setElementSize: function (e, size) {
9003
- e.style.width = size.x + 'px';
9004
- e.style.height = size.y + 'px';
9005
- },
9006
-
9007
-
9008
- addGoogleLayer: function (googleLayerName, options) {
9009
- if (!this._subLayers) this._subLayers = {};
9010
- return this._GAPIPromise.then(function () {
9011
- var Constructor = google.maps[googleLayerName];
9012
- var googleLayer = new Constructor(options);
9013
- googleLayer.setMap(this._mutant);
9014
- this._subLayers[googleLayerName] = googleLayer;
9015
- return googleLayer;
9016
- }.bind(this));
9017
- },
9018
-
9019
- removeGoogleLayer: function (googleLayerName) {
9020
- var googleLayer = this._subLayers && this._subLayers[googleLayerName];
9021
- if (!googleLayer) return;
9022
-
9023
- googleLayer.setMap(null);
9024
- delete this._subLayers[googleLayerName];
9025
- },
8968
+ }.bind(this));
8969
+ },
8970
+
8971
+ onRemove: function (map) {
8972
+ L.GridLayer.prototype.onRemove.call(this, map);
8973
+ map._container.removeChild(this._mutantContainer);
8974
+ this._mutantContainer = undefined;
8975
+
8976
+ google.maps.event.clearListeners(map, 'idle');
8977
+ google.maps.event.clearListeners(this._mutant, 'idle');
8978
+ map.off('viewreset', this._reset, this);
8979
+ map.off('move', this._update, this);
8980
+ map.off('zoomend', this._handleZoomAnim, this);
8981
+ map.off('resize', this._resize, this);
8982
+
8983
+ if (map._controlCorners) {
8984
+ map._controlCorners.bottomright.style.marginBottom = '0em';
8985
+ map._controlCorners.bottomleft.style.marginBottom = '0em';
8986
+ }
8987
+ },
9026
8988
 
8989
+ getAttribution: function () {
8990
+ return this.options.attribution;
8991
+ },
9027
8992
 
9028
- _initMutantContainer: function () {
9029
- if (!this._mutantContainer) {
9030
- this._mutantContainer = L.DomUtil.create('div', 'leaflet-google-mutant leaflet-top leaflet-left');
9031
- this._mutantContainer.id = '_MutantContainer_' + L.Util.stamp(this._mutantContainer);
9032
- this._mutantContainer.style.zIndex = '800'; //leaflet map pane at 400, controls at 1000
9033
- this._mutantContainer.style.pointerEvents = 'none';
8993
+ setOpacity: function (opacity) {
8994
+ this.options.opacity = opacity;
8995
+ if (opacity < 1) {
8996
+ L.DomUtil.setOpacity(this._mutantContainer, opacity);
8997
+ }
8998
+ },
8999
+
9000
+ setElementSize: function (e, size) {
9001
+ e.style.width = size.x + 'px';
9002
+ e.style.height = size.y + 'px';
9003
+ },
9004
+
9005
+
9006
+ addGoogleLayer: function (googleLayerName, options) {
9007
+ if (!this._subLayers) this._subLayers = {};
9008
+ return this._GAPIPromise.then(function () {
9009
+ var Constructor = google.maps[googleLayerName];
9010
+ var googleLayer = new Constructor(options);
9011
+ googleLayer.setMap(this._mutant);
9012
+ this._subLayers[googleLayerName] = googleLayer;
9013
+ return googleLayer;
9014
+ }.bind(this));
9015
+ },
9016
+
9017
+ removeGoogleLayer: function (googleLayerName) {
9018
+ var googleLayer = this._subLayers && this._subLayers[googleLayerName];
9019
+ if (!googleLayer) return;
9020
+
9021
+ googleLayer.setMap(null);
9022
+ delete this._subLayers[googleLayerName];
9023
+ },
9024
+
9025
+
9026
+ _initMutantContainer: function () {
9027
+ if (!this._mutantContainer) {
9028
+ this._mutantContainer = L.DomUtil.create('div', 'leaflet-google-mutant leaflet-top leaflet-left');
9029
+ this._mutantContainer.id = '_MutantContainer_' + L.Util.stamp(this._mutantContainer);
9030
+ this._mutantContainer.style.zIndex = '800'; //leaflet map pane at 400, controls at 1000
9031
+ this._mutantContainer.style.pointerEvents = 'none';
9032
+
9033
+ this._map.getContainer().appendChild(this._mutantContainer);
9034
+ }
9034
9035
 
9035
- this._map.getContainer().appendChild(this._mutantContainer);
9036
+ this.setOpacity(this.options.opacity);
9037
+ this.setElementSize(this._mutantContainer, this._map.getSize());
9038
+
9039
+ this._attachObserver(this._mutantContainer);
9040
+ },
9041
+
9042
+ _initMutant: function () {
9043
+ if (!this._ready || !this._mutantContainer) return;
9044
+ this._mutantCenter = new google.maps.LatLng(0, 0);
9045
+
9046
+ var map = new google.maps.Map(this._mutantContainer, {
9047
+ center: this._mutantCenter,
9048
+ zoom: 0,
9049
+ tilt: 0,
9050
+ mapTypeId: this.options.type,
9051
+ disableDefaultUI: true,
9052
+ keyboardShortcuts: false,
9053
+ draggable: false,
9054
+ disableDoubleClickZoom: true,
9055
+ scrollwheel: false,
9056
+ streetViewControl: false,
9057
+ styles: this.options.styles || {},
9058
+ backgroundColor: 'transparent'
9059
+ });
9060
+
9061
+ this._mutant = map;
9062
+
9063
+ google.maps.event.addListenerOnce(map, 'idle', function () {
9064
+ var nodes = this._mutantContainer.querySelectorAll('a');
9065
+ for (var i = 0; i < nodes.length; i++) {
9066
+ nodes[i].style.pointerEvents = 'auto';
9036
9067
  }
9068
+ }.bind(this));
9037
9069
 
9038
- this.setOpacity(this.options.opacity);
9039
- this.setElementSize(this._mutantContainer, this._map.getSize());
9040
-
9041
- this._attachObserver(this._mutantContainer);
9042
- },
9043
-
9044
- _initMutant: function () {
9045
- if (!this._ready || !this._mutantContainer) return;
9046
- this._mutantCenter = new google.maps.LatLng(0, 0);
9047
-
9048
- var map = new google.maps.Map(this._mutantContainer, {
9049
- center: this._mutantCenter,
9050
- zoom: 0,
9051
- tilt: 0,
9052
- mapTypeId: this.options.type,
9053
- disableDefaultUI: true,
9054
- keyboardShortcuts: false,
9055
- draggable: false,
9056
- disableDoubleClickZoom: true,
9057
- scrollwheel: false,
9058
- streetViewControl: false,
9059
- styles: this.options.styles || {},
9060
- backgroundColor: 'transparent'
9061
- });
9062
-
9063
- this._mutant = map;
9064
-
9065
- google.maps.event.addListenerOnce(map, 'idle', function () {
9066
- var nodes = this._mutantContainer.querySelectorAll('a');
9067
- for (var i = 0; i < nodes.length; i++) {
9068
- nodes[i].style.pointerEvents = 'auto';
9069
- }
9070
- }.bind(this));
9070
+ // 🍂event spawned
9071
+ // Fired when the mutant has been created.
9072
+ this.fire('spawned', {mapObject: map});
9073
+ },
9071
9074
 
9072
- // 🍂event spawned
9073
- // Fired when the mutant has been created.
9074
- this.fire('spawned', { mapObject: map });
9075
- },
9075
+ _attachObserver: function _attachObserver (node) {
9076
+ // console.log('Gonna observe', node);
9076
9077
 
9077
- _attachObserver: function _attachObserver(node) {
9078
- // console.log('Gonna observe', node);
9078
+ var observer = new MutationObserver(this._onMutations.bind(this));
9079
9079
 
9080
- var observer = new MutationObserver(this._onMutations.bind(this));
9080
+ // pass in the target node, as well as the observer options
9081
+ observer.observe(node, { childList: true, subtree: true });
9082
+ },
9081
9083
 
9082
- // pass in the target node, as well as the observer options
9083
- observer.observe(node, { childList: true, subtree: true });
9084
- },
9084
+ _onMutations: function _onMutations (mutations) {
9085
+ for (var i = 0; i < mutations.length; ++i) {
9086
+ var mutation = mutations[i];
9087
+ for (var j = 0; j < mutation.addedNodes.length; ++j) {
9088
+ var node = mutation.addedNodes[j];
9085
9089
 
9086
- _onMutations: function _onMutations(mutations) {
9087
- for (var i = 0; i < mutations.length; ++i) {
9088
- var mutation = mutations[i];
9089
- for (var j = 0; j < mutation.addedNodes.length; ++j) {
9090
- var node = mutation.addedNodes[j];
9091
-
9092
- if (node instanceof HTMLImageElement) {
9093
- this._onMutatedImage(node);
9094
- } else if (node instanceof HTMLElement) {
9095
- Array.prototype.forEach.call(node.querySelectorAll('img'), this._onMutatedImage.bind(this));
9096
- }
9090
+ if (node instanceof HTMLImageElement) {
9091
+ this._onMutatedImage(node);
9092
+ } else if (node instanceof HTMLElement) {
9093
+ Array.prototype.forEach.call(node.querySelectorAll('img'), this._onMutatedImage.bind(this));
9097
9094
  }
9098
9095
  }
9099
- },
9100
-
9101
- // Only images which 'src' attrib match this will be considered for moving around.
9102
- // Looks like some kind of string-based protobuf, maybe??
9103
- // Only the roads (and terrain, and vector-based stuff) match this pattern
9104
- _roadRegexp: /!1i(\d+)!2i(\d+)!3i(\d+)!/,
9105
-
9106
- // On the other hand, raster imagery matches this other pattern
9107
- _satRegexp: /x=(\d+)&y=(\d+)&z=(\d+)/,
9108
-
9109
- // On small viewports, when zooming in/out, a static image is requested
9110
- // This will not be moved around, just removed from the DOM.
9111
- _staticRegExp: /StaticMapService\.GetMapImage/,
9112
-
9113
- _onMutatedImage: function _onMutatedImage(imgNode) {
9114
- // if (imgNode.src) {
9115
- // console.log('caught mutated image: ', imgNode.src);
9116
- // }
9117
-
9118
- var coords;
9119
- var match = imgNode.src.match(this._roadRegexp);
9120
- var sublayer = 0;
9121
-
9096
+ }
9097
+ },
9098
+
9099
+ // Only images which 'src' attrib match this will be considered for moving around.
9100
+ // Looks like some kind of string-based protobuf, maybe??
9101
+ // Only the roads (and terrain, and vector-based stuff) match this pattern
9102
+ _roadRegexp: /!1i(\d+)!2i(\d+)!3i(\d+)!/,
9103
+
9104
+ // On the other hand, raster imagery matches this other pattern
9105
+ _satRegexp: /x=(\d+)&y=(\d+)&z=(\d+)/,
9106
+
9107
+ // On small viewports, when zooming in/out, a static image is requested
9108
+ // This will not be moved around, just removed from the DOM.
9109
+ _staticRegExp: /StaticMapService\.GetMapImage/,
9110
+
9111
+ _onMutatedImage: function _onMutatedImage (imgNode) {
9112
+ // if (imgNode.src) {
9113
+ // console.log('caught mutated image: ', imgNode.src);
9114
+ // }
9115
+
9116
+ var coords;
9117
+ var match = imgNode.src.match(this._roadRegexp);
9118
+ var sublayer = 0;
9119
+
9120
+ if (match) {
9121
+ coords = {
9122
+ z: match[1],
9123
+ x: match[2],
9124
+ y: match[3]
9125
+ };
9126
+ if (this._imagesPerTile > 1) {
9127
+ imgNode.style.zIndex = 1;
9128
+ sublayer = 1;
9129
+ }
9130
+ } else {
9131
+ match = imgNode.src.match(this._satRegexp);
9122
9132
  if (match) {
9123
9133
  coords = {
9124
- z: match[1],
9125
- x: match[2],
9126
- y: match[3]
9134
+ x: match[1],
9135
+ y: match[2],
9136
+ z: match[3]
9127
9137
  };
9128
- if (this._imagesPerTile > 1) {
9129
- imgNode.style.zIndex = 1;
9130
- sublayer = 1;
9131
- }
9132
- } else {
9133
- match = imgNode.src.match(this._satRegexp);
9134
- if (match) {
9135
- coords = {
9136
- x: match[1],
9137
- y: match[2],
9138
- z: match[3]
9139
- };
9140
- }
9141
- // imgNode.style.zIndex = 0;
9142
- sublayer = 0;
9143
9138
  }
9139
+ // imgNode.style.zIndex = 0;
9140
+ sublayer = 0;
9141
+ }
9144
9142
 
9145
- if (coords) {
9146
- var tileKey = this._tileCoordsToKey(coords);
9147
- imgNode.style.position = 'absolute';
9148
- imgNode.style.visibility = 'hidden';
9149
-
9150
- var key = tileKey + '/' + sublayer;
9151
- // console.log('mutation for tile', key)
9152
- //store img so it can also be used in subsequent tile requests
9153
- this._freshTiles[key] = imgNode;
9154
-
9155
- if (key in this._tileCallbacks && this._tileCallbacks[key]) {
9156
- // console.log('Fullfilling callback ', key);
9157
- //fullfill most recent tileCallback because there maybe callbacks that will never get a
9158
- //corresponding mutation (because map moved to quickly...)
9159
- this._tileCallbacks[key].pop()(imgNode);
9160
- if (!this._tileCallbacks[key].length) { delete this._tileCallbacks[key]; }
9161
- } else {
9162
- if (this._tiles[tileKey]) {
9163
- //we already have a tile in this position (mutation is probably a google layer being added)
9164
- //replace it
9165
- var c = this._tiles[tileKey].el;
9166
- var oldImg = (sublayer === 0) ? c.firstChild : c.firstChild.nextSibling;
9167
- var cloneImgNode = this._clone(imgNode);
9168
- c.replaceChild(cloneImgNode, oldImg);
9169
- }
9170
- }
9171
- } else if (imgNode.src.match(this._staticRegExp)) {
9172
- imgNode.style.visibility = 'hidden';
9173
- }
9174
- },
9175
-
9176
-
9177
- createTile: function (coords, done) {
9178
- var key = this._tileCoordsToKey(coords);
9179
-
9180
- var tileContainer = L.DomUtil.create('div');
9181
- tileContainer.dataset.pending = this._imagesPerTile;
9182
- done = done.bind(this, null, tileContainer);
9183
-
9184
- for (var i = 0; i < this._imagesPerTile; i++) {
9185
- var key2 = key + '/' + i;
9186
- if (key2 in this._freshTiles) {
9187
- var imgNode = this._freshTiles[key2];
9188
- tileContainer.appendChild(this._clone(imgNode));
9189
- tileContainer.dataset.pending--;
9190
- // console.log('Got ', key2, ' from _freshTiles');
9191
- } else {
9192
- this._tileCallbacks[key2] = this._tileCallbacks[key2] || [];
9193
- this._tileCallbacks[key2].push((function (c/*, k2*/) {
9194
- return function (imgNode) {
9195
- c.appendChild(this._clone(imgNode));
9196
- c.dataset.pending--;
9197
- if (!parseInt(c.dataset.pending)) { done(); }
9198
- // console.log('Sent ', k2, ' to _tileCallbacks, still ', c.dataset.pending, ' images to go');
9199
- }.bind(this);
9200
- }.bind(this))(tileContainer/*, key2*/));
9143
+ if (coords) {
9144
+ var tileKey = this._tileCoordsToKey(coords);
9145
+ imgNode.style.position = 'absolute';
9146
+ imgNode.style.visibility = 'hidden';
9147
+
9148
+ var key = tileKey + '/' + sublayer;
9149
+ // console.log('mutation for tile', key)
9150
+ //store img so it can also be used in subsequent tile requests
9151
+ this._freshTiles[key] = imgNode;
9152
+
9153
+ if (key in this._tileCallbacks && this._tileCallbacks[key]) {
9154
+ // console.log('Fullfilling callback ', key);
9155
+ //fullfill most recent tileCallback because there maybe callbacks that will never get a
9156
+ //corresponding mutation (because map moved to quickly...)
9157
+ this._tileCallbacks[key].pop()(imgNode);
9158
+ if (!this._tileCallbacks[key].length) { delete this._tileCallbacks[key]; }
9159
+ } else {
9160
+ if (this._tiles[tileKey]) {
9161
+ //we already have a tile in this position (mutation is probably a google layer being added)
9162
+ //replace it
9163
+ var c = this._tiles[tileKey].el;
9164
+ var oldImg = (sublayer === 0) ? c.firstChild : c.firstChild.nextSibling;
9165
+ var cloneImgNode = this._clone(imgNode);
9166
+ c.replaceChild(cloneImgNode, oldImg);
9201
9167
  }
9202
9168
  }
9169
+ } else if (imgNode.src.match(this._staticRegExp)) {
9170
+ imgNode.style.visibility = 'hidden';
9171
+ }
9172
+ },
9203
9173
 
9204
- if (!parseInt(tileContainer.dataset.pending)) {
9205
- L.Util.requestAnimFrame(done);
9206
- }
9207
- return tileContainer;
9208
- },
9209
-
9210
- _clone: function (imgNode) {
9211
- var clonedImgNode = imgNode.cloneNode(true);
9212
- clonedImgNode.style.visibility = 'visible';
9213
- return clonedImgNode;
9214
- },
9215
9174
 
9216
- _checkZoomLevels: function () {
9217
- //setting the zoom level on the Google map may result in a different zoom level than the one requested
9218
- //(it won't go beyond the level for which they have data).
9219
- var zoomLevel = this._map.getZoom();
9220
- var gMapZoomLevel = this._mutant.getZoom();
9221
- if (!zoomLevel || !gMapZoomLevel) return;
9175
+ createTile: function (coords, done) {
9176
+ var key = this._tileCoordsToKey(coords);
9222
9177
 
9178
+ var tileContainer = L.DomUtil.create('div');
9179
+ tileContainer.dataset.pending = this._imagesPerTile;
9180
+ done = done.bind(this, null, tileContainer);
9223
9181
 
9224
- if ((gMapZoomLevel !== zoomLevel) || //zoom levels are out of sync, Google doesn't have data
9225
- (gMapZoomLevel > this.options.maxNativeZoom)) { //at current location, Google does have data (contrary to maxNativeZoom)
9226
- //Update maxNativeZoom
9227
- this._setMaxNativeZoom(gMapZoomLevel);
9228
- }
9229
- },
9230
-
9231
- _setMaxNativeZoom: function (zoomLevel) {
9232
- if (zoomLevel != this.options.maxNativeZoom) {
9233
- this.options.maxNativeZoom = zoomLevel;
9234
- this._resetView();
9182
+ for (var i = 0; i < this._imagesPerTile; i++) {
9183
+ var key2 = key + '/' + i;
9184
+ if (key2 in this._freshTiles) {
9185
+ var imgNode = this._freshTiles[key2];
9186
+ tileContainer.appendChild(this._clone(imgNode));
9187
+ tileContainer.dataset.pending--;
9188
+ // console.log('Got ', key2, ' from _freshTiles');
9189
+ } else {
9190
+ this._tileCallbacks[key2] = this._tileCallbacks[key2] || [];
9191
+ this._tileCallbacks[key2].push( (function (c/*, k2*/) {
9192
+ return function (imgNode) {
9193
+ c.appendChild(this._clone(imgNode));
9194
+ c.dataset.pending--;
9195
+ if (!parseInt(c.dataset.pending)) { done(); }
9196
+ // console.log('Sent ', k2, ' to _tileCallbacks, still ', c.dataset.pending, ' images to go');
9197
+ }.bind(this);
9198
+ }.bind(this))(tileContainer/*, key2*/) );
9235
9199
  }
9236
- },
9237
-
9238
- _reset: function () {
9239
- this._initContainer();
9240
- },
9241
-
9242
- _update: function () {
9243
- // zoom level check needs to happen before super's implementation (tile addition/creation)
9244
- // otherwise tiles may be missed if maxNativeZoom is not yet correctly determined
9245
- if (this._mutant) {
9246
- var center = this._map.getCenter();
9247
- var _center = new google.maps.LatLng(center.lat, center.lng);
9248
-
9249
- this._mutant.setCenter(_center);
9250
- var zoom = this._map.getZoom();
9251
- var fractionalLevel = zoom !== Math.round(zoom);
9252
- var mutantZoom = this._mutant.getZoom();
9253
-
9254
- //ignore fractional zoom levels
9255
- if (!fractionalLevel && (zoom != mutantZoom)) {
9256
- this._mutant.setZoom(zoom);
9200
+ }
9257
9201
 
9258
- if (this._mutantIsReady) this._checkZoomLevels();
9259
- //else zoom level check will be done later by 'idle' handler
9260
- }
9261
- }
9202
+ if (!parseInt(tileContainer.dataset.pending)) {
9203
+ L.Util.requestAnimFrame(done);
9204
+ }
9205
+ return tileContainer;
9206
+ },
9207
+
9208
+ _clone: function (imgNode) {
9209
+ var clonedImgNode = imgNode.cloneNode(true);
9210
+ clonedImgNode.style.visibility = 'visible';
9211
+ return clonedImgNode;
9212
+ },
9213
+
9214
+ _checkZoomLevels: function () {
9215
+ //setting the zoom level on the Google map may result in a different zoom level than the one requested
9216
+ //(it won't go beyond the level for which they have data).
9217
+ var zoomLevel = this._map.getZoom();
9218
+ var gMapZoomLevel = this._mutant.getZoom();
9219
+ if (!zoomLevel || !gMapZoomLevel) return;
9220
+
9221
+
9222
+ if ((gMapZoomLevel !== zoomLevel) || //zoom levels are out of sync, Google doesn't have data
9223
+ (gMapZoomLevel > this.options.maxNativeZoom)) { //at current location, Google does have data (contrary to maxNativeZoom)
9224
+ //Update maxNativeZoom
9225
+ this._setMaxNativeZoom(gMapZoomLevel);
9226
+ }
9227
+ },
9262
9228
 
9263
- L.GridLayer.prototype._update.call(this);
9264
- },
9229
+ _setMaxNativeZoom: function (zoomLevel) {
9230
+ if (zoomLevel != this.options.maxNativeZoom) {
9231
+ this.options.maxNativeZoom = zoomLevel;
9232
+ this._resetView();
9233
+ }
9234
+ },
9265
9235
 
9266
- _resize: function () {
9267
- var size = this._map.getSize();
9268
- if (this._mutantContainer.style.width === size.x &&
9269
- this._mutantContainer.style.height === size.y)
9270
- return;
9271
- this.setElementSize(this._mutantContainer, size);
9272
- if (!this._mutant) return;
9273
- google.maps.event.trigger(this._mutant, 'resize');
9274
- },
9236
+ _reset: function () {
9237
+ this._initContainer();
9238
+ },
9275
9239
 
9276
- _handleZoomAnim: function () {
9277
- if (!this._mutant) return;
9240
+ _update: function () {
9241
+ // zoom level check needs to happen before super's implementation (tile addition/creation)
9242
+ // otherwise tiles may be missed if maxNativeZoom is not yet correctly determined
9243
+ if (this._mutant) {
9278
9244
  var center = this._map.getCenter();
9279
9245
  var _center = new google.maps.LatLng(center.lat, center.lng);
9280
9246
 
9281
9247
  this._mutant.setCenter(_center);
9282
- this._mutant.setZoom(Math.round(this._map.getZoom()));
9283
- },
9284
-
9285
- // Agressively prune _freshtiles when a tile with the same key is removed,
9286
- // this prevents a problem where Leaflet keeps a loaded tile longer than
9287
- // GMaps, so that GMaps makes two requests but Leaflet only consumes one,
9288
- // polluting _freshTiles with stale data.
9289
- _removeTile: function (key) {
9290
- if (!this._mutant) return;
9291
-
9292
- //give time for animations to finish before checking it tile should be pruned
9293
- setTimeout(this._pruneTile.bind(this, key), 1000);
9294
-
9248
+ var zoom = this._map.getZoom();
9249
+ var fractionalLevel = zoom !== Math.round(zoom);
9250
+ var mutantZoom = this._mutant.getZoom();
9251
+
9252
+ //ignore fractional zoom levels
9253
+ if (!fractionalLevel && (zoom != mutantZoom)) {
9254
+ this._mutant.setZoom(zoom);
9255
+
9256
+ if (this._mutantIsReady) this._checkZoomLevels();
9257
+ //else zoom level check will be done later by 'idle' handler
9258
+ }
9259
+ }
9295
9260
 
9296
- return L.GridLayer.prototype._removeTile.call(this, key);
9297
- },
9261
+ L.GridLayer.prototype._update.call(this);
9262
+ },
9298
9263
 
9299
- _pruneTile: function (key) {
9300
- var gZoom = this._mutant.getZoom();
9301
- var tileZoom = key.split(':')[2];
9302
- var googleBounds = this._mutant.getBounds();
9303
- var sw = googleBounds.getSouthWest();
9304
- var ne = googleBounds.getNorthEast();
9305
- var gMapBounds = L.latLngBounds([[sw.lat(), sw.lng()], [ne.lat(), ne.lng()]]);
9306
-
9307
- for (var i = 0; i < this._imagesPerTile; i++) {
9308
- var key2 = key + '/' + i;
9309
- if (key2 in this._freshTiles) {
9310
- var tileBounds = this._map && this._keyToBounds(key);
9311
- var stillVisible = this._map && tileBounds.overlaps(gMapBounds) && (tileZoom == gZoom);
9312
-
9313
- if (!stillVisible) delete this._freshTiles[key2];
9314
- // console.log('Prunning of ', key, (!stillVisible))
9315
- }
9264
+ _resize: function () {
9265
+ var size = this._map.getSize();
9266
+ if (this._mutantContainer.style.width === size.x &&
9267
+ this._mutantContainer.style.height === size.y)
9268
+ return;
9269
+ this.setElementSize(this._mutantContainer, size);
9270
+ if (!this._mutant) return;
9271
+ google.maps.event.trigger(this._mutant, 'resize');
9272
+ },
9273
+
9274
+ _handleZoomAnim: function () {
9275
+ if (!this._mutant) return;
9276
+ var center = this._map.getCenter();
9277
+ var _center = new google.maps.LatLng(center.lat, center.lng);
9278
+
9279
+ this._mutant.setCenter(_center);
9280
+ this._mutant.setZoom(Math.round(this._map.getZoom()));
9281
+ },
9282
+
9283
+ // Agressively prune _freshtiles when a tile with the same key is removed,
9284
+ // this prevents a problem where Leaflet keeps a loaded tile longer than
9285
+ // GMaps, so that GMaps makes two requests but Leaflet only consumes one,
9286
+ // polluting _freshTiles with stale data.
9287
+ _removeTile: function (key) {
9288
+ if (!this._mutant) return;
9289
+
9290
+ //give time for animations to finish before checking it tile should be pruned
9291
+ setTimeout(this._pruneTile.bind(this, key), 1000);
9292
+
9293
+
9294
+ return L.GridLayer.prototype._removeTile.call(this, key);
9295
+ },
9296
+
9297
+ _pruneTile: function (key) {
9298
+ var gZoom = this._mutant.getZoom();
9299
+ var tileZoom = key.split(':')[2];
9300
+ var googleBounds = this._mutant.getBounds();
9301
+ var sw = googleBounds.getSouthWest();
9302
+ var ne = googleBounds.getNorthEast();
9303
+ var gMapBounds = L.latLngBounds([[sw.lat(), sw.lng()], [ne.lat(), ne.lng()]]);
9304
+
9305
+ for (var i=0; i<this._imagesPerTile; i++) {
9306
+ var key2 = key + '/' + i;
9307
+ if (key2 in this._freshTiles) {
9308
+ var tileBounds = this._map && this._keyToBounds(key);
9309
+ var stillVisible = this._map && tileBounds.overlaps(gMapBounds) && (tileZoom == gZoom);
9310
+
9311
+ if (!stillVisible) delete this._freshTiles[key2];
9312
+ // console.log('Prunning of ', key, (!stillVisible))
9316
9313
  }
9317
9314
  }
9318
- });
9315
+ }
9316
+ });
9317
+
9319
9318
 
9320
- exports.GoogleMutant = GoogleMutant;
9321
- })));
9319
+ // 🍂factory gridLayer.googleMutant(options)
9320
+ // Returns a new `GridLayer.GoogleMutant` given its options
9321
+ L.gridLayer.googleMutant = function (options) {
9322
+ return new L.GridLayer.GoogleMutant(options);
9323
+ };
9322
9324
 
9323
9325
 
9324
9326
  /***/ }),