@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,99 @@
|
|
|
1
|
+
import {mapObject} from '../util/util';
|
|
2
|
+
import {StyleLayerIndex} from './style_layer_index';
|
|
3
|
+
|
|
4
|
+
describe('StyleLayerIndex', () => {
|
|
5
|
+
test('StyleLayerIndex#replace', () => {
|
|
6
|
+
const index = new StyleLayerIndex([
|
|
7
|
+
{id: '1', type: 'fill', source: 'source', 'source-layer': 'layer', paint: {'fill-color': 'red'}},
|
|
8
|
+
{id: '2', type: 'circle', source: 'source', 'source-layer': 'layer', paint: {'circle-color': 'green'}},
|
|
9
|
+
{id: '3', type: 'circle', source: 'source', 'source-layer': 'layer', paint: {'circle-color': 'blue'}}
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const families = index.familiesBySource['source']['layer'];
|
|
13
|
+
expect(families).toHaveLength(2);
|
|
14
|
+
expect(families[0]).toHaveLength(1);
|
|
15
|
+
expect(families[0][0].id).toBe('1');
|
|
16
|
+
expect(families[1]).toHaveLength(2);
|
|
17
|
+
expect(families[1][0].id).toBe('2');
|
|
18
|
+
expect(families[1][1].id).toBe('3');
|
|
19
|
+
|
|
20
|
+
index.replace([]);
|
|
21
|
+
expect(index.familiesBySource).toEqual({});
|
|
22
|
+
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('StyleLayerIndex#update', () => {
|
|
26
|
+
const index = new StyleLayerIndex([
|
|
27
|
+
{id: '1', type: 'fill', source: 'foo', 'source-layer': 'layer', paint: {'fill-color': 'red'}},
|
|
28
|
+
{id: '2', type: 'circle', source: 'foo', 'source-layer': 'layer', paint: {'circle-color': 'green'}},
|
|
29
|
+
{id: '3', type: 'circle', source: 'foo', 'source-layer': 'layer', paint: {'circle-color': 'blue'}}
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
index.update([
|
|
33
|
+
{id: '1', type: 'fill', source: 'bar', 'source-layer': 'layer', paint: {'fill-color': 'cyan'}},
|
|
34
|
+
{id: '2', type: 'circle', source: 'bar', 'source-layer': 'layer', paint: {'circle-color': 'magenta'}},
|
|
35
|
+
{id: '3', type: 'circle', source: 'bar', 'source-layer': 'layer', paint: {'circle-color': 'yellow'}}
|
|
36
|
+
], []);
|
|
37
|
+
|
|
38
|
+
const families = index.familiesBySource['bar']['layer'];
|
|
39
|
+
expect(families).toHaveLength(2);
|
|
40
|
+
expect(families[0]).toHaveLength(1);
|
|
41
|
+
expect(families[0][0].getPaintProperty('fill-color')).toBe('cyan');
|
|
42
|
+
expect(families[1]).toHaveLength(2);
|
|
43
|
+
expect(families[1][0].getPaintProperty('circle-color')).toBe('magenta');
|
|
44
|
+
expect(families[1][0].source).toBe('bar');
|
|
45
|
+
expect(families[1][1].getPaintProperty('circle-color')).toBe('yellow');
|
|
46
|
+
expect(families[1][1].source).toBe('bar');
|
|
47
|
+
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('StyleLayerIndex#familiesBySource', () => {
|
|
51
|
+
const index = new StyleLayerIndex([
|
|
52
|
+
{id: '0', type: 'fill', 'source': 'A', 'source-layer': 'foo'},
|
|
53
|
+
{id: '1', type: 'fill', 'source': 'A', 'source-layer': 'foo'},
|
|
54
|
+
{id: '2', type: 'fill', 'source': 'A', 'source-layer': 'foo', 'minzoom': 1},
|
|
55
|
+
{id: '3', type: 'fill', 'source': 'A', 'source-layer': 'bar'},
|
|
56
|
+
{id: '4', type: 'fill', 'source': 'B', 'source-layer': 'foo'},
|
|
57
|
+
{id: '5', type: 'fill', 'source': 'geojson'},
|
|
58
|
+
{id: '6', type: 'background'}
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
const ids = mapObject(index.familiesBySource, (bySource) => {
|
|
62
|
+
return mapObject(bySource, (families) => {
|
|
63
|
+
return families.map((family) => {
|
|
64
|
+
return family.map((layer) => layer.id);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(ids).toEqual({
|
|
70
|
+
'A': {
|
|
71
|
+
'foo': [['0', '1'], ['2']],
|
|
72
|
+
'bar': [['3']]
|
|
73
|
+
},
|
|
74
|
+
'B': {
|
|
75
|
+
'foo': [['4']]
|
|
76
|
+
},
|
|
77
|
+
'geojson': {
|
|
78
|
+
'_geojsonTileLayer': [['5']]
|
|
79
|
+
},
|
|
80
|
+
'': {
|
|
81
|
+
'_geojsonTileLayer': [['6']]
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('StyleLayerIndex groups families even if layout key order differs', () => {
|
|
88
|
+
const index = new StyleLayerIndex([
|
|
89
|
+
{id: '0', type: 'line', 'source': 'source', 'source-layer': 'layer',
|
|
90
|
+
'layout': {'line-cap': 'butt', 'line-join': 'miter'}},
|
|
91
|
+
{id: '1', type: 'line', 'source': 'source', 'source-layer': 'layer',
|
|
92
|
+
'layout': {'line-join': 'miter', 'line-cap': 'butt'}}
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
const families = index.familiesBySource['source']['layer'];
|
|
96
|
+
expect(families[0]).toHaveLength(2);
|
|
97
|
+
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {StyleLayer} from './style_layer';
|
|
2
|
+
import {createStyleLayer} from './create_style_layer';
|
|
3
|
+
|
|
4
|
+
import {featureFilter, groupByLayout} from '@maplibre/maplibre-gl-style-spec';
|
|
5
|
+
|
|
6
|
+
import type {TypedStyleLayer} from './style_layer/typed_style_layer';
|
|
7
|
+
import type {LayerSpecification} from '@maplibre/maplibre-gl-style-spec';
|
|
8
|
+
|
|
9
|
+
export type LayerConfigs = {[_: string]: LayerSpecification};
|
|
10
|
+
export type Family<Layer extends TypedStyleLayer> = Array<Layer>;
|
|
11
|
+
|
|
12
|
+
export class StyleLayerIndex {
|
|
13
|
+
familiesBySource: {
|
|
14
|
+
[source: string]: {
|
|
15
|
+
[sourceLayer: string]: Array<Family<any>>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
keyCache: {[source: string]: string};
|
|
19
|
+
|
|
20
|
+
_layerConfigs: LayerConfigs;
|
|
21
|
+
_layers: {[_: string]: StyleLayer};
|
|
22
|
+
|
|
23
|
+
constructor(layerConfigs?: Array<LayerSpecification> | null) {
|
|
24
|
+
this.keyCache = {};
|
|
25
|
+
if (layerConfigs) {
|
|
26
|
+
this.replace(layerConfigs);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
replace(layerConfigs: Array<LayerSpecification>) {
|
|
31
|
+
this._layerConfigs = {};
|
|
32
|
+
this._layers = {};
|
|
33
|
+
this.update(layerConfigs, []);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
update(layerConfigs: Array<LayerSpecification>, removedIds: Array<string>) {
|
|
37
|
+
for (const layerConfig of layerConfigs) {
|
|
38
|
+
this._layerConfigs[layerConfig.id] = layerConfig;
|
|
39
|
+
|
|
40
|
+
const layer = this._layers[layerConfig.id] = createStyleLayer(layerConfig);
|
|
41
|
+
layer._featureFilter = featureFilter(layer.filter);
|
|
42
|
+
if (this.keyCache[layerConfig.id])
|
|
43
|
+
delete this.keyCache[layerConfig.id];
|
|
44
|
+
}
|
|
45
|
+
for (const id of removedIds) {
|
|
46
|
+
delete this.keyCache[id];
|
|
47
|
+
delete this._layerConfigs[id];
|
|
48
|
+
delete this._layers[id];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.familiesBySource = {};
|
|
52
|
+
|
|
53
|
+
const groups = groupByLayout(Object.values(this._layerConfigs), this.keyCache);
|
|
54
|
+
|
|
55
|
+
for (const layerConfigs of groups) {
|
|
56
|
+
const layers = layerConfigs.map((layerConfig) => this._layers[layerConfig.id]);
|
|
57
|
+
|
|
58
|
+
const layer = layers[0];
|
|
59
|
+
if (layer.visibility === 'none') {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const sourceId = layer.source || '';
|
|
64
|
+
let sourceGroup = this.familiesBySource[sourceId];
|
|
65
|
+
if (!sourceGroup) {
|
|
66
|
+
sourceGroup = this.familiesBySource[sourceId] = {};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const sourceLayerId = layer.sourceLayer || '_geojsonTileLayer';
|
|
70
|
+
let sourceLayerFamilies = sourceGroup[sourceLayerId];
|
|
71
|
+
if (!sourceLayerFamilies) {
|
|
72
|
+
sourceLayerFamilies = sourceGroup[sourceLayerId] = [];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
sourceLayerFamilies.push(layers);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {validateStyleMin} from '@maplibre/maplibre-gl-style-spec';
|
|
2
|
+
import {ErrorEvent} from '../util/evented';
|
|
3
|
+
|
|
4
|
+
import type {Evented} from '../util/evented';
|
|
5
|
+
|
|
6
|
+
type ValidationError = {
|
|
7
|
+
message: string;
|
|
8
|
+
line: number;
|
|
9
|
+
identifier?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type Validator = (a: any) => ReadonlyArray<ValidationError>;
|
|
13
|
+
|
|
14
|
+
type ValidateStyle = {
|
|
15
|
+
source: Validator;
|
|
16
|
+
sprite: Validator;
|
|
17
|
+
glyphs: Validator;
|
|
18
|
+
layer: Validator;
|
|
19
|
+
light: Validator;
|
|
20
|
+
sky: Validator;
|
|
21
|
+
terrain: Validator;
|
|
22
|
+
filter: Validator;
|
|
23
|
+
paintProperty: Validator;
|
|
24
|
+
layoutProperty: Validator;
|
|
25
|
+
(b: any, a?: any | null): ReadonlyArray<ValidationError>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const validateStyle = (validateStyleMin as unknown as ValidateStyle);
|
|
29
|
+
|
|
30
|
+
export const validateSource = validateStyle.source;
|
|
31
|
+
export const validateLight = validateStyle.light;
|
|
32
|
+
export const validateSky = validateStyle.sky;
|
|
33
|
+
export const validateTerrain = validateStyle.terrain;
|
|
34
|
+
export const validateFilter = validateStyle.filter;
|
|
35
|
+
export const validatePaintProperty = validateStyle.paintProperty;
|
|
36
|
+
export const validateLayoutProperty = validateStyle.layoutProperty;
|
|
37
|
+
|
|
38
|
+
export function emitValidationErrors(
|
|
39
|
+
emitter: Evented,
|
|
40
|
+
errors?: ReadonlyArray<{
|
|
41
|
+
message: string;
|
|
42
|
+
identifier?: string;
|
|
43
|
+
}> | null
|
|
44
|
+
): boolean {
|
|
45
|
+
let hasErrors = false;
|
|
46
|
+
if (errors && errors.length) {
|
|
47
|
+
for (const error of errors) {
|
|
48
|
+
emitter.fire(new ErrorEvent(new Error(error.message)));
|
|
49
|
+
hasErrors = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return hasErrors;
|
|
53
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export class ZoomHistory {
|
|
2
|
+
lastZoom: number;
|
|
3
|
+
lastFloorZoom: number;
|
|
4
|
+
lastIntegerZoom: number;
|
|
5
|
+
lastIntegerZoomTime: number;
|
|
6
|
+
first: boolean;
|
|
7
|
+
|
|
8
|
+
constructor() {
|
|
9
|
+
this.first = true;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
update(z: number, now: number) {
|
|
13
|
+
const floorZ = Math.floor(z);
|
|
14
|
+
|
|
15
|
+
if (this.first) {
|
|
16
|
+
this.first = false;
|
|
17
|
+
this.lastIntegerZoom = floorZ;
|
|
18
|
+
this.lastIntegerZoomTime = 0;
|
|
19
|
+
this.lastZoom = z;
|
|
20
|
+
this.lastFloorZoom = floorZ;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (this.lastFloorZoom > floorZ) {
|
|
25
|
+
this.lastIntegerZoom = floorZ + 1;
|
|
26
|
+
this.lastIntegerZoomTime = now;
|
|
27
|
+
} else if (this.lastFloorZoom < floorZ) {
|
|
28
|
+
this.lastIntegerZoom = floorZ;
|
|
29
|
+
this.lastIntegerZoomTime = now;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (z !== this.lastZoom) {
|
|
33
|
+
this.lastZoom = z;
|
|
34
|
+
this.lastFloorZoom = floorZ;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {Anchor} from './anchor';
|
|
2
|
+
|
|
3
|
+
describe('Anchor', () => {
|
|
4
|
+
test('#constructor', () => {
|
|
5
|
+
expect(new Anchor(0, 0, 0) instanceof Anchor).toBeTruthy();
|
|
6
|
+
expect(new Anchor(0, 0, 0, 0) instanceof Anchor).toBeTruthy();
|
|
7
|
+
});
|
|
8
|
+
test('#clone', () => {
|
|
9
|
+
const a = new Anchor(1, 2, 3);
|
|
10
|
+
const b = new Anchor(1, 2, 3);
|
|
11
|
+
expect(a.clone()).toEqual(b);
|
|
12
|
+
expect(a.clone()).toEqual(a);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Point from '@mapbox/point-geometry';
|
|
2
|
+
|
|
3
|
+
import {register} from '../util/web_worker_transfer';
|
|
4
|
+
|
|
5
|
+
export class Anchor extends Point {
|
|
6
|
+
angle: any;
|
|
7
|
+
segment?: number;
|
|
8
|
+
|
|
9
|
+
constructor(x: number, y: number, angle: number, segment?: number) {
|
|
10
|
+
super(x, y);
|
|
11
|
+
this.angle = angle;
|
|
12
|
+
if (segment !== undefined) {
|
|
13
|
+
this.segment = segment;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
clone() {
|
|
18
|
+
return new Anchor(this.x, this.y, this.angle, this.segment);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
register('Anchor', Anchor);
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import Point from '@mapbox/point-geometry';
|
|
2
|
+
import {checkMaxAngle} from './check_max_angle';
|
|
3
|
+
import {Anchor} from './anchor';
|
|
4
|
+
|
|
5
|
+
describe('checkMaxAngle', () => {
|
|
6
|
+
test('line with no sharp angles', () => {
|
|
7
|
+
const line = [new Point(0, 0), new Point(20, -1), new Point(40, 1), new Point(60, 0)];
|
|
8
|
+
const anchor = new Anchor(30, 0, 0, 1);
|
|
9
|
+
expect(checkMaxAngle(line, anchor, 25, 20, Math.PI / 8)).toBeTruthy();
|
|
10
|
+
expect(checkMaxAngle(line, anchor, 25, 20, 0)).toBeFalsy();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('one sharp corner', () => {
|
|
14
|
+
const line = [new Point(0, 0), new Point(0, 10), new Point(10, 10)];
|
|
15
|
+
const anchor = new Anchor(0, 10, 0, 1);
|
|
16
|
+
expect(checkMaxAngle(line, anchor, 10, 5, Math.PI / 2)).toBeTruthy();
|
|
17
|
+
expect(checkMaxAngle(line, anchor, 10, 5, Math.PI / 2 - 0.01)).toBeFalsy();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('many small corners close together', () => {
|
|
21
|
+
const line = [
|
|
22
|
+
new Point(0, 0), new Point(10, 0), new Point(11, 0.1),
|
|
23
|
+
new Point(12, 0.3), new Point(13, 0.6), new Point(14, 1), new Point(13.9, 10)];
|
|
24
|
+
const anchor = new Anchor(12, 0.3, 0, 3);
|
|
25
|
+
expect(checkMaxAngle(line, anchor, 10, 5, Math.PI / 2)).toBeFalsy();
|
|
26
|
+
expect(checkMaxAngle(line, anchor, 10, 2, Math.PI / 2)).toBeTruthy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('label appears on the first line segment', () => {
|
|
30
|
+
const line = [new Point(0, 0), new Point(100, 0)];
|
|
31
|
+
const anchor = new Anchor(50, 0, 0, 0);
|
|
32
|
+
expect(checkMaxAngle(line, anchor, 30, 5, Math.PI / 2)).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('not enough space before the end of the line', () => {
|
|
36
|
+
const line = [new Point(0, 0), new Point(10, 0), new Point(20, 0), new Point(30, 0)];
|
|
37
|
+
const anchor = new Anchor(5, 0, 0, 0);
|
|
38
|
+
expect(checkMaxAngle(line, anchor, 11, 5, Math.PI)).toBeFalsy();
|
|
39
|
+
expect(checkMaxAngle(line, anchor, 10, 5, Math.PI)).toBeTruthy();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('not enough space after the beginning of the line', () => {
|
|
43
|
+
const line = [new Point(0, 0), new Point(10, 0), new Point(20, 0), new Point(30, 0)];
|
|
44
|
+
const anchor = new Anchor(25, 0, 0, 2);
|
|
45
|
+
expect(checkMaxAngle(line, anchor, 11, 5, Math.PI)).toBeFalsy();
|
|
46
|
+
expect(checkMaxAngle(line, anchor, 10, 5, Math.PI)).toBeTruthy();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('one segment and label length is 0', () => {
|
|
50
|
+
const line = [new Point(0, 0), new Point(10, 0)];
|
|
51
|
+
const anchor = new Anchor(5, 0, 0, 0);
|
|
52
|
+
expect(checkMaxAngle(line, anchor, 0, 5, Math.PI)).toBeTruthy();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type Point from '@mapbox/point-geometry';
|
|
2
|
+
import type {Anchor} from './anchor';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Labels placed around really sharp angles aren't readable. Check if any
|
|
6
|
+
* part of the potential label has a combined angle that is too big.
|
|
7
|
+
*
|
|
8
|
+
* @param line - The line to check
|
|
9
|
+
* @param anchor - The point on the line around which the label is anchored.
|
|
10
|
+
* @param labelLength - The length of the label in geometry units.
|
|
11
|
+
* @param windowSize - The check fails if the combined angles within a part of the line that is `windowSize` long is too big.
|
|
12
|
+
* @param maxAngle - The maximum combined angle that any window along the label is allowed to have.
|
|
13
|
+
*
|
|
14
|
+
* @returns whether the label should be placed
|
|
15
|
+
*/
|
|
16
|
+
export function checkMaxAngle(line: Array<Point>, anchor: Anchor, labelLength: number, windowSize: number, maxAngle: number) {
|
|
17
|
+
|
|
18
|
+
// horizontal labels and labels with length 0 always pass
|
|
19
|
+
if (anchor.segment === undefined || labelLength === 0) return true;
|
|
20
|
+
|
|
21
|
+
let p = anchor;
|
|
22
|
+
let index = anchor.segment + 1;
|
|
23
|
+
let anchorDistance = 0;
|
|
24
|
+
|
|
25
|
+
// move backwards along the line to the first segment the label appears on
|
|
26
|
+
while (anchorDistance > -labelLength / 2) {
|
|
27
|
+
index--;
|
|
28
|
+
|
|
29
|
+
// there isn't enough room for the label after the beginning of the line
|
|
30
|
+
if (index < 0) return false;
|
|
31
|
+
|
|
32
|
+
anchorDistance -= line[index].dist(p);
|
|
33
|
+
p = line[index];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
anchorDistance += line[index].dist(line[index + 1]);
|
|
37
|
+
index++;
|
|
38
|
+
|
|
39
|
+
// store recent corners and their total angle difference
|
|
40
|
+
const recentCorners = [];
|
|
41
|
+
let recentAngleDelta = 0;
|
|
42
|
+
|
|
43
|
+
// move forwards by the length of the label and check angles along the way
|
|
44
|
+
while (anchorDistance < labelLength / 2) {
|
|
45
|
+
const prev = line[index - 1];
|
|
46
|
+
const current = line[index];
|
|
47
|
+
const next = line[index + 1];
|
|
48
|
+
|
|
49
|
+
// there isn't enough room for the label before the end of the line
|
|
50
|
+
if (!next) return false;
|
|
51
|
+
|
|
52
|
+
let angleDelta = prev.angleTo(current) - current.angleTo(next);
|
|
53
|
+
// restrict angle to -pi..pi range
|
|
54
|
+
angleDelta = Math.abs(((angleDelta + 3 * Math.PI) % (Math.PI * 2)) - Math.PI);
|
|
55
|
+
|
|
56
|
+
recentCorners.push({
|
|
57
|
+
distance: anchorDistance,
|
|
58
|
+
angleDelta
|
|
59
|
+
});
|
|
60
|
+
recentAngleDelta += angleDelta;
|
|
61
|
+
|
|
62
|
+
// remove corners that are far enough away from the list of recent anchors
|
|
63
|
+
while (anchorDistance - recentCorners[0].distance > windowSize) {
|
|
64
|
+
recentAngleDelta -= recentCorners.shift().angleDelta;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// the sum of angles within the window area exceeds the maximum allowed value. check fails.
|
|
68
|
+
if (recentAngleDelta > maxAngle) return false;
|
|
69
|
+
|
|
70
|
+
index++;
|
|
71
|
+
anchorDistance += current.dist(next);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// no part of the line had an angle greater than the maximum allowed. check passes.
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import Point from '@mapbox/point-geometry';
|
|
2
|
+
import {clipLine} from './clip_line';
|
|
3
|
+
|
|
4
|
+
describe('clipLines', () => {
|
|
5
|
+
|
|
6
|
+
const minX = -300;
|
|
7
|
+
const maxX = 300;
|
|
8
|
+
const minY = -200;
|
|
9
|
+
const maxY = 200;
|
|
10
|
+
|
|
11
|
+
const clipLineTest = (lines) => {
|
|
12
|
+
return clipLine(lines, minX, minY, maxX, maxY);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
test('Single line fully inside', () => {
|
|
16
|
+
const line = [
|
|
17
|
+
new Point(-100, -100),
|
|
18
|
+
new Point(-40, -100),
|
|
19
|
+
new Point(200, 0),
|
|
20
|
+
new Point(-80, 195)
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
expect(clipLineTest([line])).toEqual([line]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('Multiline fully inside', () => {
|
|
27
|
+
const line0 = [
|
|
28
|
+
new Point(-250, -150),
|
|
29
|
+
new Point(-250, 150),
|
|
30
|
+
new Point(-10, 150),
|
|
31
|
+
new Point(-10, -150)
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const line1 = [
|
|
35
|
+
new Point(250, -150),
|
|
36
|
+
new Point(250, 150),
|
|
37
|
+
new Point(10, 150),
|
|
38
|
+
new Point(10, -150)
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
const lines = [line0, line1];
|
|
42
|
+
|
|
43
|
+
expect(clipLineTest(lines)).toEqual(lines);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('Lines fully outside', () => {
|
|
47
|
+
const line0 = [
|
|
48
|
+
new Point(-400, -300),
|
|
49
|
+
new Point(-350, 0),
|
|
50
|
+
new Point(-300, 300)
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
const line1 = [
|
|
54
|
+
new Point(1000, 210),
|
|
55
|
+
new Point(10000, 500)
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
expect(clipLineTest([line0, line1])).toEqual([]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('Intersect with single border', () => {
|
|
62
|
+
const line0 = [
|
|
63
|
+
new Point(-400, 0),
|
|
64
|
+
new Point(0, 0)
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
const result0 = [
|
|
68
|
+
new Point(minX, 0),
|
|
69
|
+
new Point(0, 0)
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
const line1 = [
|
|
73
|
+
new Point(250, -50),
|
|
74
|
+
new Point(350, 50)
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const result1 = [
|
|
78
|
+
new Point(250, -50),
|
|
79
|
+
new Point(maxX, 0)
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
expect(clipLineTest([line0, line1])).toEqual([result0, result1]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('Intersect with multiple borders', () => {
|
|
86
|
+
const line0 = [
|
|
87
|
+
new Point(-350, -100),
|
|
88
|
+
new Point(-200, -250)
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
const line1 = [
|
|
92
|
+
new Point(-100, 250),
|
|
93
|
+
new Point(0, 150),
|
|
94
|
+
new Point(100, 250)
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
const result0 = [
|
|
98
|
+
new Point(minX, -150),
|
|
99
|
+
new Point(-250, minY)
|
|
100
|
+
];
|
|
101
|
+
|
|
102
|
+
const result1 = [
|
|
103
|
+
new Point(-50, maxY),
|
|
104
|
+
new Point(0, 150),
|
|
105
|
+
new Point(50, maxY)
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
expect(clipLineTest([line0, line1])).toEqual([result0, result1]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('Single line can be split into multiple segments', () => {
|
|
112
|
+
const line = [
|
|
113
|
+
new Point(-80, 150),
|
|
114
|
+
new Point(-80, 350),
|
|
115
|
+
new Point(120, 1000),
|
|
116
|
+
new Point(120, 0)
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
const result0 = [
|
|
120
|
+
new Point(-80, 150),
|
|
121
|
+
new Point(-80, maxY),
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
const result1 = [
|
|
125
|
+
new Point(120, maxY),
|
|
126
|
+
new Point(120, 0),
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
expect(clipLineTest([line])).toEqual([result0, result1]);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('Non-clipped points are bit exact', () => {
|
|
133
|
+
const line = [
|
|
134
|
+
new Point(-500, -200),
|
|
135
|
+
new Point(131.2356763, 0.956732)
|
|
136
|
+
];
|
|
137
|
+
|
|
138
|
+
expect(clipLineTest([line])[1]).toEqual(line[0][1]);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('Clipped points are rounded to the nearest integer', () => {
|
|
142
|
+
const line = [
|
|
143
|
+
new Point(310, 2.9),
|
|
144
|
+
new Point(290, 2.5)
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
const result = [
|
|
148
|
+
new Point(maxX, 3),
|
|
149
|
+
new Point(290, 2.5)
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
expect(clipLineTest([line])).toEqual([result]);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import Point from '@mapbox/point-geometry';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the part of a multiline that intersects with the provided rectangular box.
|
|
5
|
+
*
|
|
6
|
+
* @param lines - the lines to check
|
|
7
|
+
* @param x1 - the left edge of the box
|
|
8
|
+
* @param y1 - the top edge of the box
|
|
9
|
+
* @param x2 - the right edge of the box
|
|
10
|
+
* @param y2 - the bottom edge of the box
|
|
11
|
+
* @returns lines
|
|
12
|
+
*/
|
|
13
|
+
export function clipLine(lines: Array<Array<Point>>, x1: number, y1: number, x2: number, y2: number): Array<Array<Point>> {
|
|
14
|
+
const clippedLines = [];
|
|
15
|
+
|
|
16
|
+
for (let l = 0; l < lines.length; l++) {
|
|
17
|
+
const line = lines[l];
|
|
18
|
+
let clippedLine;
|
|
19
|
+
|
|
20
|
+
for (let i = 0; i < line.length - 1; i++) {
|
|
21
|
+
let p0 = line[i];
|
|
22
|
+
let p1 = line[i + 1];
|
|
23
|
+
|
|
24
|
+
if (p0.x < x1 && p1.x < x1) {
|
|
25
|
+
continue;
|
|
26
|
+
} else if (p0.x < x1) {
|
|
27
|
+
p0 = new Point(x1, p0.y + (p1.y - p0.y) * ((x1 - p0.x) / (p1.x - p0.x)))._round();
|
|
28
|
+
} else if (p1.x < x1) {
|
|
29
|
+
p1 = new Point(x1, p0.y + (p1.y - p0.y) * ((x1 - p0.x) / (p1.x - p0.x)))._round();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (p0.y < y1 && p1.y < y1) {
|
|
33
|
+
continue;
|
|
34
|
+
} else if (p0.y < y1) {
|
|
35
|
+
p0 = new Point(p0.x + (p1.x - p0.x) * ((y1 - p0.y) / (p1.y - p0.y)), y1)._round();
|
|
36
|
+
} else if (p1.y < y1) {
|
|
37
|
+
p1 = new Point(p0.x + (p1.x - p0.x) * ((y1 - p0.y) / (p1.y - p0.y)), y1)._round();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (p0.x >= x2 && p1.x >= x2) {
|
|
41
|
+
continue;
|
|
42
|
+
} else if (p0.x >= x2) {
|
|
43
|
+
p0 = new Point(x2, p0.y + (p1.y - p0.y) * ((x2 - p0.x) / (p1.x - p0.x)))._round();
|
|
44
|
+
} else if (p1.x >= x2) {
|
|
45
|
+
p1 = new Point(x2, p0.y + (p1.y - p0.y) * ((x2 - p0.x) / (p1.x - p0.x)))._round();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (p0.y >= y2 && p1.y >= y2) {
|
|
49
|
+
continue;
|
|
50
|
+
} else if (p0.y >= y2) {
|
|
51
|
+
p0 = new Point(p0.x + (p1.x - p0.x) * ((y2 - p0.y) / (p1.y - p0.y)), y2)._round();
|
|
52
|
+
} else if (p1.y >= y2) {
|
|
53
|
+
p1 = new Point(p0.x + (p1.x - p0.x) * ((y2 - p0.y) / (p1.y - p0.y)), y2)._round();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!clippedLine || !p0.equals(clippedLine[clippedLine.length - 1])) {
|
|
57
|
+
clippedLine = [p0];
|
|
58
|
+
clippedLines.push(clippedLine);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
clippedLine.push(p1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return clippedLines;
|
|
66
|
+
}
|