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
package/src/index.js
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import assert from 'assert';
|
|
4
|
+
import supported from '@mapbox/mapbox-gl-supported';
|
|
5
|
+
|
|
6
|
+
import {version} from '../package.json';
|
|
7
|
+
import Map from './ui/map';
|
|
8
|
+
import NavigationControl from './ui/control/navigation_control';
|
|
9
|
+
import GeolocateControl from './ui/control/geolocate_control';
|
|
10
|
+
import AttributionControl from './ui/control/attribution_control';
|
|
11
|
+
import ScaleControl from './ui/control/scale_control';
|
|
12
|
+
import FullscreenControl from './ui/control/fullscreen_control';
|
|
13
|
+
import Popup from './ui/popup';
|
|
14
|
+
import Marker from './ui/marker';
|
|
15
|
+
import Style from './style/style';
|
|
16
|
+
import LngLat from './geo/lng_lat';
|
|
17
|
+
import LngLatBounds from './geo/lng_lat_bounds';
|
|
18
|
+
import Point from '@mapbox/point-geometry';
|
|
19
|
+
import MercatorCoordinate from './geo/mercator_coordinate';
|
|
20
|
+
import {Evented} from './util/evented';
|
|
21
|
+
import config from './util/config';
|
|
22
|
+
import {Debug} from './util/debug';
|
|
23
|
+
import {isSafari} from './util/util';
|
|
24
|
+
import {setRTLTextPlugin, getRTLTextPluginStatus} from './source/rtl_text_plugin';
|
|
25
|
+
import WorkerPool from './util/worker_pool';
|
|
26
|
+
import {prewarm, clearPrewarmedResources} from './util/global_worker_pool';
|
|
27
|
+
import {clearTileCache} from './util/tile_request_cache';
|
|
28
|
+
import {PerformanceUtils} from './util/performance';
|
|
29
|
+
|
|
30
|
+
const exported = {
|
|
31
|
+
version,
|
|
32
|
+
supported,
|
|
33
|
+
setRTLTextPlugin,
|
|
34
|
+
getRTLTextPluginStatus,
|
|
35
|
+
Map,
|
|
36
|
+
NavigationControl,
|
|
37
|
+
GeolocateControl,
|
|
38
|
+
AttributionControl,
|
|
39
|
+
ScaleControl,
|
|
40
|
+
FullscreenControl,
|
|
41
|
+
Popup,
|
|
42
|
+
Marker,
|
|
43
|
+
Style,
|
|
44
|
+
LngLat,
|
|
45
|
+
LngLatBounds,
|
|
46
|
+
Point,
|
|
47
|
+
MercatorCoordinate,
|
|
48
|
+
Evented,
|
|
49
|
+
config,
|
|
50
|
+
/**
|
|
51
|
+
* Initializes resources like WebWorkers that can be shared across maps to lower load
|
|
52
|
+
* times in some situations. `mapboxgl.workerUrl` and `mapboxgl.workerCount`, if being
|
|
53
|
+
* used, must be set before `prewarm()` is called to have an effect.
|
|
54
|
+
*
|
|
55
|
+
* By default, the lifecycle of these resources is managed automatically, and they are
|
|
56
|
+
* lazily initialized when a Map is first created. By invoking `prewarm()`, these
|
|
57
|
+
* resources will be created ahead of time, and will not be cleared when the last Map
|
|
58
|
+
* is removed from the page. This allows them to be re-used by new Map instances that
|
|
59
|
+
* are created later. They can be manually cleared by calling
|
|
60
|
+
* `mapboxgl.clearPrewarmedResources()`. This is only necessary if your web page remains
|
|
61
|
+
* active but stops using maps altogether.
|
|
62
|
+
*
|
|
63
|
+
* This is primarily useful when using GL-JS maps in a single page app, wherein a user
|
|
64
|
+
* would navigate between various views that can cause Map instances to constantly be
|
|
65
|
+
* created and destroyed.
|
|
66
|
+
*
|
|
67
|
+
* @function prewarm
|
|
68
|
+
* @example
|
|
69
|
+
* mapboxgl.prewarm()
|
|
70
|
+
*/
|
|
71
|
+
prewarm,
|
|
72
|
+
/**
|
|
73
|
+
* Clears up resources that have previously been created by `mapboxgl.prewarm()`.
|
|
74
|
+
* Note that this is typically not necessary. You should only call this function
|
|
75
|
+
* if you expect the user of your app to not return to a Map view at any point
|
|
76
|
+
* in your application.
|
|
77
|
+
*
|
|
78
|
+
* @function clearPrewarmedResources
|
|
79
|
+
* @example
|
|
80
|
+
* mapboxgl.clearPrewarmedResources()
|
|
81
|
+
*/
|
|
82
|
+
clearPrewarmedResources,
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Gets and sets the map's [access token](https://www.mapbox.com/help/define-access-token/).
|
|
86
|
+
*
|
|
87
|
+
* @var {string} accessToken
|
|
88
|
+
* @returns {string} The currently set access token.
|
|
89
|
+
* @example
|
|
90
|
+
* mapboxgl.accessToken = myAccessToken;
|
|
91
|
+
* @see [Display a map](https://www.mapbox.com/mapbox-gl-js/examples/)
|
|
92
|
+
*/
|
|
93
|
+
get accessToken(): ?string {
|
|
94
|
+
return config.ACCESS_TOKEN;
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
set accessToken(token: string) {
|
|
98
|
+
config.ACCESS_TOKEN = token;
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Gets and sets the map's default API URL for requesting tiles, styles, sprites, and glyphs
|
|
103
|
+
*
|
|
104
|
+
* @var {string} baseApiUrl
|
|
105
|
+
* @returns {string} The current base API URL.
|
|
106
|
+
* @example
|
|
107
|
+
* mapboxgl.baseApiUrl = 'https://api.mapbox.com';
|
|
108
|
+
*/
|
|
109
|
+
get baseApiUrl(): ?string {
|
|
110
|
+
return config.API_URL;
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
set baseApiUrl(url: string) {
|
|
114
|
+
config.API_URL = url;
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Gets and sets the number of web workers instantiated on a page with GL JS maps.
|
|
119
|
+
* By default, it is set to half the number of CPU cores (capped at 6).
|
|
120
|
+
* Make sure to set this property before creating any map instances for it to have effect.
|
|
121
|
+
*
|
|
122
|
+
* @var {string} workerCount
|
|
123
|
+
* @returns {number} Number of workers currently configured.
|
|
124
|
+
* @example
|
|
125
|
+
* mapboxgl.workerCount = 2;
|
|
126
|
+
*/
|
|
127
|
+
get workerCount(): number {
|
|
128
|
+
return WorkerPool.workerCount;
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
set workerCount(count: number) {
|
|
132
|
+
WorkerPool.workerCount = count;
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Gets and sets the maximum number of images (raster tiles, sprites, icons) to load in parallel,
|
|
137
|
+
* which affects performance in raster-heavy maps. 16 by default.
|
|
138
|
+
*
|
|
139
|
+
* @var {string} maxParallelImageRequests
|
|
140
|
+
* @returns {number} Number of parallel requests currently configured.
|
|
141
|
+
* @example
|
|
142
|
+
* mapboxgl.maxParallelImageRequests = 10;
|
|
143
|
+
*/
|
|
144
|
+
get maxParallelImageRequests(): number {
|
|
145
|
+
return config.MAX_PARALLEL_IMAGE_REQUESTS;
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
set maxParallelImageRequests(numRequests: number) {
|
|
149
|
+
config.MAX_PARALLEL_IMAGE_REQUESTS = numRequests;
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Clears browser storage used by this library. Using this method flushes the Mapbox tile
|
|
154
|
+
* cache that is managed by this library. Tiles may still be cached by the browser
|
|
155
|
+
* in some cases.
|
|
156
|
+
*
|
|
157
|
+
* This API is supported on browsers where the [`Cache` API](https://developer.mozilla.org/en-US/docs/Web/API/Cache)
|
|
158
|
+
* is supported and enabled. This includes all major browsers when pages are served over
|
|
159
|
+
* `https://`, except Internet Explorer and Edge Mobile.
|
|
160
|
+
*
|
|
161
|
+
* When called in unsupported browsers or environments (private or incognito mode), the
|
|
162
|
+
* callback will be called with an error argument.
|
|
163
|
+
*
|
|
164
|
+
* @function clearStorage
|
|
165
|
+
* @param {Function} callback Called with an error argument if there is an error.
|
|
166
|
+
* @example
|
|
167
|
+
* mapboxgl.clearStorage();
|
|
168
|
+
*/
|
|
169
|
+
clearStorage(callback?: (err: ?Error) => void) {
|
|
170
|
+
clearTileCache(callback);
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
workerUrl: ''
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
//This gets automatically stripped out in production builds.
|
|
177
|
+
Debug.extend(exported, {isSafari, getPerformanceMetrics: PerformanceUtils.getPerformanceMetrics});
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The version of Mapbox GL JS in use as specified in `package.json`,
|
|
181
|
+
* `CHANGELOG.md`, and the GitHub release.
|
|
182
|
+
*
|
|
183
|
+
* @var {string} version
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Test whether the browser [supports Mapbox GL JS](https://www.mapbox.com/help/mapbox-browser-support/#mapbox-gl-js).
|
|
188
|
+
*
|
|
189
|
+
* @function supported
|
|
190
|
+
* @param {Object} [options]
|
|
191
|
+
* @param {boolean} [options.failIfMajorPerformanceCaveat=false] If `true`,
|
|
192
|
+
* the function will return `false` if the performance of Mapbox GL JS would
|
|
193
|
+
* be dramatically worse than expected (e.g. a software WebGL renderer would be used).
|
|
194
|
+
* @return {boolean}
|
|
195
|
+
* @example
|
|
196
|
+
* // Show an alert if the browser does not support Mapbox GL
|
|
197
|
+
* if (!mapboxgl.supported()) {
|
|
198
|
+
* alert('Your browser does not support Mapbox GL');
|
|
199
|
+
* }
|
|
200
|
+
* @see [Check for browser support](https://www.mapbox.com/mapbox-gl-js/example/check-for-support/)
|
|
201
|
+
*/
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Sets the map's [RTL text plugin](https://www.mapbox.com/mapbox-gl-js/plugins/#mapbox-gl-rtl-text).
|
|
205
|
+
* Necessary for supporting the Arabic and Hebrew languages, which are written right-to-left. Mapbox Studio loads this plugin by default.
|
|
206
|
+
*
|
|
207
|
+
* @function setRTLTextPlugin
|
|
208
|
+
* @param {string} pluginURL URL pointing to the Mapbox RTL text plugin source.
|
|
209
|
+
* @param {Function} callback Called with an error argument if there is an error.
|
|
210
|
+
* @param {boolean} lazy If set to `true`, mapboxgl will defer loading the plugin until rtl text is encountered,
|
|
211
|
+
* rtl text will then be rendered only after the plugin finishes loading.
|
|
212
|
+
* @example
|
|
213
|
+
* mapboxgl.setRTLTextPlugin('https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.0/mapbox-gl-rtl-text.js');
|
|
214
|
+
* @see [Add support for right-to-left scripts](https://www.mapbox.com/mapbox-gl-js/example/mapbox-gl-rtl-text/)
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Gets the map's [RTL text plugin](https://www.mapbox.com/mapbox-gl-js/plugins/#mapbox-gl-rtl-text) status.
|
|
219
|
+
* The status can be `unavailable` (i.e. not requested or removed), `loading`, `loaded` or `error`.
|
|
220
|
+
* If the status is `loaded` and the plugin is requested again, an error will be thrown.
|
|
221
|
+
*
|
|
222
|
+
* @function getRTLTextPluginStatus
|
|
223
|
+
* @example
|
|
224
|
+
* const pluginStatus = mapboxgl.getRTLTextPluginStatus();
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
export default exported;
|
|
228
|
+
|
|
229
|
+
// canary assert: used to confirm that asserts have been removed from production build
|
|
230
|
+
assert(true, 'canary assert');
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import StencilMode from '../gl/stencil_mode';
|
|
4
|
+
import DepthMode from '../gl/depth_mode';
|
|
5
|
+
import CullFaceMode from '../gl/cull_face_mode';
|
|
6
|
+
import {
|
|
7
|
+
backgroundUniformValues,
|
|
8
|
+
backgroundPatternUniformValues
|
|
9
|
+
} from './program/background_program';
|
|
10
|
+
|
|
11
|
+
import type Painter from './painter';
|
|
12
|
+
import type SourceCache from '../source/source_cache';
|
|
13
|
+
import type BackgroundStyleLayer from '../style/style_layer/background_style_layer';
|
|
14
|
+
|
|
15
|
+
export default drawBackground;
|
|
16
|
+
|
|
17
|
+
function drawBackground(painter: Painter, sourceCache: SourceCache, layer: BackgroundStyleLayer) {
|
|
18
|
+
const color = layer.paint.get('background-color');
|
|
19
|
+
const opacity = layer.paint.get('background-opacity');
|
|
20
|
+
|
|
21
|
+
if (opacity === 0) return;
|
|
22
|
+
|
|
23
|
+
const context = painter.context;
|
|
24
|
+
const gl = context.gl;
|
|
25
|
+
const transform = painter.transform;
|
|
26
|
+
const tileSize = transform.tileSize;
|
|
27
|
+
const image = layer.paint.get('background-pattern');
|
|
28
|
+
if (painter.isPatternMissing(image)) return;
|
|
29
|
+
|
|
30
|
+
const pass = (!image && color.a === 1 && opacity === 1 && painter.opaquePassEnabledForLayer()) ? 'opaque' : 'translucent';
|
|
31
|
+
if (painter.renderPass !== pass) return;
|
|
32
|
+
|
|
33
|
+
const stencilMode = StencilMode.disabled;
|
|
34
|
+
const depthMode = painter.depthModeForSublayer(0, pass === 'opaque' ? DepthMode.ReadWrite : DepthMode.ReadOnly);
|
|
35
|
+
const colorMode = painter.colorModeForRenderPass();
|
|
36
|
+
|
|
37
|
+
const program = painter.useProgram(image ? 'backgroundPattern' : 'background');
|
|
38
|
+
|
|
39
|
+
const tileIDs = transform.coveringTiles({tileSize});
|
|
40
|
+
|
|
41
|
+
if (image) {
|
|
42
|
+
context.activeTexture.set(gl.TEXTURE0);
|
|
43
|
+
painter.imageManager.bind(painter.context);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const crossfade = layer.getCrossfadeParameters();
|
|
47
|
+
for (const tileID of tileIDs) {
|
|
48
|
+
const matrix = painter.transform.calculatePosMatrix(tileID.toUnwrapped());
|
|
49
|
+
const uniformValues = image ?
|
|
50
|
+
backgroundPatternUniformValues(matrix, opacity, painter, image, {tileID, tileSize}, crossfade) :
|
|
51
|
+
backgroundUniformValues(matrix, opacity, color);
|
|
52
|
+
|
|
53
|
+
program.draw(context, gl.TRIANGLES, depthMode, stencilMode, colorMode, CullFaceMode.disabled,
|
|
54
|
+
uniformValues, layer.id, painter.tileExtentBuffer,
|
|
55
|
+
painter.quadTriangleIndexBuffer, painter.tileExtentSegments);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import StencilMode from '../gl/stencil_mode';
|
|
4
|
+
import DepthMode from '../gl/depth_mode';
|
|
5
|
+
import CullFaceMode from '../gl/cull_face_mode';
|
|
6
|
+
import Program from './program';
|
|
7
|
+
import {circleUniformValues} from './program/circle_program';
|
|
8
|
+
import SegmentVector from '../data/segment';
|
|
9
|
+
import {OverscaledTileID} from '../source/tile_id';
|
|
10
|
+
|
|
11
|
+
import type Painter from './painter';
|
|
12
|
+
import type SourceCache from '../source/source_cache';
|
|
13
|
+
import type CircleStyleLayer from '../style/style_layer/circle_style_layer';
|
|
14
|
+
import type CircleBucket from '../data/bucket/circle_bucket';
|
|
15
|
+
import type ProgramConfiguration from '../data/program_configuration';
|
|
16
|
+
import type VertexBuffer from '../gl/vertex_buffer';
|
|
17
|
+
import type IndexBuffer from '../gl/index_buffer';
|
|
18
|
+
import type {UniformValues} from './uniform_binding';
|
|
19
|
+
import type {CircleUniformsType} from './program/circle_program';
|
|
20
|
+
|
|
21
|
+
export default drawCircles;
|
|
22
|
+
|
|
23
|
+
type TileRenderState = {
|
|
24
|
+
programConfiguration: ProgramConfiguration,
|
|
25
|
+
program: Program<*>,
|
|
26
|
+
layoutVertexBuffer: VertexBuffer,
|
|
27
|
+
indexBuffer: IndexBuffer,
|
|
28
|
+
uniformValues: UniformValues<CircleUniformsType>
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type SegmentsTileRenderState = {
|
|
32
|
+
segments: SegmentVector,
|
|
33
|
+
sortKey: number,
|
|
34
|
+
state: TileRenderState
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function drawCircles(painter: Painter, sourceCache: SourceCache, layer: CircleStyleLayer, coords: Array<OverscaledTileID>) {
|
|
38
|
+
if (painter.renderPass !== 'translucent') return;
|
|
39
|
+
|
|
40
|
+
const opacity = layer.paint.get('circle-opacity');
|
|
41
|
+
const strokeWidth = layer.paint.get('circle-stroke-width');
|
|
42
|
+
const strokeOpacity = layer.paint.get('circle-stroke-opacity');
|
|
43
|
+
const sortFeaturesByKey = layer.layout.get('circle-sort-key').constantOr(1) !== undefined;
|
|
44
|
+
|
|
45
|
+
if (opacity.constantOr(1) === 0 && (strokeWidth.constantOr(1) === 0 || strokeOpacity.constantOr(1) === 0)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const context = painter.context;
|
|
50
|
+
const gl = context.gl;
|
|
51
|
+
|
|
52
|
+
const depthMode = painter.depthModeForSublayer(0, DepthMode.ReadOnly);
|
|
53
|
+
// Turn off stencil testing to allow circles to be drawn across boundaries,
|
|
54
|
+
// so that large circles are not clipped to tiles
|
|
55
|
+
const stencilMode = StencilMode.disabled;
|
|
56
|
+
const colorMode = painter.colorModeForRenderPass();
|
|
57
|
+
|
|
58
|
+
const segmentsRenderStates: Array<SegmentsTileRenderState> = [];
|
|
59
|
+
|
|
60
|
+
for (let i = 0; i < coords.length; i++) {
|
|
61
|
+
const coord = coords[i];
|
|
62
|
+
|
|
63
|
+
const tile = sourceCache.getTile(coord);
|
|
64
|
+
const bucket: ?CircleBucket<*> = (tile.getBucket(layer): any);
|
|
65
|
+
if (!bucket) continue;
|
|
66
|
+
|
|
67
|
+
const programConfiguration = bucket.programConfigurations.get(layer.id);
|
|
68
|
+
const program = painter.useProgram('circle', programConfiguration);
|
|
69
|
+
const layoutVertexBuffer = bucket.layoutVertexBuffer;
|
|
70
|
+
const indexBuffer = bucket.indexBuffer;
|
|
71
|
+
const uniformValues = circleUniformValues(painter, coord, tile, layer);
|
|
72
|
+
|
|
73
|
+
const state: TileRenderState = {
|
|
74
|
+
programConfiguration,
|
|
75
|
+
program,
|
|
76
|
+
layoutVertexBuffer,
|
|
77
|
+
indexBuffer,
|
|
78
|
+
uniformValues,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
if (sortFeaturesByKey) {
|
|
82
|
+
const oldSegments = bucket.segments.get();
|
|
83
|
+
for (const segment of oldSegments) {
|
|
84
|
+
segmentsRenderStates.push({
|
|
85
|
+
segments: new SegmentVector([segment]),
|
|
86
|
+
sortKey: ((segment.sortKey: any): number),
|
|
87
|
+
state
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
segmentsRenderStates.push({
|
|
92
|
+
segments: bucket.segments,
|
|
93
|
+
sortKey: 0,
|
|
94
|
+
state
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (sortFeaturesByKey) {
|
|
101
|
+
segmentsRenderStates.sort((a, b) => a.sortKey - b.sortKey);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
for (const segmentsState of segmentsRenderStates) {
|
|
105
|
+
const {programConfiguration, program, layoutVertexBuffer, indexBuffer, uniformValues} = segmentsState.state;
|
|
106
|
+
const segments = segmentsState.segments;
|
|
107
|
+
|
|
108
|
+
program.draw(context, gl.TRIANGLES, depthMode, stencilMode, colorMode, CullFaceMode.disabled,
|
|
109
|
+
uniformValues, layer.id,
|
|
110
|
+
layoutVertexBuffer, indexBuffer, segments,
|
|
111
|
+
layer.paint, painter.transform.zoom, programConfiguration);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import type Painter from './painter';
|
|
4
|
+
import type SourceCache from '../source/source_cache';
|
|
5
|
+
import type StyleLayer from '../style/style_layer';
|
|
6
|
+
import type {OverscaledTileID} from '../source/tile_id';
|
|
7
|
+
import type SymbolBucket from '../data/bucket/symbol_bucket';
|
|
8
|
+
import DepthMode from '../gl/depth_mode';
|
|
9
|
+
import StencilMode from '../gl/stencil_mode';
|
|
10
|
+
import CullFaceMode from '../gl/cull_face_mode';
|
|
11
|
+
import {collisionUniformValues, collisionCircleUniformValues} from './program/collision_program';
|
|
12
|
+
|
|
13
|
+
import {QuadTriangleArray, CollisionCircleLayoutArray} from '../data/array_types';
|
|
14
|
+
import {collisionCircleLayout} from '../data/bucket/symbol_attributes';
|
|
15
|
+
import SegmentVector from '../data/segment';
|
|
16
|
+
import {mat4} from 'gl-matrix';
|
|
17
|
+
import VertexBuffer from '../gl/vertex_buffer';
|
|
18
|
+
import IndexBuffer from '../gl/index_buffer';
|
|
19
|
+
|
|
20
|
+
export default drawCollisionDebug;
|
|
21
|
+
|
|
22
|
+
type TileBatch = {
|
|
23
|
+
circleArray: Array<number>,
|
|
24
|
+
circleOffset: number,
|
|
25
|
+
transform: mat4,
|
|
26
|
+
invTransform: mat4
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
let quadTriangles: ?QuadTriangleArray;
|
|
30
|
+
|
|
31
|
+
function drawCollisionDebug(painter: Painter, sourceCache: SourceCache, layer: StyleLayer, coords: Array<OverscaledTileID>, translate: [number, number], translateAnchor: 'map' | 'viewport', isText: boolean) {
|
|
32
|
+
const context = painter.context;
|
|
33
|
+
const gl = context.gl;
|
|
34
|
+
const program = painter.useProgram('collisionBox');
|
|
35
|
+
const tileBatches: Array<TileBatch> = [];
|
|
36
|
+
let circleCount = 0;
|
|
37
|
+
let circleOffset = 0;
|
|
38
|
+
|
|
39
|
+
for (let i = 0; i < coords.length; i++) {
|
|
40
|
+
const coord = coords[i];
|
|
41
|
+
const tile = sourceCache.getTile(coord);
|
|
42
|
+
const bucket: ?SymbolBucket = (tile.getBucket(layer): any);
|
|
43
|
+
if (!bucket) continue;
|
|
44
|
+
let posMatrix = coord.posMatrix;
|
|
45
|
+
if (translate[0] !== 0 || translate[1] !== 0) {
|
|
46
|
+
posMatrix = painter.translatePosMatrix(coord.posMatrix, tile, translate, translateAnchor);
|
|
47
|
+
}
|
|
48
|
+
const buffers = isText ? bucket.textCollisionBox : bucket.iconCollisionBox;
|
|
49
|
+
// Get collision circle data of this bucket
|
|
50
|
+
const circleArray: Array<number> = bucket.collisionCircleArray;
|
|
51
|
+
if (circleArray.length > 0) {
|
|
52
|
+
// We need to know the projection matrix that was used for projecting collision circles to the screen.
|
|
53
|
+
// This might vary between buckets as the symbol placement is a continous process. This matrix is
|
|
54
|
+
// required for transforming points from previous screen space to the current one
|
|
55
|
+
const invTransform = mat4.create();
|
|
56
|
+
const transform = posMatrix;
|
|
57
|
+
|
|
58
|
+
mat4.mul(invTransform, bucket.placementInvProjMatrix, painter.transform.glCoordMatrix);
|
|
59
|
+
mat4.mul(invTransform, invTransform, bucket.placementViewportMatrix);
|
|
60
|
+
|
|
61
|
+
tileBatches.push({
|
|
62
|
+
circleArray,
|
|
63
|
+
circleOffset,
|
|
64
|
+
transform,
|
|
65
|
+
invTransform
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
circleCount += circleArray.length / 4; // 4 values per circle
|
|
69
|
+
circleOffset = circleCount;
|
|
70
|
+
}
|
|
71
|
+
if (!buffers) continue;
|
|
72
|
+
program.draw(context, gl.LINES,
|
|
73
|
+
DepthMode.disabled, StencilMode.disabled,
|
|
74
|
+
painter.colorModeForRenderPass(),
|
|
75
|
+
CullFaceMode.disabled,
|
|
76
|
+
collisionUniformValues(
|
|
77
|
+
posMatrix,
|
|
78
|
+
painter.transform,
|
|
79
|
+
tile),
|
|
80
|
+
layer.id, buffers.layoutVertexBuffer, buffers.indexBuffer,
|
|
81
|
+
buffers.segments, null, painter.transform.zoom, null, null,
|
|
82
|
+
buffers.collisionVertexBuffer);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!isText || !tileBatches.length) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Render collision circles
|
|
90
|
+
const circleProgram = painter.useProgram('collisionCircle');
|
|
91
|
+
|
|
92
|
+
// Construct vertex data
|
|
93
|
+
const vertexData = new CollisionCircleLayoutArray();
|
|
94
|
+
vertexData.resize(circleCount * 4);
|
|
95
|
+
vertexData._trim();
|
|
96
|
+
|
|
97
|
+
let vertexOffset = 0;
|
|
98
|
+
|
|
99
|
+
for (const batch of tileBatches) {
|
|
100
|
+
for (let i = 0; i < batch.circleArray.length / 4; i++) {
|
|
101
|
+
const circleIdx = i * 4;
|
|
102
|
+
const x = batch.circleArray[circleIdx + 0];
|
|
103
|
+
const y = batch.circleArray[circleIdx + 1];
|
|
104
|
+
const radius = batch.circleArray[circleIdx + 2];
|
|
105
|
+
const collision = batch.circleArray[circleIdx + 3];
|
|
106
|
+
|
|
107
|
+
// 4 floats per vertex, 4 vertices per quad
|
|
108
|
+
vertexData.emplace(vertexOffset++, x, y, radius, collision, 0);
|
|
109
|
+
vertexData.emplace(vertexOffset++, x, y, radius, collision, 1);
|
|
110
|
+
vertexData.emplace(vertexOffset++, x, y, radius, collision, 2);
|
|
111
|
+
vertexData.emplace(vertexOffset++, x, y, radius, collision, 3);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!quadTriangles || quadTriangles.length < circleCount * 2) {
|
|
115
|
+
quadTriangles = createQuadTriangles(circleCount);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const indexBuffer: IndexBuffer = context.createIndexBuffer(quadTriangles, true);
|
|
119
|
+
const vertexBuffer: VertexBuffer = context.createVertexBuffer(vertexData, collisionCircleLayout.members, true);
|
|
120
|
+
|
|
121
|
+
// Render batches
|
|
122
|
+
for (const batch of tileBatches) {
|
|
123
|
+
const uniforms = collisionCircleUniformValues(
|
|
124
|
+
batch.transform,
|
|
125
|
+
batch.invTransform,
|
|
126
|
+
painter.transform
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
circleProgram.draw(
|
|
130
|
+
context,
|
|
131
|
+
gl.TRIANGLES,
|
|
132
|
+
DepthMode.disabled,
|
|
133
|
+
StencilMode.disabled,
|
|
134
|
+
painter.colorModeForRenderPass(),
|
|
135
|
+
CullFaceMode.disabled,
|
|
136
|
+
uniforms,
|
|
137
|
+
layer.id,
|
|
138
|
+
vertexBuffer,
|
|
139
|
+
indexBuffer,
|
|
140
|
+
SegmentVector.simpleSegment(0, batch.circleOffset * 2, batch.circleArray.length, batch.circleArray.length / 2),
|
|
141
|
+
null,
|
|
142
|
+
painter.transform.zoom,
|
|
143
|
+
null,
|
|
144
|
+
null,
|
|
145
|
+
null);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
vertexBuffer.destroy();
|
|
149
|
+
indexBuffer.destroy();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function createQuadTriangles(quadCount: number): QuadTriangleArray {
|
|
153
|
+
const triCount = quadCount * 2;
|
|
154
|
+
const array = new QuadTriangleArray();
|
|
155
|
+
|
|
156
|
+
array.resize(triCount);
|
|
157
|
+
array._trim();
|
|
158
|
+
|
|
159
|
+
// Two triangles and 4 vertices per quad.
|
|
160
|
+
for (let i = 0; i < triCount; i++) {
|
|
161
|
+
const idx = i * 6;
|
|
162
|
+
|
|
163
|
+
array.uint16[idx + 0] = i * 4 + 0;
|
|
164
|
+
array.uint16[idx + 1] = i * 4 + 1;
|
|
165
|
+
array.uint16[idx + 2] = i * 4 + 2;
|
|
166
|
+
array.uint16[idx + 3] = i * 4 + 2;
|
|
167
|
+
array.uint16[idx + 4] = i * 4 + 3;
|
|
168
|
+
array.uint16[idx + 5] = i * 4 + 0;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return array;
|
|
172
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
export default drawCustom;
|
|
4
|
+
|
|
5
|
+
import DepthMode from '../gl/depth_mode';
|
|
6
|
+
import StencilMode from '../gl/stencil_mode';
|
|
7
|
+
|
|
8
|
+
import type Painter from './painter';
|
|
9
|
+
import type SourceCache from '../source/source_cache';
|
|
10
|
+
import type CustomStyleLayer from '../style/style_layer/custom_style_layer';
|
|
11
|
+
|
|
12
|
+
function drawCustom(painter: Painter, sourceCache: SourceCache, layer: CustomStyleLayer) {
|
|
13
|
+
|
|
14
|
+
const context = painter.context;
|
|
15
|
+
const implementation = layer.implementation;
|
|
16
|
+
|
|
17
|
+
if (painter.renderPass === 'offscreen') {
|
|
18
|
+
|
|
19
|
+
const prerender = implementation.prerender;
|
|
20
|
+
if (prerender) {
|
|
21
|
+
painter.setCustomLayerDefaults();
|
|
22
|
+
context.setColorMode(painter.colorModeForRenderPass());
|
|
23
|
+
|
|
24
|
+
prerender.call(implementation, context.gl, painter.transform.customLayerMatrix());
|
|
25
|
+
|
|
26
|
+
context.setDirty();
|
|
27
|
+
painter.setBaseState();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
} else if (painter.renderPass === 'translucent') {
|
|
31
|
+
|
|
32
|
+
painter.setCustomLayerDefaults();
|
|
33
|
+
|
|
34
|
+
context.setColorMode(painter.colorModeForRenderPass());
|
|
35
|
+
context.setStencilMode(StencilMode.disabled);
|
|
36
|
+
|
|
37
|
+
const depthMode = implementation.renderingMode === '3d' ?
|
|
38
|
+
new DepthMode(painter.context.gl.LEQUAL, DepthMode.ReadWrite, painter.depthRangeFor3D) :
|
|
39
|
+
painter.depthModeForSublayer(0, DepthMode.ReadOnly);
|
|
40
|
+
|
|
41
|
+
context.setDepthMode(depthMode);
|
|
42
|
+
|
|
43
|
+
implementation.render(context.gl, painter.transform.customLayerMatrix());
|
|
44
|
+
|
|
45
|
+
context.setDirty();
|
|
46
|
+
painter.setBaseState();
|
|
47
|
+
context.bindFramebuffer.set(null);
|
|
48
|
+
}
|
|
49
|
+
}
|