@trismegisto/maps 3.4.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION.md +831 -0
- package/NOTICE +3 -36
- package/README.md +19 -5
- package/dist/src/core/basemap.d.ts +5 -5
- package/dist/src/core/basemap.js +1 -1
- package/dist/src/core/basemap.js.map +1 -1
- package/dist/src/core/cluster-groups.d.ts +3 -3
- package/dist/src/core/cluster-groups.js.map +1 -1
- package/dist/src/core/engine.d.ts +22 -18
- package/dist/src/core/engine.js +36 -32
- package/dist/src/core/engine.js.map +1 -1
- package/dist/src/core/geo.d.ts +17 -17
- package/dist/src/core/geo.js +12 -12
- package/dist/src/core/geo.js.map +1 -1
- package/dist/src/core/geojson.d.ts +5 -5
- package/dist/src/core/geojson.js +7 -7
- package/dist/src/core/geojson.js.map +1 -1
- package/dist/src/core/interactions.d.ts +13 -36
- package/dist/src/core/interactions.js +64 -249
- package/dist/src/core/interactions.js.map +1 -1
- package/dist/src/core/map-layers.d.ts +13 -13
- package/dist/src/core/map-layers.js +7 -7
- package/dist/src/core/map-layers.js.map +1 -1
- package/dist/src/core/projection.d.ts +8 -8
- package/dist/src/core/projection.js +7 -7
- package/dist/src/core/projection.js.map +1 -1
- package/dist/src/core/route-view.d.ts +4 -4
- package/dist/src/core/route-view.js +5 -5
- package/dist/src/core/route-view.js.map +1 -1
- package/dist/src/core/route.d.ts +8 -8
- package/dist/src/core/route.js +11 -11
- package/dist/src/core/route.js.map +1 -1
- package/dist/src/core/shapes.d.ts +6 -6
- package/dist/src/core/shapes.js +5 -5
- package/dist/src/core/shapes.js.map +1 -1
- package/dist/src/core/tiles.d.ts +25 -17
- package/dist/src/core/tiles.js +32 -31
- package/dist/src/core/tiles.js.map +1 -1
- package/dist/src/core/vector.d.ts +5 -5
- package/dist/src/core/vector.js +3 -3
- package/dist/src/core/vector.js.map +1 -1
- package/dist/src/core/view.d.ts +12 -12
- package/dist/src/core/view.js +27 -27
- package/dist/src/core/view.js.map +1 -1
- package/package.json +4 -3
package/dist/src/core/geo.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
* Tipos e utilitários geográficos e de geometria plana, sem framework.
|
|
3
3
|
*
|
|
4
4
|
* Coordenadas geográficas são sempre `{ lat, lng }` em graus (WGS 84). Pontos de tela são `{ x, y }` em
|
|
5
|
-
* pixels CSS. As entradas públicas também aceitam a tupla `[lat, lng]` (`
|
|
6
|
-
* `
|
|
5
|
+
* pixels CSS. As entradas públicas também aceitam a tupla `[lat, lng]` (`GeoPointInput`), normalizada por
|
|
6
|
+
* `toGeoPoint` — GeoJSON é a única exceção (lá a ordem é `[lng, lat]`, como manda a especificação).
|
|
7
7
|
*/
|
|
8
8
|
export function point(x, y) {
|
|
9
9
|
return { x, y };
|
|
10
10
|
}
|
|
11
|
-
export function
|
|
11
|
+
export function geoPoint(lat, lng) {
|
|
12
12
|
return { lat, lng };
|
|
13
13
|
}
|
|
14
|
-
export function
|
|
14
|
+
export function toGeoPoint(value) {
|
|
15
15
|
if (isTuple(value))
|
|
16
16
|
return { lat: Number(value[0]), lng: Number(value[1]) };
|
|
17
17
|
return { lat: Number(value.lat), lng: Number(value.lng) };
|
|
@@ -19,7 +19,7 @@ export function toLatLng(value) {
|
|
|
19
19
|
function isTuple(value) {
|
|
20
20
|
return Array.isArray(value);
|
|
21
21
|
}
|
|
22
|
-
export function
|
|
22
|
+
export function isGeoBox(value) {
|
|
23
23
|
return (!!value &&
|
|
24
24
|
typeof value === 'object' &&
|
|
25
25
|
!Array.isArray(value) &&
|
|
@@ -28,10 +28,10 @@ export function isLatLngBounds(value) {
|
|
|
28
28
|
'north' in value &&
|
|
29
29
|
'east' in value);
|
|
30
30
|
}
|
|
31
|
-
export function
|
|
32
|
-
if (
|
|
31
|
+
export function toGeoBox(value) {
|
|
32
|
+
if (isGeoBox(value))
|
|
33
33
|
return value;
|
|
34
|
-
const [a, b] = value.map(
|
|
34
|
+
const [a, b] = value.map(toGeoPoint);
|
|
35
35
|
return {
|
|
36
36
|
south: Math.min(a.lat, b.lat),
|
|
37
37
|
west: Math.min(a.lng, b.lng),
|
|
@@ -40,7 +40,7 @@ export function toLatLngBounds(value) {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
/** Menor retângulo que contém todos os pontos. `null` sem pontos. */
|
|
43
|
-
export function
|
|
43
|
+
export function boxOf(points) {
|
|
44
44
|
let south = Infinity;
|
|
45
45
|
let west = Infinity;
|
|
46
46
|
let north = -Infinity;
|
|
@@ -55,10 +55,10 @@ export function boundsOf(points) {
|
|
|
55
55
|
}
|
|
56
56
|
return south === Infinity ? null : { south, west, north, east };
|
|
57
57
|
}
|
|
58
|
-
export function
|
|
58
|
+
export function boxCenter(bounds) {
|
|
59
59
|
return { lat: (bounds.south + bounds.north) / 2, lng: (bounds.west + bounds.east) / 2 };
|
|
60
60
|
}
|
|
61
|
-
export function
|
|
61
|
+
export function boxContains(bounds, p) {
|
|
62
62
|
return p.lat >= bounds.south && p.lat <= bounds.north && p.lng >= bounds.west && p.lng <= bounds.east;
|
|
63
63
|
}
|
|
64
64
|
export function addPoints(a, b) {
|
|
@@ -73,7 +73,7 @@ export function scalePoint(a, k) {
|
|
|
73
73
|
export function roundPoint(a) {
|
|
74
74
|
return { x: Math.round(a.x), y: Math.round(a.y) };
|
|
75
75
|
}
|
|
76
|
-
export function
|
|
76
|
+
export function sameGeoPoint(a, b, epsilon = 1e-9) {
|
|
77
77
|
return Math.abs(a.lat - b.lat) <= epsilon && Math.abs(a.lng - b.lng) <= epsilon;
|
|
78
78
|
}
|
|
79
79
|
/** Distância em metros pela fórmula de haversine (esfera de raio médio). */
|
package/dist/src/core/geo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geo.js","sourceRoot":"","sources":["../../../src/core/geo.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgCH,MAAM,UAAU,KAAK,CAAC,CAAS,EAAE,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C,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,OAAO,CAAC,GAAW;IACjC,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;IAC1D,OAAO,OAAO,KAAK,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC;AACrD,CAAC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, GeometryCollection, Feature e
|
|
4
4
|
* FeatureCollection. Coordenadas GeoJSON são `[lng, lat]`; aqui viram `{ lat, lng }`.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { GeoPoint, GeoBox } from './geo';
|
|
7
7
|
export type GeoJsonPosition = readonly number[];
|
|
8
8
|
export interface GeoJsonPoint {
|
|
9
9
|
readonly type: 'Point';
|
|
@@ -51,18 +51,18 @@ export type GeoShape = {
|
|
|
51
51
|
readonly kind: 'point';
|
|
52
52
|
readonly feature: GeoJsonFeature;
|
|
53
53
|
readonly featureIndex: number;
|
|
54
|
-
readonly position:
|
|
54
|
+
readonly position: GeoPoint;
|
|
55
55
|
} | {
|
|
56
56
|
readonly kind: 'line' | 'area';
|
|
57
57
|
readonly feature: GeoJsonFeature;
|
|
58
58
|
readonly featureIndex: number;
|
|
59
59
|
/** Linhas (kind `line`) ou anéis — externo e furos — de um polígono (kind `area`). */
|
|
60
|
-
readonly rings: readonly (readonly
|
|
60
|
+
readonly rings: readonly (readonly GeoPoint[])[];
|
|
61
61
|
};
|
|
62
|
-
export declare function
|
|
62
|
+
export declare function positionToGeo(position: GeoJsonPosition): GeoPoint;
|
|
63
63
|
/** Lista de features do objeto: geometria solta vira uma feature sem propriedades. */
|
|
64
64
|
export declare function geoJsonFeatures(data: GeoJsonObject | null | undefined): GeoJsonFeature[];
|
|
65
65
|
/** Converte o GeoJSON em formas. Geometria desconhecida ou malformada é ignorada (não quebra o mapa). */
|
|
66
66
|
export declare function geoJsonShapes(data: GeoJsonObject | null | undefined): GeoShape[];
|
|
67
67
|
/** Retângulo que contém todas as formas. `null` se não há coordenadas. */
|
|
68
|
-
export declare function
|
|
68
|
+
export declare function geoJsonBox(data: GeoJsonObject | null | undefined): GeoBox | null;
|
package/dist/src/core/geojson.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, GeometryCollection, Feature e
|
|
4
4
|
* FeatureCollection. Coordenadas GeoJSON são `[lng, lat]`; aqui viram `{ lat, lng }`.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
export function
|
|
6
|
+
import { boxOf } from './geo';
|
|
7
|
+
export function positionToGeo(position) {
|
|
8
8
|
return { lat: Number(position[1]), lng: Number(position[0]) };
|
|
9
9
|
}
|
|
10
10
|
/** Lista de features do objeto: geometria solta vira uma feature sem propriedades. */
|
|
@@ -30,16 +30,16 @@ export function geoJsonShapes(data) {
|
|
|
30
30
|
return shapes;
|
|
31
31
|
}
|
|
32
32
|
function collect(geometry, feature, featureIndex, out) {
|
|
33
|
-
const ring = (coords) => (Array.isArray(coords) ? coords.filter(isPosition).map(
|
|
33
|
+
const ring = (coords) => (Array.isArray(coords) ? coords.filter(isPosition).map(positionToGeo) : []);
|
|
34
34
|
switch (geometry.type) {
|
|
35
35
|
case 'Point':
|
|
36
36
|
if (isPosition(geometry.coordinates))
|
|
37
|
-
out.push({ kind: 'point', feature, featureIndex, position:
|
|
37
|
+
out.push({ kind: 'point', feature, featureIndex, position: positionToGeo(geometry.coordinates) });
|
|
38
38
|
break;
|
|
39
39
|
case 'MultiPoint':
|
|
40
40
|
for (const p of geometry.coordinates ?? []) {
|
|
41
41
|
if (isPosition(p))
|
|
42
|
-
out.push({ kind: 'point', feature, featureIndex, position:
|
|
42
|
+
out.push({ kind: 'point', feature, featureIndex, position: positionToGeo(p) });
|
|
43
43
|
}
|
|
44
44
|
break;
|
|
45
45
|
case 'LineString':
|
|
@@ -66,7 +66,7 @@ function isPosition(value) {
|
|
|
66
66
|
return Array.isArray(value) && value.length >= 2 && Number.isFinite(value[0]) && Number.isFinite(value[1]);
|
|
67
67
|
}
|
|
68
68
|
/** Retângulo que contém todas as formas. `null` se não há coordenadas. */
|
|
69
|
-
export function
|
|
69
|
+
export function geoJsonBox(data) {
|
|
70
70
|
const points = [];
|
|
71
71
|
for (const shape of geoJsonShapes(data)) {
|
|
72
72
|
if (shape.kind === 'point')
|
|
@@ -75,6 +75,6 @@ export function geoJsonBounds(data) {
|
|
|
75
75
|
for (const ring of shape.rings)
|
|
76
76
|
points.push(...ring);
|
|
77
77
|
}
|
|
78
|
-
return
|
|
78
|
+
return boxOf(points);
|
|
79
79
|
}
|
|
80
80
|
//# sourceMappingURL=geojson.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geojson.js","sourceRoot":"","sources":["../../../src/core/geojson.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"geojson.js","sourceRoot":"","sources":["../../../src/core/geojson.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAoB,KAAK,EAAE,MAAM,OAAO,CAAC;AAqEhD,MAAM,UAAU,aAAa,CAAC,QAAyB;IACrD,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAChE,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,eAAe,CAAC,IAAsC;IACpE,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC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YAC9H,MAAM;QACR,KAAK,oBAAoB;YACvB,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,UAAU,IAAI,EAAE;gBAAE,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC;YAClF,MAAM;IACV,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7G,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CAAC,IAAsC;IAC/D,MAAM,MAAM,GAAe,EAAE,CAAC;IAC9B,KAAK,MAAM,KAAK,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO;YAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;;YACnD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK;gBAAE,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gestos do mapa sobre `MapEngine`, por pointer events (mouse, caneta e toque com o mesmo código):
|
|
3
|
-
* arrastar com inércia, pinça, roda do mouse/trackpad, duplo clique e teclado.
|
|
4
|
-
*
|
|
5
|
-
* Elementos com `data-hm-map-nodrag` (controles, popups) não iniciam arrasto nem zoom por duplo clique.
|
|
6
|
-
*/
|
|
7
1
|
import { Point } from './geo';
|
|
8
2
|
import { MapEngine } from './engine';
|
|
9
3
|
export interface InteractionOptions {
|
|
10
|
-
readonly
|
|
4
|
+
readonly drag: boolean;
|
|
11
5
|
readonly inertia: boolean;
|
|
12
|
-
readonly
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
6
|
+
readonly wheelZoom: boolean;
|
|
7
|
+
readonly doubleTapZoom: boolean;
|
|
8
|
+
readonly pinchZoom: boolean;
|
|
15
9
|
readonly keyboard: boolean;
|
|
16
10
|
/** Pixels por toque de seta. */
|
|
17
|
-
readonly
|
|
11
|
+
readonly keyStep: number;
|
|
18
12
|
/** Quanto de rolagem (px) equivale a um nível de zoom. */
|
|
19
|
-
readonly
|
|
13
|
+
readonly wheelStep: number;
|
|
20
14
|
}
|
|
21
15
|
export declare const DEFAULT_INTERACTIONS: InteractionOptions;
|
|
22
16
|
export type KeyboardAction = {
|
|
@@ -31,6 +25,11 @@ export type KeyboardAction = {
|
|
|
31
25
|
* (3 níveis com Shift). Outra tecla: `null`.
|
|
32
26
|
*/
|
|
33
27
|
export declare function keyboardAction(event: Pick<KeyboardEvent, 'key' | 'shiftKey' | 'altKey' | 'ctrlKey' | 'metaKey'>, panDelta?: number): KeyboardAction | null;
|
|
28
|
+
/**
|
|
29
|
+
* Os gestos de ponteiro (arrasto com inércia, pinça, roda, duplo clique) são o controlador sem framework
|
|
30
|
+
* `ViewportGestures` do primitives, ligado ao `MapEngine` por um adaptador: o zoom do mapa anda em níveis inteiros
|
|
31
|
+
* (a roda sobe um nível por degrau e a pinça arredonda no fim). O teclado continua aqui (é do mapa).
|
|
32
|
+
*/
|
|
34
33
|
export declare class MapInteractions {
|
|
35
34
|
private readonly el;
|
|
36
35
|
private readonly engine;
|
|
@@ -38,39 +37,17 @@ export declare class MapInteractions {
|
|
|
38
37
|
/** Chamado quando uma tecla de mapa foi tratada (o app pode anunciar o novo estado). */
|
|
39
38
|
private readonly onKeyboard?;
|
|
40
39
|
private options;
|
|
41
|
-
private readonly
|
|
42
|
-
private dragStart;
|
|
43
|
-
private dragLast;
|
|
44
|
-
private dragging;
|
|
45
|
-
private samples;
|
|
46
|
-
private pinch;
|
|
47
|
-
private suppressClick;
|
|
48
|
-
private wheelAcc;
|
|
49
|
-
private wheelLastZoom;
|
|
50
|
-
private wheelResetTimer;
|
|
51
|
-
private animation;
|
|
40
|
+
private readonly gestures;
|
|
52
41
|
private readonly cleanup;
|
|
53
42
|
constructor(el: HTMLElement, engine: MapEngine, options?: Partial<InteractionOptions>, reducedMotion?: () => boolean,
|
|
54
43
|
/** Chamado quando uma tecla de mapa foi tratada (o app pode anunciar o novo estado). */
|
|
55
44
|
onKeyboard?: ((action: KeyboardAction) => void) | undefined);
|
|
45
|
+
private gestureOptions;
|
|
56
46
|
setOptions(options: Partial<InteractionOptions>): void;
|
|
57
47
|
/** Interrompe a inércia em andamento. */
|
|
58
48
|
stop(): void;
|
|
59
49
|
destroy(): void;
|
|
60
50
|
/** Executa a ação de teclado (exposto para controles e testes). */
|
|
61
51
|
applyKeyboard(action: KeyboardAction): void;
|
|
62
|
-
private on;
|
|
63
|
-
private local;
|
|
64
|
-
private blocked;
|
|
65
|
-
private pointerDown;
|
|
66
|
-
private pointerMove;
|
|
67
|
-
private pointerUp;
|
|
68
|
-
private endPinch;
|
|
69
|
-
private endDrag;
|
|
70
|
-
private animatePan;
|
|
71
|
-
private wheel;
|
|
72
|
-
private dblclick;
|
|
73
52
|
private keydown;
|
|
74
|
-
private capture;
|
|
75
|
-
private release;
|
|
76
53
|
}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gestos do mapa sobre `MapEngine`, por pointer events (mouse, caneta e toque com o mesmo código):
|
|
3
|
+
* arrastar com inércia, pinça, roda do mouse/trackpad, duplo clique e teclado.
|
|
4
|
+
*
|
|
5
|
+
* Elementos com `data-hm-map-nodrag` (controles, popups) não iniciam arrasto nem zoom por duplo clique.
|
|
6
|
+
*/
|
|
7
|
+
import { ViewportGestures } from '@trismegisto/primitives/viewport-gestures';
|
|
1
8
|
export const DEFAULT_INTERACTIONS = {
|
|
2
|
-
|
|
9
|
+
drag: true,
|
|
3
10
|
inertia: true,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
wheelZoom: true,
|
|
12
|
+
doubleTapZoom: true,
|
|
13
|
+
pinchZoom: true,
|
|
7
14
|
keyboard: true,
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
keyStep: 80,
|
|
16
|
+
wheelStep: 60,
|
|
10
17
|
};
|
|
11
18
|
/**
|
|
12
19
|
* Ação de uma tecla: setas movem `panDelta` px (×3 com Shift); `+`/`=` aproximam e `-`/`_` afastam
|
|
@@ -42,30 +49,22 @@ export function keyboardAction(event, panDelta = 80) {
|
|
|
42
49
|
return null;
|
|
43
50
|
}
|
|
44
51
|
}
|
|
45
|
-
/**
|
|
46
|
-
const INERTIA_DECELERATION = 3400;
|
|
47
|
-
const INERTIA_MAX_SPEED = 1500;
|
|
48
|
-
/** Linearidade da curva de saída: 0,4 → potência 2,5 (freia forte no fim, sem arremessar longe). */
|
|
49
|
-
const EASE_LINEARITY = 0.4;
|
|
50
|
-
/** Deslocamento mínimo (px) para um toque virar arrasto (abaixo disso é clique). */
|
|
52
|
+
/** Deslocamento mínimo (px) para um toque virar arrasto no mapa (abaixo disso é clique). */
|
|
51
53
|
const DRAG_THRESHOLD = 3;
|
|
54
|
+
/** Intervalo mínimo (ms) entre dois níveis de zoom pela roda. */
|
|
55
|
+
const WHEEL_MIN_INTERVAL = 60;
|
|
56
|
+
/**
|
|
57
|
+
* Os gestos de ponteiro (arrasto com inércia, pinça, roda, duplo clique) são o controlador sem framework
|
|
58
|
+
* `ViewportGestures` do primitives, ligado ao `MapEngine` por um adaptador: o zoom do mapa anda em níveis inteiros
|
|
59
|
+
* (a roda sobe um nível por degrau e a pinça arredonda no fim). O teclado continua aqui (é do mapa).
|
|
60
|
+
*/
|
|
52
61
|
export class MapInteractions {
|
|
53
62
|
el;
|
|
54
63
|
engine;
|
|
55
64
|
reducedMotion;
|
|
56
65
|
onKeyboard;
|
|
57
66
|
options;
|
|
58
|
-
|
|
59
|
-
dragStart = null;
|
|
60
|
-
dragLast = null;
|
|
61
|
-
dragging = false;
|
|
62
|
-
samples = [];
|
|
63
|
-
pinch = null;
|
|
64
|
-
suppressClick = false;
|
|
65
|
-
wheelAcc = 0;
|
|
66
|
-
wheelLastZoom = 0;
|
|
67
|
-
wheelResetTimer = null;
|
|
68
|
-
animation = 0;
|
|
67
|
+
gestures;
|
|
69
68
|
cleanup = [];
|
|
70
69
|
constructor(el, engine, options = {}, reducedMotion = () => false,
|
|
71
70
|
/** Chamado quando uma tecla de mapa foi tratada (o app pode anunciar o novo estado). */
|
|
@@ -75,37 +74,55 @@ export class MapInteractions {
|
|
|
75
74
|
this.reducedMotion = reducedMotion;
|
|
76
75
|
this.onKeyboard = onKeyboard;
|
|
77
76
|
this.options = { ...DEFAULT_INTERACTIONS, ...options };
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
77
|
+
const target = {
|
|
78
|
+
panBy: (dx, dy) => {
|
|
79
|
+
this.engine.panBy({ x: dx, y: dy });
|
|
80
|
+
},
|
|
81
|
+
zoomAround: (factor, at) => this.engine.zoomBy(Math.round(Math.log2(factor)), at),
|
|
82
|
+
settle: () => this.engine.settle(),
|
|
83
|
+
zoomLimits: () => [Math.pow(2, this.engine.minZoom - this.engine.zoom), Math.pow(2, this.engine.maxZoom - this.engine.zoom)],
|
|
84
|
+
previewPinch: (scale, startCenter, center) => this.engine.preview(scale, startCenter, center),
|
|
85
|
+
commitPinch: (scale, startCenter, center) => {
|
|
86
|
+
this.engine.clearPreview();
|
|
87
|
+
// O conteúdo que estava sob o centro inicial da pinça termina sob o centro final.
|
|
88
|
+
this.engine.panBy({ x: startCenter.x - center.x, y: startCenter.y - center.y });
|
|
89
|
+
const zoom = Math.round(this.engine.zoom + Math.log2(scale));
|
|
90
|
+
if (zoom !== this.engine.zoom)
|
|
91
|
+
this.engine.zoomTo(zoom, center);
|
|
92
|
+
else
|
|
93
|
+
this.engine.settle();
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
this.gestures = new ViewportGestures(el, target, this.gestureOptions());
|
|
97
|
+
const keydown = (e) => this.keydown(e);
|
|
98
|
+
el.addEventListener('keydown', keydown);
|
|
99
|
+
this.cleanup.push(() => el.removeEventListener('keydown', keydown));
|
|
100
|
+
}
|
|
101
|
+
gestureOptions() {
|
|
102
|
+
const o = this.options;
|
|
103
|
+
return {
|
|
104
|
+
pan: o.drag,
|
|
105
|
+
inertia: o.inertia,
|
|
106
|
+
pinch: o.pinchZoom,
|
|
107
|
+
wheel: o.wheelZoom ? 'zoom' : 'off',
|
|
108
|
+
wheelMode: { kind: 'stepped', pxPerStep: o.wheelStep, stepFactor: 2, minInterval: WHEEL_MIN_INTERVAL },
|
|
109
|
+
doubleClickFactor: o.doubleTapZoom ? 2 : 0,
|
|
110
|
+
dragThreshold: { mouse: DRAG_THRESHOLD, touch: DRAG_THRESHOLD },
|
|
111
|
+
ignoreSelector: '[data-hm-map-nodrag]',
|
|
112
|
+
draggingClass: 'hm-map--dragging',
|
|
113
|
+
reducedMotion: this.reducedMotion,
|
|
114
|
+
};
|
|
93
115
|
}
|
|
94
116
|
setOptions(options) {
|
|
95
117
|
this.options = { ...this.options, ...options };
|
|
118
|
+
this.gestures.setOptions(this.gestureOptions());
|
|
96
119
|
}
|
|
97
120
|
/** Interrompe a inércia em andamento. */
|
|
98
121
|
stop() {
|
|
99
|
-
|
|
100
|
-
cancelAnimationFrame(this.animation);
|
|
101
|
-
this.animation = 0;
|
|
102
|
-
this.engine.settle();
|
|
103
|
-
}
|
|
122
|
+
this.gestures.stop();
|
|
104
123
|
}
|
|
105
124
|
destroy() {
|
|
106
|
-
this.
|
|
107
|
-
if (this.wheelResetTimer)
|
|
108
|
-
clearTimeout(this.wheelResetTimer);
|
|
125
|
+
this.gestures.destroy();
|
|
109
126
|
for (const off of this.cleanup)
|
|
110
127
|
off();
|
|
111
128
|
this.cleanup.length = 0;
|
|
@@ -121,218 +138,16 @@ export class MapInteractions {
|
|
|
121
138
|
this.engine.zoomBy(action.delta);
|
|
122
139
|
}
|
|
123
140
|
}
|
|
124
|
-
// ---------------------------------------------------------------- eventos
|
|
125
|
-
on(type, handler, options) {
|
|
126
|
-
this.el.addEventListener(type, handler, options);
|
|
127
|
-
this.cleanup.push(() => this.el.removeEventListener(type, handler, options));
|
|
128
|
-
}
|
|
129
|
-
local(e) {
|
|
130
|
-
const rect = this.el.getBoundingClientRect();
|
|
131
|
-
return { x: e.clientX - rect.left, y: e.clientY - rect.top };
|
|
132
|
-
}
|
|
133
|
-
blocked(target) {
|
|
134
|
-
return target instanceof Element && !!target.closest('[data-hm-map-nodrag]');
|
|
135
|
-
}
|
|
136
|
-
pointerDown(e) {
|
|
137
|
-
if (e.pointerType === 'mouse' && e.button !== 0)
|
|
138
|
-
return;
|
|
139
|
-
if (this.blocked(e.target))
|
|
140
|
-
return;
|
|
141
|
-
this.stop();
|
|
142
|
-
this.pointers.set(e.pointerId, this.local(e));
|
|
143
|
-
if (this.pointers.size === 2 && this.options.touchZoom) {
|
|
144
|
-
this.endDrag(false);
|
|
145
|
-
const [a, b] = [...this.pointers.values()];
|
|
146
|
-
const center = mid(a, b);
|
|
147
|
-
this.pinch = { startDist: Math.max(dist(a, b), 1), startCenter: center, center, scale: 1 };
|
|
148
|
-
this.capture(e);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
if (this.pointers.size === 1 && this.options.dragging) {
|
|
152
|
-
const p = this.local(e);
|
|
153
|
-
this.dragStart = p;
|
|
154
|
-
this.dragLast = p;
|
|
155
|
-
this.dragging = false;
|
|
156
|
-
this.samples = [{ t: performance.now(), p }];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
pointerMove(e) {
|
|
160
|
-
if (!this.pointers.has(e.pointerId))
|
|
161
|
-
return;
|
|
162
|
-
const p = this.local(e);
|
|
163
|
-
this.pointers.set(e.pointerId, p);
|
|
164
|
-
if (this.pinch && this.pointers.size >= 2) {
|
|
165
|
-
const [a, b] = [...this.pointers.values()];
|
|
166
|
-
const scale = dist(a, b) / this.pinch.startDist;
|
|
167
|
-
// O zoom resultante não pode passar dos limites: a prévia para no mesmo teto.
|
|
168
|
-
const minScale = Math.pow(2, this.engine.minZoom - this.engine.zoom);
|
|
169
|
-
const maxScale = Math.pow(2, this.engine.maxZoom - this.engine.zoom);
|
|
170
|
-
this.pinch.scale = Math.max(minScale, Math.min(maxScale, scale));
|
|
171
|
-
this.pinch.center = mid(a, b);
|
|
172
|
-
this.engine.preview(this.pinch.scale, this.pinch.startCenter, this.pinch.center);
|
|
173
|
-
e.preventDefault();
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if (!this.dragStart || !this.dragLast)
|
|
177
|
-
return;
|
|
178
|
-
if (!this.dragging) {
|
|
179
|
-
if (dist(p, this.dragStart) < DRAG_THRESHOLD)
|
|
180
|
-
return;
|
|
181
|
-
this.dragging = true;
|
|
182
|
-
this.el.classList.add('hm-map--dragging');
|
|
183
|
-
this.capture(e);
|
|
184
|
-
}
|
|
185
|
-
const delta = { x: this.dragLast.x - p.x, y: this.dragLast.y - p.y };
|
|
186
|
-
this.dragLast = p;
|
|
187
|
-
this.engine.panBy(delta);
|
|
188
|
-
const now = performance.now();
|
|
189
|
-
this.samples.push({ t: now, p });
|
|
190
|
-
while (this.samples.length > 2 && now - this.samples[0].t > 100)
|
|
191
|
-
this.samples.shift();
|
|
192
|
-
e.preventDefault();
|
|
193
|
-
}
|
|
194
|
-
pointerUp(e) {
|
|
195
|
-
if (!this.pointers.has(e.pointerId))
|
|
196
|
-
return;
|
|
197
|
-
this.pointers.delete(e.pointerId);
|
|
198
|
-
this.release(e);
|
|
199
|
-
if (this.pinch) {
|
|
200
|
-
if (this.pointers.size < 2)
|
|
201
|
-
this.endPinch();
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
if (this.pointers.size === 0)
|
|
205
|
-
this.endDrag(e.type === 'pointerup' && this.options.inertia);
|
|
206
|
-
}
|
|
207
|
-
endPinch() {
|
|
208
|
-
const pinch = this.pinch;
|
|
209
|
-
this.pinch = null;
|
|
210
|
-
this.pointers.clear();
|
|
211
|
-
if (!pinch)
|
|
212
|
-
return;
|
|
213
|
-
this.engine.clearPreview();
|
|
214
|
-
// O conteúdo que estava sob o centro inicial da pinça termina sob o centro final.
|
|
215
|
-
this.engine.panBy({ x: pinch.startCenter.x - pinch.center.x, y: pinch.startCenter.y - pinch.center.y });
|
|
216
|
-
const target = Math.round(this.engine.zoom + Math.log2(pinch.scale));
|
|
217
|
-
if (target !== this.engine.zoom)
|
|
218
|
-
this.engine.zoomTo(target, pinch.center);
|
|
219
|
-
else
|
|
220
|
-
this.engine.settle();
|
|
221
|
-
this.suppressClick = true;
|
|
222
|
-
setTimeout(() => (this.suppressClick = false), 0);
|
|
223
|
-
}
|
|
224
|
-
endDrag(withInertia) {
|
|
225
|
-
const wasDragging = this.dragging;
|
|
226
|
-
this.dragStart = null;
|
|
227
|
-
this.dragLast = null;
|
|
228
|
-
this.dragging = false;
|
|
229
|
-
this.el.classList.remove('hm-map--dragging');
|
|
230
|
-
if (!wasDragging)
|
|
231
|
-
return;
|
|
232
|
-
this.suppressClick = true;
|
|
233
|
-
// O clique sintético vem logo depois do pointerup; se não vier (toque), libera no próximo ciclo.
|
|
234
|
-
setTimeout(() => (this.suppressClick = false), 0);
|
|
235
|
-
const first = this.samples[0];
|
|
236
|
-
const last = this.samples[this.samples.length - 1];
|
|
237
|
-
this.samples = [];
|
|
238
|
-
const dt = last && first ? (last.t - first.t) / 1000 : 0;
|
|
239
|
-
if (!withInertia || this.reducedMotion() || !first || !last || dt <= 0 || performance.now() - last.t > 50) {
|
|
240
|
-
this.engine.settle();
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
// Velocidade do conteúdo (px/s); a vista anda no sentido oposto.
|
|
244
|
-
let vx = (last.p.x - first.p.x) / dt;
|
|
245
|
-
let vy = (last.p.y - first.p.y) / dt;
|
|
246
|
-
const speed = Math.hypot(vx, vy);
|
|
247
|
-
if (speed < 50) {
|
|
248
|
-
this.engine.settle();
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
const limited = Math.min(speed, INERTIA_MAX_SPEED);
|
|
252
|
-
vx *= limited / speed;
|
|
253
|
-
vy *= limited / speed;
|
|
254
|
-
const duration = limited / (INERTIA_DECELERATION * EASE_LINEARITY);
|
|
255
|
-
const total = { x: (-vx * duration) / 2, y: (-vy * duration) / 2 };
|
|
256
|
-
this.animatePan(total, duration * 1000);
|
|
257
|
-
}
|
|
258
|
-
animatePan(total, durationMs) {
|
|
259
|
-
const start = performance.now();
|
|
260
|
-
const power = 1 / Math.max(EASE_LINEARITY, 0.2);
|
|
261
|
-
let done = { x: 0, y: 0 };
|
|
262
|
-
const step = (now) => {
|
|
263
|
-
const t = Math.min(1, (now - start) / durationMs);
|
|
264
|
-
const k = 1 - Math.pow(1 - t, power);
|
|
265
|
-
const target = { x: total.x * k, y: total.y * k };
|
|
266
|
-
this.engine.panBy({ x: target.x - done.x, y: target.y - done.y });
|
|
267
|
-
done = target;
|
|
268
|
-
if (t < 1)
|
|
269
|
-
this.animation = requestAnimationFrame(step);
|
|
270
|
-
else {
|
|
271
|
-
this.animation = 0;
|
|
272
|
-
this.engine.settle();
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
this.animation = requestAnimationFrame(step);
|
|
276
|
-
}
|
|
277
|
-
wheel(e) {
|
|
278
|
-
if (!this.options.scrollWheelZoom)
|
|
279
|
-
return;
|
|
280
|
-
e.preventDefault();
|
|
281
|
-
this.stop();
|
|
282
|
-
const unit = e.deltaMode === 1 ? 20 : e.deltaMode === 2 ? 60 : 1;
|
|
283
|
-
// Pinça de trackpad chega como roda com ctrl: deltas pequenos, então pesam mais.
|
|
284
|
-
this.wheelAcc += e.deltaY * unit * (e.ctrlKey ? 3 : 1);
|
|
285
|
-
if (this.wheelResetTimer)
|
|
286
|
-
clearTimeout(this.wheelResetTimer);
|
|
287
|
-
this.wheelResetTimer = setTimeout(() => (this.wheelAcc = 0), 200);
|
|
288
|
-
const now = performance.now();
|
|
289
|
-
const threshold = this.options.wheelPxPerZoomLevel;
|
|
290
|
-
if (Math.abs(this.wheelAcc) < threshold || now - this.wheelLastZoom < 60)
|
|
291
|
-
return;
|
|
292
|
-
const steps = Math.trunc(this.wheelAcc / threshold);
|
|
293
|
-
this.wheelAcc -= steps * threshold;
|
|
294
|
-
this.wheelLastZoom = now;
|
|
295
|
-
this.engine.zoomBy(-Math.sign(steps), this.local(e));
|
|
296
|
-
}
|
|
297
|
-
dblclick(e) {
|
|
298
|
-
if (!this.options.doubleClickZoom || this.blocked(e.target))
|
|
299
|
-
return;
|
|
300
|
-
e.preventDefault();
|
|
301
|
-
this.engine.zoomBy(e.shiftKey ? -1 : 1, this.local(e));
|
|
302
|
-
}
|
|
303
141
|
keydown(e) {
|
|
304
142
|
// Só com o foco no próprio mapa: marcadores e controles focados mantêm o teclado deles.
|
|
305
143
|
if (!this.options.keyboard || e.target !== this.el)
|
|
306
144
|
return;
|
|
307
|
-
const action = keyboardAction(e, this.options.
|
|
145
|
+
const action = keyboardAction(e, this.options.keyStep);
|
|
308
146
|
if (!action)
|
|
309
147
|
return;
|
|
310
148
|
e.preventDefault();
|
|
311
149
|
this.applyKeyboard(action);
|
|
312
150
|
this.onKeyboard?.(action);
|
|
313
151
|
}
|
|
314
|
-
capture(e) {
|
|
315
|
-
try {
|
|
316
|
-
this.el.setPointerCapture?.(e.pointerId);
|
|
317
|
-
}
|
|
318
|
-
catch {
|
|
319
|
-
// Ponteiro já liberado (ex.: evento sintético): sem captura, o gesto segue pelos eventos do elemento.
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
release(e) {
|
|
323
|
-
try {
|
|
324
|
-
if (this.el.hasPointerCapture?.(e.pointerId))
|
|
325
|
-
this.el.releasePointerCapture(e.pointerId);
|
|
326
|
-
}
|
|
327
|
-
catch {
|
|
328
|
-
// Idem.
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
function dist(a, b) {
|
|
333
|
-
return Math.hypot(a.x - b.x, a.y - b.y);
|
|
334
|
-
}
|
|
335
|
-
function mid(a, b) {
|
|
336
|
-
return { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
337
152
|
}
|
|
338
153
|
//# sourceMappingURL=interactions.js.map
|