mirror of
https://github.com/google-map-react/google-map-react.git
synced 2025-12-08 18:26:32 +00:00
googleMapLoader as static, mouse calc fixes on Move
This commit is contained in:
parent
068923b175
commit
add0b54875
@ -67,7 +67,6 @@ const latLng2Obj = (latLng) => isPlainObject(latLng)
|
||||
: {lat: latLng[0], lng: latLng[1]};
|
||||
|
||||
export default class GoogleMap extends Component {
|
||||
|
||||
static propTypes = {
|
||||
apiKey: PropTypes.string,
|
||||
bootstrapURLKeys: PropTypes.any,
|
||||
@ -124,6 +123,8 @@ export default class GoogleMap extends Component {
|
||||
yesIWantToUseGoogleMapApiInternals: false,
|
||||
};
|
||||
|
||||
static googleMapLoader = googleMapLoader; // eslint-disable-line
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.mounted_ = false;
|
||||
@ -522,6 +523,14 @@ export default class GoogleMap extends Component {
|
||||
this_.updateCounter_++;
|
||||
this_._onBoundsChanged(map, maps);
|
||||
|
||||
if (this.mouse_) {
|
||||
const latLng = this.geoService_.unproject(this.mouse_, true);
|
||||
this.mouse_.lat = latLng.lat;
|
||||
this.mouse_.lng = latLng.lng;
|
||||
}
|
||||
|
||||
this._onChildMouseMove();
|
||||
|
||||
this_.dragTime_ = 0;
|
||||
div.style.left = `${ptxRounded.x}px`;
|
||||
div.style.top = `${ptxRounded.y}px`;
|
||||
@ -676,6 +685,7 @@ export default class GoogleMap extends Component {
|
||||
this.props.onClick &&
|
||||
!this.childMouseDownArgs_ &&
|
||||
((new Date()).getTime() - this.childMouseUpTime_) > K_IDLE_TIMEOUT &&
|
||||
this.dragTime_ === 0 &&
|
||||
this.props.onClick(...args)
|
||||
|
||||
_onMapClick = (event) => {
|
||||
|
||||
@ -3,7 +3,12 @@ import reduce from 'lodash/collection/reduce';
|
||||
|
||||
let $script_ = null;
|
||||
|
||||
let _loadPromise;
|
||||
let loadPromise_;
|
||||
|
||||
let resolveCustomPromise_;
|
||||
const _customPromise = new Promise(resolve => {
|
||||
resolveCustomPromise_ = resolve;
|
||||
});
|
||||
|
||||
// TODO add libraries language and other map options
|
||||
export default function googleMapLoader(bootstrapURLKeys) {
|
||||
@ -11,11 +16,17 @@ export default function googleMapLoader(bootstrapURLKeys) {
|
||||
$script_ = require('scriptjs');
|
||||
}
|
||||
|
||||
if (_loadPromise) {
|
||||
return _loadPromise;
|
||||
// call from outside google-map-react
|
||||
// will be as soon as loadPromise_ resolved
|
||||
if (!bootstrapURLKeys) {
|
||||
return _customPromise;
|
||||
}
|
||||
|
||||
_loadPromise = new Promise((resolve, reject) => {
|
||||
if (loadPromise_) {
|
||||
return loadPromise_;
|
||||
}
|
||||
|
||||
loadPromise_ = new Promise((resolve, reject) => {
|
||||
if (typeof window === 'undefined') {
|
||||
reject(new Error('google map cannot be loaded outside browser env'));
|
||||
return;
|
||||
@ -58,5 +69,7 @@ export default function googleMapLoader(bootstrapURLKeys) {
|
||||
);
|
||||
});
|
||||
|
||||
return _loadPromise;
|
||||
resolveCustomPromise_(loadPromise_);
|
||||
|
||||
return loadPromise_;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user