@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,357 @@
|
|
|
1
|
+
import {LngLat} from './lng_lat';
|
|
2
|
+
import {LngLatBounds} from './lng_lat_bounds';
|
|
3
|
+
|
|
4
|
+
describe('LngLatBounds', () => {
|
|
5
|
+
test('#constructor', () => {
|
|
6
|
+
const sw = new LngLat(0, 0);
|
|
7
|
+
const ne = new LngLat(-10, 10);
|
|
8
|
+
const bounds = new LngLatBounds(sw, ne);
|
|
9
|
+
expect(bounds.getSouth()).toBe(0);
|
|
10
|
+
expect(bounds.getWest()).toBe(0);
|
|
11
|
+
expect(bounds.getNorth()).toBe(10);
|
|
12
|
+
expect(bounds.getEast()).toBe(-10);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('#constructor across dateline', () => {
|
|
16
|
+
const sw = new LngLat(170, 0);
|
|
17
|
+
const ne = new LngLat(-170, 10);
|
|
18
|
+
const bounds = new LngLatBounds(sw, ne);
|
|
19
|
+
expect(bounds.getSouth()).toBe(0);
|
|
20
|
+
expect(bounds.getWest()).toBe(170);
|
|
21
|
+
expect(bounds.getNorth()).toBe(10);
|
|
22
|
+
expect(bounds.getEast()).toBe(-170);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('#constructor across pole', () => {
|
|
26
|
+
const sw = new LngLat(0, 85);
|
|
27
|
+
const ne = new LngLat(-10, -85);
|
|
28
|
+
const bounds = new LngLatBounds(sw, ne);
|
|
29
|
+
expect(bounds.getSouth()).toBe(85);
|
|
30
|
+
expect(bounds.getWest()).toBe(0);
|
|
31
|
+
expect(bounds.getNorth()).toBe(-85);
|
|
32
|
+
expect(bounds.getEast()).toBe(-10);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('#constructor no args', () => {
|
|
36
|
+
const bounds = new LngLatBounds();
|
|
37
|
+
const t1 = () => {
|
|
38
|
+
bounds.getCenter();
|
|
39
|
+
};
|
|
40
|
+
expect(t1).toThrow();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('#extend with coordinate', () => {
|
|
44
|
+
const bounds = new LngLatBounds([0, 0], [10, 10]);
|
|
45
|
+
bounds.extend([-10, -10]);
|
|
46
|
+
|
|
47
|
+
expect(bounds.getSouth()).toBe(-10);
|
|
48
|
+
expect(bounds.getWest()).toBe(-10);
|
|
49
|
+
expect(bounds.getNorth()).toBe(10);
|
|
50
|
+
expect(bounds.getEast()).toBe(10);
|
|
51
|
+
|
|
52
|
+
bounds.extend(new LngLat(-15, -15));
|
|
53
|
+
|
|
54
|
+
expect(bounds.getSouth()).toBe(-15);
|
|
55
|
+
expect(bounds.getWest()).toBe(-15);
|
|
56
|
+
expect(bounds.getNorth()).toBe(10);
|
|
57
|
+
expect(bounds.getEast()).toBe(10);
|
|
58
|
+
|
|
59
|
+
bounds.extend([-80, -80, 80, 80]);
|
|
60
|
+
|
|
61
|
+
expect(bounds.getSouth()).toBe(-80);
|
|
62
|
+
expect(bounds.getWest()).toBe(-80);
|
|
63
|
+
expect(bounds.getNorth()).toBe(80);
|
|
64
|
+
expect(bounds.getEast()).toBe(80);
|
|
65
|
+
|
|
66
|
+
bounds.extend({lng: -90, lat: -90});
|
|
67
|
+
|
|
68
|
+
expect(bounds.getSouth()).toBe(-90);
|
|
69
|
+
expect(bounds.getWest()).toBe(-90);
|
|
70
|
+
expect(bounds.getNorth()).toBe(80);
|
|
71
|
+
expect(bounds.getEast()).toBe(80);
|
|
72
|
+
|
|
73
|
+
bounds.extend({lon: 90, lat: 90});
|
|
74
|
+
|
|
75
|
+
expect(bounds.getSouth()).toBe(-90);
|
|
76
|
+
expect(bounds.getWest()).toBe(-90);
|
|
77
|
+
expect(bounds.getNorth()).toBe(90);
|
|
78
|
+
expect(bounds.getEast()).toBe(90);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('#extend with bounds', () => {
|
|
82
|
+
const bounds1 = new LngLatBounds([0, 0], [10, 10]);
|
|
83
|
+
const bounds2 = new LngLatBounds([-10, -10], [10, 10]);
|
|
84
|
+
|
|
85
|
+
bounds1.extend(bounds2);
|
|
86
|
+
|
|
87
|
+
expect(bounds1.getSouth()).toBe(-10);
|
|
88
|
+
expect(bounds1.getWest()).toBe(-10);
|
|
89
|
+
expect(bounds1.getNorth()).toBe(10);
|
|
90
|
+
expect(bounds1.getEast()).toBe(10);
|
|
91
|
+
|
|
92
|
+
const bounds4 = new LngLatBounds([-20, -20, 20, 20]);
|
|
93
|
+
bounds1.extend(bounds4);
|
|
94
|
+
|
|
95
|
+
expect(bounds1.getSouth()).toBe(-20);
|
|
96
|
+
expect(bounds1.getWest()).toBe(-20);
|
|
97
|
+
expect(bounds1.getNorth()).toBe(20);
|
|
98
|
+
expect(bounds1.getEast()).toBe(20);
|
|
99
|
+
|
|
100
|
+
const bounds5 = new LngLatBounds();
|
|
101
|
+
bounds1.extend(bounds5);
|
|
102
|
+
|
|
103
|
+
expect(bounds1.getSouth()).toBe(-20);
|
|
104
|
+
expect(bounds1.getWest()).toBe(-20);
|
|
105
|
+
expect(bounds1.getNorth()).toBe(20);
|
|
106
|
+
expect(bounds1.getEast()).toBe(20);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('#extend with null', () => {
|
|
110
|
+
const bounds = new LngLatBounds([0, 0], [10, 10]);
|
|
111
|
+
|
|
112
|
+
bounds.extend(null);
|
|
113
|
+
|
|
114
|
+
expect(bounds.getSouth()).toBe(0);
|
|
115
|
+
expect(bounds.getWest()).toBe(0);
|
|
116
|
+
expect(bounds.getNorth()).toBe(10);
|
|
117
|
+
expect(bounds.getEast()).toBe(10);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('#extend undefined bounding box', () => {
|
|
121
|
+
const bounds1 = new LngLatBounds(undefined, undefined);
|
|
122
|
+
const bounds2 = new LngLatBounds([-10, -10], [10, 10]);
|
|
123
|
+
|
|
124
|
+
bounds1.extend(bounds2);
|
|
125
|
+
|
|
126
|
+
expect(bounds1.getSouth()).toBe(-10);
|
|
127
|
+
expect(bounds1.getWest()).toBe(-10);
|
|
128
|
+
expect(bounds1.getNorth()).toBe(10);
|
|
129
|
+
expect(bounds1.getEast()).toBe(10);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('#extend same LngLat instance', () => {
|
|
133
|
+
const point = new LngLat(0, 0);
|
|
134
|
+
const bounds = new LngLatBounds(point, point);
|
|
135
|
+
|
|
136
|
+
bounds.extend(new LngLat(15, 15));
|
|
137
|
+
|
|
138
|
+
expect(bounds.getSouth()).toBe(0);
|
|
139
|
+
expect(bounds.getWest()).toBe(0);
|
|
140
|
+
expect(bounds.getNorth()).toBe(15);
|
|
141
|
+
expect(bounds.getEast()).toBe(15);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('accessors', () => {
|
|
145
|
+
const sw = new LngLat(0, 0);
|
|
146
|
+
const ne = new LngLat(-10, -20);
|
|
147
|
+
const bounds = new LngLatBounds(sw, ne);
|
|
148
|
+
expect(bounds.getCenter()).toEqual(new LngLat(-5, -10));
|
|
149
|
+
expect(bounds.getSouth()).toBe(0);
|
|
150
|
+
expect(bounds.getWest()).toBe(0);
|
|
151
|
+
expect(bounds.getNorth()).toBe(-20);
|
|
152
|
+
expect(bounds.getEast()).toBe(-10);
|
|
153
|
+
expect(bounds.getSouthWest()).toEqual(new LngLat(0, 0));
|
|
154
|
+
expect(bounds.getSouthEast()).toEqual(new LngLat(-10, 0));
|
|
155
|
+
expect(bounds.getNorthEast()).toEqual(new LngLat(-10, -20));
|
|
156
|
+
expect(bounds.getNorthWest()).toEqual(new LngLat(0, -20));
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('#convert', () => {
|
|
160
|
+
const sw = new LngLat(0, 0);
|
|
161
|
+
const ne = new LngLat(-10, 10);
|
|
162
|
+
const bounds = new LngLatBounds(sw, ne);
|
|
163
|
+
expect(LngLatBounds.convert(undefined)).toBeUndefined();
|
|
164
|
+
expect(LngLatBounds.convert(bounds)).toEqual(bounds);
|
|
165
|
+
expect(LngLatBounds.convert([sw, ne])).toEqual(bounds);
|
|
166
|
+
expect(
|
|
167
|
+
LngLatBounds.convert([bounds.getWest(), bounds.getSouth(), bounds.getEast(), bounds.getNorth()])
|
|
168
|
+
).toEqual(bounds);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('#toArray', () => {
|
|
172
|
+
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
|
|
173
|
+
expect(llb.toArray()).toEqual([[-73.9876, 40.7661], [-73.9397, 40.8002]]);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('#toString', () => {
|
|
177
|
+
const llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
|
|
178
|
+
expect(llb.toString()).toBe('LngLatBounds(LngLat(-73.9876, 40.7661), LngLat(-73.9397, 40.8002))');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test('#isEmpty', () => {
|
|
182
|
+
const nullBounds = new LngLatBounds();
|
|
183
|
+
expect(nullBounds.isEmpty()).toBe(true);
|
|
184
|
+
|
|
185
|
+
const sw = new LngLat(0, 0);
|
|
186
|
+
const ne = new LngLat(-10, 10);
|
|
187
|
+
const bounds = new LngLatBounds(sw, ne);
|
|
188
|
+
expect(bounds.isEmpty()).toBe(false);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('#fromLngLat', () => {
|
|
192
|
+
const center0 = new LngLat(0, 0);
|
|
193
|
+
const center1 = new LngLat(-73.9749, 40.7736);
|
|
194
|
+
|
|
195
|
+
const center0Radius10 = LngLatBounds.fromLngLat(center0, 10);
|
|
196
|
+
const center1Radius10 = LngLatBounds.fromLngLat(center1, 10);
|
|
197
|
+
const center1Radius0 = LngLatBounds.fromLngLat(center1);
|
|
198
|
+
|
|
199
|
+
expect(center0Radius10.toArray()).toEqual(
|
|
200
|
+
[[-0.00008983152770714982, -0.00008983152770714982], [0.00008983152770714982, 0.00008983152770714982]]
|
|
201
|
+
);
|
|
202
|
+
expect(center1Radius10.toArray()).toEqual(
|
|
203
|
+
[[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]
|
|
204
|
+
);
|
|
205
|
+
expect(center1Radius0.toArray()).toEqual([[-73.9749, 40.7736], [-73.9749, 40.7736]]);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe('LngLatBounds adjustAntiMeridian tests', () => {
|
|
209
|
+
test('kenya', () => {
|
|
210
|
+
const sw = new LngLat(32.958984, -5.353521);
|
|
211
|
+
const ne = new LngLat(43.50585, 5.615985);
|
|
212
|
+
const bounds = new LngLatBounds(sw, ne).adjustAntiMeridian();
|
|
213
|
+
expect(bounds.getSouth()).toBe(-5.353521);
|
|
214
|
+
expect(bounds.getWest()).toBe(32.958984);
|
|
215
|
+
expect(bounds.getNorth()).toBe(5.615985);
|
|
216
|
+
expect(bounds.getEast()).toBe(43.50585);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('normal cross (crossing antimeridian)', () => {
|
|
220
|
+
const sw = new LngLat(170, 0);
|
|
221
|
+
const ne = new LngLat(-170, 10);
|
|
222
|
+
const bounds = new LngLatBounds(sw, ne).adjustAntiMeridian();
|
|
223
|
+
expect(bounds.getSouth()).toBe(0);
|
|
224
|
+
expect(bounds.getWest()).toBe(170);
|
|
225
|
+
expect(bounds.getNorth()).toBe(10);
|
|
226
|
+
expect(bounds.getEast()).toBe(190);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('exactly meridian (crossing antimeridian)', () => {
|
|
230
|
+
const sw = new LngLat(180, -20);
|
|
231
|
+
const ne = new LngLat(-180, 20);
|
|
232
|
+
const bounds = new LngLatBounds(sw, ne).adjustAntiMeridian();
|
|
233
|
+
expect(bounds.getSouth()).toBe(-20);
|
|
234
|
+
expect(bounds.getWest()).toBe(180);
|
|
235
|
+
expect(bounds.getNorth()).toBe(20);
|
|
236
|
+
expect(bounds.getEast()).toBe(180);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('small cross (crossing antimeridian)', () => {
|
|
240
|
+
const sw = new LngLat(179, -5);
|
|
241
|
+
const ne = new LngLat(-179, 5);
|
|
242
|
+
const bounds = new LngLatBounds(sw, ne).adjustAntiMeridian();
|
|
243
|
+
expect(bounds.getSouth()).toBe(-5);
|
|
244
|
+
expect(bounds.getWest()).toBe(179);
|
|
245
|
+
expect(bounds.getNorth()).toBe(5);
|
|
246
|
+
expect(bounds.getEast()).toBe(181);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('large cross (crossing antimeridian)', () => {
|
|
250
|
+
const sw = new LngLat(100, -30);
|
|
251
|
+
const ne = new LngLat(-100, 30);
|
|
252
|
+
const bounds = new LngLatBounds(sw, ne).adjustAntiMeridian();
|
|
253
|
+
expect(bounds.getSouth()).toBe(-30);
|
|
254
|
+
expect(bounds.getWest()).toBe(100);
|
|
255
|
+
expect(bounds.getNorth()).toBe(30);
|
|
256
|
+
expect(bounds.getEast()).toBe(260);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('reverse cross (crossing antimeridian)', () => {
|
|
260
|
+
const sw = new LngLat(-170, 0);
|
|
261
|
+
const ne = new LngLat(170, 10);
|
|
262
|
+
const bounds = new LngLatBounds(sw, ne).adjustAntiMeridian();
|
|
263
|
+
expect(bounds.getSouth()).toBe(0);
|
|
264
|
+
expect(bounds.getWest()).toBe(-170);
|
|
265
|
+
expect(bounds.getNorth()).toBe(10);
|
|
266
|
+
expect(bounds.getEast()).toBe(170);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test('reverse not cross', () => {
|
|
270
|
+
const sw = new LngLat(150, 0);
|
|
271
|
+
const ne = new LngLat(170, 10);
|
|
272
|
+
const bounds = new LngLatBounds(sw, ne).adjustAntiMeridian();
|
|
273
|
+
expect(bounds.getSouth()).toBe(0);
|
|
274
|
+
expect(bounds.getWest()).toBe(150);
|
|
275
|
+
expect(bounds.getNorth()).toBe(10);
|
|
276
|
+
expect(bounds.getEast()).toBe(170);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test('same longitude', () => {
|
|
280
|
+
const sw = new LngLat(175, -10);
|
|
281
|
+
const ne = new LngLat(175, 10);
|
|
282
|
+
const bounds = new LngLatBounds(sw, ne).adjustAntiMeridian();
|
|
283
|
+
expect(bounds.getSouth()).toBe(-10);
|
|
284
|
+
expect(bounds.getWest()).toBe(175);
|
|
285
|
+
expect(bounds.getNorth()).toBe(10);
|
|
286
|
+
expect(bounds.getEast()).toBe(175);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test('full world', () => {
|
|
290
|
+
const sw = new LngLat(-180, -90);
|
|
291
|
+
const ne = new LngLat(180, 90);
|
|
292
|
+
const bounds = new LngLatBounds(sw, ne).adjustAntiMeridian();
|
|
293
|
+
expect(bounds.getSouth()).toBe(-90);
|
|
294
|
+
expect(bounds.getWest()).toBe(-180);
|
|
295
|
+
expect(bounds.getNorth()).toBe(90);
|
|
296
|
+
expect(bounds.getEast()).toBe(180);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
test('across pole', () => {
|
|
300
|
+
const sw = new LngLat(0, 85);
|
|
301
|
+
const ne = new LngLat(-10, -85);
|
|
302
|
+
const bounds = new LngLatBounds(sw, ne).adjustAntiMeridian();
|
|
303
|
+
expect(bounds.getSouth()).toBe(85);
|
|
304
|
+
expect(bounds.getWest()).toBe(0);
|
|
305
|
+
expect(bounds.getNorth()).toBe(-85);
|
|
306
|
+
expect(bounds.getEast()).toBe(350);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
test('across pole reverse', () => {
|
|
310
|
+
const sw = new LngLat(-10, -85);
|
|
311
|
+
const ne = new LngLat(0, 85);
|
|
312
|
+
const bounds = new LngLatBounds(sw, ne).adjustAntiMeridian();
|
|
313
|
+
expect(bounds.getSouth()).toBe(-85);
|
|
314
|
+
expect(bounds.getWest()).toBe(-10);
|
|
315
|
+
expect(bounds.getNorth()).toBe(85);
|
|
316
|
+
expect(bounds.getEast()).toBe(0);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
test('across dateline', () => {
|
|
320
|
+
const sw = new LngLat(170, 0);
|
|
321
|
+
const ne = new LngLat(-170, 10);
|
|
322
|
+
const bounds = new LngLatBounds(sw, ne).adjustAntiMeridian();
|
|
323
|
+
expect(bounds.getSouth()).toBe(0);
|
|
324
|
+
expect(bounds.getWest()).toBe(170);
|
|
325
|
+
expect(bounds.getNorth()).toBe(10);
|
|
326
|
+
expect(bounds.getEast()).toBe(190);
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
describe('contains', () => {
|
|
331
|
+
describe('point', () => {
|
|
332
|
+
test('point is in bounds', () => {
|
|
333
|
+
const llb = new LngLatBounds([-1, -1], [1, 1]);
|
|
334
|
+
const ll = {lng: 0, lat: 0};
|
|
335
|
+
expect(llb.contains(ll)).toBeTruthy();
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test('point is not in bounds', () => {
|
|
339
|
+
const llb = new LngLatBounds([-1, -1], [1, 1]);
|
|
340
|
+
const ll = {lng: 3, lat: 3};
|
|
341
|
+
expect(llb.contains(ll)).toBeFalsy();
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test('point is in bounds that spans dateline', () => {
|
|
345
|
+
const llb = new LngLatBounds([190, -10], [170, 10]);
|
|
346
|
+
const ll = {lng: 180, lat: 0};
|
|
347
|
+
expect(llb.contains(ll)).toBeTruthy();
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
test('point is not in bounds that spans dateline', () => {
|
|
351
|
+
const llb = new LngLatBounds([190, -10], [170, 10]);
|
|
352
|
+
const ll = {lng: 0, lat: 0};
|
|
353
|
+
expect(llb.contains(ll)).toBeFalsy();
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
});
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import {LngLat} from './lng_lat';
|
|
2
|
+
import type {LngLatLike} from './lng_lat';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A {@link LngLatBounds} object, an array of {@link LngLatLike} objects in [sw, ne] order,
|
|
6
|
+
* or an array of numbers in [west, south, east, north] order.
|
|
7
|
+
*
|
|
8
|
+
* @group Geography and Geometry
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* let v1 = new LngLatBounds(
|
|
13
|
+
* new LngLat(-73.9876, 40.7661),
|
|
14
|
+
* new LngLat(-73.9397, 40.8002)
|
|
15
|
+
* );
|
|
16
|
+
* let v2 = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002])
|
|
17
|
+
* let v3 = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export type LngLatBoundsLike = LngLatBounds | [LngLatLike, LngLatLike] | [number, number, number, number];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A `LngLatBounds` object represents a geographical bounding box,
|
|
24
|
+
* defined by its southwest and northeast points in longitude and latitude.
|
|
25
|
+
*
|
|
26
|
+
* If no arguments are provided to the constructor, a `null` bounding box is created.
|
|
27
|
+
*
|
|
28
|
+
* Note that any Mapbox GL method that accepts a `LngLatBounds` object as an argument or option
|
|
29
|
+
* can also accept an `Array` of two {@link LngLatLike} constructs and will perform an implicit conversion.
|
|
30
|
+
* This flexible type is documented as {@link LngLatBoundsLike}.
|
|
31
|
+
*
|
|
32
|
+
* @group Geography and Geometry
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* let sw = new LngLat(-73.9876, 40.7661);
|
|
37
|
+
* let ne = new LngLat(-73.9397, 40.8002);
|
|
38
|
+
* let llb = new LngLatBounds(sw, ne);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export class LngLatBounds {
|
|
42
|
+
_ne: LngLat;
|
|
43
|
+
_sw: LngLat;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param sw - The southwest corner of the bounding box.
|
|
47
|
+
* OR array of 4 numbers in the order of west, south, east, north
|
|
48
|
+
* OR array of 2 LngLatLike: [sw,ne]
|
|
49
|
+
* @param ne - The northeast corner of the bounding box.
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* let sw = new LngLat(-73.9876, 40.7661);
|
|
53
|
+
* let ne = new LngLat(-73.9397, 40.8002);
|
|
54
|
+
* let llb = new LngLatBounds(sw, ne);
|
|
55
|
+
* ```
|
|
56
|
+
* OR
|
|
57
|
+
* ```ts
|
|
58
|
+
* let llb = new LngLatBounds([-73.9876, 40.7661, -73.9397, 40.8002]);
|
|
59
|
+
* ```
|
|
60
|
+
* OR
|
|
61
|
+
* ```ts
|
|
62
|
+
* let llb = new LngLatBounds([sw, ne]);
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
constructor(sw?: LngLatLike | [number, number, number, number] | [LngLatLike, LngLatLike], ne?: LngLatLike) {
|
|
66
|
+
if (!sw) {
|
|
67
|
+
// noop
|
|
68
|
+
} else if (ne) {
|
|
69
|
+
this.setSouthWest(<LngLatLike>sw).setNorthEast(ne);
|
|
70
|
+
} else if (Array.isArray(sw)) {
|
|
71
|
+
if (sw.length === 4) {
|
|
72
|
+
// 4 element array: west, south, east, north
|
|
73
|
+
this.setSouthWest([sw[0], sw[1]]).setNorthEast([sw[2], sw[3]]);
|
|
74
|
+
} else {
|
|
75
|
+
this.setSouthWest(sw[0] as LngLatLike).setNorthEast(sw[1] as LngLatLike);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Set the northeast corner of the bounding box
|
|
82
|
+
*
|
|
83
|
+
* @param ne - a {@link LngLatLike} object describing the northeast corner of the bounding box.
|
|
84
|
+
*/
|
|
85
|
+
setNorthEast(ne: LngLatLike): this {
|
|
86
|
+
this._ne = ne instanceof LngLat ? new LngLat(ne.lng, ne.lat) : LngLat.convert(ne);
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Set the southwest corner of the bounding box
|
|
92
|
+
*
|
|
93
|
+
* @param sw - a {@link LngLatLike} object describing the southwest corner of the bounding box.
|
|
94
|
+
*/
|
|
95
|
+
setSouthWest(sw: LngLatLike): this {
|
|
96
|
+
this._sw = sw instanceof LngLat ? new LngLat(sw.lng, sw.lat) : LngLat.convert(sw);
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Extend the bounds to include a given LngLatLike or LngLatBoundsLike.
|
|
102
|
+
*
|
|
103
|
+
* @param obj - object to extend to
|
|
104
|
+
*/
|
|
105
|
+
extend(obj: LngLatLike | LngLatBoundsLike): this {
|
|
106
|
+
const sw = this._sw,
|
|
107
|
+
ne = this._ne;
|
|
108
|
+
let sw2, ne2;
|
|
109
|
+
|
|
110
|
+
if (obj instanceof LngLat) {
|
|
111
|
+
sw2 = obj;
|
|
112
|
+
ne2 = obj;
|
|
113
|
+
|
|
114
|
+
} else if (obj instanceof LngLatBounds) {
|
|
115
|
+
sw2 = obj._sw;
|
|
116
|
+
ne2 = obj._ne;
|
|
117
|
+
|
|
118
|
+
if (!sw2 || !ne2) return this;
|
|
119
|
+
|
|
120
|
+
} else {
|
|
121
|
+
if (Array.isArray(obj)) {
|
|
122
|
+
if (obj.length === 4 || (obj as any[]).every(Array.isArray)) {
|
|
123
|
+
const lngLatBoundsObj = (obj as any as LngLatBoundsLike);
|
|
124
|
+
return this.extend(LngLatBounds.convert(lngLatBoundsObj));
|
|
125
|
+
} else {
|
|
126
|
+
const lngLatObj = (obj as any as LngLatLike);
|
|
127
|
+
return this.extend(LngLat.convert(lngLatObj));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
} else if (obj && ('lng' in obj || 'lon' in obj) && 'lat' in obj) {
|
|
131
|
+
return this.extend(LngLat.convert(obj));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!sw && !ne) {
|
|
138
|
+
this._sw = new LngLat(sw2.lng, sw2.lat);
|
|
139
|
+
this._ne = new LngLat(ne2.lng, ne2.lat);
|
|
140
|
+
|
|
141
|
+
} else {
|
|
142
|
+
sw.lng = Math.min(sw2.lng, sw.lng);
|
|
143
|
+
sw.lat = Math.min(sw2.lat, sw.lat);
|
|
144
|
+
ne.lng = Math.max(ne2.lng, ne.lng);
|
|
145
|
+
ne.lat = Math.max(ne2.lat, ne.lat);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Returns the geographical coordinate equidistant from the bounding box's corners.
|
|
153
|
+
*
|
|
154
|
+
* @returns The bounding box's center.
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* let llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
|
|
158
|
+
* llb.getCenter(); // = LngLat {lng: -73.96365, lat: 40.78315}
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
getCenter(): LngLat {
|
|
162
|
+
return new LngLat((this._sw.lng + this._ne.lng) / 2, (this._sw.lat + this._ne.lat) / 2);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Returns the southwest corner of the bounding box.
|
|
167
|
+
*
|
|
168
|
+
* @returns The southwest corner of the bounding box.
|
|
169
|
+
*/
|
|
170
|
+
getSouthWest(): LngLat { return this._sw; }
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Returns the northeast corner of the bounding box.
|
|
174
|
+
*
|
|
175
|
+
* @returns The northeast corner of the bounding box.
|
|
176
|
+
*/
|
|
177
|
+
getNorthEast(): LngLat { return this._ne; }
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Returns the northwest corner of the bounding box.
|
|
181
|
+
*
|
|
182
|
+
* @returns The northwest corner of the bounding box.
|
|
183
|
+
*/
|
|
184
|
+
getNorthWest(): LngLat { return new LngLat(this.getWest(), this.getNorth()); }
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Returns the southeast corner of the bounding box.
|
|
188
|
+
*
|
|
189
|
+
* @returns The southeast corner of the bounding box.
|
|
190
|
+
*/
|
|
191
|
+
getSouthEast(): LngLat { return new LngLat(this.getEast(), this.getSouth()); }
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Returns the west edge of the bounding box.
|
|
195
|
+
*
|
|
196
|
+
* @returns The west edge of the bounding box.
|
|
197
|
+
*/
|
|
198
|
+
getWest(): number { return this._sw.lng; }
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Returns the south edge of the bounding box.
|
|
202
|
+
*
|
|
203
|
+
* @returns The south edge of the bounding box.
|
|
204
|
+
*/
|
|
205
|
+
getSouth(): number { return this._sw.lat; }
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Returns the east edge of the bounding box.
|
|
209
|
+
*
|
|
210
|
+
* @returns The east edge of the bounding box.
|
|
211
|
+
*/
|
|
212
|
+
getEast(): number { return this._ne.lng; }
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Returns the north edge of the bounding box.
|
|
216
|
+
*
|
|
217
|
+
* @returns The north edge of the bounding box.
|
|
218
|
+
*/
|
|
219
|
+
getNorth(): number { return this._ne.lat; }
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Returns the bounding box represented as an array.
|
|
223
|
+
*
|
|
224
|
+
* @returns The bounding box represented as an array, consisting of the
|
|
225
|
+
* southwest and northeast coordinates of the bounding represented as arrays of numbers.
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* let llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
|
|
229
|
+
* llb.toArray(); // = [[-73.9876, 40.7661], [-73.9397, 40.8002]]
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
toArray() {
|
|
233
|
+
return [this._sw.toArray(), this._ne.toArray()];
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Return the bounding box represented as a string.
|
|
238
|
+
*
|
|
239
|
+
* @returns The bounding box represents as a string of the format
|
|
240
|
+
* `'LngLatBounds(LngLat(lng, lat), LngLat(lng, lat))'`.
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* let llb = new LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
|
|
244
|
+
* llb.toString(); // = "LngLatBounds(LngLat(-73.9876, 40.7661), LngLat(-73.9397, 40.8002))"
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
toString() {
|
|
248
|
+
return `LngLatBounds(${this._sw.toString()}, ${this._ne.toString()})`;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Check if the bounding box is an empty/`null`-type box.
|
|
253
|
+
*
|
|
254
|
+
* @returns True if bounds have been defined, otherwise false.
|
|
255
|
+
*/
|
|
256
|
+
isEmpty() {
|
|
257
|
+
return !(this._sw && this._ne);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Check if the point is within the bounding box.
|
|
262
|
+
*
|
|
263
|
+
* @param lnglat - geographic point to check against.
|
|
264
|
+
* @returns `true` if the point is within the bounding box.
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts
|
|
267
|
+
* let llb = new LngLatBounds(
|
|
268
|
+
* new LngLat(-73.9876, 40.7661),
|
|
269
|
+
* new LngLat(-73.9397, 40.8002)
|
|
270
|
+
* );
|
|
271
|
+
*
|
|
272
|
+
* let ll = new LngLat(-73.9567, 40.7789);
|
|
273
|
+
*
|
|
274
|
+
* console.log(llb.contains(ll)); // = true
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
contains(lnglat: LngLatLike) {
|
|
278
|
+
const {lng, lat} = LngLat.convert(lnglat);
|
|
279
|
+
|
|
280
|
+
const containsLatitude = this._sw.lat <= lat && lat <= this._ne.lat;
|
|
281
|
+
let containsLongitude = this._sw.lng <= lng && lng <= this._ne.lng;
|
|
282
|
+
if (this._sw.lng > this._ne.lng) { // wrapped coordinates
|
|
283
|
+
containsLongitude = this._sw.lng >= lng && lng >= this._ne.lng;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return containsLatitude && containsLongitude;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Converts an array to a `LngLatBounds` object.
|
|
291
|
+
*
|
|
292
|
+
* If a `LngLatBounds` object is passed in, the function returns it unchanged.
|
|
293
|
+
*
|
|
294
|
+
* Internally, the function calls `LngLat#convert` to convert arrays to `LngLat` values.
|
|
295
|
+
*
|
|
296
|
+
* @param input - An array of two coordinates to convert, or a `LngLatBounds` object to return.
|
|
297
|
+
* @returns A new `LngLatBounds` object, if a conversion occurred, or the original `LngLatBounds` object.
|
|
298
|
+
* @example
|
|
299
|
+
* ```ts
|
|
300
|
+
* let arr = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
|
|
301
|
+
* let llb = LngLatBounds.convert(arr); // = LngLatBounds {_sw: LngLat {lng: -73.9876, lat: 40.7661}, _ne: LngLat {lng: -73.9397, lat: 40.8002}}
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
static convert(input: LngLatBoundsLike | null): LngLatBounds {
|
|
305
|
+
if (input instanceof LngLatBounds) return input;
|
|
306
|
+
if (!input) return input as null;
|
|
307
|
+
return new LngLatBounds(input);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Returns a `LngLatBounds` from the coordinates extended by a given `radius`. The returned `LngLatBounds` completely contains the `radius`.
|
|
312
|
+
*
|
|
313
|
+
* @param center - center coordinates of the new bounds.
|
|
314
|
+
* @param radius - Distance in meters from the coordinates to extend the bounds.
|
|
315
|
+
* @returns A new `LngLatBounds` object representing the coordinates extended by the `radius`.
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* let center = new LngLat(-73.9749, 40.7736);
|
|
319
|
+
* LngLatBounds.fromLngLat(100).toArray(); // = [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
static fromLngLat(center: LngLat, radius:number = 0): LngLatBounds {
|
|
323
|
+
const earthCircumferenceInMetersAtEquator = 40075017;
|
|
324
|
+
const latAccuracy = 360 * radius / earthCircumferenceInMetersAtEquator,
|
|
325
|
+
lngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * center.lat);
|
|
326
|
+
|
|
327
|
+
return new LngLatBounds(new LngLat(center.lng - lngAccuracy, center.lat - latAccuracy),
|
|
328
|
+
new LngLat(center.lng + lngAccuracy, center.lat + latAccuracy));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Adjusts the given bounds to handle the case where the bounds cross the 180th meridian (antimeridian).
|
|
333
|
+
*
|
|
334
|
+
* @returns The adjusted LngLatBounds
|
|
335
|
+
* @example
|
|
336
|
+
* ```ts
|
|
337
|
+
* let bounds = new LngLatBounds([175.813127, -20.157768], [-178. 340903, -15.449124]);
|
|
338
|
+
* let adjustedBounds = bounds.adjustAntiMeridian();
|
|
339
|
+
* // adjustedBounds will be: [[175.813127, -20.157768], [181.659097, -15.449124]]
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
adjustAntiMeridian(): LngLatBounds {
|
|
343
|
+
const sw = new LngLat(this._sw.lng, this._sw.lat);
|
|
344
|
+
const ne = new LngLat(this._ne.lng, this._ne.lat);
|
|
345
|
+
|
|
346
|
+
if (sw.lng > ne.lng) {
|
|
347
|
+
return new LngLatBounds(
|
|
348
|
+
sw,
|
|
349
|
+
new LngLat(ne.lng + 360, ne.lat)
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
return new LngLatBounds(sw, ne);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
}
|