new release for react-leaflet 1.0.2

This commit is contained in:
Christos committed 2016-12-29 00:30:25 +02:00
1 parent 0af5d10fb9
commit 5de2a8002b
9 files changed
+1145 -512

No files matched your search

+398 -188
View File
@@ -101,38 +101,51 @@ return /******/ (function(modules) { // webpackBootstrap
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var GoogleLayer = function (_BaseTileLayer) {
_inherits(GoogleLayer, _BaseTileLayer);
var GoogleLayer = function (_GridLayer) {
_inherits(GoogleLayer, _GridLayer);
function GoogleLayer() {
_classCallCheck(this, GoogleLayer);
return _possibleConstructorReturn(this, Object.getPrototypeOf(GoogleLayer).apply(this, arguments));
return _possibleConstructorReturn(this, (GoogleLayer.__proto__ || Object.getPrototypeOf(GoogleLayer)).apply(this, arguments));
}
_createClass(GoogleLayer, [{
key: 'componentWillMount',
value: function componentWillMount() {
_get(Object.getPrototypeOf(GoogleLayer.prototype), 'componentWillMount', this).call(this);
var _props = this.props;
var _map = _props.map;
var _lc = _props.layerContainer;
var googlekey = _props.googlekey;
var type = _props.type;
var asclientid = _props.asclientid;
_get(GoogleLayer.prototype.__proto__ || Object.getPrototypeOf(GoogleLayer.prototype), 'componentWillMount', this).call(this);
var props = _objectWithoutProperties(_props, ['map', 'layerContainer', 'googlekey', 'type', 'asclientid']);
var _props = this.props,
_map = _props.map,
googlekey = _props.googlekey,
maptype = _props.maptype,
asclientid = _props.asclientid,
props = _objectWithoutProperties(_props, ['map', 'googlekey', 'maptype', 'asclientid']);
this.leafletElement = new L.Google(googlekey, type, asclientid, props);
this.leafletElement = new L.gridLayer.googleMutant(this.props);
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps) {
var _props2 = this.props,
opacity = _props2.opacity,
zIndex = _props2.zIndex;
if (opacity !== prevProps.opacity) {
this.leafletElement.setOpacity(opacity);
}
if (zIndex !== prevProps.zIndex) {
this.leafletElement.setZIndex(zIndex);
}
}
}]);
return GoogleLayer;
}(_reactLeaflet.BaseTileLayer);
}(_reactLeaflet.GridLayer);
GoogleLayer.propTypes = {
type: _react.PropTypes.string,
googlekey: _react.PropTypes.string.isRequired,
maptype: _react.PropTypes.string,
asclientid: _react.PropTypes.bool
};
exports.default = GoogleLayer;
@@ -155,223 +168,420 @@ return /******/ (function(modules) { // webpackBootstrap
'use strict';
/*
* Google layer using Google Maps API
*/
/* global google: true */
// Based on https://github.com/shramov/leaflet-plugins
// GridLayer like https://avinmathew.com/leaflet-and-google-maps/ , but using MutationObserver instead of jQuery
var GoogleMapsLoader = __webpack_require__(5);
GoogleMapsLoader.VERSION = '3.14';
GoogleMapsLoader.VERSION = '3.18';
var google = null;
L.Google = L.Class.extend({
includes: L.Mixin.Events,
// 🍂class GridLayer.GoogleMutant
// 🍂extends GridLayer
L.GridLayer.GoogleMutant = L.GridLayer.extend({
includes: L.Mixin.Events,
options: {
minZoom: 0,
maxZoom: 18,
tileSize: 256,
subdomains: 'abc',
errorTileUrl: '',
attribution: '',
opacity: 1,
continuousWorld: false,
noWrap: false,
mapOptions: {
backgroundColor: '#dddddd'
}
},
options: {
minZoom: 0,
maxZoom: 18,
tileSize: 256,
subdomains: 'abc',
errorTileUrl: '',
attribution: '', // The mutant container will add its own attribution anyways.
opacity: 1,
continuousWorld: false,
noWrap: false,
// 🍂option type: String = 'roadmap'
// Google's map type. Valid values are 'roadmap', 'satellite' or 'terrain'. 'hybrid' is not really supported.
type: 'satellite',
maxNativeZoom: 21
},
// Possible types: SATELLITE, ROADMAP, HYBRID, TERRAIN
initialize: function initialize(goolekey, type, asclientid, options) {
L.Util.setOptions(this, options);
var self = this;
initialize: function initialize(options) {
L.GridLayer.prototype.initialize.call(this, options);
var self = this;
if (asclientid) {
GoogleMapsLoader.CLIENT = goolekey;
} else {
GoogleMapsLoader.KEY = goolekey;
}
if (options.asclientid) {
GoogleMapsLoader.CLIENT = options.googlekey;
} else {
GoogleMapsLoader.KEY = options.googlekey;
}
GoogleMapsLoader.onLoad(function () {
self._ready = true;
});
GoogleMapsLoader.load(function (_google) {
google = _google;
console.log('I just loaded google maps api');
self._type = options.maptype || 'SATELLITE';
self._initMapObject();
self._update();
GoogleMapsLoader.load(function (_google) {
google = _google;
console.log('I just loaded google maps api');
self._ready = true;
//self._initMapObject();
// self.
self._initMutant();
self._update();
//this._ready = google.maps.Map !== undefined;
//if (!this._ready) L.Google.asyncWait.push(this);
});
self._type = type || 'SATELLITE';
},
//this._ready = google.maps.Map !== undefined;
//if (!this._ready) L.Google.asyncWait.push(this);
});
onAdd: function onAdd(map, insertAtTheBottom) {
this._map = map;
this._insertAtTheBottom = insertAtTheBottom;
// Couple data structures indexed by tile key
this._tileCallbacks = {}; // Callbacks for promises for tiles that are expected
this._freshTiles = {}; // Tiles from the mutant which haven't been requested yet
// create a container div for tiles
this._initContainer();
this._initMapObject();
this._imagesPerTile = self._type === 'hybrid' ? 2 : 1;
this.createTile = self._type === 'hybrid' ? this._createMultiTile : this._createSingleTile;
},
// set up events
map.on('viewreset', this._reset, this);
onAdd: function onAdd(map) {
L.GridLayer.prototype.onAdd.call(this, map);
this._initMutantContainer();
this._limitedUpdate = L.Util.limitExecByInterval(this._update, 150, this);
map.on('move', this._update, this);
// this._GAPIPromise.then(function () {
if (this._ready) {
this._map = map;
map.on('zoomanim', this._handleZoomAnim, this);
this._initMutant();
//20px instead of 1em to avoid a slight overlap with google's attribution
map._controlCorners.bottomright.style.marginBottom = '20px';
map.on('viewreset', this._reset, this);
map.on('move', this._update, this);
map.on('zoomend', this._handleZoomAnim, this);
map.on('resize', this._resize, this);
this._reset();
this._update();
},
//20px instead of 1em to avoid a slight overlap with google's attribution
map._controlCorners.bottomright.style.marginBottom = '20px';
onRemove: function onRemove(map) {
map._container.removeChild(this._container);
this._reset();
this._update();
}
//}.bind(this));
},
map.off('viewreset', this._reset, this);
onRemove: function onRemove(map) {
L.GridLayer.prototype.onRemove.call(this, map);
map._container.removeChild(this._mutantContainer);
this._mutantContainer = undefined;
map.off('move', this._update, this);
map.off('viewreset', this._reset, this);
map.off('move', this._update, this);
map.off('zoomend', this._handleZoomAnim, this);
map.off('resize', this._resize, this);
map.off('zoomanim', this._handleZoomAnim, this);
map._controlCorners.bottomright.style.marginBottom = '0em';
},
map._controlCorners.bottomright.style.marginBottom = '0em';
},
getAttribution: function getAttribution() {
return this.options.attribution;
},
getAttribution: function getAttribution() {
return this.options.attribution;
},
setOpacity: function setOpacity(opacity) {
this.options.opacity = opacity;
if (opacity < 1) {
L.DomUtil.setOpacity(this._mutantContainer, opacity);
}
},
setOpacity: function setOpacity(opacity) {
this.options.opacity = opacity;
if (opacity < 1) {
L.DomUtil.setOpacity(this._container, opacity);
}
},
setElementSize: function setElementSize(e, size) {
e.style.width = size.x + 'px';
e.style.height = size.y + 'px';
},
setElementSize: function setElementSize(e, size) {
e.style.width = size.x + 'px';
e.style.height = size.y + 'px';
},
_initMutantContainer: function _initMutantContainer() {
if (!this._mutantContainer) {
this._mutantContainer = L.DomUtil.create('div', 'leaflet-google-mutant leaflet-top leaflet-left');
this._mutantContainer.id = '_MutantContainer_' + L.Util.stamp(this._mutantContainer);
// this._mutantContainer.style.zIndex = 'auto';
this._mutantContainer.style.pointerEvents = 'none';
_initContainer: function _initContainer() {
var tilePane = this._map._container,
first = tilePane.firstChild;
this._map.getContainer().appendChild(this._mutantContainer);
}
if (!this._container) {
this._container = L.DomUtil.create('div', 'leaflet-google-layer leaflet-top leaflet-left');
this._container.id = '_GMapContainer_' + L.Util.stamp(this);
this._container.style.zIndex = 'auto';
}
this.setOpacity(this.options.opacity);
this.setElementSize(this._mutantContainer, this._map.getSize());
tilePane.insertBefore(this._container, first);
this._attachObserver(this._mutantContainer);
},
this.setOpacity(this.options.opacity);
this.setElementSize(this._container, this._map.getSize());
},
_initMutant: function _initMutant() {
if (!this._ready || !this._mutantContainer) return;
this._mutantCenter = new google.maps.LatLng(0, 0);
_initMapObject: function _initMapObject() {
if (!this._ready) return;
this._google_center = new google.maps.LatLng(0, 0);
var map = new google.maps.Map(this._container, {
center: this._google_center,
zoom: 0,
tilt: 0,
mapTypeId: google.maps.MapTypeId[this._type],
disableDefaultUI: true,
keyboardShortcuts: false,
draggable: false,
disableDoubleClickZoom: true,
scrollwheel: false,
streetViewControl: false,
styles: this.options.mapOptions.styles,
backgroundColor: this.options.mapOptions.backgroundColor
});
var map = new google.maps.Map(this._mutantContainer, {
center: this._mutantCenter,
zoom: 0,
tilt: 0,
mapTypeId: google.maps.MapTypeId[this._type],
disableDefaultUI: true,
keyboardShortcuts: false,
draggable: false,
disableDoubleClickZoom: true,
scrollwheel: false,
streetViewControl: false,
styles: this.options.styles || {},
backgroundColor: 'transparent'
});
var _this = this;
this._reposition = google.maps.event.addListenerOnce(map, 'center_changed', function () {
_this.onReposition();
});
this._google = map;
this._mutant = map;
google.maps.event.addListenerOnce(map, 'idle', function () {
_this._checkZoomLevels();
});
google.maps.event.addListenerOnce(map, 'tilesloaded', function () {
_this.fire('load');
});
//Reporting that map-object was initialized.
this.fire('MapObjectInitialized', { mapObject: map });
},
// 🍂event spawned
// Fired when the mutant has been created.
this.fire('spawned', {
mapObject: map
});
},
_checkZoomLevels: function _checkZoomLevels() {
//setting the zoom level on the Google map may result in a different zoom level than the one requested
//(it won't go beyond the level for which they have data).
// verify and make sure the zoom levels on both Leaflet and Google maps are consistent
if (this._map.getZoom() !== undefined && this._google.getZoom() !== this._map.getZoom()) {
//zoom levels are out of sync. Set the leaflet zoom level to match the google one
this._map.setZoom(this._google.getZoom());
}
},
_attachObserver: function _attachObserver(node) {
// console.log('Gonna observe', node);
_reset: function _reset() {
this._initContainer();
},
var observer = new MutationObserver(this._onMutations.bind(this));
_update: function _update() {
if (!this._google) return;
this._resize();
// pass in the target node, as well as the observer options
observer.observe(node, {
childList: true,
subtree: true
});
},
var center = this._map.getCenter();
var _center = new google.maps.LatLng(center.lat, center.lng);
_onMutations: function _onMutations(mutations) {
for (var i = 0; i < mutations.length; ++i) {
var mutation = mutations[i];
for (var j = 0; j < mutation.addedNodes.length; ++j) {
var node = mutation.addedNodes[j];
this._google.setCenter(_center);
if (this._map.getZoom() !== undefined) this._google.setZoom(Math.round(this._map.getZoom()));
if (node instanceof HTMLImageElement) {
this._onMutatedImage(node);
} else if (node instanceof HTMLElement) {
Array.prototype.forEach.call(node.querySelectorAll('img'), this._onMutatedImage.bind(this));
}
}
}
},
this._checkZoomLevels();
},
// Only images which 'src' attrib match this will be considered for moving around.
// Looks like some kind of string-based protobuf, maybe??
// Only the roads (and terrain, and vector-based stuff) match this pattern
_roadRegexp: /!1i(\d+)!2i(\d+)!3i(\d+)!/,
_resize: function _resize() {
var size = this._map.getSize();
if (this._container.style.width === size.x && this._container.style.height === size.y) return;
this.setElementSize(this._container, size);
this.onReposition();
},
// On the other hand, raster imagery matches this other pattern
_satRegexp: /x=(\d+)&y=(\d+)&z=(\d+)/,
_handleZoomAnim: function _handleZoomAnim(e) {
var center = e.center;
var _center = new google.maps.LatLng(center.lat, center.lng);
// On small viewports, when zooming in/out, a static image is requested
// This will not be moved around, just removed from the DOM.
_staticRegExp: /StaticMapService\.GetMapImage/,
this._google.setCenter(_center);
this._google.setZoom(Math.round(e.zoom));
},
_onMutatedImage: function _onMutatedImage(imgNode) {
// if (imgNode.src) {
// console.log('caught mutated image: ', imgNode.src);
// }
onReposition: function onReposition() {
if (!this._google) return;
google.maps.event.trigger(this._google, 'resize');
}
var coords;
var match = imgNode.src.match(this._roadRegexp);
var sublayer, parent;
if (match) {
coords = {
z: match[1],
x: match[2],
y: match[3]
};
if (this._imagesPerTile > 1) {
imgNode.style.zIndex = 1;
}
sublayer = 1;
} else {
match = imgNode.src.match(this._satRegexp);
if (match) {
coords = {
x: match[1],
y: match[2],
z: match[3]
};
}
// imgNode.style.zIndex = 0;
sublayer = 0;
}
if (coords) {
var key = this._tileCoordsToKey(coords);
imgNode.style.position = 'absolute';
if (this._imagesPerTile > 1) {
key += '/' + sublayer;
}
if (key in this._tileCallbacks && this._tileCallbacks[key]) {
// console.log('Fullfilling callback ', key);
this._tileCallbacks[key].pop()(imgNode);
if (!this._tileCallbacks[key].length) {
delete this._tileCallbacks[key];
}
} else {
// console.log('Caching for later', key);
parent = imgNode.parentNode;
if (parent) {
parent.removeChild(imgNode);
parent.removeChild = L.Util.falseFn;
// imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
if (key in this._freshTiles) {
this._freshTiles[key].push(imgNode);
} else {
this._freshTiles[key] = [imgNode];
}
}
} else if (imgNode.src.match(this._staticRegExp)) {
parent = imgNode.parentNode;
if (parent) {
// Remove the image, but don't store it anywhere.
// Image needs to be replaced instead of removed, as the container
// seems to be reused.
imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
}
},
// This will be used as this.createTile for 'roadmap', 'sat', 'terrain'
_createSingleTile: function createTile(coords, done) {
var key = this._tileCoordsToKey(coords);
// console.log('Need:', key);
if (key in this._freshTiles) {
var tile = this._freshTiles[key].pop();
if (!this._freshTiles[key].length) {
delete this._freshTiles[key];
}
L.Util.requestAnimFrame(done);
// console.log('Got ', key, ' from _freshTiles');
return tile;
} else {
var tileContainer = L.DomUtil.create('div');
this._tileCallbacks[key] = this._tileCallbacks[key] || [];
this._tileCallbacks[key].push(function (c /*, k*/) {
return function (imgNode) {
var parent = imgNode.parentNode;
if (parent) {
parent.removeChild(imgNode);
parent.removeChild = L.Util.falseFn;
// imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
c.appendChild(imgNode);
done();
// console.log('Sent ', k, ' to _tileCallbacks');
}.bind(this);
}.bind(this)(tileContainer /*, key*/));
return tileContainer;
}
},
// This will be used as this.createTile for 'hybrid'
_createMultiTile: function createTile(coords, done) {
var key = this._tileCoordsToKey(coords);
var tileContainer = L.DomUtil.create('div');
tileContainer.dataset.pending = this._imagesPerTile;
for (var i = 0; i < this._imagesPerTile; i++) {
var key2 = key + '/' + i;
if (key2 in this._freshTiles) {
tileContainer.appendChild(this._freshTiles[key2].pop());
if (!this._freshTiles[key2].length) {
delete this._freshTiles[key2];
}
tileContainer.dataset.pending--;
// console.log('Got ', key2, ' from _freshTiles');
} else {
this._tileCallbacks[key2] = this._tileCallbacks[key2] || [];
this._tileCallbacks[key2].push(function (c /*, k2*/) {
return function (imgNode) {
var parent = imgNode.parentNode;
if (parent) {
parent.removeChild(imgNode);
parent.removeChild = L.Util.falseFn;
// imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
c.appendChild(imgNode);
c.dataset.pending--;
if (!parseInt(c.dataset.pending)) {
done();
}
// console.log('Sent ', k2, ' to _tileCallbacks, still ', c.dataset.pending, ' images to go');
}.bind(this);
}.bind(this)(tileContainer /*, key2*/));
}
}
if (!parseInt(tileContainer.dataset.pending)) {
L.Util.requestAnimFrame(done);
}
return tileContainer;
},
_checkZoomLevels: function _checkZoomLevels() {
//setting the zoom level on the Google map may result in a different zoom level than the one requested
//(it won't go beyond the level for which they have data).
// verify and make sure the zoom levels on both Leaflet and Google maps are consistent
if (this._map.getZoom() !== undefined && this._mutant.getZoom() !== this._map.getZoom()) {
//zoom levels are out of sync. Set the leaflet zoom level to match the google one
this._map.setZoom(this._mutant.getZoom());
}
},
_reset: function _reset() {
this._initContainer();
},
_update: function _update() {
L.GridLayer.prototype._update.call(this);
if (!this._mutant) return;
var center = this._map.getCenter();
var _center = new google.maps.LatLng(center.lat, center.lng);
this._mutant.setCenter(_center);
var zoom = this._map.getZoom();
if (zoom !== undefined) {
this._mutant.setZoom(Math.round(this._map.getZoom()));
}
},
_resize: function _resize() {
var size = this._map.getSize();
if (this._mutantContainer.style.width === size.x && this._mutantContainer.style.height === size.y) return;
this.setElementSize(this._mutantContainer, size);
if (!this._mutant) return;
google.maps.event.trigger(this._mutant, 'resize');
},
_handleZoomAnim: function _handleZoomAnim() {
var center = this._map.getCenter();
var _center = new google.maps.LatLng(center.lat, center.lng);
this._mutant.setCenter(_center);
this._mutant.setZoom(Math.round(this._map.getZoom()));
},
// Agressively prune _freshtiles when a tile with the same key is removed,
// this prevents a problem where Leaflet keeps a loaded tile longer than
// GMaps, so that GMaps makes two requests but Leaflet only consumes one,
// polluting _freshTiles with stale data.
_removeTile: function _removeTile(key) {
if (this._imagesPerTile > 1) {
for (var i = 0; i < this._imagesPerTile; i++) {
var key2 = key + '/' + i;
if (key2 in this._freshTiles) {
delete this._freshTiles[key2];
}
// console.log('Pruned spurious hybrid _freshTiles');
}
} else {
if (key in this._freshTiles) {
delete this._freshTiles[key];
// console.log('Pruned spurious _freshTiles', key);
}
}
return L.GridLayer.prototype._removeTile.call(this, key);
}
});
L.Google.asyncWait = [];
L.Google.asyncInitialize = function () {
var i;
for (i = 0; i < L.Google.asyncWait.length; i++) {
var o = L.Google.asyncWait[i];
o._ready = true;
if (o._container) {
o._initMapObject();
o._update();
}
}
L.Google.asyncWait = [];
// 🍂factory gridLayer.googleMutant(options)
// Returns a new `GridLayer.GoogleMutant` given its options
L.gridLayer.googleMutant = function (options) {
return new L.GridLayer.GoogleMutant(options);
};
/***/ },
+1 -1
View File
@@ -1 +1 @@
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-leaflet")):"function"==typeof define&&define.amd?define(["react","react-leaflet"],t):"object"==typeof exports?exports.ReactLeaflet=t(require("react"),require("react-leaflet")):e.ReactLeaflet=t(e.React,e[void 0])}(this,function(e,t){return function(e){function t(n){if(o[n])return o[n].exports;var i=o[n]={exports:{},id:n,loaded:!1};return e[n].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var o={};return t.m=e,t.c=o,t.p="",t(0)}([function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0}),t.GoogleLayer=void 0;var i=o(1),r=n(i);t.GoogleLayer=r["default"]},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function i(e,t){var o={};for(var n in e)t.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(o[n]=e[n]);return o}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,o,n){return o&&e(t.prototype,o),n&&e(t,n),t}}(),c=function f(e,t,o){null===e&&(e=Function.prototype);var n=Object.getOwnPropertyDescriptor(e,t);if(void 0===n){var i=Object.getPrototypeOf(e);return null===i?void 0:f(i,t,o)}if("value"in n)return n.value;var r=n.get;if(void 0!==r)return r.call(o)},u=o(4),p=(n(u),o(5)),d=(o(2),function(e){function t(){return r(this,t),a(this,Object.getPrototypeOf(t).apply(this,arguments))}return l(t,e),s(t,[{key:"componentWillMount",value:function(){c(Object.getPrototypeOf(t.prototype),"componentWillMount",this).call(this);var e=this.props,o=(e.map,e.layerContainer,e.googlekey),n=e.type,r=e.asclientid,a=i(e,["map","layerContainer","googlekey","type","asclientid"]);this.leafletElement=new L.Google(o,n,r,a)}}]),t}(p.BaseTileLayer));d.propTypes={type:u.PropTypes.string,googlekey:u.PropTypes.string.isRequired,asclientid:u.PropTypes.bool},t["default"]=d},function(e,t,o){"use strict";var n=o(3);n.VERSION="3.14";var i=null;L.Google=L.Class.extend({includes:L.Mixin.Events,options:{minZoom:0,maxZoom:18,tileSize:256,subdomains:"abc",errorTileUrl:"",attribution:"",opacity:1,continuousWorld:!1,noWrap:!1,mapOptions:{backgroundColor:"#dddddd"}},initialize:function(e,t,o,r){L.Util.setOptions(this,r);var a=this;o?n.CLIENT=e:n.KEY=e,n.onLoad(function(){a._ready=!0}),n.load(function(e){i=e,console.log("I just loaded google maps api"),a._initMapObject(),a._update()}),a._type=t||"SATELLITE"},onAdd:function(e,t){this._map=e,this._insertAtTheBottom=t,this._initContainer(),this._initMapObject(),e.on("viewreset",this._reset,this),this._limitedUpdate=L.Util.limitExecByInterval(this._update,150,this),e.on("move",this._update,this),e.on("zoomanim",this._handleZoomAnim,this),e._controlCorners.bottomright.style.marginBottom="20px",this._reset(),this._update()},onRemove:function(e){e._container.removeChild(this._container),e.off("viewreset",this._reset,this),e.off("move",this._update,this),e.off("zoomanim",this._handleZoomAnim,this),e._controlCorners.bottomright.style.marginBottom="0em"},getAttribution:function(){return this.options.attribution},setOpacity:function(e){this.options.opacity=e,1>e&&L.DomUtil.setOpacity(this._container,e)},setElementSize:function(e,t){e.style.width=t.x+"px",e.style.height=t.y+"px"},_initContainer:function(){var e=this._map._container,t=e.firstChild;this._container||(this._container=L.DomUtil.create("div","leaflet-google-layer leaflet-top leaflet-left"),this._container.id="_GMapContainer_"+L.Util.stamp(this),this._container.style.zIndex="auto"),e.insertBefore(this._container,t),this.setOpacity(this.options.opacity),this.setElementSize(this._container,this._map.getSize())},_initMapObject:function(){if(this._ready){this._google_center=new i.maps.LatLng(0,0);var e=new i.maps.Map(this._container,{center:this._google_center,zoom:0,tilt:0,mapTypeId:i.maps.MapTypeId[this._type],disableDefaultUI:!0,keyboardShortcuts:!1,draggable:!1,disableDoubleClickZoom:!0,scrollwheel:!1,streetViewControl:!1,styles:this.options.mapOptions.styles,backgroundColor:this.options.mapOptions.backgroundColor}),t=this;this._reposition=i.maps.event.addListenerOnce(e,"center_changed",function(){t.onReposition()}),this._google=e,i.maps.event.addListenerOnce(e,"idle",functiLine truncated
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react"),require("react-leaflet")):"function"==typeof define&&define.amd?define(["react","react-leaflet"],e):"object"==typeof exports?exports.ReactLeaflet=e(require("react"),require("react-leaflet")):t.ReactLeaflet=e(t.React,t[void 0])}(this,function(t,e){return function(t){function e(n){if(i[n])return i[n].exports;var o=i[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0}),e.GoogleLayer=void 0;var o=i(1),r=n(o);e.GoogleLayer=r.default},function(t,e,i){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}function o(t,e){var i={};for(var n in t)e.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n]);return i}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0});var l=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}(),u=function t(e,i,n){null===e&&(e=Function.prototype);var o=Object.getOwnPropertyDescriptor(e,i);if(void 0===o){var r=Object.getPrototypeOf(e);return null===r?void 0:t(r,i,n)}if("value"in o)return o.value;var a=o.get;if(void 0!==a)return a.call(n)},h=i(4),p=(n(h),i(5)),c=(i(2),function(t){function e(){return r(this,e),a(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return s(e,t),l(e,[{key:"componentWillMount",value:function(){u(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"componentWillMount",this).call(this);var t=this.props;t.map,t.googlekey,t.maptype,t.asclientid,o(t,["map","googlekey","maptype","asclientid"]);this.leafletElement=new L.gridLayer.googleMutant(this.props)}},{key:"componentDidUpdate",value:function(t){var e=this.props,i=e.opacity,n=e.zIndex;i!==t.opacity&&this.leafletElement.setOpacity(i),n!==t.zIndex&&this.leafletElement.setZIndex(n)}}]),e}(p.GridLayer));c.propTypes={googlekey:h.PropTypes.string.isRequired,maptype:h.PropTypes.string,asclientid:h.PropTypes.bool},e.default=c},function(t,e,i){"use strict";var n=i(3);n.VERSION="3.18",L.GridLayer.GoogleMutant=L.GridLayer.extend({includes:L.Mixin.Events,options:{minZoom:0,maxZoom:18,tileSize:256,subdomains:"abc",errorTileUrl:"",attribution:"",opacity:1,continuousWorld:!1,noWrap:!1,type:"satellite",maxNativeZoom:21},initialize:function(t){L.GridLayer.prototype.initialize.call(this,t);var e=this;t.asclientid?n.CLIENT=t.googlekey:n.KEY=t.googlekey,e._type=t.maptype||"SATELLITE",n.load(function(t){google=t,console.log("I just loaded google maps api"),e._ready=!0,e._initMutant(),e._update()}),this._tileCallbacks={},this._freshTiles={},this._imagesPerTile="hybrid"===e._type?2:1,this.createTile="hybrid"===e._type?this._createMultiTile:this._createSingleTile},onAdd:function(t){L.GridLayer.prototype.onAdd.call(this,t),this._initMutantContainer(),this._ready&&(this._map=t,this._initMutant(),t.on("viewreset",this._reset,this),t.on("move",this._update,this),t.on("zoomend",this._handleZoomAnim,this),t.on("resize",this._resize,this),t._controlCorners.bottomright.style.marginBottom="20px",this._reset(),this._update())},onRemove:function(t){L.GridLayer.prototype.onRemove.call(this,t),t._container.removeChild(this._mutantContainer),this._mutantContainer=void 0,t.off("viewreset",this._reset,this),t.off("move",this._update,this),t.off("zoomend",this._handleZoomAnim,this),t.off("resize",this._resize,this),t._controlCorners.bottomright.style.marginBottom="0em"},getAttribution:function(){return this.options.attribution},setOpacity:function(t){this.options.opacity=t,t<1&&L.DomUtil.setOpacity(this._mutantContainer,t)},setElementSize:function(t,e){t.style.width=e.x+"px",t.style.height=e.y+"px"},_initMutantContainer:function(){this._mutantContainer||(this._mutantContainer=L.DomUtil.create("div","leaflet-google-mutant leaflet-top leaflet-left"),this._mutantContainer.id="_MutantContainer_"+L.Util.stamp(this._mutantContainer),this._mutantContainer.style.pointerEvents="none",this._map.getContainer().appendChild(this._mutantContainer)),this.setOpacity(this.options.opacity),this.setElementSize(this._mutantContainer,this._map.getSize()),this._attachObserver(this.Line truncated
+16 -5
View File
@@ -1,8 +1,13 @@
import React from 'react';
import { Map, TileLayer, LayersControl } from 'react-leaflet'
import {GoogleLayer} from '../src'
const { BaseLayer } = LayersControl;
const { BaseLayer} = LayersControl;
const key = 'Your Key goes here';
const terrain = 'TERRAIN';
const road = 'ROADMAP';
const satellite = 'SATELLITE';
const hydrid = 'HYBRID';
//// Google's map type. Valid values are 'roadmap', 'satellite' or 'terrain'. 'hybrid' is not really supported.
export default class GoogleExample extends React.Component {
@@ -17,12 +22,18 @@ export default class GoogleExample extends React.Component {
<BaseLayer name='OpenStreetMap.Mapnik'>
<TileLayer url="http://{s}.tile.osm.org/{z}/{x}/{y}.png"/>
</BaseLayer>
<BaseLayer checked name='Google Maps Roads'>
<GoogleLayer googlekey={key} type='ROADMAP'/>
<BaseLayer checked name='Google Maps Roads'>
<GoogleLayer googlekey={key} maptype={road}/>
</BaseLayer>
<BaseLayer name='Google Maps Hydrid'>
<GoogleLayer googlekey={key} type='HYBRID' />
<BaseLayer name='Google Maps Terrain'>
<GoogleLayer googlekey={key} maptype={terrain} />
</BaseLayer>
<BaseLayer name='Google Maps Satellite'>
<GoogleLayer googlekey={key} maptype={satellite} />
</BaseLayer>
<BaseLayer name='Google Maps Hydrid'>
<GoogleLayer googlekey={key} maptype={hydrid} />
</BaseLayer>
</LayersControl>
</Map>
)
+1 -1
View File
@@ -5,7 +5,7 @@
<meta charset="utf-8">
<title>React-Leaflet-Shapefile example</title>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/normalize/3.0.2/normalize.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.css">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css">
<style>
h1,
h2,
+27 -14
View File
@@ -26,38 +26,51 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var GoogleLayer = function (_BaseTileLayer) {
_inherits(GoogleLayer, _BaseTileLayer);
var GoogleLayer = function (_GridLayer) {
_inherits(GoogleLayer, _GridLayer);
function GoogleLayer() {
_classCallCheck(this, GoogleLayer);
return _possibleConstructorReturn(this, Object.getPrototypeOf(GoogleLayer).apply(this, arguments));
return _possibleConstructorReturn(this, (GoogleLayer.__proto__ || Object.getPrototypeOf(GoogleLayer)).apply(this, arguments));
}
_createClass(GoogleLayer, [{
key: 'componentWillMount',
value: function componentWillMount() {
_get(Object.getPrototypeOf(GoogleLayer.prototype), 'componentWillMount', this).call(this);
var _props = this.props;
var _map = _props.map;
var _lc = _props.layerContainer;
var googlekey = _props.googlekey;
var type = _props.type;
var asclientid = _props.asclientid;
_get(GoogleLayer.prototype.__proto__ || Object.getPrototypeOf(GoogleLayer.prototype), 'componentWillMount', this).call(this);
var props = _objectWithoutProperties(_props, ['map', 'layerContainer', 'googlekey', 'type', 'asclientid']);
var _props = this.props,
_map = _props.map,
googlekey = _props.googlekey,
maptype = _props.maptype,
asclientid = _props.asclientid,
props = _objectWithoutProperties(_props, ['map', 'googlekey', 'maptype', 'asclientid']);
this.leafletElement = new L.Google(googlekey, type, asclientid, props);
this.leafletElement = new L.gridLayer.googleMutant(this.props);
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps) {
var _props2 = this.props,
opacity = _props2.opacity,
zIndex = _props2.zIndex;
if (opacity !== prevProps.opacity) {
this.leafletElement.setOpacity(opacity);
}
if (zIndex !== prevProps.zIndex) {
this.leafletElement.setZIndex(zIndex);
}
}
}]);
return GoogleLayer;
}(_reactLeaflet.BaseTileLayer);
}(_reactLeaflet.GridLayer);
GoogleLayer.propTypes = {
type: _react.PropTypes.string,
googlekey: _react.PropTypes.string.isRequired,
maptype: _react.PropTypes.string,
asclientid: _react.PropTypes.bool
};
exports.default = GoogleLayer;
+371 -174
View File
@@ -1,220 +1,417 @@
'use strict';
/*
* Google layer using Google Maps API
*/
/* global google: true */
// Based on https://github.com/shramov/leaflet-plugins
// GridLayer like https://avinmathew.com/leaflet-and-google-maps/ , but using MutationObserver instead of jQuery
var GoogleMapsLoader = require('google-maps');
GoogleMapsLoader.VERSION = '3.14';
GoogleMapsLoader.VERSION = '3.18';
var google = null;
L.Google = L.Class.extend({
includes: L.Mixin.Events,
// 🍂class GridLayer.GoogleMutant
// 🍂extends GridLayer
L.GridLayer.GoogleMutant = L.GridLayer.extend({
includes: L.Mixin.Events,
options: {
minZoom: 0,
maxZoom: 18,
tileSize: 256,
subdomains: 'abc',
errorTileUrl: '',
attribution: '',
opacity: 1,
continuousWorld: false,
noWrap: false,
mapOptions: {
backgroundColor: '#dddddd'
}
},
options: {
minZoom: 0,
maxZoom: 18,
tileSize: 256,
subdomains: 'abc',
errorTileUrl: '',
attribution: '', // The mutant container will add its own attribution anyways.
opacity: 1,
continuousWorld: false,
noWrap: false,
// 🍂option type: String = 'roadmap'
// Google's map type. Valid values are 'roadmap', 'satellite' or 'terrain'. 'hybrid' is not really supported.
type: 'satellite',
maxNativeZoom: 21
},
// Possible types: SATELLITE, ROADMAP, HYBRID, TERRAIN
initialize: function initialize(goolekey, type, asclientid, options) {
L.Util.setOptions(this, options);
var self = this;
initialize: function initialize(options) {
L.GridLayer.prototype.initialize.call(this, options);
var self = this;
if (asclientid) {
GoogleMapsLoader.CLIENT = goolekey;
} else {
GoogleMapsLoader.KEY = goolekey;
}
if (options.asclientid) {
GoogleMapsLoader.CLIENT = options.googlekey;
} else {
GoogleMapsLoader.KEY = options.googlekey;
}
GoogleMapsLoader.onLoad(function () {
self._ready = true;
});
GoogleMapsLoader.load(function (_google) {
google = _google;
console.log('I just loaded google maps api');
self._type = options.maptype || 'SATELLITE';
self._initMapObject();
self._update();
GoogleMapsLoader.load(function (_google) {
google = _google;
console.log('I just loaded google maps api');
self._ready = true;
//self._initMapObject();
// self.
self._initMutant();
self._update();
//this._ready = google.maps.Map !== undefined;
//if (!this._ready) L.Google.asyncWait.push(this);
});
self._type = type || 'SATELLITE';
},
//this._ready = google.maps.Map !== undefined;
//if (!this._ready) L.Google.asyncWait.push(this);
});
onAdd: function onAdd(map, insertAtTheBottom) {
this._map = map;
this._insertAtTheBottom = insertAtTheBottom;
// Couple data structures indexed by tile key
this._tileCallbacks = {}; // Callbacks for promises for tiles that are expected
this._freshTiles = {}; // Tiles from the mutant which haven't been requested yet
// create a container div for tiles
this._initContainer();
this._initMapObject();
this._imagesPerTile = self._type === 'hybrid' ? 2 : 1;
this.createTile = self._type === 'hybrid' ? this._createMultiTile : this._createSingleTile;
},
// set up events
map.on('viewreset', this._reset, this);
onAdd: function onAdd(map) {
L.GridLayer.prototype.onAdd.call(this, map);
this._initMutantContainer();
this._limitedUpdate = L.Util.limitExecByInterval(this._update, 150, this);
map.on('move', this._update, this);
// this._GAPIPromise.then(function () {
if (this._ready) {
this._map = map;
map.on('zoomanim', this._handleZoomAnim, this);
this._initMutant();
//20px instead of 1em to avoid a slight overlap with google's attribution
map._controlCorners.bottomright.style.marginBottom = '20px';
map.on('viewreset', this._reset, this);
map.on('move', this._update, this);
map.on('zoomend', this._handleZoomAnim, this);
map.on('resize', this._resize, this);
this._reset();
this._update();
},
//20px instead of 1em to avoid a slight overlap with google's attribution
map._controlCorners.bottomright.style.marginBottom = '20px';
onRemove: function onRemove(map) {
map._container.removeChild(this._container);
this._reset();
this._update();
}
//}.bind(this));
},
map.off('viewreset', this._reset, this);
onRemove: function onRemove(map) {
L.GridLayer.prototype.onRemove.call(this, map);
map._container.removeChild(this._mutantContainer);
this._mutantContainer = undefined;
map.off('move', this._update, this);
map.off('viewreset', this._reset, this);
map.off('move', this._update, this);
map.off('zoomend', this._handleZoomAnim, this);
map.off('resize', this._resize, this);
map.off('zoomanim', this._handleZoomAnim, this);
map._controlCorners.bottomright.style.marginBottom = '0em';
},
map._controlCorners.bottomright.style.marginBottom = '0em';
},
getAttribution: function getAttribution() {
return this.options.attribution;
},
getAttribution: function getAttribution() {
return this.options.attribution;
},
setOpacity: function setOpacity(opacity) {
this.options.opacity = opacity;
if (opacity < 1) {
L.DomUtil.setOpacity(this._mutantContainer, opacity);
}
},
setOpacity: function setOpacity(opacity) {
this.options.opacity = opacity;
if (opacity < 1) {
L.DomUtil.setOpacity(this._container, opacity);
}
},
setElementSize: function setElementSize(e, size) {
e.style.width = size.x + 'px';
e.style.height = size.y + 'px';
},
setElementSize: function setElementSize(e, size) {
e.style.width = size.x + 'px';
e.style.height = size.y + 'px';
},
_initMutantContainer: function _initMutantContainer() {
if (!this._mutantContainer) {
this._mutantContainer = L.DomUtil.create('div', 'leaflet-google-mutant leaflet-top leaflet-left');
this._mutantContainer.id = '_MutantContainer_' + L.Util.stamp(this._mutantContainer);
// this._mutantContainer.style.zIndex = 'auto';
this._mutantContainer.style.pointerEvents = 'none';
_initContainer: function _initContainer() {
var tilePane = this._map._container,
first = tilePane.firstChild;
this._map.getContainer().appendChild(this._mutantContainer);
}
if (!this._container) {
this._container = L.DomUtil.create('div', 'leaflet-google-layer leaflet-top leaflet-left');
this._container.id = '_GMapContainer_' + L.Util.stamp(this);
this._container.style.zIndex = 'auto';
}
this.setOpacity(this.options.opacity);
this.setElementSize(this._mutantContainer, this._map.getSize());
tilePane.insertBefore(this._container, first);
this._attachObserver(this._mutantContainer);
},
this.setOpacity(this.options.opacity);
this.setElementSize(this._container, this._map.getSize());
},
_initMutant: function _initMutant() {
if (!this._ready || !this._mutantContainer) return;
this._mutantCenter = new google.maps.LatLng(0, 0);
_initMapObject: function _initMapObject() {
if (!this._ready) return;
this._google_center = new google.maps.LatLng(0, 0);
var map = new google.maps.Map(this._container, {
center: this._google_center,
zoom: 0,
tilt: 0,
mapTypeId: google.maps.MapTypeId[this._type],
disableDefaultUI: true,
keyboardShortcuts: false,
draggable: false,
disableDoubleClickZoom: true,
scrollwheel: false,
streetViewControl: false,
styles: this.options.mapOptions.styles,
backgroundColor: this.options.mapOptions.backgroundColor
});
var map = new google.maps.Map(this._mutantContainer, {
center: this._mutantCenter,
zoom: 0,
tilt: 0,
mapTypeId: google.maps.MapTypeId[this._type],
disableDefaultUI: true,
keyboardShortcuts: false,
draggable: false,
disableDoubleClickZoom: true,
scrollwheel: false,
streetViewControl: false,
styles: this.options.styles || {},
backgroundColor: 'transparent'
});
var _this = this;
this._reposition = google.maps.event.addListenerOnce(map, 'center_changed', function () {
_this.onReposition();
});
this._google = map;
this._mutant = map;
google.maps.event.addListenerOnce(map, 'idle', function () {
_this._checkZoomLevels();
});
google.maps.event.addListenerOnce(map, 'tilesloaded', function () {
_this.fire('load');
});
//Reporting that map-object was initialized.
this.fire('MapObjectInitialized', { mapObject: map });
},
// 🍂event spawned
// Fired when the mutant has been created.
this.fire('spawned', {
mapObject: map
});
},
_checkZoomLevels: function _checkZoomLevels() {
//setting the zoom level on the Google map may result in a different zoom level than the one requested
//(it won't go beyond the level for which they have data).
// verify and make sure the zoom levels on both Leaflet and Google maps are consistent
if (this._map.getZoom() !== undefined && this._google.getZoom() !== this._map.getZoom()) {
//zoom levels are out of sync. Set the leaflet zoom level to match the google one
this._map.setZoom(this._google.getZoom());
}
},
_attachObserver: function _attachObserver(node) {
// console.log('Gonna observe', node);
_reset: function _reset() {
this._initContainer();
},
var observer = new MutationObserver(this._onMutations.bind(this));
_update: function _update() {
if (!this._google) return;
this._resize();
// pass in the target node, as well as the observer options
observer.observe(node, {
childList: true,
subtree: true
});
},
var center = this._map.getCenter();
var _center = new google.maps.LatLng(center.lat, center.lng);
_onMutations: function _onMutations(mutations) {
for (var i = 0; i < mutations.length; ++i) {
var mutation = mutations[i];
for (var j = 0; j < mutation.addedNodes.length; ++j) {
var node = mutation.addedNodes[j];
this._google.setCenter(_center);
if (this._map.getZoom() !== undefined) this._google.setZoom(Math.round(this._map.getZoom()));
if (node instanceof HTMLImageElement) {
this._onMutatedImage(node);
} else if (node instanceof HTMLElement) {
Array.prototype.forEach.call(node.querySelectorAll('img'), this._onMutatedImage.bind(this));
}
}
}
},
this._checkZoomLevels();
},
// Only images which 'src' attrib match this will be considered for moving around.
// Looks like some kind of string-based protobuf, maybe??
// Only the roads (and terrain, and vector-based stuff) match this pattern
_roadRegexp: /!1i(\d+)!2i(\d+)!3i(\d+)!/,
_resize: function _resize() {
var size = this._map.getSize();
if (this._container.style.width === size.x && this._container.style.height === size.y) return;
this.setElementSize(this._container, size);
this.onReposition();
},
// On the other hand, raster imagery matches this other pattern
_satRegexp: /x=(\d+)&y=(\d+)&z=(\d+)/,
_handleZoomAnim: function _handleZoomAnim(e) {
var center = e.center;
var _center = new google.maps.LatLng(center.lat, center.lng);
// On small viewports, when zooming in/out, a static image is requested
// This will not be moved around, just removed from the DOM.
_staticRegExp: /StaticMapService\.GetMapImage/,
this._google.setCenter(_center);
this._google.setZoom(Math.round(e.zoom));
},
_onMutatedImage: function _onMutatedImage(imgNode) {
// if (imgNode.src) {
// console.log('caught mutated image: ', imgNode.src);
// }
onReposition: function onReposition() {
if (!this._google) return;
google.maps.event.trigger(this._google, 'resize');
}
var coords;
var match = imgNode.src.match(this._roadRegexp);
var sublayer, parent;
if (match) {
coords = {
z: match[1],
x: match[2],
y: match[3]
};
if (this._imagesPerTile > 1) {
imgNode.style.zIndex = 1;
}
sublayer = 1;
} else {
match = imgNode.src.match(this._satRegexp);
if (match) {
coords = {
x: match[1],
y: match[2],
z: match[3]
};
}
// imgNode.style.zIndex = 0;
sublayer = 0;
}
if (coords) {
var key = this._tileCoordsToKey(coords);
imgNode.style.position = 'absolute';
if (this._imagesPerTile > 1) {
key += '/' + sublayer;
}
if (key in this._tileCallbacks && this._tileCallbacks[key]) {
// console.log('Fullfilling callback ', key);
this._tileCallbacks[key].pop()(imgNode);
if (!this._tileCallbacks[key].length) {
delete this._tileCallbacks[key];
}
} else {
// console.log('Caching for later', key);
parent = imgNode.parentNode;
if (parent) {
parent.removeChild(imgNode);
parent.removeChild = L.Util.falseFn;
// imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
if (key in this._freshTiles) {
this._freshTiles[key].push(imgNode);
} else {
this._freshTiles[key] = [imgNode];
}
}
} else if (imgNode.src.match(this._staticRegExp)) {
parent = imgNode.parentNode;
if (parent) {
// Remove the image, but don't store it anywhere.
// Image needs to be replaced instead of removed, as the container
// seems to be reused.
imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
}
},
// This will be used as this.createTile for 'roadmap', 'sat', 'terrain'
_createSingleTile: function createTile(coords, done) {
var key = this._tileCoordsToKey(coords);
// console.log('Need:', key);
if (key in this._freshTiles) {
var tile = this._freshTiles[key].pop();
if (!this._freshTiles[key].length) {
delete this._freshTiles[key];
}
L.Util.requestAnimFrame(done);
// console.log('Got ', key, ' from _freshTiles');
return tile;
} else {
var tileContainer = L.DomUtil.create('div');
this._tileCallbacks[key] = this._tileCallbacks[key] || [];
this._tileCallbacks[key].push(function (c /*, k*/) {
return function (imgNode) {
var parent = imgNode.parentNode;
if (parent) {
parent.removeChild(imgNode);
parent.removeChild = L.Util.falseFn;
// imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
c.appendChild(imgNode);
done();
// console.log('Sent ', k, ' to _tileCallbacks');
}.bind(this);
}.bind(this)(tileContainer /*, key*/));
return tileContainer;
}
},
// This will be used as this.createTile for 'hybrid'
_createMultiTile: function createTile(coords, done) {
var key = this._tileCoordsToKey(coords);
var tileContainer = L.DomUtil.create('div');
tileContainer.dataset.pending = this._imagesPerTile;
for (var i = 0; i < this._imagesPerTile; i++) {
var key2 = key + '/' + i;
if (key2 in this._freshTiles) {
tileContainer.appendChild(this._freshTiles[key2].pop());
if (!this._freshTiles[key2].length) {
delete this._freshTiles[key2];
}
tileContainer.dataset.pending--;
// console.log('Got ', key2, ' from _freshTiles');
} else {
this._tileCallbacks[key2] = this._tileCallbacks[key2] || [];
this._tileCallbacks[key2].push(function (c /*, k2*/) {
return function (imgNode) {
var parent = imgNode.parentNode;
if (parent) {
parent.removeChild(imgNode);
parent.removeChild = L.Util.falseFn;
// imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
c.appendChild(imgNode);
c.dataset.pending--;
if (!parseInt(c.dataset.pending)) {
done();
}
// console.log('Sent ', k2, ' to _tileCallbacks, still ', c.dataset.pending, ' images to go');
}.bind(this);
}.bind(this)(tileContainer /*, key2*/));
}
}
if (!parseInt(tileContainer.dataset.pending)) {
L.Util.requestAnimFrame(done);
}
return tileContainer;
},
_checkZoomLevels: function _checkZoomLevels() {
//setting the zoom level on the Google map may result in a different zoom level than the one requested
//(it won't go beyond the level for which they have data).
// verify and make sure the zoom levels on both Leaflet and Google maps are consistent
if (this._map.getZoom() !== undefined && this._mutant.getZoom() !== this._map.getZoom()) {
//zoom levels are out of sync. Set the leaflet zoom level to match the google one
this._map.setZoom(this._mutant.getZoom());
}
},
_reset: function _reset() {
this._initContainer();
},
_update: function _update() {
L.GridLayer.prototype._update.call(this);
if (!this._mutant) return;
var center = this._map.getCenter();
var _center = new google.maps.LatLng(center.lat, center.lng);
this._mutant.setCenter(_center);
var zoom = this._map.getZoom();
if (zoom !== undefined) {
this._mutant.setZoom(Math.round(this._map.getZoom()));
}
},
_resize: function _resize() {
var size = this._map.getSize();
if (this._mutantContainer.style.width === size.x && this._mutantContainer.style.height === size.y) return;
this.setElementSize(this._mutantContainer, size);
if (!this._mutant) return;
google.maps.event.trigger(this._mutant, 'resize');
},
_handleZoomAnim: function _handleZoomAnim() {
var center = this._map.getCenter();
var _center = new google.maps.LatLng(center.lat, center.lng);
this._mutant.setCenter(_center);
this._mutant.setZoom(Math.round(this._map.getZoom()));
},
// Agressively prune _freshtiles when a tile with the same key is removed,
// this prevents a problem where Leaflet keeps a loaded tile longer than
// GMaps, so that GMaps makes two requests but Leaflet only consumes one,
// polluting _freshTiles with stale data.
_removeTile: function _removeTile(key) {
if (this._imagesPerTile > 1) {
for (var i = 0; i < this._imagesPerTile; i++) {
var key2 = key + '/' + i;
if (key2 in this._freshTiles) {
delete this._freshTiles[key2];
}
// console.log('Pruned spurious hybrid _freshTiles');
}
} else {
if (key in this._freshTiles) {
delete this._freshTiles[key];
// console.log('Pruned spurious _freshTiles', key);
}
}
return L.GridLayer.prototype._removeTile.call(this, key);
}
});
L.Google.asyncWait = [];
L.Google.asyncInitialize = function () {
var i;
for (i = 0; i < L.Google.asyncWait.length; i++) {
var o = L.Google.asyncWait[i];
o._ready = true;
if (o._container) {
o._initMapObject();
o._update();
}
}
L.Google.asyncWait = [];
// 🍂factory gridLayer.googleMutant(options)
// Returns a new `GridLayer.GoogleMutant` given its options
L.gridLayer.googleMutant = function (options) {
return new L.GridLayer.GoogleMutant(options);
};
+11 -10
View File
@@ -32,25 +32,26 @@
},
"homepage": "https://github.com/Charmatzis/react-leaflet-google#readme",
"peerDependencies": {
"leaflet": "^0.7.7",
"react-leaflet": "^0.11.5",
"react": "^15.0.2"
"leaflet": "^1.0.2",
"react-leaflet": "^1.0.1",
"react": "^15.4.1"
},
"devDependencies": {
"babel-cli": "^6.8.0",
"babel-core": "^6.8.0",
"babel-eslint": "^4.1.8",
"babel-eslint": "^7.0.0",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.0.15",
"babel-preset-stage-0": "^6.1.18",
"eslint": "^1.10.3",
"eslint-plugin-react": "^3.16.1",
"eslint": "^3.8.1",
"eslint-plugin-react": "^6.4.1",
"google-maps": "^3.2.1",
"leaflet": "^0.7.7",
"react": "^15.0.2",
"react-dom": "^15.0.2",
"react-leaflet": "^0.11.5",
"leaflet": "^1.0.2",
"lodash.isequal": "^4.4.0",
"react": "^15.4.1",
"react-dom": "^15.4.1",
"react-leaflet": "^1.0.1",
"webpack": "^1.13.0",
"webpack-dev-server": "^1.12.1"
}
+15 -5
View File
@@ -1,12 +1,12 @@
import React, {PropTypes} from 'react';
import {BaseTileLayer} from 'react-leaflet';
import {GridLayer} from 'react-leaflet';
import {Google} from './leaflet.google';
export default class GoogleLayer extends BaseTileLayer {
export default class GoogleLayer extends GridLayer {
static propTypes = {
type: PropTypes.string,
googlekey: PropTypes.string.isRequired,
maptype: PropTypes.string,
asclientid: PropTypes.bool
};
@@ -14,8 +14,18 @@ export default class GoogleLayer extends BaseTileLayer {
componentWillMount() {
super.componentWillMount();
const {map: _map, layerContainer: _lc, googlekey, type, asclientid, ...props} = this.props;
this.leafletElement = new L.Google(googlekey, type, asclientid, props);
const {map: _map, googlekey, maptype, asclientid, ...props} = this.props;
this.leafletElement = new L.gridLayer.googleMutant(this.props);
}
componentDidUpdate (prevProps) {
const { opacity, zIndex } = this.props
if (opacity !== prevProps.opacity) {
this.leafletElement.setOpacity(opacity)
}
if (zIndex !== prevProps.zIndex) {
this.leafletElement.setZIndex(zIndex)
}
}
+305 -114
View File
@@ -1,16 +1,12 @@
/*
* Google layer using Google Maps API
*/
/* global google: true */
// Based on https://github.com/shramov/leaflet-plugins
// GridLayer like https://avinmathew.com/leaflet-and-google-maps/ , but using MutationObserver instead of jQuery
var GoogleMapsLoader = require('google-maps');
GoogleMapsLoader.VERSION = '3.25';
GoogleMapsLoader.VERSION = '3.18';
var google = null;
L.Google = L.Class.extend({
// 🍂class GridLayer.GoogleMutant
// 🍂extends GridLayer
L.GridLayer.GoogleMutant = L.GridLayer.extend({
includes: L.Mixin.Events,
options: {
@@ -19,73 +15,86 @@ L.Google = L.Class.extend({
tileSize: 256,
subdomains: 'abc',
errorTileUrl: '',
attribution: '',
attribution: '', // The mutant container will add its own attribution anyways.
opacity: 1,
continuousWorld: false,
noWrap: false,
mapOptions: {
backgroundColor: '#dddddd'
}
// 🍂option type: String = 'roadmap'
// Google's map type. Valid values are 'roadmap', 'satellite' or 'terrain'. 'hybrid' is not really supported.
type: 'satellite',
maxNativeZoom: 21
},
// Possible types: SATELLITE, ROADMAP, HYBRID, TERRAIN
initialize: function (goolekey, type, asclientid, options) {
L.Util.setOptions(this, options);
initialize: function (options) {
L.GridLayer.prototype.initialize.call(this, options);
var self = this;
if (asclientid) {
GoogleMapsLoader.CLIENT = goolekey;
if (options.asclientid) {
GoogleMapsLoader.CLIENT = options.googlekey;
} else {
GoogleMapsLoader.KEY = goolekey;
GoogleMapsLoader.KEY = options.googlekey;
}
self._type = options.maptype || 'SATELLITE';
GoogleMapsLoader.onLoad(function () {
self._ready = true;
});
GoogleMapsLoader.load(function (_google) {
google = _google;
console.log('I just loaded google maps api');
self._ready = true;
self._initMapObject();
self._ready = true;
//self._initMapObject();
// self.
self._initMutant();
self._update();
//this._ready = google.maps.Map !== undefined;
//if (!this._ready) L.Google.asyncWait.push(this);
});
self._type = type || 'SATELLITE';
// Couple data structures indexed by tile key
this._tileCallbacks = {}; // Callbacks for promises for tiles that are expected
this._freshTiles = {}; // Tiles from the mutant which haven't been requested yet
this._imagesPerTile = (self._type === 'hybrid') ? 2 : 1;
this.createTile = (self._type === 'hybrid') ? this._createMultiTile : this._createSingleTile;
},
onAdd: function (map, insertAtTheBottom) {
this._map = map;
this._insertAtTheBottom = insertAtTheBottom;
onAdd: function (map) {
L.GridLayer.prototype.onAdd.call(this, map);
this._initMutantContainer();
// create a container div for tiles
this._initContainer();
this._initMapObject();
// this._GAPIPromise.then(function () {
if (this._ready) {
this._map = map;
// set up events
map.on('viewreset', this._reset, this);
this._initMutant();
this._limitedUpdate = L.Util.limitExecByInterval(this._update, 150, this);
map.on('move', this._update, this);
map.on('viewreset', this._reset, this);
map.on('move', this._update, this);
map.on('zoomend', this._handleZoomAnim, this);
map.on('resize', this._resize, this);
map.on('zoomanim', this._handleZoomAnim, this);
//20px instead of 1em to avoid a slight overlap with google's attribution
map._controlCorners.bottomright.style.marginBottom = '20px';
//20px instead of 1em to avoid a slight overlap with google's attribution
map._controlCorners.bottomright.style.marginBottom = '20px';
this._reset();
this._update();
this._reset();
this._update();
}
//}.bind(this));
},
onRemove: function (map) {
map._container.removeChild(this._container);
L.GridLayer.prototype.onRemove.call(this, map);
map._container.removeChild(this._mutantContainer);
this._mutantContainer = undefined;
map.off('viewreset', this._reset, this);
map.off('move', this._update, this);
map.off('zoomanim', this._handleZoomAnim, this);
map.off('zoomend', this._handleZoomAnim, this);
map.off('resize', this._resize, this);
map._controlCorners.bottomright.style.marginBottom = '0em';
},
@@ -97,7 +106,7 @@ L.Google = L.Class.extend({
setOpacity: function (opacity) {
this.options.opacity = opacity;
if (opacity < 1) {
L.DomUtil.setOpacity(this._container, opacity);
L.DomUtil.setOpacity(this._mutantContainer, opacity);
}
},
@@ -106,28 +115,28 @@ L.Google = L.Class.extend({
e.style.height = size.y + 'px';
},
_initContainer: function () {
var tilePane = this._map._container,
first = tilePane.firstChild;
_initMutantContainer: function () {
if (!this._mutantContainer) {
this._mutantContainer = L.DomUtil.create('div', 'leaflet-google-mutant leaflet-top leaflet-left');
this._mutantContainer.id = '_MutantContainer_' + L.Util.stamp(this._mutantContainer);
// this._mutantContainer.style.zIndex = 'auto';
this._mutantContainer.style.pointerEvents = 'none';
if (!this._container) {
this._container = L.DomUtil.create('div', 'leaflet-google-layer leaflet-top leaflet-left');
this._container.id = '_GMapContainer_' + L.Util.stamp(this);
this._container.style.zIndex = 'auto';
this._map.getContainer().appendChild(this._mutantContainer);
}
tilePane.insertBefore(this._container, first);
this.setOpacity(this.options.opacity);
this.setElementSize(this._container, this._map.getSize());
this.setElementSize(this._mutantContainer, this._map.getSize());
this._attachObserver(this._mutantContainer);
},
_initMapObject: function () {
if (!this._ready || !this._container) return;
this._google_center = new google.maps.LatLng(0, 0);
var map = new google.maps.Map(this._container, {
center: this._google_center,
_initMutant: function () {
if (!this._ready || !this._mutantContainer) return;
this._mutantCenter = new google.maps.LatLng(0, 0);
var map = new google.maps.Map(this._mutantContainer, {
center: this._mutantCenter,
zoom: 0,
tilt: 0,
mapTypeId: google.maps.MapTypeId[this._type],
@@ -137,38 +146,211 @@ L.Google = L.Class.extend({
disableDoubleClickZoom: true,
scrollwheel: false,
streetViewControl: false,
styles: this.options.mapOptions.styles,
backgroundColor: this.options.mapOptions.backgroundColor
styles: this.options.styles || {},
backgroundColor: 'transparent'
});
var _this = this;
this._reposition = google.maps.event.addListenerOnce(map, 'center_changed',
function () {
_this.onReposition();
});
this._google = map;
this._mutant = map;
google.maps.event.addListenerOnce(map, 'idle',
function () {
_this._checkZoomLevels();
});
google.maps.event.addListenerOnce(map, 'tilesloaded',
function () {
_this.fire('load');
});
//Reporting that map-object was initialized.
this.fire('MapObjectInitialized', {
// 🍂event spawned
// Fired when the mutant has been created.
this.fire('spawned', {
mapObject: map
});
},
_attachObserver: function _attachObserver(node) {
// console.log('Gonna observe', node);
var observer = new MutationObserver(this._onMutations.bind(this));
// pass in the target node, as well as the observer options
observer.observe(node, {
childList: true,
subtree: true
});
},
_onMutations: function _onMutations(mutations) {
for (var i = 0; i < mutations.length; ++i) {
var mutation = mutations[i];
for (var j = 0; j < mutation.addedNodes.length; ++j) {
var node = mutation.addedNodes[j];
if (node instanceof HTMLImageElement) {
this._onMutatedImage(node);
} else if (node instanceof HTMLElement) {
Array.prototype.forEach.call(node.querySelectorAll('img'), this._onMutatedImage.bind(this));
}
}
}
},
// Only images which 'src' attrib match this will be considered for moving around.
// Looks like some kind of string-based protobuf, maybe??
// Only the roads (and terrain, and vector-based stuff) match this pattern
_roadRegexp: /!1i(\d+)!2i(\d+)!3i(\d+)!/,
// On the other hand, raster imagery matches this other pattern
_satRegexp: /x=(\d+)&y=(\d+)&z=(\d+)/,
// On small viewports, when zooming in/out, a static image is requested
// This will not be moved around, just removed from the DOM.
_staticRegExp: /StaticMapService\.GetMapImage/,
_onMutatedImage: function _onMutatedImage(imgNode) {
// if (imgNode.src) {
// console.log('caught mutated image: ', imgNode.src);
// }
var coords;
var match = imgNode.src.match(this._roadRegexp);
var sublayer, parent;
if (match) {
coords = {
z: match[1],
x: match[2],
y: match[3]
};
if (this._imagesPerTile > 1) {
imgNode.style.zIndex = 1;
}
sublayer = 1;
} else {
match = imgNode.src.match(this._satRegexp);
if (match) {
coords = {
x: match[1],
y: match[2],
z: match[3]
};
}
// imgNode.style.zIndex = 0;
sublayer = 0;
}
if (coords) {
var key = this._tileCoordsToKey(coords);
imgNode.style.position = 'absolute';
if (this._imagesPerTile > 1) {
key += '/' + sublayer;
}
if (key in this._tileCallbacks && this._tileCallbacks[key]) {
// console.log('Fullfilling callback ', key);
this._tileCallbacks[key].pop()(imgNode);
if (!this._tileCallbacks[key].length) {
delete this._tileCallbacks[key];
}
} else {
// console.log('Caching for later', key);
parent = imgNode.parentNode;
if (parent) {
parent.removeChild(imgNode);
parent.removeChild = L.Util.falseFn;
// imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
if (key in this._freshTiles) {
this._freshTiles[key].push(imgNode);
} else {
this._freshTiles[key] = [imgNode];
}
}
} else if (imgNode.src.match(this._staticRegExp)) {
parent = imgNode.parentNode;
if (parent) {
// Remove the image, but don't store it anywhere.
// Image needs to be replaced instead of removed, as the container
// seems to be reused.
imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
}
},
// This will be used as this.createTile for 'roadmap', 'sat', 'terrain'
_createSingleTile: function createTile(coords, done) {
var key = this._tileCoordsToKey(coords);
// console.log('Need:', key);
if (key in this._freshTiles) {
var tile = this._freshTiles[key].pop();
if (!this._freshTiles[key].length) {
delete this._freshTiles[key];
}
L.Util.requestAnimFrame(done);
// console.log('Got ', key, ' from _freshTiles');
return tile;
} else {
var tileContainer = L.DomUtil.create('div');
this._tileCallbacks[key] = this._tileCallbacks[key] || [];
this._tileCallbacks[key].push((function (c /*, k*/ ) {
return function (imgNode) {
var parent = imgNode.parentNode;
if (parent) {
parent.removeChild(imgNode);
parent.removeChild = L.Util.falseFn;
// imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
c.appendChild(imgNode);
done();
// console.log('Sent ', k, ' to _tileCallbacks');
}.bind(this);
}.bind(this))(tileContainer /*, key*/ ));
return tileContainer;
}
},
// This will be used as this.createTile for 'hybrid'
_createMultiTile: function createTile(coords, done) {
var key = this._tileCoordsToKey(coords);
var tileContainer = L.DomUtil.create('div');
tileContainer.dataset.pending = this._imagesPerTile;
for (var i = 0; i < this._imagesPerTile; i++) {
var key2 = key + '/' + i;
if (key2 in this._freshTiles) {
tileContainer.appendChild(this._freshTiles[key2].pop());
if (!this._freshTiles[key2].length) {
delete this._freshTiles[key2];
}
tileContainer.dataset.pending--;
// console.log('Got ', key2, ' from _freshTiles');
} else {
this._tileCallbacks[key2] = this._tileCallbacks[key2] || [];
this._tileCallbacks[key2].push((function (c /*, k2*/ ) {
return function (imgNode) {
var parent = imgNode.parentNode;
if (parent) {
parent.removeChild(imgNode);
parent.removeChild = L.Util.falseFn;
// imgNode.parentNode.replaceChild(L.DomUtil.create('img'), imgNode);
}
c.appendChild(imgNode);
c.dataset.pending--;
if (!parseInt(c.dataset.pending)) {
done();
}
// console.log('Sent ', k2, ' to _tileCallbacks, still ', c.dataset.pending, ' images to go');
}.bind(this);
}.bind(this))(tileContainer /*, key2*/ ));
}
}
if (!parseInt(tileContainer.dataset.pending)) {
L.Util.requestAnimFrame(done);
}
return tileContainer;
},
_checkZoomLevels: function () {
//setting the zoom level on the Google map may result in a different zoom level than the one requested
//(it won't go beyond the level for which they have data).
// verify and make sure the zoom levels on both Leaflet and Google maps are consistent
if ((this._map.getZoom() !== undefined) && (this._google.getZoom() !== this._map.getZoom())) {
if ((this._map.getZoom() !== undefined) && (this._mutant.getZoom() !== this._map.getZoom())) {
//zoom levels are out of sync. Set the leaflet zoom level to match the google one
this._map.setZoom(this._google.getZoom());
this._map.setZoom(this._mutant.getZoom());
}
},
@@ -177,55 +359,64 @@ L.Google = L.Class.extend({
},
_update: function () {
if (!this._google) return;
this._resize();
L.GridLayer.prototype._update.call(this);
if (!this._mutant) return;
var center = this._map.getCenter();
var _center = new google.maps.LatLng(center.lat, center.lng);
this._google.setCenter(_center);
if (this._map.getZoom() !== undefined)
this._google.setZoom(Math.round(this._map.getZoom()));
this._checkZoomLevels();
this._mutant.setCenter(_center);
var zoom = this._map.getZoom();
if (zoom !== undefined) {
this._mutant.setZoom(Math.round(this._map.getZoom()));
}
},
_resize: function () {
var size = this._map.getSize();
if (this._container.style.width === size.x &&
this._container.style.height === size.y)
if (this._mutantContainer.style.width === size.x &&
this._mutantContainer.style.height === size.y)
return;
this.setElementSize(this._container, size);
this.onReposition();
this.setElementSize(this._mutantContainer, size);
if (!this._mutant) return;
google.maps.event.trigger(this._mutant, 'resize');
},
_handleZoomAnim: function (e) {
var center = e.center;
_handleZoomAnim: function () {
var center = this._map.getCenter();
var _center = new google.maps.LatLng(center.lat, center.lng);
this._google.setCenter(_center);
this._google.setZoom(Math.round(e.zoom));
this._mutant.setCenter(_center);
this._mutant.setZoom(Math.round(this._map.getZoom()));
},
// Agressively prune _freshtiles when a tile with the same key is removed,
// this prevents a problem where Leaflet keeps a loaded tile longer than
// GMaps, so that GMaps makes two requests but Leaflet only consumes one,
// polluting _freshTiles with stale data.
_removeTile: function (key) {
if (this._imagesPerTile > 1) {
for (var i = 0; i < this._imagesPerTile; i++) {
var key2 = key + '/' + i;
if (key2 in this._freshTiles) {
delete this._freshTiles[key2];
}
// console.log('Pruned spurious hybrid _freshTiles');
}
} else {
if (key in this._freshTiles) {
delete this._freshTiles[key];
// console.log('Pruned spurious _freshTiles', key);
}
}
onReposition: function () {
if (!this._google) return;
google.maps.event.trigger(this._google, 'resize');
return L.GridLayer.prototype._removeTile.call(this, key);
}
});
L.Google.asyncWait = [];
L.Google.asyncInitialize = function () {
var i;
for (i = 0; i < L.Google.asyncWait.length; i++) {
var o = L.Google.asyncWait[i];
o._ready = true;
if (o._container) {
o._initMapObject();
o._update();
}
}
L.Google.asyncWait = [];
// 🍂factory gridLayer.googleMutant(options)
// Returns a new `GridLayer.GoogleMutant` given its options
L.gridLayer.googleMutant = function (options) {
return new L.GridLayer.GoogleMutant(options);
};