@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,170 @@
|
|
|
1
|
+
import {FakeServer, fakeServer} from 'nise';
|
|
2
|
+
import {rtlMainThreadPluginFactory} from './rtl_text_plugin_main_thread';
|
|
3
|
+
import {sleep} from '../util/test/util';
|
|
4
|
+
import {browser} from '../util/browser';
|
|
5
|
+
import {Dispatcher} from '../util/dispatcher';
|
|
6
|
+
import {PluginState} from './rtl_text_plugin_status';
|
|
7
|
+
import {MessageType} from '../util/actor_messages';
|
|
8
|
+
const rtlMainThreadPlugin = rtlMainThreadPluginFactory();
|
|
9
|
+
|
|
10
|
+
describe('RTLMainThreadPlugin', () => {
|
|
11
|
+
let server: FakeServer;
|
|
12
|
+
let broadcastSpy: jest.SpyInstance;
|
|
13
|
+
const url = 'http://example.com/plugin';
|
|
14
|
+
const failedToLoadMessage = `RTL Text Plugin failed to import scripts from ${url}`;
|
|
15
|
+
const SyncRTLPluginStateMessageName = MessageType.syncRTLPluginState;
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
server = fakeServer.create();
|
|
19
|
+
global.fetch = null;
|
|
20
|
+
// Reset the singleton instance before each test
|
|
21
|
+
rtlMainThreadPlugin.clearRTLTextPlugin();
|
|
22
|
+
broadcastSpy = jest.spyOn(Dispatcher.prototype, 'broadcast').mockImplementation(() => { return Promise.resolve({} as any); });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
function broadcastMockSuccess(message: MessageType, payload: PluginState): Promise<PluginState[]> {
|
|
26
|
+
console.log('broadcastMockSuccessDefer', payload.pluginStatus);
|
|
27
|
+
if (message === SyncRTLPluginStateMessageName) {
|
|
28
|
+
if (payload.pluginStatus === 'loading') {
|
|
29
|
+
const resultState: PluginState = {
|
|
30
|
+
pluginStatus: 'loaded',
|
|
31
|
+
pluginURL: payload.pluginURL
|
|
32
|
+
};
|
|
33
|
+
return Promise.resolve([resultState]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function broadcastMockSuccessDefer(message: MessageType, payload: PluginState): Promise<PluginState[]> {
|
|
39
|
+
if (message === SyncRTLPluginStateMessageName) {
|
|
40
|
+
if (payload.pluginStatus === 'deferred') {
|
|
41
|
+
const resultState: PluginState = {
|
|
42
|
+
pluginStatus: 'deferred',
|
|
43
|
+
pluginURL: payload.pluginURL
|
|
44
|
+
};
|
|
45
|
+
return Promise.resolve([resultState]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function broadcastMockFailure(message: MessageType, payload: PluginState): Promise<PluginState[]> {
|
|
51
|
+
if (message === SyncRTLPluginStateMessageName) {
|
|
52
|
+
if (payload.pluginStatus === 'loading') {
|
|
53
|
+
return Promise.reject(failedToLoadMessage);
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
return Promise.resolve([]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
afterEach(() => {
|
|
61
|
+
server.restore();
|
|
62
|
+
broadcastSpy.mockRestore();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should get the RTL text plugin status', () => {
|
|
66
|
+
const status = rtlMainThreadPlugin.getRTLTextPluginStatus();
|
|
67
|
+
expect(status).toBe('unavailable');
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should set the RTL text plugin and download it', async () => {
|
|
71
|
+
broadcastSpy = jest.spyOn(Dispatcher.prototype, 'broadcast').mockImplementation(broadcastMockSuccess as any);
|
|
72
|
+
await rtlMainThreadPlugin.setRTLTextPlugin(url);
|
|
73
|
+
expect(rtlMainThreadPlugin.url).toEqual(url);
|
|
74
|
+
expect(rtlMainThreadPlugin.status).toBe('loaded');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should set the RTL text plugin but deffer downloading', async () => {
|
|
78
|
+
await rtlMainThreadPlugin.setRTLTextPlugin(url, true);
|
|
79
|
+
expect(rtlMainThreadPlugin.status).toBe('deferred');
|
|
80
|
+
expect(broadcastSpy).toHaveBeenCalledWith(SyncRTLPluginStateMessageName, {pluginStatus: 'deferred', pluginURL: url});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should throw if the plugin is already set', async () => {
|
|
84
|
+
await rtlMainThreadPlugin.setRTLTextPlugin(url, true);
|
|
85
|
+
await expect(rtlMainThreadPlugin.setRTLTextPlugin(url)).rejects.toThrow('setRTLTextPlugin cannot be called multiple times.');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should throw if the plugin url is not set', async () => {
|
|
89
|
+
const spy = jest.spyOn(browser, 'resolveURL').mockImplementation(() => { return ''; });
|
|
90
|
+
await expect(rtlMainThreadPlugin.setRTLTextPlugin(null)).rejects.toThrow('requested url null is invalid');
|
|
91
|
+
spy.mockRestore();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should be in error state if download fails', async () => {
|
|
95
|
+
broadcastSpy = jest.spyOn(Dispatcher.prototype, 'broadcast').mockImplementation(broadcastMockFailure as any);
|
|
96
|
+
const resultPromise = rtlMainThreadPlugin.setRTLTextPlugin(url);
|
|
97
|
+
await expect(resultPromise).rejects.toBe(failedToLoadMessage);
|
|
98
|
+
expect(rtlMainThreadPlugin.url).toEqual(url);
|
|
99
|
+
expect(rtlMainThreadPlugin.status).toBe('error');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should lazy load the plugin if deferred', async () => {
|
|
103
|
+
// use success spy to make sure test case does not throw exception
|
|
104
|
+
const deferredSpy = jest.spyOn(Dispatcher.prototype, 'broadcast').mockImplementation(broadcastMockSuccessDefer as any);
|
|
105
|
+
await rtlMainThreadPlugin.setRTLTextPlugin(url, true);
|
|
106
|
+
expect(deferredSpy).toHaveBeenCalledTimes(1);
|
|
107
|
+
expect(deferredSpy).toHaveBeenCalledWith(SyncRTLPluginStateMessageName, {pluginStatus: 'deferred', pluginURL: url});
|
|
108
|
+
expect(rtlMainThreadPlugin.status).toBe('deferred');
|
|
109
|
+
deferredSpy.mockRestore();
|
|
110
|
+
|
|
111
|
+
// this is really a fire and forget
|
|
112
|
+
broadcastSpy = jest.spyOn(Dispatcher.prototype, 'broadcast').mockImplementation(broadcastMockSuccess as any);
|
|
113
|
+
rtlMainThreadPlugin.lazyLoad();
|
|
114
|
+
await sleep(1);
|
|
115
|
+
|
|
116
|
+
// 'loading'
|
|
117
|
+
expect(broadcastSpy).toHaveBeenCalledWith(SyncRTLPluginStateMessageName, {pluginStatus: 'loading', pluginURL: url});
|
|
118
|
+
expect(broadcastSpy).toHaveBeenCalledTimes(1);
|
|
119
|
+
|
|
120
|
+
// second call to lazyLoad should not change anything
|
|
121
|
+
rtlMainThreadPlugin.lazyLoad();
|
|
122
|
+
expect(broadcastSpy).toHaveBeenCalledTimes(1);
|
|
123
|
+
|
|
124
|
+
expect(rtlMainThreadPlugin.status).toBe('loaded');
|
|
125
|
+
|
|
126
|
+
// 3rd call to lazyLoad should not change anything
|
|
127
|
+
rtlMainThreadPlugin.lazyLoad();
|
|
128
|
+
expect(rtlMainThreadPlugin.status).toBe('loaded');
|
|
129
|
+
expect(broadcastSpy).toHaveBeenCalledTimes(1);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should set status to requested if RTL plugin was not set', async () => {
|
|
133
|
+
rtlMainThreadPlugin.lazyLoad();
|
|
134
|
+
expect(rtlMainThreadPlugin.status).toBe('requested');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should immediately download if RTL plugin was already requested, ignoring deferred:true', async () => {
|
|
138
|
+
broadcastSpy = jest.spyOn(Dispatcher.prototype, 'broadcast').mockImplementation(broadcastMockSuccess as any);
|
|
139
|
+
rtlMainThreadPlugin.lazyLoad();
|
|
140
|
+
expect(rtlMainThreadPlugin.status).toBe('requested');
|
|
141
|
+
await sleep(1);
|
|
142
|
+
|
|
143
|
+
// notice even when deferred is true, it should download because already requested
|
|
144
|
+
await rtlMainThreadPlugin.setRTLTextPlugin(url, true);
|
|
145
|
+
expect(rtlMainThreadPlugin.status).toBe('loaded');
|
|
146
|
+
expect(broadcastSpy).toHaveBeenCalledWith(SyncRTLPluginStateMessageName, {pluginStatus: 'loading', pluginURL: url});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('should allow multiple calls to lazyLoad', async () => {
|
|
150
|
+
rtlMainThreadPlugin.lazyLoad();
|
|
151
|
+
expect(rtlMainThreadPlugin.status).toBe('requested');
|
|
152
|
+
rtlMainThreadPlugin.lazyLoad();
|
|
153
|
+
expect(rtlMainThreadPlugin.status).toBe('requested');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('should be in error state if lazyLoad fails', async () => {
|
|
157
|
+
broadcastSpy = jest.spyOn(Dispatcher.prototype, 'broadcast').mockImplementation(broadcastMockSuccessDefer);
|
|
158
|
+
const resultPromise = rtlMainThreadPlugin.setRTLTextPlugin(url, true);
|
|
159
|
+
await expect(resultPromise).resolves.toBeUndefined();
|
|
160
|
+
|
|
161
|
+
expect(rtlMainThreadPlugin.status).toBe('deferred');
|
|
162
|
+
|
|
163
|
+
// the next one should fail
|
|
164
|
+
broadcastSpy = jest.spyOn(Dispatcher.prototype, 'broadcast').mockImplementation(broadcastMockFailure as any);
|
|
165
|
+
|
|
166
|
+
await expect(rtlMainThreadPlugin._requestImport()).rejects.toBe(failedToLoadMessage);
|
|
167
|
+
expect(rtlMainThreadPlugin.url).toEqual(url);
|
|
168
|
+
expect(rtlMainThreadPlugin.status).toBe('error');
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
|
|
2
|
+
import {browser} from '../util/browser';
|
|
3
|
+
import {Event, Evented} from '../util/evented';
|
|
4
|
+
import {RTLPluginStatus, RTLPluginLoadedEventName, PluginState} from './rtl_text_plugin_status';
|
|
5
|
+
import {Dispatcher, getGlobalDispatcher} from '../util/dispatcher';
|
|
6
|
+
import {MessageType} from '../util/actor_messages';
|
|
7
|
+
|
|
8
|
+
class RTLMainThreadPlugin extends Evented {
|
|
9
|
+
status: RTLPluginStatus = 'unavailable';
|
|
10
|
+
url: string = null;
|
|
11
|
+
dispatcher: Dispatcher = getGlobalDispatcher();
|
|
12
|
+
|
|
13
|
+
/** Sync RTL plugin state by broadcasting a message to the worker */
|
|
14
|
+
_syncState(statusToSend: RTLPluginStatus): Promise<PluginState[]> {
|
|
15
|
+
this.status = statusToSend;
|
|
16
|
+
return this.dispatcher.broadcast(MessageType.syncRTLPluginState, {pluginStatus: statusToSend, pluginURL: this.url})
|
|
17
|
+
.catch((e: any) => {
|
|
18
|
+
this.status = 'error';
|
|
19
|
+
throw e;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** This one is exposed to outside */
|
|
24
|
+
getRTLTextPluginStatus(): RTLPluginStatus {
|
|
25
|
+
return this.status;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
clearRTLTextPlugin(): void {
|
|
29
|
+
this.status = 'unavailable';
|
|
30
|
+
this.url = null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async setRTLTextPlugin(url: string, deferred: boolean = false): Promise<void> {
|
|
34
|
+
if (this.url) {
|
|
35
|
+
// error
|
|
36
|
+
throw new Error('setRTLTextPlugin cannot be called multiple times.');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this.url = browser.resolveURL(url);
|
|
40
|
+
if (!this.url) {
|
|
41
|
+
throw new Error(`requested url ${url} is invalid`);
|
|
42
|
+
}
|
|
43
|
+
if (this.status === 'unavailable') {
|
|
44
|
+
|
|
45
|
+
// from initial state:
|
|
46
|
+
if (deferred) {
|
|
47
|
+
|
|
48
|
+
this.status = 'deferred';
|
|
49
|
+
// fire and forget: in this case it does not need wait for the broadcasting result
|
|
50
|
+
// it is important to sync the deferred status once because
|
|
51
|
+
// symbol_bucket will be checking it in worker
|
|
52
|
+
this._syncState(this.status);
|
|
53
|
+
|
|
54
|
+
} else {
|
|
55
|
+
return this._requestImport();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
} else if (this.status === 'requested') {
|
|
59
|
+
return this._requestImport();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Send a message to worker which will import the RTL plugin script */
|
|
64
|
+
async _requestImport() : Promise<void> {
|
|
65
|
+
|
|
66
|
+
// all errors/exceptions will be handled by _syncState
|
|
67
|
+
await this._syncState('loading');
|
|
68
|
+
this.status = 'loaded';
|
|
69
|
+
this.fire(new Event(RTLPluginLoadedEventName));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Start a lazy loading process of RTL plugin */
|
|
73
|
+
lazyLoad(): void {
|
|
74
|
+
if (this.status === 'unavailable') {
|
|
75
|
+
this.status = 'requested';
|
|
76
|
+
} else if (this.status === 'deferred') {
|
|
77
|
+
this._requestImport();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let rtlMainThreadPlugin: RTLMainThreadPlugin = null;
|
|
83
|
+
|
|
84
|
+
export function rtlMainThreadPluginFactory(): RTLMainThreadPlugin {
|
|
85
|
+
if (!rtlMainThreadPlugin) {
|
|
86
|
+
rtlMainThreadPlugin = new RTLMainThreadPlugin();
|
|
87
|
+
}
|
|
88
|
+
return rtlMainThreadPlugin;
|
|
89
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The possible option of the plugin's status
|
|
3
|
+
*
|
|
4
|
+
* `unavailable`: Not loaded.
|
|
5
|
+
*
|
|
6
|
+
* `deferred`: The plugin URL has been specified, but loading has been deferred.
|
|
7
|
+
*
|
|
8
|
+
* `requested`: at least one tile needs RTL to render, but the plugin has not been set
|
|
9
|
+
*
|
|
10
|
+
* `loading`: RTL is in the process of being loaded by worker.
|
|
11
|
+
*
|
|
12
|
+
* `loaded`: The plugin is now loaded
|
|
13
|
+
*
|
|
14
|
+
* `error`: The plugin failed to load
|
|
15
|
+
*/
|
|
16
|
+
export type RTLPluginStatus =
|
|
17
|
+
'unavailable' |
|
|
18
|
+
'deferred' |
|
|
19
|
+
'requested' |
|
|
20
|
+
'loading' |
|
|
21
|
+
'loaded' |
|
|
22
|
+
'error';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The RTL plugin state
|
|
26
|
+
*/
|
|
27
|
+
export type PluginState = {
|
|
28
|
+
pluginStatus: RTLPluginStatus;
|
|
29
|
+
pluginURL: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const RTLPluginLoadedEventName = 'RTLPluginLoaded';
|
|
33
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {PluginState, RTLPluginStatus} from './rtl_text_plugin_status';
|
|
2
|
+
|
|
3
|
+
export interface RTLTextPlugin {
|
|
4
|
+
applyArabicShaping: (a: string) => string;
|
|
5
|
+
processBidirectionalText: ((b: string, a: Array<number>) => Array<string>);
|
|
6
|
+
processStyledBidirectionalText: ((c: string, b: Array<number>, a: Array<number>) => Array<[string, Array<number>]>);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
class RTLWorkerPlugin implements RTLTextPlugin {
|
|
10
|
+
applyArabicShaping: (a: string) => string = null;
|
|
11
|
+
processBidirectionalText: ((b: string, a: Array<number>) => Array<string>) = null;
|
|
12
|
+
processStyledBidirectionalText: ((c: string, b: Array<number>, a: Array<number>) => Array<[string, Array<number>]>) = null;
|
|
13
|
+
pluginStatus: RTLPluginStatus = 'unavailable';
|
|
14
|
+
pluginURL: string = null;
|
|
15
|
+
|
|
16
|
+
setState(state: PluginState) {
|
|
17
|
+
this.pluginStatus = state.pluginStatus;
|
|
18
|
+
this.pluginURL = state.pluginURL;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getState(): PluginState {
|
|
22
|
+
return {
|
|
23
|
+
pluginStatus: this.pluginStatus,
|
|
24
|
+
pluginURL: this.pluginURL
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
setMethods(rtlTextPlugin: RTLTextPlugin) {
|
|
29
|
+
this.applyArabicShaping = rtlTextPlugin.applyArabicShaping;
|
|
30
|
+
this.processBidirectionalText = rtlTextPlugin.processBidirectionalText;
|
|
31
|
+
this.processStyledBidirectionalText = rtlTextPlugin.processStyledBidirectionalText;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
isParsed(): boolean {
|
|
35
|
+
return this.applyArabicShaping != null &&
|
|
36
|
+
this.processBidirectionalText != null &&
|
|
37
|
+
this.processStyledBidirectionalText != null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getPluginURL(): string {
|
|
41
|
+
return this.pluginURL;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getRTLTextPluginStatus() {
|
|
45
|
+
return this.pluginStatus;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const rtlWorkerPlugin = new RTLWorkerPlugin();
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {Dispatcher} from '../util/dispatcher';
|
|
2
|
+
import {SourceClass, addSourceType, create} from './source';
|
|
3
|
+
|
|
4
|
+
describe('addSourceType', () => {
|
|
5
|
+
test('adds factory function without a worker url does not dispatch to worker', async () => {
|
|
6
|
+
const sourceType = jest.fn().mockImplementation(function (id) { this.id = id; }) as SourceClass;
|
|
7
|
+
|
|
8
|
+
// expect no call to load worker source
|
|
9
|
+
const spy = jest.spyOn(Dispatcher.prototype, 'broadcast');
|
|
10
|
+
|
|
11
|
+
await addSourceType('foo', sourceType);
|
|
12
|
+
expect(spy).not.toHaveBeenCalled();
|
|
13
|
+
|
|
14
|
+
create('id', {type: 'foo'} as any, null, null);
|
|
15
|
+
expect(sourceType).toHaveBeenCalled();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('create a custom source without an id throws', async () => {
|
|
19
|
+
const sourceType = jest.fn() as SourceClass;
|
|
20
|
+
|
|
21
|
+
// expect no call to load worker source
|
|
22
|
+
const spy = jest.spyOn(Dispatcher.prototype, 'broadcast');
|
|
23
|
+
|
|
24
|
+
await addSourceType('foo2', sourceType);
|
|
25
|
+
expect(spy).not.toHaveBeenCalled();
|
|
26
|
+
|
|
27
|
+
expect(() => create('id', {type: 'foo2'} as any, null, null)).toThrow();
|
|
28
|
+
expect(sourceType).toHaveBeenCalled();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('refuses to add new type over existing name', async () => {
|
|
32
|
+
const sourceType = function () {} as any as SourceClass;
|
|
33
|
+
await expect(addSourceType('canvas', sourceType)).rejects.toThrow();
|
|
34
|
+
await expect(addSourceType('geojson', sourceType)).rejects.toThrow();
|
|
35
|
+
await expect(addSourceType('image', sourceType)).rejects.toThrow();
|
|
36
|
+
await expect(addSourceType('raster', sourceType)).rejects.toThrow();
|
|
37
|
+
await expect(addSourceType('raster-dem', sourceType)).rejects.toThrow();
|
|
38
|
+
await expect(addSourceType('vector', sourceType)).rejects.toThrow();
|
|
39
|
+
await expect(addSourceType('video', sourceType)).rejects.toThrow();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import {VectorTileSource} from '../source/vector_tile_source';
|
|
2
|
+
import {RasterTileSource} from '../source/raster_tile_source';
|
|
3
|
+
import {RasterDEMTileSource} from '../source/raster_dem_tile_source';
|
|
4
|
+
import {GeoJSONSource} from '../source/geojson_source';
|
|
5
|
+
import {VideoSource} from '../source/video_source';
|
|
6
|
+
import {ImageSource} from '../source/image_source';
|
|
7
|
+
import {CanvasSource} from '../source/canvas_source';
|
|
8
|
+
import {Dispatcher} from '../util/dispatcher';
|
|
9
|
+
|
|
10
|
+
import type {SourceSpecification} from '@maplibre/maplibre-gl-style-spec';
|
|
11
|
+
import type {Event, Evented} from '../util/evented';
|
|
12
|
+
import type {Map} from '../ui/map';
|
|
13
|
+
import type {Tile} from './tile';
|
|
14
|
+
import type {OverscaledTileID, CanonicalTileID} from './tile_id';
|
|
15
|
+
import type {CanvasSourceSpecification} from '../source/canvas_source';
|
|
16
|
+
|
|
17
|
+
const registeredSources = {} as {[key:string]: SourceClass};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The `Source` interface must be implemented by each source type, including "core" types (`vector`, `raster`,
|
|
21
|
+
* `video`, etc.) and all custom, third-party types.
|
|
22
|
+
*
|
|
23
|
+
* **Event** `data` - Fired with `{dataType: 'source', sourceDataType: 'metadata'}` to indicate that any necessary metadata
|
|
24
|
+
* has been loaded so that it's okay to call `loadTile`; and with `{dataType: 'source', sourceDataType: 'content'}`
|
|
25
|
+
* to indicate that the source data has changed, so that any current caches should be flushed.
|
|
26
|
+
*
|
|
27
|
+
* @group Sources
|
|
28
|
+
*/
|
|
29
|
+
export interface Source {
|
|
30
|
+
readonly type: string;
|
|
31
|
+
/**
|
|
32
|
+
* The id for the source. Must not be used by any existing source.
|
|
33
|
+
*/
|
|
34
|
+
id: string;
|
|
35
|
+
/**
|
|
36
|
+
* The minimum zoom level for the source.
|
|
37
|
+
*/
|
|
38
|
+
minzoom: number;
|
|
39
|
+
/**
|
|
40
|
+
* The maximum zoom level for the source.
|
|
41
|
+
*/
|
|
42
|
+
maxzoom: number;
|
|
43
|
+
/**
|
|
44
|
+
* The tile size for the source.
|
|
45
|
+
*/
|
|
46
|
+
tileSize: number;
|
|
47
|
+
/**
|
|
48
|
+
* The attribution for the source.
|
|
49
|
+
*/
|
|
50
|
+
attribution?: string;
|
|
51
|
+
/**
|
|
52
|
+
* `true` if zoom levels are rounded to the nearest integer in the source data, `false` if they are floor-ed to the nearest integer.
|
|
53
|
+
*/
|
|
54
|
+
roundZoom?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* `false` if tiles can be drawn outside their boundaries, `true` if they cannot.
|
|
57
|
+
*/
|
|
58
|
+
isTileClipped?: boolean;
|
|
59
|
+
tileID?: CanonicalTileID;
|
|
60
|
+
/**
|
|
61
|
+
* `true` if tiles should be sent back to the worker for each overzoomed zoom level, `false` if not.
|
|
62
|
+
*/
|
|
63
|
+
reparseOverscaled?: boolean;
|
|
64
|
+
vectorLayerIds?: Array<string>;
|
|
65
|
+
/**
|
|
66
|
+
* True if the source has transition, false otherwise.
|
|
67
|
+
*/
|
|
68
|
+
hasTransition(): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* True if the source is loaded, false otherwise.
|
|
71
|
+
*/
|
|
72
|
+
loaded(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* An ability to fire an event to all the listeners, see {@link Evented}
|
|
75
|
+
* @param event - The event to fire
|
|
76
|
+
*/
|
|
77
|
+
fire(event: Event): unknown;
|
|
78
|
+
/**
|
|
79
|
+
* This method is called when the source is added to the map.
|
|
80
|
+
* @param map - The map instance
|
|
81
|
+
*/
|
|
82
|
+
onAdd?(map: Map): void;
|
|
83
|
+
/**
|
|
84
|
+
* This method is called when the source is removed from the map.
|
|
85
|
+
* @param map - The map instance
|
|
86
|
+
*/
|
|
87
|
+
onRemove?(map: Map): void;
|
|
88
|
+
/**
|
|
89
|
+
* This method does the heavy lifting of loading a tile.
|
|
90
|
+
* In most cases it will defer the work to the relevant worker source.
|
|
91
|
+
* @param tile - The tile to load
|
|
92
|
+
*/
|
|
93
|
+
loadTile(tile: Tile): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* True is the tile is part of the source, false otherwise.
|
|
96
|
+
* @param tileID - The tile ID
|
|
97
|
+
*/
|
|
98
|
+
hasTile?(tileID: OverscaledTileID): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Allows to abort a tile loading.
|
|
101
|
+
* @param tile - The tile to abort
|
|
102
|
+
*/
|
|
103
|
+
abortTile?(tile: Tile): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Allows to unload a tile.
|
|
106
|
+
* @param tile - The tile to unload
|
|
107
|
+
*/
|
|
108
|
+
unloadTile?(tile: Tile): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* @returns A plain (stringifiable) JS object representing the current state of the source.
|
|
111
|
+
* Creating a source using the returned object as the `options` should result in a Source that is
|
|
112
|
+
* equivalent to this one.
|
|
113
|
+
*/
|
|
114
|
+
serialize(): any;
|
|
115
|
+
/**
|
|
116
|
+
* Allows to execute a prepare step before the source is used.
|
|
117
|
+
*/
|
|
118
|
+
prepare?(): void;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* A general definition of a {@link Source} class for factory usage
|
|
123
|
+
*/
|
|
124
|
+
export type SourceClass = {
|
|
125
|
+
new (id: string, specification: SourceSpecification | CanvasSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented): Source;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Creates a tiled data source instance given an options object.
|
|
130
|
+
*
|
|
131
|
+
* @param id - The id for the source. Must not be used by any existing source.
|
|
132
|
+
* @param specification - Source options, specific to the source type (except for `options.type`, which is always required).
|
|
133
|
+
* @param source - A source definition object compliant with
|
|
134
|
+
* [`maplibre-gl-style-spec`](https://maplibre.org/maplibre-style-spec/#sources) or, for a third-party source type,
|
|
135
|
+
* with that type's requirements.
|
|
136
|
+
* @param dispatcher - A {@link Dispatcher} instance, which can be used to send messages to the workers.
|
|
137
|
+
* @returns a newly created source
|
|
138
|
+
*/
|
|
139
|
+
export const create = (id: string, specification: SourceSpecification | CanvasSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented): Source => {
|
|
140
|
+
|
|
141
|
+
const Class = getSourceType(specification.type);
|
|
142
|
+
const source = new Class(id, specification, dispatcher, eventedParent);
|
|
143
|
+
|
|
144
|
+
if (source.id !== id) {
|
|
145
|
+
throw new Error(`Expected Source id to be ${id} instead of ${source.id}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return source;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const getSourceType = (name: string): SourceClass => {
|
|
152
|
+
switch (name) {
|
|
153
|
+
case 'geojson':
|
|
154
|
+
return GeoJSONSource;
|
|
155
|
+
case 'image':
|
|
156
|
+
return ImageSource;
|
|
157
|
+
case 'raster':
|
|
158
|
+
return RasterTileSource;
|
|
159
|
+
case 'raster-dem':
|
|
160
|
+
return RasterDEMTileSource;
|
|
161
|
+
case 'vector':
|
|
162
|
+
return VectorTileSource;
|
|
163
|
+
case 'video':
|
|
164
|
+
return VideoSource;
|
|
165
|
+
case 'canvas':
|
|
166
|
+
return CanvasSource;
|
|
167
|
+
}
|
|
168
|
+
return registeredSources[name];
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const setSourceType = (name: string, type: SourceClass) => {
|
|
172
|
+
registeredSources[name] = type;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Adds a custom source type, making it available for use with {@link Map#addSource}.
|
|
177
|
+
* @param name - The name of the source type; source definition objects use this name in the `{type: ...}` field.
|
|
178
|
+
* @param SourceType - A {@link SourceClass} - which is a constructor for the `Source` interface.
|
|
179
|
+
* @returns a promise that is resolved when the source type is ready or rejected with an error.
|
|
180
|
+
*/
|
|
181
|
+
export const addSourceType = async (name: string, SourceType: SourceClass): Promise<void> => {
|
|
182
|
+
if (getSourceType(name)) {
|
|
183
|
+
throw new Error(`A source type called "${name}" already exists.`);
|
|
184
|
+
}
|
|
185
|
+
setSourceType(name, SourceType);
|
|
186
|
+
};
|