@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,209 @@
|
|
|
1
|
+
import {DOM} from '../../util/dom';
|
|
2
|
+
|
|
3
|
+
import type {Map} from '../map';
|
|
4
|
+
import type {ControlPosition, IControl} from './control';
|
|
5
|
+
import type {MapDataEvent} from '../events';
|
|
6
|
+
import type {StyleSpecification} from '@maplibre/maplibre-gl-style-spec';
|
|
7
|
+
/**
|
|
8
|
+
* The {@link AttributionControl} options object
|
|
9
|
+
*/
|
|
10
|
+
export type AttributionControlOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* If `true`, the attribution control will always collapse when moving the map. If `false`,
|
|
13
|
+
* force the expanded attribution control. The default is a responsive attribution that collapses when the user moves the map on maps less than 640 pixels wide.
|
|
14
|
+
* **Attribution should not be collapsed if it can comfortably fit on the map. `compact` should only be used to modify default attribution when map size makes it impossible to fit default attribution and when the automatic compact resizing for default settings are not sufficient.**
|
|
15
|
+
*/
|
|
16
|
+
compact?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Attributions to show in addition to any other attributions.
|
|
19
|
+
*/
|
|
20
|
+
customAttribution?: string | Array<string>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const defaultAttributionControlOptions: AttributionControlOptions = {
|
|
24
|
+
compact: true,
|
|
25
|
+
customAttribution: '<a href="https://maplibre.org/" target="_blank">MapLibre</a>'
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An `AttributionControl` control presents the map's attribution information. By default, the attribution control is expanded (regardless of map width).
|
|
30
|
+
* @group Markers and Controls
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* let map = new Map({attributionControl: false})
|
|
34
|
+
* .addControl(new AttributionControl({
|
|
35
|
+
* compact: true
|
|
36
|
+
* }));
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export class AttributionControl implements IControl {
|
|
40
|
+
options: AttributionControlOptions;
|
|
41
|
+
_map: Map;
|
|
42
|
+
_compact: boolean | undefined;
|
|
43
|
+
_container: HTMLElement;
|
|
44
|
+
_innerContainer: HTMLElement;
|
|
45
|
+
_compactButton: HTMLElement;
|
|
46
|
+
_editLink: HTMLAnchorElement;
|
|
47
|
+
_attribHTML: string;
|
|
48
|
+
styleId: string;
|
|
49
|
+
styleOwner: string;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param options - the attribution options
|
|
53
|
+
*/
|
|
54
|
+
constructor(options: AttributionControlOptions = defaultAttributionControlOptions) {
|
|
55
|
+
this.options = options;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getDefaultPosition(): ControlPosition {
|
|
59
|
+
return 'bottom-right';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** {@inheritDoc IControl.onAdd} */
|
|
63
|
+
onAdd(map: Map) {
|
|
64
|
+
this._map = map;
|
|
65
|
+
this._compact = this.options.compact;
|
|
66
|
+
this._container = DOM.create('details', 'maplibregl-ctrl maplibregl-ctrl-attrib');
|
|
67
|
+
this._compactButton = DOM.create('summary', 'maplibregl-ctrl-attrib-button', this._container);
|
|
68
|
+
this._compactButton.addEventListener('click', this._toggleAttribution);
|
|
69
|
+
this._setElementTitle(this._compactButton, 'ToggleAttribution');
|
|
70
|
+
this._innerContainer = DOM.create('div', 'maplibregl-ctrl-attrib-inner', this._container);
|
|
71
|
+
|
|
72
|
+
this._updateAttributions();
|
|
73
|
+
this._updateCompact();
|
|
74
|
+
|
|
75
|
+
this._map.on('styledata', this._updateData);
|
|
76
|
+
this._map.on('sourcedata', this._updateData);
|
|
77
|
+
this._map.on('terrain', this._updateData);
|
|
78
|
+
this._map.on('resize', this._updateCompact);
|
|
79
|
+
this._map.on('drag', this._updateCompactMinimize);
|
|
80
|
+
|
|
81
|
+
return this._container;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** {@inheritDoc IControl.onRemove} */
|
|
85
|
+
onRemove() {
|
|
86
|
+
DOM.remove(this._container);
|
|
87
|
+
|
|
88
|
+
this._map.off('styledata', this._updateData);
|
|
89
|
+
this._map.off('sourcedata', this._updateData);
|
|
90
|
+
this._map.off('terrain', this._updateData);
|
|
91
|
+
this._map.off('resize', this._updateCompact);
|
|
92
|
+
this._map.off('drag', this._updateCompactMinimize);
|
|
93
|
+
|
|
94
|
+
this._map = undefined;
|
|
95
|
+
this._compact = undefined;
|
|
96
|
+
this._attribHTML = undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
_setElementTitle(element: HTMLElement, title: 'ToggleAttribution' | 'MapFeedback') {
|
|
100
|
+
const str = this._map._getUIString(`AttributionControl.${title}`);
|
|
101
|
+
element.title = str;
|
|
102
|
+
element.setAttribute('aria-label', str);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
_toggleAttribution = () => {
|
|
106
|
+
if (this._container.classList.contains('maplibregl-compact')) {
|
|
107
|
+
if (this._container.classList.contains('maplibregl-compact-show')) {
|
|
108
|
+
this._container.setAttribute('open', '');
|
|
109
|
+
this._container.classList.remove('maplibregl-compact-show');
|
|
110
|
+
} else {
|
|
111
|
+
this._container.classList.add('maplibregl-compact-show');
|
|
112
|
+
this._container.removeAttribute('open');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
_updateData = (e: MapDataEvent) => {
|
|
118
|
+
if (e && (e.sourceDataType === 'metadata' || e.sourceDataType === 'visibility' || e.dataType === 'style' || e.type === 'terrain')) {
|
|
119
|
+
this._updateAttributions();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
_updateAttributions() {
|
|
124
|
+
if (!this._map.style) return;
|
|
125
|
+
let attributions: Array<string> = [];
|
|
126
|
+
if (this.options.customAttribution) {
|
|
127
|
+
if (Array.isArray(this.options.customAttribution)) {
|
|
128
|
+
attributions = attributions.concat(
|
|
129
|
+
this.options.customAttribution.map(attribution => {
|
|
130
|
+
if (typeof attribution !== 'string') return '';
|
|
131
|
+
return attribution;
|
|
132
|
+
})
|
|
133
|
+
);
|
|
134
|
+
} else if (typeof this.options.customAttribution === 'string') {
|
|
135
|
+
attributions.push(this.options.customAttribution);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (this._map.style.stylesheet) {
|
|
140
|
+
const stylesheet = this._map.style.stylesheet as StyleSpecification & { owner: string; id: string };
|
|
141
|
+
this.styleOwner = stylesheet.owner;
|
|
142
|
+
this.styleId = stylesheet.id;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const sourceCaches = this._map.style.sourceCaches;
|
|
146
|
+
for (const id in sourceCaches) {
|
|
147
|
+
const sourceCache = sourceCaches[id];
|
|
148
|
+
if (sourceCache.used || sourceCache.usedForTerrain) {
|
|
149
|
+
const source = sourceCache.getSource();
|
|
150
|
+
if (source.attribution && attributions.indexOf(source.attribution) < 0) {
|
|
151
|
+
attributions.push(source.attribution);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// remove any entries that are whitespace
|
|
157
|
+
attributions = attributions.filter(e => String(e).trim());
|
|
158
|
+
|
|
159
|
+
// remove any entries that are substrings of another entry.
|
|
160
|
+
// first sort by length so that substrings come first
|
|
161
|
+
attributions.sort((a, b) => a.length - b.length);
|
|
162
|
+
attributions = attributions.filter((attrib, i) => {
|
|
163
|
+
for (let j = i + 1; j < attributions.length; j++) {
|
|
164
|
+
if (attributions[j].indexOf(attrib) >= 0) { return false; }
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// check if attribution string is different to minimize DOM changes
|
|
170
|
+
const attribHTML = attributions.join(' | ');
|
|
171
|
+
if (attribHTML === this._attribHTML) return;
|
|
172
|
+
|
|
173
|
+
this._attribHTML = attribHTML;
|
|
174
|
+
|
|
175
|
+
if (attributions.length) {
|
|
176
|
+
this._innerContainer.innerHTML = attribHTML;
|
|
177
|
+
this._container.classList.remove('maplibregl-attrib-empty');
|
|
178
|
+
} else {
|
|
179
|
+
this._container.classList.add('maplibregl-attrib-empty');
|
|
180
|
+
}
|
|
181
|
+
this._updateCompact();
|
|
182
|
+
// remove old DOM node from _editLink
|
|
183
|
+
this._editLink = null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
_updateCompact = () => {
|
|
187
|
+
if (this._map.getCanvasContainer().offsetWidth <= 640 || this._compact) {
|
|
188
|
+
if (this._compact === false) {
|
|
189
|
+
this._container.setAttribute('open', '');
|
|
190
|
+
} else if (!this._container.classList.contains('maplibregl-compact') && !this._container.classList.contains('maplibregl-attrib-empty')) {
|
|
191
|
+
this._container.setAttribute('open', '');
|
|
192
|
+
this._container.classList.add('maplibregl-compact', 'maplibregl-compact-show');
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
this._container.setAttribute('open', '');
|
|
196
|
+
if (this._container.classList.contains('maplibregl-compact')) {
|
|
197
|
+
this._container.classList.remove('maplibregl-compact', 'maplibregl-compact-show');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
_updateCompactMinimize = () => {
|
|
203
|
+
if (this._container.classList.contains('maplibregl-compact')) {
|
|
204
|
+
if (this._container.classList.contains('maplibregl-compact-show')) {
|
|
205
|
+
this._container.classList.remove('maplibregl-compact-show');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type {Map} from '../map';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A position defintion for the control to be placed, can be in one of the corners of the map.
|
|
5
|
+
* When two or more controls are places in the same location they are stacked toward the center of the map.
|
|
6
|
+
*/
|
|
7
|
+
export type ControlPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Interface for interactive controls added to the map. This is a
|
|
11
|
+
* specification for implementers to model: it is not
|
|
12
|
+
* an exported method or class.
|
|
13
|
+
*
|
|
14
|
+
* Controls must implement `onAdd` and `onRemove`, and must own an
|
|
15
|
+
* element, which is often a `div` element. To use MapLibre GL JS's
|
|
16
|
+
* default control styling, add the `maplibregl-ctrl` class to your control's
|
|
17
|
+
* node.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* class HelloWorldControl: IControl {
|
|
22
|
+
* onAdd(map) {
|
|
23
|
+
* this._map = map;
|
|
24
|
+
* this._container = document.createElement('div');
|
|
25
|
+
* this._container.className = 'maplibregl-ctrl';
|
|
26
|
+
* this._container.textContent = 'Hello, world';
|
|
27
|
+
* return this._container;
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* onRemove() {
|
|
31
|
+
* this._container.parentNode.removeChild(this._container);
|
|
32
|
+
* this._map = undefined;
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export interface IControl {
|
|
38
|
+
/**
|
|
39
|
+
* Register a control on the map and give it a chance to register event listeners
|
|
40
|
+
* and resources. This method is called by {@link Map#addControl}
|
|
41
|
+
* internally.
|
|
42
|
+
*
|
|
43
|
+
* @param map - the Map this control will be added to
|
|
44
|
+
* @returns The control's container element. This should
|
|
45
|
+
* be created by the control and returned by onAdd without being attached
|
|
46
|
+
* to the DOM: the map will insert the control's element into the DOM
|
|
47
|
+
* as necessary.
|
|
48
|
+
*/
|
|
49
|
+
onAdd(map: Map): HTMLElement;
|
|
50
|
+
/**
|
|
51
|
+
* Unregister a control on the map and give it a chance to detach event listeners
|
|
52
|
+
* and resources. This method is called by {@link Map#removeControl}
|
|
53
|
+
* internally.
|
|
54
|
+
*
|
|
55
|
+
* @param map - the Map this control will be removed from
|
|
56
|
+
*/
|
|
57
|
+
onRemove(map: Map): void;
|
|
58
|
+
/**
|
|
59
|
+
* Optionally provide a default position for this control. If this method
|
|
60
|
+
* is implemented and {@link Map#addControl} is called without the `position`
|
|
61
|
+
* parameter, the value returned by getDefaultPosition will be used as the
|
|
62
|
+
* control's position.
|
|
63
|
+
*
|
|
64
|
+
* @returns a control position, one of the values valid in addControl.
|
|
65
|
+
*/
|
|
66
|
+
readonly getDefaultPosition?: () => ControlPosition;
|
|
67
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {createMap, beforeMapTest} from '../../util/test/util';
|
|
2
|
+
import {FullscreenControl} from './fullscreen_control';
|
|
3
|
+
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
beforeMapTest();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
describe('FullscreenControl', () => {
|
|
9
|
+
test('renders control', () => {
|
|
10
|
+
Object.defineProperty(window.document, 'fullscreenEnabled', {
|
|
11
|
+
value: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
});
|
|
14
|
+
const map = createMap(undefined, undefined);
|
|
15
|
+
const fullscreen = new FullscreenControl({});
|
|
16
|
+
map.addControl(fullscreen);
|
|
17
|
+
|
|
18
|
+
expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-fullscreen')).toHaveLength(1);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('makes optional container element full screen', () => {
|
|
22
|
+
Object.defineProperty(window.document, 'fullscreenEnabled', {
|
|
23
|
+
value: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const map = createMap(undefined, undefined);
|
|
28
|
+
const container = window.document.querySelector('body')!;
|
|
29
|
+
const fullscreen = new FullscreenControl({container});
|
|
30
|
+
map.addControl(fullscreen);
|
|
31
|
+
const control = map._controls.find((ctrl) => {
|
|
32
|
+
return Object.prototype.hasOwnProperty.call(ctrl, '_fullscreen');
|
|
33
|
+
}) as FullscreenControl;
|
|
34
|
+
control._onClickFullscreen();
|
|
35
|
+
|
|
36
|
+
expect(control._container.tagName).toBe('BODY');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('uses pseudo fullscreen when fullscreen is not supported', () => {
|
|
40
|
+
const map = createMap(undefined, undefined);
|
|
41
|
+
const mapContainer = map.getContainer();
|
|
42
|
+
|
|
43
|
+
const fullscreen = new FullscreenControl({});
|
|
44
|
+
map.addControl(fullscreen);
|
|
45
|
+
const control = map._controls.find((ctrl) => {
|
|
46
|
+
return Object.prototype.hasOwnProperty.call(ctrl, '_fullscreen');
|
|
47
|
+
}) as FullscreenControl;
|
|
48
|
+
|
|
49
|
+
expect(mapContainer.classList.contains('maplibregl-pseudo-fullscreen')).toBe(false);
|
|
50
|
+
control._onClickFullscreen();
|
|
51
|
+
expect(mapContainer.classList.contains('maplibregl-pseudo-fullscreen')).toBe(true);
|
|
52
|
+
control._onClickFullscreen();
|
|
53
|
+
expect(mapContainer.classList.contains('maplibregl-pseudo-fullscreen')).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('start and end events fire for fullscreen button clicks', () => {
|
|
57
|
+
const map = createMap(undefined, undefined);
|
|
58
|
+
const fullscreen = new FullscreenControl({});
|
|
59
|
+
|
|
60
|
+
const fullscreenstart = jest.fn();
|
|
61
|
+
const fullscreenend = jest.fn();
|
|
62
|
+
|
|
63
|
+
fullscreen.on('fullscreenstart', fullscreenstart);
|
|
64
|
+
fullscreen.on('fullscreenend', fullscreenend);
|
|
65
|
+
|
|
66
|
+
map.addControl(fullscreen);
|
|
67
|
+
|
|
68
|
+
const click = new window.Event('click');
|
|
69
|
+
|
|
70
|
+
// Simulate a click to the fullscreen button
|
|
71
|
+
fullscreen._fullscreenButton.dispatchEvent(click);
|
|
72
|
+
expect(fullscreenstart).toHaveBeenCalled();
|
|
73
|
+
expect(fullscreenend).not.toHaveBeenCalled();
|
|
74
|
+
|
|
75
|
+
// Second simulated click would exit fullscreen mode
|
|
76
|
+
fullscreen._fullscreenButton.dispatchEvent(click);
|
|
77
|
+
expect(fullscreenend).toHaveBeenCalled();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('disables cooperative gestures when fullscreen becomes active', () => {
|
|
81
|
+
const cooperativeGestures = true;
|
|
82
|
+
const map = createMap({cooperativeGestures});
|
|
83
|
+
const fullscreen = new FullscreenControl({});
|
|
84
|
+
|
|
85
|
+
map.addControl(fullscreen);
|
|
86
|
+
|
|
87
|
+
const click = new window.Event('click');
|
|
88
|
+
|
|
89
|
+
// Simulate a click to the fullscreen button
|
|
90
|
+
fullscreen._fullscreenButton.dispatchEvent(click);
|
|
91
|
+
expect(map.cooperativeGestures.isEnabled()).toBeFalsy();
|
|
92
|
+
|
|
93
|
+
// Second simulated click would exit fullscreen mode
|
|
94
|
+
fullscreen._fullscreenButton.dispatchEvent(click);
|
|
95
|
+
expect(map.cooperativeGestures.isEnabled()).toBeTruthy();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('if never set, cooperative gestures remain disabled when fullscreen exits', () => {
|
|
99
|
+
const map = createMap({cooperativeGestures: false});
|
|
100
|
+
const fullscreen = new FullscreenControl({});
|
|
101
|
+
|
|
102
|
+
map.addControl(fullscreen);
|
|
103
|
+
|
|
104
|
+
const click = new window.Event('click');
|
|
105
|
+
|
|
106
|
+
// Simulate a click to the fullscreen button
|
|
107
|
+
fullscreen._fullscreenButton.dispatchEvent(click);
|
|
108
|
+
expect(map.cooperativeGestures.isEnabled()).toBeFalsy();
|
|
109
|
+
|
|
110
|
+
// Second simulated click would exit fullscreen mode
|
|
111
|
+
fullscreen._fullscreenButton.dispatchEvent(click);
|
|
112
|
+
expect(map.cooperativeGestures.isEnabled()).toBeFalsy();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import {DOM} from '../../util/dom';
|
|
2
|
+
|
|
3
|
+
import {warnOnce} from '../../util/util';
|
|
4
|
+
|
|
5
|
+
import {Event, Evented} from '../../util/evented';
|
|
6
|
+
import type {Map} from '../map';
|
|
7
|
+
import type {IControl} from './control';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The {@link FullscreenControl} options object
|
|
11
|
+
*/
|
|
12
|
+
type FullscreenControlOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* `container` is the [compatible DOM element](https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen#Compatible_elements) which should be made full screen. By default, the map container element will be made full screen.
|
|
15
|
+
*/
|
|
16
|
+
container?: HTMLElement;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A `FullscreenControl` control contains a button for toggling the map in and out of fullscreen mode.
|
|
21
|
+
* When [requestFullscreen](https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullscreen) is not supported, fullscreen is handled via CSS properties.
|
|
22
|
+
* The map's `cooperativeGestures` option is temporarily disabled while the map
|
|
23
|
+
* is in fullscreen mode, and is restored when the map exist fullscreen mode.
|
|
24
|
+
*
|
|
25
|
+
* @group Markers and Controls
|
|
26
|
+
* @param options - the full screen control options
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* map.addControl(new FullscreenControl({container: document.querySelector('body')}));
|
|
31
|
+
* ```
|
|
32
|
+
* @see [View a fullscreen map](https://maplibre.org/maplibre-gl-js/docs/examples/fullscreen/)
|
|
33
|
+
*
|
|
34
|
+
* ## Events
|
|
35
|
+
*
|
|
36
|
+
* **Event** `fullscreenstart` of type {@link Event} will be fired when fullscreen mode has started.
|
|
37
|
+
*
|
|
38
|
+
* **Event** `fullscreenend` of type {@link Event} will be fired when fullscreen mode has ended.
|
|
39
|
+
*/
|
|
40
|
+
export class FullscreenControl extends Evented implements IControl {
|
|
41
|
+
_map: Map;
|
|
42
|
+
_controlContainer: HTMLElement;
|
|
43
|
+
_fullscreen: boolean;
|
|
44
|
+
_fullscreenchange: string;
|
|
45
|
+
_fullscreenButton: HTMLButtonElement;
|
|
46
|
+
_container: HTMLElement;
|
|
47
|
+
_prevCooperativeGesturesEnabled: boolean;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param options - the control's options
|
|
51
|
+
*/
|
|
52
|
+
constructor(options: FullscreenControlOptions = {}) {
|
|
53
|
+
super();
|
|
54
|
+
this._fullscreen = false;
|
|
55
|
+
|
|
56
|
+
if (options && options.container) {
|
|
57
|
+
if (options.container instanceof HTMLElement) {
|
|
58
|
+
this._container = options.container;
|
|
59
|
+
} else {
|
|
60
|
+
warnOnce('Full screen control \'container\' must be a DOM element.');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if ('onfullscreenchange' in document) {
|
|
65
|
+
this._fullscreenchange = 'fullscreenchange';
|
|
66
|
+
} else if ('onmozfullscreenchange' in document) {
|
|
67
|
+
this._fullscreenchange = 'mozfullscreenchange';
|
|
68
|
+
} else if ('onwebkitfullscreenchange' in document) {
|
|
69
|
+
this._fullscreenchange = 'webkitfullscreenchange';
|
|
70
|
+
} else if ('onmsfullscreenchange' in document) {
|
|
71
|
+
this._fullscreenchange = 'MSFullscreenChange';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** {@inheritDoc IControl.onAdd} */
|
|
76
|
+
onAdd(map: Map): HTMLElement {
|
|
77
|
+
this._map = map;
|
|
78
|
+
if (!this._container) this._container = this._map.getContainer();
|
|
79
|
+
this._controlContainer = DOM.create('div', 'maplibregl-ctrl maplibregl-ctrl-group');
|
|
80
|
+
this._setupUI();
|
|
81
|
+
return this._controlContainer;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** {@inheritDoc IControl.onRemove} */
|
|
85
|
+
onRemove() {
|
|
86
|
+
DOM.remove(this._controlContainer);
|
|
87
|
+
this._map = null;
|
|
88
|
+
window.document.removeEventListener(this._fullscreenchange, this._onFullscreenChange);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
_setupUI() {
|
|
92
|
+
const button = this._fullscreenButton = DOM.create('button', (('maplibregl-ctrl-fullscreen')), this._controlContainer);
|
|
93
|
+
DOM.create('span', 'maplibregl-ctrl-icon', button).setAttribute('aria-hidden', 'true');
|
|
94
|
+
button.type = 'button';
|
|
95
|
+
this._updateTitle();
|
|
96
|
+
this._fullscreenButton.addEventListener('click', this._onClickFullscreen);
|
|
97
|
+
window.document.addEventListener(this._fullscreenchange, this._onFullscreenChange);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
_updateTitle() {
|
|
101
|
+
const title = this._getTitle();
|
|
102
|
+
this._fullscreenButton.setAttribute('aria-label', title);
|
|
103
|
+
this._fullscreenButton.title = title;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
_getTitle() {
|
|
107
|
+
return this._map._getUIString(this._isFullscreen() ? 'FullscreenControl.Exit' : 'FullscreenControl.Enter');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
_isFullscreen() {
|
|
111
|
+
return this._fullscreen;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
_onFullscreenChange = () => {
|
|
115
|
+
let fullscreenElement =
|
|
116
|
+
window.document.fullscreenElement ||
|
|
117
|
+
(window.document as any).mozFullScreenElement ||
|
|
118
|
+
(window.document as any).webkitFullscreenElement ||
|
|
119
|
+
(window.document as any).msFullscreenElement;
|
|
120
|
+
|
|
121
|
+
while (fullscreenElement?.shadowRoot?.fullscreenElement) {
|
|
122
|
+
fullscreenElement = fullscreenElement.shadowRoot.fullscreenElement;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if ((fullscreenElement === this._container) !== this._fullscreen) {
|
|
126
|
+
this._handleFullscreenChange();
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
_handleFullscreenChange() {
|
|
131
|
+
this._fullscreen = !this._fullscreen;
|
|
132
|
+
this._fullscreenButton.classList.toggle('maplibregl-ctrl-shrink');
|
|
133
|
+
this._fullscreenButton.classList.toggle('maplibregl-ctrl-fullscreen');
|
|
134
|
+
this._updateTitle();
|
|
135
|
+
|
|
136
|
+
if (this._fullscreen) {
|
|
137
|
+
this.fire(new Event('fullscreenstart'));
|
|
138
|
+
this._prevCooperativeGesturesEnabled = this._map.cooperativeGestures.isEnabled();
|
|
139
|
+
this._map.cooperativeGestures.disable();
|
|
140
|
+
} else {
|
|
141
|
+
this.fire(new Event('fullscreenend'));
|
|
142
|
+
if (this._prevCooperativeGesturesEnabled) {
|
|
143
|
+
this._map.cooperativeGestures.enable();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
_onClickFullscreen = () => {
|
|
149
|
+
if (this._isFullscreen()) {
|
|
150
|
+
this._exitFullscreen();
|
|
151
|
+
} else {
|
|
152
|
+
this._requestFullscreen();
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
_exitFullscreen() {
|
|
157
|
+
if (window.document.exitFullscreen) {
|
|
158
|
+
(window.document as any).exitFullscreen();
|
|
159
|
+
} else if ((window.document as any).mozCancelFullScreen) {
|
|
160
|
+
(window.document as any).mozCancelFullScreen();
|
|
161
|
+
} else if ((window.document as any).msExitFullscreen) {
|
|
162
|
+
(window.document as any).msExitFullscreen();
|
|
163
|
+
} else if ((window.document as any).webkitCancelFullScreen) {
|
|
164
|
+
(window.document as any).webkitCancelFullScreen();
|
|
165
|
+
} else {
|
|
166
|
+
this._togglePseudoFullScreen();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
_requestFullscreen() {
|
|
171
|
+
if (this._container.requestFullscreen) {
|
|
172
|
+
this._container.requestFullscreen();
|
|
173
|
+
} else if ((this._container as any).mozRequestFullScreen) {
|
|
174
|
+
(this._container as any).mozRequestFullScreen();
|
|
175
|
+
} else if ((this._container as any).msRequestFullscreen) {
|
|
176
|
+
(this._container as any).msRequestFullscreen();
|
|
177
|
+
} else if ((this._container as any).webkitRequestFullscreen) {
|
|
178
|
+
(this._container as any).webkitRequestFullscreen();
|
|
179
|
+
} else {
|
|
180
|
+
this._togglePseudoFullScreen();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
_togglePseudoFullScreen() {
|
|
185
|
+
this._container.classList.toggle('maplibregl-pseudo-fullscreen');
|
|
186
|
+
this._handleFullscreenChange();
|
|
187
|
+
this._map.resize();
|
|
188
|
+
}
|
|
189
|
+
}
|