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,531 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import {Event} from '../util/evented';
|
|
4
|
+
import DOM from '../util/dom';
|
|
5
|
+
import type Map from './map';
|
|
6
|
+
import HandlerInertia from './handler_inertia';
|
|
7
|
+
import {MapEventHandler, BlockableMapEventHandler} from './handler/map_event';
|
|
8
|
+
import BoxZoomHandler from './handler/box_zoom';
|
|
9
|
+
import TapZoomHandler from './handler/tap_zoom';
|
|
10
|
+
import {MousePanHandler, MouseRotateHandler, MousePitchHandler} from './handler/mouse';
|
|
11
|
+
import TouchPanHandler from './handler/touch_pan';
|
|
12
|
+
import {TouchZoomHandler, TouchRotateHandler, TouchPitchHandler} from './handler/touch_zoom_rotate';
|
|
13
|
+
import KeyboardHandler from './handler/keyboard';
|
|
14
|
+
import ScrollZoomHandler from './handler/scroll_zoom';
|
|
15
|
+
import DoubleClickZoomHandler from './handler/shim/dblclick_zoom';
|
|
16
|
+
import ClickZoomHandler from './handler/click_zoom';
|
|
17
|
+
import TapDragZoomHandler from './handler/tap_drag_zoom';
|
|
18
|
+
import DragPanHandler from './handler/shim/drag_pan';
|
|
19
|
+
import DragRotateHandler from './handler/shim/drag_rotate';
|
|
20
|
+
import TouchZoomRotateHandler from './handler/shim/touch_zoom_rotate';
|
|
21
|
+
import {bindAll, extend} from '../util/util';
|
|
22
|
+
import window from '../util/window';
|
|
23
|
+
import Point from '@mapbox/point-geometry';
|
|
24
|
+
import assert from 'assert';
|
|
25
|
+
|
|
26
|
+
export type InputEvent = MouseEvent | TouchEvent | KeyboardEvent | WheelEvent;
|
|
27
|
+
|
|
28
|
+
const isMoving = p => p.zoom || p.drag || p.pitch || p.rotate;
|
|
29
|
+
|
|
30
|
+
class RenderFrameEvent extends Event {
|
|
31
|
+
type: 'renderFrame';
|
|
32
|
+
timeStamp: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Handlers interpret dom events and return camera changes that should be
|
|
36
|
+
// applied to the map (`HandlerResult`s). The camera changes are all deltas.
|
|
37
|
+
// The handler itself should have no knowledge of the map's current state.
|
|
38
|
+
// This makes it easier to merge multiple results and keeps handlers simpler.
|
|
39
|
+
// For example, if there is a mousedown and mousemove, the mousePan handler
|
|
40
|
+
// would return a `panDelta` on the mousemove.
|
|
41
|
+
export interface Handler {
|
|
42
|
+
enable(): void;
|
|
43
|
+
disable(): void;
|
|
44
|
+
isEnabled(): boolean;
|
|
45
|
+
isActive(): boolean;
|
|
46
|
+
|
|
47
|
+
// `reset` can be called by the manager at any time and must reset everything to it's original state
|
|
48
|
+
reset(): void;
|
|
49
|
+
|
|
50
|
+
// Handlers can optionally implement these methods.
|
|
51
|
+
// They are called with dom events whenever those dom evens are received.
|
|
52
|
+
+touchstart?: (e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) => HandlerResult | void;
|
|
53
|
+
+touchmove?: (e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) => HandlerResult | void;
|
|
54
|
+
+touchend?: (e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) => HandlerResult | void;
|
|
55
|
+
+touchcancel?: (e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) => HandlerResult | void;
|
|
56
|
+
+mousedown?: (e: MouseEvent, point: Point) => HandlerResult | void;
|
|
57
|
+
+mousemove?: (e: MouseEvent, point: Point) => HandlerResult | void;
|
|
58
|
+
+mouseup?: (e: MouseEvent, point: Point) => HandlerResult | void;
|
|
59
|
+
+dblclick?: (e: MouseEvent, point: Point) => HandlerResult | void;
|
|
60
|
+
+wheel?: (e: WheelEvent, point: Point) => HandlerResult | void;
|
|
61
|
+
+keydown?: (e: KeyboardEvent) => HandlerResult | void;
|
|
62
|
+
+keyup?: (e: KeyboardEvent) => HandlerResult | void;
|
|
63
|
+
|
|
64
|
+
// `renderFrame` is the only non-dom event. It is called during render
|
|
65
|
+
// frames and can be used to smooth camera changes (see scroll handler).
|
|
66
|
+
+renderFrame?: () => HandlerResult | void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// All handler methods that are called with events can optionally return a `HandlerResult`.
|
|
70
|
+
export type HandlerResult = {|
|
|
71
|
+
panDelta?: Point,
|
|
72
|
+
zoomDelta?: number,
|
|
73
|
+
bearingDelta?: number,
|
|
74
|
+
pitchDelta?: number,
|
|
75
|
+
// the point to not move when changing the camera
|
|
76
|
+
around?: Point | null,
|
|
77
|
+
// same as above, except for pinch actions, which are given higher priority
|
|
78
|
+
pinchAround?: Point | null,
|
|
79
|
+
// A method that can fire a one-off easing by directly changing the map's camera.
|
|
80
|
+
cameraAnimation?: (map: Map) => any;
|
|
81
|
+
|
|
82
|
+
// The last three properties are needed by only one handler: scrollzoom.
|
|
83
|
+
// The DOM event to be used as the `originalEvent` on any camera change events.
|
|
84
|
+
originalEvent?: any,
|
|
85
|
+
// Makes the manager trigger a frame, allowing the handler to return multiple results over time (see scrollzoom).
|
|
86
|
+
needsRenderFrame?: boolean,
|
|
87
|
+
// The camera changes won't get recorded for inertial zooming.
|
|
88
|
+
noInertia?: boolean
|
|
89
|
+
|};
|
|
90
|
+
|
|
91
|
+
function hasChange(result: HandlerResult) {
|
|
92
|
+
return (result.panDelta && result.panDelta.mag()) || result.zoomDelta || result.bearingDelta || result.pitchDelta;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
class HandlerManager {
|
|
96
|
+
_map: Map;
|
|
97
|
+
_el: HTMLElement;
|
|
98
|
+
_handlers: Array<{ handlerName: string, handler: Handler, allowed: any }>;
|
|
99
|
+
_eventsInProgress: Object;
|
|
100
|
+
_frameId: number;
|
|
101
|
+
_inertia: HandlerInertia;
|
|
102
|
+
_bearingSnap: number;
|
|
103
|
+
_handlersById: { [string]: Handler };
|
|
104
|
+
_updatingCamera: boolean;
|
|
105
|
+
_changes: Array<[HandlerResult, Object, any]>;
|
|
106
|
+
_previousActiveHandlers: { [string]: Handler };
|
|
107
|
+
_listeners: Array<[HTMLElement, string, void | {passive?: boolean, capture?: boolean}]>;
|
|
108
|
+
|
|
109
|
+
constructor(map: Map, options: { interactive: boolean, pitchWithRotate: boolean, clickTolerance: number, bearingSnap: number}) {
|
|
110
|
+
this._map = map;
|
|
111
|
+
this._el = this._map.getCanvasContainer();
|
|
112
|
+
this._handlers = [];
|
|
113
|
+
this._handlersById = {};
|
|
114
|
+
this._changes = [];
|
|
115
|
+
|
|
116
|
+
this._inertia = new HandlerInertia(map);
|
|
117
|
+
this._bearingSnap = options.bearingSnap;
|
|
118
|
+
this._previousActiveHandlers = {};
|
|
119
|
+
|
|
120
|
+
// Track whether map is currently moving, to compute start/move/end events
|
|
121
|
+
this._eventsInProgress = {};
|
|
122
|
+
|
|
123
|
+
this._addDefaultHandlers(options);
|
|
124
|
+
|
|
125
|
+
bindAll(['handleEvent', 'handleWindowEvent'], this);
|
|
126
|
+
|
|
127
|
+
const el = this._el;
|
|
128
|
+
|
|
129
|
+
this._listeners = [
|
|
130
|
+
// This needs to be `passive: true` so that a double tap fires two
|
|
131
|
+
// pairs of touchstart/end events in iOS Safari 13. If this is set to
|
|
132
|
+
// `passive: false` then the second pair of events is only fired if
|
|
133
|
+
// preventDefault() is called on the first touchstart. Calling preventDefault()
|
|
134
|
+
// undesirably prevents click events.
|
|
135
|
+
[el, 'touchstart', {passive: true}],
|
|
136
|
+
// This needs to be `passive: false` so that scrolls and pinches can be
|
|
137
|
+
// prevented in browsers that don't support `touch-actions: none`, for example iOS Safari 12.
|
|
138
|
+
[el, 'touchmove', {passive: false}],
|
|
139
|
+
[el, 'touchend', undefined],
|
|
140
|
+
[el, 'touchcancel', undefined],
|
|
141
|
+
|
|
142
|
+
[el, 'mousedown', undefined],
|
|
143
|
+
[el, 'mousemove', undefined],
|
|
144
|
+
[el, 'mouseup', undefined],
|
|
145
|
+
|
|
146
|
+
// Bind window-level event listeners for move and up/end events. In the absence of
|
|
147
|
+
// the pointer capture API, which is not supported by all necessary platforms,
|
|
148
|
+
// window-level event listeners give us the best shot at capturing events that
|
|
149
|
+
// fall outside the map canvas element. Use `{capture: true}` for the move event
|
|
150
|
+
// to prevent map move events from being fired during a drag.
|
|
151
|
+
[window.document, 'mousemove', {capture: true}],
|
|
152
|
+
[window.document, 'mouseup', undefined],
|
|
153
|
+
|
|
154
|
+
[el, 'mouseover', undefined],
|
|
155
|
+
[el, 'mouseout', undefined],
|
|
156
|
+
[el, 'dblclick', undefined],
|
|
157
|
+
[el, 'click', undefined],
|
|
158
|
+
|
|
159
|
+
[el, 'keydown', {capture: false}],
|
|
160
|
+
[el, 'keyup', undefined],
|
|
161
|
+
|
|
162
|
+
[el, 'wheel', {passive: false}],
|
|
163
|
+
[el, 'contextmenu', undefined],
|
|
164
|
+
|
|
165
|
+
[window, 'blur', undefined]
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
for (const [target, type, listenerOptions] of this._listeners) {
|
|
169
|
+
DOM.addEventListener(target, type, target === window.document ? this.handleWindowEvent : this.handleEvent, listenerOptions);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
destroy() {
|
|
174
|
+
for (const [target, type, listenerOptions] of this._listeners) {
|
|
175
|
+
DOM.removeEventListener(target, type, target === window.document ? this.handleWindowEvent : this.handleEvent, listenerOptions);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
_addDefaultHandlers(options: { interactive: boolean, pitchWithRotate: boolean, clickTolerance: number }) {
|
|
180
|
+
const map = this._map;
|
|
181
|
+
const el = map.getCanvasContainer();
|
|
182
|
+
this._add('mapEvent', new MapEventHandler(map, options));
|
|
183
|
+
|
|
184
|
+
const boxZoom = map.boxZoom = new BoxZoomHandler(map, options);
|
|
185
|
+
this._add('boxZoom', boxZoom);
|
|
186
|
+
|
|
187
|
+
const tapZoom = new TapZoomHandler();
|
|
188
|
+
const clickZoom = new ClickZoomHandler();
|
|
189
|
+
map.doubleClickZoom = new DoubleClickZoomHandler(clickZoom, tapZoom);
|
|
190
|
+
this._add('tapZoom', tapZoom);
|
|
191
|
+
this._add('clickZoom', clickZoom);
|
|
192
|
+
|
|
193
|
+
const tapDragZoom = new TapDragZoomHandler();
|
|
194
|
+
this._add('tapDragZoom', tapDragZoom);
|
|
195
|
+
|
|
196
|
+
const touchPitch = map.touchPitch = new TouchPitchHandler();
|
|
197
|
+
this._add('touchPitch', touchPitch);
|
|
198
|
+
|
|
199
|
+
const mouseRotate = new MouseRotateHandler(options);
|
|
200
|
+
const mousePitch = new MousePitchHandler(options);
|
|
201
|
+
map.dragRotate = new DragRotateHandler(options, mouseRotate, mousePitch);
|
|
202
|
+
this._add('mouseRotate', mouseRotate, ['mousePitch']);
|
|
203
|
+
this._add('mousePitch', mousePitch, ['mouseRotate']);
|
|
204
|
+
|
|
205
|
+
const mousePan = new MousePanHandler(options);
|
|
206
|
+
const touchPan = new TouchPanHandler(options);
|
|
207
|
+
map.dragPan = new DragPanHandler(el, mousePan, touchPan);
|
|
208
|
+
this._add('mousePan', mousePan);
|
|
209
|
+
this._add('touchPan', touchPan, ['touchZoom', 'touchRotate']);
|
|
210
|
+
|
|
211
|
+
const touchRotate = new TouchRotateHandler();
|
|
212
|
+
const touchZoom = new TouchZoomHandler();
|
|
213
|
+
map.touchZoomRotate = new TouchZoomRotateHandler(el, touchZoom, touchRotate, tapDragZoom);
|
|
214
|
+
this._add('touchRotate', touchRotate, ['touchPan', 'touchZoom']);
|
|
215
|
+
this._add('touchZoom', touchZoom, ['touchPan', 'touchRotate']);
|
|
216
|
+
|
|
217
|
+
const scrollZoom = map.scrollZoom = new ScrollZoomHandler(map, this);
|
|
218
|
+
this._add('scrollZoom', scrollZoom, ['mousePan']);
|
|
219
|
+
|
|
220
|
+
const keyboard = map.keyboard = new KeyboardHandler();
|
|
221
|
+
this._add('keyboard', keyboard);
|
|
222
|
+
|
|
223
|
+
this._add('blockableMapEvent', new BlockableMapEventHandler(map));
|
|
224
|
+
|
|
225
|
+
for (const name of ['boxZoom', 'doubleClickZoom', 'tapDragZoom', 'touchPitch', 'dragRotate', 'dragPan', 'touchZoomRotate', 'scrollZoom', 'keyboard']) {
|
|
226
|
+
if (options.interactive && (options: any)[name]) {
|
|
227
|
+
(map: any)[name].enable((options: any)[name]);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
_add(handlerName: string, handler: Handler, allowed?: Array<string>) {
|
|
233
|
+
this._handlers.push({handlerName, handler, allowed});
|
|
234
|
+
this._handlersById[handlerName] = handler;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
stop(allowEndAnimation: boolean) {
|
|
238
|
+
// do nothing if this method was triggered by a gesture update
|
|
239
|
+
if (this._updatingCamera) return;
|
|
240
|
+
|
|
241
|
+
for (const {handler} of this._handlers) {
|
|
242
|
+
handler.reset();
|
|
243
|
+
}
|
|
244
|
+
this._inertia.clear();
|
|
245
|
+
this._fireEvents({}, {}, allowEndAnimation);
|
|
246
|
+
this._changes = [];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
isActive() {
|
|
250
|
+
for (const {handler} of this._handlers) {
|
|
251
|
+
if (handler.isActive()) return true;
|
|
252
|
+
}
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
isZooming() {
|
|
257
|
+
return !!this._eventsInProgress.zoom || this._map.scrollZoom.isZooming();
|
|
258
|
+
}
|
|
259
|
+
isRotating() {
|
|
260
|
+
return !!this._eventsInProgress.rotate;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
isMoving() {
|
|
264
|
+
return Boolean(isMoving(this._eventsInProgress)) || this.isZooming();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
_blockedByActive(activeHandlers: { [string]: Handler }, allowed: Array<string>, myName: string) {
|
|
268
|
+
for (const name in activeHandlers) {
|
|
269
|
+
if (name === myName) continue;
|
|
270
|
+
if (!allowed || allowed.indexOf(name) < 0) {
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
handleWindowEvent(e: InputEvent) {
|
|
278
|
+
this.handleEvent(e, `${e.type}Window`);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
_getMapTouches(touches: TouchList) {
|
|
282
|
+
const mapTouches = [];
|
|
283
|
+
for (const t of touches) {
|
|
284
|
+
const target = ((t.target: any): Node);
|
|
285
|
+
if (this._el.contains(target)) {
|
|
286
|
+
mapTouches.push(t);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return ((mapTouches: any): TouchList);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
handleEvent(e: InputEvent | RenderFrameEvent, eventName?: string) {
|
|
293
|
+
|
|
294
|
+
this._updatingCamera = true;
|
|
295
|
+
assert(e.timeStamp !== undefined);
|
|
296
|
+
|
|
297
|
+
const inputEvent = e.type === 'renderFrame' ? undefined : ((e: any): InputEvent);
|
|
298
|
+
|
|
299
|
+
/*
|
|
300
|
+
* We don't call e.preventDefault() for any events by default.
|
|
301
|
+
* Handlers are responsible for calling it where necessary.
|
|
302
|
+
*/
|
|
303
|
+
|
|
304
|
+
const mergedHandlerResult: HandlerResult = {needsRenderFrame: false};
|
|
305
|
+
const eventsInProgress = {};
|
|
306
|
+
const activeHandlers = {};
|
|
307
|
+
|
|
308
|
+
const mapTouches = e.touches ? this._getMapTouches(((e: any): TouchEvent).touches) : undefined;
|
|
309
|
+
const points = mapTouches ? DOM.touchPos(this._el, mapTouches) : DOM.mousePos(this._el, ((e: any): MouseEvent));
|
|
310
|
+
|
|
311
|
+
for (const {handlerName, handler, allowed} of this._handlers) {
|
|
312
|
+
if (!handler.isEnabled()) continue;
|
|
313
|
+
|
|
314
|
+
let data: HandlerResult | void;
|
|
315
|
+
if (this._blockedByActive(activeHandlers, allowed, handlerName)) {
|
|
316
|
+
handler.reset();
|
|
317
|
+
|
|
318
|
+
} else {
|
|
319
|
+
if ((handler: any)[eventName || e.type]) {
|
|
320
|
+
data = (handler: any)[eventName || e.type](e, points, mapTouches);
|
|
321
|
+
this.mergeHandlerResult(mergedHandlerResult, eventsInProgress, data, handlerName, inputEvent);
|
|
322
|
+
if (data && data.needsRenderFrame) {
|
|
323
|
+
this._triggerRenderFrame();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (data || handler.isActive()) {
|
|
329
|
+
activeHandlers[handlerName] = handler;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const deactivatedHandlers = {};
|
|
334
|
+
for (const name in this._previousActiveHandlers) {
|
|
335
|
+
if (!activeHandlers[name]) {
|
|
336
|
+
deactivatedHandlers[name] = inputEvent;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
this._previousActiveHandlers = activeHandlers;
|
|
340
|
+
|
|
341
|
+
if (Object.keys(deactivatedHandlers).length || hasChange(mergedHandlerResult)) {
|
|
342
|
+
this._changes.push([mergedHandlerResult, eventsInProgress, deactivatedHandlers]);
|
|
343
|
+
this._triggerRenderFrame();
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (Object.keys(activeHandlers).length || hasChange(mergedHandlerResult)) {
|
|
347
|
+
this._map._stop(true);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
this._updatingCamera = false;
|
|
351
|
+
|
|
352
|
+
const {cameraAnimation} = mergedHandlerResult;
|
|
353
|
+
if (cameraAnimation) {
|
|
354
|
+
this._inertia.clear();
|
|
355
|
+
this._fireEvents({}, {}, true);
|
|
356
|
+
this._changes = [];
|
|
357
|
+
cameraAnimation(this._map);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
mergeHandlerResult(mergedHandlerResult: HandlerResult, eventsInProgress: Object, handlerResult: HandlerResult, name: string, e?: InputEvent) {
|
|
362
|
+
if (!handlerResult) return;
|
|
363
|
+
|
|
364
|
+
extend(mergedHandlerResult, handlerResult);
|
|
365
|
+
|
|
366
|
+
const eventData = {handlerName: name, originalEvent: handlerResult.originalEvent || e};
|
|
367
|
+
|
|
368
|
+
// track which handler changed which camera property
|
|
369
|
+
if (handlerResult.zoomDelta !== undefined) {
|
|
370
|
+
eventsInProgress.zoom = eventData;
|
|
371
|
+
}
|
|
372
|
+
if (handlerResult.panDelta !== undefined) {
|
|
373
|
+
eventsInProgress.drag = eventData;
|
|
374
|
+
}
|
|
375
|
+
if (handlerResult.pitchDelta !== undefined) {
|
|
376
|
+
eventsInProgress.pitch = eventData;
|
|
377
|
+
}
|
|
378
|
+
if (handlerResult.bearingDelta !== undefined) {
|
|
379
|
+
eventsInProgress.rotate = eventData;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
_applyChanges() {
|
|
385
|
+
const combined = {};
|
|
386
|
+
const combinedEventsInProgress = {};
|
|
387
|
+
const combinedDeactivatedHandlers = {};
|
|
388
|
+
|
|
389
|
+
for (const [change, eventsInProgress, deactivatedHandlers] of this._changes) {
|
|
390
|
+
|
|
391
|
+
if (change.panDelta) combined.panDelta = (combined.panDelta || new Point(0, 0))._add(change.panDelta);
|
|
392
|
+
if (change.zoomDelta) combined.zoomDelta = (combined.zoomDelta || 0) + change.zoomDelta;
|
|
393
|
+
if (change.bearingDelta) combined.bearingDelta = (combined.bearingDelta || 0) + change.bearingDelta;
|
|
394
|
+
if (change.pitchDelta) combined.pitchDelta = (combined.pitchDelta || 0) + change.pitchDelta;
|
|
395
|
+
if (change.around !== undefined) combined.around = change.around;
|
|
396
|
+
if (change.pinchAround !== undefined) combined.pinchAround = change.pinchAround;
|
|
397
|
+
if (change.noInertia) combined.noInertia = change.noInertia;
|
|
398
|
+
|
|
399
|
+
extend(combinedEventsInProgress, eventsInProgress);
|
|
400
|
+
extend(combinedDeactivatedHandlers, deactivatedHandlers);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
this._updateMapTransform(combined, combinedEventsInProgress, combinedDeactivatedHandlers);
|
|
404
|
+
this._changes = [];
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
_updateMapTransform(combinedResult: any, combinedEventsInProgress: Object, deactivatedHandlers: Object) {
|
|
408
|
+
|
|
409
|
+
const map = this._map;
|
|
410
|
+
const tr = map.transform;
|
|
411
|
+
|
|
412
|
+
if (!hasChange(combinedResult)) {
|
|
413
|
+
return this._fireEvents(combinedEventsInProgress, deactivatedHandlers, true);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
let {panDelta, zoomDelta, bearingDelta, pitchDelta, around, pinchAround} = combinedResult;
|
|
417
|
+
|
|
418
|
+
if (pinchAround !== undefined) {
|
|
419
|
+
around = pinchAround;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// stop any ongoing camera animations (easeTo, flyTo)
|
|
423
|
+
map._stop(true);
|
|
424
|
+
|
|
425
|
+
around = around || map.transform.centerPoint;
|
|
426
|
+
const loc = tr.pointLocation(panDelta ? around.sub(panDelta) : around);
|
|
427
|
+
if (bearingDelta) tr.bearing += bearingDelta;
|
|
428
|
+
if (pitchDelta) tr.pitch += pitchDelta;
|
|
429
|
+
if (zoomDelta) tr.zoom += zoomDelta;
|
|
430
|
+
tr.setLocationAtPoint(loc, around);
|
|
431
|
+
|
|
432
|
+
this._map._update();
|
|
433
|
+
if (!combinedResult.noInertia) this._inertia.record(combinedResult);
|
|
434
|
+
this._fireEvents(combinedEventsInProgress, deactivatedHandlers, true);
|
|
435
|
+
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
_fireEvents(newEventsInProgress: { [string]: Object }, deactivatedHandlers: Object, allowEndAnimation: boolean) {
|
|
439
|
+
|
|
440
|
+
const wasMoving = isMoving(this._eventsInProgress);
|
|
441
|
+
const nowMoving = isMoving(newEventsInProgress);
|
|
442
|
+
|
|
443
|
+
const startEvents = {};
|
|
444
|
+
|
|
445
|
+
for (const eventName in newEventsInProgress) {
|
|
446
|
+
const {originalEvent} = newEventsInProgress[eventName];
|
|
447
|
+
if (!this._eventsInProgress[eventName]) {
|
|
448
|
+
startEvents[`${eventName}start`] = originalEvent;
|
|
449
|
+
}
|
|
450
|
+
this._eventsInProgress[eventName] = newEventsInProgress[eventName];
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// fire start events only after this._eventsInProgress has been updated
|
|
454
|
+
if (!wasMoving && nowMoving) {
|
|
455
|
+
this._fireEvent('movestart', nowMoving.originalEvent);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
for (const name in startEvents) {
|
|
459
|
+
this._fireEvent(name, startEvents[name]);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
if (nowMoving) {
|
|
463
|
+
this._fireEvent('move', nowMoving.originalEvent);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
for (const eventName in newEventsInProgress) {
|
|
467
|
+
const {originalEvent} = newEventsInProgress[eventName];
|
|
468
|
+
this._fireEvent(eventName, originalEvent);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const endEvents = {};
|
|
472
|
+
|
|
473
|
+
let originalEndEvent;
|
|
474
|
+
for (const eventName in this._eventsInProgress) {
|
|
475
|
+
const {handlerName, originalEvent} = this._eventsInProgress[eventName];
|
|
476
|
+
if (!this._handlersById[handlerName].isActive()) {
|
|
477
|
+
delete this._eventsInProgress[eventName];
|
|
478
|
+
originalEndEvent = deactivatedHandlers[handlerName] || originalEvent;
|
|
479
|
+
endEvents[`${eventName}end`] = originalEndEvent;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
for (const name in endEvents) {
|
|
484
|
+
this._fireEvent(name, endEvents[name]);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const stillMoving = isMoving(this._eventsInProgress);
|
|
488
|
+
if (allowEndAnimation && (wasMoving || nowMoving) && !stillMoving) {
|
|
489
|
+
this._updatingCamera = true;
|
|
490
|
+
const inertialEase = this._inertia._onMoveEnd(this._map.dragPan._inertiaOptions);
|
|
491
|
+
|
|
492
|
+
const shouldSnapToNorth = bearing => bearing !== 0 && -this._bearingSnap < bearing && bearing < this._bearingSnap;
|
|
493
|
+
|
|
494
|
+
if (inertialEase) {
|
|
495
|
+
if (shouldSnapToNorth(inertialEase.bearing || this._map.getBearing())) {
|
|
496
|
+
inertialEase.bearing = 0;
|
|
497
|
+
}
|
|
498
|
+
this._map.easeTo(inertialEase, {originalEvent: originalEndEvent});
|
|
499
|
+
} else {
|
|
500
|
+
this._map.fire(new Event('moveend', {originalEvent: originalEndEvent}));
|
|
501
|
+
if (shouldSnapToNorth(this._map.getBearing())) {
|
|
502
|
+
this._map.resetNorth();
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
this._updatingCamera = false;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
_fireEvent(type: string, e: *) {
|
|
511
|
+
this._map.fire(new Event(type, e ? {originalEvent: e} : {}));
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
_requestFrame() {
|
|
515
|
+
this._map.triggerRepaint();
|
|
516
|
+
return this._map._renderTaskQueue.add(timeStamp => {
|
|
517
|
+
delete this._frameId;
|
|
518
|
+
this.handleEvent(new RenderFrameEvent('renderFrame', {timeStamp}));
|
|
519
|
+
this._applyChanges();
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
_triggerRenderFrame() {
|
|
524
|
+
if (this._frameId === undefined) {
|
|
525
|
+
this._frameId = this._requestFrame();
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
export default HandlerManager;
|
package/src/ui/hash.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import {bindAll} from '../util/util';
|
|
4
|
+
import window from '../util/window';
|
|
5
|
+
import throttle from '../util/throttle';
|
|
6
|
+
|
|
7
|
+
import type Map from './map';
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Adds the map's position to its page's location hash.
|
|
11
|
+
* Passed as an option to the map object.
|
|
12
|
+
*
|
|
13
|
+
* @returns {Hash} `this`
|
|
14
|
+
*/
|
|
15
|
+
class Hash {
|
|
16
|
+
_map: Map;
|
|
17
|
+
_updateHash: () => ?TimeoutID;
|
|
18
|
+
_hashName: ?string;
|
|
19
|
+
|
|
20
|
+
constructor(hashName: ?string) {
|
|
21
|
+
this._hashName = hashName && encodeURIComponent(hashName);
|
|
22
|
+
bindAll([
|
|
23
|
+
'_getCurrentHash',
|
|
24
|
+
'_onHashChange',
|
|
25
|
+
'_updateHash'
|
|
26
|
+
], this);
|
|
27
|
+
|
|
28
|
+
// Mobile Safari doesn't allow updating the hash more than 100 times per 30 seconds.
|
|
29
|
+
this._updateHash = throttle(this._updateHashUnthrottled.bind(this), 30 * 1000 / 100);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
* Map element to listen for coordinate changes
|
|
34
|
+
*
|
|
35
|
+
* @param {Object} map
|
|
36
|
+
* @returns {Hash} `this`
|
|
37
|
+
*/
|
|
38
|
+
addTo(map: Map) {
|
|
39
|
+
this._map = map;
|
|
40
|
+
window.addEventListener('hashchange', this._onHashChange, false);
|
|
41
|
+
this._map.on('moveend', this._updateHash);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
* Removes hash
|
|
47
|
+
*
|
|
48
|
+
* @returns {Popup} `this`
|
|
49
|
+
*/
|
|
50
|
+
remove() {
|
|
51
|
+
window.removeEventListener('hashchange', this._onHashChange, false);
|
|
52
|
+
this._map.off('moveend', this._updateHash);
|
|
53
|
+
clearTimeout(this._updateHash());
|
|
54
|
+
|
|
55
|
+
delete this._map;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
getHashString(mapFeedback?: boolean) {
|
|
60
|
+
const center = this._map.getCenter(),
|
|
61
|
+
zoom = Math.round(this._map.getZoom() * 100) / 100,
|
|
62
|
+
// derived from equation: 512px * 2^z / 360 / 10^d < 0.5px
|
|
63
|
+
precision = Math.ceil((zoom * Math.LN2 + Math.log(512 / 360 / 0.5)) / Math.LN10),
|
|
64
|
+
m = Math.pow(10, precision),
|
|
65
|
+
lng = Math.round(center.lng * m) / m,
|
|
66
|
+
lat = Math.round(center.lat * m) / m,
|
|
67
|
+
bearing = this._map.getBearing(),
|
|
68
|
+
pitch = this._map.getPitch();
|
|
69
|
+
let hash = '';
|
|
70
|
+
if (mapFeedback) {
|
|
71
|
+
// new map feedback site has some constraints that don't allow
|
|
72
|
+
// us to use the same hash format as we do for the Map hash option.
|
|
73
|
+
hash += `/${lng}/${lat}/${zoom}`;
|
|
74
|
+
} else {
|
|
75
|
+
hash += `${zoom}/${lat}/${lng}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (bearing || pitch) hash += (`/${Math.round(bearing * 10) / 10}`);
|
|
79
|
+
if (pitch) hash += (`/${Math.round(pitch)}`);
|
|
80
|
+
|
|
81
|
+
if (this._hashName) {
|
|
82
|
+
const hashName = this._hashName;
|
|
83
|
+
let found = false;
|
|
84
|
+
const parts = window.location.hash.slice(1).split('&').map(part => {
|
|
85
|
+
const key = part.split('=')[0];
|
|
86
|
+
if (key === hashName) {
|
|
87
|
+
found = true;
|
|
88
|
+
return `${key}=${hash}`;
|
|
89
|
+
}
|
|
90
|
+
return part;
|
|
91
|
+
}).filter(a => a);
|
|
92
|
+
if (!found) {
|
|
93
|
+
parts.push(`${hashName}=${hash}`);
|
|
94
|
+
}
|
|
95
|
+
return `#${parts.join('&')}`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return `#${hash}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
_getCurrentHash() {
|
|
102
|
+
// Get the current hash from location, stripped from its number sign
|
|
103
|
+
const hash = window.location.hash.replace('#', '');
|
|
104
|
+
if (this._hashName) {
|
|
105
|
+
// Split the parameter-styled hash into parts and find the value we need
|
|
106
|
+
let keyval;
|
|
107
|
+
hash.split('&').map(
|
|
108
|
+
part => part.split('=')
|
|
109
|
+
).forEach(part => {
|
|
110
|
+
if (part[0] === this._hashName) {
|
|
111
|
+
keyval = part;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return (keyval ? keyval[1] || '' : '').split('/');
|
|
115
|
+
}
|
|
116
|
+
return hash.split('/');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
_onHashChange() {
|
|
120
|
+
const loc = this._getCurrentHash();
|
|
121
|
+
if (loc.length >= 3 && !loc.some(v => isNaN(v))) {
|
|
122
|
+
const bearing = this._map.dragRotate.isEnabled() && this._map.touchZoomRotate.isEnabled() ? +(loc[3] || 0) : this._map.getBearing();
|
|
123
|
+
this._map.jumpTo({
|
|
124
|
+
center: [+loc[2], +loc[1]],
|
|
125
|
+
zoom: +loc[0],
|
|
126
|
+
bearing,
|
|
127
|
+
pitch: +(loc[4] || 0)
|
|
128
|
+
});
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
_updateHashUnthrottled() {
|
|
135
|
+
// Replace if already present, else append the updated hash string
|
|
136
|
+
const location = window.location.href.replace(/(#.+)?$/, this.getHashString());
|
|
137
|
+
try {
|
|
138
|
+
window.history.replaceState(window.history.state, null, location);
|
|
139
|
+
} catch (SecurityError) {
|
|
140
|
+
// IE11 does not allow this if the page is within an iframe created
|
|
141
|
+
// with iframe.contentWindow.document.write(...).
|
|
142
|
+
// https://github.com/mapbox/mapbox-gl-js/issues/7410
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export default Hash;
|