diff --git a/packages/map/legacy/README.md b/packages/map/legacy/README.md deleted file mode 100644 index 26b480e6f5..0000000000 --- a/packages/map/legacy/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## Map - -Map fork from [mapbox-gl-js@1.x](https://github.com/mapbox/mapbox-gl-js/tree/release-v1.13.3), keep event loop, responds user interaction and updates the internal state of the map (current viewport, camera angle, etc.) diff --git a/packages/map/legacy/css/l7.css b/packages/map/legacy/css/l7.css deleted file mode 100644 index 4a6d99c397..0000000000 --- a/packages/map/legacy/css/l7.css +++ /dev/null @@ -1,163 +0,0 @@ -.l7-map { - font: - 12px/20px 'Helvetica Neue', - Arial, - Helvetica, - sans-serif; - overflow: hidden; - position: relative; - -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -} - -.l7-canvas { - position: absolute; - left: 0; - top: 0; -} - -.l7-map:-webkit-full-screen { - width: 100%; - height: 100%; -} - -.l7-canary { - background-color: salmon; -} - -.l7-canvas-container.l7-interactive, -.l7-ctrl-group button.l7-ctrl-compass { - cursor: grab; - user-select: none; -} - -.l7-canvas-container.l7-interactive.l7-track-pointer { - cursor: pointer; -} - -.l7-canvas-container.l7-interactive:active, -.l7-ctrl-group button.l7-ctrl-compass:active { - cursor: grabbing; -} - -.l7-canvas-container.l7-touch-zoom-rotate, -.l7-canvas-container.l7-touch-zoom-rotate .l7-canvas { - touch-action: pan-x pan-y; -} - -.l7-canvas-container.l7-touch-drag-pan, -.l7-canvas-container.l7-touch-drag-pan .l7-canvas { - touch-action: pinch-zoom; -} - -.l7-canvas-container.l7-touch-zoom-rotate.l7-touch-drag-pan, -.l7-canvas-container.l7-touch-zoom-rotate.l7-touch-drag-pan .l7-canvas { - touch-action: none; -} - -.l7-canvas-container.l7-touch-drag-pan.l7-cooperative-gestures, -.l7-canvas-container.l7-touch-drag-pan.l7-cooperative-gestures .l7-canvas { - touch-action: pan-x pan-y; -} - -.l7-cooperative-gesture-screen { - background: rgba(0 0 0 / 40%); - position: absolute; - inset: 0; - display: flex; - justify-content: center; - align-items: center; - color: white; - padding: 1rem; - font-size: 1.4em; - line-height: 1.2; - opacity: 0; - pointer-events: none; - transition: opacity 1s ease 1s; - z-index: 99999; -} - -.l7-cooperative-gesture-screen.l7-show { - opacity: 1; - transition: opacity 0.05s; -} - -.l7-cooperative-gesture-screen .l7-mobile-message { - display: none; -} - -@media (hover: none), (width <= 480px) { - .l7-cooperative-gesture-screen .l7-desktop-message { - display: none; - } - - .l7-cooperative-gesture-screen .l7-mobile-message { - display: block; - } -} - -.l7-ctrl-top-left, -.l7-ctrl-top-right, -.l7-ctrl-bottom-left, -.l7-ctrl-bottom-right { - position: absolute; - pointer-events: none; - z-index: 2; -} -.l7-ctrl-top-left { - top: 0; - left: 0; -} -.l7-ctrl-top-right { - top: 0; - right: 0; -} -.l7-ctrl-bottom-left { - bottom: 0; - left: 0; -} -.l7-ctrl-bottom-right { - right: 0; - bottom: 0; -} - -.l7-ctrl { - clear: both; - pointer-events: auto; - - /* workaround for a Safari bug https://github.com/mapbox/mapbox-gl-js/issues/8185 */ - transform: translate(0, 0); -} -.l7-ctrl-top-left .l7-ctrl { - margin: 10px 0 0 10px; - float: left; -} -.l7-ctrl-top-right .l7-ctrl { - margin: 10px 10px 0 0; - float: right; -} -.l7-ctrl-bottom-left .l7-ctrl { - margin: 0 0 10px 10px; - float: left; -} -.l7-ctrl-bottom-right .l7-ctrl { - margin: 0 10px 10px 0; - float: right; -} - -.l7-crosshair, -.l7-crosshair .l7-interactive, -.l7-crosshair .l7-interactive:active { - cursor: crosshair; -} - -.l7-boxzoom { - position: absolute; - top: 0; - left: 0; - width: 0; - height: 0; - background: #fff; - border: 2px dotted #202020; - opacity: 0.5; - z-index: 10; -} diff --git a/packages/map/legacy/handler/handler_inertia.ts b/packages/map/legacy/handler/handler_inertia.ts deleted file mode 100644 index 89cb25fd72..0000000000 --- a/packages/map/legacy/handler/handler_inertia.ts +++ /dev/null @@ -1,168 +0,0 @@ -import Point from '@mapbox/point-geometry'; -import type { DragPanOptions } from './handler/shim/drag_pan'; -import type { Map } from './map'; -import { browser } from './util/browser'; -import { bezier, clamp, extend } from './util/util'; - -const defaultInertiaOptions = { - linearity: 0.3, - easing: bezier(0, 0, 0.3, 1), -}; - -const defaultPanInertiaOptions = extend( - { - deceleration: 2500, - maxSpeed: 1400, - }, - defaultInertiaOptions, -); - -const defaultZoomInertiaOptions = extend( - { - deceleration: 20, - maxSpeed: 1400, - }, - defaultInertiaOptions, -); - -const defaultBearingInertiaOptions = extend( - { - deceleration: 1000, - maxSpeed: 360, - }, - defaultInertiaOptions, -); - -const defaultPitchInertiaOptions = extend( - { - deceleration: 1000, - maxSpeed: 90, - }, - defaultInertiaOptions, -); - -export type InertiaOptions = { - linearity: number; - easing: (t: number) => number; - deceleration: number; - maxSpeed: number; -}; - -export class HandlerInertia { - _map: Map; - _inertiaBuffer: Array<{ - time: number; - settings: any; - }>; - - constructor(map: Map) { - this._map = map; - this.clear(); - } - - clear() { - this._inertiaBuffer = []; - } - - record(settings: any) { - this._drainInertiaBuffer(); - this._inertiaBuffer.push({ time: browser.now(), settings }); - } - - _drainInertiaBuffer() { - const inertia = this._inertiaBuffer, - now = browser.now(), - cutoff = 160; //msec - - while (inertia.length > 0 && now - inertia[0].time > cutoff) inertia.shift(); - } - - _onMoveEnd(panInertiaOptions?: DragPanOptions | boolean) { - this._drainInertiaBuffer(); - if (this._inertiaBuffer.length < 2) { - return; - } - - const deltas = { - zoom: 0, - bearing: 0, - pitch: 0, - pan: new Point(0, 0), - pinchAround: undefined, - around: undefined, - }; - - for (const { settings } of this._inertiaBuffer) { - deltas.zoom += settings.zoomDelta || 0; - deltas.bearing += settings.bearingDelta || 0; - deltas.pitch += settings.pitchDelta || 0; - if (settings.panDelta) deltas.pan._add(settings.panDelta); - if (settings.around) deltas.around = settings.around; - if (settings.pinchAround) deltas.pinchAround = settings.pinchAround; - } - - const lastEntry = this._inertiaBuffer[this._inertiaBuffer.length - 1]; - const duration = lastEntry.time - this._inertiaBuffer[0].time; - - const easeOptions = {} as any; - - if (deltas.pan.mag()) { - const result = calculateEasing( - deltas.pan.mag(), - duration, - extend({}, defaultPanInertiaOptions, panInertiaOptions || {}), - ); - easeOptions.offset = deltas.pan.mult(result.amount / deltas.pan.mag()); - easeOptions.center = this._map.transform.center; - extendDuration(easeOptions, result); - } - - if (deltas.zoom) { - const result = calculateEasing(deltas.zoom, duration, defaultZoomInertiaOptions); - easeOptions.zoom = this._map.transform.zoom + result.amount; - extendDuration(easeOptions, result); - } - - if (deltas.bearing) { - const result = calculateEasing(deltas.bearing, duration, defaultBearingInertiaOptions); - easeOptions.bearing = this._map.transform.bearing + clamp(result.amount, -179, 179); - extendDuration(easeOptions, result); - } - - if (deltas.pitch) { - const result = calculateEasing(deltas.pitch, duration, defaultPitchInertiaOptions); - easeOptions.pitch = this._map.transform.pitch + result.amount; - extendDuration(easeOptions, result); - } - - if (easeOptions.zoom || easeOptions.bearing) { - const last = deltas.pinchAround === undefined ? deltas.around : deltas.pinchAround; - easeOptions.around = last ? this._map.unproject(last) : this._map.getCenter(); - } - - this.clear(); - return extend(easeOptions, { - noMoveStart: true, - }); - } -} - -// Unfortunately zoom, bearing, etc can't have different durations and easings so -// we need to choose one. We use the longest duration and it's corresponding easing. -function extendDuration(easeOptions, result) { - if (!easeOptions.duration || easeOptions.duration < result.duration) { - easeOptions.duration = result.duration; - easeOptions.easing = result.easing; - } -} - -function calculateEasing(amount, inertiaDuration: number, inertiaOptions) { - const { maxSpeed, linearity, deceleration } = inertiaOptions; - const speed = clamp((amount * linearity) / (inertiaDuration / 1000), -maxSpeed, maxSpeed); - const duration = Math.abs(speed) / (deceleration * linearity); - return { - easing: inertiaOptions.easing, - duration: duration * 1000, - amount: speed * (duration / 2), - }; -}