@scoova/mgl 1.0.0
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/LICENSE.txt +116 -0
- package/README.md +174 -0
- package/build/banner.ts +12 -0
- package/build/bump-version-changelog.js +26 -0
- package/build/check-bundle-size.js +77 -0
- package/build/generate-dist-package.js +26 -0
- package/build/generate-doc-images.ts +78 -0
- package/build/generate-docs.ts +190 -0
- package/build/generate-shaders.ts +68 -0
- package/build/generate-struct-arrays.ts +438 -0
- package/build/generate-style-code.ts +283 -0
- package/build/readme.md +56 -0
- package/build/release-notes.js +45 -0
- package/build/rollup/bundle_prelude.js +29 -0
- package/build/rollup/maplibregl.js +22 -0
- package/build/rollup_plugins.ts +58 -0
- package/dist/LICENSE.txt +116 -0
- package/dist/maplibre-gl.css +1 -0
- package/dist/maplibre-gl.d.ts +13304 -0
- package/dist/maplibre-gl.js +59 -0
- package/dist/maplibre-gl.js.map +1 -0
- package/dist/package.json +1 -0
- package/package.json +192 -0
- package/src/css/maplibre-gl.css +854 -0
- package/src/css/svg/maplibregl-ctrl-attrib.svg +3 -0
- package/src/css/svg/maplibregl-ctrl-compass.svg +4 -0
- package/src/css/svg/maplibregl-ctrl-fullscreen.svg +3 -0
- package/src/css/svg/maplibregl-ctrl-geolocate.svg +5 -0
- package/src/css/svg/maplibregl-ctrl-logo.svg +11 -0
- package/src/css/svg/maplibregl-ctrl-shrink.svg +3 -0
- package/src/css/svg/maplibregl-ctrl-terrain.svg +3 -0
- package/src/css/svg/maplibregl-ctrl-zoom-in.svg +3 -0
- package/src/css/svg/maplibregl-ctrl-zoom-out.svg +3 -0
- package/src/data/array_types.g.ts +1130 -0
- package/src/data/bucket/circle_attributes.ts +8 -0
- package/src/data/bucket/circle_bucket.ts +197 -0
- package/src/data/bucket/fill_attributes.ts +8 -0
- package/src/data/bucket/fill_bucket.test.ts +95 -0
- package/src/data/bucket/fill_bucket.ts +228 -0
- package/src/data/bucket/fill_extrusion_attributes.ts +13 -0
- package/src/data/bucket/fill_extrusion_bucket.ts +305 -0
- package/src/data/bucket/heatmap_bucket.ts +12 -0
- package/src/data/bucket/line_attributes.ts +8 -0
- package/src/data/bucket/line_attributes_ext.ts +8 -0
- package/src/data/bucket/line_bucket.test.ts +142 -0
- package/src/data/bucket/line_bucket.ts +592 -0
- package/src/data/bucket/pattern_attributes.ts +9 -0
- package/src/data/bucket/pattern_bucket_features.ts +57 -0
- package/src/data/bucket/symbol_attributes.ts +122 -0
- package/src/data/bucket/symbol_bucket.test.ts +243 -0
- package/src/data/bucket/symbol_bucket.ts +975 -0
- package/src/data/bucket.ts +123 -0
- package/src/data/dem_data.test.ts +237 -0
- package/src/data/dem_data.ts +171 -0
- package/src/data/evaluation_feature.ts +18 -0
- package/src/data/extent.ts +13 -0
- package/src/data/feature_index.ts +337 -0
- package/src/data/feature_position_map.test.ts +33 -0
- package/src/data/feature_position_map.ts +126 -0
- package/src/data/index_array_type.ts +9 -0
- package/src/data/load_geometry.test.ts +49 -0
- package/src/data/load_geometry.ts +44 -0
- package/src/data/pos3d_attributes.ts +5 -0
- package/src/data/pos_attributes.ts +5 -0
- package/src/data/program_configuration.ts +735 -0
- package/src/data/raster_bounds_attributes.ts +6 -0
- package/src/data/segment.ts +89 -0
- package/src/geo/edge_insets.test.ts +83 -0
- package/src/geo/edge_insets.ts +146 -0
- package/src/geo/lng_lat.test.ts +65 -0
- package/src/geo/lng_lat.ts +169 -0
- package/src/geo/lng_lat_bounds.test.ts +357 -0
- package/src/geo/lng_lat_bounds.ts +356 -0
- package/src/geo/mercator_coordinate.test.ts +34 -0
- package/src/geo/mercator_coordinate.ts +157 -0
- package/src/geo/projection/projection.ts +72 -0
- package/src/geo/transform.test.ts +509 -0
- package/src/geo/transform.ts +1072 -0
- package/src/gl/color_mode.ts +31 -0
- package/src/gl/context.ts +321 -0
- package/src/gl/cull_face_mode.ts +22 -0
- package/src/gl/depth_mode.ts +26 -0
- package/src/gl/framebuffer.ts +48 -0
- package/src/gl/index_buffer.ts +55 -0
- package/src/gl/render_pool.test.ts +69 -0
- package/src/gl/render_pool.ts +93 -0
- package/src/gl/state.test.ts +125 -0
- package/src/gl/stencil_mode.ts +27 -0
- package/src/gl/types.ts +59 -0
- package/src/gl/value.ts +534 -0
- package/src/gl/vertex_buffer.test.ts +57 -0
- package/src/gl/vertex_buffer.ts +111 -0
- package/src/gl/webgl2.ts +12 -0
- package/src/index.test.ts +121 -0
- package/src/index.ts +250 -0
- package/src/render/draw_background.ts +53 -0
- package/src/render/draw_circle.ts +113 -0
- package/src/render/draw_collision_debug.ts +168 -0
- package/src/render/draw_custom.test.ts +73 -0
- package/src/render/draw_custom.ts +45 -0
- package/src/render/draw_debug.test.ts +122 -0
- package/src/render/draw_debug.ts +148 -0
- package/src/render/draw_fill.test.ts +137 -0
- package/src/render/draw_fill.ts +128 -0
- package/src/render/draw_fill_extrusion.ts +97 -0
- package/src/render/draw_heatmap.ts +228 -0
- package/src/render/draw_hillshade.ts +119 -0
- package/src/render/draw_line.ts +125 -0
- package/src/render/draw_raster.ts +133 -0
- package/src/render/draw_sky.ts +44 -0
- package/src/render/draw_symbol.test.ts +223 -0
- package/src/render/draw_symbol.ts +499 -0
- package/src/render/draw_terrain.ts +99 -0
- package/src/render/glyph_atlas.ts +83 -0
- package/src/render/glyph_manager.test.ts +147 -0
- package/src/render/glyph_manager.ts +198 -0
- package/src/render/image_atlas.ts +159 -0
- package/src/render/image_manager.ts +337 -0
- package/src/render/line_atlas.test.ts +38 -0
- package/src/render/line_atlas.ts +214 -0
- package/src/render/mesh.ts +25 -0
- package/src/render/painter.test.ts +51 -0
- package/src/render/painter.ts +666 -0
- package/src/render/program/background_program.ts +100 -0
- package/src/render/program/circle_program.ts +61 -0
- package/src/render/program/clipping_mask_program.ts +19 -0
- package/src/render/program/collision_program.ts +47 -0
- package/src/render/program/debug_program.ts +29 -0
- package/src/render/program/fill_extrusion_program.ts +120 -0
- package/src/render/program/fill_program.ts +121 -0
- package/src/render/program/heatmap_program.ts +76 -0
- package/src/render/program/hillshade_program.ts +116 -0
- package/src/render/program/line_program.ts +207 -0
- package/src/render/program/pattern.ts +102 -0
- package/src/render/program/program_uniforms.ts +46 -0
- package/src/render/program/raster_program.ts +88 -0
- package/src/render/program/sky_program.ts +28 -0
- package/src/render/program/symbol_program.ts +266 -0
- package/src/render/program/terrain_program.ts +116 -0
- package/src/render/program.ts +233 -0
- package/src/render/render_to_texture.test.ts +151 -0
- package/src/render/render_to_texture.ts +197 -0
- package/src/render/terrain.test.ts +322 -0
- package/src/render/terrain.ts +464 -0
- package/src/render/texture.ts +114 -0
- package/src/render/uniform_binding.test.ts +122 -0
- package/src/render/uniform_binding.ts +157 -0
- package/src/render/update_pattern_positions_in_program.test.ts +74 -0
- package/src/render/update_pattern_positions_in_program.ts +50 -0
- package/src/render/vertex_array_object.ts +163 -0
- package/src/shaders/README.md +42 -0
- package/src/shaders/_prelude.fragment.glsl +19 -0
- package/src/shaders/_prelude.fragment.glsl.g.ts +2 -0
- package/src/shaders/_prelude.vertex.glsl +148 -0
- package/src/shaders/_prelude.vertex.glsl.g.ts +2 -0
- package/src/shaders/background.fragment.glsl +10 -0
- package/src/shaders/background.fragment.glsl.g.ts +2 -0
- package/src/shaders/background.vertex.glsl +7 -0
- package/src/shaders/background.vertex.glsl.g.ts +2 -0
- package/src/shaders/background_pattern.fragment.glsl +28 -0
- package/src/shaders/background_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/background_pattern.vertex.glsl +19 -0
- package/src/shaders/background_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/circle.fragment.glsl +34 -0
- package/src/shaders/circle.fragment.glsl.g.ts +2 -0
- package/src/shaders/circle.vertex.glsl +68 -0
- package/src/shaders/circle.vertex.glsl.g.ts +2 -0
- package/src/shaders/clipping_mask.fragment.glsl +3 -0
- package/src/shaders/clipping_mask.fragment.glsl.g.ts +2 -0
- package/src/shaders/clipping_mask.vertex.glsl +7 -0
- package/src/shaders/clipping_mask.vertex.glsl.g.ts +2 -0
- package/src/shaders/collision_box.fragment.glsl +20 -0
- package/src/shaders/collision_box.fragment.glsl.g.ts +2 -0
- package/src/shaders/collision_box.vertex.glsl +27 -0
- package/src/shaders/collision_box.vertex.glsl.g.ts +2 -0
- package/src/shaders/collision_circle.fragment.glsl +17 -0
- package/src/shaders/collision_circle.fragment.glsl.g.ts +2 -0
- package/src/shaders/collision_circle.vertex.glsl +59 -0
- package/src/shaders/collision_circle.vertex.glsl.g.ts +2 -0
- package/src/shaders/debug.fragment.glsl +9 -0
- package/src/shaders/debug.fragment.glsl.g.ts +2 -0
- package/src/shaders/debug.vertex.glsl +12 -0
- package/src/shaders/debug.vertex.glsl.g.ts +2 -0
- package/src/shaders/encode_attribute.test.ts +11 -0
- package/src/shaders/encode_attribute.ts +13 -0
- package/src/shaders/fill.fragment.glsl +13 -0
- package/src/shaders/fill.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill.vertex.glsl +13 -0
- package/src/shaders/fill.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion.fragment.glsl +9 -0
- package/src/shaders/fill_extrusion.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion.vertex.glsl +84 -0
- package/src/shaders/fill_extrusion.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion_pattern.fragment.glsl +47 -0
- package/src/shaders/fill_extrusion_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion_pattern.vertex.glsl +96 -0
- package/src/shaders/fill_extrusion_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_outline.fragment.glsl +17 -0
- package/src/shaders/fill_outline.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_outline.vertex.glsl +17 -0
- package/src/shaders/fill_outline.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_outline_pattern.fragment.glsl +43 -0
- package/src/shaders/fill_outline_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_outline_pattern.vertex.glsl +44 -0
- package/src/shaders/fill_outline_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_pattern.fragment.glsl +39 -0
- package/src/shaders/fill_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_pattern.vertex.glsl +39 -0
- package/src/shaders/fill_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/heatmap.fragment.glsl +22 -0
- package/src/shaders/heatmap.fragment.glsl.g.ts +2 -0
- package/src/shaders/heatmap.vertex.glsl +54 -0
- package/src/shaders/heatmap.vertex.glsl.g.ts +2 -0
- package/src/shaders/heatmap_texture.fragment.glsl +15 -0
- package/src/shaders/heatmap_texture.fragment.glsl.g.ts +2 -0
- package/src/shaders/heatmap_texture.vertex.glsl +11 -0
- package/src/shaders/heatmap_texture.vertex.glsl.g.ts +2 -0
- package/src/shaders/hillshade.fragment.glsl +52 -0
- package/src/shaders/hillshade.fragment.glsl.g.ts +2 -0
- package/src/shaders/hillshade.vertex.glsl +11 -0
- package/src/shaders/hillshade.vertex.glsl.g.ts +2 -0
- package/src/shaders/hillshade_prepare.fragment.glsl +77 -0
- package/src/shaders/hillshade_prepare.fragment.glsl.g.ts +2 -0
- package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
- package/src/shaders/hillshade_prepare.vertex.glsl.g.ts +2 -0
- package/src/shaders/line.fragment.glsl +30 -0
- package/src/shaders/line.fragment.glsl.g.ts +2 -0
- package/src/shaders/line.vertex.glsl +89 -0
- package/src/shaders/line.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_gradient.fragment.glsl +34 -0
- package/src/shaders/line_gradient.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_gradient.vertex.glsl +92 -0
- package/src/shaders/line_gradient.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_pattern.fragment.glsl +77 -0
- package/src/shaders/line_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_pattern.vertex.glsl +103 -0
- package/src/shaders/line_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_sdf.fragment.glsl +45 -0
- package/src/shaders/line_sdf.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_sdf.vertex.glsl +101 -0
- package/src/shaders/line_sdf.vertex.glsl.g.ts +2 -0
- package/src/shaders/raster.fragment.glsl +53 -0
- package/src/shaders/raster.fragment.glsl.g.ts +2 -0
- package/src/shaders/raster.vertex.glsl +21 -0
- package/src/shaders/raster.vertex.glsl.g.ts +2 -0
- package/src/shaders/shaders.ts +197 -0
- package/src/shaders/sky.fragment.glsl +17 -0
- package/src/shaders/sky.fragment.glsl.g.ts +2 -0
- package/src/shaders/sky.vertex.glsl +5 -0
- package/src/shaders/sky.vertex.glsl.g.ts +2 -0
- package/src/shaders/symbol_icon.fragment.glsl +17 -0
- package/src/shaders/symbol_icon.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_icon.vertex.glsl +117 -0
- package/src/shaders/symbol_icon.vertex.glsl.g.ts +2 -0
- package/src/shaders/symbol_sdf.fragment.glsl +58 -0
- package/src/shaders/symbol_sdf.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_sdf.vertex.glsl +142 -0
- package/src/shaders/symbol_sdf.vertex.glsl.g.ts +2 -0
- package/src/shaders/symbol_text_and_icon.fragment.glsl +68 -0
- package/src/shaders/symbol_text_and_icon.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_text_and_icon.vertex.glsl +140 -0
- package/src/shaders/symbol_text_and_icon.vertex.glsl.g.ts +2 -0
- package/src/shaders/terrain.fragment.glsl +32 -0
- package/src/shaders/terrain.fragment.glsl.g.ts +2 -0
- package/src/shaders/terrain.vertex.glsl +17 -0
- package/src/shaders/terrain.vertex.glsl.g.ts +2 -0
- package/src/shaders/terrain_coords.fragment.glsl +11 -0
- package/src/shaders/terrain_coords.fragment.glsl.g.ts +2 -0
- package/src/shaders/terrain_coords.vertex.glsl +13 -0
- package/src/shaders/terrain_coords.vertex.glsl.g.ts +2 -0
- package/src/shaders/terrain_depth.fragment.glsl +15 -0
- package/src/shaders/terrain_depth.fragment.glsl.g.ts +2 -0
- package/src/shaders/terrain_depth.vertex.glsl +13 -0
- package/src/shaders/terrain_depth.vertex.glsl.g.ts +2 -0
- package/src/source/canvas_source.test.ts +210 -0
- package/src/source/canvas_source.ts +227 -0
- package/src/source/geojson_source.test.ts +492 -0
- package/src/source/geojson_source.ts +431 -0
- package/src/source/geojson_source_diff.test.ts +364 -0
- package/src/source/geojson_source_diff.ts +172 -0
- package/src/source/geojson_worker_source.test.ts +399 -0
- package/src/source/geojson_worker_source.ts +303 -0
- package/src/source/geojson_wrapper.test.ts +32 -0
- package/src/source/geojson_wrapper.ts +81 -0
- package/src/source/image_source.test.ts +235 -0
- package/src/source/image_source.ts +338 -0
- package/src/source/load_tilejson.ts +47 -0
- package/src/source/pixels_to_tile_units.ts +25 -0
- package/src/source/protocol_crud.ts +48 -0
- package/src/source/query_features.test.ts +31 -0
- package/src/source/query_features.ts +252 -0
- package/src/source/raster_dem_tile_source.test.ts +158 -0
- package/src/source/raster_dem_tile_source.ts +166 -0
- package/src/source/raster_dem_tile_worker_source.test.ts +36 -0
- package/src/source/raster_dem_tile_worker_source.ts +38 -0
- package/src/source/raster_tile_source.test.ts +206 -0
- package/src/source/raster_tile_source.ts +227 -0
- package/src/source/rtl_text_plugin_main_thread.test.ts +170 -0
- package/src/source/rtl_text_plugin_main_thread.ts +89 -0
- package/src/source/rtl_text_plugin_status.ts +33 -0
- package/src/source/rtl_text_plugin_worker.ts +49 -0
- package/src/source/source.test.ts +41 -0
- package/src/source/source.ts +186 -0
- package/src/source/source_cache.test.ts +2069 -0
- package/src/source/source_cache.ts +1102 -0
- package/src/source/source_state.ts +157 -0
- package/src/source/terrain_source_cache.test.ts +105 -0
- package/src/source/terrain_source_cache.ts +204 -0
- package/src/source/tile.test.ts +290 -0
- package/src/source/tile.ts +478 -0
- package/src/source/tile_bounds.ts +34 -0
- package/src/source/tile_cache.test.ts +130 -0
- package/src/source/tile_cache.ts +208 -0
- package/src/source/tile_id.test.ts +112 -0
- package/src/source/tile_id.ts +221 -0
- package/src/source/vector_tile_source.test.ts +401 -0
- package/src/source/vector_tile_source.ts +283 -0
- package/src/source/vector_tile_worker_source.test.ts +396 -0
- package/src/source/vector_tile_worker_source.ts +199 -0
- package/src/source/video_source.test.ts +124 -0
- package/src/source/video_source.ts +204 -0
- package/src/source/worker.test.ts +233 -0
- package/src/source/worker.ts +301 -0
- package/src/source/worker_source.ts +117 -0
- package/src/source/worker_tile.test.ts +226 -0
- package/src/source/worker_tile.ts +208 -0
- package/src/style/create_style_layer.ts +39 -0
- package/src/style/evaluation_parameters.ts +62 -0
- package/src/style/format_section_override.test.ts +62 -0
- package/src/style/format_section_override.ts +50 -0
- package/src/style/light.test.ts +86 -0
- package/src/style/light.ts +135 -0
- package/src/style/load_glyph_range.test.ts +40 -0
- package/src/style/load_glyph_range.ts +32 -0
- package/src/style/load_sprite.test.ts +227 -0
- package/src/style/load_sprite.ts +71 -0
- package/src/style/parse_glyph_pbf.ts +42 -0
- package/src/style/pauseable_placement.ts +138 -0
- package/src/style/properties.ts +726 -0
- package/src/style/query_utils.test.ts +107 -0
- package/src/style/query_utils.ts +70 -0
- package/src/style/sky.ts +127 -0
- package/src/style/style.test.ts +2654 -0
- package/src/style/style.ts +1814 -0
- package/src/style/style_glyph.ts +25 -0
- package/src/style/style_image.ts +188 -0
- package/src/style/style_layer/background_style_layer.ts +17 -0
- package/src/style/style_layer/background_style_layer_properties.g.ts +40 -0
- package/src/style/style_layer/circle_style_layer.ts +98 -0
- package/src/style/style_layer/circle_style_layer_properties.g.ts +76 -0
- package/src/style/style_layer/custom_style_layer.ts +233 -0
- package/src/style/style_layer/fill_extrusion_style_layer.ts +224 -0
- package/src/style/style_layer/fill_extrusion_style_layer_properties.g.ts +55 -0
- package/src/style/style_layer/fill_style_layer.test.ts +37 -0
- package/src/style/style_layer/fill_style_layer.ts +65 -0
- package/src/style/style_layer/fill_style_layer_properties.g.ts +64 -0
- package/src/style/style_layer/heatmap_style_layer.ts +74 -0
- package/src/style/style_layer/heatmap_style_layer_properties.g.ts +46 -0
- package/src/style/style_layer/hillshade_style_layer.ts +21 -0
- package/src/style/style_layer/hillshade_style_layer_properties.g.ts +49 -0
- package/src/style/style_layer/line_style_layer.test.ts +50 -0
- package/src/style/style_layer/line_style_layer.ts +131 -0
- package/src/style/style_layer/line_style_layer_properties.g.ts +88 -0
- package/src/style/style_layer/overlap_mode.test.ts +57 -0
- package/src/style/style_layer/overlap_mode.ts +25 -0
- package/src/style/style_layer/raster_style_layer.ts +17 -0
- package/src/style/style_layer/raster_style_layer_properties.g.ts +55 -0
- package/src/style/style_layer/symbol_style_layer.ts +195 -0
- package/src/style/style_layer/symbol_style_layer_properties.g.ts +218 -0
- package/src/style/style_layer/typed_style_layer.ts +9 -0
- package/src/style/style_layer/variable_text_anchor.test.ts +117 -0
- package/src/style/style_layer/variable_text_anchor.ts +163 -0
- package/src/style/style_layer.test.ts +372 -0
- package/src/style/style_layer.ts +287 -0
- package/src/style/style_layer_index.test.ts +99 -0
- package/src/style/style_layer_index.ts +78 -0
- package/src/style/validate_style.ts +53 -0
- package/src/style/zoom_history.ts +40 -0
- package/src/symbol/anchor.test.ts +14 -0
- package/src/symbol/anchor.ts +22 -0
- package/src/symbol/check_max_angle.test.ts +54 -0
- package/src/symbol/check_max_angle.ts +76 -0
- package/src/symbol/clip_line.test.ts +154 -0
- package/src/symbol/clip_line.ts +66 -0
- package/src/symbol/collision_feature.test.ts +98 -0
- package/src/symbol/collision_feature.ts +114 -0
- package/src/symbol/collision_index.test.ts +19 -0
- package/src/symbol/collision_index.ts +618 -0
- package/src/symbol/cross_tile_symbol_index.test.ts +260 -0
- package/src/symbol/cross_tile_symbol_index.ts +367 -0
- package/src/symbol/get_anchors.test.ts +113 -0
- package/src/symbol/get_anchors.ts +167 -0
- package/src/symbol/grid_index.test.ts +75 -0
- package/src/symbol/grid_index.ts +414 -0
- package/src/symbol/merge_lines.test.ts +30 -0
- package/src/symbol/merge_lines.ts +80 -0
- package/src/symbol/one_em.ts +3 -0
- package/src/symbol/opacity_state.ts +23 -0
- package/src/symbol/path_interpolator.test.ts +134 -0
- package/src/symbol/path_interpolator.ts +55 -0
- package/src/symbol/placement.ts +1371 -0
- package/src/symbol/projection.test.ts +171 -0
- package/src/symbol/projection.ts +833 -0
- package/src/symbol/quads.test.ts +157 -0
- package/src/symbol/quads.ts +349 -0
- package/src/symbol/shaping.test.ts +360 -0
- package/src/symbol/shaping.ts +911 -0
- package/src/symbol/symbol_layout.ts +739 -0
- package/src/symbol/symbol_size.ts +129 -0
- package/src/symbol/symbol_style_layer.test.ts +103 -0
- package/src/symbol/transform_text.ts +27 -0
- package/src/ui/anchor.ts +27 -0
- package/src/ui/camera.test.ts +2301 -0
- package/src/ui/camera.ts +1520 -0
- package/src/ui/control/attribution_control.test.ts +543 -0
- package/src/ui/control/attribution_control.ts +209 -0
- package/src/ui/control/control.ts +67 -0
- package/src/ui/control/fullscreen_control.test.ts +114 -0
- package/src/ui/control/fullscreen_control.ts +189 -0
- package/src/ui/control/geolocate_control.test.ts +619 -0
- package/src/ui/control/geolocate_control.ts +725 -0
- package/src/ui/control/logo_control.test.ts +88 -0
- package/src/ui/control/logo_control.ts +86 -0
- package/src/ui/control/navigation_control.test.ts +238 -0
- package/src/ui/control/navigation_control.ts +294 -0
- package/src/ui/control/scale_control.test.ts +52 -0
- package/src/ui/control/scale_control.ts +152 -0
- package/src/ui/control/terrain_control.test.ts +58 -0
- package/src/ui/control/terrain_control.ts +74 -0
- package/src/ui/default_locale.ts +25 -0
- package/src/ui/events.ts +758 -0
- package/src/ui/handler/box_zoom.test.ts +163 -0
- package/src/ui/handler/box_zoom.ts +171 -0
- package/src/ui/handler/click_zoom.ts +55 -0
- package/src/ui/handler/cooperative_gestures.test.ts +338 -0
- package/src/ui/handler/cooperative_gestures.ts +111 -0
- package/src/ui/handler/dblclick_zoom.test.ts +151 -0
- package/src/ui/handler/drag_handler.ts +174 -0
- package/src/ui/handler/drag_move_state_manager.ts +115 -0
- package/src/ui/handler/drag_pan.test.ts +487 -0
- package/src/ui/handler/drag_rotate.test.ts +859 -0
- package/src/ui/handler/handler_util.ts +10 -0
- package/src/ui/handler/keyboard.test.ts +235 -0
- package/src/ui/handler/keyboard.ts +212 -0
- package/src/ui/handler/map_event.test.ts +158 -0
- package/src/ui/handler/map_event.ts +161 -0
- package/src/ui/handler/mouse.ts +92 -0
- package/src/ui/handler/mouse_handler_interface.test.ts +111 -0
- package/src/ui/handler/mouse_rotate.test.ts +62 -0
- package/src/ui/handler/one_finger_touch_drag.ts +45 -0
- package/src/ui/handler/one_finger_touch_drag_handler_interface.test.ts +77 -0
- package/src/ui/handler/scroll_zoom.test.ts +382 -0
- package/src/ui/handler/scroll_zoom.ts +379 -0
- package/src/ui/handler/shim/dblclick_zoom.ts +64 -0
- package/src/ui/handler/shim/drag_pan.ts +104 -0
- package/src/ui/handler/shim/drag_rotate.ts +76 -0
- package/src/ui/handler/shim/two_fingers_touch.ts +112 -0
- package/src/ui/handler/tap_drag_zoom.test.ts +113 -0
- package/src/ui/handler/tap_drag_zoom.ts +112 -0
- package/src/ui/handler/tap_recognizer.ts +138 -0
- package/src/ui/handler/tap_zoom.ts +98 -0
- package/src/ui/handler/touch_pan.ts +115 -0
- package/src/ui/handler/transform-provider.ts +44 -0
- package/src/ui/handler/two_fingers_touch.test.ts +283 -0
- package/src/ui/handler/two_fingers_touch.ts +336 -0
- package/src/ui/handler_inertia.ts +157 -0
- package/src/ui/handler_manager.ts +637 -0
- package/src/ui/hash.test.ts +404 -0
- package/src/ui/hash.ts +153 -0
- package/src/ui/map.ts +3393 -0
- package/src/ui/map_tests/map_animation.test.ts +61 -0
- package/src/ui/map_tests/map_basic.test.ts +223 -0
- package/src/ui/map_tests/map_bounds.test.ts +123 -0
- package/src/ui/map_tests/map_calculate_camera_options.test.ts +113 -0
- package/src/ui/map_tests/map_canvas.test.ts +59 -0
- package/src/ui/map_tests/map_control.test.ts +61 -0
- package/src/ui/map_tests/map_disable_handlers.test.ts +38 -0
- package/src/ui/map_tests/map_events.test.ts +1001 -0
- package/src/ui/map_tests/map_feature_state.test.ts +421 -0
- package/src/ui/map_tests/map_images.test.ts +175 -0
- package/src/ui/map_tests/map_is_moving.test.ts +164 -0
- package/src/ui/map_tests/map_is_rotating.test.ts +62 -0
- package/src/ui/map_tests/map_is_zooming.test.ts +86 -0
- package/src/ui/map_tests/map_layer.test.ts +457 -0
- package/src/ui/map_tests/map_options.test.ts +64 -0
- package/src/ui/map_tests/map_pitch.test.ts +90 -0
- package/src/ui/map_tests/map_pixel_ratio.test.ts +75 -0
- package/src/ui/map_tests/map_query_rendered_features.test.ts +93 -0
- package/src/ui/map_tests/map_render.test.ts +90 -0
- package/src/ui/map_tests/map_request_render_frame.test.ts +51 -0
- package/src/ui/map_tests/map_resize.test.ts +120 -0
- package/src/ui/map_tests/map_style.test.ts +541 -0
- package/src/ui/map_tests/map_terrian.test.ts +104 -0
- package/src/ui/map_tests/map_webgl.test.ts +72 -0
- package/src/ui/map_tests/map_world_copies.test.ts +103 -0
- package/src/ui/map_tests/map_zoom.test.ts +95 -0
- package/src/ui/marker.test.ts +1149 -0
- package/src/ui/marker.ts +880 -0
- package/src/ui/popup.test.ts +827 -0
- package/src/ui/popup.ts +717 -0
- package/src/util/abort_error.ts +21 -0
- package/src/util/actor.test.ts +218 -0
- package/src/util/actor.ts +241 -0
- package/src/util/actor_messages.ts +149 -0
- package/src/util/ajax.test.ts +237 -0
- package/src/util/ajax.ts +297 -0
- package/src/util/browser.test.ts +23 -0
- package/src/util/browser.ts +63 -0
- package/src/util/color_ramp.test.ts +105 -0
- package/src/util/color_ramp.ts +56 -0
- package/src/util/config.ts +29 -0
- package/src/util/dictionary_coder.ts +23 -0
- package/src/util/dispatcher.test.ts +76 -0
- package/src/util/dispatcher.ts +78 -0
- package/src/util/dom.ts +135 -0
- package/src/util/evented.test.ts +231 -0
- package/src/util/evented.ts +178 -0
- package/src/util/find_pole_of_inaccessibility.test.ts +21 -0
- package/src/util/find_pole_of_inaccessibility.ts +130 -0
- package/src/util/geolocation_support.test.ts +43 -0
- package/src/util/geolocation_support.ts +23 -0
- package/src/util/global_worker_pool.ts +65 -0
- package/src/util/image.ts +150 -0
- package/src/util/image_request.test.ts +408 -0
- package/src/util/image_request.ts +246 -0
- package/src/util/intersection_tests.ts +206 -0
- package/src/util/is_char_in_unicode_block.test.ts +15 -0
- package/src/util/is_char_in_unicode_block.ts +345 -0
- package/src/util/offscreen_canvas_distorted.test.ts +13 -0
- package/src/util/offscreen_canvas_distorted.ts +39 -0
- package/src/util/offscreen_canvas_supported.ts +11 -0
- package/src/util/performance.ts +117 -0
- package/src/util/primitives.test.ts +140 -0
- package/src/util/primitives.ts +143 -0
- package/src/util/request_manager.ts +42 -0
- package/src/util/resolve_tokens.test.ts +45 -0
- package/src/util/resolve_tokens.ts +17 -0
- package/src/util/script_detection.test.ts +138 -0
- package/src/util/script_detection.ts +376 -0
- package/src/util/smart_wrap.test.ts +97 -0
- package/src/util/smart_wrap.ts +58 -0
- package/src/util/struct_array.test.ts +101 -0
- package/src/util/struct_array.ts +246 -0
- package/src/util/style.test.ts +34 -0
- package/src/util/style.ts +28 -0
- package/src/util/task_queue.test.ts +114 -0
- package/src/util/task_queue.ts +64 -0
- package/src/util/test/util.ts +185 -0
- package/src/util/throttle.test.ts +42 -0
- package/src/util/throttle.ts +28 -0
- package/src/util/throttled_invoker.ts +41 -0
- package/src/util/transferable_grid_index.test.ts +56 -0
- package/src/util/transferable_grid_index.ts +214 -0
- package/src/util/util.test.ts +414 -0
- package/src/util/util.ts +724 -0
- package/src/util/vectortile_to_geojson.ts +72 -0
- package/src/util/verticalize_punctuation.ts +110 -0
- package/src/util/web_worker.ts +16 -0
- package/src/util/web_worker_transfer.test.ts +153 -0
- package/src/util/web_worker_transfer.ts +254 -0
- package/src/util/webp_supported.ts +63 -0
- package/src/util/worker_pool.test.ts +43 -0
- package/src/util/worker_pool.ts +58 -0
- package/src/util/world_bounds.test.ts +59 -0
- package/src/util/world_bounds.ts +46 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {GeoJSONWrapper} from './geojson_wrapper';
|
|
2
|
+
|
|
3
|
+
describe('geojsonwrapper', () => {
|
|
4
|
+
test('linestring', () => {
|
|
5
|
+
const features = [{
|
|
6
|
+
type: 2,
|
|
7
|
+
geometry: [[[0, 0], [10, 10]]],
|
|
8
|
+
tags: {hello: 'world'}
|
|
9
|
+
}];
|
|
10
|
+
|
|
11
|
+
const wrap = new GeoJSONWrapper(features as any);
|
|
12
|
+
const feature = wrap.feature(0);
|
|
13
|
+
|
|
14
|
+
expect(feature).toBeTruthy();
|
|
15
|
+
expect(feature.loadGeometry()).toEqual([[{x: 0, y: 0}, {x: 10, y: 10}]]);
|
|
16
|
+
expect(feature.type).toBe(2);
|
|
17
|
+
expect(feature.properties).toEqual({hello: 'world'});
|
|
18
|
+
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('point', () => {
|
|
22
|
+
const features = [{
|
|
23
|
+
type: 1,
|
|
24
|
+
geometry: [[0, 1]],
|
|
25
|
+
tags: {}
|
|
26
|
+
}];
|
|
27
|
+
|
|
28
|
+
const wrap = new GeoJSONWrapper(features as any);
|
|
29
|
+
const feature = wrap.feature(0);
|
|
30
|
+
expect(feature.loadGeometry()).toEqual([[{x: 0, y: 1}]]);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import Point from '@mapbox/point-geometry';
|
|
2
|
+
|
|
3
|
+
import mvt from '@mapbox/vector-tile';
|
|
4
|
+
import type {VectorTileFeature, VectorTileLayer, VectorTile} from '@mapbox/vector-tile';
|
|
5
|
+
const toGeoJSON = mvt.VectorTileFeature.prototype.toGeoJSON;
|
|
6
|
+
import {EXTENT} from '../data/extent';
|
|
7
|
+
import type {TileFeature, AnyProps} from 'supercluster';
|
|
8
|
+
import type {Feature as GeoJSONVTFeature} from 'geojson-vt';
|
|
9
|
+
|
|
10
|
+
export type Feature = TileFeature<AnyProps, AnyProps> | GeoJSONVTFeature;
|
|
11
|
+
|
|
12
|
+
class FeatureWrapper implements VectorTileFeature {
|
|
13
|
+
_feature: Feature;
|
|
14
|
+
|
|
15
|
+
extent: number;
|
|
16
|
+
type: Feature['type'];
|
|
17
|
+
id: number;
|
|
18
|
+
properties: {[_: string]: string | number | boolean};
|
|
19
|
+
|
|
20
|
+
constructor(feature: Feature) {
|
|
21
|
+
this._feature = feature;
|
|
22
|
+
|
|
23
|
+
this.extent = EXTENT;
|
|
24
|
+
this.type = feature.type;
|
|
25
|
+
this.properties = feature.tags;
|
|
26
|
+
|
|
27
|
+
// If the feature has a top-level `id` property, copy it over, but only
|
|
28
|
+
// if it can be coerced to an integer, because this wrapper is used for
|
|
29
|
+
// serializing geojson feature data into vector tile PBF data, and the
|
|
30
|
+
// vector tile spec only supports integer values for feature ids --
|
|
31
|
+
// allowing non-integer values here results in a non-compliant PBF
|
|
32
|
+
// that causes an exception when it is parsed with vector-tile-js
|
|
33
|
+
if ('id' in feature && !isNaN(feature.id as any)) {
|
|
34
|
+
this.id = parseInt(feature.id, 10);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
loadGeometry() {
|
|
39
|
+
if (this._feature.type === 1) {
|
|
40
|
+
const geometry = [];
|
|
41
|
+
for (const point of this._feature.geometry) {
|
|
42
|
+
geometry.push([new Point(point[0], point[1])]);
|
|
43
|
+
}
|
|
44
|
+
return geometry;
|
|
45
|
+
} else {
|
|
46
|
+
const geometry = [];
|
|
47
|
+
for (const ring of this._feature.geometry) {
|
|
48
|
+
const newRing = [];
|
|
49
|
+
for (const point of ring) {
|
|
50
|
+
newRing.push(new Point(point[0], point[1]));
|
|
51
|
+
}
|
|
52
|
+
geometry.push(newRing);
|
|
53
|
+
}
|
|
54
|
+
return geometry;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
toGeoJSON(x: number, y: number, z: number) {
|
|
59
|
+
return toGeoJSON.call(this, x, y, z);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export class GeoJSONWrapper implements VectorTile, VectorTileLayer {
|
|
64
|
+
layers: {[_: string]: VectorTileLayer};
|
|
65
|
+
name: string;
|
|
66
|
+
extent: number;
|
|
67
|
+
length: number;
|
|
68
|
+
_features: Array<Feature>;
|
|
69
|
+
|
|
70
|
+
constructor(features: Array<Feature>) {
|
|
71
|
+
this.layers = {'_geojsonTileLayer': this};
|
|
72
|
+
this.name = '_geojsonTileLayer';
|
|
73
|
+
this.extent = EXTENT;
|
|
74
|
+
this.length = features.length;
|
|
75
|
+
this._features = features;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
feature(i: number): VectorTileFeature {
|
|
79
|
+
return new FeatureWrapper(this._features[i]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import {ImageSource} from './image_source';
|
|
2
|
+
import {Evented} from '../util/evented';
|
|
3
|
+
import {Transform} from '../geo/transform';
|
|
4
|
+
import {extend} from '../util/util';
|
|
5
|
+
import {type FakeServer, fakeServer} from 'nise';
|
|
6
|
+
import {RequestManager} from '../util/request_manager';
|
|
7
|
+
import {sleep, stubAjaxGetImage} from '../util/test/util';
|
|
8
|
+
import {Tile} from './tile';
|
|
9
|
+
import {OverscaledTileID} from './tile_id';
|
|
10
|
+
import {VertexBuffer} from '../gl/vertex_buffer';
|
|
11
|
+
import {SegmentVector} from '../data/segment';
|
|
12
|
+
import {Texture} from '../render/texture';
|
|
13
|
+
import type {ImageSourceSpecification} from '@maplibre/maplibre-gl-style-spec';
|
|
14
|
+
|
|
15
|
+
function createSource(options) {
|
|
16
|
+
options = extend({
|
|
17
|
+
coordinates: [[0, 0], [1, 0], [1, 1], [0, 1]]
|
|
18
|
+
}, options);
|
|
19
|
+
|
|
20
|
+
const source = new ImageSource('id', options, {} as any, options.eventedParent);
|
|
21
|
+
return source;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class StubMap extends Evented {
|
|
25
|
+
transform: Transform;
|
|
26
|
+
painter: any;
|
|
27
|
+
_requestManager: RequestManager;
|
|
28
|
+
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
this.transform = new Transform();
|
|
32
|
+
this._requestManager = {
|
|
33
|
+
transformRequest: (url) => {
|
|
34
|
+
return {url};
|
|
35
|
+
}
|
|
36
|
+
} as any as RequestManager;
|
|
37
|
+
this.painter = {
|
|
38
|
+
context: {
|
|
39
|
+
gl: {}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('ImageSource', () => {
|
|
46
|
+
stubAjaxGetImage(undefined);
|
|
47
|
+
let server: FakeServer;
|
|
48
|
+
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
global.fetch = null;
|
|
51
|
+
server = fakeServer.create();
|
|
52
|
+
server.respondWith(new ArrayBuffer(1));
|
|
53
|
+
server.respondWith('/missing-image.png', [404, {}, '']);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('constructor', () => {
|
|
57
|
+
const source = createSource({url: '/image.png'});
|
|
58
|
+
|
|
59
|
+
expect(source.minzoom).toBe(0);
|
|
60
|
+
expect(source.maxzoom).toBe(22);
|
|
61
|
+
expect(source.tileSize).toBe(512);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('fires dataloading event', async () => {
|
|
65
|
+
const source = createSource({url: '/image.png'});
|
|
66
|
+
source.on('dataloading', (e) => {
|
|
67
|
+
expect(e.dataType).toBe('source');
|
|
68
|
+
});
|
|
69
|
+
source.onAdd(new StubMap() as any);
|
|
70
|
+
server.respond();
|
|
71
|
+
await sleep(0);
|
|
72
|
+
expect(source.image).toBeTruthy();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('transforms url request', () => {
|
|
76
|
+
const source = createSource({url: '/image.png'});
|
|
77
|
+
const map = new StubMap() as any;
|
|
78
|
+
const spy = jest.spyOn(map._requestManager, 'transformRequest');
|
|
79
|
+
source.onAdd(map);
|
|
80
|
+
server.respond();
|
|
81
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
82
|
+
expect(spy.mock.calls[0][0]).toBe('/image.png');
|
|
83
|
+
expect(spy.mock.calls[0][1]).toBe('Image');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('updates url from updateImage', () => {
|
|
87
|
+
const source = createSource({url: '/image.png'});
|
|
88
|
+
const map = new StubMap() as any;
|
|
89
|
+
const spy = jest.spyOn(map._requestManager, 'transformRequest');
|
|
90
|
+
source.onAdd(map);
|
|
91
|
+
server.respond();
|
|
92
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
93
|
+
expect(spy.mock.calls[0][0]).toBe('/image.png');
|
|
94
|
+
expect(spy.mock.calls[0][1]).toBe('Image');
|
|
95
|
+
source.updateImage({url: '/image2.png'});
|
|
96
|
+
server.respond();
|
|
97
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
|
98
|
+
expect(spy.mock.calls[1][0]).toBe('/image2.png');
|
|
99
|
+
expect(spy.mock.calls[1][1]).toBe('Image');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('sets coordinates', () => {
|
|
103
|
+
const source = createSource({url: '/image.png'});
|
|
104
|
+
const map = new StubMap() as any;
|
|
105
|
+
source.onAdd(map);
|
|
106
|
+
server.respond();
|
|
107
|
+
const beforeSerialized = source.serialize();
|
|
108
|
+
expect(beforeSerialized.coordinates).toEqual([[0, 0], [1, 0], [1, 1], [0, 1]]);
|
|
109
|
+
source.setCoordinates([[0, 0], [-1, 0], [-1, -1], [0, -1]]);
|
|
110
|
+
const afterSerialized = source.serialize();
|
|
111
|
+
expect(afterSerialized.coordinates).toEqual([[0, 0], [-1, 0], [-1, -1], [0, -1]]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('sets coordinates via updateImage', async () => {
|
|
115
|
+
const source = createSource({url: '/image.png'});
|
|
116
|
+
const map = new StubMap() as any;
|
|
117
|
+
source.onAdd(map);
|
|
118
|
+
server.respond();
|
|
119
|
+
const beforeSerialized = source.serialize();
|
|
120
|
+
expect(beforeSerialized.coordinates).toEqual([[0, 0], [1, 0], [1, 1], [0, 1]]);
|
|
121
|
+
source.updateImage({
|
|
122
|
+
url: '/image2.png',
|
|
123
|
+
coordinates: [[0, 0], [-1, 0], [-1, -1], [0, -1]]
|
|
124
|
+
});
|
|
125
|
+
server.respond();
|
|
126
|
+
await sleep(0);
|
|
127
|
+
const afterSerialized = source.serialize();
|
|
128
|
+
expect(afterSerialized.coordinates).toEqual([[0, 0], [-1, 0], [-1, -1], [0, -1]]);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('fires data event when content is loaded', () => new Promise<void>(done => {
|
|
132
|
+
const source = createSource({url: '/image.png'});
|
|
133
|
+
source.on('data', (e) => {
|
|
134
|
+
if (e.dataType === 'source' && e.sourceDataType === 'content') {
|
|
135
|
+
expect(typeof source.tileID == 'object').toBeTruthy();
|
|
136
|
+
done();
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
source.onAdd(new StubMap() as any);
|
|
140
|
+
server.respond();
|
|
141
|
+
}));
|
|
142
|
+
|
|
143
|
+
test('fires data event when metadata is loaded', () => new Promise<void>(done => {
|
|
144
|
+
const source = createSource({url: '/image.png'});
|
|
145
|
+
source.on('data', (e) => {
|
|
146
|
+
if (e.dataType === 'source' && e.sourceDataType === 'metadata') {
|
|
147
|
+
done();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
source.onAdd(new StubMap() as any);
|
|
151
|
+
server.respond();
|
|
152
|
+
}));
|
|
153
|
+
|
|
154
|
+
test('fires idle event on prepare call when there is at least one not loaded tile', () => new Promise<void>(done => {
|
|
155
|
+
const source = createSource({url: '/image.png'});
|
|
156
|
+
const tile = new Tile(new OverscaledTileID(1, 0, 1, 0, 0), 512);
|
|
157
|
+
source.on('data', (e) => {
|
|
158
|
+
if (e.dataType === 'source' && e.sourceDataType === 'idle') {
|
|
159
|
+
expect(tile.state).toBe('loaded');
|
|
160
|
+
done();
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
source.onAdd(new StubMap() as any);
|
|
164
|
+
server.respond();
|
|
165
|
+
|
|
166
|
+
source.tiles[String(tile.tileID.wrap)] = tile;
|
|
167
|
+
source.image = new ImageBitmap();
|
|
168
|
+
// assign dummies directly so we don't need to stub the gl things
|
|
169
|
+
source.boundsBuffer = {destroy: () => {}} as VertexBuffer;
|
|
170
|
+
source.boundsSegments = {} as SegmentVector;
|
|
171
|
+
source.texture = {} as Texture;
|
|
172
|
+
source.prepare();
|
|
173
|
+
}));
|
|
174
|
+
|
|
175
|
+
test('serialize url and coordinates', () => {
|
|
176
|
+
const source = createSource({url: '/image.png'});
|
|
177
|
+
|
|
178
|
+
const serialized = source.serialize() as ImageSourceSpecification;
|
|
179
|
+
expect(serialized.type).toBe('image');
|
|
180
|
+
expect(serialized.url).toBe('/image.png');
|
|
181
|
+
expect(serialized.coordinates).toEqual([[0, 0], [1, 0], [1, 1], [0, 1]]);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('allows using updateImage before initial image is loaded', async () => {
|
|
185
|
+
const map = new StubMap() as any;
|
|
186
|
+
const source = createSource({url: '/image.png', eventedParent: map});
|
|
187
|
+
|
|
188
|
+
// Suppress errors because we're aborting when updating.
|
|
189
|
+
map.on('error', () => {});
|
|
190
|
+
source.onAdd(map);
|
|
191
|
+
expect(source.image).toBeUndefined();
|
|
192
|
+
source.updateImage({url: '/image2.png'});
|
|
193
|
+
server.respond();
|
|
194
|
+
await sleep(10);
|
|
195
|
+
|
|
196
|
+
expect(source.image).toBeTruthy();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('cancels request if updateImage is used', () => {
|
|
200
|
+
const map = new StubMap() as any;
|
|
201
|
+
const source = createSource({url: '/image.png', eventedParent: map});
|
|
202
|
+
|
|
203
|
+
// Suppress errors because we're aborting.
|
|
204
|
+
map.on('error', () => {});
|
|
205
|
+
source.onAdd(map);
|
|
206
|
+
|
|
207
|
+
const spy = jest.spyOn(server.requests[0] as any, 'abort');
|
|
208
|
+
|
|
209
|
+
source.updateImage({url: '/image2.png'});
|
|
210
|
+
expect(spy).toHaveBeenCalled();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('marks the source as loaded when the request has received a response', async () => {
|
|
214
|
+
const map = new StubMap() as any;
|
|
215
|
+
const source = createSource({url: '/image.png', eventedParent: map});
|
|
216
|
+
|
|
217
|
+
expect(source.loaded()).toBe(false);
|
|
218
|
+
source.onAdd(map);
|
|
219
|
+
server.respond();
|
|
220
|
+
await sleep(0);
|
|
221
|
+
expect(source.loaded()).toBe(true);
|
|
222
|
+
|
|
223
|
+
const missingImagesource = createSource({url: '/missing-image.png', eventedParent: map});
|
|
224
|
+
|
|
225
|
+
// Suppress errors as we're loading a missing image.
|
|
226
|
+
map.on('error', () => {});
|
|
227
|
+
|
|
228
|
+
expect(missingImagesource.loaded()).toBe(false);
|
|
229
|
+
missingImagesource.onAdd(map);
|
|
230
|
+
server.respond();
|
|
231
|
+
await sleep(0);
|
|
232
|
+
|
|
233
|
+
expect(missingImagesource.loaded()).toBe(true);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import {CanonicalTileID} from './tile_id';
|
|
2
|
+
import {Event, ErrorEvent, Evented} from '../util/evented';
|
|
3
|
+
import {ImageRequest} from '../util/image_request';
|
|
4
|
+
import {ResourceType} from '../util/request_manager';
|
|
5
|
+
import {EXTENT} from '../data/extent';
|
|
6
|
+
import {RasterBoundsArray} from '../data/array_types.g';
|
|
7
|
+
import rasterBoundsAttributes from '../data/raster_bounds_attributes';
|
|
8
|
+
import {SegmentVector} from '../data/segment';
|
|
9
|
+
import {Texture} from '../render/texture';
|
|
10
|
+
import {MercatorCoordinate} from '../geo/mercator_coordinate';
|
|
11
|
+
|
|
12
|
+
import type {Source} from './source';
|
|
13
|
+
import type {CanvasSourceSpecification} from './canvas_source';
|
|
14
|
+
import type {Map} from '../ui/map';
|
|
15
|
+
import type {Dispatcher} from '../util/dispatcher';
|
|
16
|
+
import type {Tile} from './tile';
|
|
17
|
+
import type {VertexBuffer} from '../gl/vertex_buffer';
|
|
18
|
+
import type {
|
|
19
|
+
ImageSourceSpecification,
|
|
20
|
+
VideoSourceSpecification
|
|
21
|
+
} from '@maplibre/maplibre-gl-style-spec';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Four geographical coordinates,
|
|
25
|
+
* represented as arrays of longitude and latitude numbers, which define the corners of the image.
|
|
26
|
+
* The coordinates start at the top left corner of the image and proceed in clockwise order.
|
|
27
|
+
* They do not have to represent a rectangle.
|
|
28
|
+
*/
|
|
29
|
+
export type Coordinates = [[number, number], [number, number], [number, number], [number, number]];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The options object for the {@link ImageSource#updateImage} method
|
|
33
|
+
*/
|
|
34
|
+
export type UpdateImageOptions = {
|
|
35
|
+
/**
|
|
36
|
+
* Required image URL.
|
|
37
|
+
*/
|
|
38
|
+
url: string;
|
|
39
|
+
/**
|
|
40
|
+
* The image coordinates
|
|
41
|
+
*/
|
|
42
|
+
coordinates?: Coordinates;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A data source containing an image.
|
|
47
|
+
* (See the [Style Specification](https://maplibre.org/maplibre-style-spec/#sources-image) for detailed documentation of options.)
|
|
48
|
+
*
|
|
49
|
+
* @group Sources
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* // add to map
|
|
54
|
+
* map.addSource('some id', {
|
|
55
|
+
* type: 'image',
|
|
56
|
+
* url: 'https://www.maplibre.org/images/foo.png',
|
|
57
|
+
* coordinates: [
|
|
58
|
+
* [-76.54, 39.18],
|
|
59
|
+
* [-76.52, 39.18],
|
|
60
|
+
* [-76.52, 39.17],
|
|
61
|
+
* [-76.54, 39.17]
|
|
62
|
+
* ]
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // update coordinates
|
|
66
|
+
* let mySource = map.getSource('some id');
|
|
67
|
+
* mySource.setCoordinates([
|
|
68
|
+
* [-76.54335737228394, 39.18579907229748],
|
|
69
|
+
* [-76.52803659439087, 39.1838364847587],
|
|
70
|
+
* [-76.5295386314392, 39.17683392507606],
|
|
71
|
+
* [-76.54520273208618, 39.17876344106642]
|
|
72
|
+
* ]);
|
|
73
|
+
*
|
|
74
|
+
* // update url and coordinates simultaneously
|
|
75
|
+
* mySource.updateImage({
|
|
76
|
+
* url: 'https://www.maplibre.org/images/bar.png',
|
|
77
|
+
* coordinates: [
|
|
78
|
+
* [-76.54335737228394, 39.18579907229748],
|
|
79
|
+
* [-76.52803659439087, 39.1838364847587],
|
|
80
|
+
* [-76.5295386314392, 39.17683392507606],
|
|
81
|
+
* [-76.54520273208618, 39.17876344106642]
|
|
82
|
+
* ]
|
|
83
|
+
* })
|
|
84
|
+
*
|
|
85
|
+
* map.removeSource('some id'); // remove
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export class ImageSource extends Evented implements Source {
|
|
89
|
+
type: string;
|
|
90
|
+
id: string;
|
|
91
|
+
minzoom: number;
|
|
92
|
+
maxzoom: number;
|
|
93
|
+
tileSize: number;
|
|
94
|
+
url: string;
|
|
95
|
+
|
|
96
|
+
coordinates: Coordinates;
|
|
97
|
+
tiles: {[_: string]: Tile};
|
|
98
|
+
options: any;
|
|
99
|
+
dispatcher: Dispatcher;
|
|
100
|
+
map: Map;
|
|
101
|
+
texture: Texture | null;
|
|
102
|
+
image: HTMLImageElement | ImageBitmap;
|
|
103
|
+
tileID: CanonicalTileID;
|
|
104
|
+
_boundsArray: RasterBoundsArray;
|
|
105
|
+
boundsBuffer: VertexBuffer;
|
|
106
|
+
boundsSegments: SegmentVector;
|
|
107
|
+
_loaded: boolean;
|
|
108
|
+
_request: AbortController;
|
|
109
|
+
|
|
110
|
+
/** @internal */
|
|
111
|
+
constructor(id: string, options: ImageSourceSpecification | VideoSourceSpecification | CanvasSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented) {
|
|
112
|
+
super();
|
|
113
|
+
this.id = id;
|
|
114
|
+
this.dispatcher = dispatcher;
|
|
115
|
+
this.coordinates = options.coordinates;
|
|
116
|
+
|
|
117
|
+
this.type = 'image';
|
|
118
|
+
this.minzoom = 0;
|
|
119
|
+
this.maxzoom = 22;
|
|
120
|
+
this.tileSize = 512;
|
|
121
|
+
this.tiles = {};
|
|
122
|
+
this._loaded = false;
|
|
123
|
+
|
|
124
|
+
this.setEventedParent(eventedParent);
|
|
125
|
+
|
|
126
|
+
this.options = options;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async load(newCoordinates?: Coordinates): Promise<void> {
|
|
130
|
+
this._loaded = false;
|
|
131
|
+
this.fire(new Event('dataloading', {dataType: 'source'}));
|
|
132
|
+
|
|
133
|
+
this.url = this.options.url;
|
|
134
|
+
|
|
135
|
+
this._request = new AbortController();
|
|
136
|
+
try {
|
|
137
|
+
const image = await ImageRequest.getImage(this.map._requestManager.transformRequest(this.url, ResourceType.Image), this._request);
|
|
138
|
+
this._request = null;
|
|
139
|
+
this._loaded = true;
|
|
140
|
+
|
|
141
|
+
if (image && image.data) {
|
|
142
|
+
this.image = image.data;
|
|
143
|
+
if (newCoordinates) {
|
|
144
|
+
this.coordinates = newCoordinates;
|
|
145
|
+
}
|
|
146
|
+
this._finishLoading();
|
|
147
|
+
}
|
|
148
|
+
} catch (err) {
|
|
149
|
+
this._request = null;
|
|
150
|
+
this._loaded = true;
|
|
151
|
+
this.fire(new ErrorEvent(err));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
loaded(): boolean {
|
|
156
|
+
return this._loaded;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Updates the image URL and, optionally, the coordinates. To avoid having the image flash after changing,
|
|
161
|
+
* set the `raster-fade-duration` paint property on the raster layer to 0.
|
|
162
|
+
*
|
|
163
|
+
* @param options - The options object.
|
|
164
|
+
*/
|
|
165
|
+
updateImage(options: UpdateImageOptions): this {
|
|
166
|
+
if (!options.url) {
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (this._request) {
|
|
171
|
+
this._request.abort();
|
|
172
|
+
this._request = null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
this.options.url = options.url;
|
|
176
|
+
this.load(options.coordinates).finally(() => { this.texture = null; });
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
_finishLoading() {
|
|
181
|
+
if (this.map) {
|
|
182
|
+
this.setCoordinates(this.coordinates);
|
|
183
|
+
this.fire(new Event('data', {dataType: 'source', sourceDataType: 'metadata'}));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
onAdd(map: Map) {
|
|
188
|
+
this.map = map;
|
|
189
|
+
this.load();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
onRemove() {
|
|
193
|
+
if (this._request) {
|
|
194
|
+
this._request.abort();
|
|
195
|
+
this._request = null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Sets the image's coordinates and re-renders the map.
|
|
201
|
+
*
|
|
202
|
+
* @param coordinates - Four geographical coordinates,
|
|
203
|
+
* represented as arrays of longitude and latitude numbers, which define the corners of the image.
|
|
204
|
+
* The coordinates start at the top left corner of the image and proceed in clockwise order.
|
|
205
|
+
* They do not have to represent a rectangle.
|
|
206
|
+
*/
|
|
207
|
+
setCoordinates(coordinates: Coordinates): this {
|
|
208
|
+
this.coordinates = coordinates;
|
|
209
|
+
|
|
210
|
+
// Calculate which mercator tile is suitable for rendering the video in
|
|
211
|
+
// and create a buffer with the corner coordinates. These coordinates
|
|
212
|
+
// may be outside the tile, because raster tiles aren't clipped when rendering.
|
|
213
|
+
|
|
214
|
+
// transform the geo coordinates into (zoom 0) tile space coordinates
|
|
215
|
+
const cornerCoords = coordinates.map(MercatorCoordinate.fromLngLat);
|
|
216
|
+
|
|
217
|
+
// Compute the coordinates of the tile we'll use to hold this image's
|
|
218
|
+
// render data
|
|
219
|
+
this.tileID = getCoordinatesCenterTileID(cornerCoords);
|
|
220
|
+
|
|
221
|
+
// Constrain min/max zoom to our tile's zoom level in order to force
|
|
222
|
+
// SourceCache to request this tile (no matter what the map's zoom
|
|
223
|
+
// level)
|
|
224
|
+
this.minzoom = this.maxzoom = this.tileID.z;
|
|
225
|
+
|
|
226
|
+
// Transform the corner coordinates into the coordinate space of our
|
|
227
|
+
// tile.
|
|
228
|
+
const tileCoords = cornerCoords.map((coord) => this.tileID.getTilePoint(coord)._round());
|
|
229
|
+
|
|
230
|
+
this._boundsArray = new RasterBoundsArray();
|
|
231
|
+
this._boundsArray.emplaceBack(tileCoords[0].x, tileCoords[0].y, 0, 0);
|
|
232
|
+
this._boundsArray.emplaceBack(tileCoords[1].x, tileCoords[1].y, EXTENT, 0);
|
|
233
|
+
this._boundsArray.emplaceBack(tileCoords[3].x, tileCoords[3].y, 0, EXTENT);
|
|
234
|
+
this._boundsArray.emplaceBack(tileCoords[2].x, tileCoords[2].y, EXTENT, EXTENT);
|
|
235
|
+
|
|
236
|
+
if (this.boundsBuffer) {
|
|
237
|
+
this.boundsBuffer.destroy();
|
|
238
|
+
delete this.boundsBuffer;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
this.fire(new Event('data', {dataType: 'source', sourceDataType: 'content'}));
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
prepare() {
|
|
246
|
+
if (Object.keys(this.tiles).length === 0 || !this.image) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const context = this.map.painter.context;
|
|
251
|
+
const gl = context.gl;
|
|
252
|
+
|
|
253
|
+
if (!this.boundsBuffer) {
|
|
254
|
+
this.boundsBuffer = context.createVertexBuffer(this._boundsArray, rasterBoundsAttributes.members);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (!this.boundsSegments) {
|
|
258
|
+
this.boundsSegments = SegmentVector.simpleSegment(0, 0, 4, 2);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (!this.texture) {
|
|
262
|
+
this.texture = new Texture(context, this.image, gl.RGBA);
|
|
263
|
+
this.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
let newTilesLoaded = false;
|
|
267
|
+
for (const w in this.tiles) {
|
|
268
|
+
const tile = this.tiles[w];
|
|
269
|
+
if (tile.state !== 'loaded') {
|
|
270
|
+
tile.state = 'loaded';
|
|
271
|
+
tile.texture = this.texture;
|
|
272
|
+
newTilesLoaded = true;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (newTilesLoaded) {
|
|
277
|
+
this.fire(new Event('data', {dataType: 'source', sourceDataType: 'idle', sourceId: this.id}));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async loadTile(tile: Tile): Promise<void> {
|
|
282
|
+
// We have a single tile -- whose coordinates are this.tileID -- that
|
|
283
|
+
// covers the image we want to render. If that's the one being
|
|
284
|
+
// requested, set it up with the image; otherwise, mark the tile as
|
|
285
|
+
// `errored` to indicate that we have no data for it.
|
|
286
|
+
// If the world wraps, we may have multiple "wrapped" copies of the
|
|
287
|
+
// single tile.
|
|
288
|
+
if (this.tileID && this.tileID.equals(tile.tileID.canonical)) {
|
|
289
|
+
this.tiles[String(tile.tileID.wrap)] = tile;
|
|
290
|
+
tile.buckets = {};
|
|
291
|
+
} else {
|
|
292
|
+
tile.state = 'errored';
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
serialize(): ImageSourceSpecification | VideoSourceSpecification | CanvasSourceSpecification {
|
|
297
|
+
return {
|
|
298
|
+
type: 'image',
|
|
299
|
+
url: this.options.url,
|
|
300
|
+
coordinates: this.coordinates
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
hasTransition() {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Given a list of coordinates, get their center as a coordinate.
|
|
311
|
+
*
|
|
312
|
+
* @returns centerpoint
|
|
313
|
+
* @internal
|
|
314
|
+
*/
|
|
315
|
+
export function getCoordinatesCenterTileID(coords: Array<MercatorCoordinate>) {
|
|
316
|
+
let minX = Infinity;
|
|
317
|
+
let minY = Infinity;
|
|
318
|
+
let maxX = -Infinity;
|
|
319
|
+
let maxY = -Infinity;
|
|
320
|
+
|
|
321
|
+
for (const coord of coords) {
|
|
322
|
+
minX = Math.min(minX, coord.x);
|
|
323
|
+
minY = Math.min(minY, coord.y);
|
|
324
|
+
maxX = Math.max(maxX, coord.x);
|
|
325
|
+
maxY = Math.max(maxY, coord.y);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const dx = maxX - minX;
|
|
329
|
+
const dy = maxY - minY;
|
|
330
|
+
const dMax = Math.max(dx, dy);
|
|
331
|
+
const zoom = Math.max(0, Math.floor(-Math.log(dMax) / Math.LN2));
|
|
332
|
+
const tilesAtZoom = Math.pow(2, zoom);
|
|
333
|
+
|
|
334
|
+
return new CanonicalTileID(
|
|
335
|
+
zoom,
|
|
336
|
+
Math.floor((minX + maxX) / 2 * tilesAtZoom),
|
|
337
|
+
Math.floor((minY + maxY) / 2 * tilesAtZoom));
|
|
338
|
+
}
|