From 660484182175140a2978f0077a87a868a86d617a Mon Sep 17 00:00:00 2001 From: yunji Date: Tue, 4 Jun 2024 21:30:10 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=BB=98=E8=AE=A4=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=20MapNext=20=E8=87=B3=20maplibre-gl-js@4.3.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/map/README.md | 33 +++- .../map-next/ui => __tests__}/camera.test.ts | 26 +-- .../geo/edge_insets.test.ts | 2 +- .../geo/lng_lat_bounds.test.ts | 4 +- .../geo/mercator_coordinate.test.ts | 4 +- .../geo/transform.test.ts | 6 +- .../ui => __tests__}/handler/box_zoom.test.ts | 8 +- .../handler/dblclick_zoom.test.ts | 8 +- .../ui => __tests__}/handler/drag_pan.test.ts | 10 +- .../handler/drag_rotate.test.ts | 12 +- .../ui => __tests__}/handler/keyboard.test.ts | 10 +- .../handler/map_event.test.ts | 10 +- .../handler/mouse_handler_interface.test.ts | 2 +- .../handler/mouse_rotate.test.ts | 12 +- ...inger_touch_drag_handler_interface.test.ts | 2 +- .../map/__tests__/handler/scroll_zoom.spec.ts | 82 -------- .../handler/scroll_zoom.test.ts | 10 +- .../handler/tap_drag_zoom.test.ts | 8 +- .../handler/two_fingers_touch.test.ts | 12 +- packages/map/__tests__/hash.spec.ts | 38 ---- .../util/test => __tests__/libs}/fixed.ts | 0 .../libs}/simulate_interaction.ts | 0 .../util/test => __tests__/libs}/util.ts | 4 +- packages/map/__tests__/map.init.spec.ts | 24 --- packages/map/__tests__/map.spec.ts | 183 ------------------ .../map_tests/map_animation.test.ts | 4 +- .../map_tests/map_basic.test.ts | 18 +- .../map_tests/map_bounds.test.ts | 6 +- .../map_tests/map_disable_handlers.test.ts | 2 +- .../map_tests/map_events.test.ts | 6 +- .../map_tests/map_is_moving.test.ts | 10 +- .../map_tests/map_is_rotating.test.ts | 10 +- .../map_tests/map_is_zooming.test.ts | 10 +- .../map_tests/map_pitch.test.ts | 2 +- .../map_request_render_frame.test.ts | 2 +- .../map_tests/map_resize.test.ts | 2 +- .../map_tests/map_world_copies.test.ts | 2 +- .../map_tests/map_zoom.test.ts | 2 +- .../util/browser.test.ts | 2 +- .../util/evented.test.ts | 2 +- .../util/task_queue.test.ts | 2 +- packages/map/src/index.ts | 11 +- packages/map/src/map-next/README.md | 32 --- packages/map/src/map-next/{ui => }/camera.ts | 22 +-- packages/map/src/{ => map-next}/css/l7.css | 48 ++++- packages/map/src/map-next/{ui => }/events.ts | 8 +- packages/map/src/map-next/geo/transform.ts | 2 +- .../src/map-next/{ui => }/handler/box_zoom.ts | 10 +- .../map-next/{ui => }/handler/click_zoom.ts | 0 .../{ui => }/handler/cooperative_gestures.ts | 20 +- .../map-next/{ui => }/handler/drag_handler.ts | 2 +- .../handler/drag_move_state_manager.ts | 2 +- .../map-next/{ui => }/handler/handler_util.ts | 0 .../src/map-next/{ui => }/handler/keyboard.ts | 0 .../map-next/{ui => }/handler/map_event.ts | 0 .../src/map-next/{ui => }/handler/mouse.ts | 2 +- .../{ui => }/handler/one_finger_touch_drag.ts | 0 .../map-next/{ui => }/handler/scroll_zoom.ts | 8 +- .../{ui => }/handler/shim/dblclick_zoom.ts | 2 +- .../{ui => }/handler/shim/drag_pan.ts | 6 +- .../{ui => }/handler/shim/drag_rotate.ts | 0 .../handler/shim/two_fingers_touch.ts | 4 +- .../{ui => }/handler/tap_drag_zoom.ts | 0 .../{ui => }/handler/tap_recognizer.ts | 0 .../src/map-next/{ui => }/handler/tap_zoom.ts | 0 .../map-next/{ui => }/handler/touch_pan.ts | 0 .../{ui => }/handler/transform-provider.ts | 4 +- .../{ui => }/handler/two_fingers_touch.ts | 2 +- .../src/map-next/{ui => }/handler_inertia.ts | 4 +- .../src/map-next/{ui => }/handler_manager.ts | 8 +- packages/map/src/map-next/index.ts | 4 +- packages/map/src/map-next/{ui => }/map.ts | 36 ++-- packages/map/src/map/README.md | 3 + packages/map/src/{ => map}/camera.ts | 0 packages/map/src/map/css/l7.css | 163 ++++++++++++++++ packages/map/src/{ => map}/earthmap.ts | 4 + packages/map/src/{ => map}/geo/edge_insets.ts | 0 packages/map/src/{ => map}/geo/lng_lat.ts | 0 .../map/src/{ => map}/geo/lng_lat_bounds.ts | 0 packages/map/src/{ => map}/geo/mercator.ts | 4 +- packages/map/src/{ => map}/geo/point.ts | 0 packages/map/src/{ => map}/geo/simple.ts | 4 +- packages/map/src/{ => map}/geo/transform.ts | 2 +- .../map/src/{ => map}/handler/IHandler.ts | 0 .../{ => map}/handler/blockable_map_event.ts | 0 .../map/src/{ => map}/handler/box_zoom.ts | 0 .../map/src/{ => map}/handler/click_zoom.ts | 0 .../map/src/{ => map}/handler/events/event.ts | 0 .../map/src/{ => map}/handler/events/index.ts | 0 .../handler/events/map_mouse_event.ts | 0 .../handler/events/map_touch_event.ts | 0 .../handler/events/map_wheel_event.ts | 0 .../{ => map}/handler/events/render_event.ts | 0 .../src/{ => map}/handler/handler_inertia.ts | 0 .../src/{ => map}/handler/handler_manager.ts | 0 .../map/src/{ => map}/handler/handler_util.ts | 0 .../map/src/{ => map}/handler/keyboard.ts | 0 .../map/src/{ => map}/handler/map_event.ts | 0 .../map/src/{ => map}/handler/mouse/index.ts | 0 .../{ => map}/handler/mouse/mouse_handler.ts | 0 .../handler/mouse/mousepan_handler.ts | 0 .../handler/mouse/mousepitch_hander.ts | 0 .../handler/mouse/mouserotate_hander.ts | 0 .../map/src/{ => map}/handler/mouse/util.ts | 0 .../map/src/{ => map}/handler/scroll_zoom.ts | 0 .../{ => map}/handler/shim/dblclick_zoom.ts | 0 .../src/{ => map}/handler/shim/drag_pan.ts | 4 +- .../src/{ => map}/handler/shim/drag_rotate.ts | 0 .../handler/shim/touch_zoom_rotate.ts | 0 .../handler/tap/single_tap_recognizer.ts | 0 .../{ => map}/handler/tap/tap_drag_zoom.ts | 0 .../{ => map}/handler/tap/tap_recognizer.ts | 0 .../map/src/{ => map}/handler/tap/tap_zoom.ts | 0 .../map/src/{ => map}/handler/touch/index.ts | 0 .../src/{ => map}/handler/touch/touch_pan.ts | 0 .../{ => map}/handler/touch/touch_pitch.ts | 0 .../{ => map}/handler/touch/touch_rotate.ts | 0 .../src/{ => map}/handler/touch/touch_zoom.ts | 0 .../src/{ => map}/handler/touch/two_touch.ts | 0 packages/map/src/{ => map}/hash.ts | 0 packages/map/src/{ => map}/interface.ts | 4 + packages/map/src/{ => map}/map.ts | 6 +- packages/map/src/{ => map}/util.ts | 0 packages/map/src/{ => map}/utils/Aabb.ts | 0 packages/map/src/{ => map}/utils/dom.ts | 0 .../map/src/{ => map}/utils/performance.ts | 0 .../map/src/{ => map}/utils/primitives.ts | 0 .../map/src/{ => map}/utils/task_queue.ts | 0 packages/maps/src/bmap/index.ts | 3 +- packages/maps/src/earth/index.ts | 4 +- packages/maps/src/earth/map.ts | 5 +- packages/maps/src/map/index.ts | 4 +- packages/maps/src/map/map.ts | 14 +- packages/maps/src/utils/BaseMapService.ts | 12 +- 134 files changed, 466 insertions(+), 599 deletions(-) rename packages/map/{src/map-next/ui => __tests__}/camera.test.ts (99%) rename packages/map/{src/map-next => __tests__}/geo/edge_insets.test.ts (97%) rename packages/map/{src/map-next => __tests__}/geo/lng_lat_bounds.test.ts (98%) rename packages/map/{src/map-next => __tests__}/geo/mercator_coordinate.test.ts (87%) rename packages/map/{src/map-next => __tests__}/geo/transform.test.ts (98%) rename packages/map/{src/map-next/ui => __tests__}/handler/box_zoom.test.ts (96%) rename packages/map/{src/map-next/ui => __tests__}/handler/dblclick_zoom.test.ts (95%) rename packages/map/{src/map-next/ui => __tests__}/handler/drag_pan.test.ts (98%) rename packages/map/{src/map-next/ui => __tests__}/handler/drag_rotate.test.ts (98%) rename packages/map/{src/map-next/ui => __tests__}/handler/keyboard.test.ts (97%) rename packages/map/{src/map-next/ui => __tests__}/handler/map_event.test.ts (96%) rename packages/map/{src/map-next/ui => __tests__}/handler/mouse_handler_interface.test.ts (99%) rename packages/map/{src/map-next/ui => __tests__}/handler/mouse_rotate.test.ts (86%) rename packages/map/{src/map-next/ui => __tests__}/handler/one_finger_touch_drag_handler_interface.test.ts (98%) delete mode 100644 packages/map/__tests__/handler/scroll_zoom.spec.ts rename packages/map/{src/map-next/ui => __tests__}/handler/scroll_zoom.test.ts (97%) rename packages/map/{src/map-next/ui => __tests__}/handler/tap_drag_zoom.test.ts (93%) rename packages/map/{src/map-next/ui => __tests__}/handler/two_fingers_touch.test.ts (96%) delete mode 100644 packages/map/__tests__/hash.spec.ts rename packages/map/{src/map-next/util/test => __tests__/libs}/fixed.ts (100%) rename packages/map/{src/map-next/util/test => __tests__/libs}/simulate_interaction.ts (100%) rename packages/map/{src/map-next/util/test => __tests__/libs}/util.ts (94%) delete mode 100644 packages/map/__tests__/map.init.spec.ts delete mode 100644 packages/map/__tests__/map.spec.ts rename packages/map/{src/map-next/ui => __tests__}/map_tests/map_animation.test.ts (92%) rename packages/map/{src/map-next/ui => __tests__}/map_tests/map_basic.test.ts (82%) rename packages/map/{src/map-next/ui => __tests__}/map_tests/map_bounds.test.ts (95%) rename packages/map/{src/map-next/ui => __tests__}/map_tests/map_disable_handlers.test.ts (93%) rename packages/map/{src/map-next/ui => __tests__}/map_tests/map_events.test.ts (97%) rename packages/map/{src/map-next/ui => __tests__}/map_tests/map_is_moving.test.ts (93%) rename packages/map/{src/map-next/ui => __tests__}/map_tests/map_is_rotating.test.ts (83%) rename packages/map/{src/map-next/ui => __tests__}/map_tests/map_is_zooming.test.ts (87%) rename packages/map/{src/map-next/ui => __tests__}/map_tests/map_pitch.test.ts (97%) rename packages/map/{src/map-next/ui => __tests__}/map_tests/map_request_render_frame.test.ts (95%) rename packages/map/{src/map-next/ui => __tests__}/map_tests/map_resize.test.ts (97%) rename packages/map/{src/map-next/ui => __tests__}/map_tests/map_world_copies.test.ts (98%) rename packages/map/{src/map-next/ui => __tests__}/map_tests/map_zoom.test.ts (96%) rename packages/map/{src/map-next => __tests__}/util/browser.test.ts (88%) rename packages/map/{src/map-next => __tests__}/util/evented.test.ts (99%) rename packages/map/{src/map-next => __tests__}/util/task_queue.test.ts (97%) delete mode 100644 packages/map/src/map-next/README.md rename packages/map/src/map-next/{ui => }/camera.ts (98%) rename packages/map/src/{ => map-next}/css/l7.css (71%) rename packages/map/src/map-next/{ui => }/events.ts (98%) rename packages/map/src/map-next/{ui => }/handler/box_zoom.ts (93%) rename packages/map/src/map-next/{ui => }/handler/click_zoom.ts (100%) rename packages/map/src/map-next/{ui => }/handler/cooperative_gestures.ts (83%) rename packages/map/src/map-next/{ui => }/handler/drag_handler.ts (99%) rename packages/map/src/map-next/{ui => }/handler/drag_move_state_manager.ts (98%) rename packages/map/src/map-next/{ui => }/handler/handler_util.ts (100%) rename packages/map/src/map-next/{ui => }/handler/keyboard.ts (100%) rename packages/map/src/map-next/{ui => }/handler/map_event.ts (100%) rename packages/map/src/map-next/{ui => }/handler/mouse.ts (98%) rename packages/map/src/map-next/{ui => }/handler/one_finger_touch_drag.ts (100%) rename packages/map/src/map-next/{ui => }/handler/scroll_zoom.ts (98%) rename packages/map/src/map-next/{ui => }/handler/shim/dblclick_zoom.ts (96%) rename packages/map/src/map-next/{ui => }/handler/shim/drag_pan.ts (93%) rename packages/map/src/map-next/{ui => }/handler/shim/drag_rotate.ts (100%) rename packages/map/src/map-next/{ui => }/handler/shim/two_fingers_touch.ts (96%) rename packages/map/src/map-next/{ui => }/handler/tap_drag_zoom.ts (100%) rename packages/map/src/map-next/{ui => }/handler/tap_recognizer.ts (100%) rename packages/map/src/map-next/{ui => }/handler/tap_zoom.ts (100%) rename packages/map/src/map-next/{ui => }/handler/touch_pan.ts (100%) rename packages/map/src/map-next/{ui => }/handler/transform-provider.ts (90%) rename packages/map/src/map-next/{ui => }/handler/two_fingers_touch.ts (99%) rename packages/map/src/map-next/{ui => }/handler_inertia.ts (97%) rename packages/map/src/map-next/{ui => }/handler_manager.ts (99%) rename packages/map/src/map-next/{ui => }/map.ts (97%) create mode 100644 packages/map/src/map/README.md rename packages/map/src/{ => map}/camera.ts (100%) create mode 100644 packages/map/src/map/css/l7.css rename packages/map/src/{ => map}/earthmap.ts (99%) rename packages/map/src/{ => map}/geo/edge_insets.ts (100%) rename packages/map/src/{ => map}/geo/lng_lat.ts (100%) rename packages/map/src/{ => map}/geo/lng_lat_bounds.ts (100%) rename packages/map/src/{ => map}/geo/mercator.ts (95%) rename packages/map/src/{ => map}/geo/point.ts (100%) rename packages/map/src/{ => map}/geo/simple.ts (95%) rename packages/map/src/{ => map}/geo/transform.ts (99%) rename packages/map/src/{ => map}/handler/IHandler.ts (100%) rename packages/map/src/{ => map}/handler/blockable_map_event.ts (100%) rename packages/map/src/{ => map}/handler/box_zoom.ts (100%) rename packages/map/src/{ => map}/handler/click_zoom.ts (100%) rename packages/map/src/{ => map}/handler/events/event.ts (100%) rename packages/map/src/{ => map}/handler/events/index.ts (100%) rename packages/map/src/{ => map}/handler/events/map_mouse_event.ts (100%) rename packages/map/src/{ => map}/handler/events/map_touch_event.ts (100%) rename packages/map/src/{ => map}/handler/events/map_wheel_event.ts (100%) rename packages/map/src/{ => map}/handler/events/render_event.ts (100%) rename packages/map/src/{ => map}/handler/handler_inertia.ts (100%) rename packages/map/src/{ => map}/handler/handler_manager.ts (100%) rename packages/map/src/{ => map}/handler/handler_util.ts (100%) rename packages/map/src/{ => map}/handler/keyboard.ts (100%) rename packages/map/src/{ => map}/handler/map_event.ts (100%) rename packages/map/src/{ => map}/handler/mouse/index.ts (100%) rename packages/map/src/{ => map}/handler/mouse/mouse_handler.ts (100%) rename packages/map/src/{ => map}/handler/mouse/mousepan_handler.ts (100%) rename packages/map/src/{ => map}/handler/mouse/mousepitch_hander.ts (100%) rename packages/map/src/{ => map}/handler/mouse/mouserotate_hander.ts (100%) rename packages/map/src/{ => map}/handler/mouse/util.ts (100%) rename packages/map/src/{ => map}/handler/scroll_zoom.ts (100%) rename packages/map/src/{ => map}/handler/shim/dblclick_zoom.ts (100%) rename packages/map/src/{ => map}/handler/shim/drag_pan.ts (95%) rename packages/map/src/{ => map}/handler/shim/drag_rotate.ts (100%) rename packages/map/src/{ => map}/handler/shim/touch_zoom_rotate.ts (100%) rename packages/map/src/{ => map}/handler/tap/single_tap_recognizer.ts (100%) rename packages/map/src/{ => map}/handler/tap/tap_drag_zoom.ts (100%) rename packages/map/src/{ => map}/handler/tap/tap_recognizer.ts (100%) rename packages/map/src/{ => map}/handler/tap/tap_zoom.ts (100%) rename packages/map/src/{ => map}/handler/touch/index.ts (100%) rename packages/map/src/{ => map}/handler/touch/touch_pan.ts (100%) rename packages/map/src/{ => map}/handler/touch/touch_pitch.ts (100%) rename packages/map/src/{ => map}/handler/touch/touch_rotate.ts (100%) rename packages/map/src/{ => map}/handler/touch/touch_zoom.ts (100%) rename packages/map/src/{ => map}/handler/touch/two_touch.ts (100%) rename packages/map/src/{ => map}/hash.ts (100%) rename packages/map/src/{ => map}/interface.ts (94%) rename packages/map/src/{ => map}/map.ts (99%) rename packages/map/src/{ => map}/util.ts (100%) rename packages/map/src/{ => map}/utils/Aabb.ts (100%) rename packages/map/src/{ => map}/utils/dom.ts (100%) rename packages/map/src/{ => map}/utils/performance.ts (100%) rename packages/map/src/{ => map}/utils/primitives.ts (100%) rename packages/map/src/{ => map}/utils/task_queue.ts (100%) diff --git a/packages/map/README.md b/packages/map/README.md index 74ed6847c3d..0b384a5def6 100644 --- a/packages/map/README.md +++ b/packages/map/README.md @@ -1,11 +1,32 @@ -# `map` +## Map -> TODO: description +Map fork from [maplibre-gl-js@4.3.2](https://github.com/maplibre/maplibre-gl-js), keep event loop, responds user interaction and updates the internal state of the map (current viewport, camera angle, etc.) -## Usage +```mermaid +sequenceDiagram + actor user + participant DOM + participant handler_manager + participant handler + participant camera + participant transform + participant map -``` -const map = require('map'); + user->>camera: map#setCenter, map#panTo + camera->>transform: update + camera->>map: fire move event + map->>map: _render() -// TODO: DEMONSTRATE API + user->>DOM: resize, pan,
click, scroll,
... + DOM->>handler_manager: DOM events + handler_manager->>handler: forward event + handler-->>handler_manager: HandlerResult + handler_manager->>transform: update + handler_manager->>map: fire move event + map->>map: _render() ``` + +- [Transform](../src/geo/transform.ts) holds the current viewport details (pitch, zoom, bearing, bounds, etc.). Two places in the code update transform directly: + - [Camera](../src/ui/camera.ts) (parent class of [Map](../src/ui/map)) in response to explicit calls to [Camera#panTo](../src/ui/camera.ts#L207), [Camera#setCenter](../src/ui/camera.ts#L169) + - [HandlerManager](../src/ui/handler_manager.ts) in response to DOM events. It forwards those events to interaction processors that live in [src/ui/handler](../src/ui/handler), which accumulate a merged [HandlerResult](../src/ui/handler_manager.ts#L64) that kick off a render frame loop, decreasing the inertia and nudging map.transform by that amount on each frame from [HandlerManager#\_updateMapTransform()](../src/ui/handler_manager.ts#L413). That loop continues in the inertia decreases to 0. +- Both camera and handler_manager are responsible for firing `move`, `zoom`, `movestart`, `moveend`, ... events on the map after they update transform. Each of these events (along with style changes and data load events) triggers a call to [Map#\_render()](../src/ui/map.ts#L2480) which renders a single frame of the map. diff --git a/packages/map/src/map-next/ui/camera.test.ts b/packages/map/__tests__/camera.test.ts similarity index 99% rename from packages/map/src/map-next/ui/camera.test.ts rename to packages/map/__tests__/camera.test.ts index 3a7eea7dc51..5514d6f111d 100644 --- a/packages/map/src/map-next/ui/camera.test.ts +++ b/packages/map/__tests__/camera.test.ts @@ -1,16 +1,16 @@ -import { Transform } from '../geo/transform'; -import { browser } from '../util/browser'; -import type { TaskID } from '../util/task_queue'; -import { TaskQueue } from '../util/task_queue'; -import type { CameraOptions } from './camera'; -import { Camera } from './camera'; - -import { LngLat } from '../geo/lng_lat'; -import { LngLatBounds } from '../geo/lng_lat_bounds'; -import { mercatorZfromAltitude } from '../geo/mercator_coordinate'; -import type { Event } from '../util/evented'; -import { fixedLngLat, fixedNum } from '../util/test/fixed'; -import { setMatchMedia } from '../util/test/util'; +import type { CameraOptions } from '../src/map-next/camera'; +import { Camera } from '../src/map-next/camera'; +import { Transform } from '../src/map-next/geo/transform'; +import { browser } from '../src/map-next/util/browser'; +import type { TaskID } from '../src/map-next/util/task_queue'; +import { TaskQueue } from '../src/map-next/util/task_queue'; + +import { LngLat } from '../src/map-next/geo/lng_lat'; +import { LngLatBounds } from '../src/map-next/geo/lng_lat_bounds'; +import { mercatorZfromAltitude } from '../src/map-next/geo/mercator_coordinate'; +import type { Event } from '../src/map-next/util/evented'; +import { fixedLngLat, fixedNum } from './libs/fixed'; +import { setMatchMedia } from './libs/util'; beforeEach(() => { setMatchMedia(); diff --git a/packages/map/src/map-next/geo/edge_insets.test.ts b/packages/map/__tests__/geo/edge_insets.test.ts similarity index 97% rename from packages/map/src/map-next/geo/edge_insets.test.ts rename to packages/map/__tests__/geo/edge_insets.test.ts index 9ef7aed9eda..547c4bed008 100644 --- a/packages/map/src/map-next/geo/edge_insets.test.ts +++ b/packages/map/__tests__/geo/edge_insets.test.ts @@ -1,4 +1,4 @@ -import { EdgeInsets } from '../geo/edge_insets'; +import { EdgeInsets } from '../../src/map-next/geo/edge_insets'; describe('EdgeInsets', () => { describe('#constructor', () => { diff --git a/packages/map/src/map-next/geo/lng_lat_bounds.test.ts b/packages/map/__tests__/geo/lng_lat_bounds.test.ts similarity index 98% rename from packages/map/src/map-next/geo/lng_lat_bounds.test.ts rename to packages/map/__tests__/geo/lng_lat_bounds.test.ts index 7afa778fc9a..9aa852059f7 100644 --- a/packages/map/src/map-next/geo/lng_lat_bounds.test.ts +++ b/packages/map/__tests__/geo/lng_lat_bounds.test.ts @@ -1,5 +1,5 @@ -import { LngLat } from './lng_lat'; -import { LngLatBounds } from './lng_lat_bounds'; +import { LngLat } from '../../src/map-next/geo/lng_lat'; +import { LngLatBounds } from '../../src/map-next/geo/lng_lat_bounds'; describe('LngLatBounds', () => { test('#constructor', () => { diff --git a/packages/map/src/map-next/geo/mercator_coordinate.test.ts b/packages/map/__tests__/geo/mercator_coordinate.test.ts similarity index 87% rename from packages/map/src/map-next/geo/mercator_coordinate.test.ts rename to packages/map/__tests__/geo/mercator_coordinate.test.ts index 97ad342699a..e58d74ca4b6 100644 --- a/packages/map/src/map-next/geo/mercator_coordinate.test.ts +++ b/packages/map/__tests__/geo/mercator_coordinate.test.ts @@ -1,5 +1,5 @@ -import { LngLat } from './lng_lat'; -import { MercatorCoordinate, mercatorScale } from './mercator_coordinate'; +import { LngLat } from '../../src/map-next/geo/lng_lat'; +import { MercatorCoordinate, mercatorScale } from '../../src/map-next/geo/mercator_coordinate'; describe('LngLat', () => { test('#constructor', () => { diff --git a/packages/map/src/map-next/geo/transform.test.ts b/packages/map/__tests__/geo/transform.test.ts similarity index 98% rename from packages/map/src/map-next/geo/transform.test.ts rename to packages/map/__tests__/geo/transform.test.ts index dba14c25a43..e4693b03607 100644 --- a/packages/map/src/map-next/geo/transform.test.ts +++ b/packages/map/__tests__/geo/transform.test.ts @@ -1,7 +1,7 @@ import Point from '@mapbox/point-geometry'; -import { fixedCoord, fixedLngLat } from '../util/test/fixed'; -import { LngLat } from './lng_lat'; -import { MAX_VALID_LATITUDE, Transform } from './transform'; +import { LngLat } from '../../src/map-next/geo/lng_lat'; +import { MAX_VALID_LATITUDE, Transform } from '../../src/map-next/geo/transform'; +import { fixedCoord, fixedLngLat } from '../libs/fixed'; describe('transform', () => { test('creates a transform', () => { diff --git a/packages/map/src/map-next/ui/handler/box_zoom.test.ts b/packages/map/__tests__/handler/box_zoom.test.ts similarity index 96% rename from packages/map/src/map-next/ui/handler/box_zoom.test.ts rename to packages/map/__tests__/handler/box_zoom.test.ts index 3d78b176695..cea6cb61a62 100644 --- a/packages/map/src/map-next/ui/handler/box_zoom.test.ts +++ b/packages/map/__tests__/handler/box_zoom.test.ts @@ -1,7 +1,7 @@ -import { DOM } from '../../util/dom'; -import simulate from '../../util/test/simulate_interaction'; -import { beforeMapTest } from '../../util/test/util'; -import { Map } from '../map'; +import { Map } from '../../src/map-next/map'; +import { DOM } from '../../src/map-next/util/dom'; +import simulate from '../libs/simulate_interaction'; +import { beforeMapTest } from '../libs/util'; function createMap(clickTolerance) { return new Map({ container: DOM.create('div', '', window.document.body), clickTolerance }); diff --git a/packages/map/src/map-next/ui/handler/dblclick_zoom.test.ts b/packages/map/__tests__/handler/dblclick_zoom.test.ts similarity index 95% rename from packages/map/src/map-next/ui/handler/dblclick_zoom.test.ts rename to packages/map/__tests__/handler/dblclick_zoom.test.ts index 2aa2d2bc46f..faabb3e8d24 100644 --- a/packages/map/src/map-next/ui/handler/dblclick_zoom.test.ts +++ b/packages/map/__tests__/handler/dblclick_zoom.test.ts @@ -1,7 +1,7 @@ -import simulate from '../../util/test/simulate_interaction'; -import { beforeMapTest } from '../../util/test/util'; -import type { MapOptions } from '../map'; -import { Map } from '../map'; +import type { MapOptions } from '../../src/map-next/map'; +import { Map } from '../../src/map-next/map'; +import simulate from '../libs/simulate_interaction'; +import { beforeMapTest } from '../libs/util'; function createMap() { return new Map({ container: window.document.createElement('div') } as any as MapOptions); diff --git a/packages/map/src/map-next/ui/handler/drag_pan.test.ts b/packages/map/__tests__/handler/drag_pan.test.ts similarity index 98% rename from packages/map/src/map-next/ui/handler/drag_pan.test.ts rename to packages/map/__tests__/handler/drag_pan.test.ts index d9a48e1eecb..c9c555d2d78 100644 --- a/packages/map/src/map-next/ui/handler/drag_pan.test.ts +++ b/packages/map/__tests__/handler/drag_pan.test.ts @@ -1,8 +1,8 @@ -import { DOM } from '../../util/dom'; -import simulate from '../../util/test/simulate_interaction'; -import { beforeMapTest } from '../../util/test/util'; -import type { MapOptions } from '../map'; -import { Map } from '../map'; +import type { MapOptions } from '../../src/map-next/map'; +import { Map } from '../../src/map-next/map'; +import { DOM } from '../../src/map-next/util/dom'; +import simulate from '../libs/simulate_interaction'; +import { beforeMapTest } from '../libs/util'; function createMap(clickTolerance?, dragPan?) { return new Map({ diff --git a/packages/map/src/map-next/ui/handler/drag_rotate.test.ts b/packages/map/__tests__/handler/drag_rotate.test.ts similarity index 98% rename from packages/map/src/map-next/ui/handler/drag_rotate.test.ts rename to packages/map/__tests__/handler/drag_rotate.test.ts index 59bd1c805c1..338ef45b07e 100644 --- a/packages/map/src/map-next/ui/handler/drag_rotate.test.ts +++ b/packages/map/__tests__/handler/drag_rotate.test.ts @@ -1,10 +1,10 @@ -import { browser } from '../../util/browser'; -import { DOM } from '../../util/dom'; -import simulate from '../../util/test/simulate_interaction'; -import { extend } from '../../util/util'; -import { Map } from '../map'; +import { Map } from '../../src/map-next/map'; +import { browser } from '../../src/map-next/util/browser'; +import { DOM } from '../../src/map-next/util/dom'; +import { extend } from '../../src/map-next/util/util'; +import simulate from '../libs/simulate_interaction'; -import { beforeMapTest } from '../../util/test/util'; +import { beforeMapTest } from '../libs/util'; function createMap(options?) { return new Map(extend({ container: DOM.create('div', '', window.document.body) }, options)); diff --git a/packages/map/src/map-next/ui/handler/keyboard.test.ts b/packages/map/__tests__/handler/keyboard.test.ts similarity index 97% rename from packages/map/src/map-next/ui/handler/keyboard.test.ts rename to packages/map/__tests__/handler/keyboard.test.ts index b522e05a78e..f8ff939faa9 100644 --- a/packages/map/src/map-next/ui/handler/keyboard.test.ts +++ b/packages/map/__tests__/handler/keyboard.test.ts @@ -1,8 +1,8 @@ -import { Map } from '../../ui/map'; -import { DOM } from '../../util/dom'; -import simulate from '../../util/test/simulate_interaction'; -import { beforeMapTest } from '../../util/test/util'; -import { extend } from '../../util/util'; +import { Map } from '../../src/map-next/map'; +import { DOM } from '../../src/map-next/util/dom'; +import { extend } from '../../src/map-next/util/util'; +import simulate from '../libs/simulate_interaction'; +import { beforeMapTest } from '../libs/util'; function createMap(options?) { return new Map( diff --git a/packages/map/src/map-next/ui/handler/map_event.test.ts b/packages/map/__tests__/handler/map_event.test.ts similarity index 96% rename from packages/map/src/map-next/ui/handler/map_event.test.ts rename to packages/map/__tests__/handler/map_event.test.ts index 97b944b3855..2122e7fb94c 100644 --- a/packages/map/src/map-next/ui/handler/map_event.test.ts +++ b/packages/map/__tests__/handler/map_event.test.ts @@ -1,8 +1,8 @@ -import { DOM } from '../../util/dom'; -import simulate from '../../util/test/simulate_interaction'; -import { beforeMapTest } from '../../util/test/util'; -import type { MapOptions } from '../map'; -import { Map } from '../map'; +import type { MapOptions } from '../../src/map-next/map'; +import { Map } from '../../src/map-next/map'; +import { DOM } from '../../src/map-next/util/dom'; +import simulate from '../libs/simulate_interaction'; +import { beforeMapTest } from '../libs/util'; function createMap() { return new Map({ diff --git a/packages/map/src/map-next/ui/handler/mouse_handler_interface.test.ts b/packages/map/__tests__/handler/mouse_handler_interface.test.ts similarity index 99% rename from packages/map/src/map-next/ui/handler/mouse_handler_interface.test.ts rename to packages/map/__tests__/handler/mouse_handler_interface.test.ts index afb9bfcbb36..44ace28da49 100644 --- a/packages/map/src/map-next/ui/handler/mouse_handler_interface.test.ts +++ b/packages/map/__tests__/handler/mouse_handler_interface.test.ts @@ -4,7 +4,7 @@ import { generateMousePanHandler, generateMousePitchHandler, generateMouseRotationHandler, -} from './mouse'; +} from '../../src/map-next/handler/mouse'; describe('mouse handler tests', () => { test('MouseRotateHandler', () => { diff --git a/packages/map/src/map-next/ui/handler/mouse_rotate.test.ts b/packages/map/__tests__/handler/mouse_rotate.test.ts similarity index 86% rename from packages/map/src/map-next/ui/handler/mouse_rotate.test.ts rename to packages/map/__tests__/handler/mouse_rotate.test.ts index 3a8776d1140..42a9858b5bc 100644 --- a/packages/map/src/map-next/ui/handler/mouse_rotate.test.ts +++ b/packages/map/__tests__/handler/mouse_rotate.test.ts @@ -1,9 +1,9 @@ -import { Map } from '../../ui/map'; -import { browser } from '../../util/browser'; -import { DOM } from '../../util/dom'; -import simulate from '../../util/test/simulate_interaction'; -import { beforeMapTest } from '../../util/test/util'; -import { extend } from '../../util/util'; +import { Map } from '../../src/map-next/map'; +import { browser } from '../../src/map-next/util/browser'; +import { DOM } from '../../src/map-next/util/dom'; +import { extend } from '../../src/map-next/util/util'; +import simulate from '../libs/simulate_interaction'; +import { beforeMapTest } from '../libs/util'; function createMap(options?) { return new Map(extend({ container: DOM.create('div', '', window.document.body) }, options)); diff --git a/packages/map/src/map-next/ui/handler/one_finger_touch_drag_handler_interface.test.ts b/packages/map/__tests__/handler/one_finger_touch_drag_handler_interface.test.ts similarity index 98% rename from packages/map/src/map-next/ui/handler/one_finger_touch_drag_handler_interface.test.ts rename to packages/map/__tests__/handler/one_finger_touch_drag_handler_interface.test.ts index 843e1bfef91..13d0c7beed7 100644 --- a/packages/map/src/map-next/ui/handler/one_finger_touch_drag_handler_interface.test.ts +++ b/packages/map/__tests__/handler/one_finger_touch_drag_handler_interface.test.ts @@ -3,7 +3,7 @@ import Point from '@mapbox/point-geometry'; import { generateOneFingerTouchPitchHandler, generateOneFingerTouchRotationHandler, -} from './one_finger_touch_drag'; +} from '../../src/map-next/handler/one_finger_touch_drag'; const testTouch = { identifier: 0 } as Touch; diff --git a/packages/map/__tests__/handler/scroll_zoom.spec.ts b/packages/map/__tests__/handler/scroll_zoom.spec.ts deleted file mode 100644 index da5779af1d9..00000000000 --- a/packages/map/__tests__/handler/scroll_zoom.spec.ts +++ /dev/null @@ -1,82 +0,0 @@ -import Point from '../../src/geo/point'; -import type HandlerManager from '../../src/handler/handler_manager'; -import ScrollZoomHandler from '../../src/handler/scroll_zoom'; -import { Map } from '../../src/map'; - -describe('Map', () => { - const el = document.createElement('div'); - el.id = 'test-div-id'; - // el.style.width = '500px'; - // el.style.height = '500px'; - el.style.background = '#aaa'; - let map: Map; - let handlerManager: HandlerManager; - let scrollZoomHandler: ScrollZoomHandler; - document.querySelector('body')?.appendChild(el); - beforeEach(() => { - map = new Map({ - container: el, - zoom: 10, - }); - handlerManager = map.handlers; - // @ts-ignore - scrollZoomHandler = handlerManager.handlersById['scrollZoom']; - }); - - // handlerManager isactive - it('handlerManager is active', () => { - expect(handlerManager.isActive()).toEqual(false); - }); - - it('scrollZoomHandler', () => { - expect(scrollZoomHandler).toBeInstanceOf(ScrollZoomHandler); - }); - it('boxZoomHandler box select', () => { - // @ts-ignore - const boxZoom = handlerManager.handlersById['boxZoom']; - boxZoom.disable(); - boxZoom.enable(); - - // 模拟鼠标按下事件 - let e = new MouseEvent('mousedown', { - shiftKey: true, - button: 0, - clientX: 100, - clientY: 100, - }); - // 创建一个 Point 对象 - const point1 = new Point(0, 0); - //@ts-ignore - boxZoom.mousedown(e, point1); - - // 模拟鼠标移动事件 - const point2 = new Point(200, 200); - e = new MouseEvent('mousemove', { clientX: 200, clientY: 200 }); - //@ts-ignore - boxZoom.mousemoveWindow(e, point2); - - // 模拟鼠标释放事件 - const point3 = new Point(200, 200); - e = new MouseEvent('mouseup', { clientX: 200, clientY: 200 }); - //@ts-ignore - boxZoom.mouseupWindow(e, point3); - expect(map.getZoom()).toEqual(10); - - // 验证结果 - // 这将取决于你的boxZoomHandler如何处理这些事件 - // 例如,你可能会检查地图的缩放级别或视口是否已经改变 - }); - // wheel - it('scrollZoomHandler wheel', () => { - const e = new WheelEvent('wheel', { deltaY: -500 }); - scrollZoomHandler.wheel(e); - scrollZoomHandler.renderFrame(); - expect(map.getZoom()).toEqual(10); - }); - - // disable - it('scrollZoomHandler disable', () => { - scrollZoomHandler.disable(); - expect(scrollZoomHandler.isEnabled()).toEqual(false); - }); -}); diff --git a/packages/map/src/map-next/ui/handler/scroll_zoom.test.ts b/packages/map/__tests__/handler/scroll_zoom.test.ts similarity index 97% rename from packages/map/src/map-next/ui/handler/scroll_zoom.test.ts rename to packages/map/__tests__/handler/scroll_zoom.test.ts index f5903014f72..dced2198d63 100644 --- a/packages/map/src/map-next/ui/handler/scroll_zoom.test.ts +++ b/packages/map/__tests__/handler/scroll_zoom.test.ts @@ -1,8 +1,8 @@ -import { Map } from '../../ui/map'; -import { browser } from '../../util/browser'; -import { DOM } from '../../util/dom'; -import simulate from '../../util/test/simulate_interaction'; -import { beforeMapTest, setPerformance } from '../../util/test/util'; +import { Map } from '../../src/map-next/map'; +import { browser } from '../../src/map-next/util/browser'; +import { DOM } from '../../src/map-next/util/dom'; +import simulate from '../libs/simulate_interaction'; +import { beforeMapTest, setPerformance } from '../libs/util'; function createMap() { return new Map({ diff --git a/packages/map/src/map-next/ui/handler/tap_drag_zoom.test.ts b/packages/map/__tests__/handler/tap_drag_zoom.test.ts similarity index 93% rename from packages/map/src/map-next/ui/handler/tap_drag_zoom.test.ts rename to packages/map/__tests__/handler/tap_drag_zoom.test.ts index 1b75c4ea3e2..58c565454c9 100644 --- a/packages/map/src/map-next/ui/handler/tap_drag_zoom.test.ts +++ b/packages/map/__tests__/handler/tap_drag_zoom.test.ts @@ -1,7 +1,7 @@ -import simulate from '../../util/test/simulate_interaction'; -import { beforeMapTest } from '../../util/test/util'; -import type { MapOptions } from '../map'; -import { Map } from '../map'; +import type { MapOptions } from '../../src/map-next/map'; +import { Map } from '../../src/map-next/map'; +import simulate from '../libs/simulate_interaction'; +import { beforeMapTest } from '../libs/util'; function createMap() { return new Map({ container: window.document.createElement('div') } as any as MapOptions); diff --git a/packages/map/src/map-next/ui/handler/two_fingers_touch.test.ts b/packages/map/__tests__/handler/two_fingers_touch.test.ts similarity index 96% rename from packages/map/src/map-next/ui/handler/two_fingers_touch.test.ts rename to packages/map/__tests__/handler/two_fingers_touch.test.ts index 0b361ea2142..41ec92b8005 100644 --- a/packages/map/src/map-next/ui/handler/two_fingers_touch.test.ts +++ b/packages/map/__tests__/handler/two_fingers_touch.test.ts @@ -1,8 +1,8 @@ -import { DOM } from '../../util/dom'; -import simulate from '../../util/test/simulate_interaction'; -import { beforeMapTest } from '../../util/test/util'; -import type { MapOptions } from '../map'; -import { Map } from '../map'; +import type { MapOptions } from '../../src/map-next/map'; +import { Map } from '../../src/map-next/map'; +import { DOM } from '../../src/map-next/util/dom'; +import simulate from '../libs/simulate_interaction'; +import { beforeMapTest } from '../libs/util'; function createMap() { return new Map({ container: DOM.create('div', '', window.document.body) } as any as MapOptions); @@ -220,7 +220,7 @@ describe('touch zoom rotate', () => { test('TwoFingersTouchZoomRotateHandler adds css class used for disabling default touch behavior in some browsers', () => { const map = createMap(); - const className = 'maplibregl-touch-zoom-rotate'; + const className = 'l7-touch-zoom-rotate'; expect(map.getCanvasContainer().classList.contains(className)).toBeTruthy(); map.touchZoomRotate.disable(); expect(map.getCanvasContainer().classList.contains(className)).toBeFalsy(); diff --git a/packages/map/__tests__/hash.spec.ts b/packages/map/__tests__/hash.spec.ts deleted file mode 100644 index 8ccbf01cee0..00000000000 --- a/packages/map/__tests__/hash.spec.ts +++ /dev/null @@ -1,38 +0,0 @@ -import Hash from '../src/hash'; -import { Map } from '../src/map'; -describe('Map', () => { - const el = document.createElement('div'); - el.id = 'test-div-id'; - // el.style.width = '500px'; - // el.style.height = '500px'; - el.style.background = '#aaa'; - let map: Map; - let hash: Hash; - document.querySelector('body')?.appendChild(el); - beforeEach(() => { - map = new Map({ - container: el, - }); - hash = new Hash('map'); - hash.addTo(map); - }); - it('hash update', () => { - map.setZoom(10); - map.setBearing(10); - map.setPitch(10); - map.setCenter([0, 0]); - expect(window.location.hash).toEqual('#map=10/0/0'); - }); - - it('hash remove', () => { - hash.remove(); - // @ts-ignore - expect(hash.map).toEqual(undefined); - }); - it('hash onHashChange', () => { - window.location.hash = '#map=11/10/10'; - hash.onHashChange(); - expect(map.getZoom()).toEqual(11); - expect(map.getCenter()).toEqual({ lng: 10, lat: 10 }); - }); -}); diff --git a/packages/map/src/map-next/util/test/fixed.ts b/packages/map/__tests__/libs/fixed.ts similarity index 100% rename from packages/map/src/map-next/util/test/fixed.ts rename to packages/map/__tests__/libs/fixed.ts diff --git a/packages/map/src/map-next/util/test/simulate_interaction.ts b/packages/map/__tests__/libs/simulate_interaction.ts similarity index 100% rename from packages/map/src/map-next/util/test/simulate_interaction.ts rename to packages/map/__tests__/libs/simulate_interaction.ts diff --git a/packages/map/src/map-next/util/test/util.ts b/packages/map/__tests__/libs/util.ts similarity index 94% rename from packages/map/src/map-next/util/test/util.ts rename to packages/map/__tests__/libs/util.ts index fc5d631578f..d647b4c3ee8 100644 --- a/packages/map/src/map-next/util/test/util.ts +++ b/packages/map/__tests__/libs/util.ts @@ -1,5 +1,5 @@ -import { Map } from '../../ui/map'; -import { extend } from '../../util/util'; +import { Map } from '../../src/map-next/map'; +import { extend } from '../../src/map-next/util/util'; export function createMap(options?, callback?) { const container = window.document.createElement('div'); diff --git a/packages/map/__tests__/map.init.spec.ts b/packages/map/__tests__/map.init.spec.ts deleted file mode 100644 index 0309e3ae752..00000000000 --- a/packages/map/__tests__/map.init.spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Map } from '../src/map'; -describe('Map', () => { - const el = document.createElement('div'); - el.id = 'test-div-id'; - // el.style.width = '500px'; - // el.style.height = '500px'; - el.style.background = '#aaa'; - let map: Map; - document.querySelector('body')?.appendChild(el); - beforeEach(() => { - map = new Map({ - container: el, - }); - }); - it('should resize correctly', () => { - // 创建Map的实例,将mock的Map传 - - // map.resize(); - map.setCenter([120.11114550000002, 30.27817071635984]); - map.setZoom(8.592359444611867); - - // 验证transform.resize方法是否被正确调用 - }); -}); diff --git a/packages/map/__tests__/map.spec.ts b/packages/map/__tests__/map.spec.ts deleted file mode 100644 index 0ae74eb8f3e..00000000000 --- a/packages/map/__tests__/map.spec.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { Map } from '../src/map'; -describe('Map', () => { - const el = document.createElement('div'); - el.id = 'test-div-id'; - // el.style.width = '500px'; - // el.style.height = '500px'; - el.style.background = '#aaa'; - let map: Map; - document.querySelector('body')?.appendChild(el); - beforeEach(() => { - map = new Map({ - container: el, - }); - }); - it('should resize correctly', () => { - // 创建Map的实例,将mock的Map传 - - // map.resize(); - map.setCenter([121.434765, 31.256735]); - map.setZoom(14.83); - - // 验证transform.resize方法是否被正确调用 - }); - it('Map set zoom', () => { - map.setZoom(5); - expect(map.getZoom()).toEqual(5); - }); - it('Map set center', () => { - map.setCenter([120, 30]); - expect(map.getCenter()).toEqual({ lat: 30, lng: 120 }); - }); - it('Map set pitch', () => { - map.setPitch(10); - expect(map.getPitch()).toEqual(10); - }); - it('Map set Bearing', () => { - map.setBearing(10); - expect(map.getBearing()).toEqual(10); - }); - it('Map panTo ', () => { - map.panTo([121, 31], { animate: false }); - expect(map.getCenter()).toEqual({ lat: 31, lng: 121 }); - }); - it('Map panBy', () => { - map.panBy([10, 10], { animate: false }); - expect(map.getCenter().lng).toBeCloseTo(7.03, 2); - }); - it('Map zoomTo', () => { - map.zoomTo(10, { animate: false }); - expect(map.getZoom()).toEqual(10); - }); - it('Map zoomIn', () => { - map.setZoom(9); - map.zoomIn({ animate: false }); - expect(map.getZoom()).toEqual(10); - }); - it('Map zoomOut', () => { - map.setZoom(10); - map.zoomOut({ animate: false }); - expect(map.getZoom()).toEqual(9); - }); - it('Map setMaxZoom', () => { - map.setMaxZoom(15); - expect(map.getMaxZoom()).toEqual(15); - }); - it('Map setMinZoom', () => { - map.setMinZoom(5); - expect(map.getMinZoom()).toEqual(5); - }); - it('Map setMaxPitch', () => { - map.setMaxPitch(60); - expect(map.getMaxPitch()).toEqual(60); - }); - it('Map setMinPitch', () => { - map.setMinPitch(5); - expect(map.getMinPitch()).toEqual(5); - }); - // setPadding - it('Map setPadding', () => { - map.setPadding({ - top: 10, - bottom: 10, - left: 10, - right: 10, - }); - expect(map.getPadding()).toEqual({ bottom: 10, left: 10, right: 10, top: 10 }); - }); - // rotateTo - it('Map rotateTo', () => { - map.rotateTo(90); - expect(map.getBearing()).toEqual(-0); - }); - // resetNorth - it('Map resetNorth', () => { - map.resetNorth(); - expect(map.getBearing()).toEqual(-0); - }); - // resetNorthPitch - it('Map resetNorthPitch', () => { - map.resetNorthPitch(); - expect(map.getPitch()).toEqual(0); - }); - // fitBounds - it('Map fitBounds', () => { - map.fitBounds( - [ - [120, 30], - [121, 31], - ], - { animate: false }, - ); - expect(map.getZoom()).toBeCloseTo(7.5, 1); - }); - // snapToNorth - it('Map snapToNorth', () => { - map.snapToNorth(); - expect(map.getBearing()).toEqual(-0); - }); - //jumpTo - it('Map jumpTo', () => { - map.jumpTo( - { - center: [120, 30], - zoom: 10, - bearing: 90, - pitch: 60, - }, - { - animate: false, - }, - ); - expect(map.getCenter()).toEqual({ lat: 30, lng: 120 }); - expect(map.getZoom()).toEqual(10); - expect(map.getBearing()).toEqual(90); - expect(map.getPitch()).toEqual(60); - }); - - // map getContainer - it('Map getContainer', () => { - expect(map.getContainer()).toEqual(el); - }); - // getcanvas - it('Map getCanvas', () => { - expect(map.getCanvas()).toBeUndefined(); - }); - // project - it('Map project', () => { - expect(map.project([120, 30]).x).toBeCloseTo(370.6, 0); - expect(map.project([120, 30]).y).toBeCloseTo(105.2, 1); - }); - // unproject - it('Map unproject', () => { - expect(map.unproject([100, 100]).lng).toBeCloseTo(-70.3, 1); - expect(map.unproject([100, 100]).lat).toBeCloseTo(33.1, 1); - }); - // getbounds - it('Map getBounds', () => { - expect(map.getBounds().toArray()).toEqual([ - [-140.6250000000022, -71.96538769913126], - [140.62499999999886, 71.96538769913161], - ]); - }); - // map remove - it('Map remove', () => { - map.remove(); - expect(map.getCanvasContainer()).toEqual(null); - }); - // getMaxBounds - it('Map getMaxBounds', () => { - expect(map.getMaxBounds()).toEqual(null); - }); - // // setMaxBounds - it('Map setMaxBounds', () => { - map.setMaxBounds([ - [120, 30], - [121, 31], - ]); - expect(map.getMaxBounds()?.toArray()).toEqual([ - [120, 30], - [121, 31], - ]); - }); -}); diff --git a/packages/map/src/map-next/ui/map_tests/map_animation.test.ts b/packages/map/__tests__/map_tests/map_animation.test.ts similarity index 92% rename from packages/map/src/map-next/ui/map_tests/map_animation.test.ts rename to packages/map/__tests__/map_tests/map_animation.test.ts index a8bcd7c18cb..7e05e46c825 100644 --- a/packages/map/src/map-next/ui/map_tests/map_animation.test.ts +++ b/packages/map/__tests__/map_tests/map_animation.test.ts @@ -1,5 +1,5 @@ -import simulate from '../../util/test/simulate_interaction'; -import { beforeMapTest, createMap } from '../../util/test/util'; +import simulate from '../libs/simulate_interaction'; +import { beforeMapTest, createMap } from '../libs/util'; beforeEach(() => { beforeMapTest(); diff --git a/packages/map/src/map-next/ui/map_tests/map_basic.test.ts b/packages/map/__tests__/map_tests/map_basic.test.ts similarity index 82% rename from packages/map/src/map-next/ui/map_tests/map_basic.test.ts rename to packages/map/__tests__/map_tests/map_basic.test.ts index fc119ca7c03..63f9ab390e7 100644 --- a/packages/map/src/map-next/ui/map_tests/map_basic.test.ts +++ b/packages/map/__tests__/map_tests/map_basic.test.ts @@ -1,7 +1,7 @@ -import { fixedLngLat } from '../../util/test/fixed'; -import { beforeMapTest, createMap } from '../../util/test/util'; -import type { MapOptions } from '../map'; -import { Map } from '../map'; +import type { MapOptions } from '../../src/map-next/map'; +import { Map } from '../../src/map-next/map'; +import { fixedLngLat } from '../libs/fixed'; +import { beforeMapTest, createMap } from '../libs/util'; beforeEach(() => { beforeMapTest(); @@ -58,24 +58,20 @@ describe('Map', () => { expect( map .getContainer() - .querySelector('.maplibregl-cooperative-gesture-screen') + .querySelector('.l7-cooperative-gesture-screen') .getAttribute('aria-hidden'), ).toBeTruthy(); }); test('cooperativeGesture container element is not available when cooperativeGestures not initialized', () => { const map = createMap({ cooperativeGestures: false }); - expect( - map.getContainer().querySelector('.maplibregl-cooperative-gesture-screen'), - ).toBeFalsy(); + expect(map.getContainer().querySelector('.l7-cooperative-gesture-screen')).toBeFalsy(); }); test('cooperativeGesture container element is not available when cooperativeGestures disabled', () => { const map = createMap({ cooperativeGestures: true }); map.cooperativeGestures.disable(); - expect( - map.getContainer().querySelector('.maplibregl-cooperative-gesture-screen'), - ).toBeFalsy(); + expect(map.getContainer().querySelector('.l7-cooperative-gesture-screen')).toBeFalsy(); }); }); }); diff --git a/packages/map/src/map-next/ui/map_tests/map_bounds.test.ts b/packages/map/__tests__/map_tests/map_bounds.test.ts similarity index 95% rename from packages/map/src/map-next/ui/map_tests/map_bounds.test.ts rename to packages/map/__tests__/map_tests/map_bounds.test.ts index c7fa8179255..3e713599bba 100644 --- a/packages/map/src/map-next/ui/map_tests/map_bounds.test.ts +++ b/packages/map/__tests__/map_tests/map_bounds.test.ts @@ -1,6 +1,6 @@ -import type { LngLatBoundsLike } from '../../geo/lng_lat_bounds'; -import { fixedLngLat, fixedNum } from '../../util/test/fixed'; -import { beforeMapTest, createMap } from '../../util/test/util'; +import type { LngLatBoundsLike } from '../../src/map-next/geo/lng_lat_bounds'; +import { fixedLngLat, fixedNum } from '../libs/fixed'; +import { beforeMapTest, createMap } from '../libs/util'; beforeEach(() => { beforeMapTest(); diff --git a/packages/map/src/map-next/ui/map_tests/map_disable_handlers.test.ts b/packages/map/__tests__/map_tests/map_disable_handlers.test.ts similarity index 93% rename from packages/map/src/map-next/ui/map_tests/map_disable_handlers.test.ts rename to packages/map/__tests__/map_tests/map_disable_handlers.test.ts index 00964bbaf4b..607c0e178d3 100644 --- a/packages/map/src/map-next/ui/map_tests/map_disable_handlers.test.ts +++ b/packages/map/__tests__/map_tests/map_disable_handlers.test.ts @@ -1,4 +1,4 @@ -import { beforeMapTest, createMap } from '../../util/test/util'; +import { beforeMapTest, createMap } from '../libs/util'; beforeEach(() => { beforeMapTest(); diff --git a/packages/map/src/map-next/ui/map_tests/map_events.test.ts b/packages/map/__tests__/map_tests/map_events.test.ts similarity index 97% rename from packages/map/src/map-next/ui/map_tests/map_events.test.ts rename to packages/map/__tests__/map_tests/map_events.test.ts index bc1d49538e8..fb8d73db4d8 100644 --- a/packages/map/src/map-next/ui/map_tests/map_events.test.ts +++ b/packages/map/__tests__/map_tests/map_events.test.ts @@ -1,6 +1,6 @@ -import { ErrorEvent, Event as EventedEvent } from '../../util/evented'; -import simulate from '../../util/test/simulate_interaction'; -import { beforeMapTest, createMap } from '../../util/test/util'; +import { ErrorEvent, Event as EventedEvent } from '../../src/map-next/util/evented'; +import simulate from '../libs/simulate_interaction'; +import { beforeMapTest, createMap } from '../libs/util'; function assertNotAny() {} diff --git a/packages/map/src/map-next/ui/map_tests/map_is_moving.test.ts b/packages/map/__tests__/map_tests/map_is_moving.test.ts similarity index 93% rename from packages/map/src/map-next/ui/map_tests/map_is_moving.test.ts rename to packages/map/__tests__/map_tests/map_is_moving.test.ts index 9e1a93456d2..eb12136f36f 100644 --- a/packages/map/src/map-next/ui/map_tests/map_is_moving.test.ts +++ b/packages/map/__tests__/map_tests/map_is_moving.test.ts @@ -1,9 +1,9 @@ -import { browser } from '../../util/browser'; -import { DOM } from '../../util/dom'; -import simulate from '../../util/test/simulate_interaction'; -import { Map } from '../map'; +import { Map } from '../../src/map-next/map'; +import { browser } from '../../src/map-next/util/browser'; +import { DOM } from '../../src/map-next/util/dom'; +import simulate from '../libs/simulate_interaction'; -import { beforeMapTest } from '../../util/test/util'; +import { beforeMapTest } from '../libs/util'; let map; diff --git a/packages/map/src/map-next/ui/map_tests/map_is_rotating.test.ts b/packages/map/__tests__/map_tests/map_is_rotating.test.ts similarity index 83% rename from packages/map/src/map-next/ui/map_tests/map_is_rotating.test.ts rename to packages/map/__tests__/map_tests/map_is_rotating.test.ts index ca2f656878b..8f728616083 100644 --- a/packages/map/src/map-next/ui/map_tests/map_is_rotating.test.ts +++ b/packages/map/__tests__/map_tests/map_is_rotating.test.ts @@ -1,8 +1,8 @@ -import { browser } from '../../util/browser'; -import { DOM } from '../../util/dom'; -import simulate from '../../util/test/simulate_interaction'; -import { beforeMapTest } from '../../util/test/util'; -import { Map } from '../map'; +import { Map } from '../../src/map-next/map'; +import { browser } from '../../src/map-next/util/browser'; +import { DOM } from '../../src/map-next/util/dom'; +import simulate from '../libs/simulate_interaction'; +import { beforeMapTest } from '../libs/util'; let map; diff --git a/packages/map/src/map-next/ui/map_tests/map_is_zooming.test.ts b/packages/map/__tests__/map_tests/map_is_zooming.test.ts similarity index 87% rename from packages/map/src/map-next/ui/map_tests/map_is_zooming.test.ts rename to packages/map/__tests__/map_tests/map_is_zooming.test.ts index 08b1d7b41ea..a3c95498a55 100644 --- a/packages/map/src/map-next/ui/map_tests/map_is_zooming.test.ts +++ b/packages/map/__tests__/map_tests/map_is_zooming.test.ts @@ -1,8 +1,8 @@ -import { browser } from '../../util/browser'; -import { DOM } from '../../util/dom'; -import simulate from '../../util/test/simulate_interaction'; -import { beforeMapTest } from '../../util/test/util'; -import { Map } from '../map'; +import { Map } from '../../src/map-next/map'; +import { browser } from '../../src/map-next/util/browser'; +import { DOM } from '../../src/map-next/util/dom'; +import simulate from '../libs/simulate_interaction'; +import { beforeMapTest } from '../libs/util'; function createMap() { return new Map({ container: DOM.create('div', '', window.document.body) }); diff --git a/packages/map/src/map-next/ui/map_tests/map_pitch.test.ts b/packages/map/__tests__/map_tests/map_pitch.test.ts similarity index 97% rename from packages/map/src/map-next/ui/map_tests/map_pitch.test.ts rename to packages/map/__tests__/map_tests/map_pitch.test.ts index f843754d8a3..e02f79d8595 100644 --- a/packages/map/src/map-next/ui/map_tests/map_pitch.test.ts +++ b/packages/map/__tests__/map_tests/map_pitch.test.ts @@ -1,4 +1,4 @@ -import { beforeMapTest, createMap } from '../../util/test/util'; +import { beforeMapTest, createMap } from '../libs/util'; beforeEach(() => { beforeMapTest(); diff --git a/packages/map/src/map-next/ui/map_tests/map_request_render_frame.test.ts b/packages/map/__tests__/map_tests/map_request_render_frame.test.ts similarity index 95% rename from packages/map/src/map-next/ui/map_tests/map_request_render_frame.test.ts rename to packages/map/__tests__/map_tests/map_request_render_frame.test.ts index 26870134af4..65af29024de 100644 --- a/packages/map/src/map-next/ui/map_tests/map_request_render_frame.test.ts +++ b/packages/map/__tests__/map_tests/map_request_render_frame.test.ts @@ -1,4 +1,4 @@ -import { beforeMapTest, createMap } from '../../util/test/util'; +import { beforeMapTest, createMap } from '../libs/util'; beforeEach(() => { beforeMapTest(); diff --git a/packages/map/src/map-next/ui/map_tests/map_resize.test.ts b/packages/map/__tests__/map_tests/map_resize.test.ts similarity index 97% rename from packages/map/src/map-next/ui/map_tests/map_resize.test.ts rename to packages/map/__tests__/map_tests/map_resize.test.ts index 6ab90e10615..5d9c4348988 100644 --- a/packages/map/src/map-next/ui/map_tests/map_resize.test.ts +++ b/packages/map/__tests__/map_tests/map_resize.test.ts @@ -1,4 +1,4 @@ -import { beforeMapTest, createMap, sleep } from '../../util/test/util'; +import { beforeMapTest, createMap, sleep } from '../libs/util'; beforeEach(() => { beforeMapTest(); diff --git a/packages/map/src/map-next/ui/map_tests/map_world_copies.test.ts b/packages/map/__tests__/map_tests/map_world_copies.test.ts similarity index 98% rename from packages/map/src/map-next/ui/map_tests/map_world_copies.test.ts rename to packages/map/__tests__/map_tests/map_world_copies.test.ts index 88e09f2f2da..5722e56a871 100644 --- a/packages/map/src/map-next/ui/map_tests/map_world_copies.test.ts +++ b/packages/map/__tests__/map_tests/map_world_copies.test.ts @@ -1,4 +1,4 @@ -import { beforeMapTest, createMap } from '../../util/test/util'; +import { beforeMapTest, createMap } from '../libs/util'; beforeEach(() => { beforeMapTest(); diff --git a/packages/map/src/map-next/ui/map_tests/map_zoom.test.ts b/packages/map/__tests__/map_tests/map_zoom.test.ts similarity index 96% rename from packages/map/src/map-next/ui/map_tests/map_zoom.test.ts rename to packages/map/__tests__/map_tests/map_zoom.test.ts index 01970c5c9cc..865630eba97 100644 --- a/packages/map/src/map-next/ui/map_tests/map_zoom.test.ts +++ b/packages/map/__tests__/map_tests/map_zoom.test.ts @@ -1,4 +1,4 @@ -import { beforeMapTest, createMap } from '../../util/test/util'; +import { beforeMapTest, createMap } from '../libs/util'; beforeEach(() => { beforeMapTest(); diff --git a/packages/map/src/map-next/util/browser.test.ts b/packages/map/__tests__/util/browser.test.ts similarity index 88% rename from packages/map/src/map-next/util/browser.test.ts rename to packages/map/__tests__/util/browser.test.ts index 0676c7b15fd..16a28f8bc9a 100644 --- a/packages/map/src/map-next/util/browser.test.ts +++ b/packages/map/__tests__/util/browser.test.ts @@ -1,4 +1,4 @@ -import { browser } from './browser'; +import { browser } from '../../src/map-next/util/browser'; describe('browser', () => { test('frameAsync', async () => { diff --git a/packages/map/src/map-next/util/evented.test.ts b/packages/map/__tests__/util/evented.test.ts similarity index 99% rename from packages/map/src/map-next/util/evented.test.ts rename to packages/map/__tests__/util/evented.test.ts index 5b05241456c..974a0950ffa 100644 --- a/packages/map/src/map-next/util/evented.test.ts +++ b/packages/map/__tests__/util/evented.test.ts @@ -1,4 +1,4 @@ -import { Event, Evented } from './evented'; +import { Event, Evented } from '../../src/map-next/util/evented'; describe('Evented', () => { test('calls listeners added with "on"', () => { diff --git a/packages/map/src/map-next/util/task_queue.test.ts b/packages/map/__tests__/util/task_queue.test.ts similarity index 97% rename from packages/map/src/map-next/util/task_queue.test.ts rename to packages/map/__tests__/util/task_queue.test.ts index 1e3586a9863..5200251c6d1 100644 --- a/packages/map/src/map-next/util/task_queue.test.ts +++ b/packages/map/__tests__/util/task_queue.test.ts @@ -1,4 +1,4 @@ -import { TaskQueue } from './task_queue'; +import { TaskQueue } from '../../src/map-next/util/task_queue'; describe('TaskQueue', () => { test('Calls callbacks, in order', () => { diff --git a/packages/map/src/index.ts b/packages/map/src/index.ts index 25c19e47d52..3c3dc9ef24c 100644 --- a/packages/map/src/index.ts +++ b/packages/map/src/index.ts @@ -1,4 +1,7 @@ -export * from './earthmap'; -export * from './geo/mercator'; -export * from './interface'; -export * from './map'; +/********** 下一个版本移除,不再导出 *********/ +export * from './map-next'; +export * from './map/earthmap'; +export * from './map/interface'; +/********** 下一个版本移除,不再导出 *********/ + +export * from './map/map'; diff --git a/packages/map/src/map-next/README.md b/packages/map/src/map-next/README.md deleted file mode 100644 index 7dd2939b19a..00000000000 --- a/packages/map/src/map-next/README.md +++ /dev/null @@ -1,32 +0,0 @@ -## Map - -Map fork from [maplibre-gl-js](maplibre-gl-js), keep event, responds user interaction and updates the internal state of the map (current viewport, camera angle, etc.) - -```mermaid -sequenceDiagram - actor user - participant DOM - participant handler_manager - participant handler - participant camera - participant transform - participant map - - user->>camera: map#setCenter, map#panTo - camera->>transform: update - camera->>map: fire move event - map->>map: _render() - - user->>DOM: resize, pan,
click, scroll,
... - DOM->>handler_manager: DOM events - handler_manager->>handler: forward event - handler-->>handler_manager: HandlerResult - handler_manager->>transform: update - handler_manager->>map: fire move event - map->>map: _render() -``` - -- [Transform](../src/geo/transform.ts) holds the current viewport details (pitch, zoom, bearing, bounds, etc.). Two places in the code update transform directly: - - [Camera](../src/ui/camera.ts) (parent class of [Map](../src/ui/map)) in response to explicit calls to [Camera#panTo](../src/ui/camera.ts#L207), [Camera#setCenter](../src/ui/camera.ts#L169) - - [HandlerManager](../src/ui/handler_manager.ts) in response to DOM events. It forwards those events to interaction processors that live in [src/ui/handler](../src/ui/handler), which accumulate a merged [HandlerResult](../src/ui/handler_manager.ts#L64) that kick off a render frame loop, decreasing the inertia and nudging map.transform by that amount on each frame from [HandlerManager#\_updateMapTransform()](../src/ui/handler_manager.ts#L413). That loop continues in the inertia decreases to 0. -- Both camera and handler_manager are responsible for firing `move`, `zoom`, `movestart`, `moveend`, ... events on the map after they update transform. Each of these events (along with style changes and data load events) triggers a call to [Map#\_render()](../src/ui/map.ts#L2480) which renders a single frame of the map. diff --git a/packages/map/src/map-next/ui/camera.ts b/packages/map/src/map-next/camera.ts similarity index 98% rename from packages/map/src/map-next/ui/camera.ts rename to packages/map/src/map-next/camera.ts index 532dfa0a448..b0301c51b7a 100644 --- a/packages/map/src/map-next/ui/camera.ts +++ b/packages/map/src/map-next/camera.ts @@ -1,9 +1,9 @@ import Point from '@mapbox/point-geometry'; -import { LngLat } from '../geo/lng_lat'; -import { LngLatBounds } from '../geo/lng_lat_bounds'; -import { MercatorCoordinate } from '../geo/mercator_coordinate'; -import { browser } from '../util/browser'; -import { Event, Evented } from '../util/evented'; +import { LngLat } from './geo/lng_lat'; +import { LngLatBounds } from './geo/lng_lat_bounds'; +import { MercatorCoordinate } from './geo/mercator_coordinate'; +import { browser } from './util/browser'; +import { Event, Evented } from './util/evented'; import { clamp, defaultEasing, @@ -13,14 +13,14 @@ import { pick, warnOnce, wrap, -} from '../util/util'; +} from './util/util'; -import type { PaddingOptions } from '../geo/edge_insets'; -import type { LngLatLike } from '../geo/lng_lat'; -import type { LngLatBoundsLike } from '../geo/lng_lat_bounds'; -import type { Transform } from '../geo/transform'; -import type { TaskID } from '../util/task_queue'; +import type { PaddingOptions } from './geo/edge_insets'; +import type { LngLatLike } from './geo/lng_lat'; +import type { LngLatBoundsLike } from './geo/lng_lat_bounds'; +import type { Transform } from './geo/transform'; import type { HandlerManager } from './handler_manager'; +import type { TaskID } from './util/task_queue'; /** * A [Point](https://github.com/mapbox/point-geometry) or an array of two numbers representing `x` and `y` screen coordinates in pixels. * diff --git a/packages/map/src/css/l7.css b/packages/map/src/map-next/css/l7.css similarity index 71% rename from packages/map/src/css/l7.css rename to packages/map/src/map-next/css/l7.css index f1faa047a3f..4a6d99c3970 100644 --- a/packages/map/src/css/l7.css +++ b/packages/map/src/map-next/css/l7.css @@ -26,12 +26,7 @@ .l7-canvas-container.l7-interactive, .l7-ctrl-group button.l7-ctrl-compass { - cursor: -webkit-grab; - cursor: -moz-grab; cursor: grab; - -moz-user-select: none; - -webkit-user-select: none; - -ms-user-select: none; user-select: none; } @@ -41,8 +36,6 @@ .l7-canvas-container.l7-interactive:active, .l7-ctrl-group button.l7-ctrl-compass:active { - cursor: -webkit-grabbing; - cursor: -moz-grabbing; cursor: grabbing; } @@ -61,6 +54,47 @@ 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, diff --git a/packages/map/src/map-next/ui/events.ts b/packages/map/src/map-next/events.ts similarity index 98% rename from packages/map/src/map-next/ui/events.ts rename to packages/map/src/map-next/events.ts index bd3aea5673d..f1a83b6a207 100644 --- a/packages/map/src/map-next/ui/events.ts +++ b/packages/map/src/map-next/events.ts @@ -1,10 +1,10 @@ -import { Event } from '../util/evented'; +import { Event } from './util/evented'; import Point from '@mapbox/point-geometry'; -import { DOM } from '../util/dom'; -import { extend } from '../util/util'; +import { DOM } from './util/dom'; +import { extend } from './util/util'; -import type { LngLat } from '../geo/lng_lat'; +import type { LngLat } from './geo/lng_lat'; import type { Map } from './map'; /** diff --git a/packages/map/src/map-next/geo/transform.ts b/packages/map/src/map-next/geo/transform.ts index 35456374e44..f8a2eaccf29 100644 --- a/packages/map/src/map-next/geo/transform.ts +++ b/packages/map/src/map-next/geo/transform.ts @@ -537,7 +537,7 @@ export class Transform { this.latRange = [bounds.getSouth(), bounds.getNorth()]; this._constrain(); } else { - this.lngRange = [-180, 180]; + this.lngRange = null; this.latRange = [-MAX_VALID_LATITUDE, MAX_VALID_LATITUDE]; } } diff --git a/packages/map/src/map-next/ui/handler/box_zoom.ts b/packages/map/src/map-next/handler/box_zoom.ts similarity index 93% rename from packages/map/src/map-next/ui/handler/box_zoom.ts rename to packages/map/src/map-next/handler/box_zoom.ts index ab22b354477..0a627211132 100644 --- a/packages/map/src/map-next/ui/handler/box_zoom.ts +++ b/packages/map/src/map-next/handler/box_zoom.ts @@ -1,6 +1,6 @@ -import { DOM } from '../../util/dom'; +import { DOM } from '../util/dom'; -import { Event } from '../../util/evented'; +import { Event } from '../util/evented'; import { TransformProvider } from './transform-provider'; import type Point from '@mapbox/point-geometry'; @@ -108,8 +108,8 @@ export class BoxZoomHandler implements Handler { this._lastPos = pos; if (!this._box) { - this._box = DOM.create('div', 'maplibregl-boxzoom', this._container); - this._container.classList.add('maplibregl-crosshair'); + this._box = DOM.create('div', 'l7-boxzoom', this._container); + this._container.classList.add('l7-crosshair'); this._fireEvent('boxzoomstart', e); } @@ -159,7 +159,7 @@ export class BoxZoomHandler implements Handler { reset() { this._active = false; - this._container.classList.remove('maplibregl-crosshair'); + this._container.classList.remove('l7-crosshair'); if (this._box) { DOM.remove(this._box); diff --git a/packages/map/src/map-next/ui/handler/click_zoom.ts b/packages/map/src/map-next/handler/click_zoom.ts similarity index 100% rename from packages/map/src/map-next/ui/handler/click_zoom.ts rename to packages/map/src/map-next/handler/click_zoom.ts diff --git a/packages/map/src/map-next/ui/handler/cooperative_gestures.ts b/packages/map/src/map-next/handler/cooperative_gestures.ts similarity index 83% rename from packages/map/src/map-next/ui/handler/cooperative_gestures.ts rename to packages/map/src/map-next/handler/cooperative_gestures.ts index 2c54f6726c7..d867e629297 100644 --- a/packages/map/src/map-next/ui/handler/cooperative_gestures.ts +++ b/packages/map/src/map-next/handler/cooperative_gestures.ts @@ -1,5 +1,5 @@ -import { DOM } from '../../util/dom'; import type { Handler } from '../handler_manager'; +import { DOM } from '../util/dom'; import type { Map } from '../map'; @@ -46,20 +46,16 @@ export class CooperativeGesturesHandler implements Handler { if (this._container) return; const mapCanvasContainer = this._map.getCanvasContainer(); // Add a cooperative gestures class (enable touch-action: pan-x pan-y;) - mapCanvasContainer.classList.add('maplibregl-cooperative-gestures'); - this._container = DOM.create( - 'div', - 'maplibregl-cooperative-gesture-screen', - mapCanvasContainer, - ); + mapCanvasContainer.classList.add('l7-cooperative-gestures'); + this._container = DOM.create('div', 'l7-cooperative-gesture-screen', mapCanvasContainer); // Create and append the desktop message div const desktopDiv = document.createElement('div'); - desktopDiv.className = 'maplibregl-desktop-message'; + desktopDiv.className = 'l7-desktop-message'; desktopDiv.textContent = 'Missing UI string'; this._container.appendChild(desktopDiv); // Create and append the mobile message div const mobileDiv = document.createElement('div'); - mobileDiv.className = 'maplibregl-mobile-message'; + mobileDiv.className = 'l7-mobile-message'; mobileDiv.textContent = 'Missing UI string'; this._container.appendChild(mobileDiv); // Remove cooperative gesture screen from the accessibility tree since screenreaders cannot interact with the map using gestures @@ -70,7 +66,7 @@ export class CooperativeGesturesHandler implements Handler { if (this._container) { DOM.remove(this._container); const mapCanvasContainer = this._map.getCanvasContainer(); - mapCanvasContainer.classList.remove('maplibregl-cooperative-gestures'); + mapCanvasContainer.classList.remove('l7-cooperative-gestures'); } delete this._container; } @@ -103,9 +99,9 @@ export class CooperativeGesturesHandler implements Handler { _onCooperativeGesture(showNotification: boolean) { if (!this._enabled || !showNotification) return; // Alert user how to scroll/pan - this._container.classList.add('maplibregl-show'); + this._container.classList.add('l7-show'); setTimeout(() => { - this._container.classList.remove('maplibregl-show'); + this._container.classList.remove('l7-show'); }, 100); } } diff --git a/packages/map/src/map-next/ui/handler/drag_handler.ts b/packages/map/src/map-next/handler/drag_handler.ts similarity index 99% rename from packages/map/src/map-next/ui/handler/drag_handler.ts rename to packages/map/src/map-next/handler/drag_handler.ts index 3b0b78ff3e7..79a2ff16ebd 100644 --- a/packages/map/src/map-next/ui/handler/drag_handler.ts +++ b/packages/map/src/map-next/handler/drag_handler.ts @@ -1,6 +1,6 @@ import type Point from '@mapbox/point-geometry'; -import { DOM } from '../../util/dom'; import type { Handler } from '../handler_manager'; +import { DOM } from '../util/dom'; import type { DragMoveStateManager } from './drag_move_state_manager'; interface DragMovementResult { diff --git a/packages/map/src/map-next/ui/handler/drag_move_state_manager.ts b/packages/map/src/map-next/handler/drag_move_state_manager.ts similarity index 98% rename from packages/map/src/map-next/ui/handler/drag_move_state_manager.ts rename to packages/map/src/map-next/handler/drag_move_state_manager.ts index ad0fe69c9b3..c098aeb806c 100644 --- a/packages/map/src/map-next/ui/handler/drag_move_state_manager.ts +++ b/packages/map/src/map-next/handler/drag_move_state_manager.ts @@ -1,4 +1,4 @@ -import { DOM } from '../../util/dom'; +import { DOM } from '../util/dom'; const LEFT_BUTTON = 0; const RIGHT_BUTTON = 2; diff --git a/packages/map/src/map-next/ui/handler/handler_util.ts b/packages/map/src/map-next/handler/handler_util.ts similarity index 100% rename from packages/map/src/map-next/ui/handler/handler_util.ts rename to packages/map/src/map-next/handler/handler_util.ts diff --git a/packages/map/src/map-next/ui/handler/keyboard.ts b/packages/map/src/map-next/handler/keyboard.ts similarity index 100% rename from packages/map/src/map-next/ui/handler/keyboard.ts rename to packages/map/src/map-next/handler/keyboard.ts diff --git a/packages/map/src/map-next/ui/handler/map_event.ts b/packages/map/src/map-next/handler/map_event.ts similarity index 100% rename from packages/map/src/map-next/ui/handler/map_event.ts rename to packages/map/src/map-next/handler/map_event.ts diff --git a/packages/map/src/map-next/ui/handler/mouse.ts b/packages/map/src/map-next/handler/mouse.ts similarity index 98% rename from packages/map/src/map-next/ui/handler/mouse.ts rename to packages/map/src/map-next/handler/mouse.ts index 738c6bf375e..31bbf8d3657 100644 --- a/packages/map/src/map-next/ui/handler/mouse.ts +++ b/packages/map/src/map-next/handler/mouse.ts @@ -1,6 +1,6 @@ import type Point from '@mapbox/point-geometry'; -import { DOM } from '../../util/dom'; +import { DOM } from '../util/dom'; import type { DragMoveHandler, DragPanResult, diff --git a/packages/map/src/map-next/ui/handler/one_finger_touch_drag.ts b/packages/map/src/map-next/handler/one_finger_touch_drag.ts similarity index 100% rename from packages/map/src/map-next/ui/handler/one_finger_touch_drag.ts rename to packages/map/src/map-next/handler/one_finger_touch_drag.ts diff --git a/packages/map/src/map-next/ui/handler/scroll_zoom.ts b/packages/map/src/map-next/handler/scroll_zoom.ts similarity index 98% rename from packages/map/src/map-next/ui/handler/scroll_zoom.ts rename to packages/map/src/map-next/handler/scroll_zoom.ts index a090857206c..4d612e1df25 100644 --- a/packages/map/src/map-next/ui/handler/scroll_zoom.ts +++ b/packages/map/src/map-next/handler/scroll_zoom.ts @@ -1,8 +1,8 @@ -import { DOM } from '../../util/dom'; +import { DOM } from '../util/dom'; -import { LngLat } from '../../geo/lng_lat'; -import { browser } from '../../util/browser'; -import { bezier, defaultEasing, interpolates } from '../../util/util'; +import { LngLat } from '../geo/lng_lat'; +import { browser } from '../util/browser'; +import { bezier, defaultEasing, interpolates } from '../util/util'; import { TransformProvider } from './transform-provider'; import type Point from '@mapbox/point-geometry'; diff --git a/packages/map/src/map-next/ui/handler/shim/dblclick_zoom.ts b/packages/map/src/map-next/handler/shim/dblclick_zoom.ts similarity index 96% rename from packages/map/src/map-next/ui/handler/shim/dblclick_zoom.ts rename to packages/map/src/map-next/handler/shim/dblclick_zoom.ts index 14c383abf0b..ee977c7b812 100644 --- a/packages/map/src/map-next/ui/handler/shim/dblclick_zoom.ts +++ b/packages/map/src/map-next/handler/shim/dblclick_zoom.ts @@ -1,5 +1,5 @@ import type { ClickZoomHandler } from '../click_zoom'; -import type { TapZoomHandler } from './../tap_zoom'; +import type { TapZoomHandler } from '../tap_zoom'; /** * The `DoubleClickZoomHandler` allows the user to zoom the map at a point by diff --git a/packages/map/src/map-next/ui/handler/shim/drag_pan.ts b/packages/map/src/map-next/handler/shim/drag_pan.ts similarity index 93% rename from packages/map/src/map-next/ui/handler/shim/drag_pan.ts rename to packages/map/src/map-next/handler/shim/drag_pan.ts index 3429d5a6816..271fd4129e1 100644 --- a/packages/map/src/map-next/ui/handler/shim/drag_pan.ts +++ b/packages/map/src/map-next/handler/shim/drag_pan.ts @@ -1,5 +1,5 @@ import type { MousePanHandler } from '../mouse'; -import type { TouchPanHandler } from './../touch_pan'; +import type { TouchPanHandler } from '../touch_pan'; /** * A {@link DragPanHandler} options object @@ -66,7 +66,7 @@ export class DragPanHandler { this._inertiaOptions = options || {}; this._mousePan.enable(); this._touchPan.enable(); - this._el.classList.add('maplibregl-touch-drag-pan'); + this._el.classList.add('l7-touch-drag-pan'); } /** @@ -80,7 +80,7 @@ export class DragPanHandler { disable() { this._mousePan.disable(); this._touchPan.disable(); - this._el.classList.remove('maplibregl-touch-drag-pan'); + this._el.classList.remove('l7-touch-drag-pan'); } /** diff --git a/packages/map/src/map-next/ui/handler/shim/drag_rotate.ts b/packages/map/src/map-next/handler/shim/drag_rotate.ts similarity index 100% rename from packages/map/src/map-next/ui/handler/shim/drag_rotate.ts rename to packages/map/src/map-next/handler/shim/drag_rotate.ts diff --git a/packages/map/src/map-next/ui/handler/shim/two_fingers_touch.ts b/packages/map/src/map-next/handler/shim/two_fingers_touch.ts similarity index 96% rename from packages/map/src/map-next/ui/handler/shim/two_fingers_touch.ts rename to packages/map/src/map-next/handler/shim/two_fingers_touch.ts index bc0310968d7..023be4f14b9 100644 --- a/packages/map/src/map-next/ui/handler/shim/two_fingers_touch.ts +++ b/packages/map/src/map-next/handler/shim/two_fingers_touch.ts @@ -52,7 +52,7 @@ export class TwoFingersTouchZoomRotateHandler { this._touchZoom.enable(options); if (!this._rotationDisabled) this._touchRotate.enable(options); this._tapDragZoom.enable(); - this._el.classList.add('maplibregl-touch-zoom-rotate'); + this._el.classList.add('l7-touch-zoom-rotate'); } /** @@ -67,7 +67,7 @@ export class TwoFingersTouchZoomRotateHandler { this._touchZoom.disable(); this._touchRotate.disable(); this._tapDragZoom.disable(); - this._el.classList.remove('maplibregl-touch-zoom-rotate'); + this._el.classList.remove('l7-touch-zoom-rotate'); } /** diff --git a/packages/map/src/map-next/ui/handler/tap_drag_zoom.ts b/packages/map/src/map-next/handler/tap_drag_zoom.ts similarity index 100% rename from packages/map/src/map-next/ui/handler/tap_drag_zoom.ts rename to packages/map/src/map-next/handler/tap_drag_zoom.ts diff --git a/packages/map/src/map-next/ui/handler/tap_recognizer.ts b/packages/map/src/map-next/handler/tap_recognizer.ts similarity index 100% rename from packages/map/src/map-next/ui/handler/tap_recognizer.ts rename to packages/map/src/map-next/handler/tap_recognizer.ts diff --git a/packages/map/src/map-next/ui/handler/tap_zoom.ts b/packages/map/src/map-next/handler/tap_zoom.ts similarity index 100% rename from packages/map/src/map-next/ui/handler/tap_zoom.ts rename to packages/map/src/map-next/handler/tap_zoom.ts diff --git a/packages/map/src/map-next/ui/handler/touch_pan.ts b/packages/map/src/map-next/handler/touch_pan.ts similarity index 100% rename from packages/map/src/map-next/ui/handler/touch_pan.ts rename to packages/map/src/map-next/handler/touch_pan.ts diff --git a/packages/map/src/map-next/ui/handler/transform-provider.ts b/packages/map/src/map-next/handler/transform-provider.ts similarity index 90% rename from packages/map/src/map-next/ui/handler/transform-provider.ts rename to packages/map/src/map-next/handler/transform-provider.ts index 09b695cb813..b6a3b6240e7 100644 --- a/packages/map/src/map-next/ui/handler/transform-provider.ts +++ b/packages/map/src/map-next/handler/transform-provider.ts @@ -1,7 +1,7 @@ import Point from '@mapbox/point-geometry'; -import type { LngLat } from '../../geo/lng_lat'; -import type { Transform } from '../../geo/transform'; import type { PointLike } from '../camera'; +import type { LngLat } from '../geo/lng_lat'; +import type { Transform } from '../geo/transform'; import type { Map } from '../map'; /** diff --git a/packages/map/src/map-next/ui/handler/two_fingers_touch.ts b/packages/map/src/map-next/handler/two_fingers_touch.ts similarity index 99% rename from packages/map/src/map-next/ui/handler/two_fingers_touch.ts rename to packages/map/src/map-next/handler/two_fingers_touch.ts index 4cb89be1a94..96b1c1c0eb3 100644 --- a/packages/map/src/map-next/ui/handler/two_fingers_touch.ts +++ b/packages/map/src/map-next/handler/two_fingers_touch.ts @@ -1,7 +1,7 @@ import type Point from '@mapbox/point-geometry'; -import { DOM } from '../../util/dom'; import type { Handler, HandlerResult } from '../handler_manager'; import type { Map } from '../map'; +import { DOM } from '../util/dom'; /** * An options object sent to the enable function of some of the handlers diff --git a/packages/map/src/map-next/ui/handler_inertia.ts b/packages/map/src/map-next/handler_inertia.ts similarity index 97% rename from packages/map/src/map-next/ui/handler_inertia.ts rename to packages/map/src/map-next/handler_inertia.ts index 39b8b50148c..89cb25fd72d 100644 --- a/packages/map/src/map-next/ui/handler_inertia.ts +++ b/packages/map/src/map-next/handler_inertia.ts @@ -1,8 +1,8 @@ import Point from '@mapbox/point-geometry'; -import { browser } from '../util/browser'; -import { bezier, clamp, extend } from '../util/util'; 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, diff --git a/packages/map/src/map-next/ui/handler_manager.ts b/packages/map/src/map-next/handler_manager.ts similarity index 99% rename from packages/map/src/map-next/ui/handler_manager.ts rename to packages/map/src/map-next/handler_manager.ts index 45a04ac3a55..9a26fbfb82b 100644 --- a/packages/map/src/map-next/ui/handler_manager.ts +++ b/packages/map/src/map-next/handler_manager.ts @@ -1,8 +1,4 @@ import Point from '@mapbox/point-geometry'; -import { browser } from '../util/browser'; -import { DOM } from '../util/dom'; -import { Event } from '../util/evented'; -import { extend } from '../util/util'; import { BoxZoomHandler } from './handler/box_zoom'; import { ClickZoomHandler } from './handler/click_zoom'; import { CooperativeGesturesHandler } from './handler/cooperative_gestures'; @@ -28,6 +24,10 @@ import { } from './handler/two_fingers_touch'; import { HandlerInertia } from './handler_inertia'; import type { CompleteMapOptions, Map } from './map'; +import { browser } from './util/browser'; +import { DOM } from './util/dom'; +import { Event } from './util/evented'; +import { extend } from './util/util'; const isMoving = (p: EventsInProgress) => p.zoom || p.drag || p.pitch || p.rotate; diff --git a/packages/map/src/map-next/index.ts b/packages/map/src/map-next/index.ts index 36674f6c4c8..60478e30187 100644 --- a/packages/map/src/map-next/index.ts +++ b/packages/map/src/map-next/index.ts @@ -1 +1,3 @@ -export { Map } from './ui/map'; +export { MercatorCoordinate } from './geo/mercator_coordinate'; +export { Map as MapNext } from './map'; +export type { MapOptions } from './map'; diff --git a/packages/map/src/map-next/ui/map.ts b/packages/map/src/map-next/map.ts similarity index 97% rename from packages/map/src/map-next/ui/map.ts rename to packages/map/src/map-next/map.ts index fc789c3bed2..83ee8707638 100644 --- a/packages/map/src/map-next/ui/map.ts +++ b/packages/map/src/map-next/map.ts @@ -1,23 +1,24 @@ import Point from '@mapbox/point-geometry'; -import { LngLat } from '../geo/lng_lat'; -import { LngLatBounds } from '../geo/lng_lat_bounds'; -import { Transform } from '../geo/transform'; -import { browser } from '../util/browser'; -import { DOM } from '../util/dom'; -import type { Listener } from '../util/evented'; -import { Event } from '../util/evented'; -import { TaskQueue } from '../util/task_queue'; -import type { Complete } from '../util/util'; -import { extend, uniqueId } from '../util/util'; import { Camera } from './camera'; import type { MapEventType } from './events'; +import { LngLat } from './geo/lng_lat'; +import { LngLatBounds } from './geo/lng_lat_bounds'; +import { Transform } from './geo/transform'; import { HandlerManager } from './handler_manager'; +import { browser } from './util/browser'; +import { DOM } from './util/dom'; +import type { Listener } from './util/evented'; +import { Event } from './util/evented'; +import { TaskQueue } from './util/task_queue'; +import type { Complete } from './util/util'; +import { extend, uniqueId } from './util/util'; + +import './css/l7.css'; import { lodashUtil } from '@antv/l7-utils'; -import type { LngLatLike } from '../geo/lng_lat'; -import type { LngLatBoundsLike } from '../geo/lng_lat_bounds'; -import type { TaskID } from '../util/task_queue'; import type { CameraOptions, FitBoundsOptions, PointLike } from './camera'; +import type { LngLatLike } from './geo/lng_lat'; +import type { LngLatBoundsLike } from './geo/lng_lat_bounds'; import type { BoxZoomHandler } from './handler/box_zoom'; import type { CooperativeGesturesHandler, GestureOptions } from './handler/cooperative_gestures'; import type { KeyboardHandler } from './handler/keyboard'; @@ -27,6 +28,7 @@ import type { DragPanHandler, DragPanOptions } from './handler/shim/drag_pan'; import type { DragRotateHandler } from './handler/shim/drag_rotate'; import type { TwoFingersTouchZoomRotateHandler } from './handler/shim/two_fingers_touch'; import type { AroundCenterOptions, TwoFingersTouchPitchHandler } from './handler/two_fingers_touch'; +import type { TaskID } from './util/task_queue'; /** * The {@link Map} options object. @@ -900,15 +902,15 @@ export class Map extends Camera { _setupContainer() { const container = this._container; - container.classList.add('maplibregl-map'); + container.classList.add('l7-map'); const canvasContainer = (this._canvasContainer = DOM.create( 'div', - 'maplibregl-canvas-container', + 'l7-canvas-container', container, )); if (this._interactive) { - canvasContainer.classList.add('maplibregl-interactive'); + canvasContainer.classList.add('l7-interactive'); } this._container.addEventListener('scroll', this._onMapScroll, false); @@ -997,7 +999,7 @@ export class Map extends Camera { this._resizeObserver?.disconnect(); DOM.remove(this._canvasContainer); - this._container.classList.remove('maplibregl-map'); + this._container.classList.remove('l7-map'); this._removed = true; this.fire(new Event('remove')); diff --git a/packages/map/src/map/README.md b/packages/map/src/map/README.md new file mode 100644 index 00000000000..26b480e6f50 --- /dev/null +++ b/packages/map/src/map/README.md @@ -0,0 +1,3 @@ +## 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/src/camera.ts b/packages/map/src/map/camera.ts similarity index 100% rename from packages/map/src/camera.ts rename to packages/map/src/map/camera.ts diff --git a/packages/map/src/map/css/l7.css b/packages/map/src/map/css/l7.css new file mode 100644 index 00000000000..4a6d99c3970 --- /dev/null +++ b/packages/map/src/map/css/l7.css @@ -0,0 +1,163 @@ +.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/src/earthmap.ts b/packages/map/src/map/earthmap.ts similarity index 99% rename from packages/map/src/earthmap.ts rename to packages/map/src/map/earthmap.ts index de95de44546..185a7b9749f 100644 --- a/packages/map/src/earthmap.ts +++ b/packages/map/src/map/earthmap.ts @@ -58,6 +58,10 @@ const DefaultOptions: IMapOptions = { pitchEnabled: true, rotateEnabled: true, }; + +/** + * @deprecated + */ export class EarthMap extends Camera { public doubleClickZoom: DoubleClickZoomHandler; public dragRotate: DragRotateHandler; diff --git a/packages/map/src/geo/edge_insets.ts b/packages/map/src/map/geo/edge_insets.ts similarity index 100% rename from packages/map/src/geo/edge_insets.ts rename to packages/map/src/map/geo/edge_insets.ts diff --git a/packages/map/src/geo/lng_lat.ts b/packages/map/src/map/geo/lng_lat.ts similarity index 100% rename from packages/map/src/geo/lng_lat.ts rename to packages/map/src/map/geo/lng_lat.ts diff --git a/packages/map/src/geo/lng_lat_bounds.ts b/packages/map/src/map/geo/lng_lat_bounds.ts similarity index 100% rename from packages/map/src/geo/lng_lat_bounds.ts rename to packages/map/src/map/geo/lng_lat_bounds.ts diff --git a/packages/map/src/geo/mercator.ts b/packages/map/src/map/geo/mercator.ts similarity index 95% rename from packages/map/src/geo/mercator.ts rename to packages/map/src/map/geo/mercator.ts index b8eb9347c00..dcee92f63fe 100644 --- a/packages/map/src/geo/mercator.ts +++ b/packages/map/src/map/geo/mercator.ts @@ -1,5 +1,5 @@ -import type { LngLatLike } from '../geo/lng_lat'; -import LngLat, { earthRadius } from '../geo/lng_lat'; +import type { LngLatLike } from './lng_lat'; +import LngLat, { earthRadius } from './lng_lat'; /* * The average circumference of the world in meters. diff --git a/packages/map/src/geo/point.ts b/packages/map/src/map/geo/point.ts similarity index 100% rename from packages/map/src/geo/point.ts rename to packages/map/src/map/geo/point.ts diff --git a/packages/map/src/geo/simple.ts b/packages/map/src/map/geo/simple.ts similarity index 95% rename from packages/map/src/geo/simple.ts rename to packages/map/src/map/geo/simple.ts index 7219394d437..24cbc9ea735 100644 --- a/packages/map/src/geo/simple.ts +++ b/packages/map/src/map/geo/simple.ts @@ -1,5 +1,5 @@ -import type { LngLatLike } from '../geo/lng_lat'; -import LngLat, { earthRadius } from '../geo/lng_lat'; +import type { LngLatLike } from './lng_lat'; +import LngLat, { earthRadius } from './lng_lat'; /* * The average circumference of the world in meters. diff --git a/packages/map/src/geo/transform.ts b/packages/map/src/map/geo/transform.ts similarity index 99% rename from packages/map/src/geo/transform.ts rename to packages/map/src/map/geo/transform.ts index db33c0f83e4..8505ec8e0ec 100644 --- a/packages/map/src/geo/transform.ts +++ b/packages/map/src/map/geo/transform.ts @@ -1,6 +1,5 @@ // @ts-ignore import { mat2, mat4, vec4 } from 'gl-matrix'; -import Point from '../geo/point'; import { clamp, interpolate, wrap } from '../util'; import type { IPaddingOptions } from './edge_insets'; import EdgeInsets from './edge_insets'; @@ -11,6 +10,7 @@ import MercatorCoordinate, { mercatorYfromLat, mercatorZfromAltitude, } from './mercator'; +import Point from './point'; export const EXTENT = 8192; export default class Transform { get minZoom(): number { diff --git a/packages/map/src/handler/IHandler.ts b/packages/map/src/map/handler/IHandler.ts similarity index 100% rename from packages/map/src/handler/IHandler.ts rename to packages/map/src/map/handler/IHandler.ts diff --git a/packages/map/src/handler/blockable_map_event.ts b/packages/map/src/map/handler/blockable_map_event.ts similarity index 100% rename from packages/map/src/handler/blockable_map_event.ts rename to packages/map/src/map/handler/blockable_map_event.ts diff --git a/packages/map/src/handler/box_zoom.ts b/packages/map/src/map/handler/box_zoom.ts similarity index 100% rename from packages/map/src/handler/box_zoom.ts rename to packages/map/src/map/handler/box_zoom.ts diff --git a/packages/map/src/handler/click_zoom.ts b/packages/map/src/map/handler/click_zoom.ts similarity index 100% rename from packages/map/src/handler/click_zoom.ts rename to packages/map/src/map/handler/click_zoom.ts diff --git a/packages/map/src/handler/events/event.ts b/packages/map/src/map/handler/events/event.ts similarity index 100% rename from packages/map/src/handler/events/event.ts rename to packages/map/src/map/handler/events/event.ts diff --git a/packages/map/src/handler/events/index.ts b/packages/map/src/map/handler/events/index.ts similarity index 100% rename from packages/map/src/handler/events/index.ts rename to packages/map/src/map/handler/events/index.ts diff --git a/packages/map/src/handler/events/map_mouse_event.ts b/packages/map/src/map/handler/events/map_mouse_event.ts similarity index 100% rename from packages/map/src/handler/events/map_mouse_event.ts rename to packages/map/src/map/handler/events/map_mouse_event.ts diff --git a/packages/map/src/handler/events/map_touch_event.ts b/packages/map/src/map/handler/events/map_touch_event.ts similarity index 100% rename from packages/map/src/handler/events/map_touch_event.ts rename to packages/map/src/map/handler/events/map_touch_event.ts diff --git a/packages/map/src/handler/events/map_wheel_event.ts b/packages/map/src/map/handler/events/map_wheel_event.ts similarity index 100% rename from packages/map/src/handler/events/map_wheel_event.ts rename to packages/map/src/map/handler/events/map_wheel_event.ts diff --git a/packages/map/src/handler/events/render_event.ts b/packages/map/src/map/handler/events/render_event.ts similarity index 100% rename from packages/map/src/handler/events/render_event.ts rename to packages/map/src/map/handler/events/render_event.ts diff --git a/packages/map/src/handler/handler_inertia.ts b/packages/map/src/map/handler/handler_inertia.ts similarity index 100% rename from packages/map/src/handler/handler_inertia.ts rename to packages/map/src/map/handler/handler_inertia.ts diff --git a/packages/map/src/handler/handler_manager.ts b/packages/map/src/map/handler/handler_manager.ts similarity index 100% rename from packages/map/src/handler/handler_manager.ts rename to packages/map/src/map/handler/handler_manager.ts diff --git a/packages/map/src/handler/handler_util.ts b/packages/map/src/map/handler/handler_util.ts similarity index 100% rename from packages/map/src/handler/handler_util.ts rename to packages/map/src/map/handler/handler_util.ts diff --git a/packages/map/src/handler/keyboard.ts b/packages/map/src/map/handler/keyboard.ts similarity index 100% rename from packages/map/src/handler/keyboard.ts rename to packages/map/src/map/handler/keyboard.ts diff --git a/packages/map/src/handler/map_event.ts b/packages/map/src/map/handler/map_event.ts similarity index 100% rename from packages/map/src/handler/map_event.ts rename to packages/map/src/map/handler/map_event.ts diff --git a/packages/map/src/handler/mouse/index.ts b/packages/map/src/map/handler/mouse/index.ts similarity index 100% rename from packages/map/src/handler/mouse/index.ts rename to packages/map/src/map/handler/mouse/index.ts diff --git a/packages/map/src/handler/mouse/mouse_handler.ts b/packages/map/src/map/handler/mouse/mouse_handler.ts similarity index 100% rename from packages/map/src/handler/mouse/mouse_handler.ts rename to packages/map/src/map/handler/mouse/mouse_handler.ts diff --git a/packages/map/src/handler/mouse/mousepan_handler.ts b/packages/map/src/map/handler/mouse/mousepan_handler.ts similarity index 100% rename from packages/map/src/handler/mouse/mousepan_handler.ts rename to packages/map/src/map/handler/mouse/mousepan_handler.ts diff --git a/packages/map/src/handler/mouse/mousepitch_hander.ts b/packages/map/src/map/handler/mouse/mousepitch_hander.ts similarity index 100% rename from packages/map/src/handler/mouse/mousepitch_hander.ts rename to packages/map/src/map/handler/mouse/mousepitch_hander.ts diff --git a/packages/map/src/handler/mouse/mouserotate_hander.ts b/packages/map/src/map/handler/mouse/mouserotate_hander.ts similarity index 100% rename from packages/map/src/handler/mouse/mouserotate_hander.ts rename to packages/map/src/map/handler/mouse/mouserotate_hander.ts diff --git a/packages/map/src/handler/mouse/util.ts b/packages/map/src/map/handler/mouse/util.ts similarity index 100% rename from packages/map/src/handler/mouse/util.ts rename to packages/map/src/map/handler/mouse/util.ts diff --git a/packages/map/src/handler/scroll_zoom.ts b/packages/map/src/map/handler/scroll_zoom.ts similarity index 100% rename from packages/map/src/handler/scroll_zoom.ts rename to packages/map/src/map/handler/scroll_zoom.ts diff --git a/packages/map/src/handler/shim/dblclick_zoom.ts b/packages/map/src/map/handler/shim/dblclick_zoom.ts similarity index 100% rename from packages/map/src/handler/shim/dblclick_zoom.ts rename to packages/map/src/map/handler/shim/dblclick_zoom.ts diff --git a/packages/map/src/handler/shim/drag_pan.ts b/packages/map/src/map/handler/shim/drag_pan.ts similarity index 95% rename from packages/map/src/handler/shim/drag_pan.ts rename to packages/map/src/map/handler/shim/drag_pan.ts index 751121dbbec..8b734189608 100644 --- a/packages/map/src/handler/shim/drag_pan.ts +++ b/packages/map/src/map/handler/shim/drag_pan.ts @@ -1,5 +1,5 @@ -import type { MousePanHandler } from '../mouse/'; -import type { TouchPanHandler } from '../touch/'; +import type { MousePanHandler } from '../mouse'; +import type { TouchPanHandler } from '../touch'; export interface IDragPanOptions { linearity?: number; diff --git a/packages/map/src/handler/shim/drag_rotate.ts b/packages/map/src/map/handler/shim/drag_rotate.ts similarity index 100% rename from packages/map/src/handler/shim/drag_rotate.ts rename to packages/map/src/map/handler/shim/drag_rotate.ts diff --git a/packages/map/src/handler/shim/touch_zoom_rotate.ts b/packages/map/src/map/handler/shim/touch_zoom_rotate.ts similarity index 100% rename from packages/map/src/handler/shim/touch_zoom_rotate.ts rename to packages/map/src/map/handler/shim/touch_zoom_rotate.ts diff --git a/packages/map/src/handler/tap/single_tap_recognizer.ts b/packages/map/src/map/handler/tap/single_tap_recognizer.ts similarity index 100% rename from packages/map/src/handler/tap/single_tap_recognizer.ts rename to packages/map/src/map/handler/tap/single_tap_recognizer.ts diff --git a/packages/map/src/handler/tap/tap_drag_zoom.ts b/packages/map/src/map/handler/tap/tap_drag_zoom.ts similarity index 100% rename from packages/map/src/handler/tap/tap_drag_zoom.ts rename to packages/map/src/map/handler/tap/tap_drag_zoom.ts diff --git a/packages/map/src/handler/tap/tap_recognizer.ts b/packages/map/src/map/handler/tap/tap_recognizer.ts similarity index 100% rename from packages/map/src/handler/tap/tap_recognizer.ts rename to packages/map/src/map/handler/tap/tap_recognizer.ts diff --git a/packages/map/src/handler/tap/tap_zoom.ts b/packages/map/src/map/handler/tap/tap_zoom.ts similarity index 100% rename from packages/map/src/handler/tap/tap_zoom.ts rename to packages/map/src/map/handler/tap/tap_zoom.ts diff --git a/packages/map/src/handler/touch/index.ts b/packages/map/src/map/handler/touch/index.ts similarity index 100% rename from packages/map/src/handler/touch/index.ts rename to packages/map/src/map/handler/touch/index.ts diff --git a/packages/map/src/handler/touch/touch_pan.ts b/packages/map/src/map/handler/touch/touch_pan.ts similarity index 100% rename from packages/map/src/handler/touch/touch_pan.ts rename to packages/map/src/map/handler/touch/touch_pan.ts diff --git a/packages/map/src/handler/touch/touch_pitch.ts b/packages/map/src/map/handler/touch/touch_pitch.ts similarity index 100% rename from packages/map/src/handler/touch/touch_pitch.ts rename to packages/map/src/map/handler/touch/touch_pitch.ts diff --git a/packages/map/src/handler/touch/touch_rotate.ts b/packages/map/src/map/handler/touch/touch_rotate.ts similarity index 100% rename from packages/map/src/handler/touch/touch_rotate.ts rename to packages/map/src/map/handler/touch/touch_rotate.ts diff --git a/packages/map/src/handler/touch/touch_zoom.ts b/packages/map/src/map/handler/touch/touch_zoom.ts similarity index 100% rename from packages/map/src/handler/touch/touch_zoom.ts rename to packages/map/src/map/handler/touch/touch_zoom.ts diff --git a/packages/map/src/handler/touch/two_touch.ts b/packages/map/src/map/handler/touch/two_touch.ts similarity index 100% rename from packages/map/src/handler/touch/two_touch.ts rename to packages/map/src/map/handler/touch/two_touch.ts diff --git a/packages/map/src/hash.ts b/packages/map/src/map/hash.ts similarity index 100% rename from packages/map/src/hash.ts rename to packages/map/src/map/hash.ts diff --git a/packages/map/src/interface.ts b/packages/map/src/map/interface.ts similarity index 94% rename from packages/map/src/interface.ts rename to packages/map/src/map/interface.ts index a33eb93060f..fe668a43f72 100644 --- a/packages/map/src/interface.ts +++ b/packages/map/src/map/interface.ts @@ -1,5 +1,9 @@ import type { LngLatBoundsLike } from './geo/lng_lat_bounds'; +/** + * @deprecated + * 请使用 MapOptions + */ export interface IMapOptions { hash: boolean; style?: any; diff --git a/packages/map/src/map.ts b/packages/map/src/map/map.ts similarity index 99% rename from packages/map/src/map.ts rename to packages/map/src/map/map.ts index ec6c7d7f2aa..b363fc24b01 100644 --- a/packages/map/src/map.ts +++ b/packages/map/src/map/map.ts @@ -1,6 +1,6 @@ import { DOM, lodashUtil } from '@antv/l7-utils'; import Camera from './camera'; -import './css/l7.css'; +// import './css/l7.css'; import type { LngLatLike } from './geo/lng_lat'; import LngLat from './geo/lng_lat'; import type { LngLatBoundsLike } from './geo/lng_lat_bounds'; @@ -74,6 +74,10 @@ const DefaultOptions: IMapOptions = { pitchEnabled: true, rotateEnabled: true, }; + +/** + * @deprecated + */ export class Map extends Camera { public doubleClickZoom: DoubleClickZoomHandler; public dragRotate: DragRotateHandler; diff --git a/packages/map/src/util.ts b/packages/map/src/map/util.ts similarity index 100% rename from packages/map/src/util.ts rename to packages/map/src/map/util.ts diff --git a/packages/map/src/utils/Aabb.ts b/packages/map/src/map/utils/Aabb.ts similarity index 100% rename from packages/map/src/utils/Aabb.ts rename to packages/map/src/map/utils/Aabb.ts diff --git a/packages/map/src/utils/dom.ts b/packages/map/src/map/utils/dom.ts similarity index 100% rename from packages/map/src/utils/dom.ts rename to packages/map/src/map/utils/dom.ts diff --git a/packages/map/src/utils/performance.ts b/packages/map/src/map/utils/performance.ts similarity index 100% rename from packages/map/src/utils/performance.ts rename to packages/map/src/map/utils/performance.ts diff --git a/packages/map/src/utils/primitives.ts b/packages/map/src/map/utils/primitives.ts similarity index 100% rename from packages/map/src/utils/primitives.ts rename to packages/map/src/map/utils/primitives.ts diff --git a/packages/map/src/utils/task_queue.ts b/packages/map/src/map/utils/task_queue.ts similarity index 100% rename from packages/map/src/utils/task_queue.ts rename to packages/map/src/map/utils/task_queue.ts diff --git a/packages/maps/src/bmap/index.ts b/packages/maps/src/bmap/index.ts index 6abba1cbc1f..744d924b71b 100644 --- a/packages/maps/src/bmap/index.ts +++ b/packages/maps/src/bmap/index.ts @@ -1,7 +1,6 @@ -import type { Map } from '@antv/l7-map'; import BaseMapWrapper from '../utils/BaseMapWrapper'; import MapService from './map'; -export default class MapboxWrapper extends BaseMapWrapper { +export default class MapboxWrapper extends BaseMapWrapper { protected getServiceConstructor() { return MapService; } diff --git a/packages/maps/src/earth/index.ts b/packages/maps/src/earth/index.ts index 8374d687d70..bf6b5c5770b 100644 --- a/packages/maps/src/earth/index.ts +++ b/packages/maps/src/earth/index.ts @@ -1,7 +1,7 @@ -import type { Map } from '@antv/l7-map'; +import type { MapNext } from '@antv/l7-map'; import BaseMapWrapper from '../utils/BaseMapWrapper'; import MapService from './map'; -export default class EarthWrapper extends BaseMapWrapper { +export default class EarthWrapper extends BaseMapWrapper { protected getServiceConstructor() { return MapService; } diff --git a/packages/maps/src/earth/map.ts b/packages/maps/src/earth/map.ts index 9cd05b0801e..1f56709e7fc 100644 --- a/packages/maps/src/earth/map.ts +++ b/packages/maps/src/earth/map.ts @@ -4,8 +4,7 @@ */ import type { IEarthService, IMercator, IViewport } from '@antv/l7-core'; import { CoordinateSystem, MapServiceEvent } from '@antv/l7-core'; -import type { Map } from '@antv/l7-map'; -import { EarthMap } from '@antv/l7-map'; +import type { MapNext } from '@antv/l7-map'; import BaseMapService from '../utils/BaseMapService'; import Viewport from './Viewport'; const EventMap: { @@ -21,7 +20,7 @@ const LNGLAT_OFFSET_ZOOM_THRESHOLD = 12; /** * EarthService */ -export default class L7EarthService extends BaseMapService implements IEarthService { +export default class L7EarthService extends BaseMapService implements IEarthService { public lngLatToMercator(lnglat: [number, number], altitude: number): IMercator { throw new Error('Method not implemented.'); } diff --git a/packages/maps/src/map/index.ts b/packages/maps/src/map/index.ts index 6abba1cbc1f..1fb2da59044 100644 --- a/packages/maps/src/map/index.ts +++ b/packages/maps/src/map/index.ts @@ -1,7 +1,7 @@ -import type { Map } from '@antv/l7-map'; +import type { MapNext } from '@antv/l7-map'; import BaseMapWrapper from '../utils/BaseMapWrapper'; import MapService from './map'; -export default class MapboxWrapper extends BaseMapWrapper { +export default class MapboxWrapper extends BaseMapWrapper { protected getServiceConstructor() { return MapService; } diff --git a/packages/maps/src/map/map.ts b/packages/maps/src/map/map.ts index 48dc28d6148..9695e570b05 100644 --- a/packages/maps/src/map/map.ts +++ b/packages/maps/src/map/map.ts @@ -3,14 +3,14 @@ * MapboxService */ import type { IMercator } from '@antv/l7-core'; -import { Map, MercatorCoordinate } from '@antv/l7-map'; +import { MapNext, MercatorCoordinate } from '@antv/l7-map'; import { mat4, vec3 } from 'gl-matrix'; import Viewport from '../lib/web-mercator-viewport'; import { MapType } from '../types'; import BaseMapService from '../utils/BaseMapService'; // TODO: 基于抽象类 BaseMap 实现 -export default class DefaultMapService extends BaseMapService { +export default class DefaultMapService extends BaseMapService { public version: string = MapType.DEFAULT; /** * 将经纬度转成墨卡托坐标 @@ -90,9 +90,8 @@ export default class DefaultMapService extends BaseMapService { } else { this.$mapContainer = this.creatMapContainer(id); // @ts-ignore - this.map = new Map({ + this.map = new MapNext({ container: this.$mapContainer, - style: this.getMapStyleValue(style), bearing: rotation, ...rest, }); @@ -130,12 +129,7 @@ export default class DefaultMapService extends BaseMapService { } public exportMap(type: 'jpg' | 'png'): string { - const renderCanvas = this.map.getCanvas(); - const layersPng = - type === 'jpg' - ? (renderCanvas?.toDataURL('image/jpeg') as string) - : (renderCanvas?.toDataURL('image/png') as string); - return layersPng; + return ''; } public getCanvasOverlays() { diff --git a/packages/maps/src/utils/BaseMapService.ts b/packages/maps/src/utils/BaseMapService.ts index 6ea3658f106..d93774a728d 100644 --- a/packages/maps/src/utils/BaseMapService.ts +++ b/packages/maps/src/utils/BaseMapService.ts @@ -18,7 +18,7 @@ import type { MapStyleName, } from '@antv/l7-core'; import { CoordinateSystem, MapServiceEvent } from '@antv/l7-core'; -import type { Map } from '@antv/l7-map'; +import type { MapNext } from '@antv/l7-map'; import { DOM } from '@antv/l7-utils'; import { EventEmitter } from 'eventemitter3'; import type { ISimpleMapCoord } from './simpleMapCoord'; @@ -35,9 +35,9 @@ const EventMap: { const LNGLAT_OFFSET_ZOOM_THRESHOLD = 12; -export default abstract class BaseMapService implements IMapService { +export default abstract class BaseMapService implements IMapService { public version: string = 'DEFAUlTMAP'; - public map: Map & T; + public map: MapNext & T; public simpleMapCoord: ISimpleMapCoord = new SimpleMapCoord(); // 背景色 public bgColor: string = 'rgba(0.0, 0.0, 0.0, 0.0)'; @@ -230,7 +230,8 @@ export default abstract class BaseMapService implements IMapService } public setMapStyle(style: any): void { - this.map.setStyle(this.getMapStyleValue(style)); + // @ts-ignore + this.map?.setStyle(this.getMapStyleValue(style)); } // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -307,7 +308,8 @@ export default abstract class BaseMapService implements IMapService } public exportMap(type: 'jpg' | 'png'): string { - const renderCanvas = this.map.getCanvas(); + // @ts-ignore + const renderCanvas = this.map?.getCanvas(); const layersPng = type === 'jpg' ? (renderCanvas?.toDataURL('image/jpeg') as string)