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,212 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import {OverscaledTileID} from './tile_id';
|
|
4
|
+
import type Tile from './tile';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A [least-recently-used cache](http://en.wikipedia.org/wiki/Cache_algorithms)
|
|
8
|
+
* with hash lookup made possible by keeping a list of keys in parallel to
|
|
9
|
+
* an array of dictionary of values
|
|
10
|
+
*
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
class TileCache {
|
|
14
|
+
max: number;
|
|
15
|
+
data: {[key: string]: Array<{ value: Tile, timeout: ?TimeoutID}>};
|
|
16
|
+
order: Array<string>;
|
|
17
|
+
onRemove: (element: Tile) => void;
|
|
18
|
+
/**
|
|
19
|
+
* @param {number} max number of permitted values
|
|
20
|
+
* @param {Function} onRemove callback called with items when they expire
|
|
21
|
+
*/
|
|
22
|
+
constructor(max: number, onRemove: (element: Tile) => void) {
|
|
23
|
+
this.max = max;
|
|
24
|
+
this.onRemove = onRemove;
|
|
25
|
+
this.reset();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Clear the cache
|
|
30
|
+
*
|
|
31
|
+
* @returns {TileCache} this cache
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
reset() {
|
|
35
|
+
for (const key in this.data) {
|
|
36
|
+
for (const removedData of this.data[key]) {
|
|
37
|
+
if (removedData.timeout) clearTimeout(removedData.timeout);
|
|
38
|
+
this.onRemove(removedData.value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
this.data = {};
|
|
43
|
+
this.order = [];
|
|
44
|
+
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Add a key, value combination to the cache, trimming its size if this pushes
|
|
50
|
+
* it over max length.
|
|
51
|
+
*
|
|
52
|
+
* @param {OverscaledTileID} tileID lookup key for the item
|
|
53
|
+
* @param {*} data any value
|
|
54
|
+
*
|
|
55
|
+
* @returns {TileCache} this cache
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
add(tileID: OverscaledTileID, data: Tile, expiryTimeout: number | void) {
|
|
59
|
+
const key = tileID.wrapped().key;
|
|
60
|
+
if (this.data[key] === undefined) {
|
|
61
|
+
this.data[key] = [];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const dataWrapper = {
|
|
65
|
+
value: data,
|
|
66
|
+
timeout: undefined
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (expiryTimeout !== undefined) {
|
|
70
|
+
dataWrapper.timeout = setTimeout(() => {
|
|
71
|
+
this.remove(tileID, dataWrapper);
|
|
72
|
+
}, expiryTimeout);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.data[key].push(dataWrapper);
|
|
76
|
+
this.order.push(key);
|
|
77
|
+
|
|
78
|
+
if (this.order.length > this.max) {
|
|
79
|
+
const removedData = this._getAndRemoveByKey(this.order[0]);
|
|
80
|
+
if (removedData) this.onRemove(removedData);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Determine whether the value attached to `key` is present
|
|
88
|
+
*
|
|
89
|
+
* @param {OverscaledTileID} tileID the key to be looked-up
|
|
90
|
+
* @returns {boolean} whether the cache has this value
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
has(tileID: OverscaledTileID): boolean {
|
|
94
|
+
return tileID.wrapped().key in this.data;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Get the value attached to a specific key and remove data from cache.
|
|
99
|
+
* If the key is not found, returns `null`
|
|
100
|
+
*
|
|
101
|
+
* @param {OverscaledTileID} tileID the key to look up
|
|
102
|
+
* @returns {*} the data, or null if it isn't found
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
getAndRemove(tileID: OverscaledTileID): ?Tile {
|
|
106
|
+
if (!this.has(tileID)) { return null; }
|
|
107
|
+
return this._getAndRemoveByKey(tileID.wrapped().key);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/*
|
|
111
|
+
* Get and remove the value with the specified key.
|
|
112
|
+
*/
|
|
113
|
+
_getAndRemoveByKey(key: string): ?Tile {
|
|
114
|
+
const data = this.data[key].shift();
|
|
115
|
+
if (data.timeout) clearTimeout(data.timeout);
|
|
116
|
+
|
|
117
|
+
if (this.data[key].length === 0) {
|
|
118
|
+
delete this.data[key];
|
|
119
|
+
}
|
|
120
|
+
this.order.splice(this.order.indexOf(key), 1);
|
|
121
|
+
|
|
122
|
+
return data.value;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/*
|
|
126
|
+
* Get the value with the specified (wrapped tile) key.
|
|
127
|
+
*/
|
|
128
|
+
getByKey(key: string): ?Tile {
|
|
129
|
+
const data = this.data[key];
|
|
130
|
+
return data ? data[0].value : null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Get the value attached to a specific key without removing data
|
|
135
|
+
* from the cache. If the key is not found, returns `null`
|
|
136
|
+
*
|
|
137
|
+
* @param {OverscaledTileID} tileID the key to look up
|
|
138
|
+
* @returns {*} the data, or null if it isn't found
|
|
139
|
+
* @private
|
|
140
|
+
*/
|
|
141
|
+
get(tileID: OverscaledTileID): ?Tile {
|
|
142
|
+
if (!this.has(tileID)) { return null; }
|
|
143
|
+
|
|
144
|
+
const data = this.data[tileID.wrapped().key][0];
|
|
145
|
+
return data.value;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Remove a key/value combination from the cache.
|
|
150
|
+
*
|
|
151
|
+
* @param {OverscaledTileID} tileID the key for the pair to delete
|
|
152
|
+
* @param {Tile} value If a value is provided, remove that exact version of the value.
|
|
153
|
+
* @returns {TileCache} this cache
|
|
154
|
+
* @private
|
|
155
|
+
*/
|
|
156
|
+
remove(tileID: OverscaledTileID, value: ?{ value: Tile, timeout: ?TimeoutID}) {
|
|
157
|
+
if (!this.has(tileID)) { return this; }
|
|
158
|
+
const key = tileID.wrapped().key;
|
|
159
|
+
|
|
160
|
+
const dataIndex = value === undefined ? 0 : this.data[key].indexOf(value);
|
|
161
|
+
const data = this.data[key][dataIndex];
|
|
162
|
+
this.data[key].splice(dataIndex, 1);
|
|
163
|
+
if (data.timeout) clearTimeout(data.timeout);
|
|
164
|
+
if (this.data[key].length === 0) {
|
|
165
|
+
delete this.data[key];
|
|
166
|
+
}
|
|
167
|
+
this.onRemove(data.value);
|
|
168
|
+
this.order.splice(this.order.indexOf(key), 1);
|
|
169
|
+
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Change the max size of the cache.
|
|
175
|
+
*
|
|
176
|
+
* @param {number} max the max size of the cache
|
|
177
|
+
* @returns {TileCache} this cache
|
|
178
|
+
* @private
|
|
179
|
+
*/
|
|
180
|
+
setMaxSize(max: number): TileCache {
|
|
181
|
+
this.max = max;
|
|
182
|
+
|
|
183
|
+
while (this.order.length > this.max) {
|
|
184
|
+
const removedData = this._getAndRemoveByKey(this.order[0]);
|
|
185
|
+
if (removedData) this.onRemove(removedData);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Remove entries that do not pass a filter function. Used for removing
|
|
193
|
+
* stale tiles from the cache.
|
|
194
|
+
*
|
|
195
|
+
* @param {function} filterFn Determines whether the tile is filtered. If the supplied function returns false, the tile will be filtered out.
|
|
196
|
+
*/
|
|
197
|
+
filter(filterFn: (tile: Tile) => boolean) {
|
|
198
|
+
const removed = [];
|
|
199
|
+
for (const key in this.data) {
|
|
200
|
+
for (const entry of this.data[key]) {
|
|
201
|
+
if (!filterFn(entry.value)) {
|
|
202
|
+
removed.push(entry);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
for (const r of removed) {
|
|
207
|
+
this.remove(r.value.tileID, r);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export default TileCache;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import {getTileBBox} from '@mapbox/whoots-js';
|
|
4
|
+
import EXTENT from '../data/extent';
|
|
5
|
+
import Point from '@mapbox/point-geometry';
|
|
6
|
+
import MercatorCoordinate from '../geo/mercator_coordinate';
|
|
7
|
+
|
|
8
|
+
import assert from 'assert';
|
|
9
|
+
import {register} from '../util/web_worker_transfer';
|
|
10
|
+
|
|
11
|
+
export class CanonicalTileID {
|
|
12
|
+
z: number;
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
key: string;
|
|
16
|
+
|
|
17
|
+
constructor(z: number, x: number, y: number) {
|
|
18
|
+
assert(z >= 0 && z <= 25);
|
|
19
|
+
assert(x >= 0 && x < Math.pow(2, z));
|
|
20
|
+
assert(y >= 0 && y < Math.pow(2, z));
|
|
21
|
+
this.z = z;
|
|
22
|
+
this.x = x;
|
|
23
|
+
this.y = y;
|
|
24
|
+
this.key = calculateKey(0, z, z, x, y);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
equals(id: CanonicalTileID) {
|
|
28
|
+
return this.z === id.z && this.x === id.x && this.y === id.y;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// given a list of urls, choose a url template and return a tile URL
|
|
32
|
+
url(urls: Array<string>, scheme: ?string) {
|
|
33
|
+
const bbox = getTileBBox(this.x, this.y, this.z);
|
|
34
|
+
const quadkey = getQuadkey(this.z, this.x, this.y);
|
|
35
|
+
|
|
36
|
+
return urls[(this.x + this.y) % urls.length]
|
|
37
|
+
.replace('{prefix}', (this.x % 16).toString(16) + (this.y % 16).toString(16))
|
|
38
|
+
.replace('{z}', String(this.z))
|
|
39
|
+
.replace('{x}', String(this.x))
|
|
40
|
+
.replace('{y}', String(scheme === 'tms' ? (Math.pow(2, this.z) - this.y - 1) : this.y))
|
|
41
|
+
.replace('{quadkey}', quadkey)
|
|
42
|
+
.replace('{bbox-epsg-3857}', bbox);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getTilePoint(coord: MercatorCoordinate) {
|
|
46
|
+
const tilesAtZoom = Math.pow(2, this.z);
|
|
47
|
+
return new Point(
|
|
48
|
+
(coord.x * tilesAtZoom - this.x) * EXTENT,
|
|
49
|
+
(coord.y * tilesAtZoom - this.y) * EXTENT);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
toString() {
|
|
53
|
+
return `${this.z}/${this.x}/${this.y}`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class UnwrappedTileID {
|
|
58
|
+
wrap: number;
|
|
59
|
+
canonical: CanonicalTileID;
|
|
60
|
+
key: string;
|
|
61
|
+
|
|
62
|
+
constructor(wrap: number, canonical: CanonicalTileID) {
|
|
63
|
+
this.wrap = wrap;
|
|
64
|
+
this.canonical = canonical;
|
|
65
|
+
this.key = calculateKey(wrap, canonical.z, canonical.z, canonical.x, canonical.y);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export class OverscaledTileID {
|
|
70
|
+
overscaledZ: number;
|
|
71
|
+
wrap: number;
|
|
72
|
+
canonical: CanonicalTileID;
|
|
73
|
+
key: string;
|
|
74
|
+
posMatrix: Float32Array;
|
|
75
|
+
|
|
76
|
+
constructor(overscaledZ: number, wrap: number, z: number, x: number, y: number) {
|
|
77
|
+
assert(overscaledZ >= z);
|
|
78
|
+
this.overscaledZ = overscaledZ;
|
|
79
|
+
this.wrap = wrap;
|
|
80
|
+
this.canonical = new CanonicalTileID(z, +x, +y);
|
|
81
|
+
this.key = calculateKey(wrap, overscaledZ, z, x, y);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
equals(id: OverscaledTileID) {
|
|
85
|
+
return this.overscaledZ === id.overscaledZ && this.wrap === id.wrap && this.canonical.equals(id.canonical);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
scaledTo(targetZ: number) {
|
|
89
|
+
assert(targetZ <= this.overscaledZ);
|
|
90
|
+
const zDifference = this.canonical.z - targetZ;
|
|
91
|
+
if (targetZ > this.canonical.z) {
|
|
92
|
+
return new OverscaledTileID(targetZ, this.wrap, this.canonical.z, this.canonical.x, this.canonical.y);
|
|
93
|
+
} else {
|
|
94
|
+
return new OverscaledTileID(targetZ, this.wrap, targetZ, this.canonical.x >> zDifference, this.canonical.y >> zDifference);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/*
|
|
99
|
+
* calculateScaledKey is an optimization:
|
|
100
|
+
* when withWrap == true, implements the same as this.scaledTo(z).key,
|
|
101
|
+
* when withWrap == false, implements the same as this.scaledTo(z).wrapped().key.
|
|
102
|
+
*/
|
|
103
|
+
calculateScaledKey(targetZ: number, withWrap: boolean): string {
|
|
104
|
+
assert(targetZ <= this.overscaledZ);
|
|
105
|
+
const zDifference = this.canonical.z - targetZ;
|
|
106
|
+
if (targetZ > this.canonical.z) {
|
|
107
|
+
return calculateKey(this.wrap * +withWrap, targetZ, this.canonical.z, this.canonical.x, this.canonical.y);
|
|
108
|
+
} else {
|
|
109
|
+
return calculateKey(this.wrap * +withWrap, targetZ, targetZ, this.canonical.x >> zDifference, this.canonical.y >> zDifference);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
isChildOf(parent: OverscaledTileID) {
|
|
114
|
+
if (parent.wrap !== this.wrap) {
|
|
115
|
+
// We can't be a child if we're in a different world copy
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
const zDifference = this.canonical.z - parent.canonical.z;
|
|
119
|
+
// We're first testing for z == 0, to avoid a 32 bit shift, which is undefined.
|
|
120
|
+
return parent.overscaledZ === 0 || (
|
|
121
|
+
parent.overscaledZ < this.overscaledZ &&
|
|
122
|
+
parent.canonical.x === (this.canonical.x >> zDifference) &&
|
|
123
|
+
parent.canonical.y === (this.canonical.y >> zDifference));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
children(sourceMaxZoom: number) {
|
|
127
|
+
if (this.overscaledZ >= sourceMaxZoom) {
|
|
128
|
+
// return a single tile coord representing a an overscaled tile
|
|
129
|
+
return [new OverscaledTileID(this.overscaledZ + 1, this.wrap, this.canonical.z, this.canonical.x, this.canonical.y)];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const z = this.canonical.z + 1;
|
|
133
|
+
const x = this.canonical.x * 2;
|
|
134
|
+
const y = this.canonical.y * 2;
|
|
135
|
+
return [
|
|
136
|
+
new OverscaledTileID(z, this.wrap, z, x, y),
|
|
137
|
+
new OverscaledTileID(z, this.wrap, z, x + 1, y),
|
|
138
|
+
new OverscaledTileID(z, this.wrap, z, x, y + 1),
|
|
139
|
+
new OverscaledTileID(z, this.wrap, z, x + 1, y + 1)
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
isLessThan(rhs: OverscaledTileID) {
|
|
144
|
+
if (this.wrap < rhs.wrap) return true;
|
|
145
|
+
if (this.wrap > rhs.wrap) return false;
|
|
146
|
+
|
|
147
|
+
if (this.overscaledZ < rhs.overscaledZ) return true;
|
|
148
|
+
if (this.overscaledZ > rhs.overscaledZ) return false;
|
|
149
|
+
|
|
150
|
+
if (this.canonical.x < rhs.canonical.x) return true;
|
|
151
|
+
if (this.canonical.x > rhs.canonical.x) return false;
|
|
152
|
+
|
|
153
|
+
if (this.canonical.y < rhs.canonical.y) return true;
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
wrapped() {
|
|
158
|
+
return new OverscaledTileID(this.overscaledZ, 0, this.canonical.z, this.canonical.x, this.canonical.y);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
unwrapTo(wrap: number) {
|
|
162
|
+
return new OverscaledTileID(this.overscaledZ, wrap, this.canonical.z, this.canonical.x, this.canonical.y);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
overscaleFactor() {
|
|
166
|
+
return Math.pow(2, this.overscaledZ - this.canonical.z);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
toUnwrapped() {
|
|
170
|
+
return new UnwrappedTileID(this.wrap, this.canonical);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
toString() {
|
|
174
|
+
return `${this.overscaledZ}/${this.canonical.x}/${this.canonical.y}`;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
getTilePoint(coord: MercatorCoordinate) {
|
|
178
|
+
return this.canonical.getTilePoint(new MercatorCoordinate(coord.x - this.wrap, coord.y));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function calculateKey(wrap: number, overscaledZ: number, z: number, x: number, y: number): string {
|
|
183
|
+
wrap *= 2;
|
|
184
|
+
if (wrap < 0) wrap = wrap * -1 - 1;
|
|
185
|
+
const dim = 1 << z;
|
|
186
|
+
return (dim * dim * wrap + dim * y + x).toString(36) + z.toString(36) + overscaledZ.toString(36);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function getQuadkey(z, x, y) {
|
|
190
|
+
let quadkey = '', mask;
|
|
191
|
+
for (let i = z; i > 0; i--) {
|
|
192
|
+
mask = 1 << (i - 1);
|
|
193
|
+
quadkey += ((x & mask ? 1 : 0) + (y & mask ? 2 : 0));
|
|
194
|
+
}
|
|
195
|
+
return quadkey;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
register('CanonicalTileID', CanonicalTileID);
|
|
199
|
+
register('OverscaledTileID', OverscaledTileID, {omit: ['posMatrix']});
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import {Event, ErrorEvent, Evented} from '../util/evented';
|
|
4
|
+
|
|
5
|
+
import {extend, pick} from '../util/util';
|
|
6
|
+
import loadTileJSON from './load_tilejson';
|
|
7
|
+
import {postTurnstileEvent, postMapLoadEvent} from '../util/mapbox';
|
|
8
|
+
import TileBounds from './tile_bounds';
|
|
9
|
+
import {ResourceType} from '../util/ajax';
|
|
10
|
+
import browser from '../util/browser';
|
|
11
|
+
import {cacheEntryPossiblyAdded} from '../util/tile_request_cache';
|
|
12
|
+
|
|
13
|
+
import type {Source} from './source';
|
|
14
|
+
import type {OverscaledTileID} from './tile_id';
|
|
15
|
+
import type Map from '../ui/map';
|
|
16
|
+
import type Dispatcher from '../util/dispatcher';
|
|
17
|
+
import type Tile from './tile';
|
|
18
|
+
import type {Callback} from '../types/callback';
|
|
19
|
+
import type {Cancelable} from '../types/cancelable';
|
|
20
|
+
import type {VectorSourceSpecification, PromoteIdSpecification} from '../style-spec/types';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A source containing vector tiles in [Mapbox Vector Tile format](https://docs.mapbox.com/vector-tiles/reference/).
|
|
24
|
+
* (See the [Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#vector) for detailed documentation of options.)
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* map.addSource('some id', {
|
|
28
|
+
* type: 'vector',
|
|
29
|
+
* url: 'mapbox://mapbox.mapbox-streets-v6'
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* map.addSource('some id', {
|
|
34
|
+
* type: 'vector',
|
|
35
|
+
* tiles: ['https://d25uarhxywzl1j.cloudfront.net/v0.1/{z}/{x}/{y}.mvt'],
|
|
36
|
+
* minzoom: 6,
|
|
37
|
+
* maxzoom: 14
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* map.getSource('some id').setUrl("mapbox://mapbox.mapbox-streets-v6");
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* map.getSource('some id').setTiles(['https://d25uarhxywzl1j.cloudfront.net/v0.1/{z}/{x}/{y}.mvt']);
|
|
45
|
+
* @see [Add a vector tile source](https://docs.mapbox.com/mapbox-gl-js/example/vector-source/)
|
|
46
|
+
* @see [Add a third party vector tile source](https://docs.mapbox.com/mapbox-gl-js/example/third-party/)
|
|
47
|
+
*/
|
|
48
|
+
class VectorTileSource extends Evented implements Source {
|
|
49
|
+
type: 'vector';
|
|
50
|
+
id: string;
|
|
51
|
+
minzoom: number;
|
|
52
|
+
maxzoom: number;
|
|
53
|
+
url: string;
|
|
54
|
+
scheme: string;
|
|
55
|
+
tileSize: number;
|
|
56
|
+
promoteId: ?PromoteIdSpecification;
|
|
57
|
+
|
|
58
|
+
_options: VectorSourceSpecification;
|
|
59
|
+
_collectResourceTiming: boolean;
|
|
60
|
+
dispatcher: Dispatcher;
|
|
61
|
+
map: Map;
|
|
62
|
+
bounds: ?[number, number, number, number];
|
|
63
|
+
tiles: Array<string>;
|
|
64
|
+
tileBounds: TileBounds;
|
|
65
|
+
reparseOverscaled: boolean;
|
|
66
|
+
isTileClipped: boolean;
|
|
67
|
+
_tileJSONRequest: ?Cancelable;
|
|
68
|
+
_loaded: boolean;
|
|
69
|
+
|
|
70
|
+
constructor(id: string, options: VectorSourceSpecification & {collectResourceTiming: boolean}, dispatcher: Dispatcher, eventedParent: Evented) {
|
|
71
|
+
super();
|
|
72
|
+
this.id = id;
|
|
73
|
+
this.dispatcher = dispatcher;
|
|
74
|
+
|
|
75
|
+
this.type = 'vector';
|
|
76
|
+
this.minzoom = 0;
|
|
77
|
+
this.maxzoom = 22;
|
|
78
|
+
this.scheme = 'xyz';
|
|
79
|
+
this.tileSize = 512;
|
|
80
|
+
this.reparseOverscaled = true;
|
|
81
|
+
this.isTileClipped = true;
|
|
82
|
+
this._loaded = false;
|
|
83
|
+
|
|
84
|
+
extend(this, pick(options, ['url', 'scheme', 'tileSize', 'promoteId']));
|
|
85
|
+
this._options = extend({type: 'vector'}, options);
|
|
86
|
+
|
|
87
|
+
this._collectResourceTiming = options.collectResourceTiming;
|
|
88
|
+
|
|
89
|
+
if (this.tileSize !== 512) {
|
|
90
|
+
throw new Error('vector tile sources must have a tileSize of 512');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
this.setEventedParent(eventedParent);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
load() {
|
|
97
|
+
this._loaded = false;
|
|
98
|
+
this.fire(new Event('dataloading', {dataType: 'source'}));
|
|
99
|
+
this._tileJSONRequest = loadTileJSON(this._options, this.map._requestManager, (err, tileJSON) => {
|
|
100
|
+
this._tileJSONRequest = null;
|
|
101
|
+
this._loaded = true;
|
|
102
|
+
if (err) {
|
|
103
|
+
this.fire(new ErrorEvent(err));
|
|
104
|
+
} else if (tileJSON) {
|
|
105
|
+
extend(this, tileJSON);
|
|
106
|
+
if (tileJSON.bounds) this.tileBounds = new TileBounds(tileJSON.bounds, this.minzoom, this.maxzoom);
|
|
107
|
+
postTurnstileEvent(tileJSON.tiles, this.map._requestManager._customAccessToken);
|
|
108
|
+
postMapLoadEvent(tileJSON.tiles, this.map._getMapId(), this.map._requestManager._skuToken, this.map._requestManager._customAccessToken);
|
|
109
|
+
|
|
110
|
+
// `content` is included here to prevent a race condition where `Style#_updateSources` is called
|
|
111
|
+
// before the TileJSON arrives. this makes sure the tiles needed are loaded once TileJSON arrives
|
|
112
|
+
// ref: https://github.com/mapbox/mapbox-gl-js/pull/4347#discussion_r104418088
|
|
113
|
+
this.fire(new Event('data', {dataType: 'source', sourceDataType: 'metadata'}));
|
|
114
|
+
this.fire(new Event('data', {dataType: 'source', sourceDataType: 'content'}));
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
loaded(): boolean {
|
|
120
|
+
return this._loaded;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
hasTile(tileID: OverscaledTileID) {
|
|
124
|
+
return !this.tileBounds || this.tileBounds.contains(tileID.canonical);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
onAdd(map: Map) {
|
|
128
|
+
this.map = map;
|
|
129
|
+
this.load();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
setSourceProperty(callback: Function) {
|
|
133
|
+
if (this._tileJSONRequest) {
|
|
134
|
+
this._tileJSONRequest.cancel();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
callback();
|
|
138
|
+
|
|
139
|
+
const sourceCache = this.map.style.sourceCaches[this.id];
|
|
140
|
+
sourceCache.clearTiles();
|
|
141
|
+
this.load();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Sets the source `tiles` property and re-renders the map.
|
|
146
|
+
*
|
|
147
|
+
* @param {string[]} tiles An array of one or more tile source URLs, as in the TileJSON spec.
|
|
148
|
+
* @returns {VectorTileSource} this
|
|
149
|
+
*/
|
|
150
|
+
setTiles(tiles: Array<string>) {
|
|
151
|
+
this.setSourceProperty(() => {
|
|
152
|
+
this._options.tiles = tiles;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Sets the source `url` property and re-renders the map.
|
|
160
|
+
*
|
|
161
|
+
* @param {string} url A URL to a TileJSON resource. Supported protocols are `http:`, `https:`, and `mapbox://<Tileset ID>`.
|
|
162
|
+
* @returns {VectorTileSource} this
|
|
163
|
+
*/
|
|
164
|
+
setUrl(url: string) {
|
|
165
|
+
this.setSourceProperty(() => {
|
|
166
|
+
this.url = url;
|
|
167
|
+
this._options.url = url;
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
onRemove() {
|
|
174
|
+
if (this._tileJSONRequest) {
|
|
175
|
+
this._tileJSONRequest.cancel();
|
|
176
|
+
this._tileJSONRequest = null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
serialize() {
|
|
181
|
+
return extend({}, this._options);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
loadTile(tile: Tile, callback: Callback<void>) {
|
|
185
|
+
const url = this.map._requestManager.normalizeTileURL(tile.tileID.canonical.url(this.tiles, this.scheme));
|
|
186
|
+
const params = {
|
|
187
|
+
request: this.map._requestManager.transformRequest(url, ResourceType.Tile),
|
|
188
|
+
uid: tile.uid,
|
|
189
|
+
tileID: tile.tileID,
|
|
190
|
+
zoom: tile.tileID.overscaledZ,
|
|
191
|
+
tileSize: this.tileSize * tile.tileID.overscaleFactor(),
|
|
192
|
+
type: this.type,
|
|
193
|
+
source: this.id,
|
|
194
|
+
pixelRatio: browser.devicePixelRatio,
|
|
195
|
+
showCollisionBoxes: this.map.showCollisionBoxes,
|
|
196
|
+
promoteId: this.promoteId
|
|
197
|
+
};
|
|
198
|
+
params.request.collectResourceTiming = this._collectResourceTiming;
|
|
199
|
+
|
|
200
|
+
if (!tile.actor || tile.state === 'expired') {
|
|
201
|
+
tile.actor = this.dispatcher.getActor();
|
|
202
|
+
tile.request = tile.actor.send('loadTile', params, done.bind(this));
|
|
203
|
+
} else if (tile.state === 'loading') {
|
|
204
|
+
// schedule tile reloading after it has been loaded
|
|
205
|
+
tile.reloadCallback = callback;
|
|
206
|
+
} else {
|
|
207
|
+
tile.request = tile.actor.send('reloadTile', params, done.bind(this));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function done(err, data) {
|
|
211
|
+
delete tile.request;
|
|
212
|
+
|
|
213
|
+
if (tile.aborted)
|
|
214
|
+
return callback(null);
|
|
215
|
+
|
|
216
|
+
if (err && err.status !== 404) {
|
|
217
|
+
return callback(err);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (data && data.resourceTiming)
|
|
221
|
+
tile.resourceTiming = data.resourceTiming;
|
|
222
|
+
|
|
223
|
+
if (this.map._refreshExpiredTiles && data) tile.setExpiryData(data);
|
|
224
|
+
tile.loadVectorData(data, this.map.painter);
|
|
225
|
+
|
|
226
|
+
cacheEntryPossiblyAdded(this.dispatcher);
|
|
227
|
+
|
|
228
|
+
callback(null);
|
|
229
|
+
|
|
230
|
+
if (tile.reloadCallback) {
|
|
231
|
+
this.loadTile(tile, tile.reloadCallback);
|
|
232
|
+
tile.reloadCallback = null;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
abortTile(tile: Tile) {
|
|
238
|
+
if (tile.request) {
|
|
239
|
+
tile.request.cancel();
|
|
240
|
+
delete tile.request;
|
|
241
|
+
}
|
|
242
|
+
if (tile.actor) {
|
|
243
|
+
tile.actor.send('abortTile', {uid: tile.uid, type: this.type, source: this.id}, undefined);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
unloadTile(tile: Tile) {
|
|
248
|
+
tile.unloadVectorData();
|
|
249
|
+
if (tile.actor) {
|
|
250
|
+
tile.actor.send('removeTile', {uid: tile.uid, type: this.type, source: this.id}, undefined);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
hasTransition() {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export default VectorTileSource;
|