mapbox-gl 1.13.2
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/.flowconfig +61 -0
- package/CHANGELOG.md +2485 -0
- package/LICENSE.txt +84 -0
- package/README.md +34 -0
- package/build/banner.js +4 -0
- package/build/check-bundle-size.js +140 -0
- package/build/diff-tarball.js +18 -0
- package/build/generate-access-token-script.js +11 -0
- package/build/generate-flow-typed-style-spec.js +188 -0
- package/build/generate-release-list.js +21 -0
- package/build/generate-struct-arrays.js +243 -0
- package/build/generate-style-code.js +159 -0
- package/build/mapbox-gl.js.flow +3 -0
- package/build/print-release-url.js +6 -0
- package/build/rollup_plugin_minify_style_spec.js +24 -0
- package/build/rollup_plugins.js +80 -0
- package/build/run-node +3 -0
- package/build/run-tap +8 -0
- package/build/test/build-tape.js +19 -0
- package/dist/mapbox-gl-csp-worker.js +2 -0
- package/dist/mapbox-gl-csp-worker.js.map +1 -0
- package/dist/mapbox-gl-csp.js +2 -0
- package/dist/mapbox-gl-csp.js.map +1 -0
- package/dist/mapbox-gl-dev.js +65889 -0
- package/dist/mapbox-gl-dev.js.flow +3 -0
- package/dist/mapbox-gl-unminified.js +42889 -0
- package/dist/mapbox-gl-unminified.js.map +1 -0
- package/dist/mapbox-gl.css +1 -0
- package/dist/mapbox-gl.js +42 -0
- package/dist/mapbox-gl.js.flow +3 -0
- package/dist/mapbox-gl.js.map +1 -0
- package/dist/style-spec/index.es.js +15032 -0
- package/dist/style-spec/index.es.js.map +1 -0
- package/dist/style-spec/index.js +15058 -0
- package/dist/style-spec/index.js.map +1 -0
- package/flow-typed/gl.js +5 -0
- package/flow-typed/jsdom.js +18 -0
- package/flow-typed/mapbox-gl-supported.js +9 -0
- package/flow-typed/mapbox-unitbezier.js +14 -0
- package/flow-typed/offscreen-canvas.js +9 -0
- package/flow-typed/pbf.js +25 -0
- package/flow-typed/point-geometry.js +44 -0
- package/flow-typed/potpack.js +12 -0
- package/flow-typed/sinon.js +28 -0
- package/flow-typed/vector-tile.js +41 -0
- package/package.json +173 -0
- package/src/css/mapbox-gl.css +812 -0
- package/src/css/svg/mapboxgl-ctrl-attrib.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-compass.svg +4 -0
- package/src/css/svg/mapboxgl-ctrl-fullscreen.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-geolocate.svg +5 -0
- package/src/css/svg/mapboxgl-ctrl-logo.svg +20 -0
- package/src/css/svg/mapboxgl-ctrl-shrink.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-zoom-in.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-zoom-out.svg +3 -0
- package/src/data/array_types.js +1135 -0
- package/src/data/bucket/circle_attributes.js +9 -0
- package/src/data/bucket/circle_bucket.js +201 -0
- package/src/data/bucket/fill_attributes.js +9 -0
- package/src/data/bucket/fill_bucket.js +229 -0
- package/src/data/bucket/fill_extrusion_attributes.js +10 -0
- package/src/data/bucket/fill_extrusion_bucket.js +283 -0
- package/src/data/bucket/heatmap_bucket.js +17 -0
- package/src/data/bucket/line_attributes.js +10 -0
- package/src/data/bucket/line_attributes_ext.js +10 -0
- package/src/data/bucket/line_bucket.js +594 -0
- package/src/data/bucket/pattern_attributes.js +12 -0
- package/src/data/bucket/pattern_bucket_features.js +60 -0
- package/src/data/bucket/symbol_attributes.js +117 -0
- package/src/data/bucket/symbol_bucket.js +937 -0
- package/src/data/bucket.js +123 -0
- package/src/data/dem_data.js +125 -0
- package/src/data/evaluation_feature.js +25 -0
- package/src/data/extent.js +18 -0
- package/src/data/feature_index.js +322 -0
- package/src/data/feature_position_map.js +131 -0
- package/src/data/index_array_type.js +16 -0
- package/src/data/load_geometry.js +46 -0
- package/src/data/pos_attributes.js +6 -0
- package/src/data/program_configuration.js +708 -0
- package/src/data/raster_bounds_attributes.js +7 -0
- package/src/data/segment.js +76 -0
- package/src/geo/edge_insets.js +102 -0
- package/src/geo/lng_lat.js +168 -0
- package/src/geo/lng_lat_bounds.js +276 -0
- package/src/geo/mercator_coordinate.js +150 -0
- package/src/geo/transform.js +834 -0
- package/src/gl/color_mode.js +34 -0
- package/src/gl/context.js +302 -0
- package/src/gl/cull_face_mode.js +26 -0
- package/src/gl/depth_mode.js +29 -0
- package/src/gl/framebuffer.js +44 -0
- package/src/gl/index_buffer.js +55 -0
- package/src/gl/stencil_mode.js +30 -0
- package/src/gl/types.js +84 -0
- package/src/gl/value.js +520 -0
- package/src/gl/vertex_buffer.js +119 -0
- package/src/index.js +230 -0
- package/src/render/draw_background.js +57 -0
- package/src/render/draw_circle.js +113 -0
- package/src/render/draw_collision_debug.js +172 -0
- package/src/render/draw_custom.js +49 -0
- package/src/render/draw_debug.js +127 -0
- package/src/render/draw_fill.js +124 -0
- package/src/render/draw_fill_extrusion.js +95 -0
- package/src/render/draw_heatmap.js +133 -0
- package/src/render/draw_hillshade.js +107 -0
- package/src/render/draw_line.js +125 -0
- package/src/render/draw_raster.js +125 -0
- package/src/render/draw_symbol.js +392 -0
- package/src/render/glyph_atlas.js +71 -0
- package/src/render/glyph_manager.js +182 -0
- package/src/render/image_atlas.js +149 -0
- package/src/render/image_manager.js +306 -0
- package/src/render/line_atlas.js +210 -0
- package/src/render/painter.js +654 -0
- package/src/render/program/background_program.js +103 -0
- package/src/render/program/circle_program.js +69 -0
- package/src/render/program/clipping_mask_program.js +20 -0
- package/src/render/program/collision_program.js +76 -0
- package/src/render/program/debug_program.js +35 -0
- package/src/render/program/fill_extrusion_program.js +122 -0
- package/src/render/program/fill_program.js +126 -0
- package/src/render/program/heatmap_program.js +83 -0
- package/src/render/program/hillshade_program.js +119 -0
- package/src/render/program/line_program.js +211 -0
- package/src/render/program/pattern.js +102 -0
- package/src/render/program/program_uniforms.js +42 -0
- package/src/render/program/raster_program.js +92 -0
- package/src/render/program/symbol_program.js +224 -0
- package/src/render/program.js +188 -0
- package/src/render/texture.js +122 -0
- package/src/render/uniform_binding.js +147 -0
- package/src/render/vertex_array_object.js +163 -0
- package/src/shaders/README.md +42 -0
- package/src/shaders/_prelude.fragment.glsl +17 -0
- package/src/shaders/_prelude.vertex.glsl +73 -0
- package/src/shaders/background.fragment.glsl +10 -0
- package/src/shaders/background.vertex.glsl +7 -0
- package/src/shaders/background_pattern.fragment.glsl +28 -0
- package/src/shaders/background_pattern.vertex.glsl +20 -0
- package/src/shaders/circle.fragment.glsl +39 -0
- package/src/shaders/circle.vertex.glsl +64 -0
- package/src/shaders/clipping_mask.fragment.glsl +3 -0
- package/src/shaders/clipping_mask.vertex.glsl +7 -0
- package/src/shaders/collision_box.fragment.glsl +21 -0
- package/src/shaders/collision_box.vertex.glsl +27 -0
- package/src/shaders/collision_circle.fragment.glsl +17 -0
- package/src/shaders/collision_circle.vertex.glsl +59 -0
- package/src/shaders/debug.fragment.glsl +9 -0
- package/src/shaders/debug.vertex.glsl +12 -0
- package/src/shaders/encode_attribute.js +17 -0
- package/src/shaders/fill.fragment.glsl +13 -0
- package/src/shaders/fill.vertex.glsl +13 -0
- package/src/shaders/fill_extrusion.fragment.glsl +9 -0
- package/src/shaders/fill_extrusion.vertex.glsl +66 -0
- package/src/shaders/fill_extrusion_pattern.fragment.glsl +45 -0
- package/src/shaders/fill_extrusion_pattern.vertex.glsl +79 -0
- package/src/shaders/fill_outline.fragment.glsl +17 -0
- package/src/shaders/fill_outline.vertex.glsl +17 -0
- package/src/shaders/fill_outline_pattern.fragment.glsl +43 -0
- package/src/shaders/fill_outline_pattern.vertex.glsl +44 -0
- package/src/shaders/fill_pattern.fragment.glsl +36 -0
- package/src/shaders/fill_pattern.vertex.glsl +39 -0
- package/src/shaders/heatmap.fragment.glsl +22 -0
- package/src/shaders/heatmap.vertex.glsl +54 -0
- package/src/shaders/heatmap_texture.fragment.glsl +14 -0
- package/src/shaders/heatmap_texture.vertex.glsl +11 -0
- package/src/shaders/hillshade.fragment.glsl +52 -0
- package/src/shaders/hillshade.vertex.glsl +11 -0
- package/src/shaders/hillshade_prepare.fragment.glsl +75 -0
- package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
- package/src/shaders/index.js +20 -0
- package/src/shaders/line.fragment.glsl +30 -0
- package/src/shaders/line.vertex.glsl +85 -0
- package/src/shaders/line_gradient.fragment.glsl +34 -0
- package/src/shaders/line_gradient.vertex.glsl +88 -0
- package/src/shaders/line_pattern.fragment.glsl +74 -0
- package/src/shaders/line_pattern.vertex.glsl +99 -0
- package/src/shaders/line_sdf.fragment.glsl +45 -0
- package/src/shaders/line_sdf.vertex.glsl +98 -0
- package/src/shaders/raster.fragment.glsl +52 -0
- package/src/shaders/raster.vertex.glsl +21 -0
- package/src/shaders/shaders.js +185 -0
- package/src/shaders/symbol_icon.fragment.glsl +17 -0
- package/src/shaders/symbol_icon.vertex.glsl +94 -0
- package/src/shaders/symbol_sdf.fragment.glsl +52 -0
- package/src/shaders/symbol_sdf.vertex.glsl +115 -0
- package/src/shaders/symbol_text_and_icon.fragment.glsl +68 -0
- package/src/shaders/symbol_text_and_icon.vertex.glsl +116 -0
- package/src/source/canvas_source.js +238 -0
- package/src/source/geojson_source.js +370 -0
- package/src/source/geojson_worker_source.js +366 -0
- package/src/source/geojson_wrapper.js +94 -0
- package/src/source/image_source.js +307 -0
- package/src/source/load_tilejson.js +39 -0
- package/src/source/pixels_to_tile_units.js +21 -0
- package/src/source/query_features.js +208 -0
- package/src/source/raster_dem_tile_source.js +138 -0
- package/src/source/raster_dem_tile_worker_source.js +62 -0
- package/src/source/raster_tile_source.js +169 -0
- package/src/source/rtl_text_plugin.js +143 -0
- package/src/source/source.js +137 -0
- package/src/source/source_cache.js +953 -0
- package/src/source/source_state.js +159 -0
- package/src/source/tile.js +458 -0
- package/src/source/tile_bounds.js +38 -0
- package/src/source/tile_cache.js +212 -0
- package/src/source/tile_id.js +199 -0
- package/src/source/vector_tile_source.js +259 -0
- package/src/source/vector_tile_worker_source.js +216 -0
- package/src/source/video_source.js +203 -0
- package/src/source/worker.js +240 -0
- package/src/source/worker_source.js +107 -0
- package/src/source/worker_tile.js +224 -0
- package/src/style/create_style_layer.js +36 -0
- package/src/style/evaluation_parameters.js +62 -0
- package/src/style/format_section_override.js +56 -0
- package/src/style/light.js +130 -0
- package/src/style/load_glyph_range.js +38 -0
- package/src/style/load_sprite.js +67 -0
- package/src/style/parse_glyph_pbf.js +44 -0
- package/src/style/pauseable_placement.js +132 -0
- package/src/style/properties.js +753 -0
- package/src/style/query_utils.js +43 -0
- package/src/style/style.js +1374 -0
- package/src/style/style_glyph.js +17 -0
- package/src/style/style_image.js +137 -0
- package/src/style/style_layer/background_style_layer.js +21 -0
- package/src/style/style_layer/background_style_layer_properties.js +40 -0
- package/src/style/style_layer/circle_style_layer.js +98 -0
- package/src/style/style_layer/circle_style_layer_properties.js +63 -0
- package/src/style/style_layer/custom_style_layer.js +223 -0
- package/src/style/style_layer/fill_extrusion_style_layer.js +224 -0
- package/src/style/style_layer/fill_extrusion_style_layer_properties.js +50 -0
- package/src/style/style_layer/fill_style_layer.js +67 -0
- package/src/style/style_layer/fill_style_layer_properties.js +55 -0
- package/src/style/style_layer/heatmap_style_layer.js +73 -0
- package/src/style/style_layer/heatmap_style_layer_properties.js +44 -0
- package/src/style/style_layer/hillshade_style_layer.js +25 -0
- package/src/style/style_layer/hillshade_style_layer_properties.js +46 -0
- package/src/style/style_layer/layer_properties.js.ejs +69 -0
- package/src/style/style_layer/line_style_layer.js +150 -0
- package/src/style/style_layer/line_style_layer_properties.js +71 -0
- package/src/style/style_layer/raster_style_layer.js +21 -0
- package/src/style/style_layer/raster_style_layer_properties.js +50 -0
- package/src/style/style_layer/symbol_style_layer.js +190 -0
- package/src/style/style_layer/symbol_style_layer_properties.js +153 -0
- package/src/style/style_layer/typed_style_layer.js +17 -0
- package/src/style/style_layer.js +283 -0
- package/src/style/style_layer_index.js +80 -0
- package/src/style/validate_style.js +42 -0
- package/src/style/zoom_history.js +44 -0
- package/src/style-spec/.eslintrc +5 -0
- package/src/style-spec/CHANGELOG.md +468 -0
- package/src/style-spec/README.md +59 -0
- package/src/style-spec/bin/gl-style-composite +9 -0
- package/src/style-spec/bin/gl-style-format +22 -0
- package/src/style-spec/bin/gl-style-migrate +9 -0
- package/src/style-spec/bin/gl-style-validate +50 -0
- package/src/style-spec/composite.js +50 -0
- package/src/style-spec/declass.js +42 -0
- package/src/style-spec/deref.js +52 -0
- package/src/style-spec/diff.js +393 -0
- package/src/style-spec/dist/.gitkeep +0 -0
- package/src/style-spec/dist/index.es.js +15032 -0
- package/src/style-spec/dist/index.es.js.map +1 -0
- package/src/style-spec/dist/index.js +15058 -0
- package/src/style-spec/dist/index.js.map +1 -0
- package/src/style-spec/empty.js +29 -0
- package/src/style-spec/error/parsing_error.js +16 -0
- package/src/style-spec/error/validation_error.js +18 -0
- package/src/style-spec/expression/compound_expression.js +162 -0
- package/src/style-spec/expression/definitions/assertion.js +130 -0
- package/src/style-spec/expression/definitions/at.js +70 -0
- package/src/style-spec/expression/definitions/case.js +85 -0
- package/src/style-spec/expression/definitions/coalesce.js +93 -0
- package/src/style-spec/expression/definitions/coercion.js +133 -0
- package/src/style-spec/expression/definitions/collator.js +78 -0
- package/src/style-spec/expression/definitions/comparison.js +184 -0
- package/src/style-spec/expression/definitions/format.js +144 -0
- package/src/style-spec/expression/definitions/image.js +52 -0
- package/src/style-spec/expression/definitions/in.js +72 -0
- package/src/style-spec/expression/definitions/index.js +565 -0
- package/src/style-spec/expression/definitions/index_of.js +89 -0
- package/src/style-spec/expression/definitions/interpolate.js +267 -0
- package/src/style-spec/expression/definitions/length.js +61 -0
- package/src/style-spec/expression/definitions/let.js +72 -0
- package/src/style-spec/expression/definitions/literal.js +77 -0
- package/src/style-spec/expression/definitions/match.js +158 -0
- package/src/style-spec/expression/definitions/number_format.js +142 -0
- package/src/style-spec/expression/definitions/slice.js +86 -0
- package/src/style-spec/expression/definitions/step.js +120 -0
- package/src/style-spec/expression/definitions/var.js +46 -0
- package/src/style-spec/expression/definitions/within.js +342 -0
- package/src/style-spec/expression/evaluation_context.js +59 -0
- package/src/style-spec/expression/expression.js +27 -0
- package/src/style-spec/expression/index.js +392 -0
- package/src/style-spec/expression/is_constant.js +59 -0
- package/src/style-spec/expression/parsing_context.js +233 -0
- package/src/style-spec/expression/parsing_error.js +13 -0
- package/src/style-spec/expression/runtime_error.js +17 -0
- package/src/style-spec/expression/scope.js +36 -0
- package/src/style-spec/expression/stops.js +39 -0
- package/src/style-spec/expression/types/collator.js +61 -0
- package/src/style-spec/expression/types/formatted.js +73 -0
- package/src/style-spec/expression/types/resolved_image.js +29 -0
- package/src/style-spec/expression/types.js +126 -0
- package/src/style-spec/expression/values.js +123 -0
- package/src/style-spec/feature_filter/README.md +55 -0
- package/src/style-spec/feature_filter/convert.js +208 -0
- package/src/style-spec/feature_filter/index.js +175 -0
- package/src/style-spec/format.js +51 -0
- package/src/style-spec/function/convert.js +270 -0
- package/src/style-spec/function/index.js +262 -0
- package/src/style-spec/group_by_layout.js +75 -0
- package/src/style-spec/migrate/expressions.js +39 -0
- package/src/style-spec/migrate/v8.js +203 -0
- package/src/style-spec/migrate/v9.js +26 -0
- package/src/style-spec/migrate.js +36 -0
- package/src/style-spec/package.json +41 -0
- package/src/style-spec/read_style.js +14 -0
- package/src/style-spec/reference/latest.js +3 -0
- package/src/style-spec/reference/v8.json +5914 -0
- package/src/style-spec/rollup.config.js +65 -0
- package/src/style-spec/style-spec.js +124 -0
- package/src/style-spec/types.js +432 -0
- package/src/style-spec/util/color.js +95 -0
- package/src/style-spec/util/color_spaces.js +139 -0
- package/src/style-spec/util/deep_equal.js +28 -0
- package/src/style-spec/util/extend.js +10 -0
- package/src/style-spec/util/get_type.js +17 -0
- package/src/style-spec/util/interpolate.js +22 -0
- package/src/style-spec/util/properties.js +15 -0
- package/src/style-spec/util/ref_properties.js +2 -0
- package/src/style-spec/util/result.js +19 -0
- package/src/style-spec/util/unbundle_jsonlint.js +24 -0
- package/src/style-spec/validate/latest.js +11 -0
- package/src/style-spec/validate/validate.js +75 -0
- package/src/style-spec/validate/validate_array.js +52 -0
- package/src/style-spec/validate/validate_boolean.js +15 -0
- package/src/style-spec/validate/validate_color.js +20 -0
- package/src/style-spec/validate/validate_constants.js +13 -0
- package/src/style-spec/validate/validate_enum.js +21 -0
- package/src/style-spec/validate/validate_expression.js +43 -0
- package/src/style-spec/validate/validate_filter.js +117 -0
- package/src/style-spec/validate/validate_formatted.js +11 -0
- package/src/style-spec/validate/validate_function.js +207 -0
- package/src/style-spec/validate/validate_glyphs_url.js +21 -0
- package/src/style-spec/validate/validate_image.js +11 -0
- package/src/style-spec/validate/validate_layer.js +134 -0
- package/src/style-spec/validate/validate_layout_property.js +6 -0
- package/src/style-spec/validate/validate_light.js +47 -0
- package/src/style-spec/validate/validate_number.js +29 -0
- package/src/style-spec/validate/validate_object.js +61 -0
- package/src/style-spec/validate/validate_paint_property.js +6 -0
- package/src/style-spec/validate/validate_property.js +64 -0
- package/src/style-spec/validate/validate_source.js +111 -0
- package/src/style-spec/validate/validate_string.js +15 -0
- package/src/style-spec/validate_mapbox_api_supported.js +171 -0
- package/src/style-spec/validate_style.js +39 -0
- package/src/style-spec/validate_style.min.js +78 -0
- package/src/style-spec/visit.js +77 -0
- package/src/symbol/anchor.js +26 -0
- package/src/symbol/check_max_angle.js +81 -0
- package/src/symbol/clip_line.js +71 -0
- package/src/symbol/collision_feature.js +109 -0
- package/src/symbol/collision_index.js +373 -0
- package/src/symbol/cross_tile_symbol_index.js +301 -0
- package/src/symbol/get_anchors.js +167 -0
- package/src/symbol/grid_index.js +335 -0
- package/src/symbol/mergelines.js +82 -0
- package/src/symbol/one_em.js +4 -0
- package/src/symbol/opacity_state.js +27 -0
- package/src/symbol/path_interpolator.js +61 -0
- package/src/symbol/placement.js +1124 -0
- package/src/symbol/projection.js +451 -0
- package/src/symbol/quads.js +334 -0
- package/src/symbol/shaping.js +816 -0
- package/src/symbol/symbol_layout.js +796 -0
- package/src/symbol/symbol_size.js +113 -0
- package/src/symbol/transform_text.js +29 -0
- package/src/types/callback.js +17 -0
- package/src/types/cancelable.js +3 -0
- package/src/types/tilejson.js +17 -0
- package/src/types/transferable.js +3 -0
- package/src/types/window.js +172 -0
- package/src/ui/anchor.js +32 -0
- package/src/ui/camera.js +1277 -0
- package/src/ui/control/attribution_control.js +212 -0
- package/src/ui/control/fullscreen_control.js +147 -0
- package/src/ui/control/geolocate_control.js +707 -0
- package/src/ui/control/logo_control.js +92 -0
- package/src/ui/control/navigation_control.js +257 -0
- package/src/ui/control/scale_control.js +142 -0
- package/src/ui/default_locale.js +22 -0
- package/src/ui/events.js +1301 -0
- package/src/ui/handler/box_zoom.js +170 -0
- package/src/ui/handler/click_zoom.js +52 -0
- package/src/ui/handler/handler_util.js +12 -0
- package/src/ui/handler/keyboard.js +208 -0
- package/src/ui/handler/map_event.js +156 -0
- package/src/ui/handler/mouse.js +171 -0
- package/src/ui/handler/scroll_zoom.js +350 -0
- package/src/ui/handler/shim/dblclick_zoom.js +62 -0
- package/src/ui/handler/shim/drag_pan.js +88 -0
- package/src/ui/handler/shim/drag_rotate.js +67 -0
- package/src/ui/handler/shim/touch_zoom_rotate.js +108 -0
- package/src/ui/handler/tap_drag_zoom.js +103 -0
- package/src/ui/handler/tap_recognizer.js +133 -0
- package/src/ui/handler/tap_zoom.js +93 -0
- package/src/ui/handler/touch_pan.js +101 -0
- package/src/ui/handler/touch_zoom_rotate.js +305 -0
- package/src/ui/handler_inertia.js +158 -0
- package/src/ui/handler_manager.js +531 -0
- package/src/ui/hash.js +148 -0
- package/src/ui/map.js +2874 -0
- package/src/ui/marker.js +672 -0
- package/src/ui/popup.js +640 -0
- package/src/util/actor.js +212 -0
- package/src/util/ajax.js +388 -0
- package/src/util/browser/web_worker.js +10 -0
- package/src/util/browser/window.js +6 -0
- package/src/util/browser.js +70 -0
- package/src/util/classify_rings.js +52 -0
- package/src/util/color_ramp.js +61 -0
- package/src/util/config.js +30 -0
- package/src/util/debug.js +28 -0
- package/src/util/dictionary_coder.js +30 -0
- package/src/util/dispatcher.js +70 -0
- package/src/util/dom.js +142 -0
- package/src/util/evented.js +174 -0
- package/src/util/find_pole_of_inaccessibility.js +129 -0
- package/src/util/global_worker_pool.js +35 -0
- package/src/util/image.js +142 -0
- package/src/util/intersection_tests.js +208 -0
- package/src/util/is_char_in_unicode_block.js +311 -0
- package/src/util/mapbox.js +491 -0
- package/src/util/offscreen_canvas_supported.js +14 -0
- package/src/util/performance.js +112 -0
- package/src/util/primitives.js +145 -0
- package/src/util/resolve_tokens.js +16 -0
- package/src/util/script_detection.js +328 -0
- package/src/util/sku_token.js +42 -0
- package/src/util/smart_wrap.js +55 -0
- package/src/util/struct_array.js +243 -0
- package/src/util/struct_array.js.ejs +112 -0
- package/src/util/struct_array_layout.js.ejs +98 -0
- package/src/util/task_queue.js +68 -0
- package/src/util/throttle.js +27 -0
- package/src/util/throttled_invoker.js +46 -0
- package/src/util/tile_request_cache.js +172 -0
- package/src/util/util.js +524 -0
- package/src/util/vectortile_to_geojson.js +50 -0
- package/src/util/verticalize_punctuation.js +114 -0
- package/src/util/web_worker.js +91 -0
- package/src/util/web_worker_transfer.js +266 -0
- package/src/util/webp_supported.js +69 -0
- package/src/util/window.js +102 -0
- package/src/util/worker_pool.js +57 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import Point from '@mapbox/point-geometry';
|
|
4
|
+
|
|
5
|
+
export default clipLine;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns the part of a multiline that intersects with the provided rectangular box.
|
|
9
|
+
*
|
|
10
|
+
* @param lines
|
|
11
|
+
* @param x1 the left edge of the box
|
|
12
|
+
* @param y1 the top edge of the box
|
|
13
|
+
* @param x2 the right edge of the box
|
|
14
|
+
* @param y2 the bottom edge of the box
|
|
15
|
+
* @returns lines
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
function clipLine(lines: Array<Array<Point>>, x1: number, y1: number, x2: number, y2: number): Array<Array<Point>> {
|
|
19
|
+
const clippedLines = [];
|
|
20
|
+
|
|
21
|
+
for (let l = 0; l < lines.length; l++) {
|
|
22
|
+
const line = lines[l];
|
|
23
|
+
let clippedLine;
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < line.length - 1; i++) {
|
|
26
|
+
let p0 = line[i];
|
|
27
|
+
let p1 = line[i + 1];
|
|
28
|
+
|
|
29
|
+
if (p0.x < x1 && p1.x < x1) {
|
|
30
|
+
continue;
|
|
31
|
+
} else if (p0.x < x1) {
|
|
32
|
+
p0 = new Point(x1, p0.y + (p1.y - p0.y) * ((x1 - p0.x) / (p1.x - p0.x)))._round();
|
|
33
|
+
} else if (p1.x < x1) {
|
|
34
|
+
p1 = new Point(x1, p0.y + (p1.y - p0.y) * ((x1 - p0.x) / (p1.x - p0.x)))._round();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (p0.y < y1 && p1.y < y1) {
|
|
38
|
+
continue;
|
|
39
|
+
} else if (p0.y < y1) {
|
|
40
|
+
p0 = new Point(p0.x + (p1.x - p0.x) * ((y1 - p0.y) / (p1.y - p0.y)), y1)._round();
|
|
41
|
+
} else if (p1.y < y1) {
|
|
42
|
+
p1 = new Point(p0.x + (p1.x - p0.x) * ((y1 - p0.y) / (p1.y - p0.y)), y1)._round();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (p0.x >= x2 && p1.x >= x2) {
|
|
46
|
+
continue;
|
|
47
|
+
} else if (p0.x >= x2) {
|
|
48
|
+
p0 = new Point(x2, p0.y + (p1.y - p0.y) * ((x2 - p0.x) / (p1.x - p0.x)))._round();
|
|
49
|
+
} else if (p1.x >= x2) {
|
|
50
|
+
p1 = new Point(x2, p0.y + (p1.y - p0.y) * ((x2 - p0.x) / (p1.x - p0.x)))._round();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (p0.y >= y2 && p1.y >= y2) {
|
|
54
|
+
continue;
|
|
55
|
+
} else if (p0.y >= y2) {
|
|
56
|
+
p0 = new Point(p0.x + (p1.x - p0.x) * ((y2 - p0.y) / (p1.y - p0.y)), y2)._round();
|
|
57
|
+
} else if (p1.y >= y2) {
|
|
58
|
+
p1 = new Point(p0.x + (p1.x - p0.x) * ((y2 - p0.y) / (p1.y - p0.y)), y2)._round();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!clippedLine || !p0.equals(clippedLine[clippedLine.length - 1])) {
|
|
62
|
+
clippedLine = [p0];
|
|
63
|
+
clippedLines.push(clippedLine);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
clippedLine.push(p1);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return clippedLines;
|
|
71
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import type {CollisionBoxArray} from '../data/array_types';
|
|
4
|
+
import Point from '@mapbox/point-geometry';
|
|
5
|
+
import type Anchor from './anchor';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A CollisionFeature represents the area of the tile covered by a single label.
|
|
9
|
+
* It is used with CollisionIndex to check if the label overlaps with any
|
|
10
|
+
* previous labels. A CollisionFeature is mostly just a set of CollisionBox
|
|
11
|
+
* objects.
|
|
12
|
+
*
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
class CollisionFeature {
|
|
16
|
+
boxStartIndex: number;
|
|
17
|
+
boxEndIndex: number;
|
|
18
|
+
circleDiameter: ?number;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Create a CollisionFeature, adding its collision box data to the given collisionBoxArray in the process.
|
|
22
|
+
* For line aligned labels a collision circle diameter is computed instead.
|
|
23
|
+
*
|
|
24
|
+
* @param anchor The point along the line around which the label is anchored.
|
|
25
|
+
* @param shaped The text or icon shaping results.
|
|
26
|
+
* @param boxScale A magic number used to convert from glyph metrics units to geometry units.
|
|
27
|
+
* @param padding The amount of padding to add around the label edges.
|
|
28
|
+
* @param alignLine Whether the label is aligned with the line or the viewport.
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
constructor(collisionBoxArray: CollisionBoxArray,
|
|
32
|
+
anchor: Anchor,
|
|
33
|
+
featureIndex: number,
|
|
34
|
+
sourceLayerIndex: number,
|
|
35
|
+
bucketIndex: number,
|
|
36
|
+
shaped: Object,
|
|
37
|
+
boxScale: number,
|
|
38
|
+
padding: number,
|
|
39
|
+
alignLine: boolean,
|
|
40
|
+
rotate: number) {
|
|
41
|
+
|
|
42
|
+
this.boxStartIndex = collisionBoxArray.length;
|
|
43
|
+
|
|
44
|
+
if (alignLine) {
|
|
45
|
+
// Compute height of the shape in glyph metrics and apply collision padding.
|
|
46
|
+
// Note that the pixel based 'text-padding' is applied at runtime
|
|
47
|
+
let top = shaped.top;
|
|
48
|
+
let bottom = shaped.bottom;
|
|
49
|
+
const collisionPadding = shaped.collisionPadding;
|
|
50
|
+
|
|
51
|
+
if (collisionPadding) {
|
|
52
|
+
top -= collisionPadding[1];
|
|
53
|
+
bottom += collisionPadding[3];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let height = bottom - top;
|
|
57
|
+
|
|
58
|
+
if (height > 0) {
|
|
59
|
+
// set minimum box height to avoid very many small labels
|
|
60
|
+
height = Math.max(10, height);
|
|
61
|
+
this.circleDiameter = height;
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
let y1 = shaped.top * boxScale - padding;
|
|
65
|
+
let y2 = shaped.bottom * boxScale + padding;
|
|
66
|
+
let x1 = shaped.left * boxScale - padding;
|
|
67
|
+
let x2 = shaped.right * boxScale + padding;
|
|
68
|
+
|
|
69
|
+
const collisionPadding = shaped.collisionPadding;
|
|
70
|
+
if (collisionPadding) {
|
|
71
|
+
x1 -= collisionPadding[0] * boxScale;
|
|
72
|
+
y1 -= collisionPadding[1] * boxScale;
|
|
73
|
+
x2 += collisionPadding[2] * boxScale;
|
|
74
|
+
y2 += collisionPadding[3] * boxScale;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (rotate) {
|
|
78
|
+
// Account for *-rotate in point collision boxes
|
|
79
|
+
// See https://github.com/mapbox/mapbox-gl-js/issues/6075
|
|
80
|
+
// Doesn't account for icon-text-fit
|
|
81
|
+
|
|
82
|
+
const tl = new Point(x1, y1);
|
|
83
|
+
const tr = new Point(x2, y1);
|
|
84
|
+
const bl = new Point(x1, y2);
|
|
85
|
+
const br = new Point(x2, y2);
|
|
86
|
+
|
|
87
|
+
const rotateRadians = rotate * Math.PI / 180;
|
|
88
|
+
|
|
89
|
+
tl._rotate(rotateRadians);
|
|
90
|
+
tr._rotate(rotateRadians);
|
|
91
|
+
bl._rotate(rotateRadians);
|
|
92
|
+
br._rotate(rotateRadians);
|
|
93
|
+
|
|
94
|
+
// Collision features require an "on-axis" geometry,
|
|
95
|
+
// so take the envelope of the rotated geometry
|
|
96
|
+
// (may be quite large for wide labels rotated 45 degrees)
|
|
97
|
+
x1 = Math.min(tl.x, tr.x, bl.x, br.x);
|
|
98
|
+
x2 = Math.max(tl.x, tr.x, bl.x, br.x);
|
|
99
|
+
y1 = Math.min(tl.y, tr.y, bl.y, br.y);
|
|
100
|
+
y2 = Math.max(tl.y, tr.y, bl.y, br.y);
|
|
101
|
+
}
|
|
102
|
+
collisionBoxArray.emplaceBack(anchor.x, anchor.y, x1, y1, x2, y2, featureIndex, sourceLayerIndex, bucketIndex);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
this.boxEndIndex = collisionBoxArray.length;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export default CollisionFeature;
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import Point from '@mapbox/point-geometry';
|
|
4
|
+
import clipLine from './clip_line';
|
|
5
|
+
import PathInterpolator from './path_interpolator';
|
|
6
|
+
|
|
7
|
+
import * as intersectionTests from '../util/intersection_tests';
|
|
8
|
+
import Grid from './grid_index';
|
|
9
|
+
import {mat4} from 'gl-matrix';
|
|
10
|
+
import ONE_EM from '../symbol/one_em';
|
|
11
|
+
import assert from 'assert';
|
|
12
|
+
|
|
13
|
+
import * as projection from '../symbol/projection';
|
|
14
|
+
|
|
15
|
+
import type Transform from '../geo/transform';
|
|
16
|
+
import type {SingleCollisionBox} from '../data/bucket/symbol_bucket';
|
|
17
|
+
import type {
|
|
18
|
+
GlyphOffsetArray,
|
|
19
|
+
SymbolLineVertexArray
|
|
20
|
+
} from '../data/array_types';
|
|
21
|
+
|
|
22
|
+
// When a symbol crosses the edge that causes it to be included in
|
|
23
|
+
// collision detection, it will cause changes in the symbols around
|
|
24
|
+
// it. This constant specifies how many pixels to pad the edge of
|
|
25
|
+
// the viewport for collision detection so that the bulk of the changes
|
|
26
|
+
// occur offscreen. Making this constant greater increases label
|
|
27
|
+
// stability, but it's expensive.
|
|
28
|
+
const viewportPadding = 100;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A collision index used to prevent symbols from overlapping. It keep tracks of
|
|
32
|
+
* where previous symbols have been placed and is used to check if a new
|
|
33
|
+
* symbol overlaps with any previously added symbols.
|
|
34
|
+
*
|
|
35
|
+
* There are two steps to insertion: first placeCollisionBox/Circles checks if
|
|
36
|
+
* there's room for a symbol, then insertCollisionBox/Circles actually puts the
|
|
37
|
+
* symbol in the index. The two step process allows paired symbols to be inserted
|
|
38
|
+
* together even if they overlap.
|
|
39
|
+
*
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
class CollisionIndex {
|
|
43
|
+
grid: Grid;
|
|
44
|
+
ignoredGrid: Grid;
|
|
45
|
+
transform: Transform;
|
|
46
|
+
pitchfactor: number;
|
|
47
|
+
screenRightBoundary: number;
|
|
48
|
+
screenBottomBoundary: number;
|
|
49
|
+
gridRightBoundary: number;
|
|
50
|
+
gridBottomBoundary: number;
|
|
51
|
+
|
|
52
|
+
constructor(
|
|
53
|
+
transform: Transform,
|
|
54
|
+
grid: Grid = new Grid(transform.width + 2 * viewportPadding, transform.height + 2 * viewportPadding, 25),
|
|
55
|
+
ignoredGrid: Grid = new Grid(transform.width + 2 * viewportPadding, transform.height + 2 * viewportPadding, 25)
|
|
56
|
+
) {
|
|
57
|
+
this.transform = transform;
|
|
58
|
+
|
|
59
|
+
this.grid = grid;
|
|
60
|
+
this.ignoredGrid = ignoredGrid;
|
|
61
|
+
this.pitchfactor = Math.cos(transform._pitch) * transform.cameraToCenterDistance;
|
|
62
|
+
|
|
63
|
+
this.screenRightBoundary = transform.width + viewportPadding;
|
|
64
|
+
this.screenBottomBoundary = transform.height + viewportPadding;
|
|
65
|
+
this.gridRightBoundary = transform.width + 2 * viewportPadding;
|
|
66
|
+
this.gridBottomBoundary = transform.height + 2 * viewportPadding;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
placeCollisionBox(collisionBox: SingleCollisionBox, allowOverlap: boolean, textPixelRatio: number, posMatrix: mat4, collisionGroupPredicate?: any): { box: Array<number>, offscreen: boolean } {
|
|
70
|
+
const projectedPoint = this.projectAndGetPerspectiveRatio(posMatrix, collisionBox.anchorPointX, collisionBox.anchorPointY);
|
|
71
|
+
const tileToViewport = textPixelRatio * projectedPoint.perspectiveRatio;
|
|
72
|
+
const tlX = collisionBox.x1 * tileToViewport + projectedPoint.point.x;
|
|
73
|
+
const tlY = collisionBox.y1 * tileToViewport + projectedPoint.point.y;
|
|
74
|
+
const brX = collisionBox.x2 * tileToViewport + projectedPoint.point.x;
|
|
75
|
+
const brY = collisionBox.y2 * tileToViewport + projectedPoint.point.y;
|
|
76
|
+
|
|
77
|
+
if (!this.isInsideGrid(tlX, tlY, brX, brY) ||
|
|
78
|
+
(!allowOverlap && this.grid.hitTest(tlX, tlY, brX, brY, collisionGroupPredicate))) {
|
|
79
|
+
return {
|
|
80
|
+
box: [],
|
|
81
|
+
offscreen: false
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
box: [tlX, tlY, brX, brY],
|
|
87
|
+
offscreen: this.isOffscreen(tlX, tlY, brX, brY)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
placeCollisionCircles(allowOverlap: boolean,
|
|
92
|
+
symbol: any,
|
|
93
|
+
lineVertexArray: SymbolLineVertexArray,
|
|
94
|
+
glyphOffsetArray: GlyphOffsetArray,
|
|
95
|
+
fontSize: number,
|
|
96
|
+
posMatrix: mat4,
|
|
97
|
+
labelPlaneMatrix: mat4,
|
|
98
|
+
labelToScreenMatrix?: mat4,
|
|
99
|
+
showCollisionCircles: boolean,
|
|
100
|
+
pitchWithMap: boolean,
|
|
101
|
+
collisionGroupPredicate?: any,
|
|
102
|
+
circlePixelDiameter: number,
|
|
103
|
+
textPixelPadding: number): { circles: Array<number>, offscreen: boolean, collisionDetected: boolean } {
|
|
104
|
+
const placedCollisionCircles = [];
|
|
105
|
+
|
|
106
|
+
const tileUnitAnchorPoint = new Point(symbol.anchorX, symbol.anchorY);
|
|
107
|
+
const screenAnchorPoint = projection.project(tileUnitAnchorPoint, posMatrix);
|
|
108
|
+
const perspectiveRatio = projection.getPerspectiveRatio(this.transform.cameraToCenterDistance, screenAnchorPoint.signedDistanceFromCamera);
|
|
109
|
+
const labelPlaneFontSize = pitchWithMap ? fontSize / perspectiveRatio : fontSize * perspectiveRatio;
|
|
110
|
+
const labelPlaneFontScale = labelPlaneFontSize / ONE_EM;
|
|
111
|
+
|
|
112
|
+
const labelPlaneAnchorPoint = projection.project(tileUnitAnchorPoint, labelPlaneMatrix).point;
|
|
113
|
+
|
|
114
|
+
const projectionCache = {};
|
|
115
|
+
const lineOffsetX = symbol.lineOffsetX * labelPlaneFontScale;
|
|
116
|
+
const lineOffsetY = symbol.lineOffsetY * labelPlaneFontScale;
|
|
117
|
+
|
|
118
|
+
const firstAndLastGlyph = projection.placeFirstAndLastGlyph(
|
|
119
|
+
labelPlaneFontScale,
|
|
120
|
+
glyphOffsetArray,
|
|
121
|
+
lineOffsetX,
|
|
122
|
+
lineOffsetY,
|
|
123
|
+
/*flip*/ false,
|
|
124
|
+
labelPlaneAnchorPoint,
|
|
125
|
+
tileUnitAnchorPoint,
|
|
126
|
+
symbol,
|
|
127
|
+
lineVertexArray,
|
|
128
|
+
labelPlaneMatrix,
|
|
129
|
+
projectionCache);
|
|
130
|
+
|
|
131
|
+
let collisionDetected = false;
|
|
132
|
+
let inGrid = false;
|
|
133
|
+
let entirelyOffscreen = true;
|
|
134
|
+
|
|
135
|
+
if (firstAndLastGlyph) {
|
|
136
|
+
const radius = circlePixelDiameter * 0.5 * perspectiveRatio + textPixelPadding;
|
|
137
|
+
const screenPlaneMin = new Point(-viewportPadding, -viewportPadding);
|
|
138
|
+
const screenPlaneMax = new Point(this.screenRightBoundary, this.screenBottomBoundary);
|
|
139
|
+
const interpolator = new PathInterpolator();
|
|
140
|
+
|
|
141
|
+
// Construct a projected path from projected line vertices. Anchor points are ignored and removed
|
|
142
|
+
const first = firstAndLastGlyph.first;
|
|
143
|
+
const last = firstAndLastGlyph.last;
|
|
144
|
+
|
|
145
|
+
let projectedPath = [];
|
|
146
|
+
for (let i = first.path.length - 1; i >= 1; i--) {
|
|
147
|
+
projectedPath.push(first.path[i]);
|
|
148
|
+
}
|
|
149
|
+
for (let i = 1; i < last.path.length; i++) {
|
|
150
|
+
projectedPath.push(last.path[i]);
|
|
151
|
+
}
|
|
152
|
+
assert(projectedPath.length >= 2);
|
|
153
|
+
|
|
154
|
+
// Tolerate a slightly longer distance than one diameter between two adjacent circles
|
|
155
|
+
const circleDist = radius * 2.5;
|
|
156
|
+
|
|
157
|
+
// The path might need to be converted into screen space if a pitched map is used as the label space
|
|
158
|
+
if (labelToScreenMatrix) {
|
|
159
|
+
const screenSpacePath = projectedPath.map(p => projection.project(p, labelToScreenMatrix));
|
|
160
|
+
|
|
161
|
+
// Do not try to place collision circles if even of the points is behind the camera.
|
|
162
|
+
// This is a plausible scenario with big camera pitch angles
|
|
163
|
+
if (screenSpacePath.some(point => point.signedDistanceFromCamera <= 0)) {
|
|
164
|
+
projectedPath = [];
|
|
165
|
+
} else {
|
|
166
|
+
projectedPath = screenSpacePath.map(p => p.point);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
let segments = [];
|
|
171
|
+
|
|
172
|
+
if (projectedPath.length > 0) {
|
|
173
|
+
// Quickly check if the path is fully inside or outside of the padded collision region.
|
|
174
|
+
// For overlapping paths we'll only create collision circles for the visible segments
|
|
175
|
+
const minPoint = projectedPath[0].clone();
|
|
176
|
+
const maxPoint = projectedPath[0].clone();
|
|
177
|
+
|
|
178
|
+
for (let i = 1; i < projectedPath.length; i++) {
|
|
179
|
+
minPoint.x = Math.min(minPoint.x, projectedPath[i].x);
|
|
180
|
+
minPoint.y = Math.min(minPoint.y, projectedPath[i].y);
|
|
181
|
+
maxPoint.x = Math.max(maxPoint.x, projectedPath[i].x);
|
|
182
|
+
maxPoint.y = Math.max(maxPoint.y, projectedPath[i].y);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (minPoint.x >= screenPlaneMin.x && maxPoint.x <= screenPlaneMax.x &&
|
|
186
|
+
minPoint.y >= screenPlaneMin.y && maxPoint.y <= screenPlaneMax.y) {
|
|
187
|
+
// Quad fully visible
|
|
188
|
+
segments = [projectedPath];
|
|
189
|
+
} else if (maxPoint.x < screenPlaneMin.x || minPoint.x > screenPlaneMax.x ||
|
|
190
|
+
maxPoint.y < screenPlaneMin.y || minPoint.y > screenPlaneMax.y) {
|
|
191
|
+
// Not visible
|
|
192
|
+
segments = [];
|
|
193
|
+
} else {
|
|
194
|
+
segments = clipLine([projectedPath], screenPlaneMin.x, screenPlaneMin.y, screenPlaneMax.x, screenPlaneMax.y);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
for (const seg of segments) {
|
|
199
|
+
// interpolate positions for collision circles. Add a small padding to both ends of the segment
|
|
200
|
+
assert(seg.length > 0);
|
|
201
|
+
interpolator.reset(seg, radius * 0.25);
|
|
202
|
+
|
|
203
|
+
let numCircles = 0;
|
|
204
|
+
|
|
205
|
+
if (interpolator.length <= 0.5 * radius) {
|
|
206
|
+
numCircles = 1;
|
|
207
|
+
} else {
|
|
208
|
+
numCircles = Math.ceil(interpolator.paddedLength / circleDist) + 1;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
for (let i = 0; i < numCircles; i++) {
|
|
212
|
+
const t = i / Math.max(numCircles - 1, 1);
|
|
213
|
+
const circlePosition = interpolator.lerp(t);
|
|
214
|
+
|
|
215
|
+
// add viewport padding to the position and perform initial collision check
|
|
216
|
+
const centerX = circlePosition.x + viewportPadding;
|
|
217
|
+
const centerY = circlePosition.y + viewportPadding;
|
|
218
|
+
|
|
219
|
+
placedCollisionCircles.push(centerX, centerY, radius, 0);
|
|
220
|
+
|
|
221
|
+
const x1 = centerX - radius;
|
|
222
|
+
const y1 = centerY - radius;
|
|
223
|
+
const x2 = centerX + radius;
|
|
224
|
+
const y2 = centerY + radius;
|
|
225
|
+
|
|
226
|
+
entirelyOffscreen = entirelyOffscreen && this.isOffscreen(x1, y1, x2, y2);
|
|
227
|
+
inGrid = inGrid || this.isInsideGrid(x1, y1, x2, y2);
|
|
228
|
+
|
|
229
|
+
if (!allowOverlap) {
|
|
230
|
+
if (this.grid.hitTestCircle(centerX, centerY, radius, collisionGroupPredicate)) {
|
|
231
|
+
// Don't early exit if we're showing the debug circles because we still want to calculate
|
|
232
|
+
// which circles are in use
|
|
233
|
+
collisionDetected = true;
|
|
234
|
+
if (!showCollisionCircles) {
|
|
235
|
+
return {
|
|
236
|
+
circles: [],
|
|
237
|
+
offscreen: false,
|
|
238
|
+
collisionDetected
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
circles: ((!showCollisionCircles && collisionDetected) || !inGrid) ? [] : placedCollisionCircles,
|
|
249
|
+
offscreen: entirelyOffscreen,
|
|
250
|
+
collisionDetected
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Because the geometries in the CollisionIndex are an approximation of the shape of
|
|
256
|
+
* symbols on the map, we use the CollisionIndex to look up the symbol part of
|
|
257
|
+
* `queryRenderedFeatures`.
|
|
258
|
+
*
|
|
259
|
+
* @private
|
|
260
|
+
*/
|
|
261
|
+
queryRenderedSymbols(viewportQueryGeometry: Array<Point>) {
|
|
262
|
+
if (viewportQueryGeometry.length === 0 || (this.grid.keysLength() === 0 && this.ignoredGrid.keysLength() === 0)) {
|
|
263
|
+
return {};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const query = [];
|
|
267
|
+
let minX = Infinity;
|
|
268
|
+
let minY = Infinity;
|
|
269
|
+
let maxX = -Infinity;
|
|
270
|
+
let maxY = -Infinity;
|
|
271
|
+
for (const point of viewportQueryGeometry) {
|
|
272
|
+
const gridPoint = new Point(point.x + viewportPadding, point.y + viewportPadding);
|
|
273
|
+
minX = Math.min(minX, gridPoint.x);
|
|
274
|
+
minY = Math.min(minY, gridPoint.y);
|
|
275
|
+
maxX = Math.max(maxX, gridPoint.x);
|
|
276
|
+
maxY = Math.max(maxY, gridPoint.y);
|
|
277
|
+
query.push(gridPoint);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const features = this.grid.query(minX, minY, maxX, maxY)
|
|
281
|
+
.concat(this.ignoredGrid.query(minX, minY, maxX, maxY));
|
|
282
|
+
|
|
283
|
+
const seenFeatures = {};
|
|
284
|
+
const result = {};
|
|
285
|
+
|
|
286
|
+
for (const feature of features) {
|
|
287
|
+
const featureKey = feature.key;
|
|
288
|
+
// Skip already seen features.
|
|
289
|
+
if (seenFeatures[featureKey.bucketInstanceId] === undefined) {
|
|
290
|
+
seenFeatures[featureKey.bucketInstanceId] = {};
|
|
291
|
+
}
|
|
292
|
+
if (seenFeatures[featureKey.bucketInstanceId][featureKey.featureIndex]) {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Check if query intersects with the feature box
|
|
297
|
+
// "Collision Circles" for line labels are treated as boxes here
|
|
298
|
+
// Since there's no actual collision taking place, the circle vs. square
|
|
299
|
+
// distinction doesn't matter as much, and box geometry is easier
|
|
300
|
+
// to work with.
|
|
301
|
+
const bbox = [
|
|
302
|
+
new Point(feature.x1, feature.y1),
|
|
303
|
+
new Point(feature.x2, feature.y1),
|
|
304
|
+
new Point(feature.x2, feature.y2),
|
|
305
|
+
new Point(feature.x1, feature.y2)
|
|
306
|
+
];
|
|
307
|
+
if (!intersectionTests.polygonIntersectsPolygon(query, bbox)) {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
seenFeatures[featureKey.bucketInstanceId][featureKey.featureIndex] = true;
|
|
312
|
+
if (result[featureKey.bucketInstanceId] === undefined) {
|
|
313
|
+
result[featureKey.bucketInstanceId] = [];
|
|
314
|
+
}
|
|
315
|
+
result[featureKey.bucketInstanceId].push(featureKey.featureIndex);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return result;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
insertCollisionBox(collisionBox: Array<number>, ignorePlacement: boolean, bucketInstanceId: number, featureIndex: number, collisionGroupID: number) {
|
|
322
|
+
const grid = ignorePlacement ? this.ignoredGrid : this.grid;
|
|
323
|
+
|
|
324
|
+
const key = {bucketInstanceId, featureIndex, collisionGroupID};
|
|
325
|
+
grid.insert(key, collisionBox[0], collisionBox[1], collisionBox[2], collisionBox[3]);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
insertCollisionCircles(collisionCircles: Array<number>, ignorePlacement: boolean, bucketInstanceId: number, featureIndex: number, collisionGroupID: number) {
|
|
329
|
+
const grid = ignorePlacement ? this.ignoredGrid : this.grid;
|
|
330
|
+
|
|
331
|
+
const key = {bucketInstanceId, featureIndex, collisionGroupID};
|
|
332
|
+
for (let k = 0; k < collisionCircles.length; k += 4) {
|
|
333
|
+
grid.insertCircle(key, collisionCircles[k], collisionCircles[k + 1], collisionCircles[k + 2]);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
projectAndGetPerspectiveRatio(posMatrix: mat4, x: number, y: number) {
|
|
338
|
+
const p = [x, y, 0, 1];
|
|
339
|
+
projection.xyTransformMat4(p, p, posMatrix);
|
|
340
|
+
const a = new Point(
|
|
341
|
+
(((p[0] / p[3] + 1) / 2) * this.transform.width) + viewportPadding,
|
|
342
|
+
(((-p[1] / p[3] + 1) / 2) * this.transform.height) + viewportPadding
|
|
343
|
+
);
|
|
344
|
+
return {
|
|
345
|
+
point: a,
|
|
346
|
+
// See perspective ratio comment in symbol_sdf.vertex
|
|
347
|
+
// We're doing collision detection in viewport space so we need
|
|
348
|
+
// to scale down boxes in the distance
|
|
349
|
+
perspectiveRatio: 0.5 + 0.5 * (this.transform.cameraToCenterDistance / p[3])
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
isOffscreen(x1: number, y1: number, x2: number, y2: number) {
|
|
354
|
+
return x2 < viewportPadding || x1 >= this.screenRightBoundary || y2 < viewportPadding || y1 > this.screenBottomBoundary;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
isInsideGrid(x1: number, y1: number, x2: number, y2: number) {
|
|
358
|
+
return x2 >= 0 && x1 < this.gridRightBoundary && y2 >= 0 && y1 < this.gridBottomBoundary;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/*
|
|
362
|
+
* Returns a matrix for transforming collision shapes to viewport coordinate space.
|
|
363
|
+
* Use this function to render e.g. collision circles on the screen.
|
|
364
|
+
* example transformation: clipPos = glCoordMatrix * viewportMatrix * circle_pos
|
|
365
|
+
*/
|
|
366
|
+
getViewportMatrix(): mat4 {
|
|
367
|
+
const m = mat4.identity([]);
|
|
368
|
+
mat4.translate(m, m, [-viewportPadding, -viewportPadding, 0.0]);
|
|
369
|
+
return m;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export default CollisionIndex;
|