Skip to content

map support options.mousemoveThrottleEnable #2573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions packages/maptalks/src/map/Map.DomEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Map.include(/** @lends Map.prototype */ {
}
const clickTimeThreshold = this.options['clickTimeThreshold'];
const type = e.type;
if (isMoveEvent(type) && !GlobalConfig.isTest && isMousemoveEventBlocked(this, this.options['mousemoveThrottleTime'])) {
if (isMoveEvent(type) && !GlobalConfig.isTest && this.options['mousemoveThrottleEnable'] && isMousemoveEventBlocked(this, this.options['mousemoveThrottleTime'])) {
return;
}
const isMouseDown = type === 'mousedown' || (type === 'touchstart' && (!(e as TouchEvent).touches || (e as TouchEvent).touches.length === 1));
Expand Down Expand Up @@ -471,16 +471,24 @@ Map.include(/** @lends Map.prototype */ {
return;
}
this._wrapTerrainData(eventParam);

const mousemoveHandler = () => {
if (eventParam.domEvent && eventParam.domEvent._cancelBubble) {
// Always trigger _moumove _touchmove event
// for hit test etc
this._fireEvent('_' + type, eventParam);
return;
}
this._fireEvent(type, eventParam);
};
if (isMoveEvent(type)) {
this.getRenderer().callInNextFrame(() => {
if (eventParam.domEvent && eventParam.domEvent._cancelBubble) {
// Always trigger _moumove _touchmove event
// for hit test etc
this._fireEvent('_' + type, eventParam);
return;
}
this._fireEvent(type, eventParam);
});
if (!this.options['mousemoveThrottleEnable']) {
mousemoveHandler();
} else {
this.getRenderer().callInNextFrame(() => {
mousemoveHandler();
});
}
} else {
this._fireEvent(type, eventParam);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/maptalks/src/map/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const REDRAW_OPTIONS_PROPERTIES = ['centerCross', 'fog', 'fogColor', 'debugSky']
* @property {Number} [options.heightFactor=1] - the factor for height/altitude calculation,This affects the height calculation of all layers(vectortilelayer/gllayer/threelayer/3dtilelayer)
* @property {Boolean} [options.stopRenderOnOffscreen=true] - whether to stop map rendering when container is offscreen
* @property {Boolean} [options.originLatitudeForAltitude=40] - default latitude for map.altitudeToPoint method
* @property {Boolean} [options.mousemoveThrottleEnable=true] - enable map mousemove event throttling
* @property {Number} [options.mousemoveThrottleTime=48] - mousemove event interval time(ms)
* @property {Number} [options.maxFPS=0] - 0 means no frame is locked, otherwise the frame is locked
* @property {Number} [options.cameraFarUndergroundInMeter=2000] - camera far distance from underground in meter
Expand Down Expand Up @@ -161,6 +162,7 @@ const options: MapOptionsType = {

'switchDragButton': false,
'mousemoveThrottleTime': MOUSEMOVE_THROTTLE_TIME,
'mousemoveThrottleEnable': true,
'maxFPS': 0,
'debug': false,
'cameraFarUndergroundInMeter': 2000,
Expand Down Expand Up @@ -2840,6 +2842,7 @@ export type MapOptionsType = {
supportPluginEvent?: boolean;
switchDragButton?: boolean;
mousemoveThrottleTime?: number;
mousemoveThrottleEnable?: boolean;
maxFPS?: number;
debug?: boolean;
spatialReference?: SpatialReferenceType,
Expand Down
2 changes: 1 addition & 1 deletion packages/maptalks/src/map/handler/Map.GeometryEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class MapGeometryEventsHandler extends Handler {
}
let oneMoreEvent = null;
const eventType = type || domEvent.type;
if (isMoveEvent(eventType) && !GlobalConfig.isTest && isMousemoveEventBlocked(this, map.options['mousemoveThrottleTime'])) {
if (isMoveEvent(eventType) && !GlobalConfig.isTest && map.options['mousemoveThrottleEnable'] && isMousemoveEventBlocked(this, map.options['mousemoveThrottleTime'])) {
stopPropagation(domEvent);
return;
}
Expand Down