Skip to content

Some updates #2182

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

Merged
merged 2 commits into from
Jan 5, 2024
Merged
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
10 changes: 5 additions & 5 deletions src/core/util/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,14 +526,14 @@ export function isMoveEvent(type) {
return type && (type === 'mousemove' || type === 'touchmove');
}

export const MOUSEMOVE_EVENT_TIMETHRESHOLD = 48;
export const MOUSEMOVE_THROTTLE_TIME = 48;

export function mousemoveEventTimeThresholdJudge(target, mousemoveTimeThreshold) {
export function isMousemoveEventBlocked(target, mousemoveThrottleTime) {
const currentTime = now();
const TIME = mousemoveTimeThreshold || MOUSEMOVE_EVENT_TIMETHRESHOLD;
const TIME = mousemoveThrottleTime || MOUSEMOVE_THROTTLE_TIME;
if (target._mousemoveTime && currentTime - target._mousemoveTime < TIME) {
return false;
return true;
}
target._mousemoveTime = currentTime;
return true;
return false;
}
6 changes: 2 additions & 4 deletions src/layer/OverlayLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ class OverlayLayer extends Layer {
for (let i = 0, l = geometries.length; i < l; i++) {
let geo = geometries[i];
if (!(geo && (GeoJSON._isGeoJSON(geo) || isGeometry(geo)))) {
console.error(geo, 'is not Invalid geometry to add to layer(' + this.getId() + ') at index:' + i);
continue;
throw new Error('Invalid geometry to add to layer(' + this.getId() + ') at index:' + i);
}
if (geo.getLayer && geo.getLayer() === this) {
continue;
Expand All @@ -265,8 +264,7 @@ class OverlayLayer extends Layer {
}
// geojson to Geometry may be null
if (!geo) {
console.error(geo, 'is not Invalid geometry to add to layer(' + this.getId() + ') at index:' + i);
continue;
throw new Error('Invalid geometry to add to layer(' + this.getId() + ') at index:' + i);
}
if (!Array.isArray(geo)) {
this._add(geo, extent, i);
Expand Down
4 changes: 2 additions & 2 deletions src/map/Map.DomEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
preventDefault,
getEventContainerPoint,
isMoveEvent,
mousemoveEventTimeThresholdJudge
isMousemoveEventBlocked
} from '../core/util/dom';
import Map from './Map';

Expand Down Expand Up @@ -223,7 +223,7 @@ Map.include(/** @lends Map.prototype */ {
}
const clickTimeThreshold = this.options['clickTimeThreshold'];
const type = e.type;
if (isMoveEvent(type) && !Browser.isTest && !mousemoveEventTimeThresholdJudge(this, this.options['mousemoveTimeThreshold'])) {
if (isMoveEvent(type) && !Browser.isTest && isMousemoveEventBlocked(this, this.options['mousemoveThrottleTime'])) {
return;
}
const isMouseDown = type === 'mousedown' || (type === 'touchstart' && (!e.touches || e.touches.length === 1));
Expand Down
6 changes: 3 additions & 3 deletions src/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Coordinate from '../geo/Coordinate';
import Layer from '../layer/Layer';
import Renderable from '../renderer/Renderable';
import SpatialReference from './spatial-reference/SpatialReference';
import { computeDomPosition, MOUSEMOVE_EVENT_TIMETHRESHOLD } from '../core/util/dom';
import { computeDomPosition, MOUSEMOVE_THROTTLE_TIME } from '../core/util/dom';
import EPSG9807 from '../geo/projection/Projection.EPSG9807.js';

const TEMP_COORD = new Coordinate(0, 0);
Expand Down Expand Up @@ -89,7 +89,7 @@ const REDRAW_OPTIONS_PROPERTIES = ['centerCross', 'fog', 'fogColor', 'debugSky']
* @property {Boolean} [options.cameraInfiniteFar=false] - Increase camera far plane to infinite. Enable this option may reduce map's performance.
* @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 {Number} [options.mousemoveTimeThreshold=48] - mousemove event interval time(ms)
* @property {Number} [options.mousemoveThrottleTime=48] - mousemove event interval time(ms)
* @memberOf Map
* @instance
*/
Expand Down Expand Up @@ -151,7 +151,7 @@ const options = {
'supportPluginEvent': true,

'switchDragButton': false,
'mousemoveTimeThreshold': MOUSEMOVE_EVENT_TIMETHRESHOLD
'mousemoveThrottleTime': MOUSEMOVE_THROTTLE_TIME
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/map/handler/Map.GeometryEvents.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { now } from '../../core/util';
import { on, off, getEventContainerPoint, preventDefault, stopPropagation, isMoveEvent, mousemoveEventTimeThresholdJudge } from '../../core/util/dom';
import { on, off, getEventContainerPoint, preventDefault, stopPropagation, isMoveEvent, isMousemoveEventBlocked } from '../../core/util/dom';
import Handler from '../../handler/Handler';
import Geometry from '../../geometry/Geometry';
import Map from '../Map';
Expand Down Expand Up @@ -205,7 +205,7 @@ class MapGeometryEventsHandler extends Handler {
}
let oneMoreEvent = null;
const eventType = type || domEvent.type;
if (isMoveEvent(eventType) && !Browser.isTest && !mousemoveEventTimeThresholdJudge(this, map.options['mousemoveTimeThreshold'])) {
if (isMoveEvent(eventType) && !Browser.isTest && isMousemoveEventBlocked(this, map.options['mousemoveThrottleTime'])) {
stopPropagation(domEvent);
return;
}
Expand Down
4 changes: 1 addition & 3 deletions src/ui/UIMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,7 @@ class UIMarker extends Handlerable(UIComponent) {

onAdd() {
if (this._owner && !this._owner.isMap) {
console.error('UIMarker Can only be added to the map,but owner is:', this._owner);
delete this._owner;
return this;
throw new Error('UIMarker Can only be added to the map, but owner is:', this._owner.getJSONType());
}
this.show();
return this;
Expand Down
27 changes: 21 additions & 6 deletions test/ui/UIMarkerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,33 @@ describe('UI.UIMarker', function () {
dy: -5
});
//layer add uimarker
layer.addGeometry(marker);
try {
layer.addGeometry(marker);
} catch (err) {
expect(!!err).to.be.ok();
}
expect(layer.getGeometries().length).to.be.equal(0);
//add Invalid geometry
layer.addGeometry({ type: 'hello' });
try {
layer.addGeometry({ type: 'hello' });
} catch (err) {
expect(!!err).to.be.ok();
}

expect(layer.getGeometries().length).to.be.equal(0);
//uimarker add to layer
marker.addTo(layer);
expect(marker.getOwner()).to.be.equal(undefined);
try {
marker.addTo(layer);
} catch (err) {
expect(!!err).to.be.ok();
}
//uimarker add Geometry
const point = new maptalks.Marker(map.getCenter());
marker.addTo(point);
expect(marker.getOwner()).to.be.equal(undefined);
try {
marker.addTo(point);
} catch (err) {
expect(!!err).to.be.ok();
}
done();
});
});