mirror of
https://github.com/RustyRaptor/react-leaflet-google.git
synced 2026-12-03 23:45:17 -07:00
Avoid loading google maps twice, fixes #6
This commit is contained in:
1 parent
3f54399bc9
commit
7c60d01470
4 files changed
+18
-228
No files matched your search
Vendored
+7
-226
@@ -1,13 +1,13 @@
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
module.exports = factory(require("react"), require("react-leaflet"));
|
||||
module.exports = factory(require("react"), require("react-leaflet"), require("google-maps"));
|
||||
else if(typeof define === 'function' && define.amd)
|
||||
define(["react", "react-leaflet"], factory);
|
||||
define(["react", "react-leaflet", "google-maps"], factory);
|
||||
else if(typeof exports === 'object')
|
||||
exports["ReactLeaflet"] = factory(require("react"), require("react-leaflet"));
|
||||
exports["ReactLeaflet"] = factory(require("react"), require("react-leaflet"), require("google-maps"));
|
||||
else
|
||||
root["ReactLeaflet"] = factory(root["React"], root[undefined]);
|
||||
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__) {
|
||||
root["ReactLeaflet"] = factory(root["React"], root[undefined], root["GoogleMapsLoader"]);
|
||||
})(this, function(__WEBPACK_EXTERNAL_MODULE_2__, __WEBPACK_EXTERNAL_MODULE_3__, __WEBPACK_EXTERNAL_MODULE_5__) {
|
||||
return /******/ (function(modules) { // webpackBootstrap
|
||||
/******/ // The module cache
|
||||
/******/ var installedModules = {};
|
||||
@@ -586,228 +586,9 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
|
||||
/***/ },
|
||||
/* 5 */
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;(function(root, factory) {
|
||||
|
||||
if (root === null) {
|
||||
throw new Error('Google-maps package can be used only in browser');
|
||||
}
|
||||
|
||||
if (true) {
|
||||
!(__WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
||||
} else if (typeof exports === 'object') {
|
||||
module.exports = factory();
|
||||
} else {
|
||||
root.GoogleMapsLoader = factory();
|
||||
}
|
||||
|
||||
})(typeof window !== 'undefined' ? window : null, function() {
|
||||
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
var googleVersion = '3.18';
|
||||
|
||||
var script = null;
|
||||
|
||||
var google = null;
|
||||
|
||||
var loading = false;
|
||||
|
||||
var callbacks = [];
|
||||
|
||||
var onLoadEvents = [];
|
||||
|
||||
var originalCreateLoaderMethod = null;
|
||||
|
||||
|
||||
var GoogleMapsLoader = {};
|
||||
|
||||
|
||||
GoogleMapsLoader.URL = 'https://maps.googleapis.com/maps/api/js';
|
||||
|
||||
GoogleMapsLoader.KEY = null;
|
||||
|
||||
GoogleMapsLoader.LIBRARIES = [];
|
||||
|
||||
GoogleMapsLoader.CLIENT = null;
|
||||
|
||||
GoogleMapsLoader.CHANNEL = null;
|
||||
|
||||
GoogleMapsLoader.LANGUAGE = null;
|
||||
|
||||
GoogleMapsLoader.REGION = null;
|
||||
|
||||
GoogleMapsLoader.VERSION = googleVersion;
|
||||
|
||||
GoogleMapsLoader.WINDOW_CALLBACK_NAME = '__google_maps_api_provider_initializator__';
|
||||
|
||||
|
||||
GoogleMapsLoader._googleMockApiObject = {};
|
||||
|
||||
|
||||
GoogleMapsLoader.load = function(fn) {
|
||||
if (google === null) {
|
||||
if (loading === true) {
|
||||
if (fn) {
|
||||
callbacks.push(fn);
|
||||
}
|
||||
} else {
|
||||
loading = true;
|
||||
|
||||
window[GoogleMapsLoader.WINDOW_CALLBACK_NAME] = function() {
|
||||
ready(fn);
|
||||
};
|
||||
|
||||
GoogleMapsLoader.createLoader();
|
||||
}
|
||||
} else if (fn) {
|
||||
fn(google);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
GoogleMapsLoader.createLoader = function() {
|
||||
script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.src = GoogleMapsLoader.createUrl();
|
||||
|
||||
document.body.appendChild(script);
|
||||
};
|
||||
|
||||
|
||||
GoogleMapsLoader.isLoaded = function() {
|
||||
return google !== null;
|
||||
};
|
||||
|
||||
|
||||
GoogleMapsLoader.createUrl = function() {
|
||||
var url = GoogleMapsLoader.URL;
|
||||
|
||||
url += '?callback=' + GoogleMapsLoader.WINDOW_CALLBACK_NAME;
|
||||
|
||||
if (GoogleMapsLoader.KEY) {
|
||||
url += '&key=' + GoogleMapsLoader.KEY;
|
||||
}
|
||||
|
||||
if (GoogleMapsLoader.LIBRARIES.length > 0) {
|
||||
url += '&libraries=' + GoogleMapsLoader.LIBRARIES.join(',');
|
||||
}
|
||||
|
||||
if (GoogleMapsLoader.CLIENT) {
|
||||
url += '&client=' + GoogleMapsLoader.CLIENT + '&v=' + GoogleMapsLoader.VERSION;
|
||||
}
|
||||
|
||||
if (GoogleMapsLoader.CHANNEL) {
|
||||
url += '&channel=' + GoogleMapsLoader.CHANNEL;
|
||||
}
|
||||
|
||||
if (GoogleMapsLoader.LANGUAGE) {
|
||||
url += '&language=' + GoogleMapsLoader.LANGUAGE;
|
||||
}
|
||||
|
||||
if (GoogleMapsLoader.REGION) {
|
||||
url += '®ion=' + GoogleMapsLoader.REGION;
|
||||
}
|
||||
|
||||
return url;
|
||||
};
|
||||
|
||||
|
||||
GoogleMapsLoader.release = function(fn) {
|
||||
var release = function() {
|
||||
GoogleMapsLoader.KEY = null;
|
||||
GoogleMapsLoader.LIBRARIES = [];
|
||||
GoogleMapsLoader.CLIENT = null;
|
||||
GoogleMapsLoader.CHANNEL = null;
|
||||
GoogleMapsLoader.LANGUAGE = null;
|
||||
GoogleMapsLoader.REGION = null;
|
||||
GoogleMapsLoader.VERSION = googleVersion;
|
||||
|
||||
google = null;
|
||||
loading = false;
|
||||
callbacks = [];
|
||||
onLoadEvents = [];
|
||||
|
||||
if (typeof window.google !== 'undefined') {
|
||||
delete window.google;
|
||||
}
|
||||
|
||||
if (typeof window[GoogleMapsLoader.WINDOW_CALLBACK_NAME] !== 'undefined') {
|
||||
delete window[GoogleMapsLoader.WINDOW_CALLBACK_NAME];
|
||||
}
|
||||
|
||||
if (originalCreateLoaderMethod !== null) {
|
||||
GoogleMapsLoader.createLoader = originalCreateLoaderMethod;
|
||||
originalCreateLoaderMethod = null;
|
||||
}
|
||||
|
||||
if (script !== null) {
|
||||
script.parentElement.removeChild(script);
|
||||
script = null;
|
||||
}
|
||||
|
||||
if (fn) {
|
||||
fn();
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
GoogleMapsLoader.load(function() {
|
||||
release();
|
||||
});
|
||||
} else {
|
||||
release();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
GoogleMapsLoader.onLoad = function(fn) {
|
||||
onLoadEvents.push(fn);
|
||||
};
|
||||
|
||||
|
||||
GoogleMapsLoader.makeMock = function() {
|
||||
originalCreateLoaderMethod = GoogleMapsLoader.createLoader;
|
||||
|
||||
GoogleMapsLoader.createLoader = function() {
|
||||
window.google = GoogleMapsLoader._googleMockApiObject;
|
||||
window[GoogleMapsLoader.WINDOW_CALLBACK_NAME]();
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
var ready = function(fn) {
|
||||
var i;
|
||||
|
||||
loading = false;
|
||||
|
||||
if (google === null) {
|
||||
google = window.google;
|
||||
}
|
||||
|
||||
for (i = 0; i < onLoadEvents.length; i++) {
|
||||
onLoadEvents[i](google);
|
||||
}
|
||||
|
||||
if (fn) {
|
||||
fn(google);
|
||||
}
|
||||
|
||||
for (i = 0; i < callbacks.length; i++) {
|
||||
callbacks[i](google);
|
||||
}
|
||||
|
||||
callbacks = [];
|
||||
};
|
||||
|
||||
|
||||
return GoogleMapsLoader;
|
||||
|
||||
});
|
||||
/***/ function(module, exports) {
|
||||
|
||||
module.exports = __WEBPACK_EXTERNAL_MODULE_5__;
|
||||
|
||||
/***/ }
|
||||
/******/ ])
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
!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
|
||||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("google-maps"),require("react"),require("react-leaflet")):"function"==typeof define&&define.amd?define(["google-maps","react","react-leaflet"],e):"object"==typeof exports?exports.ReactLeaflet=e(require("google-maps"),require("react"),require("react-leaflet")):t.ReactLeaflet=e(t.GoogleMapsLoader,t.React,t[void 0])}(this,function(t,e,i){return function(t){function e(o){if(i[o])return i[o].exports;var n=i[o]={exports:{},id:o,loaded:!1};return t[o].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e,i){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0}),e.GoogleLayer=void 0;var n=i(1),r=o(n);e.GoogleLayer=r.default},function(t,e,i){"use strict";function o(t){return t&&t.__esModule?t:{default:t}}function n(t,e){var i={};for(var o in t)e.indexOf(o)>=0||Object.prototype.hasOwnProperty.call(t,o)&&(i[o]=t[o]);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 o=e[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,i,o){return i&&t(e.prototype,i),o&&t(e,o),e}}(),h=function t(e,i,o){null===e&&(e=Function.prototype);var n=Object.getOwnPropertyDescriptor(e,i);if(void 0===n){var r=Object.getPrototypeOf(e);return null===r?void 0:t(r,i,o)}if("value"in n)return n.value;var a=n.get;if(void 0!==a)return a.call(o)},p=i(4),u=(o(p),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(){h(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"componentWillMount",this).call(this);var t=this.props;t.map,t.googlekey,t.maptype,t.asclientid,n(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,o=e.zIndex;i!==t.opacity&&this.leafletElement.setOpacity(i),o!==t.zIndex&&this.leafletElement.setZIndex(o)}}]),e}(u.GridLayer));c.propTypes={googlekey:p.PropTypes.string.isRequired,maptype:p.PropTypes.string,asclientid:p.PropTypes.bool},e.default=c},function(t,e,i){"use strict";var o=i(3);o.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?o.CLIENT=t.googlekey:o.KEY=t.googlekey,e._type=t.maptype||"SATELLITE",o.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.setLine truncated
|
||||
+2
-1
@@ -35,7 +35,8 @@
|
||||
"peerDependencies": {
|
||||
"leaflet": "^1.0.2",
|
||||
"react-leaflet": "^1.0.1",
|
||||
"react": "^15.4.1"
|
||||
"react": "^15.4.1",
|
||||
"google-maps": "^3.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.8.0",
|
||||
|
||||
@@ -35,6 +35,14 @@ module.exports = {
|
||||
commonjs2: 'react',
|
||||
root: 'React'
|
||||
}
|
||||
},
|
||||
{
|
||||
'google-maps': {
|
||||
amd: 'google-maps',
|
||||
commonjs: 'google-maps',
|
||||
commonjs2: 'google-maps',
|
||||
root: 'GoogleMapsLoader'
|
||||
}
|
||||
}
|
||||
],
|
||||
module: {
|
||||
|
||||
Reference in new issue
Block a user