{
return this.props.hoverDistance;
}
_onDrag = (...args) => this.props.onDrag &&
this.props.onDrag(...args);
_onZoomAnimationStart = (...args) => this.props.onZoomAnimationStart &&
this.props.onZoomAnimationStart(...args)
_onZoomAnimationEnd = (...args) => this.props.onZoomAnimationEnd &&
this.props.onZoomAnimationEnd(...args)
_onChildClick = (...args) => {
if (this.props.onChildClick) {
return this.props.onChildClick(...args);
}
}
_onChildMouseDown = (hoverKey, childProps) => {
if (this.props.onChildMouseDown) {
this.childMouseDownArgs_ = [hoverKey, childProps];
this.props.onChildMouseDown(hoverKey, childProps, {...this.mouse_});
}
}
// this method works only if this.props.onChildMouseDown was called
_onChildMouseUp = () => {
if (this.childMouseDownArgs_) {
if (this.props.onChildMouseUp) {
this.props.onChildMouseUp(...this.childMouseDownArgs_, {...this.mouse_});
}
this.childMouseDownArgs_ = null;
this.childMouseUpTime_ = (new Date()).getTime();
}
}
// this method works only if this.props.onChildMouseDown was called
_onChildMouseMove = () => {
if (this.childMouseDownArgs_) {
if (this.props.onChildMouseMove) {
this.props.onChildMouseMove(...this.childMouseDownArgs_, {...this.mouse_});
}
}
}
_onChildMouseEnter = (...args) => {
if (this.props.onChildMouseEnter) {
return this.props.onChildMouseEnter(...args);
}
}
_onChildMouseLeave = (...args) => {
if (this.props.onChildMouseLeave) {
return this.props.onChildMouseLeave(...args);
}
}
_setViewSize = () => {
if (!this.mounted_) return;
const mapDom = ReactDOM.findDOMNode(this.refs.google_map_dom);
this.geoService_.setViewSize(mapDom.clientWidth, mapDom.clientHeight);
this._onBoundsChanged();
}
_onWindowResize = () => {
this.resetSizeOnIdle_ = true;
}
_onMapMouseMove = (e) => {
if (!this.mouseInMap_) return;
const currTime = (new Date()).getTime();
const K_RECALC_CLIENT_RECT_MS = 50;
if (currTime - this.mouseMoveTime_ > K_RECALC_CLIENT_RECT_MS) {
this.boundingRect_ = e.currentTarget.getBoundingClientRect();
}
this.mouseMoveTime_ = currTime;
const mousePosX = e.clientX - this.boundingRect_.left;
const mousePosY = e.clientY - this.boundingRect_.top;
if (!this.mouse_) {
this.mouse_ = {x: 0, y: 0, lat: 0, lng: 0};
}
this.mouse_.x = mousePosX;
this.mouse_.y = mousePosY;
const latLng = this.geoService_.unproject(this.mouse_, true);
this.mouse_.lat = latLng.lat;
this.mouse_.lng = latLng.lng;
this._onChildMouseMove();
if (currTime - this.dragTime_ < K_IDLE_TIMEOUT) {
this.fireMouseEventOnIdle_ = true;
} else {
this.markersDispatcher_.emit('kON_MOUSE_POSITION_CHANGE');
this.fireMouseEventOnIdle_ = false;
}
}
// K_IDLE_CLICK_TIMEOUT - looks like 300 is enough
_onClick = (...args) =>
this.props.onClick &&
!this.childMouseDownArgs_ &&
((new Date()).getTime() - this.childMouseUpTime_) > K_IDLE_CLICK_TIMEOUT &&
this.dragTime_ === 0 &&
this.props.onClick(...args)
_onMapClick = (event) => {
if (this.markersDispatcher_) {
const currTime = (new Date()).getTime();
if (currTime - this.dragTime_ > K_IDLE_TIMEOUT) {
if (this.mouse_) {
this._onClick({
...this.mouse_,
event,
});
}
this.markersDispatcher_.emit('kON_CLICK', event);
}
}
}
// gmap can't prevent map drag if mousedown event already occured
// the only workaround I find is prevent mousedown native browser event
_onMapMouseDownNative = (event) => {
if (!this.mouseInMap_) return;
this._onMapMouseDown(event);
if (this.props.draggable === false) {
event.preventDefault();
event.stopPropagation();
}
}
_onMapMouseDown = (event) => {
if (this.markersDispatcher_) {
const currTime = (new Date()).getTime();
if (currTime - this.dragTime_ > K_IDLE_TIMEOUT) {
this.markersDispatcher_.emit('kON_MDOWN', event);
}
}
}
_onMapMouseDownCapture = () => {
if (detectBrowser().isChrome) {
// to fix strange zoom in chrome
if (!this.mouse_) {
this.zoomControlClickTime_ = (new Date()).getTime();
}
}
}
_onKeyDownCapture = () => {
if (detectBrowser().isChrome) {
this.zoomControlClickTime_ = (new Date()).getTime();
}
}
_isCenterDefined = (center) => center && (
(isPlainObject(center) && isNumber(center.lat) && isNumber(center.lng)) ||
(center.length === 2 && isNumber(center[0]) && isNumber(center[1]))
)
_onBoundsChanged = (map, maps, callExtBoundsChange) => {
if (map) {
const gmC = map.getCenter();
this.geoService_.setView([gmC.lat(), gmC.lng()], map.getZoom(), 0);
}
if ((this.props.onChange || this.props.onBoundsChange) && this.geoService_.canProject()) {
const zoom = this.geoService_.getZoom();
const bounds = this.geoService_.getBounds();
const centerLatLng = this.geoService_.getCenter();
if (!isArraysEqualEps(bounds, this.prevBounds_, kEPS)) {
if (callExtBoundsChange !== false) {
const marginBounds = this.geoService_.getBounds(this.props.margin);
if (this.props.onBoundsChange) {
this.props.onBoundsChange(
this.centerIsObject_
? {...centerLatLng}
: [centerLatLng.lat, centerLatLng.lng],
zoom,
bounds,
marginBounds
);
}
if (this.props.onChange) {
this.props.onChange({
center: {...centerLatLng},
zoom,
bounds: {
nw: {
lat: bounds[0],
lng: bounds[1],
},
se: {
lat: bounds[2],
lng: bounds[3],
},
},
marginBounds: {
nw: {
lat: marginBounds[0],
lng: marginBounds[1],
},
se: {
lat: marginBounds[2],
lng: marginBounds[3],
},
},
size: this.geoService_.hasSize()
? {
width: this.geoService_.getWidth(),
height: this.geoService_.getHeight(),
}
: {
width: 0,
height: 0,
},
});
}
this.prevBounds_ = bounds;
}
}
// uncomment for strange bugs
if (process.env.NODE_ENV !== 'production') { // compare with google calculations
if (map) {
const locBounds = map.getBounds();
const ne = locBounds.getNorthEast();
const sw = locBounds.getSouthWest();
const gmC = map.getCenter();
// compare with google map
if (!isArraysEqualEps(
[centerLatLng.lat, centerLatLng.lng],
[gmC.lat(), gmC.lng()], kEPS
)) {
console.info('GoogleMap center not eq:', // eslint-disable-line no-console
[centerLatLng.lat, centerLatLng.lng], [gmC.lat(), gmC.lng()]);
}
if (!isArraysEqualEps(bounds, [ne.lat(), sw.lng(), sw.lat(), ne.lng()], kEPS)) {
// this is normal if this message occured on resize
console.info('GoogleMap bounds not eq:', '\n', // eslint-disable-line no-console
bounds, '\n', [ne.lat(), sw.lng(), sw.lat(), ne.lng()]);
}
}
}
}
}
render() {
const mapMarkerPrerender = !this.state.overlayCreated ? (
) : null;
return (
{/* render markers before map load done */}
{mapMarkerPrerender}
);
}
}