From 5de2a8002b2d0aeea7ee350acb11166d7c3e1c29 Mon Sep 17 00:00:00 2001 From: Christos Date: Thu, 29 Dec 2016 00:30:25 +0200 Subject: [PATCH] new release for react-leaflet 1.0.2 --- dist/react-leaflet-google.js | 586 +++++++++++++++++++++---------- dist/react-leaflet-google.min.js | 2 +- example/google.js | 21 +- example/index.html | 2 +- lib/Google.js | 41 ++- lib/leaflet.google.js | 545 +++++++++++++++++++--------- package.json | 21 +- src/Google.js | 20 +- src/leaflet.google.js | 419 ++++++++++++++++------ 9 files changed, 1145 insertions(+), 512 deletions(-) diff --git a/dist/react-leaflet-google.js b/dist/react-leaflet-google.js index 1c1f722..1a605c8 100644 --- a/dist/react-leaflet-google.js +++ b/dist/react-leaflet-google.js @@ -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); }; /***/ }, diff --git a/dist/react-leaflet-google.min.js b/dist/react-leaflet-google.min.js index 20f6361..745b729 100644 --- a/dist/react-leaflet-google.min.js +++ b/dist/react-leaflet-google.min.js @@ -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;oe&&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",function(){t._checkZoomLevels()}),i.maps.event.addListenerOnce(e,"tilesloaded",function(){t.fire("load")}),this.fire("MapObjectInitialized",{mapObject:e})}},_checkZoomLevels:function(){void 0!==this._map.getZoom()&&this._google.getZoom()!==this._map.getZoom()&&this._map.setZoom(this._google.getZoom())},_reset:function(){this._initContainer()},_update:function(){if(this._google){this._resize();var e=this._map.getCenter(),t=new i.maps.LatLng(e.lat,e.lng);this._google.setCenter(t),void 0!==this._map.getZoom()&&this._google.setZoom(Math.round(this._map.getZoom())),this._checkZoomLevels()}},_resize:function(){var e=this._map.getSize();this._container.style.width===e.x&&this._container.style.height===e.y||(this.setElementSize(this._container,e),this.onReposition())},_handleZoomAnim:function(e){var t=e.center,o=new i.maps.LatLng(t.lat,t.lng);this._google.setCenter(o),this._google.setZoom(Math.round(e.zoom))},onReposition:function(){this._google&&i.maps.event.trigger(this._google,"resize")}}),L.Google.asyncWait=[],L.Google.asyncInitialize=function(){var e;for(e=0;e0&&(e+="&libraries="+l.LIBRARIES.join(",")),l.CLIENT&&(e+="&client="+l.CLIENT+"&v="+l.VERSION),l.CHANNEL&&(e+="&channel="+l.CHANNEL),l.LANGUAGE&&(e+="&language="+l.LANGUAGE),l.REGION&&(e+="®ion="+l.REGION),e},l.release=function(s){var c=function(){l.KEY=null,l.LIBRARIES=[],l.CLIENT=null,l.CHANNEL=null,l.LANGUAGE=null,l.REGION=null,l.VERSION=e,o=null,n=!1,i=[],r=[],"undefined"!=typeof window.google&&delete window.google,"undefined"!=typeof window[l.WINDOW_CALLBACK_NAME]&&delete window[l.WINDOW_CALLBACK_NAME],null!==a&&(l.createLoader=a,a=null),null!==t&&(t.parentElement.removeChild(t),t=null),s&&s()};n?l.load(function(){c()}):c()},l.onLoad=function(e){r.push(e)},l.makeMock=function(){a=l.createLoader,l.createLoader=function(){window.google=l._googleMockApiObject,window[l.WINDOW_CALLBACK_NAME]()}};var s=function(e){var t;for(n=!1,null===o&&(o=window.google),t=0;t=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;i1&&(t.style.zIndex=1),i=1):(o=t.src.match(this._satRegexp),o&&(e={x:o[1],y:o[2],z:o[3]}),i=0),e){var r=this._tileCoordsToKey(e);t.style.position="absolute",this._imagesPerTile>1&&(r+="/"+i),r in this._tileCallbacks&&this._tileCallbacks[r]?(this._tileCallbacks[r].pop()(t),this._tileCallbacks[r].length||delete this._tileCallbacks[r]):(n=t.parentNode,n&&(n.removeChild(t),n.removeChild=L.Util.falseFn),r in this._freshTiles?this._freshTiles[r].push(t):this._freshTiles[r]=[t])}else t.src.match(this._staticRegExp)&&(n=t.parentNode,n&&t.parentNode.replaceChild(L.DomUtil.create("img"),t))},_createSingleTile:function(t,e){var i=this._tileCoordsToKey(t);if(i in this._freshTiles){var n=this._freshTiles[i].pop();return this._freshTiles[i].length||delete this._freshTiles[i],L.Util.requestAnimFrame(e),n}var o=L.DomUtil.create("div");return this._tileCallbacks[i]=this._tileCallbacks[i]||[],this._tileCallbacks[i].push(function(t){return function(i){var n=i.parentNode;n&&(n.removeChild(i),n.removeChild=L.Util.falseFn),t.appendChild(i),e()}.bind(this)}.bind(this)(o)),o},_createMultiTile:function(t,e){var i=this._tileCoordsToKey(t),n=L.DomUtil.create("div");n.dataset.pending=this._imagesPerTile;for(var o=0;o1)for(var e=0;e0&&(t+="&libraries="+s.LIBRARIES.join(",")),s.CLIENT&&(t+="&client="+s.CLIENT+"&v="+s.VERSION),s.CHANNEL&&(t+="&channel="+s.CHANNEL),s.LANGUAGE&&(t+="&language="+s.LANGUAGE),s.REGION&&(t+="®ion="+s.REGION),t},s.release=function(l){var u=function(){s.KEY=null,s.LIBRARIES=[],s.CLIENT=null,s.CHANNEL=null,s.LANGUAGE=null,s.REGION=null,s.VERSION=t,i=null,n=!1,o=[],r=[],"undefined"!=typeof window.google&&delete window.google,"undefined"!=typeof window[s.WINDOW_CALLBACK_NAME]&&delete window[s.WINDOW_CALLBACK_NAME],null!==a&&(s.createLoader=a,a=null),null!==e&&(e.parentElement.removeChild(e),e=null),l&&l()};n?s.load(function(){u()}):u()},s.onLoad=function(t){r.push(t)},s.makeMock=function(){a=s.createLoader,s.createLoader=function(){window.google=s._googleMockApiObject,window[s.WINDOW_CALLBACK_NAME]()}};var l=function(t){var e;for(n=!1,null===i&&(i=window.google),e=0;e - - + + - - + + + + + + + + ) diff --git a/example/index.html b/example/index.html index 723f8a6..c162216 100644 --- a/example/index.html +++ b/example/index.html @@ -5,7 +5,7 @@ React-Leaflet-Shapefile example - +