@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,619 @@
|
|
|
1
|
+
import geolocation from 'mock-geolocation';
|
|
2
|
+
import {LngLatBounds} from '../../geo/lng_lat_bounds';
|
|
3
|
+
import {createMap, beforeMapTest, sleep} from '../../util/test/util';
|
|
4
|
+
import {GeolocateControl} from './geolocate_control';
|
|
5
|
+
jest.mock('../../util/geolocation_support', () => (
|
|
6
|
+
{
|
|
7
|
+
checkGeolocationSupport: jest.fn()
|
|
8
|
+
}
|
|
9
|
+
));
|
|
10
|
+
import {checkGeolocationSupport} from '../../util/geolocation_support';
|
|
11
|
+
import type {LngLat} from '../../geo/lng_lat';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Convert the coordinates of a LngLat object to a fixed number of digits
|
|
15
|
+
* @param lngLat - the location
|
|
16
|
+
* @param digits - digits the number of digits to set
|
|
17
|
+
* @returns a string representation of the object with the required number of digits
|
|
18
|
+
*/
|
|
19
|
+
function lngLatAsFixed(lngLat: LngLat, digits: number): {lat: string; lng: string} {
|
|
20
|
+
return {
|
|
21
|
+
lng: lngLat.lng.toFixed(digits),
|
|
22
|
+
lat: lngLat.lat.toFixed(digits)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('GeolocateControl with no options', () => {
|
|
27
|
+
geolocation.use();
|
|
28
|
+
let map;
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
beforeMapTest();
|
|
32
|
+
map = createMap(undefined, undefined);
|
|
33
|
+
(checkGeolocationSupport as any as jest.SpyInstance).mockImplementationOnce(() => Promise.resolve(true));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
map.remove();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('is disabled when there is no support', async () => {
|
|
41
|
+
(checkGeolocationSupport as any as jest.SpyInstance).mockReset().mockImplementationOnce(() => Promise.resolve(false));
|
|
42
|
+
const geolocate = new GeolocateControl(undefined);
|
|
43
|
+
const spy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
44
|
+
map.addControl(geolocate);
|
|
45
|
+
await sleep(0);
|
|
46
|
+
expect(geolocate._geolocateButton.disabled).toBeTruthy();
|
|
47
|
+
spy.mockRestore();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('is enabled when there is support', async () => {
|
|
51
|
+
const geolocate = new GeolocateControl(undefined);
|
|
52
|
+
map.addControl(geolocate);
|
|
53
|
+
await sleep(0);
|
|
54
|
+
expect(geolocate._geolocateButton.disabled).toBeFalsy();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('has permissions', async () => {
|
|
58
|
+
|
|
59
|
+
(window.navigator as any).permissions = {
|
|
60
|
+
query: () => Promise.resolve({state: 'granted'})
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const geolocate = new GeolocateControl(undefined);
|
|
64
|
+
map.addControl(geolocate);
|
|
65
|
+
|
|
66
|
+
await sleep(0);
|
|
67
|
+
expect(geolocate._geolocateButton.disabled).toBeFalsy();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('error event', async () => {
|
|
71
|
+
const geolocate = new GeolocateControl(undefined);
|
|
72
|
+
map.addControl(geolocate);
|
|
73
|
+
await sleep(0);
|
|
74
|
+
const click = new window.Event('click');
|
|
75
|
+
const errorPromise = geolocate.once('error');
|
|
76
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
77
|
+
|
|
78
|
+
geolocation.sendError({code: 2, message: 'error message'});
|
|
79
|
+
const error = await errorPromise;
|
|
80
|
+
|
|
81
|
+
expect(error.code).toBe(2);
|
|
82
|
+
expect(error.message).toBe('error message');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('does not throw if removed quickly', () => {
|
|
86
|
+
(checkGeolocationSupport as any as jest.SpyInstance).mockReset()
|
|
87
|
+
.mockImplementationOnce(() => {
|
|
88
|
+
return sleep(10);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const geolocate = new GeolocateControl(undefined);
|
|
92
|
+
map.addControl(geolocate);
|
|
93
|
+
map.removeControl(geolocate);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('outofmaxbounds event in active lock state', async () => {
|
|
97
|
+
const geolocate = new GeolocateControl(undefined);
|
|
98
|
+
map.addControl(geolocate);
|
|
99
|
+
await sleep(0);
|
|
100
|
+
map.setMaxBounds([[0, 0], [10, 10]]);
|
|
101
|
+
geolocate._watchState = 'ACTIVE_LOCK';
|
|
102
|
+
|
|
103
|
+
const click = new window.Event('click');
|
|
104
|
+
|
|
105
|
+
const outofmaxboundsPromise = geolocate.once('outofmaxbounds');
|
|
106
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
107
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 3, timestamp: 4});
|
|
108
|
+
const position = await outofmaxboundsPromise;
|
|
109
|
+
|
|
110
|
+
expect(geolocate._watchState).toBe('ACTIVE_ERROR');
|
|
111
|
+
expect(position.coords.latitude).toBe(10);
|
|
112
|
+
expect(position.coords.longitude).toBe(20);
|
|
113
|
+
expect(position.coords.accuracy).toBe(3);
|
|
114
|
+
expect(position.timestamp).toBe(4);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('outofmaxbounds event in background state', async () => {
|
|
118
|
+
const geolocate = new GeolocateControl(undefined);
|
|
119
|
+
map.addControl(geolocate);
|
|
120
|
+
await sleep(0);
|
|
121
|
+
map.setMaxBounds([[0, 0], [10, 10]]);
|
|
122
|
+
geolocate._watchState = 'BACKGROUND';
|
|
123
|
+
|
|
124
|
+
const click = new window.Event('click');
|
|
125
|
+
|
|
126
|
+
const promise = geolocate.once('outofmaxbounds');
|
|
127
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
128
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 3, timestamp: 4});
|
|
129
|
+
const position = await promise;
|
|
130
|
+
expect(geolocate._watchState).toBe('BACKGROUND_ERROR');
|
|
131
|
+
expect(position.coords.latitude).toBe(10);
|
|
132
|
+
expect(position.coords.longitude).toBe(20);
|
|
133
|
+
expect(position.coords.accuracy).toBe(3);
|
|
134
|
+
expect(position.timestamp).toBe(4);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('geolocate event', async () => {
|
|
138
|
+
const geolocate = new GeolocateControl(undefined);
|
|
139
|
+
map.addControl(geolocate);
|
|
140
|
+
await sleep(0);
|
|
141
|
+
const click = new window.Event('click');
|
|
142
|
+
|
|
143
|
+
const promise = geolocate.once('geolocate');
|
|
144
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
145
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 30, timestamp: 40});
|
|
146
|
+
|
|
147
|
+
const position = await promise;
|
|
148
|
+
expect(position.coords.latitude).toBe(10);
|
|
149
|
+
expect(position.coords.longitude).toBe(20);
|
|
150
|
+
expect(position.coords.accuracy).toBe(30);
|
|
151
|
+
expect(position.timestamp).toBe(40);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('trigger', async () => {
|
|
155
|
+
const geolocate = new GeolocateControl(undefined);
|
|
156
|
+
map.addControl(geolocate);
|
|
157
|
+
await sleep(0);
|
|
158
|
+
expect(geolocate.trigger()).toBeTruthy();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('trigger and then error when tracking user location should get to active error state', async () => {
|
|
162
|
+
const geolocate = new GeolocateControl({trackUserLocation: true});
|
|
163
|
+
map.addControl(geolocate);
|
|
164
|
+
await sleep(0);
|
|
165
|
+
|
|
166
|
+
geolocate.trigger();
|
|
167
|
+
geolocation.sendError({code: 2, message: 'error message'});
|
|
168
|
+
expect(geolocate._watchState).toBe('ACTIVE_ERROR');
|
|
169
|
+
expect(geolocate._geolocateButton.classList.contains('maplibregl-ctrl-geolocate-active-error')).toBeTruthy();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('trigger before added to map', () => {
|
|
173
|
+
jest.spyOn(console, 'warn').mockImplementation(() => { });
|
|
174
|
+
|
|
175
|
+
const geolocate = new GeolocateControl(undefined);
|
|
176
|
+
|
|
177
|
+
expect(geolocate.trigger()).toBeFalsy();
|
|
178
|
+
expect(console.warn).toHaveBeenCalledWith('Geolocate control triggered before added to a map');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('geolocate fitBoundsOptions', async () => {
|
|
182
|
+
const geolocate = new GeolocateControl({
|
|
183
|
+
fitBoundsOptions: {
|
|
184
|
+
duration: 0,
|
|
185
|
+
maxZoom: 10
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
map.addControl(geolocate);
|
|
189
|
+
await sleep(0);
|
|
190
|
+
const click = new window.Event('click');
|
|
191
|
+
|
|
192
|
+
const moveEndPromise = map.once('moveend');
|
|
193
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
194
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 1});
|
|
195
|
+
await moveEndPromise;
|
|
196
|
+
expect(map.getZoom()).toBe(10);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('was removed before Geolocation support was checked', () => {
|
|
200
|
+
expect(() => {
|
|
201
|
+
const geolocate = new GeolocateControl(undefined);
|
|
202
|
+
map.addControl(geolocate);
|
|
203
|
+
geolocate.trigger();
|
|
204
|
+
map.removeControl(geolocate);
|
|
205
|
+
}).not.toThrow();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('non-zero bearing', async () => {
|
|
209
|
+
map.setBearing(45);
|
|
210
|
+
const geolocate = new GeolocateControl({
|
|
211
|
+
fitBoundsOptions: {
|
|
212
|
+
duration: 0,
|
|
213
|
+
maxZoom: 10
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
map.addControl(geolocate);
|
|
217
|
+
await sleep(0);
|
|
218
|
+
const click = new window.Event('click');
|
|
219
|
+
|
|
220
|
+
const moveEndPromise = map.once('moveend');
|
|
221
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
222
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 1});
|
|
223
|
+
await moveEndPromise;
|
|
224
|
+
expect(lngLatAsFixed(map.getCenter(), 4)).toEqual({lat: '10.0000', lng: '20.0000'});
|
|
225
|
+
expect(map.getBearing()).toBe(45);
|
|
226
|
+
expect(map.getZoom()).toBe(10);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('no watching map camera on geolocation', async () => {
|
|
230
|
+
const geolocate = new GeolocateControl({
|
|
231
|
+
fitBoundsOptions: {
|
|
232
|
+
maxZoom: 20,
|
|
233
|
+
duration: 0
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
map.addControl(geolocate);
|
|
237
|
+
await sleep(0);
|
|
238
|
+
const click = new window.Event('click');
|
|
239
|
+
|
|
240
|
+
const moveEndPromise = map.once('moveend');
|
|
241
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
242
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 1000});
|
|
243
|
+
await moveEndPromise;
|
|
244
|
+
const mapCenter = map.getCenter();
|
|
245
|
+
expect(lngLatAsFixed(mapCenter, 4)).toEqual({lat: '10.0000', lng: '20.0000'});
|
|
246
|
+
|
|
247
|
+
const mapBounds = map.getBounds();
|
|
248
|
+
|
|
249
|
+
// map bounds should contain or equal accuracy bounds, that is the ensure accuracy bounds doesn't fall outside the map bounds
|
|
250
|
+
const accuracyBounds = LngLatBounds.fromLngLat(mapCenter, 1000);
|
|
251
|
+
|
|
252
|
+
expect(accuracyBounds.getNorth().toFixed(4) <= mapBounds.getNorth().toFixed(4)).toBeTruthy();
|
|
253
|
+
expect(accuracyBounds.getSouth().toFixed(4) >= mapBounds.getSouth().toFixed(4)).toBeTruthy();
|
|
254
|
+
expect(accuracyBounds.getEast().toFixed(4) <= mapBounds.getEast().toFixed(4)).toBeTruthy();
|
|
255
|
+
expect(accuracyBounds.getWest().toFixed(4) >= mapBounds.getWest().toFixed(4)).toBeTruthy();
|
|
256
|
+
|
|
257
|
+
// map bounds should not be too much bigger on all edges of the accuracy bounds (this test will only work for an orthogonal bearing),
|
|
258
|
+
// ensures map bounds does not contain buffered accuracy bounds, as if it does there is too much gap around the accuracy bounds
|
|
259
|
+
const bufferedAccuracyBounds = LngLatBounds.fromLngLat(mapCenter, 1100);
|
|
260
|
+
|
|
261
|
+
expect(
|
|
262
|
+
(bufferedAccuracyBounds.getNorth().toFixed(4) < mapBounds.getNorth().toFixed(4)) &&
|
|
263
|
+
(bufferedAccuracyBounds.getSouth().toFixed(4) > mapBounds.getSouth().toFixed(4)) &&
|
|
264
|
+
(bufferedAccuracyBounds.getEast().toFixed(4) < mapBounds.getEast().toFixed(4)) &&
|
|
265
|
+
(bufferedAccuracyBounds.getWest().toFixed(4) > mapBounds.getWest().toFixed(4))
|
|
266
|
+
).toBeFalsy();
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test('watching map updates recenter on location with dot', async () => {
|
|
270
|
+
const geolocate = new GeolocateControl({
|
|
271
|
+
trackUserLocation: true,
|
|
272
|
+
showUserLocation: true,
|
|
273
|
+
fitBoundsOptions: {
|
|
274
|
+
duration: 0
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
map.addControl(geolocate);
|
|
278
|
+
await sleep(0);
|
|
279
|
+
const click = new window.Event('click');
|
|
280
|
+
|
|
281
|
+
const firstMoveEnd = map.once('moveend');
|
|
282
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
283
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 30});
|
|
284
|
+
|
|
285
|
+
await firstMoveEnd;
|
|
286
|
+
|
|
287
|
+
expect(lngLatAsFixed(map.getCenter(), 4)).toEqual({lat: '10.0000', lng: '20.0000'});
|
|
288
|
+
expect(geolocate._userLocationDotMarker._map).toBeTruthy();
|
|
289
|
+
expect(
|
|
290
|
+
geolocate._userLocationDotMarker._element.classList.contains('maplibregl-user-location-dot-stale')
|
|
291
|
+
).toBeFalsy();
|
|
292
|
+
const secontMoveEnd = map.once('moveend');
|
|
293
|
+
geolocation.change({latitude: 40, longitude: 50, accuracy: 60});
|
|
294
|
+
await secontMoveEnd;
|
|
295
|
+
expect(lngLatAsFixed(map.getCenter(), 4)).toEqual({lat: '40.0000', lng: '50.0000'});
|
|
296
|
+
const errorPromise = geolocate.once('error');
|
|
297
|
+
geolocation.changeError({code: 2, message: 'position unavailable'});
|
|
298
|
+
await errorPromise;
|
|
299
|
+
expect(geolocate._userLocationDotMarker._map).toBeTruthy();
|
|
300
|
+
expect(geolocate._userLocationDotMarker._element.classList.contains('maplibregl-user-location-dot-stale')).toBeTruthy();
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* @deprecated 'trackuserlocationend' event will not be thrown in this situation later,
|
|
305
|
+
* 'userlocationlostfocus event' test added instead.
|
|
306
|
+
*/
|
|
307
|
+
test('watching map background event', async () => {
|
|
308
|
+
const geolocate = new GeolocateControl({
|
|
309
|
+
trackUserLocation: true,
|
|
310
|
+
fitBoundsOptions: {
|
|
311
|
+
duration: 0
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
map.addControl(geolocate);
|
|
315
|
+
await sleep(0);
|
|
316
|
+
const click = new window.Event('click');
|
|
317
|
+
|
|
318
|
+
const moveEndPromise = map.once('moveend');
|
|
319
|
+
// click the button to activate it into the enabled watch state
|
|
320
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
321
|
+
// send through a location update which should reposition the map and trigger the 'moveend' event above
|
|
322
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 30});
|
|
323
|
+
await moveEndPromise;
|
|
324
|
+
const trackPromise = geolocate.once('trackuserlocationend');
|
|
325
|
+
// manually pan the map away from the geolocation position which should trigger the 'trackuserlocationend' event above
|
|
326
|
+
map.jumpTo({
|
|
327
|
+
center: [10, 5]
|
|
328
|
+
});
|
|
329
|
+
await trackPromise;
|
|
330
|
+
expect(map.getCenter()).toEqual({lng: 10, lat: 5});
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test('userlocationlostfocus event', async () => {
|
|
334
|
+
const geolocate = new GeolocateControl({
|
|
335
|
+
trackUserLocation: true,
|
|
336
|
+
fitBoundsOptions: {
|
|
337
|
+
duration: 0
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
map.addControl(geolocate);
|
|
341
|
+
await sleep(0);
|
|
342
|
+
const click = new window.Event('click');
|
|
343
|
+
|
|
344
|
+
const moveEndPromise = map.once('moveend');
|
|
345
|
+
// click the button to activate it into the enabled watch state
|
|
346
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
347
|
+
// send through a location update which should reposition the map and trigger the 'moveend' event above
|
|
348
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 30});
|
|
349
|
+
await moveEndPromise;
|
|
350
|
+
const trackPromise = geolocate.once('userlocationlostfocus');
|
|
351
|
+
// manually pan the map away from the geolocation position which should trigger the 'userlocationlostfocus' event above
|
|
352
|
+
map.jumpTo({
|
|
353
|
+
center: [10, 5]
|
|
354
|
+
});
|
|
355
|
+
await trackPromise;
|
|
356
|
+
expect(map.getCenter()).toEqual({lng: 10, lat: 5});
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
test('watching geolocate turns off', async () => {
|
|
360
|
+
const geolocate = new GeolocateControl({
|
|
361
|
+
trackUserLocation: true,
|
|
362
|
+
fitBoundsOptions: {
|
|
363
|
+
duration: 0
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
map.addControl(geolocate);
|
|
367
|
+
await sleep(0);
|
|
368
|
+
const click = new window.Event('click');
|
|
369
|
+
|
|
370
|
+
const moveEndPromise = map.once('moveend');
|
|
371
|
+
// click the button to activate it into the enabled watch state
|
|
372
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
373
|
+
// send through a location update which should reposition the map and trigger the 'moveend' event above
|
|
374
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 30});
|
|
375
|
+
await moveEndPromise;
|
|
376
|
+
const turnOffPromise = geolocate.once('trackuserlocationend');
|
|
377
|
+
// click the button to deactivate geolocate and trigger 'trackuserlocationend' event
|
|
378
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
379
|
+
await turnOffPromise;
|
|
380
|
+
expect(geolocate._watchState).toBe('OFF');
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
test('watching map background state', async () => {
|
|
384
|
+
const geolocate = new GeolocateControl({
|
|
385
|
+
trackUserLocation: true,
|
|
386
|
+
fitBoundsOptions: {
|
|
387
|
+
duration: 0
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
map.addControl(geolocate);
|
|
391
|
+
await sleep(0);
|
|
392
|
+
const click = new window.Event('click');
|
|
393
|
+
|
|
394
|
+
const moveEndPromise = map.once('moveend');
|
|
395
|
+
// click the button to activate it into the enabled watch state
|
|
396
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
397
|
+
// send through a location update which should reposition the map and trigger the 'moveend' event above
|
|
398
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 30});
|
|
399
|
+
await moveEndPromise;
|
|
400
|
+
const secondMoveEnd = map.once('moveend');
|
|
401
|
+
// manually pan the map away from the geolocation position which should trigger the 'moveend' event above
|
|
402
|
+
map.jumpTo({
|
|
403
|
+
center: [10, 5]
|
|
404
|
+
});
|
|
405
|
+
await secondMoveEnd;
|
|
406
|
+
const geolocatePromise = geolocate.once('geolocate');
|
|
407
|
+
// update the geolocation position, since we are in background state when 'geolocate' is triggered above, the camera shouldn't have changed
|
|
408
|
+
geolocation.change({latitude: 0, longitude: 0, accuracy: 10});
|
|
409
|
+
await geolocatePromise;
|
|
410
|
+
expect(map.getCenter()).toEqual({lng: 10, lat: 5});
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
test('trackuserlocationstart event', async () => {
|
|
414
|
+
const geolocate = new GeolocateControl({
|
|
415
|
+
trackUserLocation: true,
|
|
416
|
+
fitBoundsOptions: {
|
|
417
|
+
duration: 0
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
map.addControl(geolocate);
|
|
421
|
+
await sleep(0);
|
|
422
|
+
const click = new window.Event('click');
|
|
423
|
+
|
|
424
|
+
const promise = geolocate.once('trackuserlocationstart');
|
|
425
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
426
|
+
await promise;
|
|
427
|
+
expect(map.getCenter()).toEqual({lng: 0, lat: 0});
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
test('userlocationfocus event', async () => {
|
|
431
|
+
const geolocate = new GeolocateControl({
|
|
432
|
+
trackUserLocation: true,
|
|
433
|
+
fitBoundsOptions: {
|
|
434
|
+
duration: 0
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
map.addControl(geolocate);
|
|
438
|
+
await sleep(0);
|
|
439
|
+
const click = new window.Event('click');
|
|
440
|
+
|
|
441
|
+
const moveEndPromise = map.once('moveend');
|
|
442
|
+
// click the button to activate it into the enabled watch state
|
|
443
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
444
|
+
// send through a location update which should reposition the map and trigger the 'moveend' event above
|
|
445
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 30});
|
|
446
|
+
await moveEndPromise;
|
|
447
|
+
const trackPromise = geolocate.once('userlocationlostfocus');
|
|
448
|
+
// manually pan the map away from the geolocation position which should trigger the 'userlocationlostfocus' event above
|
|
449
|
+
map.jumpTo({
|
|
450
|
+
center: [10, 5]
|
|
451
|
+
});
|
|
452
|
+
await trackPromise;
|
|
453
|
+
const lockToDotPromise = geolocate.once('userlocationfocus');
|
|
454
|
+
// click the button to focus on user location and trigger 'userlocationfocus' event
|
|
455
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
456
|
+
await lockToDotPromise;
|
|
457
|
+
expect(geolocate._watchState).toBe('ACTIVE_LOCK');
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
test('does not switch to BACKGROUND and stays in ACTIVE_LOCK state on window resize', async () => {
|
|
461
|
+
const geolocate = new GeolocateControl({
|
|
462
|
+
trackUserLocation: true,
|
|
463
|
+
});
|
|
464
|
+
map.addControl(geolocate);
|
|
465
|
+
await sleep(0);
|
|
466
|
+
const click = new window.Event('click');
|
|
467
|
+
|
|
468
|
+
const geolocatePromise = geolocate.once('geolocate');
|
|
469
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
470
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 30, timestamp: 40});
|
|
471
|
+
await geolocatePromise;
|
|
472
|
+
expect(geolocate._watchState).toBe('ACTIVE_LOCK');
|
|
473
|
+
window.dispatchEvent(new window.Event('resize'));
|
|
474
|
+
expect(geolocate._watchState).toBe('ACTIVE_LOCK');
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
test('switches to BACKGROUND state on map manipulation', async () => {
|
|
478
|
+
const geolocate = new GeolocateControl({
|
|
479
|
+
trackUserLocation: true,
|
|
480
|
+
});
|
|
481
|
+
map.addControl(geolocate);
|
|
482
|
+
await sleep(0);
|
|
483
|
+
const click = new window.Event('click');
|
|
484
|
+
|
|
485
|
+
const geolocatePromise = geolocate.once('geolocate');
|
|
486
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
487
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 30, timestamp: 40});
|
|
488
|
+
await geolocatePromise;
|
|
489
|
+
expect(geolocate._watchState).toBe('ACTIVE_LOCK');
|
|
490
|
+
map.jumpTo({
|
|
491
|
+
center: [0, 0]
|
|
492
|
+
});
|
|
493
|
+
expect(geolocate._watchState).toBe('BACKGROUND');
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
test('accuracy circle not shown if showAccuracyCircle = false', async () => {
|
|
497
|
+
const geolocate = new GeolocateControl({
|
|
498
|
+
trackUserLocation: true,
|
|
499
|
+
showUserLocation: true,
|
|
500
|
+
showAccuracyCircle: false,
|
|
501
|
+
});
|
|
502
|
+
map.addControl(geolocate);
|
|
503
|
+
await sleep(0);
|
|
504
|
+
const click = new window.Event('click');
|
|
505
|
+
|
|
506
|
+
const geolocatePromise = geolocate.once('geolocate');
|
|
507
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
508
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 700});
|
|
509
|
+
await geolocatePromise;
|
|
510
|
+
map.jumpTo({
|
|
511
|
+
center: [10, 20]
|
|
512
|
+
});
|
|
513
|
+
const zoomendPromise = map.once('zoomend');
|
|
514
|
+
map.zoomTo(10, {duration: 0});
|
|
515
|
+
await zoomendPromise;
|
|
516
|
+
expect(!geolocate._circleElement.style.width).toBeTruthy();
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
test('accuracy circle radius matches reported accuracy', async () => {
|
|
520
|
+
const geolocate = new GeolocateControl({
|
|
521
|
+
trackUserLocation: true,
|
|
522
|
+
showUserLocation: true,
|
|
523
|
+
});
|
|
524
|
+
map.addControl(geolocate);
|
|
525
|
+
await sleep(0);
|
|
526
|
+
const click = new window.Event('click');
|
|
527
|
+
|
|
528
|
+
const geolocatePromise = geolocate.once('geolocate');
|
|
529
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
530
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 700});
|
|
531
|
+
await geolocatePromise;
|
|
532
|
+
expect(geolocate._accuracyCircleMarker._map).toBeTruthy();
|
|
533
|
+
expect(geolocate._accuracy).toBe(700);
|
|
534
|
+
map.jumpTo({
|
|
535
|
+
center: [10, 20]
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
// test with bugger radius
|
|
539
|
+
let zoomendPromise = map.once('zoomend');
|
|
540
|
+
map.zoomTo(12, {duration: 0});
|
|
541
|
+
await zoomendPromise;
|
|
542
|
+
expect(geolocate._circleElement.style.width).toBe('79px');
|
|
543
|
+
zoomendPromise = map.once('zoomend');
|
|
544
|
+
map.zoomTo(10, {duration: 0});
|
|
545
|
+
await zoomendPromise;
|
|
546
|
+
expect(geolocate._circleElement.style.width).toBe('20px');
|
|
547
|
+
zoomendPromise = map.once('zoomend');
|
|
548
|
+
|
|
549
|
+
// test with smaller radius
|
|
550
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 20});
|
|
551
|
+
map.zoomTo(20, {duration: 0});
|
|
552
|
+
await zoomendPromise;
|
|
553
|
+
expect(geolocate._circleElement.style.width).toBe('19982px');
|
|
554
|
+
zoomendPromise = map.once('zoomend');
|
|
555
|
+
map.zoomTo(18, {duration: 0});
|
|
556
|
+
await zoomendPromise;
|
|
557
|
+
expect(geolocate._circleElement.style.width).toBe('4996px');
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
test('shown even if trackUserLocation = false', async () => {
|
|
561
|
+
const geolocate = new GeolocateControl({
|
|
562
|
+
trackUserLocation: false,
|
|
563
|
+
showUserLocation: true,
|
|
564
|
+
showAccuracyCircle: true,
|
|
565
|
+
});
|
|
566
|
+
map.addControl(geolocate);
|
|
567
|
+
await sleep(0);
|
|
568
|
+
const click = new window.Event('click');
|
|
569
|
+
|
|
570
|
+
const geolocatePromise = geolocate.once('geolocate');
|
|
571
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
572
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 700});
|
|
573
|
+
await geolocatePromise;
|
|
574
|
+
map.jumpTo({
|
|
575
|
+
center: [10, 20]
|
|
576
|
+
});
|
|
577
|
+
const zoomendPromise = map.once('zoomend');
|
|
578
|
+
map.zoomTo(10, {duration: 0});
|
|
579
|
+
await zoomendPromise;
|
|
580
|
+
expect(geolocate._circleElement.style.width).toBeTruthy();
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
test('shown even if trackUserLocation = false', async () => {
|
|
584
|
+
const geolocate = new GeolocateControl({
|
|
585
|
+
trackUserLocation: false,
|
|
586
|
+
showUserLocation: true,
|
|
587
|
+
showAccuracyCircle: true,
|
|
588
|
+
});
|
|
589
|
+
map.addControl(geolocate);
|
|
590
|
+
await sleep(0);
|
|
591
|
+
const click = new window.Event('click');
|
|
592
|
+
|
|
593
|
+
const geolocatePromise = geolocate.once('geolocate');
|
|
594
|
+
geolocate._geolocateButton.dispatchEvent(click);
|
|
595
|
+
geolocation.send({latitude: 10, longitude: 20, accuracy: 700});
|
|
596
|
+
await geolocatePromise;
|
|
597
|
+
map.jumpTo({
|
|
598
|
+
center: [10, 20]
|
|
599
|
+
});
|
|
600
|
+
const zoomendPromise = map.once('zoomend');
|
|
601
|
+
map.zoomTo(10, {duration: 0});
|
|
602
|
+
await zoomendPromise;
|
|
603
|
+
expect(geolocate._circleElement.style.width).toBeTruthy();
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
test('Geolocate control should appear only once', async () => {
|
|
607
|
+
const geolocateControl = new GeolocateControl({});
|
|
608
|
+
|
|
609
|
+
map.addControl(geolocateControl);
|
|
610
|
+
// adding and removing to verify there is no race condition, and it is just added once
|
|
611
|
+
map.removeControl(geolocateControl);
|
|
612
|
+
map.addControl(geolocateControl);
|
|
613
|
+
|
|
614
|
+
await map.once('idle');
|
|
615
|
+
|
|
616
|
+
const geolocateUIelem = await geolocateControl._container.getElementsByClassName('maplibregl-ctrl-geolocate');
|
|
617
|
+
expect(geolocateUIelem).toHaveLength(1);
|
|
618
|
+
});
|
|
619
|
+
});
|