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,129 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import Queue from 'tinyqueue';
|
|
4
|
+
|
|
5
|
+
import Point from '@mapbox/point-geometry';
|
|
6
|
+
import {distToSegmentSquared} from './intersection_tests';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Finds an approximation of a polygon's Pole Of Inaccessibiliy https://en.wikipedia.org/wiki/Pole_of_inaccessibility
|
|
10
|
+
* This is a copy of http://github.com/mapbox/polylabel adapted to use Points
|
|
11
|
+
*
|
|
12
|
+
* @param polygonRings first item in array is the outer ring followed optionally by the list of holes, should be an element of the result of util/classify_rings
|
|
13
|
+
* @param precision Specified in input coordinate units. If 0 returns after first run, if > 0 repeatedly narrows the search space until the radius of the area searched for the best pole is less than precision
|
|
14
|
+
* @param debug Print some statistics to the console during execution
|
|
15
|
+
* @returns Pole of Inaccessibiliy.
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
export default function (polygonRings: Array<Array<Point>>, precision?: number = 1, debug?: boolean = false): Point {
|
|
19
|
+
// find the bounding box of the outer ring
|
|
20
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
21
|
+
const outerRing = polygonRings[0];
|
|
22
|
+
for (let i = 0; i < outerRing.length; i++) {
|
|
23
|
+
const p = outerRing[i];
|
|
24
|
+
if (!i || p.x < minX) minX = p.x;
|
|
25
|
+
if (!i || p.y < minY) minY = p.y;
|
|
26
|
+
if (!i || p.x > maxX) maxX = p.x;
|
|
27
|
+
if (!i || p.y > maxY) maxY = p.y;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const width = maxX - minX;
|
|
31
|
+
const height = maxY - minY;
|
|
32
|
+
const cellSize = Math.min(width, height);
|
|
33
|
+
let h = cellSize / 2;
|
|
34
|
+
|
|
35
|
+
// a priority queue of cells in order of their "potential" (max distance to polygon)
|
|
36
|
+
const cellQueue = new Queue([], compareMax);
|
|
37
|
+
|
|
38
|
+
if (cellSize === 0) return new Point(minX, minY);
|
|
39
|
+
|
|
40
|
+
// cover polygon with initial cells
|
|
41
|
+
for (let x = minX; x < maxX; x += cellSize) {
|
|
42
|
+
for (let y = minY; y < maxY; y += cellSize) {
|
|
43
|
+
cellQueue.push(new Cell(x + h, y + h, h, polygonRings));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// take centroid as the first best guess
|
|
48
|
+
let bestCell = getCentroidCell(polygonRings);
|
|
49
|
+
let numProbes = cellQueue.length;
|
|
50
|
+
|
|
51
|
+
while (cellQueue.length) {
|
|
52
|
+
// pick the most promising cell from the queue
|
|
53
|
+
const cell = cellQueue.pop();
|
|
54
|
+
|
|
55
|
+
// update the best cell if we found a better one
|
|
56
|
+
if (cell.d > bestCell.d || !bestCell.d) {
|
|
57
|
+
bestCell = cell;
|
|
58
|
+
if (debug) console.log('found best %d after %d probes', Math.round(1e4 * cell.d) / 1e4, numProbes);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// do not drill down further if there's no chance of a better solution
|
|
62
|
+
if (cell.max - bestCell.d <= precision) continue;
|
|
63
|
+
|
|
64
|
+
// split the cell into four cells
|
|
65
|
+
h = cell.h / 2;
|
|
66
|
+
cellQueue.push(new Cell(cell.p.x - h, cell.p.y - h, h, polygonRings));
|
|
67
|
+
cellQueue.push(new Cell(cell.p.x + h, cell.p.y - h, h, polygonRings));
|
|
68
|
+
cellQueue.push(new Cell(cell.p.x - h, cell.p.y + h, h, polygonRings));
|
|
69
|
+
cellQueue.push(new Cell(cell.p.x + h, cell.p.y + h, h, polygonRings));
|
|
70
|
+
numProbes += 4;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (debug) {
|
|
74
|
+
console.log(`num probes: ${numProbes}`);
|
|
75
|
+
console.log(`best distance: ${bestCell.d}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return bestCell.p;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function compareMax(a, b) {
|
|
82
|
+
return b.max - a.max;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function Cell(x, y, h, polygon) {
|
|
86
|
+
this.p = new Point(x, y);
|
|
87
|
+
this.h = h; // half the cell size
|
|
88
|
+
this.d = pointToPolygonDist(this.p, polygon); // distance from cell center to polygon
|
|
89
|
+
this.max = this.d + this.h * Math.SQRT2; // max distance to polygon within a cell
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// signed distance from point to polygon outline (negative if point is outside)
|
|
93
|
+
function pointToPolygonDist(p, polygon) {
|
|
94
|
+
let inside = false;
|
|
95
|
+
let minDistSq = Infinity;
|
|
96
|
+
|
|
97
|
+
for (let k = 0; k < polygon.length; k++) {
|
|
98
|
+
const ring = polygon[k];
|
|
99
|
+
|
|
100
|
+
for (let i = 0, len = ring.length, j = len - 1; i < len; j = i++) {
|
|
101
|
+
const a = ring[i];
|
|
102
|
+
const b = ring[j];
|
|
103
|
+
|
|
104
|
+
if ((a.y > p.y !== b.y > p.y) &&
|
|
105
|
+
(p.x < (b.x - a.x) * (p.y - a.y) / (b.y - a.y) + a.x)) inside = !inside;
|
|
106
|
+
|
|
107
|
+
minDistSq = Math.min(minDistSq, distToSegmentSquared(p, a, b));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return (inside ? 1 : -1) * Math.sqrt(minDistSq);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// get polygon centroid
|
|
115
|
+
function getCentroidCell(polygon) {
|
|
116
|
+
let area = 0;
|
|
117
|
+
let x = 0;
|
|
118
|
+
let y = 0;
|
|
119
|
+
const points = polygon[0];
|
|
120
|
+
for (let i = 0, len = points.length, j = len - 1; i < len; j = i++) {
|
|
121
|
+
const a = points[i];
|
|
122
|
+
const b = points[j];
|
|
123
|
+
const f = a.x * b.y - b.x * a.y;
|
|
124
|
+
x += (a.x + b.x) * f;
|
|
125
|
+
y += (a.y + b.y) * f;
|
|
126
|
+
area += f * 3;
|
|
127
|
+
}
|
|
128
|
+
return new Cell(x / area, y / area, 0, polygon);
|
|
129
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import WorkerPool, {PRELOAD_POOL_ID} from './worker_pool';
|
|
4
|
+
|
|
5
|
+
let globalWorkerPool;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Creates (if necessary) and returns the single, global WorkerPool instance
|
|
9
|
+
* to be shared across each Map
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
export default function getGlobalWorkerPool () {
|
|
13
|
+
if (!globalWorkerPool) {
|
|
14
|
+
globalWorkerPool = new WorkerPool();
|
|
15
|
+
}
|
|
16
|
+
return globalWorkerPool;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function prewarm() {
|
|
20
|
+
const workerPool = getGlobalWorkerPool();
|
|
21
|
+
workerPool.acquire(PRELOAD_POOL_ID);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function clearPrewarmedResources() {
|
|
25
|
+
const pool = globalWorkerPool;
|
|
26
|
+
if (pool) {
|
|
27
|
+
// Remove the pool only if all maps that referenced the preloaded global worker pool have been removed.
|
|
28
|
+
if (pool.isPreloaded() && pool.numActive() === 1) {
|
|
29
|
+
pool.release(PRELOAD_POOL_ID);
|
|
30
|
+
globalWorkerPool = null;
|
|
31
|
+
} else {
|
|
32
|
+
console.warn('Could not clear WebWorkers since there are active Map instances that still reference it. The pre-warmed WebWorker pool can only be cleared when all map instances have been removed with map.remove()');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import assert from 'assert';
|
|
4
|
+
|
|
5
|
+
import {register} from './web_worker_transfer';
|
|
6
|
+
|
|
7
|
+
export type Size = {
|
|
8
|
+
width: number,
|
|
9
|
+
height: number
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type Point = {
|
|
13
|
+
x: number,
|
|
14
|
+
y: number
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function createImage(image: *, {width, height}: Size, channels: number, data?: Uint8Array | Uint8ClampedArray) {
|
|
18
|
+
if (!data) {
|
|
19
|
+
data = new Uint8Array(width * height * channels);
|
|
20
|
+
} else if (data instanceof Uint8ClampedArray) {
|
|
21
|
+
data = new Uint8Array(data.buffer);
|
|
22
|
+
} else if (data.length !== width * height * channels) {
|
|
23
|
+
throw new RangeError('mismatched image size');
|
|
24
|
+
}
|
|
25
|
+
image.width = width;
|
|
26
|
+
image.height = height;
|
|
27
|
+
image.data = data;
|
|
28
|
+
return image;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function resizeImage(image: *, {width, height}: Size, channels: number) {
|
|
32
|
+
if (width === image.width && height === image.height) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const newImage = createImage({}, {width, height}, channels);
|
|
37
|
+
|
|
38
|
+
copyImage(image, newImage, {x: 0, y: 0}, {x: 0, y: 0}, {
|
|
39
|
+
width: Math.min(image.width, width),
|
|
40
|
+
height: Math.min(image.height, height)
|
|
41
|
+
}, channels);
|
|
42
|
+
|
|
43
|
+
image.width = width;
|
|
44
|
+
image.height = height;
|
|
45
|
+
image.data = newImage.data;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function copyImage(srcImg: *, dstImg: *, srcPt: Point, dstPt: Point, size: Size, channels: number) {
|
|
49
|
+
if (size.width === 0 || size.height === 0) {
|
|
50
|
+
return dstImg;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (size.width > srcImg.width ||
|
|
54
|
+
size.height > srcImg.height ||
|
|
55
|
+
srcPt.x > srcImg.width - size.width ||
|
|
56
|
+
srcPt.y > srcImg.height - size.height) {
|
|
57
|
+
throw new RangeError('out of range source coordinates for image copy');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (size.width > dstImg.width ||
|
|
61
|
+
size.height > dstImg.height ||
|
|
62
|
+
dstPt.x > dstImg.width - size.width ||
|
|
63
|
+
dstPt.y > dstImg.height - size.height) {
|
|
64
|
+
throw new RangeError('out of range destination coordinates for image copy');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const srcData = srcImg.data;
|
|
68
|
+
const dstData = dstImg.data;
|
|
69
|
+
|
|
70
|
+
assert(srcData !== dstData);
|
|
71
|
+
|
|
72
|
+
for (let y = 0; y < size.height; y++) {
|
|
73
|
+
const srcOffset = ((srcPt.y + y) * srcImg.width + srcPt.x) * channels;
|
|
74
|
+
const dstOffset = ((dstPt.y + y) * dstImg.width + dstPt.x) * channels;
|
|
75
|
+
for (let i = 0; i < size.width * channels; i++) {
|
|
76
|
+
dstData[dstOffset + i] = srcData[srcOffset + i];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return dstImg;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class AlphaImage {
|
|
83
|
+
width: number;
|
|
84
|
+
height: number;
|
|
85
|
+
data: Uint8Array;
|
|
86
|
+
|
|
87
|
+
constructor(size: Size, data?: Uint8Array | Uint8ClampedArray) {
|
|
88
|
+
createImage(this, size, 1, data);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
resize(size: Size) {
|
|
92
|
+
resizeImage(this, size, 1);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
clone() {
|
|
96
|
+
return new AlphaImage({width: this.width, height: this.height}, new Uint8Array(this.data));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static copy(srcImg: AlphaImage, dstImg: AlphaImage, srcPt: Point, dstPt: Point, size: Size) {
|
|
100
|
+
copyImage(srcImg, dstImg, srcPt, dstPt, size, 1);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Not premultiplied, because ImageData is not premultiplied.
|
|
105
|
+
// UNPACK_PREMULTIPLY_ALPHA_WEBGL must be used when uploading to a texture.
|
|
106
|
+
export class RGBAImage {
|
|
107
|
+
width: number;
|
|
108
|
+
height: number;
|
|
109
|
+
|
|
110
|
+
// data must be a Uint8Array instead of Uint8ClampedArray because texImage2D does not
|
|
111
|
+
// support Uint8ClampedArray in all browsers
|
|
112
|
+
data: Uint8Array;
|
|
113
|
+
|
|
114
|
+
constructor(size: Size, data?: Uint8Array | Uint8ClampedArray) {
|
|
115
|
+
createImage(this, size, 4, data);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
resize(size: Size) {
|
|
119
|
+
resizeImage(this, size, 4);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
replace(data: Uint8Array | Uint8ClampedArray, copy?: boolean) {
|
|
123
|
+
if (copy) {
|
|
124
|
+
this.data.set(data);
|
|
125
|
+
} else if (data instanceof Uint8ClampedArray) {
|
|
126
|
+
this.data = new Uint8Array(data.buffer);
|
|
127
|
+
} else {
|
|
128
|
+
this.data = data;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
clone() {
|
|
133
|
+
return new RGBAImage({width: this.width, height: this.height}, new Uint8Array(this.data));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
static copy(srcImg: RGBAImage | ImageData, dstImg: RGBAImage, srcPt: Point, dstPt: Point, size: Size) {
|
|
137
|
+
copyImage(srcImg, dstImg, srcPt, dstPt, size, 4);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
register('AlphaImage', AlphaImage);
|
|
142
|
+
register('RGBAImage', RGBAImage);
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import {isCounterClockwise} from './util';
|
|
4
|
+
|
|
5
|
+
import Point from '@mapbox/point-geometry';
|
|
6
|
+
|
|
7
|
+
export {polygonIntersectsBufferedPoint, polygonIntersectsMultiPolygon, polygonIntersectsBufferedMultiLine, polygonIntersectsPolygon, distToSegmentSquared, polygonIntersectsBox};
|
|
8
|
+
|
|
9
|
+
type Line = Array<Point>;
|
|
10
|
+
type MultiLine = Array<Line>;
|
|
11
|
+
type Ring = Array<Point>;
|
|
12
|
+
type Polygon = Array<Point>;
|
|
13
|
+
type MultiPolygon = Array<Polygon>;
|
|
14
|
+
|
|
15
|
+
function polygonIntersectsPolygon(polygonA: Polygon, polygonB: Polygon) {
|
|
16
|
+
for (let i = 0; i < polygonA.length; i++) {
|
|
17
|
+
if (polygonContainsPoint(polygonB, polygonA[i])) return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
for (let i = 0; i < polygonB.length; i++) {
|
|
21
|
+
if (polygonContainsPoint(polygonA, polygonB[i])) return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (lineIntersectsLine(polygonA, polygonB)) return true;
|
|
25
|
+
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function polygonIntersectsBufferedPoint(polygon: Polygon, point: Point, radius: number) {
|
|
30
|
+
if (polygonContainsPoint(polygon, point)) return true;
|
|
31
|
+
if (pointIntersectsBufferedLine(point, polygon, radius)) return true;
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function polygonIntersectsMultiPolygon(polygon: Polygon, multiPolygon: MultiPolygon) {
|
|
36
|
+
|
|
37
|
+
if (polygon.length === 1) {
|
|
38
|
+
return multiPolygonContainsPoint(multiPolygon, polygon[0]);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
for (let m = 0; m < multiPolygon.length; m++) {
|
|
42
|
+
const ring = multiPolygon[m];
|
|
43
|
+
for (let n = 0; n < ring.length; n++) {
|
|
44
|
+
if (polygonContainsPoint(polygon, ring[n])) return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
for (let i = 0; i < polygon.length; i++) {
|
|
49
|
+
if (multiPolygonContainsPoint(multiPolygon, polygon[i])) return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (let k = 0; k < multiPolygon.length; k++) {
|
|
53
|
+
if (lineIntersectsLine(polygon, multiPolygon[k])) return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function polygonIntersectsBufferedMultiLine(polygon: Polygon, multiLine: MultiLine, radius: number) {
|
|
60
|
+
for (let i = 0; i < multiLine.length; i++) {
|
|
61
|
+
const line = multiLine[i];
|
|
62
|
+
|
|
63
|
+
if (polygon.length >= 3) {
|
|
64
|
+
for (let k = 0; k < line.length; k++) {
|
|
65
|
+
if (polygonContainsPoint(polygon, line[k])) return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (lineIntersectsBufferedLine(polygon, line, radius)) return true;
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function lineIntersectsBufferedLine(lineA: Line, lineB: Line, radius: number) {
|
|
75
|
+
|
|
76
|
+
if (lineA.length > 1) {
|
|
77
|
+
if (lineIntersectsLine(lineA, lineB)) return true;
|
|
78
|
+
|
|
79
|
+
// Check whether any point in either line is within radius of the other line
|
|
80
|
+
for (let j = 0; j < lineB.length; j++) {
|
|
81
|
+
if (pointIntersectsBufferedLine(lineB[j], lineA, radius)) return true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
for (let k = 0; k < lineA.length; k++) {
|
|
86
|
+
if (pointIntersectsBufferedLine(lineA[k], lineB, radius)) return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function lineIntersectsLine(lineA: Line, lineB: Line) {
|
|
93
|
+
if (lineA.length === 0 || lineB.length === 0) return false;
|
|
94
|
+
for (let i = 0; i < lineA.length - 1; i++) {
|
|
95
|
+
const a0 = lineA[i];
|
|
96
|
+
const a1 = lineA[i + 1];
|
|
97
|
+
for (let j = 0; j < lineB.length - 1; j++) {
|
|
98
|
+
const b0 = lineB[j];
|
|
99
|
+
const b1 = lineB[j + 1];
|
|
100
|
+
if (lineSegmentIntersectsLineSegment(a0, a1, b0, b1)) return true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function lineSegmentIntersectsLineSegment(a0: Point, a1: Point, b0: Point, b1: Point) {
|
|
107
|
+
return isCounterClockwise(a0, b0, b1) !== isCounterClockwise(a1, b0, b1) &&
|
|
108
|
+
isCounterClockwise(a0, a1, b0) !== isCounterClockwise(a0, a1, b1);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function pointIntersectsBufferedLine(p: Point, line: Line, radius: number) {
|
|
112
|
+
const radiusSquared = radius * radius;
|
|
113
|
+
|
|
114
|
+
if (line.length === 1) return p.distSqr(line[0]) < radiusSquared;
|
|
115
|
+
|
|
116
|
+
for (let i = 1; i < line.length; i++) {
|
|
117
|
+
// Find line segments that have a distance <= radius^2 to p
|
|
118
|
+
// In that case, we treat the line as "containing point p".
|
|
119
|
+
const v = line[i - 1], w = line[i];
|
|
120
|
+
if (distToSegmentSquared(p, v, w) < radiusSquared) return true;
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Code from http://stackoverflow.com/a/1501725/331379.
|
|
126
|
+
function distToSegmentSquared(p: Point, v: Point, w: Point) {
|
|
127
|
+
const l2 = v.distSqr(w);
|
|
128
|
+
if (l2 === 0) return p.distSqr(v);
|
|
129
|
+
const t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
|
|
130
|
+
if (t < 0) return p.distSqr(v);
|
|
131
|
+
if (t > 1) return p.distSqr(w);
|
|
132
|
+
return p.distSqr(w.sub(v)._mult(t)._add(v));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// point in polygon ray casting algorithm
|
|
136
|
+
function multiPolygonContainsPoint(rings: Array<Ring>, p: Point) {
|
|
137
|
+
let c = false,
|
|
138
|
+
ring, p1, p2;
|
|
139
|
+
|
|
140
|
+
for (let k = 0; k < rings.length; k++) {
|
|
141
|
+
ring = rings[k];
|
|
142
|
+
for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
|
|
143
|
+
p1 = ring[i];
|
|
144
|
+
p2 = ring[j];
|
|
145
|
+
if (((p1.y > p.y) !== (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) {
|
|
146
|
+
c = !c;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return c;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function polygonContainsPoint(ring: Ring, p: Point) {
|
|
154
|
+
let c = false;
|
|
155
|
+
for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
|
|
156
|
+
const p1 = ring[i];
|
|
157
|
+
const p2 = ring[j];
|
|
158
|
+
if (((p1.y > p.y) !== (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) {
|
|
159
|
+
c = !c;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return c;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function polygonIntersectsBox(ring: Ring, boxX1: number, boxY1: number, boxX2: number, boxY2: number) {
|
|
166
|
+
for (const p of ring) {
|
|
167
|
+
if (boxX1 <= p.x &&
|
|
168
|
+
boxY1 <= p.y &&
|
|
169
|
+
boxX2 >= p.x &&
|
|
170
|
+
boxY2 >= p.y) return true;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const corners = [
|
|
174
|
+
new Point(boxX1, boxY1),
|
|
175
|
+
new Point(boxX1, boxY2),
|
|
176
|
+
new Point(boxX2, boxY2),
|
|
177
|
+
new Point(boxX2, boxY1)];
|
|
178
|
+
|
|
179
|
+
if (ring.length > 2) {
|
|
180
|
+
for (const corner of corners) {
|
|
181
|
+
if (polygonContainsPoint(ring, corner)) return true;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
for (let i = 0; i < ring.length - 1; i++) {
|
|
186
|
+
const p1 = ring[i];
|
|
187
|
+
const p2 = ring[i + 1];
|
|
188
|
+
if (edgeIntersectsBox(p1, p2, corners)) return true;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function edgeIntersectsBox(e1: Point, e2: Point, corners: Array<Point>) {
|
|
195
|
+
const tl = corners[0];
|
|
196
|
+
const br = corners[2];
|
|
197
|
+
// the edge and box do not intersect in either the x or y dimensions
|
|
198
|
+
if (((e1.x < tl.x) && (e2.x < tl.x)) ||
|
|
199
|
+
((e1.x > br.x) && (e2.x > br.x)) ||
|
|
200
|
+
((e1.y < tl.y) && (e2.y < tl.y)) ||
|
|
201
|
+
((e1.y > br.y) && (e2.y > br.y))) return false;
|
|
202
|
+
|
|
203
|
+
// check if all corners of the box are on the same side of the edge
|
|
204
|
+
const dir = isCounterClockwise(e1, e2, corners[0]);
|
|
205
|
+
return dir !== isCounterClockwise(e1, e2, corners[1]) ||
|
|
206
|
+
dir !== isCounterClockwise(e1, e2, corners[2]) ||
|
|
207
|
+
dir !== isCounterClockwise(e1, e2, corners[3]);
|
|
208
|
+
}
|