maplibre-gl 3.1.0 → 3.2.0-pre.2
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/README.md +7 -7
- package/build/generate-doc-images.ts +73 -0
- package/build/generate-docs.ts +100 -0
- package/build/generate-struct-arrays.ts +9 -12
- package/dist/maplibre-gl-csp-worker.js +1 -1
- package/dist/maplibre-gl-csp-worker.js.map +1 -1
- package/dist/maplibre-gl-csp.js +1 -1
- package/dist/maplibre-gl-csp.js.map +1 -1
- package/dist/maplibre-gl-dev.js +3303 -3398
- package/dist/maplibre-gl-dev.js.map +1 -1
- package/dist/maplibre-gl.d.ts +3899 -3531
- package/dist/maplibre-gl.js +3 -3
- package/dist/maplibre-gl.js.map +1 -1
- package/package.json +28 -25
- package/src/data/array_types.g.ts +14 -48
- package/src/data/bucket/circle_bucket.ts +11 -14
- package/src/data/bucket/fill_bucket.test.ts +6 -6
- package/src/data/bucket/fill_bucket.ts +10 -12
- package/src/data/bucket/fill_extrusion_bucket.ts +11 -13
- package/src/data/bucket/heatmap_bucket.ts +3 -6
- package/src/data/bucket/line_attributes.ts +1 -2
- package/src/data/bucket/line_attributes_ext.ts +1 -2
- package/src/data/bucket/line_bucket.test.ts +5 -5
- package/src/data/bucket/line_bucket.ts +18 -21
- package/src/data/bucket/pattern_attributes.ts +1 -3
- package/src/data/bucket/pattern_bucket_features.ts +3 -3
- package/src/data/bucket/symbol_bucket.test.ts +5 -5
- package/src/data/bucket/symbol_bucket.ts +12 -15
- package/src/data/bucket.ts +7 -11
- package/src/data/dem_data.test.ts +1 -1
- package/src/data/dem_data.ts +1 -1
- package/src/data/evaluation_feature.ts +4 -5
- package/src/data/extent.ts +1 -4
- package/src/data/feature_index.ts +14 -13
- package/src/data/feature_position_map.test.ts +4 -4
- package/src/data/feature_position_map.ts +1 -1
- package/src/data/index_array_type.ts +0 -1
- package/src/data/load_geometry.test.ts +1 -1
- package/src/data/load_geometry.ts +3 -4
- package/src/data/program_configuration.ts +6 -11
- package/src/data/segment.ts +9 -6
- package/src/geo/edge_insets.test.ts +1 -1
- package/src/geo/edge_insets.ts +36 -26
- package/src/geo/lng_lat.test.ts +1 -1
- package/src/geo/lng_lat.ts +61 -44
- package/src/geo/lng_lat_bounds.test.ts +2 -2
- package/src/geo/lng_lat_bounds.ts +88 -68
- package/src/geo/mercator_coordinate.test.ts +2 -2
- package/src/geo/mercator_coordinate.ts +34 -27
- package/src/geo/transform.test.ts +3 -3
- package/src/geo/transform.ts +58 -79
- package/src/gl/color_mode.ts +1 -3
- package/src/gl/context.ts +12 -11
- package/src/gl/cull_face_mode.ts +1 -3
- package/src/gl/depth_mode.ts +1 -3
- package/src/gl/framebuffer.ts +5 -4
- package/src/gl/index_buffer.ts +5 -4
- package/src/gl/render_pool.test.ts +2 -2
- package/src/gl/render_pool.ts +5 -5
- package/src/gl/state.test.ts +1 -1
- package/src/gl/stencil_mode.ts +1 -3
- package/src/gl/value.ts +1 -1
- package/src/gl/vertex_buffer.test.ts +2 -2
- package/src/gl/vertex_buffer.ts +8 -14
- package/src/index.test.ts +2 -2
- package/src/index.ts +121 -113
- package/src/render/draw_background.ts +7 -9
- package/src/render/draw_circle.ts +13 -15
- package/src/render/draw_collision_debug.ts +11 -13
- package/src/render/draw_custom.ts +6 -8
- package/src/render/draw_debug.test.ts +4 -4
- package/src/render/draw_debug.ts +8 -10
- package/src/render/draw_fill.test.ts +13 -13
- package/src/render/draw_fill.ts +9 -11
- package/src/render/draw_fill_extrusion.ts +10 -12
- package/src/render/draw_heatmap.ts +12 -14
- package/src/render/draw_hillshade.ts +10 -12
- package/src/render/draw_line.ts +9 -9
- package/src/render/draw_raster.ts +9 -11
- package/src/render/draw_symbol.test.ts +16 -16
- package/src/render/draw_symbol.ts +15 -16
- package/src/render/draw_terrain.ts +11 -11
- package/src/render/glyph_atlas.ts +10 -1
- package/src/render/glyph_manager.test.ts +3 -3
- package/src/render/glyph_manager.ts +7 -7
- package/src/render/image_atlas.ts +6 -3
- package/src/render/image_manager.ts +3 -5
- package/src/render/line_atlas.test.ts +1 -1
- package/src/render/line_atlas.ts +19 -14
- package/src/render/painter.ts +85 -65
- package/src/render/program/background_program.ts +2 -2
- package/src/render/program/circle_program.ts +5 -5
- package/src/render/program/clipping_mask_program.ts +1 -1
- package/src/render/program/collision_program.ts +4 -4
- package/src/render/program/debug_program.ts +1 -1
- package/src/render/program/fill_extrusion_program.ts +3 -3
- package/src/render/program/fill_program.ts +3 -3
- package/src/render/program/heatmap_program.ts +5 -5
- package/src/render/program/hillshade_program.ts +7 -7
- package/src/render/program/line_program.ts +6 -6
- package/src/render/program/pattern.ts +3 -3
- package/src/render/program/raster_program.ts +2 -2
- package/src/render/program/symbol_program.ts +2 -2
- package/src/render/program/terrain_program.ts +1 -1
- package/src/render/program.ts +18 -16
- package/src/render/render_to_texture.test.ts +15 -15
- package/src/render/render_to_texture.ts +10 -10
- package/src/render/terrain.test.ts +38 -7
- package/src/render/terrain.ts +103 -67
- package/src/render/texture.ts +5 -4
- package/src/render/uniform_binding.test.ts +1 -1
- package/src/render/uniform_binding.ts +7 -1
- package/src/render/update_pattern_positions_in_program.ts +5 -5
- package/src/render/vertex_array_object.ts +9 -8
- package/src/shaders/encode_attribute.ts +0 -2
- package/src/shaders/shaders.ts +1 -3
- package/src/source/canvas_source.test.ts +6 -6
- package/src/source/canvas_source.ts +46 -60
- package/src/source/geojson_source.test.ts +5 -5
- package/src/source/geojson_source.ts +75 -59
- package/src/source/geojson_source_diff.ts +39 -2
- package/src/source/geojson_worker_source.test.ts +3 -3
- package/src/source/geojson_worker_source.ts +20 -26
- package/src/source/geojson_wrapper.test.ts +3 -3
- package/src/source/geojson_wrapper.ts +2 -4
- package/src/source/image_source.test.ts +9 -8
- package/src/source/image_source.ts +49 -35
- package/src/source/load_tilejson.ts +2 -2
- package/src/source/pixels_to_tile_units.ts +2 -3
- package/src/source/query_features.test.ts +3 -3
- package/src/source/query_features.ts +50 -19
- package/src/source/raster_dem_tile_source.test.ts +3 -3
- package/src/source/raster_dem_tile_source.ts +23 -10
- package/src/source/raster_dem_tile_worker_source.test.ts +2 -2
- package/src/source/raster_dem_tile_worker_source.ts +3 -5
- package/src/source/raster_tile_source.test.ts +3 -3
- package/src/source/raster_tile_source.ts +38 -11
- package/src/source/rtl_text_plugin.ts +4 -1
- package/src/source/source.ts +67 -59
- package/src/source/source_cache.test.ts +7 -7
- package/src/source/source_cache.ts +17 -38
- package/src/source/source_state.ts +2 -5
- package/src/source/terrain_source_cache.test.ts +8 -8
- package/src/source/terrain_source_cache.ts +42 -27
- package/src/source/tile.test.ts +3 -3
- package/src/source/tile.ts +32 -38
- package/src/source/tile_bounds.ts +2 -4
- package/src/source/tile_cache.test.ts +2 -2
- package/src/source/tile_cache.ts +20 -30
- package/src/source/tile_id.ts +11 -2
- package/src/source/vector_tile_source.test.ts +3 -3
- package/src/source/vector_tile_source.ts +34 -24
- package/src/source/vector_tile_worker_source.test.ts +4 -4
- package/src/source/vector_tile_worker_source.ts +11 -23
- package/src/source/video_source.test.ts +5 -5
- package/src/source/video_source.ts +21 -28
- package/src/source/worker.ts +6 -8
- package/src/source/worker_source.ts +6 -8
- package/src/source/worker_tile.test.ts +5 -5
- package/src/source/worker_tile.ts +13 -16
- package/src/style/create_style_layer.ts +31 -26
- package/src/style/evaluation_parameters.ts +5 -4
- package/src/style/format_section_override.test.ts +2 -2
- package/src/style/format_section_override.ts +1 -1
- package/src/style/light.test.ts +2 -2
- package/src/style/light.ts +3 -5
- package/src/style/load_glyph_range.test.ts +1 -1
- package/src/style/load_glyph_range.ts +3 -3
- package/src/style/load_sprite.test.ts +1 -1
- package/src/style/load_sprite.ts +3 -3
- package/src/style/parse_glyph_pbf.ts +1 -1
- package/src/style/pauseable_placement.ts +7 -9
- package/src/style/properties.ts +4 -53
- package/src/style/query_utils.ts +3 -3
- package/src/style/style.test.ts +22 -19
- package/src/style/style.ts +118 -84
- package/src/style/style_glyph.ts +6 -0
- package/src/style/style_image.ts +39 -33
- package/src/style/style_layer/background_style_layer.ts +2 -4
- package/src/style/style_layer/circle_style_layer.ts +7 -6
- package/src/style/style_layer/custom_style_layer.ts +23 -48
- package/src/style/style_layer/fill_extrusion_style_layer.ts +4 -6
- package/src/style/style_layer/fill_style_layer.ts +5 -7
- package/src/style/style_layer/heatmap_style_layer.ts +8 -7
- package/src/style/style_layer/hillshade_style_layer.ts +2 -4
- package/src/style/style_layer/line_style_layer.ts +6 -8
- package/src/style/style_layer/overlap_mode.test.ts +3 -3
- package/src/style/style_layer/overlap_mode.ts +3 -0
- package/src/style/style_layer/raster_style_layer.ts +2 -4
- package/src/style/style_layer/symbol_style_layer.ts +6 -8
- package/src/style/style_layer/typed_style_layer.ts +7 -7
- package/src/style/style_layer.test.ts +5 -5
- package/src/style/style_layer.ts +7 -6
- package/src/style/style_layer_index.test.ts +1 -1
- package/src/style/style_layer_index.ts +3 -5
- package/src/style/zoom_history.ts +1 -3
- package/src/symbol/anchor.test.ts +1 -1
- package/src/symbol/anchor.ts +1 -3
- package/src/symbol/check_max_angle.test.ts +8 -2
- package/src/symbol/check_max_angle.ts +10 -13
- package/src/symbol/clip_line.test.ts +1 -1
- package/src/symbol/clip_line.ts +6 -9
- package/src/symbol/collision_feature.test.ts +2 -2
- package/src/symbol/collision_feature.ts +7 -12
- package/src/symbol/collision_index.test.ts +2 -2
- package/src/symbol/collision_index.ts +5 -11
- package/src/symbol/cross_tile_symbol_index.test.ts +2 -2
- package/src/symbol/cross_tile_symbol_index.ts +5 -7
- package/src/symbol/get_anchors.ts +2 -2
- package/src/symbol/grid_index.test.ts +1 -1
- package/src/symbol/grid_index.ts +4 -5
- package/src/symbol/merge_lines.test.ts +1 -1
- package/src/symbol/merge_lines.ts +1 -1
- package/src/symbol/opacity_state.ts +1 -3
- package/src/symbol/path_interpolator.test.ts +1 -1
- package/src/symbol/path_interpolator.ts +1 -3
- package/src/symbol/placement.ts +9 -9
- package/src/symbol/projection.ts +61 -34
- package/src/symbol/quads.ts +7 -11
- package/src/symbol/shaping.ts +1 -1
- package/src/symbol/symbol_layout.ts +9 -12
- package/src/symbol/symbol_size.ts +1 -1
- package/src/symbol/symbol_style_layer.test.ts +4 -4
- package/src/symbol/transform_text.ts +2 -2
- package/src/types/callback.ts +14 -14
- package/src/types/cancelable.ts +3 -0
- package/src/types/transferable.ts +3 -0
- package/src/ui/anchor.ts +4 -0
- package/src/ui/camera.test.ts +6 -6
- package/src/ui/camera.ts +392 -361
- package/src/ui/control/attribution_control.test.ts +1 -1
- package/src/ui/control/attribution_control.ts +34 -30
- package/src/ui/control/control.ts +14 -20
- package/src/ui/control/fullscreen_control.test.ts +1 -1
- package/src/ui/control/fullscreen_control.ts +21 -26
- package/src/ui/control/geolocate_control.test.ts +5 -5
- package/src/ui/control/geolocate_control.ts +181 -194
- package/src/ui/control/logo_control.ts +20 -16
- package/src/ui/control/navigation_control.test.ts +1 -1
- package/src/ui/control/navigation_control.ts +46 -42
- package/src/ui/control/scale_control.test.ts +1 -1
- package/src/ui/control/scale_control.ts +30 -21
- package/src/ui/control/terrain_control.test.ts +1 -1
- package/src/ui/control/terrain_control.ts +14 -18
- package/src/ui/default_locale.ts +1 -3
- package/src/ui/events.ts +570 -1281
- package/src/ui/handler/box_zoom.test.ts +2 -2
- package/src/ui/handler/box_zoom.ts +16 -11
- package/src/ui/handler/click_zoom.ts +11 -3
- package/src/ui/handler/cooperative_gestures.test.ts +3 -3
- package/src/ui/handler/dblclick_zoom.test.ts +1 -1
- package/src/ui/handler/drag_handler.ts +30 -22
- package/src/ui/handler/drag_move_state_manager.ts +1 -1
- package/src/ui/handler/drag_pan.test.ts +2 -2
- package/src/ui/handler/drag_rotate.test.ts +3 -3
- package/src/ui/handler/keyboard.test.ts +2 -2
- package/src/ui/handler/keyboard.ts +22 -13
- package/src/ui/handler/map_event.test.ts +2 -2
- package/src/ui/handler/map_event.ts +1 -1
- package/src/ui/handler/mouse.ts +1 -1
- package/src/ui/handler/mouse_rotate.test.ts +3 -3
- package/src/ui/handler/scroll_zoom.test.ts +3 -3
- package/src/ui/handler/scroll_zoom.ts +45 -52
- package/src/ui/handler/shim/dblclick_zoom.ts +12 -6
- package/src/ui/handler/shim/drag_pan.ts +34 -14
- package/src/ui/handler/shim/drag_rotate.ts +20 -12
- package/src/ui/handler/shim/two_fingers_touch.ts +24 -18
- package/src/ui/handler/tap_drag_zoom.test.ts +113 -0
- package/src/ui/handler/tap_drag_zoom.ts +18 -10
- package/src/ui/handler/tap_recognizer.ts +1 -1
- package/src/ui/handler/tap_zoom.ts +4 -3
- package/src/ui/handler/touch_pan.ts +3 -2
- package/src/ui/handler/transform-provider.ts +4 -6
- package/src/ui/handler/two_fingers_touch.test.ts +3 -3
- package/src/ui/handler/two_fingers_touch.ts +64 -47
- package/src/ui/handler_inertia.ts +4 -4
- package/src/ui/handler_manager.ts +86 -52
- package/src/ui/hash.test.ts +1 -1
- package/src/ui/hash.ts +21 -28
- package/src/ui/map/isMoving.test.ts +3 -3
- package/src/ui/map/isRotating.test.ts +3 -3
- package/src/ui/map/isZooming.test.ts +3 -3
- package/src/ui/map.test.ts +97 -8
- package/src/ui/map.ts +856 -702
- package/src/ui/map_events.test.ts +1 -1
- package/src/ui/marker.test.ts +35 -15
- package/src/ui/marker.ts +220 -141
- package/src/ui/popup.test.ts +2 -2
- package/src/ui/popup.ts +179 -147
- package/src/util/actor.test.ts +7 -7
- package/src/util/actor.ts +25 -22
- package/src/util/ajax.ts +37 -17
- package/src/util/browser.test.ts +1 -1
- package/src/util/browser.ts +2 -6
- package/src/util/classify_rings.test.ts +1 -1
- package/src/util/classify_rings.ts +1 -1
- package/src/util/color_ramp.ts +0 -2
- package/src/util/config.ts +6 -3
- package/src/util/debug.ts +0 -2
- package/src/util/dictionary_coder.ts +1 -4
- package/src/util/dispatcher.test.ts +3 -3
- package/src/util/dispatcher.ts +4 -9
- package/src/util/dom.ts +1 -1
- package/src/util/evented.ts +23 -18
- package/src/util/find_pole_of_inaccessibility.test.ts +1 -1
- package/src/util/find_pole_of_inaccessibility.ts +4 -5
- package/src/util/global_worker_pool.ts +2 -3
- package/src/util/image.ts +10 -4
- package/src/util/image_request.test.ts +3 -3
- package/src/util/image_request.ts +15 -14
- package/src/util/is_char_in_unicode_block.ts +1 -3
- package/src/util/offscreen_canvas_supported.ts +1 -1
- package/src/util/performance.ts +1 -2
- package/src/util/request_manager.ts +4 -0
- package/src/util/resolve_tokens.test.ts +1 -1
- package/src/util/resolve_tokens.ts +3 -6
- package/src/util/script_detection.ts +1 -4
- package/src/util/smart_wrap.ts +3 -5
- package/src/util/struct_array.ts +18 -14
- package/src/util/style.ts +2 -2
- package/src/util/task_queue.test.ts +1 -1
- package/src/util/task_queue.ts +1 -3
- package/src/util/test/mock_webgl.ts +6 -0
- package/src/util/test/util.ts +2 -2
- package/src/util/throttle.test.ts +1 -1
- package/src/util/throttle.ts +1 -2
- package/src/util/throttled_invoker.ts +1 -5
- package/src/util/transferable_grid_index.test.ts +1 -1
- package/src/util/transferable_grid_index.ts +1 -3
- package/src/util/util.test.ts +1 -14
- package/src/util/util.ts +44 -107
- package/src/util/vectortile_to_geojson.ts +13 -3
- package/src/util/verticalize_punctuation.ts +1 -1
- package/src/util/web_worker.ts +2 -2
- package/src/util/web_worker_transfer.ts +11 -8
- package/src/util/webp_supported.ts +2 -4
- package/src/util/worker_pool.test.ts +1 -1
- package/src/util/worker_pool.ts +4 -5
package/src/render/terrain.ts
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
|
|
2
|
-
import Tile from '../source/tile';
|
|
2
|
+
import {Tile} from '../source/tile';
|
|
3
3
|
import {mat4, vec2} from 'gl-matrix';
|
|
4
4
|
import {OverscaledTileID} from '../source/tile_id';
|
|
5
5
|
import {RGBAImage} from '../util/image';
|
|
6
6
|
import {warnOnce} from '../util/util';
|
|
7
7
|
import {Pos3dArray, TriangleIndexArray} from '../data/array_types.g';
|
|
8
8
|
import pos3dAttributes from '../data/pos3d_attributes';
|
|
9
|
-
import SegmentVector from '../data/segment';
|
|
10
|
-
import VertexBuffer from '../gl/vertex_buffer';
|
|
11
|
-
import IndexBuffer from '../gl/index_buffer';
|
|
12
|
-
import Painter from './painter';
|
|
13
|
-
import Texture from '../render/texture';
|
|
14
|
-
import type Framebuffer from '../gl/framebuffer';
|
|
9
|
+
import {SegmentVector} from '../data/segment';
|
|
10
|
+
import {VertexBuffer} from '../gl/vertex_buffer';
|
|
11
|
+
import {IndexBuffer} from '../gl/index_buffer';
|
|
12
|
+
import {Painter} from './painter';
|
|
13
|
+
import {Texture} from '../render/texture';
|
|
14
|
+
import type {Framebuffer} from '../gl/framebuffer';
|
|
15
15
|
import Point from '@mapbox/point-geometry';
|
|
16
|
-
import MercatorCoordinate from '../geo/mercator_coordinate';
|
|
17
|
-
import TerrainSourceCache from '../source/terrain_source_cache';
|
|
18
|
-
import SourceCache from '../source/source_cache';
|
|
19
|
-
import EXTENT from '../data/extent';
|
|
20
|
-
import {interpolates} from '@maplibre/maplibre-gl-style-spec';
|
|
16
|
+
import {MercatorCoordinate} from '../geo/mercator_coordinate';
|
|
17
|
+
import {TerrainSourceCache} from '../source/terrain_source_cache';
|
|
18
|
+
import {SourceCache} from '../source/source_cache';
|
|
19
|
+
import {EXTENT} from '../data/extent';
|
|
21
20
|
import type {TerrainSpecification} from '@maplibre/maplibre-gl-style-spec';
|
|
22
21
|
import {earthRadius} from '../geo/lng_lat';
|
|
23
22
|
|
|
23
|
+
/**
|
|
24
|
+
* A terrain GPU related object
|
|
25
|
+
*/
|
|
24
26
|
export type TerrainData = {
|
|
25
27
|
'u_depth': number;
|
|
26
28
|
'u_terrain': number;
|
|
@@ -33,6 +35,9 @@ export type TerrainData = {
|
|
|
33
35
|
tile: Tile;
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
/**
|
|
39
|
+
* A terrain mesh object
|
|
40
|
+
*/
|
|
36
41
|
export type TerrainMesh = {
|
|
37
42
|
indexBuffer: IndexBuffer;
|
|
38
43
|
vertexBuffer: VertexBuffer;
|
|
@@ -66,44 +71,69 @@ export type TerrainMesh = {
|
|
|
66
71
|
* cache of the last 150 newest rendered tiles.
|
|
67
72
|
*
|
|
68
73
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
export class Terrain {
|
|
75
|
+
/**
|
|
76
|
+
* The style this terrain crresponds to
|
|
77
|
+
*/
|
|
72
78
|
painter: Painter;
|
|
73
|
-
|
|
79
|
+
/**
|
|
80
|
+
* the sourcecache this terrain is based on
|
|
81
|
+
*/
|
|
74
82
|
sourceCache: TerrainSourceCache;
|
|
75
|
-
|
|
83
|
+
/**
|
|
84
|
+
* the TerrainSpecification object passed to this instance
|
|
85
|
+
*/
|
|
76
86
|
options: TerrainSpecification;
|
|
77
|
-
|
|
87
|
+
/**
|
|
88
|
+
* define the meshSize per tile.
|
|
89
|
+
*/
|
|
78
90
|
meshSize: number;
|
|
79
|
-
|
|
91
|
+
/**
|
|
92
|
+
* multiplicator for the elevation. Used to make terrain more "extreme".
|
|
93
|
+
*/
|
|
80
94
|
exaggeration: number;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
95
|
+
/**
|
|
96
|
+
* to not see pixels in the render-to-texture tiles it is good to render them bigger
|
|
97
|
+
* this number is the multiplicator (must be a power of 2) for the current tileSize.
|
|
98
|
+
* So to get good results with not too much memory footprint a value of 2 should be fine.
|
|
99
|
+
*/
|
|
84
100
|
qualityFactor: number;
|
|
85
|
-
|
|
101
|
+
/**
|
|
102
|
+
* holds the framebuffer object in size of the screen to render the coords & depth into a texture.
|
|
103
|
+
*/
|
|
86
104
|
_fbo: Framebuffer;
|
|
87
105
|
_fboCoordsTexture: Texture;
|
|
88
106
|
_fboDepthTexture: Texture;
|
|
89
107
|
_emptyDepthTexture: Texture;
|
|
90
|
-
|
|
91
|
-
|
|
108
|
+
/**
|
|
109
|
+
* GL Objects for the terrain-mesh
|
|
110
|
+
* The mesh is a regular mesh, which has the advantage that it can be reused for all tiles.
|
|
111
|
+
*/
|
|
92
112
|
_mesh: TerrainMesh;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
113
|
+
/**
|
|
114
|
+
* coords index contains a list of tileID.keys. This index is used to identify
|
|
115
|
+
* the tile via the alpha-cannel in the coords-texture.
|
|
116
|
+
* As the alpha-channel has 1 Byte a max of 255 tiles can rendered without an error.
|
|
117
|
+
*/
|
|
96
118
|
coordsIndex: Array<string>;
|
|
97
|
-
|
|
119
|
+
/**
|
|
120
|
+
* tile-coords encoded in the rgb channel, _coordsIndex is in the alpha-channel.
|
|
121
|
+
*/
|
|
98
122
|
_coordsTexture: Texture;
|
|
99
|
-
|
|
123
|
+
/**
|
|
124
|
+
* accuracy of the coords. 2 * tileSize should be enoughth.
|
|
125
|
+
*/
|
|
100
126
|
_coordsTextureSize: number;
|
|
101
|
-
|
|
127
|
+
/**
|
|
128
|
+
* variables for an empty dem texture, which is used while the raster-dem tile is loading.
|
|
129
|
+
*/
|
|
102
130
|
_emptyDemUnpack: number[];
|
|
103
131
|
_emptyDemTexture: Texture;
|
|
104
132
|
_emptyDemMatrix: mat4;
|
|
105
|
-
|
|
106
|
-
|
|
133
|
+
/**
|
|
134
|
+
* as of overzooming of raster-dem tiles in high zoomlevels, this cache contains
|
|
135
|
+
* matrices to transform from vector-tile coords to raster-dem-tile coords.
|
|
136
|
+
*/
|
|
107
137
|
_demMatrixCache: {[_: string]: { matrix: mat4; coord: OverscaledTileID }};
|
|
108
138
|
|
|
109
139
|
constructor(painter: Painter, sourceCache: SourceCache, options: TerrainSpecification) {
|
|
@@ -120,36 +150,42 @@ export default class Terrain {
|
|
|
120
150
|
|
|
121
151
|
/**
|
|
122
152
|
* get the elevation-value from original dem-data for a given tile-coordinate
|
|
123
|
-
* @param
|
|
124
|
-
* @param
|
|
125
|
-
* @param
|
|
126
|
-
* @param
|
|
127
|
-
* @returns
|
|
153
|
+
* @param tileID - the tile to get elevation for
|
|
154
|
+
* @param x - between 0 .. EXTENT
|
|
155
|
+
* @param y - between 0 .. EXTENT
|
|
156
|
+
* @param extent - optional, default 8192
|
|
157
|
+
* @returns the elevation
|
|
128
158
|
*/
|
|
129
159
|
getDEMElevation(tileID: OverscaledTileID, x: number, y: number, extent: number = EXTENT): number {
|
|
130
160
|
if (!(x >= 0 && x < extent && y >= 0 && y < extent)) return 0;
|
|
131
|
-
let elevation = 0;
|
|
132
161
|
const terrain = this.getTerrainData(tileID);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
162
|
+
const dem = terrain.tile?.dem;
|
|
163
|
+
if (!dem)
|
|
164
|
+
return 0;
|
|
165
|
+
|
|
166
|
+
const pos = vec2.transformMat4([] as any, [x / extent * EXTENT, y / extent * EXTENT], terrain.u_terrain_matrix);
|
|
167
|
+
const coord = [pos[0] * dem.dim, pos[1] * dem.dim];
|
|
168
|
+
|
|
169
|
+
// bilinear interpolation
|
|
170
|
+
const cx = Math.floor(coord[0]),
|
|
171
|
+
cy = Math.floor(coord[1]),
|
|
172
|
+
tx = coord[0] - cx,
|
|
173
|
+
ty = coord[1] - cy;
|
|
174
|
+
return (
|
|
175
|
+
dem.get(cx, cy) * (1 - tx) * (1 - ty) +
|
|
176
|
+
dem.get(cx + 1, cy) * (tx) * (1 - ty) +
|
|
177
|
+
dem.get(cx, cy + 1) * (1 - tx) * (ty) +
|
|
178
|
+
dem.get(cx + 1, cy + 1) * (tx) * (ty)
|
|
179
|
+
);
|
|
144
180
|
}
|
|
145
181
|
|
|
146
182
|
/**
|
|
147
183
|
* get the Elevation for given coordinate in respect of exaggeration.
|
|
148
|
-
* @param
|
|
149
|
-
* @param
|
|
150
|
-
* @param
|
|
151
|
-
* @param
|
|
152
|
-
* @returns
|
|
184
|
+
* @param tileID - the tile id
|
|
185
|
+
* @param x - between 0 .. EXTENT
|
|
186
|
+
* @param y - between 0 .. EXTENT
|
|
187
|
+
* @param extent - optional, default 8192
|
|
188
|
+
* @returns the elevation
|
|
153
189
|
*/
|
|
154
190
|
getElevation(tileID: OverscaledTileID, x: number, y: number, extent: number = EXTENT): number {
|
|
155
191
|
return this.getDEMElevation(tileID, x, y, extent) * this.exaggeration;
|
|
@@ -157,8 +193,8 @@ export default class Terrain {
|
|
|
157
193
|
|
|
158
194
|
/**
|
|
159
195
|
* returns a Terrain Object for a tile. Unless the tile corresponds to data (e.g. tile is loading), return a flat dem object
|
|
160
|
-
* @param
|
|
161
|
-
* @returns
|
|
196
|
+
* @param tileID - the tile to get the terrain for
|
|
197
|
+
* @returns the terrain data to use in the program
|
|
162
198
|
*/
|
|
163
199
|
getTerrainData(tileID: OverscaledTileID): TerrainData {
|
|
164
200
|
// create empty DEM Objects, which will used while raster-dem tiles are loading.
|
|
@@ -213,8 +249,8 @@ export default class Terrain {
|
|
|
213
249
|
|
|
214
250
|
/**
|
|
215
251
|
* get a framebuffer as big as the map-div, which will be used to render depth & coords into a texture
|
|
216
|
-
* @param
|
|
217
|
-
* @returns
|
|
252
|
+
* @param texture - the texture
|
|
253
|
+
* @returns the frame buffer
|
|
218
254
|
*/
|
|
219
255
|
getFramebuffer(texture: string): Framebuffer {
|
|
220
256
|
const painter = this.painter;
|
|
@@ -252,7 +288,7 @@ export default class Terrain {
|
|
|
252
288
|
* - 4 higher bits for x
|
|
253
289
|
* - 4 higher bits for y
|
|
254
290
|
* - 8 bits for coordsIndex (1 .. 255) (= number of terraintile), is later setted in draw_terrain uniform value
|
|
255
|
-
* @returns
|
|
291
|
+
* @returns the texture
|
|
256
292
|
*/
|
|
257
293
|
getCoordsTexture(): Texture {
|
|
258
294
|
const context = this.painter.context;
|
|
@@ -273,8 +309,8 @@ export default class Terrain {
|
|
|
273
309
|
|
|
274
310
|
/**
|
|
275
311
|
* Reads a pixel from the coords-framebuffer and translate this to mercator.
|
|
276
|
-
* @param
|
|
277
|
-
* @returns
|
|
312
|
+
* @param p - Screen-Coordinate
|
|
313
|
+
* @returns mercator coordinate for a screen pixel
|
|
278
314
|
*/
|
|
279
315
|
pointCoordinate(p: Point): MercatorCoordinate {
|
|
280
316
|
const rgba = new Uint8Array(4);
|
|
@@ -300,7 +336,7 @@ export default class Terrain {
|
|
|
300
336
|
|
|
301
337
|
/**
|
|
302
338
|
* create a regular mesh which will be used by all terrain-tiles
|
|
303
|
-
* @returns
|
|
339
|
+
* @returns the created regular mesh
|
|
304
340
|
*/
|
|
305
341
|
getTerrainMesh(): TerrainMesh {
|
|
306
342
|
if (this._mesh) return this._mesh;
|
|
@@ -347,10 +383,10 @@ export default class Terrain {
|
|
|
347
383
|
/**
|
|
348
384
|
* Calculates a height of the frame around the terrain-mesh to avoid stiching between
|
|
349
385
|
* tile boundaries in different zoomlevels.
|
|
350
|
-
* @param zoom current zoomlevel
|
|
386
|
+
* @param zoom - current zoomlevel
|
|
351
387
|
* @returns the elevation delta in meters
|
|
352
388
|
*/
|
|
353
|
-
getMeshFrameDelta(zoom: number) {
|
|
389
|
+
getMeshFrameDelta(zoom: number): number {
|
|
354
390
|
// divide by 5 is evaluated by trial & error to get a frame in the right height
|
|
355
391
|
return 2 * Math.PI * earthRadius / Math.pow(2, zoom) / 5;
|
|
356
392
|
}
|
|
@@ -359,8 +395,8 @@ export default class Terrain {
|
|
|
359
395
|
* Get the minimum and maximum elevation contained in a tile. This includes any
|
|
360
396
|
* exaggeration included in the terrain.
|
|
361
397
|
*
|
|
362
|
-
* @param tileID
|
|
363
|
-
* @returns
|
|
398
|
+
* @param tileID - ID of the tile to be used as a source for the min/max elevation
|
|
399
|
+
* @returns the minimum and maximum elevation found in the tile, including the terrain's
|
|
364
400
|
* exaggeration
|
|
365
401
|
*/
|
|
366
402
|
getMinMaxElevation(tileID: OverscaledTileID): {minElevation: number | null; maxElevation: number | null} {
|
package/src/render/texture.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type Context from '../gl/context';
|
|
1
|
+
import type {Context} from '../gl/context';
|
|
2
2
|
import type {RGBAImage, AlphaImage} from '../util/image';
|
|
3
3
|
import {isImageBitmap} from '../util/util';
|
|
4
4
|
|
|
@@ -15,7 +15,10 @@ type EmptyImage = {
|
|
|
15
15
|
type DataTextureImage = RGBAImage | AlphaImage | EmptyImage;
|
|
16
16
|
export type TextureImage = TexImageSource | DataTextureImage;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* A `Texture` GL related object
|
|
20
|
+
*/
|
|
21
|
+
export class Texture {
|
|
19
22
|
context: Context;
|
|
20
23
|
size: [number, number];
|
|
21
24
|
texture: WebGLTexture;
|
|
@@ -108,5 +111,3 @@ class Texture {
|
|
|
108
111
|
this.texture = null;
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
|
-
|
|
112
|
-
export default Texture;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Color} from '@maplibre/maplibre-gl-style-spec';
|
|
2
2
|
|
|
3
|
-
import type Context from '../gl/context';
|
|
3
|
+
import type {Context} from '../gl/context';
|
|
4
4
|
import {mat4, vec2, vec3, vec4} from 'gl-matrix';
|
|
5
5
|
|
|
6
6
|
type $ObjMap<T extends {}, F extends (v: any) => any> = {
|
|
@@ -10,6 +10,9 @@ type $ObjMap<T extends {}, F extends (v: any) => any> = {
|
|
|
10
10
|
export type UniformValues<Us extends {}> = $ObjMap<Us, <V>(u: Uniform<V>) => V>;
|
|
11
11
|
export type UniformLocations = {[_: string]: WebGLUniformLocation};
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* A base uniform abstract class
|
|
15
|
+
*/
|
|
13
16
|
abstract class Uniform<T> {
|
|
14
17
|
gl: WebGLRenderingContext|WebGL2RenderingContext;
|
|
15
18
|
location: WebGLUniformLocation;
|
|
@@ -146,4 +149,7 @@ export {
|
|
|
146
149
|
UniformMatrix4f
|
|
147
150
|
};
|
|
148
151
|
|
|
152
|
+
/**
|
|
153
|
+
* A uniform bindings
|
|
154
|
+
*/
|
|
149
155
|
export type UniformBindings = {[_: string]: Uniform<any>};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type {CrossFaded} from '../style/properties';
|
|
2
2
|
import type {ResolvedImage} from '@maplibre/maplibre-gl-style-spec';
|
|
3
|
-
import type Tile from '../source/tile';
|
|
4
|
-
import type ProgramConfiguration from '../data/program_configuration';
|
|
5
|
-
import type FillExtrusionStyleLayer from '../style/style_layer/fill_extrusion_style_layer';
|
|
6
|
-
import type FillStyleLayer from '../style/style_layer/fill_style_layer';
|
|
3
|
+
import type {Tile} from '../source/tile';
|
|
4
|
+
import type {ProgramConfiguration} from '../data/program_configuration';
|
|
5
|
+
import type {FillExtrusionStyleLayer} from '../style/style_layer/fill_extrusion_style_layer';
|
|
6
|
+
import type {FillStyleLayer} from '../style/style_layer/fill_style_layer';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A simple helper shared by draw_fill and draw_fill_extrusions to find the correct pattern positions AND update program.
|
|
@@ -18,7 +18,7 @@ import type FillStyleLayer from '../style/style_layer/fill_style_layer';
|
|
|
18
18
|
* @param tile - current tile being drawn
|
|
19
19
|
* @param layer - current layer being rendered
|
|
20
20
|
*/
|
|
21
|
-
export
|
|
21
|
+
export function updatePatternPositionsInProgram(
|
|
22
22
|
programConfiguration: ProgramConfiguration,
|
|
23
23
|
propertyName: 'fill-pattern' | 'fill-extrusion-pattern',
|
|
24
24
|
constantPattern: CrossFaded<ResolvedImage>,
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
|
|
2
|
-
import type Program from './program';
|
|
3
|
-
import type VertexBuffer from '../gl/vertex_buffer';
|
|
4
|
-
import type IndexBuffer from '../gl/index_buffer';
|
|
5
|
-
import type Context from '../gl/context';
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import type {Program} from './program';
|
|
3
|
+
import type {VertexBuffer} from '../gl/vertex_buffer';
|
|
4
|
+
import type {IndexBuffer} from '../gl/index_buffer';
|
|
5
|
+
import type {Context} from '../gl/context';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A vertex array object used to pass data to the webgl code
|
|
9
|
+
*/
|
|
10
|
+
export class VertexArrayObject {
|
|
8
11
|
context: Context;
|
|
9
12
|
boundProgram: Program<any>;
|
|
10
13
|
boundLayoutVertexBuffer: VertexBuffer;
|
|
@@ -157,5 +160,3 @@ class VertexArrayObject {
|
|
|
157
160
|
}
|
|
158
161
|
}
|
|
159
162
|
}
|
|
160
|
-
|
|
161
|
-
export default VertexArrayObject;
|
|
@@ -4,8 +4,6 @@ import {clamp} from '../util/util';
|
|
|
4
4
|
* Packs two numbers, interpreted as 8-bit unsigned integers, into a single
|
|
5
5
|
* float. Unpack them in the shader using the `unpack_float()` function,
|
|
6
6
|
* defined in _prelude.vertex.glsl
|
|
7
|
-
*
|
|
8
|
-
* @private
|
|
9
7
|
*/
|
|
10
8
|
export function packUint8ToFloat(a: number, b: number) {
|
|
11
9
|
// coerce a and b to 8-bit ints
|
package/src/shaders/shaders.ts
CHANGED
|
@@ -58,7 +58,7 @@ import terrainCoordsFrag from './terrain_coords.fragment.glsl.g';
|
|
|
58
58
|
import terrainFrag from './terrain.fragment.glsl.g';
|
|
59
59
|
import terrainVert from './terrain.vertex.glsl.g';
|
|
60
60
|
|
|
61
|
-
const shaders = {
|
|
61
|
+
export const shaders = {
|
|
62
62
|
prelude: compile(preludeFrag, preludeVert),
|
|
63
63
|
background: compile(backgroundFrag, backgroundVert),
|
|
64
64
|
backgroundPattern: compile(backgroundPatternFrag, backgroundPatternVert),
|
|
@@ -90,8 +90,6 @@ const shaders = {
|
|
|
90
90
|
terrainCoords: compile(terrainCoordsFrag, terrainVert)
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
export default shaders;
|
|
94
|
-
|
|
95
93
|
// Expand #pragmas to #ifdefs.
|
|
96
94
|
|
|
97
95
|
function compile(fragmentSource, vertexSource) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import CanvasSource from '../source/canvas_source';
|
|
2
|
-
import Transform from '../geo/transform';
|
|
1
|
+
import {CanvasSource} from '../source/canvas_source';
|
|
2
|
+
import {Transform} from '../geo/transform';
|
|
3
3
|
import {Event, Evented} from '../util/evented';
|
|
4
4
|
import {extend} from '../util/util';
|
|
5
5
|
|
|
6
|
-
import type Dispatcher from '../util/dispatcher';
|
|
7
|
-
import Tile from './tile';
|
|
6
|
+
import type {Dispatcher} from '../util/dispatcher';
|
|
7
|
+
import {Tile} from './tile';
|
|
8
8
|
import {OverscaledTileID} from './tile_id';
|
|
9
|
-
import VertexBuffer from '../gl/vertex_buffer';
|
|
10
|
-
import SegmentVector from '../data/segment';
|
|
9
|
+
import {VertexBuffer} from '../gl/vertex_buffer';
|
|
10
|
+
import {SegmentVector} from '../data/segment';
|
|
11
11
|
|
|
12
12
|
function createSource(options?) {
|
|
13
13
|
const c = options && options.canvas || window.document.createElement('canvas');
|
|
@@ -1,36 +1,45 @@
|
|
|
1
|
-
import ImageSource from './image_source';
|
|
1
|
+
import {ImageSource} from './image_source';
|
|
2
2
|
|
|
3
3
|
import rasterBoundsAttributes from '../data/raster_bounds_attributes';
|
|
4
|
-
import SegmentVector from '../data/segment';
|
|
5
|
-
import Texture from '../render/texture';
|
|
4
|
+
import {SegmentVector} from '../data/segment';
|
|
5
|
+
import {Texture} from '../render/texture';
|
|
6
6
|
import {Event, ErrorEvent} from '../util/evented';
|
|
7
7
|
import {ValidationError} from '@maplibre/maplibre-gl-style-spec';
|
|
8
8
|
|
|
9
|
-
import type Map from '../ui/map';
|
|
10
|
-
import type Dispatcher from '../util/dispatcher';
|
|
9
|
+
import type {Map} from '../ui/map';
|
|
10
|
+
import type {Dispatcher} from '../util/dispatcher';
|
|
11
11
|
import type {Evented} from '../util/evented';
|
|
12
12
|
|
|
13
|
-
export type CanvasSourceSpecification = {
|
|
14
|
-
'type': 'canvas';
|
|
15
|
-
'coordinates': [[number, number], [number, number], [number, number], [number, number]];
|
|
16
|
-
'animate'?: boolean;
|
|
17
|
-
'canvas': string | HTMLCanvasElement;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
13
|
/**
|
|
21
14
|
* Options to add a canvas source type to the map.
|
|
22
|
-
*
|
|
23
|
-
* @typedef {Object} CanvasSourceOptions
|
|
24
|
-
* @property {string} type Source type. Must be `"canvas"`.
|
|
25
|
-
* @property {string|HTMLCanvasElement} canvas Canvas source from which to read pixels. Can be a string representing the ID of the canvas element, or the `HTMLCanvasElement` itself.
|
|
26
|
-
* @property {Array<Array<number>>} coordinates Four geographical coordinates denoting where to place the corners of the canvas, specified in `[longitude, latitude]` pairs.
|
|
27
|
-
* @property {boolean} [animate=true] Whether the canvas source is animated. If the canvas is static (i.e. pixels do not need to be re-read on every frame), `animate` should be set to `false` to improve performance.
|
|
28
15
|
*/
|
|
16
|
+
export type CanvasSourceSpecification = {
|
|
17
|
+
/**
|
|
18
|
+
* Source type. Must be `"canvas"`.
|
|
19
|
+
*/
|
|
20
|
+
type: 'canvas';
|
|
21
|
+
/**
|
|
22
|
+
* Four geographical coordinates denoting where to place the corners of the canvas, specified in `[longitude, latitude]` pairs.
|
|
23
|
+
*/
|
|
24
|
+
coordinates: [[number, number], [number, number], [number, number], [number, number]];
|
|
25
|
+
/**
|
|
26
|
+
* Whether the canvas source is animated. If the canvas is static (i.e. pixels do not need to be re-read on every frame), `animate` should be set to `false` to improve performance.
|
|
27
|
+
* @defaultValue true
|
|
28
|
+
*/
|
|
29
|
+
animate?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Canvas source from which to read pixels. Can be a string representing the ID of the canvas element, or the `HTMLCanvasElement` itself.
|
|
32
|
+
*/
|
|
33
|
+
canvas?: string | HTMLCanvasElement;
|
|
34
|
+
};
|
|
29
35
|
|
|
30
36
|
/**
|
|
31
|
-
* A data source containing the contents of an HTML canvas. See {@link
|
|
37
|
+
* A data source containing the contents of an HTML canvas. See {@link CanvasSourceSpecification} for detailed documentation of options.
|
|
38
|
+
*
|
|
39
|
+
* @group Sources
|
|
32
40
|
*
|
|
33
41
|
* @example
|
|
42
|
+
* ```ts
|
|
34
43
|
* // add to map
|
|
35
44
|
* map.addSource('some id', {
|
|
36
45
|
* type: 'canvas',
|
|
@@ -45,7 +54,7 @@ export type CanvasSourceSpecification = {
|
|
|
45
54
|
* });
|
|
46
55
|
*
|
|
47
56
|
* // update
|
|
48
|
-
*
|
|
57
|
+
* let mySource = map.getSource('some id');
|
|
49
58
|
* mySource.setCoordinates([
|
|
50
59
|
* [-76.54335737228394, 39.18579907229748],
|
|
51
60
|
* [-76.52803659439087, 39.1838364847587],
|
|
@@ -54,19 +63,26 @@ export type CanvasSourceSpecification = {
|
|
|
54
63
|
* ]);
|
|
55
64
|
*
|
|
56
65
|
* map.removeSource('some id'); // remove
|
|
66
|
+
* ```
|
|
57
67
|
*/
|
|
58
|
-
class CanvasSource extends ImageSource {
|
|
68
|
+
export class CanvasSource extends ImageSource {
|
|
59
69
|
options: CanvasSourceSpecification;
|
|
60
70
|
animate: boolean;
|
|
61
71
|
canvas: HTMLCanvasElement;
|
|
62
72
|
width: number;
|
|
63
73
|
height: number;
|
|
74
|
+
/**
|
|
75
|
+
* Enables animation. The image will be copied from the canvas to the map on each frame.
|
|
76
|
+
*/
|
|
64
77
|
play: () => void;
|
|
78
|
+
/**
|
|
79
|
+
* Disables animation. The map will display a static copy of the canvas image.
|
|
80
|
+
*/
|
|
65
81
|
pause: () => void;
|
|
66
82
|
_playing: boolean;
|
|
67
83
|
|
|
68
84
|
/**
|
|
69
|
-
* @
|
|
85
|
+
* @hidden
|
|
70
86
|
*/
|
|
71
87
|
constructor(id: string, options: CanvasSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented) {
|
|
72
88
|
super(id, options, dispatcher, eventedParent);
|
|
@@ -93,21 +109,7 @@ class CanvasSource extends ImageSource {
|
|
|
93
109
|
this.animate = options.animate !== undefined ? options.animate : true;
|
|
94
110
|
}
|
|
95
111
|
|
|
96
|
-
|
|
97
|
-
* Enables animation. The image will be copied from the canvas to the map on each frame.
|
|
98
|
-
* @method play
|
|
99
|
-
* @instance
|
|
100
|
-
* @memberof CanvasSource
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Disables animation. The map will display a static copy of the canvas image.
|
|
105
|
-
* @method pause
|
|
106
|
-
* @instance
|
|
107
|
-
* @memberof CanvasSource
|
|
108
|
-
*/
|
|
109
|
-
|
|
110
|
-
load() {
|
|
112
|
+
load = () => {
|
|
111
113
|
this._loaded = true;
|
|
112
114
|
if (!this.canvas) {
|
|
113
115
|
this.canvas = (this.options.canvas instanceof HTMLCanvasElement) ?
|
|
@@ -137,14 +139,14 @@ class CanvasSource extends ImageSource {
|
|
|
137
139
|
};
|
|
138
140
|
|
|
139
141
|
this._finishLoading();
|
|
140
|
-
}
|
|
142
|
+
};
|
|
141
143
|
|
|
142
144
|
/**
|
|
143
145
|
* Returns the HTML `canvas` element.
|
|
144
146
|
*
|
|
145
|
-
* @returns
|
|
147
|
+
* @returns The HTML `canvas` element.
|
|
146
148
|
*/
|
|
147
|
-
getCanvas() {
|
|
149
|
+
getCanvas(): HTMLCanvasElement {
|
|
148
150
|
return this.canvas;
|
|
149
151
|
}
|
|
150
152
|
|
|
@@ -160,21 +162,7 @@ class CanvasSource extends ImageSource {
|
|
|
160
162
|
this.pause();
|
|
161
163
|
}
|
|
162
164
|
|
|
163
|
-
|
|
164
|
-
// * Sets the canvas's coordinates and re-renders the map.
|
|
165
|
-
// *
|
|
166
|
-
// * @method setCoordinates
|
|
167
|
-
// * @instance
|
|
168
|
-
// * @memberof CanvasSource
|
|
169
|
-
// * @param {Array<Array<number>>} coordinates Four geographical coordinates,
|
|
170
|
-
// * represented as arrays of longitude and latitude numbers, which define the corners of the canvas.
|
|
171
|
-
// * The coordinates start at the top left corner of the canvas and proceed in clockwise order.
|
|
172
|
-
// * They do not have to represent a rectangle.
|
|
173
|
-
// * @returns {CanvasSource} this
|
|
174
|
-
// */
|
|
175
|
-
// setCoordinates inherited from ImageSource
|
|
176
|
-
|
|
177
|
-
prepare() {
|
|
165
|
+
prepare = () => {
|
|
178
166
|
let resize = false;
|
|
179
167
|
if (this.canvas.width !== this.width) {
|
|
180
168
|
this.width = this.canvas.width;
|
|
@@ -219,14 +207,14 @@ class CanvasSource extends ImageSource {
|
|
|
219
207
|
if (newTilesLoaded) {
|
|
220
208
|
this.fire(new Event('data', {dataType: 'source', sourceDataType: 'idle', sourceId: this.id}));
|
|
221
209
|
}
|
|
222
|
-
}
|
|
210
|
+
};
|
|
223
211
|
|
|
224
|
-
serialize():
|
|
212
|
+
serialize = (): CanvasSourceSpecification => {
|
|
225
213
|
return {
|
|
226
214
|
type: 'canvas',
|
|
227
215
|
coordinates: this.coordinates
|
|
228
216
|
};
|
|
229
|
-
}
|
|
217
|
+
};
|
|
230
218
|
|
|
231
219
|
hasTransition() {
|
|
232
220
|
return this._playing;
|
|
@@ -239,5 +227,3 @@ class CanvasSource extends ImageSource {
|
|
|
239
227
|
return false;
|
|
240
228
|
}
|
|
241
229
|
}
|
|
242
|
-
|
|
243
|
-
export default CanvasSource;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import Tile from './tile';
|
|
1
|
+
import {Tile} from './tile';
|
|
2
2
|
import {OverscaledTileID} from './tile_id';
|
|
3
|
-
import GeoJSONSource,
|
|
4
|
-
import Transform from '../geo/transform';
|
|
5
|
-
import LngLat from '../geo/lng_lat';
|
|
3
|
+
import {GeoJSONSource, GeoJSONSourceOptions} from './geojson_source';
|
|
4
|
+
import {Transform} from '../geo/transform';
|
|
5
|
+
import {LngLat} from '../geo/lng_lat';
|
|
6
6
|
import {extend} from '../util/util';
|
|
7
|
-
import Dispatcher from '../util/dispatcher';
|
|
7
|
+
import {Dispatcher} from '../util/dispatcher';
|
|
8
8
|
import {RequestManager} from '../util/request_manager';
|
|
9
9
|
|
|
10
10
|
const wrapDispatcher = (dispatcher) => {
|