@mapwhit/tilerenderer 0.47.1
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/LICENSE.txt +87 -0
- package/README.md +25 -0
- package/build/min/.dir +0 -0
- package/build/min/package.json +3 -0
- package/build/min/src/shaders/_prelude.fragment.glsl.txt +13 -0
- package/build/min/src/shaders/_prelude.vertex.glsl.txt +14 -0
- package/build/min/src/shaders/background.fragment.glsl.txt +5 -0
- package/build/min/src/shaders/background.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/background_pattern.fragment.glsl.txt +5 -0
- package/build/min/src/shaders/background_pattern.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/circle.fragment.glsl.txt +20 -0
- package/build/min/src/shaders/circle.vertex.glsl.txt +17 -0
- package/build/min/src/shaders/clipping_mask.fragment.glsl.txt +1 -0
- package/build/min/src/shaders/clipping_mask.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/collision_box.fragment.glsl.txt +1 -0
- package/build/min/src/shaders/collision_box.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/collision_circle.fragment.glsl.txt +1 -0
- package/build/min/src/shaders/collision_circle.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/debug.fragment.glsl.txt +1 -0
- package/build/min/src/shaders/debug.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/fill.fragment.glsl.txt +10 -0
- package/build/min/src/shaders/fill.vertex.glsl.txt +7 -0
- package/build/min/src/shaders/fill_extrusion.fragment.glsl.txt +13 -0
- package/build/min/src/shaders/fill_extrusion.vertex.glsl.txt +9 -0
- package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.txt +15 -0
- package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.txt +11 -0
- package/build/min/src/shaders/fill_outline.fragment.glsl.txt +10 -0
- package/build/min/src/shaders/fill_outline.vertex.glsl.txt +7 -0
- package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.txt +13 -0
- package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.txt +9 -0
- package/build/min/src/shaders/fill_pattern.fragment.glsl.txt +13 -0
- package/build/min/src/shaders/fill_pattern.vertex.glsl.txt +9 -0
- package/build/min/src/shaders/heatmap.fragment.glsl.txt +10 -0
- package/build/min/src/shaders/heatmap.vertex.glsl.txt +8 -0
- package/build/min/src/shaders/heatmap_texture.fragment.glsl.txt +5 -0
- package/build/min/src/shaders/heatmap_texture.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/hillshade.fragment.glsl.txt +7 -0
- package/build/min/src/shaders/hillshade.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/hillshade_prepare.fragment.glsl.txt +8 -0
- package/build/min/src/shaders/hillshade_prepare.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/line.fragment.glsl.txt +12 -0
- package/build/min/src/shaders/line.vertex.glsl.txt +17 -0
- package/build/min/src/shaders/line_gradient.fragment.glsl.txt +10 -0
- package/build/min/src/shaders/line_gradient.vertex.glsl.txt +16 -0
- package/build/min/src/shaders/line_pattern.fragment.glsl.txt +15 -0
- package/build/min/src/shaders/line_pattern.vertex.glsl.txt +20 -0
- package/build/min/src/shaders/line_sdf.fragment.glsl.txt +17 -0
- package/build/min/src/shaders/line_sdf.vertex.glsl.txt +20 -0
- package/build/min/src/shaders/raster.fragment.glsl.txt +5 -0
- package/build/min/src/shaders/raster.vertex.glsl.txt +1 -0
- package/build/min/src/shaders/symbol_icon.fragment.glsl.txt +9 -0
- package/build/min/src/shaders/symbol_icon.vertex.glsl.txt +5 -0
- package/build/min/src/shaders/symbol_sdf.fragment.glsl.txt +19 -0
- package/build/min/src/shaders/symbol_sdf.vertex.glsl.txt +13 -0
- package/package.json +44 -0
- package/src/css/mapbox-gl.css +506 -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-background.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-geolocate.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-logo-compact.svg +2 -0
- package/src/css/svg/mapboxgl-ctrl-logo.svg +1 -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 +1138 -0
- package/src/data/bucket/circle_attributes.js +5 -0
- package/src/data/bucket/circle_bucket.js +118 -0
- package/src/data/bucket/fill_attributes.js +5 -0
- package/src/data/bucket/fill_bucket.js +166 -0
- package/src/data/bucket/fill_extrusion_attributes.js +11 -0
- package/src/data/bucket/fill_extrusion_bucket.js +247 -0
- package/src/data/bucket/heatmap_bucket.js +12 -0
- package/src/data/bucket/line_attributes.js +11 -0
- package/src/data/bucket/line_bucket.js +625 -0
- package/src/data/bucket/pattern_attributes.js +9 -0
- package/src/data/bucket/pattern_bucket_features.js +44 -0
- package/src/data/bucket/symbol_attributes.js +95 -0
- package/src/data/bucket/symbol_bucket.js +697 -0
- package/src/data/bucket.js +53 -0
- package/src/data/dem_data.js +126 -0
- package/src/data/extent.js +17 -0
- package/src/data/feature_index.js +254 -0
- package/src/data/index_array_type.js +14 -0
- package/src/data/load_geometry.js +42 -0
- package/src/data/pos_attributes.js +3 -0
- package/src/data/program_configuration.js +782 -0
- package/src/data/raster_bounds_attributes.js +6 -0
- package/src/data/segment.js +63 -0
- package/src/geo/coordinate.js +78 -0
- package/src/geo/lng_lat.js +129 -0
- package/src/geo/lng_lat_bounds.js +253 -0
- package/src/geo/transform.js +605 -0
- package/src/gl/color_mode.js +21 -0
- package/src/gl/context.js +193 -0
- package/src/gl/cull_face_mode.js +22 -0
- package/src/gl/depth_mode.js +18 -0
- package/src/gl/framebuffer.js +28 -0
- package/src/gl/index_buffer.js +52 -0
- package/src/gl/stencil_mode.js +17 -0
- package/src/gl/types.js +0 -0
- package/src/gl/value.js +676 -0
- package/src/gl/vertex_buffer.js +101 -0
- package/src/index.js +50 -0
- package/src/render/draw_background.js +60 -0
- package/src/render/draw_circle.js +55 -0
- package/src/render/draw_collision_debug.js +45 -0
- package/src/render/draw_debug.js +429 -0
- package/src/render/draw_fill.js +143 -0
- package/src/render/draw_fill_extrusion.js +101 -0
- package/src/render/draw_heatmap.js +159 -0
- package/src/render/draw_hillshade.js +144 -0
- package/src/render/draw_line.js +99 -0
- package/src/render/draw_raster.js +151 -0
- package/src/render/draw_symbol.js +231 -0
- package/src/render/glyph_atlas.js +55 -0
- package/src/render/glyph_manager.js +145 -0
- package/src/render/image_atlas.js +97 -0
- package/src/render/image_manager.js +183 -0
- package/src/render/line_atlas.js +139 -0
- package/src/render/painter.js +483 -0
- package/src/render/program/background_program.js +46 -0
- package/src/render/program/circle_program.js +40 -0
- package/src/render/program/clipping_mask_program.js +11 -0
- package/src/render/program/collision_program.js +28 -0
- package/src/render/program/debug_program.js +13 -0
- package/src/render/program/fill_extrusion_program.js +76 -0
- package/src/render/program/fill_program.js +60 -0
- package/src/render/program/heatmap_program.js +46 -0
- package/src/render/program/hillshade_program.js +77 -0
- package/src/render/program/line_program.js +119 -0
- package/src/render/program/pattern.js +57 -0
- package/src/render/program/program_uniforms.js +46 -0
- package/src/render/program/raster_program.js +50 -0
- package/src/render/program/symbol_program.js +112 -0
- package/src/render/program.js +133 -0
- package/src/render/texture.js +88 -0
- package/src/render/tile_mask.js +108 -0
- package/src/render/uniform_binding.js +129 -0
- package/src/render/vertex_array_object.js +155 -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 +63 -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 +26 -0
- package/src/shaders/collision_circle.fragment.glsl +34 -0
- package/src/shaders/collision_circle.vertex.glsl +36 -0
- package/src/shaders/debug.fragment.glsl +5 -0
- package/src/shaders/debug.vertex.glsl +7 -0
- package/src/shaders/encode_attribute.js +19 -0
- package/src/shaders/fill.fragment.glsl +13 -0
- package/src/shaders/fill.vertex.glsl +13 -0
- package/src/shaders/fill_extrusion.fragment.glsl +16 -0
- package/src/shaders/fill_extrusion.vertex.glsl +66 -0
- package/src/shaders/fill_extrusion_pattern.fragment.glsl +41 -0
- package/src/shaders/fill_extrusion_pattern.vertex.glsl +76 -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 +41 -0
- package/src/shaders/fill_pattern.fragment.glsl +36 -0
- package/src/shaders/fill_pattern.vertex.glsl +36 -0
- package/src/shaders/heatmap.fragment.glsl +21 -0
- package/src/shaders/heatmap.vertex.glsl +53 -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 +72 -0
- package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
- package/src/shaders/index.js +194 -0
- package/src/shaders/line.fragment.glsl +28 -0
- package/src/shaders/line.vertex.glsl +84 -0
- package/src/shaders/line_gradient.fragment.glsl +34 -0
- package/src/shaders/line_gradient.vertex.glsl +84 -0
- package/src/shaders/line_pattern.fragment.glsl +69 -0
- package/src/shaders/line_pattern.vertex.glsl +88 -0
- package/src/shaders/line_sdf.fragment.glsl +44 -0
- package/src/shaders/line_sdf.vertex.glsl +95 -0
- package/src/shaders/raster.fragment.glsl +52 -0
- package/src/shaders/raster.vertex.glsl +21 -0
- package/src/shaders/symbol_icon.fragment.glsl +17 -0
- package/src/shaders/symbol_icon.vertex.glsl +91 -0
- package/src/shaders/symbol_sdf.fragment.glsl +50 -0
- package/src/shaders/symbol_sdf.vertex.glsl +117 -0
- package/src/source/geojson_source.js +267 -0
- package/src/source/geojson_worker_source.js +210 -0
- package/src/source/geojson_wrapper.js +67 -0
- package/src/source/image_source.js +213 -0
- package/src/source/load_tilejson.js +40 -0
- package/src/source/pixels_to_tile_units.js +17 -0
- package/src/source/query_features.js +198 -0
- package/src/source/raster_dem_tile_source.js +140 -0
- package/src/source/raster_dem_tile_worker_source.js +26 -0
- package/src/source/raster_tile_source.js +126 -0
- package/src/source/rtl_text_plugin.js +63 -0
- package/src/source/source.js +75 -0
- package/src/source/source_cache.js +794 -0
- package/src/source/source_state.js +55 -0
- package/src/source/tile.js +332 -0
- package/src/source/tile_bounds.js +40 -0
- package/src/source/tile_cache.js +122 -0
- package/src/source/tile_id.js +150 -0
- package/src/source/vector_tile_source.js +144 -0
- package/src/source/vector_tile_worker_source.js +126 -0
- package/src/source/worker.js +175 -0
- package/src/source/worker_source.js +14 -0
- package/src/source/worker_tile.js +199 -0
- package/src/style/create_style_layer.js +25 -0
- package/src/style/evaluation_parameters.js +45 -0
- package/src/style/light.js +112 -0
- package/src/style/load_glyph_range.js +17 -0
- package/src/style/load_sprite.js +26 -0
- package/src/style/parse_glyph_pbf.js +45 -0
- package/src/style/pauseable_placement.js +88 -0
- package/src/style/properties.js +691 -0
- package/src/style/query_utils.js +39 -0
- package/src/style/style.js +955 -0
- package/src/style/style_layer/background_style_layer.js +11 -0
- package/src/style/style_layer/background_style_layer_properties.js +25 -0
- package/src/style/style_layer/circle_style_layer.js +93 -0
- package/src/style/style_layer/circle_style_layer_properties.js +76 -0
- package/src/style/style_layer/fill_extrusion_style_layer.js +194 -0
- package/src/style/style_layer/fill_extrusion_style_layer_properties.js +56 -0
- package/src/style/style_layer/fill_style_layer.js +46 -0
- package/src/style/style_layer/fill_style_layer_properties.js +45 -0
- package/src/style/style_layer/heatmap_style_layer.js +51 -0
- package/src/style/style_layer/heatmap_style_layer_properties.js +52 -0
- package/src/style/style_layer/hillshade_style_layer.js +15 -0
- package/src/style/style_layer/hillshade_style_layer_properties.js +43 -0
- package/src/style/style_layer/line_style_layer.js +129 -0
- package/src/style/style_layer/line_style_layer_properties.js +104 -0
- package/src/style/style_layer/raster_style_layer.js +11 -0
- package/src/style/style_layer/raster_style_layer_properties.js +55 -0
- package/src/style/style_layer/symbol_style_layer.js +66 -0
- package/src/style/style_layer/symbol_style_layer_properties.js +288 -0
- package/src/style/style_layer.js +183 -0
- package/src/style/style_layer_index.js +61 -0
- package/src/style/zoom_history.js +36 -0
- package/src/style-spec/deref.js +51 -0
- package/src/style-spec/error/parsing_error.js +8 -0
- package/src/style-spec/error/validation_error.js +10 -0
- package/src/style-spec/expression/compound_expression.js +118 -0
- package/src/style-spec/expression/definitions/array.js +82 -0
- package/src/style-spec/expression/definitions/assertion.js +69 -0
- package/src/style-spec/expression/definitions/at.js +57 -0
- package/src/style-spec/expression/definitions/case.js +73 -0
- package/src/style-spec/expression/definitions/coalesce.js +68 -0
- package/src/style-spec/expression/definitions/coercion.js +96 -0
- package/src/style-spec/expression/definitions/collator.js +102 -0
- package/src/style-spec/expression/definitions/equals.js +93 -0
- package/src/style-spec/expression/definitions/index.js +407 -0
- package/src/style-spec/expression/definitions/interpolate.js +235 -0
- package/src/style-spec/expression/definitions/length.js +54 -0
- package/src/style-spec/expression/definitions/let.js +60 -0
- package/src/style-spec/expression/definitions/literal.js +64 -0
- package/src/style-spec/expression/definitions/match.js +142 -0
- package/src/style-spec/expression/definitions/step.js +116 -0
- package/src/style-spec/expression/definitions/var.js +38 -0
- package/src/style-spec/expression/evaluation_context.js +35 -0
- package/src/style-spec/expression/index.js +329 -0
- package/src/style-spec/expression/is_constant.js +63 -0
- package/src/style-spec/expression/parsing_context.js +213 -0
- package/src/style-spec/expression/parsing_error.js +9 -0
- package/src/style-spec/expression/runtime_error.js +12 -0
- package/src/style-spec/expression/scope.js +34 -0
- package/src/style-spec/expression/stops.js +37 -0
- package/src/style-spec/expression/types.js +77 -0
- package/src/style-spec/expression/values.js +126 -0
- package/src/style-spec/feature_filter/README.md +55 -0
- package/src/style-spec/feature_filter/index.js +158 -0
- package/src/style-spec/function/convert.js +256 -0
- package/src/style-spec/function/index.js +299 -0
- package/src/style-spec/group_by_layout.js +68 -0
- package/src/style-spec/reference/v8.json +5356 -0
- package/src/style-spec/util/color.js +73 -0
- package/src/style-spec/util/color_spaces.js +128 -0
- package/src/style-spec/util/eval_support.js +8 -0
- package/src/style-spec/util/get_type.js +18 -0
- package/src/style-spec/util/interpolate.js +21 -0
- package/src/style-spec/util/properties.js +17 -0
- package/src/style-spec/util/ref_properties.js +1 -0
- package/src/style-spec/util/result.js +19 -0
- package/src/symbol/anchor.js +21 -0
- package/src/symbol/check_max_angle.js +75 -0
- package/src/symbol/clip_line.js +73 -0
- package/src/symbol/collision_feature.js +230 -0
- package/src/symbol/collision_index.js +379 -0
- package/src/symbol/cross_tile_symbol_index.js +270 -0
- package/src/symbol/get_anchors.js +177 -0
- package/src/symbol/grid_index.js +318 -0
- package/src/symbol/mergelines.js +75 -0
- package/src/symbol/opacity_state.js +21 -0
- package/src/symbol/placement.js +563 -0
- package/src/symbol/projection.js +601 -0
- package/src/symbol/quads.js +173 -0
- package/src/symbol/shaping.js +347 -0
- package/src/symbol/symbol_layout.js +519 -0
- package/src/symbol/symbol_size.js +110 -0
- package/src/symbol/transform_text.js +16 -0
- package/src/ui/anchor.js +24 -0
- package/src/ui/bind_handlers.js +199 -0
- package/src/ui/camera.js +954 -0
- package/src/ui/events.js +210 -0
- package/src/ui/handler/box_zoom.js +151 -0
- package/src/ui/handler/dblclick_zoom.js +91 -0
- package/src/ui/handler/drag_pan.js +285 -0
- package/src/ui/handler/drag_rotate.js +290 -0
- package/src/ui/handler/frame.js +28 -0
- package/src/ui/handler/inertia.js +45 -0
- package/src/ui/handler/keyboard.js +148 -0
- package/src/ui/handler/scroll_zoom.js +284 -0
- package/src/ui/handler/touch_zoom_rotate.js +263 -0
- package/src/ui/map.js +1645 -0
- package/src/util/actor.js +104 -0
- package/src/util/async.js +23 -0
- package/src/util/browser.js +61 -0
- package/src/util/callback.js +26 -0
- package/src/util/classify_rings.js +43 -0
- package/src/util/color_ramp.js +24 -0
- package/src/util/config.js +24 -0
- package/src/util/dictionary_coder.js +25 -0
- package/src/util/dispatcher.js +68 -0
- package/src/util/dom.js +102 -0
- package/src/util/evented.js +182 -0
- package/src/util/find_pole_of_inaccessibility.js +129 -0
- package/src/util/global_worker_pool.js +15 -0
- package/src/util/image.js +124 -0
- package/src/util/interpolate.js +5 -0
- package/src/util/intersection_tests.js +207 -0
- package/src/util/is_char_in_unicode_block.js +287 -0
- package/src/util/loader/image.js +32 -0
- package/src/util/object.js +178 -0
- package/src/util/script_detection.js +337 -0
- package/src/util/struct_array.js +197 -0
- package/src/util/task_queue.js +57 -0
- package/src/util/throttle.js +26 -0
- package/src/util/tile_cover.js +114 -0
- package/src/util/token.js +13 -0
- package/src/util/unique_id.js +12 -0
- package/src/util/util.js +192 -0
- package/src/util/vectortile_to_geojson.js +44 -0
- package/src/util/verticalize_punctuation.js +112 -0
- package/src/util/warn.js +21 -0
- package/src/util/web_worker.js +5 -0
- package/src/util/web_worker_transfer.js +228 -0
- package/src/util/worker_pool.js +41 -0
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
const LngLat = require('./lng_lat');
|
|
2
|
+
|
|
3
|
+
const Point = require('@mapbox/point-geometry');
|
|
4
|
+
const Coordinate = require('./coordinate');
|
|
5
|
+
const { wrap, clamp } = require('../util/util');
|
|
6
|
+
const interpolate = require('../util/interpolate');
|
|
7
|
+
const tileCover = require('../util/tile_cover');
|
|
8
|
+
const { UnwrappedTileID } = require('../source/tile_id');
|
|
9
|
+
const EXTENT = require('../data/extent');
|
|
10
|
+
const { vec4, mat4, mat2 } = require('@mapbox/gl-matrix');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A single transform, generally used for a single tile to be
|
|
14
|
+
* scaled, rotated, and zoomed.
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
class Transform {
|
|
18
|
+
constructor(minZoom, maxZoom, renderWorldCopies) {
|
|
19
|
+
this.tileSize = 512; // constant
|
|
20
|
+
|
|
21
|
+
this._renderWorldCopies = renderWorldCopies === undefined ? true : renderWorldCopies;
|
|
22
|
+
this._minZoom = minZoom || 0;
|
|
23
|
+
this._maxZoom = maxZoom || 22;
|
|
24
|
+
|
|
25
|
+
this.latRange = [-85.05113, 85.05113];
|
|
26
|
+
|
|
27
|
+
this.width = 0;
|
|
28
|
+
this.height = 0;
|
|
29
|
+
this._center = new LngLat(0, 0);
|
|
30
|
+
this.zoom = 0;
|
|
31
|
+
this.angle = 0;
|
|
32
|
+
this._fov = 0.6435011087932844;
|
|
33
|
+
this._pitch = 0;
|
|
34
|
+
this._unmodified = true;
|
|
35
|
+
this._posMatrixCache = {};
|
|
36
|
+
this._alignedPosMatrixCache = {};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
clone() {
|
|
40
|
+
const clone = new Transform(this._minZoom, this._maxZoom, this._renderWorldCopies);
|
|
41
|
+
clone.tileSize = this.tileSize;
|
|
42
|
+
clone.latRange = this.latRange;
|
|
43
|
+
clone.width = this.width;
|
|
44
|
+
clone.height = this.height;
|
|
45
|
+
clone._center = this._center;
|
|
46
|
+
clone.zoom = this.zoom;
|
|
47
|
+
clone.angle = this.angle;
|
|
48
|
+
clone._fov = this._fov;
|
|
49
|
+
clone._pitch = this._pitch;
|
|
50
|
+
clone._unmodified = this._unmodified;
|
|
51
|
+
clone._calcMatrices();
|
|
52
|
+
return clone;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get minZoom() {
|
|
56
|
+
return this._minZoom;
|
|
57
|
+
}
|
|
58
|
+
set minZoom(zoom) {
|
|
59
|
+
if (this._minZoom === zoom) return;
|
|
60
|
+
this._minZoom = zoom;
|
|
61
|
+
this.zoom = Math.max(this.zoom, zoom);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get maxZoom() {
|
|
65
|
+
return this._maxZoom;
|
|
66
|
+
}
|
|
67
|
+
set maxZoom(zoom) {
|
|
68
|
+
if (this._maxZoom === zoom) return;
|
|
69
|
+
this._maxZoom = zoom;
|
|
70
|
+
this.zoom = Math.min(this.zoom, zoom);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get renderWorldCopies() {
|
|
74
|
+
return this._renderWorldCopies;
|
|
75
|
+
}
|
|
76
|
+
set renderWorldCopies(renderWorldCopies) {
|
|
77
|
+
if (renderWorldCopies === undefined) {
|
|
78
|
+
renderWorldCopies = true;
|
|
79
|
+
} else if (renderWorldCopies === null) {
|
|
80
|
+
renderWorldCopies = false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this._renderWorldCopies = renderWorldCopies;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get worldSize() {
|
|
87
|
+
return this.tileSize * this.scale;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get centerPoint() {
|
|
91
|
+
return this.size._div(2);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get size() {
|
|
95
|
+
return new Point(this.width, this.height);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get bearing() {
|
|
99
|
+
return (-this.angle / Math.PI) * 180;
|
|
100
|
+
}
|
|
101
|
+
set bearing(bearing) {
|
|
102
|
+
const b = (-wrap(bearing, -180, 180) * Math.PI) / 180;
|
|
103
|
+
if (this.angle === b) return;
|
|
104
|
+
this._unmodified = false;
|
|
105
|
+
this.angle = b;
|
|
106
|
+
this._calcMatrices();
|
|
107
|
+
|
|
108
|
+
// 2x2 matrix for rotating points
|
|
109
|
+
this.rotationMatrix = mat2.create();
|
|
110
|
+
mat2.rotate(this.rotationMatrix, this.rotationMatrix, this.angle);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get pitch() {
|
|
114
|
+
return (this._pitch / Math.PI) * 180;
|
|
115
|
+
}
|
|
116
|
+
set pitch(pitch) {
|
|
117
|
+
const p = (clamp(pitch, 0, 60) / 180) * Math.PI;
|
|
118
|
+
if (this._pitch === p) return;
|
|
119
|
+
this._unmodified = false;
|
|
120
|
+
this._pitch = p;
|
|
121
|
+
this._calcMatrices();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
get fov() {
|
|
125
|
+
return (this._fov / Math.PI) * 180;
|
|
126
|
+
}
|
|
127
|
+
set fov(fov) {
|
|
128
|
+
fov = Math.max(0.01, Math.min(60, fov));
|
|
129
|
+
if (this._fov === fov) return;
|
|
130
|
+
this._unmodified = false;
|
|
131
|
+
this._fov = (fov / 180) * Math.PI;
|
|
132
|
+
this._calcMatrices();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
get zoom() {
|
|
136
|
+
return this._zoom;
|
|
137
|
+
}
|
|
138
|
+
set zoom(zoom) {
|
|
139
|
+
const z = Math.min(Math.max(zoom, this.minZoom), this.maxZoom);
|
|
140
|
+
if (this._zoom === z) return;
|
|
141
|
+
this._unmodified = false;
|
|
142
|
+
this._zoom = z;
|
|
143
|
+
this.scale = this.zoomScale(z);
|
|
144
|
+
this.tileZoom = Math.floor(z);
|
|
145
|
+
this.zoomFraction = z - this.tileZoom;
|
|
146
|
+
this._constrain();
|
|
147
|
+
this._calcMatrices();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
get center() {
|
|
151
|
+
return this._center;
|
|
152
|
+
}
|
|
153
|
+
set center(center) {
|
|
154
|
+
if (center.lat === this._center.lat && center.lng === this._center.lng) return;
|
|
155
|
+
this._unmodified = false;
|
|
156
|
+
this._center = center;
|
|
157
|
+
this._constrain();
|
|
158
|
+
this._calcMatrices();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Return a zoom level that will cover all tiles the transform
|
|
163
|
+
* @param {Object} options
|
|
164
|
+
* @param {number} options.tileSize
|
|
165
|
+
* @param {boolean} options.roundZoom
|
|
166
|
+
* @returns {number} zoom level
|
|
167
|
+
*/
|
|
168
|
+
coveringZoomLevel(options) {
|
|
169
|
+
return (options.roundZoom ? Math.round : Math.floor)(this.zoom + this.scaleZoom(this.tileSize / options.tileSize));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Return any "wrapped" copies of a given tile coordinate that are visible
|
|
174
|
+
* in the current view.
|
|
175
|
+
*
|
|
176
|
+
* @private
|
|
177
|
+
*/
|
|
178
|
+
getVisibleUnwrappedCoordinates(tileID) {
|
|
179
|
+
const ul = this.pointCoordinate(new Point(0, 0), 0);
|
|
180
|
+
const ur = this.pointCoordinate(new Point(this.width, 0), 0);
|
|
181
|
+
const w0 = Math.floor(ul.column);
|
|
182
|
+
const w1 = Math.floor(ur.column);
|
|
183
|
+
const result = [new UnwrappedTileID(0, tileID)];
|
|
184
|
+
if (this._renderWorldCopies) {
|
|
185
|
+
for (let w = w0; w <= w1; w++) {
|
|
186
|
+
if (w === 0) continue;
|
|
187
|
+
result.push(new UnwrappedTileID(w, tileID));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Return all coordinates that could cover this transform for a covering
|
|
195
|
+
* zoom level.
|
|
196
|
+
* @param {Object} options
|
|
197
|
+
* @param {number} options.tileSize
|
|
198
|
+
* @param {number} options.minzoom
|
|
199
|
+
* @param {number} options.maxzoom
|
|
200
|
+
* @param {boolean} options.roundZoom
|
|
201
|
+
* @param {boolean} options.reparseOverscaled
|
|
202
|
+
* @param {boolean} options.renderWorldCopies
|
|
203
|
+
* @returns {Array<Tile>} tiles
|
|
204
|
+
*/
|
|
205
|
+
coveringTiles(options) {
|
|
206
|
+
let z = this.coveringZoomLevel(options);
|
|
207
|
+
const actualZ = z;
|
|
208
|
+
|
|
209
|
+
if (options.minzoom !== undefined && z < options.minzoom) return [];
|
|
210
|
+
if (options.maxzoom !== undefined && z > options.maxzoom) z = options.maxzoom;
|
|
211
|
+
|
|
212
|
+
const centerCoord = this.pointCoordinate(this.centerPoint, z);
|
|
213
|
+
const centerPoint = new Point(centerCoord.column - 0.5, centerCoord.row - 0.5);
|
|
214
|
+
const cornerCoords = [
|
|
215
|
+
this.pointCoordinate(new Point(0, 0), z),
|
|
216
|
+
this.pointCoordinate(new Point(this.width, 0), z),
|
|
217
|
+
this.pointCoordinate(new Point(this.width, this.height), z),
|
|
218
|
+
this.pointCoordinate(new Point(0, this.height), z)
|
|
219
|
+
];
|
|
220
|
+
return tileCover(z, cornerCoords, options.reparseOverscaled ? actualZ : z, this._renderWorldCopies).sort(
|
|
221
|
+
(a, b) => centerPoint.dist(a.canonical) - centerPoint.dist(b.canonical)
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
resize(width, height) {
|
|
226
|
+
this.width = width;
|
|
227
|
+
this.height = height;
|
|
228
|
+
|
|
229
|
+
this.pixelsToGLUnits = [2 / width, -2 / height];
|
|
230
|
+
this._constrain();
|
|
231
|
+
this._calcMatrices();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
get unmodified() {
|
|
235
|
+
return this._unmodified;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
zoomScale(zoom) {
|
|
239
|
+
return 2 ** zoom;
|
|
240
|
+
}
|
|
241
|
+
scaleZoom(scale) {
|
|
242
|
+
return Math.log(scale) / Math.LN2;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
project(lnglat) {
|
|
246
|
+
return new Point(this.lngX(lnglat.lng), this.latY(lnglat.lat));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
unproject(point) {
|
|
250
|
+
return new LngLat(this.xLng(point.x), this.yLat(point.y));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
get x() {
|
|
254
|
+
return this.lngX(this.center.lng);
|
|
255
|
+
}
|
|
256
|
+
get y() {
|
|
257
|
+
return this.latY(this.center.lat);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
get point() {
|
|
261
|
+
return new Point(this.x, this.y);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* latitude to absolute x coord
|
|
266
|
+
* @returns {number} pixel coordinate
|
|
267
|
+
*/
|
|
268
|
+
lngX(lng) {
|
|
269
|
+
return ((180 + lng) * this.worldSize) / 360;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* latitude to absolute y coord
|
|
273
|
+
* @returns {number} pixel coordinate
|
|
274
|
+
*/
|
|
275
|
+
latY(lat) {
|
|
276
|
+
const y = (180 / Math.PI) * Math.log(Math.tan(Math.PI / 4 + (lat * Math.PI) / 360));
|
|
277
|
+
return ((180 - y) * this.worldSize) / 360;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
xLng(x) {
|
|
281
|
+
return (x * 360) / this.worldSize - 180;
|
|
282
|
+
}
|
|
283
|
+
yLat(y) {
|
|
284
|
+
const y2 = 180 - (y * 360) / this.worldSize;
|
|
285
|
+
return (360 / Math.PI) * Math.atan(Math.exp((y2 * Math.PI) / 180)) - 90;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
setLocationAtPoint(lnglat, point) {
|
|
289
|
+
const translate = this.pointCoordinate(point)._sub(this.pointCoordinate(this.centerPoint));
|
|
290
|
+
this.center = this.coordinateLocation(this.locationCoordinate(lnglat)._sub(translate));
|
|
291
|
+
if (this._renderWorldCopies) {
|
|
292
|
+
this.center = this.center.wrap();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Given a location, return the screen point that corresponds to it
|
|
298
|
+
* @param {LngLat} lnglat location
|
|
299
|
+
* @returns {Point} screen point
|
|
300
|
+
*/
|
|
301
|
+
locationPoint(lnglat) {
|
|
302
|
+
return this.coordinatePoint(this.locationCoordinate(lnglat));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Given a point on screen, return its lnglat
|
|
307
|
+
* @param {Point} p screen point
|
|
308
|
+
* @returns {LngLat} lnglat location
|
|
309
|
+
*/
|
|
310
|
+
pointLocation(p) {
|
|
311
|
+
return this.coordinateLocation(this.pointCoordinate(p));
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Given a geographical lnglat, return an unrounded
|
|
316
|
+
* coordinate that represents it at this transform's zoom level.
|
|
317
|
+
* @param {LngLat} lnglat
|
|
318
|
+
* @returns {Coordinate}
|
|
319
|
+
*/
|
|
320
|
+
locationCoordinate(lnglat) {
|
|
321
|
+
return new Coordinate(
|
|
322
|
+
this.lngX(lnglat.lng) / this.tileSize,
|
|
323
|
+
this.latY(lnglat.lat) / this.tileSize,
|
|
324
|
+
this.zoom
|
|
325
|
+
).zoomTo(this.tileZoom);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Given a Coordinate, return its geographical position.
|
|
330
|
+
* @param {Coordinate} coord
|
|
331
|
+
* @returns {LngLat} lnglat
|
|
332
|
+
*/
|
|
333
|
+
coordinateLocation(coord) {
|
|
334
|
+
const zoomedCoord = coord.zoomTo(this.zoom);
|
|
335
|
+
return new LngLat(this.xLng(zoomedCoord.column * this.tileSize), this.yLat(zoomedCoord.row * this.tileSize));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
pointCoordinate(p, zoom) {
|
|
339
|
+
if (zoom === undefined) zoom = this.tileZoom;
|
|
340
|
+
|
|
341
|
+
const targetZ = 0;
|
|
342
|
+
// since we don't know the correct projected z value for the point,
|
|
343
|
+
// unproject two points to get a line and then find the point on that
|
|
344
|
+
// line with z=0
|
|
345
|
+
|
|
346
|
+
const coord0 = [p.x, p.y, 0, 1];
|
|
347
|
+
const coord1 = [p.x, p.y, 1, 1];
|
|
348
|
+
|
|
349
|
+
vec4.transformMat4(coord0, coord0, this.pixelMatrixInverse);
|
|
350
|
+
vec4.transformMat4(coord1, coord1, this.pixelMatrixInverse);
|
|
351
|
+
|
|
352
|
+
const w0 = coord0[3];
|
|
353
|
+
const w1 = coord1[3];
|
|
354
|
+
const x0 = coord0[0] / w0;
|
|
355
|
+
const x1 = coord1[0] / w1;
|
|
356
|
+
const y0 = coord0[1] / w0;
|
|
357
|
+
const y1 = coord1[1] / w1;
|
|
358
|
+
const z0 = coord0[2] / w0;
|
|
359
|
+
const z1 = coord1[2] / w1;
|
|
360
|
+
|
|
361
|
+
const t = z0 === z1 ? 0 : (targetZ - z0) / (z1 - z0);
|
|
362
|
+
|
|
363
|
+
return new Coordinate(
|
|
364
|
+
interpolate(x0, x1, t) / this.tileSize,
|
|
365
|
+
interpolate(y0, y1, t) / this.tileSize,
|
|
366
|
+
this.zoom
|
|
367
|
+
)._zoomTo(zoom);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Given a coordinate, return the screen point that corresponds to it
|
|
372
|
+
* @param {Coordinate} coord
|
|
373
|
+
* @returns {Point} screen point
|
|
374
|
+
*/
|
|
375
|
+
coordinatePoint(coord) {
|
|
376
|
+
const zoomedCoord = coord.zoomTo(this.zoom);
|
|
377
|
+
const p = [zoomedCoord.column * this.tileSize, zoomedCoord.row * this.tileSize, 0, 1];
|
|
378
|
+
vec4.transformMat4(p, p, this.pixelMatrix);
|
|
379
|
+
return new Point(p[0] / p[3], p[1] / p[3]);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Calculate the posMatrix that, given a tile coordinate, would be used to display the tile on a map.
|
|
384
|
+
* @param {UnwrappedTileID} unwrappedTileID;
|
|
385
|
+
*/
|
|
386
|
+
calculatePosMatrix(unwrappedTileID, aligned = false) {
|
|
387
|
+
const posMatrixKey = unwrappedTileID.key;
|
|
388
|
+
const cache = aligned ? this._alignedPosMatrixCache : this._posMatrixCache;
|
|
389
|
+
if (cache[posMatrixKey]) {
|
|
390
|
+
return cache[posMatrixKey];
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const canonical = unwrappedTileID.canonical;
|
|
394
|
+
const scale = this.worldSize / this.zoomScale(canonical.z);
|
|
395
|
+
const unwrappedX = canonical.x + 2 ** canonical.z * unwrappedTileID.wrap;
|
|
396
|
+
|
|
397
|
+
const posMatrix = mat4.identity(new Float64Array(16));
|
|
398
|
+
mat4.translate(posMatrix, posMatrix, [unwrappedX * scale, canonical.y * scale, 0]);
|
|
399
|
+
mat4.scale(posMatrix, posMatrix, [scale / EXTENT, scale / EXTENT, 1]);
|
|
400
|
+
mat4.multiply(posMatrix, aligned ? this.alignedProjMatrix : this.projMatrix, posMatrix);
|
|
401
|
+
|
|
402
|
+
cache[posMatrixKey] = new Float32Array(posMatrix);
|
|
403
|
+
return cache[posMatrixKey];
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
_constrain() {
|
|
407
|
+
if (!this.center || !this.width || !this.height || this._constraining) return;
|
|
408
|
+
|
|
409
|
+
this._constraining = true;
|
|
410
|
+
|
|
411
|
+
let minY = -90;
|
|
412
|
+
let maxY = 90;
|
|
413
|
+
let minX = -180;
|
|
414
|
+
let maxX = 180;
|
|
415
|
+
let sy;
|
|
416
|
+
let sx;
|
|
417
|
+
let x2;
|
|
418
|
+
let y2;
|
|
419
|
+
const size = this.size;
|
|
420
|
+
const unmodified = this._unmodified;
|
|
421
|
+
|
|
422
|
+
if (this.latRange) {
|
|
423
|
+
const latRange = this.latRange;
|
|
424
|
+
minY = this.latY(latRange[1]);
|
|
425
|
+
maxY = this.latY(latRange[0]);
|
|
426
|
+
sy = maxY - minY < size.y ? size.y / (maxY - minY) : 0;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (this.lngRange) {
|
|
430
|
+
const lngRange = this.lngRange;
|
|
431
|
+
minX = this.lngX(lngRange[0]);
|
|
432
|
+
maxX = this.lngX(lngRange[1]);
|
|
433
|
+
sx = maxX - minX < size.x ? size.x / (maxX - minX) : 0;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// how much the map should scale to fit the screen into given latitude/longitude ranges
|
|
437
|
+
const s = Math.max(sx || 0, sy || 0);
|
|
438
|
+
|
|
439
|
+
if (s) {
|
|
440
|
+
this.center = this.unproject(new Point(sx ? (maxX + minX) / 2 : this.x, sy ? (maxY + minY) / 2 : this.y));
|
|
441
|
+
this.zoom += this.scaleZoom(s);
|
|
442
|
+
this._unmodified = unmodified;
|
|
443
|
+
this._constraining = false;
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (this.latRange) {
|
|
448
|
+
const y = this.y;
|
|
449
|
+
const h2 = size.y / 2;
|
|
450
|
+
|
|
451
|
+
if (y - h2 < minY) y2 = minY + h2;
|
|
452
|
+
if (y + h2 > maxY) y2 = maxY - h2;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (this.lngRange) {
|
|
456
|
+
const x = this.x;
|
|
457
|
+
const w2 = size.x / 2;
|
|
458
|
+
|
|
459
|
+
if (x - w2 < minX) x2 = minX + w2;
|
|
460
|
+
if (x + w2 > maxX) x2 = maxX - w2;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// pan the map if the screen goes off the range
|
|
464
|
+
if (x2 !== undefined || y2 !== undefined) {
|
|
465
|
+
this.center = this.unproject(new Point(x2 !== undefined ? x2 : this.x, y2 !== undefined ? y2 : this.y));
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
this._unmodified = unmodified;
|
|
469
|
+
this._constraining = false;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
_calcMatrices() {
|
|
473
|
+
if (!this.height) return;
|
|
474
|
+
|
|
475
|
+
this.cameraToCenterDistance = (0.5 / Math.tan(this._fov / 2)) * this.height;
|
|
476
|
+
|
|
477
|
+
// Find the distance from the center point [width/2, height/2] to the
|
|
478
|
+
// center top point [width/2, 0] in Z units, using the law of sines.
|
|
479
|
+
// 1 Z unit is equivalent to 1 horizontal px at the center of the map
|
|
480
|
+
// (the distance between[width/2, height/2] and [width/2 + 1, height/2])
|
|
481
|
+
const halfFov = this._fov / 2;
|
|
482
|
+
const groundAngle = Math.PI / 2 + this._pitch;
|
|
483
|
+
const topHalfSurfaceDistance =
|
|
484
|
+
(Math.sin(halfFov) * this.cameraToCenterDistance) / Math.sin(Math.PI - groundAngle - halfFov);
|
|
485
|
+
const x = this.x;
|
|
486
|
+
const y = this.y;
|
|
487
|
+
|
|
488
|
+
// Calculate z distance of the farthest fragment that should be rendered.
|
|
489
|
+
const furthestDistance = Math.cos(Math.PI / 2 - this._pitch) * topHalfSurfaceDistance + this.cameraToCenterDistance;
|
|
490
|
+
// Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`
|
|
491
|
+
const farZ = furthestDistance * 1.01;
|
|
492
|
+
|
|
493
|
+
// matrix for conversion from location to GL coordinates (-1 .. 1)
|
|
494
|
+
let m = new Float64Array(16);
|
|
495
|
+
mat4.perspective(m, this._fov, this.width / this.height, 1, farZ);
|
|
496
|
+
|
|
497
|
+
mat4.scale(m, m, [1, -1, 1]);
|
|
498
|
+
mat4.translate(m, m, [0, 0, -this.cameraToCenterDistance]);
|
|
499
|
+
mat4.rotateX(m, m, this._pitch);
|
|
500
|
+
mat4.rotateZ(m, m, this.angle);
|
|
501
|
+
mat4.translate(m, m, [-x, -y, 0]);
|
|
502
|
+
|
|
503
|
+
// scale vertically to meters per pixel (inverse of ground resolution):
|
|
504
|
+
// worldSize / (circumferenceOfEarth * cos(lat * π / 180))
|
|
505
|
+
const verticalScale =
|
|
506
|
+
this.worldSize / (2 * Math.PI * 6378137 * Math.abs(Math.cos(this.center.lat * (Math.PI / 180))));
|
|
507
|
+
mat4.scale(m, m, [1, 1, verticalScale, 1]);
|
|
508
|
+
|
|
509
|
+
this.projMatrix = m;
|
|
510
|
+
|
|
511
|
+
// Make a second projection matrix that is aligned to a pixel grid for rendering raster tiles.
|
|
512
|
+
// We're rounding the (floating point) x/y values to achieve to avoid rendering raster images to fractional
|
|
513
|
+
// coordinates. Additionally, we adjust by half a pixel in either direction in case that viewport dimension
|
|
514
|
+
// is an odd integer to preserve rendering to the pixel grid. We're rotating this shift based on the angle
|
|
515
|
+
// of the transformation so that 0°, 90°, 180°, and 270° rasters are crisp, and adjust the shift so that
|
|
516
|
+
// it is always <= 0.5 pixels.
|
|
517
|
+
const xShift = (this.width % 2) / 2;
|
|
518
|
+
const yShift = (this.height % 2) / 2;
|
|
519
|
+
const angleCos = Math.cos(this.angle);
|
|
520
|
+
const angleSin = Math.sin(this.angle);
|
|
521
|
+
const dx = x - Math.round(x) + angleCos * xShift + angleSin * yShift;
|
|
522
|
+
const dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift;
|
|
523
|
+
const alignedM = new Float64Array(m);
|
|
524
|
+
mat4.translate(alignedM, alignedM, [dx > 0.5 ? dx - 1 : dx, dy > 0.5 ? dy - 1 : dy, 0]);
|
|
525
|
+
this.alignedProjMatrix = alignedM;
|
|
526
|
+
|
|
527
|
+
// matrix for conversion from location to screen coordinates
|
|
528
|
+
m = mat4.create();
|
|
529
|
+
mat4.scale(m, m, [this.width / 2, -this.height / 2, 1]);
|
|
530
|
+
mat4.translate(m, m, [1, -1, 0]);
|
|
531
|
+
this.pixelMatrix = mat4.multiply(new Float64Array(16), m, this.projMatrix);
|
|
532
|
+
|
|
533
|
+
// inverse matrix for conversion from screen coordinaes to location
|
|
534
|
+
m = mat4.invert(new Float64Array(16), this.pixelMatrix);
|
|
535
|
+
if (!m) throw new Error('failed to invert matrix');
|
|
536
|
+
this.pixelMatrixInverse = m;
|
|
537
|
+
|
|
538
|
+
this._posMatrixCache = {};
|
|
539
|
+
this._alignedPosMatrixCache = {};
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
maxPitchScaleFactor() {
|
|
543
|
+
// calcMatrices hasn't run yet
|
|
544
|
+
if (!this.pixelMatrixInverse) return 1;
|
|
545
|
+
|
|
546
|
+
const coord = this.pointCoordinate(new Point(0, 0)).zoomTo(this.zoom);
|
|
547
|
+
const p = [coord.column * this.tileSize, coord.row * this.tileSize, 0, 1];
|
|
548
|
+
const topPoint = vec4.transformMat4(p, p, this.pixelMatrix);
|
|
549
|
+
return topPoint[3] / this.cameraToCenterDistance;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/*
|
|
553
|
+
* The camera looks at the map from a 3D (lng, lat, altitude) location. Let's use `cameraLocation`
|
|
554
|
+
* as the name for the location under the camera and on the surface of the earth (lng, lat, 0).
|
|
555
|
+
* `cameraPoint` is the projected position of the `cameraLocation`.
|
|
556
|
+
*
|
|
557
|
+
* This point is useful to us because only fill-extrusions that are between `cameraPoint` and
|
|
558
|
+
* the query point on the surface of the earth can extend and intersect the query.
|
|
559
|
+
*
|
|
560
|
+
* When the map is not pitched the `cameraPoint` is equivalent to the center of the map because
|
|
561
|
+
* the camera is right above the center of the map.
|
|
562
|
+
*/
|
|
563
|
+
getCameraPoint() {
|
|
564
|
+
const pitch = this._pitch;
|
|
565
|
+
const yOffset = Math.tan(pitch) * (this.cameraToCenterDistance || 1);
|
|
566
|
+
return this.centerPoint.add(new Point(0, yOffset));
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/*
|
|
570
|
+
* When the map is pitched, some of the 3D features that intersect a query will not intersect
|
|
571
|
+
* the query at the surface of the earth. Instead the feature may be closer and only intersect
|
|
572
|
+
* the query because it extrudes into the air.
|
|
573
|
+
*
|
|
574
|
+
* This returns a geometry that includes all of the original query as well as all possible ares of the
|
|
575
|
+
* screen where the *base* of a visible extrusion could be.
|
|
576
|
+
* - For point queries, the line from the query point to the "camera point"
|
|
577
|
+
* - For other geometries, the envelope of the query geometry and the "camera point"
|
|
578
|
+
*/
|
|
579
|
+
getCameraQueryGeometry(queryGeometry) {
|
|
580
|
+
const c = this.getCameraPoint();
|
|
581
|
+
|
|
582
|
+
if (queryGeometry.length === 1) {
|
|
583
|
+
return [queryGeometry[0], c];
|
|
584
|
+
}
|
|
585
|
+
let minX = c.x;
|
|
586
|
+
let minY = c.y;
|
|
587
|
+
let maxX = c.x;
|
|
588
|
+
let maxY = c.y;
|
|
589
|
+
for (const p of queryGeometry) {
|
|
590
|
+
minX = Math.min(minX, p.x);
|
|
591
|
+
minY = Math.min(minY, p.y);
|
|
592
|
+
maxX = Math.max(maxX, p.x);
|
|
593
|
+
maxY = Math.max(maxY, p.y);
|
|
594
|
+
}
|
|
595
|
+
return [
|
|
596
|
+
new Point(minX, minY),
|
|
597
|
+
new Point(maxX, minY),
|
|
598
|
+
new Point(maxX, maxY),
|
|
599
|
+
new Point(minX, maxY),
|
|
600
|
+
new Point(minX, minY)
|
|
601
|
+
];
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
module.exports = Transform;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const Color = require('../style-spec/util/color');
|
|
2
|
+
|
|
3
|
+
const ZERO = 0x0000;
|
|
4
|
+
const ONE = 0x0001;
|
|
5
|
+
const ONE_MINUS_SRC_ALPHA = 0x0303;
|
|
6
|
+
|
|
7
|
+
class ColorMode {
|
|
8
|
+
constructor(blendFunction, blendColor, mask) {
|
|
9
|
+
this.blendFunction = blendFunction;
|
|
10
|
+
this.blendColor = blendColor;
|
|
11
|
+
this.mask = mask;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
ColorMode.Replace = [ONE, ZERO];
|
|
16
|
+
|
|
17
|
+
ColorMode.disabled = new ColorMode(ColorMode.Replace, Color.transparent, [false, false, false, false]);
|
|
18
|
+
ColorMode.unblended = new ColorMode(ColorMode.Replace, Color.transparent, [true, true, true, true]);
|
|
19
|
+
ColorMode.alphaBlended = new ColorMode([ONE, ONE_MINUS_SRC_ALPHA], Color.transparent, [true, true, true, true]);
|
|
20
|
+
|
|
21
|
+
module.exports = ColorMode;
|