@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
package/src/ui/popup.ts
ADDED
|
@@ -0,0 +1,717 @@
|
|
|
1
|
+
import {extend} from '../util/util';
|
|
2
|
+
import {Event, Evented} from '../util/evented';
|
|
3
|
+
import {MapMouseEvent} from '../ui/events';
|
|
4
|
+
import {DOM} from '../util/dom';
|
|
5
|
+
import {LngLat} from '../geo/lng_lat';
|
|
6
|
+
import Point from '@mapbox/point-geometry';
|
|
7
|
+
import {smartWrap} from '../util/smart_wrap';
|
|
8
|
+
import {anchorTranslate, applyAnchorClass} from './anchor';
|
|
9
|
+
|
|
10
|
+
import type {PositionAnchor} from './anchor';
|
|
11
|
+
import type {Map} from './map';
|
|
12
|
+
import type {LngLatLike} from '../geo/lng_lat';
|
|
13
|
+
import type {PointLike} from './camera';
|
|
14
|
+
|
|
15
|
+
const defaultOptions = {
|
|
16
|
+
closeButton: true,
|
|
17
|
+
closeOnClick: true,
|
|
18
|
+
focusAfterOpen: true,
|
|
19
|
+
className: '',
|
|
20
|
+
maxWidth: '240px',
|
|
21
|
+
subpixelPositioning: false
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A pixel offset specified as:
|
|
26
|
+
*
|
|
27
|
+
* - a single number specifying a distance from the location
|
|
28
|
+
* - a {@link PointLike} specifying a constant offset
|
|
29
|
+
* - an object of {@link Point}s specifying an offset for each anchor position
|
|
30
|
+
*
|
|
31
|
+
* Negative offsets indicate left and up.
|
|
32
|
+
*/
|
|
33
|
+
export type Offset = number | PointLike | {
|
|
34
|
+
[_ in PositionAnchor]: PointLike;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The {@link Popup} options object
|
|
39
|
+
*/
|
|
40
|
+
export type PopupOptions = {
|
|
41
|
+
/**
|
|
42
|
+
* If `true`, a close button will appear in the top right corner of the popup.
|
|
43
|
+
* @defaultValue true
|
|
44
|
+
*/
|
|
45
|
+
closeButton?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* If `true`, the popup will closed when the map is clicked.
|
|
48
|
+
* @defaultValue true
|
|
49
|
+
*/
|
|
50
|
+
closeOnClick?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* If `true`, the popup will closed when the map moves.
|
|
53
|
+
* @defaultValue false
|
|
54
|
+
*/
|
|
55
|
+
closeOnMove?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* If `true`, the popup will try to focus the first focusable element inside the popup.
|
|
58
|
+
* @defaultValue true
|
|
59
|
+
*/
|
|
60
|
+
focusAfterOpen?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* A string indicating the part of the Popup that should
|
|
63
|
+
* be positioned closest to the coordinate set via {@link Popup#setLngLat}.
|
|
64
|
+
* Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`,
|
|
65
|
+
* `'top-right'`, `'bottom-left'`, and `'bottom-right'`. If unset the anchor will be
|
|
66
|
+
* dynamically set to ensure the popup falls within the map container with a preference
|
|
67
|
+
* for `'bottom'`.
|
|
68
|
+
*/
|
|
69
|
+
anchor?: PositionAnchor;
|
|
70
|
+
/**
|
|
71
|
+
* A pixel offset applied to the popup's location
|
|
72
|
+
*/
|
|
73
|
+
offset?: Offset;
|
|
74
|
+
/**
|
|
75
|
+
* Space-separated CSS class names to add to popup container
|
|
76
|
+
*/
|
|
77
|
+
className?: string;
|
|
78
|
+
/**
|
|
79
|
+
* A string that sets the CSS property of the popup's maximum width, eg `'300px'`.
|
|
80
|
+
* To ensure the popup resizes to fit its content, set this property to `'none'`.
|
|
81
|
+
* Available values can be found here: https://developer.mozilla.org/en-US/docs/Web/CSS/max-width
|
|
82
|
+
* @defaultValue '240px'
|
|
83
|
+
*/
|
|
84
|
+
maxWidth?: string;
|
|
85
|
+
/**
|
|
86
|
+
* If `true`, rounding is disabled for placement of the popup, allowing for
|
|
87
|
+
* subpixel positioning and smoother movement when the popup is translated.
|
|
88
|
+
* @defaultValue false
|
|
89
|
+
*/
|
|
90
|
+
subpixelPositioning?: boolean;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const focusQuerySelector = [
|
|
94
|
+
'a[href]',
|
|
95
|
+
'[tabindex]:not([tabindex=\'-1\'])',
|
|
96
|
+
'[contenteditable]:not([contenteditable=\'false\'])',
|
|
97
|
+
'button:not([disabled])',
|
|
98
|
+
'input:not([disabled])',
|
|
99
|
+
'select:not([disabled])',
|
|
100
|
+
'textarea:not([disabled])',
|
|
101
|
+
].join(', ');
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A popup component.
|
|
105
|
+
*
|
|
106
|
+
* @group Markers and Controls
|
|
107
|
+
*
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* Create a popup
|
|
111
|
+
* ```ts
|
|
112
|
+
* let popup = new Popup();
|
|
113
|
+
* // Set an event listener that will fire
|
|
114
|
+
* // any time the popup is opened
|
|
115
|
+
* popup.on('open', () => {
|
|
116
|
+
* console.log('popup was opened');
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* Create a popup
|
|
122
|
+
* ```ts
|
|
123
|
+
* let popup = new Popup();
|
|
124
|
+
* // Set an event listener that will fire
|
|
125
|
+
* // any time the popup is closed
|
|
126
|
+
* popup.on('close', () => {
|
|
127
|
+
* console.log('popup was closed');
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* let markerHeight = 50, markerRadius = 10, linearOffset = 25;
|
|
134
|
+
* let popupOffsets = {
|
|
135
|
+
* 'top': [0, 0],
|
|
136
|
+
* 'top-left': [0,0],
|
|
137
|
+
* 'top-right': [0,0],
|
|
138
|
+
* 'bottom': [0, -markerHeight],
|
|
139
|
+
* 'bottom-left': [linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
|
|
140
|
+
* 'bottom-right': [-linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
|
|
141
|
+
* 'left': [markerRadius, (markerHeight - markerRadius) * -1],
|
|
142
|
+
* 'right': [-markerRadius, (markerHeight - markerRadius) * -1]
|
|
143
|
+
* };
|
|
144
|
+
* let popup = new Popup({offset: popupOffsets, className: 'my-class'})
|
|
145
|
+
* .setLngLat(e.lngLat)
|
|
146
|
+
* .setHTML("<h1>Hello World!</h1>")
|
|
147
|
+
* .setMaxWidth("300px")
|
|
148
|
+
* .addTo(map);
|
|
149
|
+
* ```
|
|
150
|
+
* @see [Display a popup](https://maplibre.org/maplibre-gl-js/docs/examples/popup/)
|
|
151
|
+
* @see [Display a popup on hover](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-hover/)
|
|
152
|
+
* @see [Display a popup on click](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-click/)
|
|
153
|
+
* @see [Attach a popup to a marker instance](https://maplibre.org/maplibre-gl-js/docs/examples/set-popup/)
|
|
154
|
+
*
|
|
155
|
+
* ## Events
|
|
156
|
+
*
|
|
157
|
+
* **Event** `open` of type {@link Event} will be fired when the popup is opened manually or programmatically.
|
|
158
|
+
*
|
|
159
|
+
* **Event** `close` of type {@link Event} will be fired when the popup is closed manually or programmatically.
|
|
160
|
+
*/
|
|
161
|
+
export class Popup extends Evented {
|
|
162
|
+
_map: Map;
|
|
163
|
+
options: PopupOptions;
|
|
164
|
+
_content: HTMLElement;
|
|
165
|
+
_container: HTMLElement;
|
|
166
|
+
_closeButton: HTMLButtonElement;
|
|
167
|
+
_tip: HTMLElement;
|
|
168
|
+
_lngLat: LngLat;
|
|
169
|
+
_trackPointer: boolean;
|
|
170
|
+
_pos: Point;
|
|
171
|
+
_flatPos: Point;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @param options - the options
|
|
175
|
+
*/
|
|
176
|
+
constructor(options?: PopupOptions) {
|
|
177
|
+
super();
|
|
178
|
+
this.options = extend(Object.create(defaultOptions), options);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Adds the popup to a map.
|
|
183
|
+
*
|
|
184
|
+
* @param map - The MapLibre GL JS map to add the popup to.
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* new Popup()
|
|
188
|
+
* .setLngLat([0, 0])
|
|
189
|
+
* .setHTML("<h1>Null Island</h1>")
|
|
190
|
+
* .addTo(map);
|
|
191
|
+
* ```
|
|
192
|
+
* @see [Display a popup](https://maplibre.org/maplibre-gl-js/docs/examples/popup/)
|
|
193
|
+
* @see [Display a popup on hover](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-hover/)
|
|
194
|
+
* @see [Display a popup on click](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-click/)
|
|
195
|
+
* @see [Show polygon information on click](https://maplibre.org/maplibre-gl-js/docs/examples/polygon-popup-on-click/)
|
|
196
|
+
*/
|
|
197
|
+
addTo(map: Map): this {
|
|
198
|
+
if (this._map) this.remove();
|
|
199
|
+
|
|
200
|
+
this._map = map;
|
|
201
|
+
if (this.options.closeOnClick) {
|
|
202
|
+
this._map.on('click', this._onClose);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (this.options.closeOnMove) {
|
|
206
|
+
this._map.on('move', this._onClose);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
this._map.on('remove', this.remove);
|
|
210
|
+
this._update();
|
|
211
|
+
this._focusFirstElement();
|
|
212
|
+
|
|
213
|
+
if (this._trackPointer) {
|
|
214
|
+
this._map.on('mousemove', this._onMouseMove);
|
|
215
|
+
this._map.on('mouseup', this._onMouseUp);
|
|
216
|
+
if (this._container) {
|
|
217
|
+
this._container.classList.add('maplibregl-popup-track-pointer');
|
|
218
|
+
}
|
|
219
|
+
this._map._canvasContainer.classList.add('maplibregl-track-pointer');
|
|
220
|
+
} else {
|
|
221
|
+
this._map.on('move', this._update);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
this.fire(new Event('open'));
|
|
225
|
+
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @returns `true` if the popup is open, `false` if it is closed.
|
|
231
|
+
*/
|
|
232
|
+
isOpen() {
|
|
233
|
+
return !!this._map;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Removes the popup from the map it has been added to.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```ts
|
|
241
|
+
* let popup = new Popup().addTo(map);
|
|
242
|
+
* popup.remove();
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
remove = (): this => {
|
|
246
|
+
if (this._content) {
|
|
247
|
+
DOM.remove(this._content);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (this._container) {
|
|
251
|
+
DOM.remove(this._container);
|
|
252
|
+
delete this._container;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (this._map) {
|
|
256
|
+
this._map.off('move', this._update);
|
|
257
|
+
this._map.off('move', this._onClose);
|
|
258
|
+
this._map.off('click', this._onClose);
|
|
259
|
+
this._map.off('remove', this.remove);
|
|
260
|
+
this._map.off('mousemove', this._onMouseMove);
|
|
261
|
+
this._map.off('mouseup', this._onMouseUp);
|
|
262
|
+
this._map.off('drag', this._onDrag);
|
|
263
|
+
this._map._canvasContainer.classList.remove('maplibregl-track-pointer');
|
|
264
|
+
delete this._map;
|
|
265
|
+
this.fire(new Event('close'));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return this;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Returns the geographical location of the popup's anchor.
|
|
273
|
+
*
|
|
274
|
+
* The longitude of the result may differ by a multiple of 360 degrees from the longitude previously
|
|
275
|
+
* set by `setLngLat` because `Popup` wraps the anchor longitude across copies of the world to keep
|
|
276
|
+
* the popup on screen.
|
|
277
|
+
*
|
|
278
|
+
* @returns The geographical location of the popup's anchor.
|
|
279
|
+
*/
|
|
280
|
+
getLngLat(): LngLat {
|
|
281
|
+
return this._lngLat;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Sets the geographical location of the popup's anchor, and moves the popup to it. Replaces trackPointer() behavior.
|
|
286
|
+
*
|
|
287
|
+
* @param lnglat - The geographical location to set as the popup's anchor.
|
|
288
|
+
*/
|
|
289
|
+
setLngLat(lnglat: LngLatLike): this {
|
|
290
|
+
this._lngLat = LngLat.convert(lnglat);
|
|
291
|
+
this._pos = null;
|
|
292
|
+
this._flatPos = null;
|
|
293
|
+
|
|
294
|
+
this._trackPointer = false;
|
|
295
|
+
|
|
296
|
+
this._update();
|
|
297
|
+
|
|
298
|
+
if (this._map) {
|
|
299
|
+
this._map.on('move', this._update);
|
|
300
|
+
this._map.off('mousemove', this._onMouseMove);
|
|
301
|
+
if (this._container) {
|
|
302
|
+
this._container.classList.remove('maplibregl-popup-track-pointer');
|
|
303
|
+
}
|
|
304
|
+
this._map._canvasContainer.classList.remove('maplibregl-track-pointer');
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return this;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Tracks the popup anchor to the cursor position on screens with a pointer device (it will be hidden on touchscreens). Replaces the `setLngLat` behavior.
|
|
312
|
+
* For most use cases, set `closeOnClick` and `closeButton` to `false`.
|
|
313
|
+
* @example
|
|
314
|
+
* ```ts
|
|
315
|
+
* let popup = new Popup({ closeOnClick: false, closeButton: false })
|
|
316
|
+
* .setHTML("<h1>Hello World!</h1>")
|
|
317
|
+
* .trackPointer()
|
|
318
|
+
* .addTo(map);
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
trackPointer(): this {
|
|
322
|
+
this._trackPointer = true;
|
|
323
|
+
this._pos = null;
|
|
324
|
+
this._flatPos = null;
|
|
325
|
+
this._update();
|
|
326
|
+
if (this._map) {
|
|
327
|
+
this._map.off('move', this._update);
|
|
328
|
+
this._map.on('mousemove', this._onMouseMove);
|
|
329
|
+
this._map.on('drag', this._onDrag);
|
|
330
|
+
if (this._container) {
|
|
331
|
+
this._container.classList.add('maplibregl-popup-track-pointer');
|
|
332
|
+
}
|
|
333
|
+
this._map._canvasContainer.classList.add('maplibregl-track-pointer');
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
return this;
|
|
337
|
+
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Returns the `Popup`'s HTML element.
|
|
342
|
+
* @example
|
|
343
|
+
* Change the `Popup` element's font size
|
|
344
|
+
* ```ts
|
|
345
|
+
* let popup = new Popup()
|
|
346
|
+
* .setLngLat([-96, 37.8])
|
|
347
|
+
* .setHTML("<p>Hello World!</p>")
|
|
348
|
+
* .addTo(map);
|
|
349
|
+
* let popupElem = popup.getElement();
|
|
350
|
+
* popupElem.style.fontSize = "25px";
|
|
351
|
+
* ```
|
|
352
|
+
* @returns element
|
|
353
|
+
*/
|
|
354
|
+
getElement(): HTMLElement {
|
|
355
|
+
return this._container;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Sets the popup's content to a string of text.
|
|
360
|
+
*
|
|
361
|
+
* This function creates a [Text](https://developer.mozilla.org/en-US/docs/Web/API/Text) node in the DOM,
|
|
362
|
+
* so it cannot insert raw HTML. Use this method for security against XSS
|
|
363
|
+
* if the popup content is user-provided.
|
|
364
|
+
*
|
|
365
|
+
* @param text - Textual content for the popup.
|
|
366
|
+
* @example
|
|
367
|
+
* ```ts
|
|
368
|
+
* let popup = new Popup()
|
|
369
|
+
* .setLngLat(e.lngLat)
|
|
370
|
+
* .setText('Hello, world!')
|
|
371
|
+
* .addTo(map);
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
setText(text: string): this {
|
|
375
|
+
return this.setDOMContent(document.createTextNode(text));
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Sets the popup's content to the HTML provided as a string.
|
|
380
|
+
*
|
|
381
|
+
* This method does not perform HTML filtering or sanitization, and must be
|
|
382
|
+
* used only with trusted content. Consider {@link Popup#setText} if
|
|
383
|
+
* the content is an untrusted text string.
|
|
384
|
+
*
|
|
385
|
+
* @param html - A string representing HTML content for the popup.
|
|
386
|
+
* @example
|
|
387
|
+
* ```ts
|
|
388
|
+
* let popup = new Popup()
|
|
389
|
+
* .setLngLat(e.lngLat)
|
|
390
|
+
* .setHTML("<h1>Hello World!</h1>")
|
|
391
|
+
* .addTo(map);
|
|
392
|
+
* ```
|
|
393
|
+
* @see [Display a popup](https://maplibre.org/maplibre-gl-js/docs/examples/popup/)
|
|
394
|
+
* @see [Display a popup on hover](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-hover/)
|
|
395
|
+
* @see [Display a popup on click](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-click/)
|
|
396
|
+
* @see [Attach a popup to a marker instance](https://maplibre.org/maplibre-gl-js/docs/examples/set-popup/)
|
|
397
|
+
*/
|
|
398
|
+
setHTML(html: string): this {
|
|
399
|
+
const frag = document.createDocumentFragment();
|
|
400
|
+
const temp = document.createElement('body');
|
|
401
|
+
let child;
|
|
402
|
+
temp.innerHTML = html;
|
|
403
|
+
while (true) {
|
|
404
|
+
child = temp.firstChild;
|
|
405
|
+
if (!child) break;
|
|
406
|
+
frag.appendChild(child);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return this.setDOMContent(frag);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Returns the popup's maximum width.
|
|
414
|
+
*
|
|
415
|
+
* @returns The maximum width of the popup.
|
|
416
|
+
*/
|
|
417
|
+
getMaxWidth(): string {
|
|
418
|
+
return this._container?.style.maxWidth;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Sets the popup's maximum width. This is setting the CSS property `max-width`.
|
|
423
|
+
* Available values can be found here: https://developer.mozilla.org/en-US/docs/Web/CSS/max-width
|
|
424
|
+
*
|
|
425
|
+
* @param maxWidth - A string representing the value for the maximum width.
|
|
426
|
+
*/
|
|
427
|
+
setMaxWidth(maxWidth: string): this {
|
|
428
|
+
this.options.maxWidth = maxWidth;
|
|
429
|
+
this._update();
|
|
430
|
+
return this;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Sets the popup's content to the element provided as a DOM node.
|
|
435
|
+
*
|
|
436
|
+
* @param htmlNode - A DOM node to be used as content for the popup.
|
|
437
|
+
* @example
|
|
438
|
+
* Create an element with the popup content
|
|
439
|
+
* ```ts
|
|
440
|
+
* let div = document.createElement('div');
|
|
441
|
+
* div.innerHTML = 'Hello, world!';
|
|
442
|
+
* let popup = new Popup()
|
|
443
|
+
* .setLngLat(e.lngLat)
|
|
444
|
+
* .setDOMContent(div)
|
|
445
|
+
* .addTo(map);
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
setDOMContent(htmlNode: Node): this {
|
|
449
|
+
if (this._content) {
|
|
450
|
+
// Clear out children first.
|
|
451
|
+
while (this._content.hasChildNodes()) {
|
|
452
|
+
if (this._content.firstChild) {
|
|
453
|
+
this._content.removeChild(this._content.firstChild);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
} else {
|
|
457
|
+
this._content = DOM.create('div', 'maplibregl-popup-content', this._container);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// The close button should be the last tabbable element inside the popup for a good keyboard UX.
|
|
461
|
+
this._content.appendChild(htmlNode);
|
|
462
|
+
this._createCloseButton();
|
|
463
|
+
this._update();
|
|
464
|
+
this._focusFirstElement();
|
|
465
|
+
return this;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Adds a CSS class to the popup container element.
|
|
470
|
+
*
|
|
471
|
+
* @param className - Non-empty string with CSS class name to add to popup container
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```ts
|
|
475
|
+
* let popup = new Popup()
|
|
476
|
+
* popup.addClassName('some-class')
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
addClassName(className: string) {
|
|
480
|
+
if (this._container) {
|
|
481
|
+
this._container.classList.add(className);
|
|
482
|
+
}
|
|
483
|
+
return this;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Removes a CSS class from the popup container element.
|
|
488
|
+
*
|
|
489
|
+
* @param className - Non-empty string with CSS class name to remove from popup container
|
|
490
|
+
*
|
|
491
|
+
* @example
|
|
492
|
+
* ```ts
|
|
493
|
+
* let popup = new Popup()
|
|
494
|
+
* popup.removeClassName('some-class')
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
removeClassName(className: string) {
|
|
498
|
+
if (this._container) {
|
|
499
|
+
this._container.classList.remove(className);
|
|
500
|
+
}
|
|
501
|
+
return this;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Sets the popup's offset.
|
|
506
|
+
*
|
|
507
|
+
* @param offset - Sets the popup's offset.
|
|
508
|
+
*/
|
|
509
|
+
setOffset (offset?: Offset): this {
|
|
510
|
+
this.options.offset = offset;
|
|
511
|
+
this._update();
|
|
512
|
+
return this;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Add or remove the given CSS class on the popup container, depending on whether the container currently has that class.
|
|
517
|
+
*
|
|
518
|
+
* @param className - Non-empty string with CSS class name to add/remove
|
|
519
|
+
*
|
|
520
|
+
* @returns if the class was removed return false, if class was added, then return true, undefined if there is no container
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```ts
|
|
524
|
+
* let popup = new Popup()
|
|
525
|
+
* popup.toggleClassName('toggleClass')
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
toggleClassName(className: string): boolean | undefined {
|
|
529
|
+
if (this._container) {
|
|
530
|
+
return this._container.classList.toggle(className);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Set the option to allow subpixel positioning of the popup by passing a boolean
|
|
536
|
+
*
|
|
537
|
+
* @param value - When boolean is true, subpixel positioning is enabled for the popup.
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```ts
|
|
541
|
+
* let popup = new Popup()
|
|
542
|
+
* popup.setSubpixelPositioning(true);
|
|
543
|
+
* ```
|
|
544
|
+
*/
|
|
545
|
+
setSubpixelPositioning(value: boolean) {
|
|
546
|
+
this.options.subpixelPositioning = value;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
_createCloseButton() {
|
|
550
|
+
if (this.options.closeButton) {
|
|
551
|
+
this._closeButton = DOM.create('button', 'maplibregl-popup-close-button', this._content);
|
|
552
|
+
this._closeButton.type = 'button';
|
|
553
|
+
this._closeButton.innerHTML = '×';
|
|
554
|
+
this._closeButton.addEventListener('click', this._onClose);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
_onMouseUp = (event: MapMouseEvent) => {
|
|
559
|
+
this._update(event.point);
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
_onMouseMove = (event: MapMouseEvent) => {
|
|
563
|
+
this._update(event.point);
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
_onDrag = (event: MapMouseEvent) => {
|
|
567
|
+
this._update(event.point);
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
_update = (cursor?: Point) => {
|
|
571
|
+
const hasPosition = this._lngLat || this._trackPointer;
|
|
572
|
+
|
|
573
|
+
if (!this._map || !hasPosition || !this._content) { return; }
|
|
574
|
+
|
|
575
|
+
if (!this._container) {
|
|
576
|
+
this._container = DOM.create('div', 'maplibregl-popup', this._map.getContainer());
|
|
577
|
+
// Same fix as Marker: positioned via a raw pixel translate() in
|
|
578
|
+
// _update() below, which assumes LTR. Pin direction so an RTL
|
|
579
|
+
// page doesn't mirror the popup's placement. — Scoova fix,
|
|
580
|
+
// upstream MapLibre GL JS v4.7.1 base.
|
|
581
|
+
this._container.style.direction = 'ltr';
|
|
582
|
+
this._tip = DOM.create('div', 'maplibregl-popup-tip', this._container);
|
|
583
|
+
this._container.appendChild(this._content);
|
|
584
|
+
if (this.options.className) {
|
|
585
|
+
for (const name of this.options.className.split(' ')) {
|
|
586
|
+
this._container.classList.add(name);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
if (this._closeButton) {
|
|
591
|
+
this._closeButton.setAttribute('aria-label', this._map._getUIString('Popup.Close'));
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if (this._trackPointer) {
|
|
595
|
+
this._container.classList.add('maplibregl-popup-track-pointer');
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
if (this.options.maxWidth && this._container.style.maxWidth !== this.options.maxWidth) {
|
|
600
|
+
this._container.style.maxWidth = this.options.maxWidth;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
if (this._map.transform.renderWorldCopies && !this._trackPointer) {
|
|
604
|
+
this._lngLat = smartWrap(this._lngLat, this._flatPos, this._map.transform);
|
|
605
|
+
} else {
|
|
606
|
+
this._lngLat = this._lngLat?.wrap();
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
if (this._trackPointer && !cursor) return;
|
|
610
|
+
|
|
611
|
+
const pos = this._flatPos = this._pos = this._trackPointer && cursor ? cursor : this._map.project(this._lngLat);
|
|
612
|
+
if (this._map.terrain) {
|
|
613
|
+
// flat position is saved because smartWrap needs non-elevated points
|
|
614
|
+
this._flatPos = this._trackPointer && cursor ? cursor : this._map.transform.locationPoint(this._lngLat);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
let anchor = this.options.anchor;
|
|
618
|
+
const offset = normalizeOffset(this.options.offset);
|
|
619
|
+
|
|
620
|
+
if (!anchor) {
|
|
621
|
+
const width = this._container.offsetWidth;
|
|
622
|
+
const height = this._container.offsetHeight;
|
|
623
|
+
let anchorComponents;
|
|
624
|
+
|
|
625
|
+
if (pos.y + offset.bottom.y < height) {
|
|
626
|
+
anchorComponents = ['top'];
|
|
627
|
+
} else if (pos.y > this._map.transform.height - height) {
|
|
628
|
+
anchorComponents = ['bottom'];
|
|
629
|
+
} else {
|
|
630
|
+
anchorComponents = [];
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
if (pos.x < width / 2) {
|
|
634
|
+
anchorComponents.push('left');
|
|
635
|
+
} else if (pos.x > this._map.transform.width - width / 2) {
|
|
636
|
+
anchorComponents.push('right');
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
if (anchorComponents.length === 0) {
|
|
640
|
+
anchor = 'bottom';
|
|
641
|
+
} else {
|
|
642
|
+
anchor = (anchorComponents.join('-') as any);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
let offsetedPos = pos.add(offset[anchor]);
|
|
647
|
+
|
|
648
|
+
if (!this.options.subpixelPositioning) {
|
|
649
|
+
offsetedPos = offsetedPos.round();
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
DOM.setTransform(this._container, `${anchorTranslate[anchor]} translate(${offsetedPos.x}px,${offsetedPos.y}px)`);
|
|
653
|
+
applyAnchorClass(this._container, anchor, 'popup');
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
_focusFirstElement() {
|
|
657
|
+
if (!this.options.focusAfterOpen || !this._container) return;
|
|
658
|
+
|
|
659
|
+
const firstFocusable = this._container.querySelector(focusQuerySelector) as HTMLElement;
|
|
660
|
+
|
|
661
|
+
if (firstFocusable) firstFocusable.focus();
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
_onClose = () => {
|
|
665
|
+
this.remove();
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
function normalizeOffset(offset?: Offset | null) {
|
|
670
|
+
if (!offset) {
|
|
671
|
+
return normalizeOffset(new Point(0, 0));
|
|
672
|
+
|
|
673
|
+
} else if (typeof offset === 'number') {
|
|
674
|
+
// input specifies a radius from which to calculate offsets at all positions
|
|
675
|
+
const cornerOffset = Math.round(Math.abs(offset) / Math.SQRT2);
|
|
676
|
+
return {
|
|
677
|
+
'center': new Point(0, 0),
|
|
678
|
+
'top': new Point(0, offset),
|
|
679
|
+
'top-left': new Point(cornerOffset, cornerOffset),
|
|
680
|
+
'top-right': new Point(-cornerOffset, cornerOffset),
|
|
681
|
+
'bottom': new Point(0, -offset),
|
|
682
|
+
'bottom-left': new Point(cornerOffset, -cornerOffset),
|
|
683
|
+
'bottom-right': new Point(-cornerOffset, -cornerOffset),
|
|
684
|
+
'left': new Point(offset, 0),
|
|
685
|
+
'right': new Point(-offset, 0)
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
} else if (offset instanceof Point || Array.isArray(offset)) {
|
|
689
|
+
// input specifies a single offset to be applied to all positions
|
|
690
|
+
const convertedOffset = Point.convert(offset);
|
|
691
|
+
return {
|
|
692
|
+
'center': convertedOffset,
|
|
693
|
+
'top': convertedOffset,
|
|
694
|
+
'top-left': convertedOffset,
|
|
695
|
+
'top-right': convertedOffset,
|
|
696
|
+
'bottom': convertedOffset,
|
|
697
|
+
'bottom-left': convertedOffset,
|
|
698
|
+
'bottom-right': convertedOffset,
|
|
699
|
+
'left': convertedOffset,
|
|
700
|
+
'right': convertedOffset
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
} else {
|
|
704
|
+
// input specifies an offset per position
|
|
705
|
+
return {
|
|
706
|
+
'center': Point.convert(offset['center'] || [0, 0]),
|
|
707
|
+
'top': Point.convert(offset['top'] || [0, 0]),
|
|
708
|
+
'top-left': Point.convert(offset['top-left'] || [0, 0]),
|
|
709
|
+
'top-right': Point.convert(offset['top-right'] || [0, 0]),
|
|
710
|
+
'bottom': Point.convert(offset['bottom'] || [0, 0]),
|
|
711
|
+
'bottom-left': Point.convert(offset['bottom-left'] || [0, 0]),
|
|
712
|
+
'bottom-right': Point.convert(offset['bottom-right'] || [0, 0]),
|
|
713
|
+
'left': Point.convert(offset['left'] || [0, 0]),
|
|
714
|
+
'right': Point.convert(offset['right'] || [0, 0])
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
}
|