google-map-react
Version:
isomorphic google map react component, allows render react components on the google map
1,569 lines (1,242 loc) • 142 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"), require("react-dom"));
else if(typeof define === 'function' && define.amd)
define(["react", "react-dom"], factory);
else if(typeof exports === 'object')
exports["GoogleMapReact"] = factory(require("react"), require("react-dom"));
else
root["GoogleMapReact"] = factory(root["React"], root["ReactDOM"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_35__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
var _google_map = __webpack_require__(14);
var _google_map2 = _interopRequireDefault(_google_map);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = _google_map2.default;
/***/ }),
/* 1 */
/***/ (function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
/***/ }),
/* 2 */
/***/ (function(module, exports) {
'use strict';
module.exports = Point;
/**
* A standalone point geometry with useful accessor, comparison, and
* modification methods.
*
* @class Point
* @param {Number} x the x-coordinate. this could be longitude or screen
* pixels, or any other sort of unit.
* @param {Number} y the y-coordinate. this could be latitude or screen
* pixels, or any other sort of unit.
* @example
* var point = new Point(-77, 38);
*/
function Point(x, y) {
this.x = x;
this.y = y;
}
Point.prototype = {
/**
* Clone this point, returning a new point that can be modified
* without affecting the old one.
* @return {Point} the clone
*/
clone: function() { return new Point(this.x, this.y); },
/**
* Add this point's x & y coordinates to another point,
* yielding a new point.
* @param {Point} p the other point
* @return {Point} output point
*/
add: function(p) { return this.clone()._add(p); },
/**
* Subtract this point's x & y coordinates to from point,
* yielding a new point.
* @param {Point} p the other point
* @return {Point} output point
*/
sub: function(p) { return this.clone()._sub(p); },
/**
* Multiply this point's x & y coordinates by point,
* yielding a new point.
* @param {Point} p the other point
* @return {Point} output point
*/
multByPoint: function(p) { return this.clone()._multByPoint(p); },
/**
* Divide this point's x & y coordinates by point,
* yielding a new point.
* @param {Point} p the other point
* @return {Point} output point
*/
divByPoint: function(p) { return this.clone()._divByPoint(p); },
/**
* Multiply this point's x & y coordinates by a factor,
* yielding a new point.
* @param {Point} k factor
* @return {Point} output point
*/
mult: function(k) { return this.clone()._mult(k); },
/**
* Divide this point's x & y coordinates by a factor,
* yielding a new point.
* @param {Point} k factor
* @return {Point} output point
*/
div: function(k) { return this.clone()._div(k); },
/**
* Rotate this point around the 0, 0 origin by an angle a,
* given in radians
* @param {Number} a angle to rotate around, in radians
* @return {Point} output point
*/
rotate: function(a) { return this.clone()._rotate(a); },
/**
* Rotate this point around p point by an angle a,
* given in radians
* @param {Number} a angle to rotate around, in radians
* @param {Point} p Point to rotate around
* @return {Point} output point
*/
rotateAround: function(a,p) { return this.clone()._rotateAround(a,p); },
/**
* Multiply this point by a 4x1 transformation matrix
* @param {Array<Number>} m transformation matrix
* @return {Point} output point
*/
matMult: function(m) { return this.clone()._matMult(m); },
/**
* Calculate this point but as a unit vector from 0, 0, meaning
* that the distance from the resulting point to the 0, 0
* coordinate will be equal to 1 and the angle from the resulting
* point to the 0, 0 coordinate will be the same as before.
* @return {Point} unit vector point
*/
unit: function() { return this.clone()._unit(); },
/**
* Compute a perpendicular point, where the new y coordinate
* is the old x coordinate and the new x coordinate is the old y
* coordinate multiplied by -1
* @return {Point} perpendicular point
*/
perp: function() { return this.clone()._perp(); },
/**
* Return a version of this point with the x & y coordinates
* rounded to integers.
* @return {Point} rounded point
*/
round: function() { return this.clone()._round(); },
/**
* Return the magitude of this point: this is the Euclidean
* distance from the 0, 0 coordinate to this point's x and y
* coordinates.
* @return {Number} magnitude
*/
mag: function() {
return Math.sqrt(this.x * this.x + this.y * this.y);
},
/**
* Judge whether this point is equal to another point, returning
* true or false.
* @param {Point} other the other point
* @return {boolean} whether the points are equal
*/
equals: function(other) {
return this.x === other.x &&
this.y === other.y;
},
/**
* Calculate the distance from this point to another point
* @param {Point} p the other point
* @return {Number} distance
*/
dist: function(p) {
return Math.sqrt(this.distSqr(p));
},
/**
* Calculate the distance from this point to another point,
* without the square root step. Useful if you're comparing
* relative distances.
* @param {Point} p the other point
* @return {Number} distance
*/
distSqr: function(p) {
var dx = p.x - this.x,
dy = p.y - this.y;
return dx * dx + dy * dy;
},
/**
* Get the angle from the 0, 0 coordinate to this point, in radians
* coordinates.
* @return {Number} angle
*/
angle: function() {
return Math.atan2(this.y, this.x);
},
/**
* Get the angle from this point to another point, in radians
* @param {Point} b the other point
* @return {Number} angle
*/
angleTo: function(b) {
return Math.atan2(this.y - b.y, this.x - b.x);
},
/**
* Get the angle between this point and another point, in radians
* @param {Point} b the other point
* @return {Number} angle
*/
angleWith: function(b) {
return this.angleWithSep(b.x, b.y);
},
/*
* Find the angle of the two vectors, solving the formula for
* the cross product a x b = |a||b|sin(θ) for θ.
* @param {Number} x the x-coordinate
* @param {Number} y the y-coordinate
* @return {Number} the angle in radians
*/
angleWithSep: function(x, y) {
return Math.atan2(
this.x * y - this.y * x,
this.x * x + this.y * y);
},
_matMult: function(m) {
var x = m[0] * this.x + m[1] * this.y,
y = m[2] * this.x + m[3] * this.y;
this.x = x;
this.y = y;
return this;
},
_add: function(p) {
this.x += p.x;
this.y += p.y;
return this;
},
_sub: function(p) {
this.x -= p.x;
this.y -= p.y;
return this;
},
_mult: function(k) {
this.x *= k;
this.y *= k;
return this;
},
_div: function(k) {
this.x /= k;
this.y /= k;
return this;
},
_multByPoint: function(p) {
this.x *= p.x;
this.y *= p.y;
return this;
},
_divByPoint: function(p) {
this.x /= p.x;
this.y /= p.y;
return this;
},
_unit: function() {
this._div(this.mag());
return this;
},
_perp: function() {
var y = this.y;
this.y = this.x;
this.x = -y;
return this;
},
_rotate: function(angle) {
var cos = Math.cos(angle),
sin = Math.sin(angle),
x = cos * this.x - sin * this.y,
y = sin * this.x + cos * this.y;
this.x = x;
this.y = y;
return this;
},
_rotateAround: function(angle, p) {
var cos = Math.cos(angle),
sin = Math.sin(angle),
x = p.x + cos * (this.x - p.x) - sin * (this.y - p.y),
y = p.y + sin * (this.x - p.x) + cos * (this.y - p.y);
this.x = x;
this.y = y;
return this;
},
_round: function() {
this.x = Math.round(this.x);
this.y = Math.round(this.y);
return this;
}
};
/**
* Construct a point from an array if necessary, otherwise if the input
* is already a Point, or an unknown type, return it unchanged
* @param {Array<Number>|Point|*} a any kind of input value
* @return {Point} constructed point, or passed-through value.
* @example
* // this
* var point = Point.convert([0, 1]);
* // is equivalent to
* var point = new Point(0, 1);
*/
Point.convert = function (a) {
if (a instanceof Point) {
return a;
}
if (Array.isArray(a)) {
return new Point(a[0], a[1]);
}
return a;
};
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _react = __webpack_require__(1);
var _react2 = _interopRequireDefault(_react);
var _propTypes = __webpack_require__(11);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _omit = __webpack_require__(6);
var _omit2 = _interopRequireDefault(_omit);
var _shallowEqual = __webpack_require__(7);
var _shallowEqual2 = _interopRequireDefault(_shallowEqual);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
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; }
// utils
var mainStyle = {
width: '100%',
height: '100%',
left: 0,
top: 0,
margin: 0,
padding: 0,
position: 'absolute'
};
var style = {
width: 0,
height: 0,
left: 0,
top: 0,
backgroundColor: 'transparent',
position: 'absolute'
};
var GoogleMapMarkers = function (_Component) {
_inherits(GoogleMapMarkers, _Component);
/* eslint-disable react/forbid-prop-types */
function GoogleMapMarkers(props) {
_classCallCheck(this, GoogleMapMarkers);
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
_this._getState = function () {
return {
children: _this.props.dispatcher.getChildren(),
updateCounter: _this.props.dispatcher.getUpdateCounter()
};
};
_this._onChangeHandler = function () {
if (!_this.dimesionsCache_) {
return;
}
var prevChildCount = (_this.state.children || []).length;
var state = _this._getState();
_this.setState(state, function () {
return (state.children || []).length !== prevChildCount && _this._onMouseChangeHandler();
});
};
_this._onChildClick = function () {
if (_this.props.onChildClick) {
if (_this.hoverChildProps_) {
var hoverKey = _this.hoverKey_;
var childProps = _this.hoverChildProps_;
// click works only on hovered item
_this.props.onChildClick(hoverKey, childProps);
}
}
};
_this._onChildMouseDown = function () {
if (_this.props.onChildMouseDown) {
if (_this.hoverChildProps_) {
var hoverKey = _this.hoverKey_;
var childProps = _this.hoverChildProps_;
// works only on hovered item
_this.props.onChildMouseDown(hoverKey, childProps);
}
}
};
_this._onChildMouseEnter = function (hoverKey, childProps) {
if (!_this.dimesionsCache_) {
return;
}
if (_this.props.onChildMouseEnter) {
_this.props.onChildMouseEnter(hoverKey, childProps);
}
_this.hoverChildProps_ = childProps;
_this.hoverKey_ = hoverKey;
_this.setState({ hoverKey: hoverKey });
};
_this._onChildMouseLeave = function () {
if (!_this.dimesionsCache_) {
return;
}
var hoverKey = _this.hoverKey_;
var childProps = _this.hoverChildProps_;
if (hoverKey !== undefined && hoverKey !== null) {
if (_this.props.onChildMouseLeave) {
_this.props.onChildMouseLeave(hoverKey, childProps);
}
_this.hoverKey_ = null;
_this.hoverChildProps_ = null;
_this.setState({ hoverKey: null });
}
};
_this._onMouseAllow = function (value) {
if (!value) {
_this._onChildMouseLeave();
}
_this.allowMouse_ = value;
};
_this._onMouseChangeHandler = function () {
if (_this.allowMouse_) {
_this._onMouseChangeHandlerRaf();
}
};
_this._onMouseChangeHandlerRaf = function () {
if (!_this.dimesionsCache_) {
return;
}
var mp = _this.props.dispatcher.getMousePosition();
if (mp) {
var distances = [];
var hoverDistance = _this.props.getHoverDistance();
_react2.default.Children.forEach(_this.state.children, function (child, childIndex) {
if (!child) return;
// layers
if (child.props.latLng === undefined && child.props.lat === undefined && child.props.lng === undefined) {
return;
}
var childKey = child.key !== undefined && child.key !== null ? child.key : childIndex;
var dist = _this.props.distanceToMouse(_this.dimesionsCache_[childKey], mp, child.props);
if (dist < hoverDistance) {
distances.push({
key: childKey,
dist: dist,
props: child.props
});
}
});
if (distances.length) {
distances.sort(function (a, b) {
return a.dist - b.dist;
});
var hoverKey = distances[0].key;
var childProps = distances[0].props;
if (_this.hoverKey_ !== hoverKey) {
_this._onChildMouseLeave();
_this._onChildMouseEnter(hoverKey, childProps);
}
} else {
_this._onChildMouseLeave();
}
} else {
_this._onChildMouseLeave();
}
};
_this._getDimensions = function (key) {
var childKey = key;
return _this.dimesionsCache_[childKey];
};
_this.props.dispatcher.on('kON_CHANGE', _this._onChangeHandler);
_this.props.dispatcher.on('kON_MOUSE_POSITION_CHANGE', _this._onMouseChangeHandler);
_this.props.dispatcher.on('kON_CLICK', _this._onChildClick);
_this.props.dispatcher.on('kON_MDOWN', _this._onChildMouseDown);
_this.dimesionsCache_ = {};
_this.hoverKey_ = null;
_this.hoverChildProps_ = null;
_this.allowMouse_ = true;
_this.state = _extends({}, _this._getState(), { hoverKey: null });
return _this;
}
/* eslint-enable react/forbid-prop-types */
GoogleMapMarkers.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
if (this.props.experimental === true) {
return !(0, _shallowEqual2.default)(this.props, nextProps) || !(0, _shallowEqual2.default)((0, _omit2.default)(this.state, ['hoverKey']), (0, _omit2.default)(nextState, ['hoverKey']));
}
return !(0, _shallowEqual2.default)(this.props, nextProps) || !(0, _shallowEqual2.default)(this.state, nextState);
};
GoogleMapMarkers.prototype.componentWillUnmount = function componentWillUnmount() {
this.props.dispatcher.removeListener('kON_CHANGE', this._onChangeHandler);
this.props.dispatcher.removeListener('kON_MOUSE_POSITION_CHANGE', this._onMouseChangeHandler);
this.props.dispatcher.removeListener('kON_CLICK', this._onChildClick);
this.props.dispatcher.removeListener('kON_MDOWN', this._onChildMouseDown);
this.dimesionsCache_ = null;
};
GoogleMapMarkers.prototype.render = function render() {
var _this2 = this;
var mainElementStyle = this.props.style || mainStyle;
this.dimesionsCache_ = {};
var markers = _react2.default.Children.map(this.state.children, function (child, childIndex) {
if (!child) return undefined;
if (child.props.latLng === undefined && child.props.lat === undefined && child.props.lng === undefined) {
return _react2.default.cloneElement(child, {
$geoService: _this2.props.geoService,
$onMouseAllow: _this2._onMouseAllow,
$prerender: _this2.props.prerender
});
}
var latLng = child.props.latLng !== undefined ? child.props.latLng : { lat: child.props.lat, lng: child.props.lng };
var pt = _this2.props.projectFromLeftTop ? _this2.props.geoService.fromLatLngToContainerPixel(latLng) : _this2.props.geoService.project(latLng);
var stylePtPos = {
left: pt.x,
top: pt.y
};
// If the component has a southeast corner defined (either as a LatLng, or a separate
// lat and lng pair), set the width and height based on the distance between the northwest
// and the southeast corner to lock the overlay to the correct geographic bounds.
if (child.props.seLatLng !== undefined || child.props.seLat !== undefined && child.props.seLng !== undefined) {
var seLatLng = child.props.seLatLng !== undefined ? child.props.seLatLng : { lat: child.props.seLat, lng: child.props.seLng };
var sePt = _this2.props.projectFromLeftTop ? _this2.props.geoService.fromLatLngToContainerPixel(seLatLng) : _this2.props.geoService.project(seLatLng);
stylePtPos.width = sePt.x - pt.x;
stylePtPos.height = sePt.y - pt.y;
}
var dx = 0;
var dy = 0;
if (!_this2.props.projectFromLeftTop) {
// center projection
if (_this2.props.geoService.hasSize()) {
dx = _this2.props.geoService.getWidth() / 2;
dy = _this2.props.geoService.getHeight() / 2;
}
}
// to prevent rerender on child element i need to pass
// const params $getDimensions and $dimensionKey instead of dimension object
var childKey = child.key !== undefined && child.key !== null ? child.key : childIndex;
_this2.dimesionsCache_[childKey] = _extends({
x: pt.x + dx,
y: pt.y + dy
}, latLng);
return _react2.default.createElement(
'div',
{
key: childKey,
style: _extends({}, style, stylePtPos),
className: child.props.$markerHolderClassName
},
_react2.default.cloneElement(child, {
$hover: childKey === _this2.state.hoverKey,
$getDimensions: _this2._getDimensions,
$dimensionKey: childKey,
$geoService: _this2.props.geoService,
$onMouseAllow: _this2._onMouseAllow,
$prerender: _this2.props.prerender
})
);
});
return _react2.default.createElement(
'div',
{ style: mainElementStyle },
markers
);
};
return GoogleMapMarkers;
}(_react.Component);
GoogleMapMarkers.propTypes = {
geoService: _propTypes2.default.any,
style: _propTypes2.default.any,
distanceToMouse: _propTypes2.default.func,
dispatcher: _propTypes2.default.any,
onChildClick: _propTypes2.default.func,
onChildMouseDown: _propTypes2.default.func,
onChildMouseLeave: _propTypes2.default.func,
onChildMouseEnter: _propTypes2.default.func,
getHoverDistance: _propTypes2.default.func,
projectFromLeftTop: _propTypes2.default.bool,
prerender: _propTypes2.default.bool
};
GoogleMapMarkers.defaultProps = {
projectFromLeftTop: false,
prerender: false
};
exports.default = GoogleMapMarkers;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _wrap2 = __webpack_require__(5);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var LatLng = function () {
function LatLng(lat, lng) {
_classCallCheck(this, LatLng);
if (isNaN(lat) || isNaN(lng)) {
throw new Error('Invalid LatLng object: (' + lat + ', ' + lng + ')');
}
this.lat = +lat;
this.lng = +lng;
}
LatLng.prototype.wrap = function wrap() {
return new LatLng(this.lat, (0, _wrap2.wrap)(this.lng, -180, 180));
};
return LatLng;
}();
LatLng.convert = function (a) {
if (a instanceof LatLng) {
return a;
}
if (Array.isArray(a)) {
return new LatLng(a[0], a[1]);
}
if ('lng' in a && 'lat' in a) {
return new LatLng(a.lat, a.lng);
}
return a;
};
exports.default = LatLng;
/***/ }),
/* 5 */
/***/ (function(module, exports) {
"use strict";
exports.__esModule = true;
exports.wrap = wrap;
/* eslint-disable import/prefer-default-export */
function wrap(n, min, max) {
var d = max - min;
return n === max ? n : ((n - min) % d + d) % d + min;
}
/***/ }),
/* 6 */
/***/ (function(module, exports) {
"use strict";
exports.__esModule = true;
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
// https://github.com/acdlite/recompose/blob/master/src/packages/recompose/utils/omit.js
var omit = function omit(obj, keys) {
var rest = _objectWithoutProperties(obj, []);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
if (key in rest) {
delete rest[key];
}
}
return rest;
};
exports.default = omit;
/***/ }),
/* 7 */
/***/ (function(module, exports) {
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @providesModule shallowEqual
* @typechecks
*
*/
var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* inlined Object.is polyfill to avoid requiring consumers ship their own
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
*/
function is(x, y) {
// SameValue algorithm
if (x === y) {
// Steps 1-5, 7-10
// Steps 6.b-6.e: +0 != -0
// Added the nonzero y check to make Flow happy, but it is redundant
return x !== 0 || y !== 0 || 1 / x === 1 / y;
}
// Step 6.a: NaN == NaN
// eslint-disable-next-line no-self-compare
return x !== x && y !== y;
}
/**
* Performs equality by iterating through keys on an object and returning false
* when any key has values which are not strictly equal between the arguments.
* Returns true when the values of all keys are strictly equal.
*/
function shallowEqual(objA, objB) {
if (is(objA, objB)) {
return true;
}
if ((typeof objA === 'undefined' ? 'undefined' : _typeof(objA)) !== 'object' || objA === null || (typeof objB === 'undefined' ? 'undefined' : _typeof(objB)) !== 'object' || objB === null) {
return false;
}
var keysA = Object.keys(objA);
var keysB = Object.keys(objB);
if (keysA.length !== keysB.length) {
return false;
}
// Test for A's keys different from B.
for (var i = 0; i < keysA.length; i++) {
if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
return false;
}
}
return true;
}
module.exports = shallowEqual;
/* src: https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/shallowEqual.js */
/***/ }),
/* 8 */
/***/ (function(module, exports) {
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
function makeEmptyFunction(arg) {
return function () {
return arg;
};
}
/**
* This function accepts and discards inputs; it has no side effects. This is
* primarily useful idiomatically for overridable function endpoints which
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
*/
var emptyFunction = function emptyFunction() {};
emptyFunction.thatReturns = makeEmptyFunction;
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
emptyFunction.thatReturnsThis = function () {
return this;
};
emptyFunction.thatReturnsArgument = function (arg) {
return arg;
};
module.exports = emptyFunction;
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
'use strict';
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
var validateFormat = function validateFormat(format) {};
if (true) {
validateFormat = function validateFormat(format) {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
};
}
function invariant(condition, format, a, b, c, d, e, f) {
validateFormat(format);
if (!condition) {
var error;
if (format === undefined) {
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(format.replace(/%s/g, function () {
return args[argIndex++];
}));
error.name = 'Invariant Violation';
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
}
module.exports = invariant;
/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
'use strict';
var emptyFunction = __webpack_require__(8);
/**
* Similar to invariant but only logs a warning if the condition is not met.
* This can be used to log issues in development environments in critical
* paths. Removing the logging code for production environments will keep the
* same logic and follow the same code paths.
*/
var warning = emptyFunction;
if (true) {
var printWarning = function printWarning(format) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
};
warning = function warning(condition, format) {
if (format === undefined) {
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
}
if (format.indexOf('Failed Composite propType: ') === 0) {
return; // Ignore CompositeComponent proptype check.
}
if (!condition) {
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
args[_key2 - 2] = arguments[_key2];
}
printWarning.apply(undefined, [format].concat(args));
}
};
}
module.exports = warning;
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
if (true) {
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' &&
Symbol.for &&
Symbol.for('react.element')) ||
0xeac7;
var isValidElement = function(object) {
return typeof object === 'object' &&
object !== null &&
object.$$typeof === REACT_ELEMENT_TYPE;
};
// By explicitly using `prop-types` you are opting into new development behavior.
// http://fb.me/prop-types-in-prod
var throwOnDirectAccess = true;
module.exports = __webpack_require__(33)(isValidElement, throwOnDirectAccess);
} else {
// By explicitly using `prop-types` you are opting into new production behavior.
// http://fb.me/prop-types-in-prod
module.exports = require('./factoryWithThrowingShims')();
}
/***/ }),
/* 12 */
/***/ (function(module, exports) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
module.exports = ReactPropTypesSecret;
/***/ }),
/* 13 */
/***/ (function(module, exports) {
"use strict";
exports.__esModule = true;
var generateHeatmap = exports.generateHeatmap = function generateHeatmap(instance, _ref) {
var positions = _ref.positions;
return new instance.visualization.HeatmapLayer({
data: positions.reduce(function (acc, _ref2) {
var lat = _ref2.lat,
lng = _ref2.lng,
_ref2$weight = _ref2.weight,
weight = _ref2$weight === undefined ? 1 : _ref2$weight;
acc.push({
location: new instance.LatLng(lat, lng),
weight: weight
});
return acc;
}, [])
});
};
var optionsHeatmap = exports.optionsHeatmap = function optionsHeatmap(instance, _ref3) {
var _ref3$options = _ref3.options,
options = _ref3$options === undefined ? {} : _ref3$options;
return Object.keys(options).map(function (option) {
return instance.set(option, options[option]);
});
};
/***/ }),
/* 14 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
exports.__esModule = true;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _react = __webpack_require__(1);
var _react2 = _interopRequireDefault(_react);
var _propTypes = __webpack_require__(11);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _reactDom = __webpack_require__(35);
var _reactDom2 = _interopRequireDefault(_reactDom);
var _google_map_map = __webpack_require__(15);
var _google_map_map2 = _interopRequireDefault(_google_map_map);
var _marker_dispatcher = __webpack_require__(18);
var _marker_dispatcher2 = _interopRequireDefault(_marker_dispatcher);
var _google_map_markers = __webpack_require__(3);
var _google_map_markers2 = _interopRequireDefault(_google_map_markers);
var _google_map_markers_prerender = __webpack_require__(16);
var _google_map_markers_prerender2 = _interopRequireDefault(_google_map_markers_prerender);
var _google_heatmap = __webpack_require__(13);
var _google_map_loader = __webpack_require__(17);
var _google_map_loader2 = _interopRequireDefault(_google_map_loader);
var _geo = __webpack_require__(21);
var _geo2 = _interopRequireDefault(_geo);
var _raf = __webpack_require__(29);
var _raf2 = _interopRequireDefault(_raf);
var _pick = __webpack_require__(28);
var _pick2 = _interopRequireDefault(_pick);
var _omit = __webpack_require__(6);
var _omit2 = _interopRequireDefault(_omit);
var _log = __webpack_require__(27);
var _log2 = _interopRequireDefault(_log);
var _isEmpty = __webpack_require__(23);
var _isEmpty2 = _interopRequireDefault(_isEmpty);
var _isNumber = __webpack_require__(24);
var _isNumber2 = _interopRequireDefault(_isNumber);
var _detect = __webpack_require__(19);
var _detect2 = _interopRequireDefault(_detect);
var _shallowEqual = __webpack_require__(7);
var _shallowEqual2 = _interopRequireDefault(_shallowEqual);
var _isPlainObject = __webpack_require__(25);
var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
var _isArraysEqualEps = __webpack_require__(22);
var _isArraysEqualEps2 = _interopRequireDefault(_isArraysEqualEps);
var _detectElementResize = __webpack_require__(20);
var _detectElementResize2 = _interopRequireDefault(_detectElementResize);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
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; } /* eslint-disable import/no-extraneous-dependencies, react/forbid-prop-types, react/no-find-dom-node, no-console */
// helpers
// loaders
// utils
// consts
var kEPS = 0.00001;
var K_GOOGLE_TILE_SIZE = 256;
// real minZoom calculated here _getMinZoom
var K_IDLE_TIMEOUT = 100;
var K_IDLE_CLICK_TIMEOUT = 300;
var DEFAULT_MIN_ZOOM = 3;
// Starting with version 3.32, the maps API calls `draw()` each frame during
// a zoom animation.
var DRAW_CALLED_DURING_ANIMATION_VERSION = 32;
function defaultOptions_() /* maps */{
return {
overviewMapControl: false,
streetViewControl: false,
rotateControl: true,
mapTypeControl: false,
// disable poi
styles: [{
featureType: 'poi',
elementType: 'labels',
stylers: [{ visibility: 'off' }]
}],
minZoom: DEFAULT_MIN_ZOOM // dynamically recalculted if possible during init
};
}
var latLng2Obj = function latLng2Obj(latLng) {
return (0, _isPlainObject2.default)(latLng) ? latLng : { lat: latLng[0], lng: latLng[1] };
};
var _checkMinZoom = function _checkMinZoom(zoom, minZoom) {
if (true) {
if (zoom < minZoom) {
console.warn('GoogleMap: ' + // eslint-disable-line
'minZoom option is less than recommended ' + 'minZoom option for your map sizes.\n' + 'overrided to value ' + minZoom);
}
}
if (minZoom < zoom) {
return zoom;
}
return minZoom;
};
var isFullScreen = function isFullScreen() {
return document.fullscreen || document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement;
};
var GoogleMap = function (_Component) {
_inherits(GoogleMap, _Component);
// eslint-disable-line
function GoogleMap(props) {
_classCallCheck(this, GoogleMap);
var _this = _possibleConstructorReturn(this, _Component.call(this, props));
_this._getMinZoom = function () {
if (_this.geoService_.getWidth() > 0 || _this.geoService_.getHeight() > 0) {
var tilesPerWidth = Math.ceil(_this.geoService_.getWidth() / K_GOOGLE_TILE_SIZE) + 2;
var tilesPerHeight = Math.ceil(_this.geoService_.getHeight() / K_GOOGLE_TILE_SIZE) + 2;
var maxTilesPerDim = Math.max(tilesPerWidth, tilesPerHeight);
return Math.ceil((0, _log2.default)(maxTilesPerDim));
}
return DEFAULT_MIN_ZOOM;
};
_this._computeMinZoom = function (minZoom) {
if (!(0, _isEmpty2.default)(minZoom)) {
return minZoom;
}
return _this._getMinZoom();
};
_this._mapDomResizeCallback = function () {
_this.resetSizeOnIdle_ = true;
if (_this.maps_) {
var originalCenter = _this.props.center || _this.props.defaultCenter;
var currentCenter = _this.map_.getCenter();
_this.maps_.event.trigger(_this.map_, 'resize');
_this.map_.setCenter(_this.props.resetBoundsOnResize ? originalCenter : currentCenter);
}
};
_this._setLayers = function (layerTypes) {
layerTypes.forEach(function (layerType) {
_this.layers_[layerType] = new _this.maps_[layerType]();
_this.layers_[layerType].setMap(_this.map_);
});
};
_this._initMap = function () {
// only initialize the map once
if (_this.initialized_) {
return;
}
_this.initialized_ = true;
var propsCenter = latLng2Obj(_this.props.center || _this.props.defaultCenter);
_this.geoService_.setView(propsCenter, _this.props.zoom || _this.props.defaultZoom, 0);
_this._onBoundsChanged(); // now we can calculate map bounds center etc...
var bootstrapURLKeys = _extends({}, _this.props.apiKey && { key: _this.props.apiKey }, _this.props.bootstrapURLKeys);
_this.props.googleMapLoader(bootstrapURLKeys, _this.props.heatmapLibrary).then(function (maps) {
if (!_this.mounted_) {
return;
}
var centerLatLng = _this.geoService_.getCenter();
var propsOptions = {
zoom: _this.props.zoom || _this.props.defaultZoom,
center: new maps.LatLng(centerLatLng.lat, centerLatLng.lng)
};
// Start Heatmap
if (_this.props.heatmap.positions) {
Object.assign(_this, {
heatmap: (0, _google_heatmap.generateHeatmap)(maps, _this.props.heatmap)
});
(0, _google_heatmap.optionsHeatmap)(_this.heatmap, _this.props.heatmap);
}
// End Heatmap
// prevent to exapose full api
// next props must be exposed (console.log(Object.keys(pick(maps, isPlainObject))))
// "Animation", "ControlPosition", "MapTypeControlStyle", "MapTypeId",
// "NavigationControlStyle", "ScaleControlStyle", "StrokePosition",
// "SymbolPath", "ZoomControlStyle",
// "event", "DirectionsStatus", "DirectionsTravelMode", "DirectionsUnitSystem",
// "DistanceMatrixStatus",
// "DistanceMatrixElementStatus", "ElevationStatus", "GeocoderLocationType",
// "GeocoderStatus", "KmlLayerStatus",
// "MaxZoomStatus", "StreetViewStatus", "TransitMode", "TransitRoutePreference",
// "TravelMode", "UnitSystem"
var mapPlainObjects = (0, _pick2.default)(maps, _isPlainObject2.default);
var options = typeof _this.props.options === 'function' ? _this.props.options(mapPlainObjects) : _this.props.options;
var defaultOptions = defaultOptions_(mapPlainObjects);
var draggableOptions = !(0, _isEmpty2.default)(_this.props.draggable) && {
draggable: _this.props.draggable
};
var minZoom = _this._computeMinZoom(options.minZoom);
_this.minZoom_ = minZoom;
var preMapOptions = _extends({}, defaultOptions, {
minZoom: minZoom
}, options, propsOptions);
_this.defaultDraggableOption_ = !(0, _isEmpty2.default)(preMapOptions.draggable) ? preMapOptions.draggable : _this.defaultDraggableOption_;
var mapOptions = _extends({}, preMapOptions, draggableOptions);
mapOptions.minZoom = _checkMinZoom(mapOptions.minZoom, minZoom);
var map = new maps.Map(_reactDom2.default.findDOMNode(_this.googleMapDom_), mapOptions);
_this.map_ = map;
_this.maps_ = maps;
_this._setLayers(_this.props.layerTypes);
// Parse `google.maps.version` to capture the major version number.
var versionMatch = maps.version.match(/^3\.(\d+)\./);
// The major version is the first (and only) captured group.
var mapsVersion = versionMatch && Number(versionMatch[1]);
// render in overlay
var this_ = _this;
var overlay = Object.assign(new maps.OverlayView(), {
onAdd: function onAdd() {
var K_MAX_WIDTH = typeof screen !== 'undefined' ? screen.width + 'px' : '2000px';
var K_MAX_HEIGHT = typeof screen !== 'undefined' ? screen.height + 'px' : '2000px';
var div = document.createElement('div');
this.div = div;
div.style.backgroundColor = 'transparent';
div.style.position = 'absolute';
div.style.left = '0px';
div.style.top = '0px';
div.style.width = K_MAX_WIDTH; // prevents some chrome draw defects
div.style.height = K_MAX_HEIGHT;
var panes = this.getPanes();
panes.overlayMouseTarget.appendChild(div);
this_.geoService_.setMapCanvasProjection(maps, overlay.getProjection());
_reactDom2.default.unstable_renderSubtreeIntoContainer(this_, _react2.default.createElement(_google_map_markers2.default, {
experimental: this_.props.experimental,
onChildClick: this_._onChildClick,
onChildMouseDown: this_._onChildMouseDown,
onChildMouseEnter: this_._onChildMouseEnter,
onChildMouseLeave: this_._onChildMouseLeave,
geoService: this_.geoService_,
projectFromLeftTop: true,
distanceToMouse: this_.props.distanceToMouse,
getHoverDistance: this_._getHoverDistance,
dispatcher: this_.markersDispatcher_
}), div,
// remove prerendered markers
function () {
return this_.setState({ overlayCreated: true });
});
},
onRemove: function onRemove() {
if (this.div) {
_reactDom2.default.unmountComponentAtNode(this.div);
}
},
draw: function draw() {
var div = overlay.div;
var overlayProjection = overlay.getProjection();
var ptx = overlayProjection.fromLatLngToDivPixel(overlayProjection.fromContainerPixelToLatLng({ x: 0, y: 0 }));
// need round for safari still can't find what need for firefox
var ptxRounded = (0, _detect2.default)().isSafari ? { x: Math.round(ptx.x), y: Math.round(ptx.y) } : { x: ptx.x, y: ptx.y };
this_.updateCounter_++;
this_._onBoundsChanged(map, maps, !this_.props.debounced);
if (!this_.googleApiLoadedCalled_) {
this_._onGoogleApiLoaded({ map: map, maps: maps });
this_.googleApiLoadedCalled_ = true;
}
div.style.left = ptxRounded.x + 'px';
div.style.top = ptxRounded.y + 'px';
if (this_.markersDispatcher_) {
this_.markersDispatcher_.emit('kON_CHANGE');
}
}
});
_this.overlay_ = overlay;
overlay.setMap(map);
if (_this.props.heatmap.positions) {
_this.heatmap.setMap(map);
}
maps.event.addListener(map, 'zoom_changed', function () {
// recalc position at zoom start
if (this_.geoService_.getZoom() !== map.getZoom()) {
if (!this_.zoomAnimationInProgress_) {
this_.zoomAnimationInProgress_ = true;
this_._onZoomAnimationStart();
}
// If draw() is not called each frame during a zoom animation,
// simulate it.
if (mapsVersion < DRAW_CALLED_DURING_ANIMATION_VERSION) {
var TIMEOUT_ZOOM = 300;
if (new Date().getTime() - _this.zoomControlClickTime_ < TIMEOUT_ZOOM) {
// there is strange Google Map Api behavior in chrome when zoom animation of map
// is started only on second raf call, if was click on zoom control
// or +- keys pressed, so i wait for two rafs before change state
// this does not fully prevent animation jump
// but reduce it's occurence probability
(0, _raf2.default)(function () {
return (0, _raf2.default)(function () {
this_.updateCounter_++;
this_._onBoundsChanged(map, maps);
});
});
} else {
this_.updateCounter_++;
this_._onBoundsChanged(map, maps);
}
}
}
});
maps.event.addListener(map, 'idle', function () {
if (_this.resetSizeOnIdle_) {
_this._setViewSize();
var currMinZoom = _this._computeMinZoom(_this.props.options.minZoom);
if (currMinZoom !== _this.minZoom_) {
_this.minZoom_ = currMinZoom;
map.setOptions({ minZoom: currMinZoom });
}
_this.resetSizeOnIdle_ = false;
}
if (this_.zoomAnimationInProgress_) {
this_.zoomAnimationInProgress_ = false;
this_._onZoomAnimationEnd();
}
this_.updateCounter_++;
this_._onBoundsChanged(map, maps);
if (_this.mouse_) {
var latLng = _this.geoService_.unproject(_this.mouse_, true);
_this.mouse_.lat = latLng.lat;
_this.mouse_.lng = latLng.lng;
}
_this._onChildMouseMove();
this_.dragTime_ = 0;
var div = overlay.div;
var overlayProjection = overlay.getProjection();
if (div && overlayProjection) {
var ptx = overlayProjection.fromLatLngToDivPixel(overlayProjection.fromContainerPixelToL