maplibre-gl 2.0.4 → 2.1.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/build/{banner.js → banner.ts} +1 -1
- package/build/generate-query-test-fixtures.ts +123 -0
- package/build/generate-shaders.ts +35 -0
- package/build/generate-struct-arrays.ts +7 -7
- package/build/generate-style-code.ts +8 -8
- package/build/generate-style-spec.ts +5 -4
- package/build/generate-typings.ts +16 -0
- package/build/readme.md +8 -18
- package/build/release-notes.js +9 -13
- package/build/{rollup_plugin_minify_style_spec.js → rollup_plugin_minify_style_spec.ts} +4 -3
- package/build/{rollup_plugins.js → rollup_plugins.ts} +12 -26
- package/dist/maplibre-gl-dev.js +54885 -0
- package/dist/maplibre-gl.css +1 -1
- package/dist/maplibre-gl.d.ts +1583 -1023
- package/dist/maplibre-gl.js +3 -3
- package/dist/maplibre-gl.js.map +1 -1
- package/package.json +99 -141
- package/src/css/maplibre-gl.css +36 -36
- package/src/data/{array_types.ts → array_types.g.ts} +0 -0
- package/src/data/bucket/circle_bucket.ts +1 -1
- package/src/data/bucket/fill_bucket.test.ts +1 -1
- package/src/data/bucket/fill_bucket.ts +4 -4
- package/src/data/bucket/fill_extrusion_bucket.ts +1 -1
- package/src/data/bucket/line_bucket.test.ts +1 -1
- package/src/data/bucket/line_bucket.ts +6 -6
- package/src/data/bucket/symbol_bucket.test.ts +16 -16
- package/src/data/bucket/symbol_bucket.ts +56 -56
- package/src/data/bucket.ts +43 -43
- package/src/data/dem_data.ts +12 -12
- package/src/data/evaluation_feature.ts +10 -10
- package/src/data/feature_index.ts +37 -37
- package/src/data/feature_position_map.ts +5 -5
- package/src/data/index_array_type.ts +1 -1
- package/src/data/load_geometry.test.ts +1 -1
- package/src/data/program_configuration.ts +47 -47
- package/src/data/segment.ts +14 -14
- package/src/geo/edge_insets.ts +2 -2
- package/src/geo/lng_lat.ts +4 -4
- package/src/geo/lng_lat_bounds.ts +35 -35
- package/src/geo/mercator_coordinate.ts +5 -5
- package/src/geo/transform.test.ts +1 -1
- package/src/geo/transform.ts +14 -14
- package/src/gl/context.ts +3 -3
- package/src/gl/types.ts +19 -19
- package/src/gl/value.ts +6 -6
- package/src/gl/vertex_buffer.test.ts +1 -1
- package/src/index.ts +24 -9
- package/src/render/draw_circle.ts +8 -8
- package/src/render/draw_collision_debug.ts +5 -5
- package/src/render/draw_debug.ts +1 -1
- package/src/render/draw_line.ts +4 -4
- package/src/render/draw_symbol.ts +21 -21
- package/src/render/glyph_atlas.ts +12 -12
- package/src/render/glyph_manager.test.ts +10 -21
- package/src/render/glyph_manager.ts +34 -33
- package/src/render/image_manager.ts +4 -4
- package/src/render/painter.ts +16 -14
- package/src/render/program/background_program.ts +29 -29
- package/src/render/program/circle_program.ts +11 -11
- package/src/render/program/clipping_mask_program.ts +1 -1
- package/src/render/program/collision_program.ts +9 -9
- package/src/render/program/debug_program.ts +4 -4
- package/src/render/program/fill_extrusion_program.ts +31 -31
- package/src/render/program/fill_program.ts +29 -29
- package/src/render/program/heatmap_program.ts +12 -12
- package/src/render/program/hillshade_program.ts +12 -12
- package/src/render/program/line_program.ts +41 -41
- package/src/render/program/pattern.ts +28 -28
- package/src/render/program/raster_program.ts +21 -21
- package/src/render/program/symbol_program.ts +97 -97
- package/src/render/program.ts +25 -25
- package/src/render/texture.ts +9 -9
- package/src/render/uniform_binding.ts +1 -1
- package/src/render/vertex_array_object.ts +13 -13
- package/src/shaders/_prelude.fragment.glsl.g.ts +2 -0
- package/src/shaders/_prelude.vertex.glsl.g.ts +2 -0
- package/src/shaders/background.fragment.glsl.g.ts +2 -0
- package/src/shaders/background.vertex.glsl.g.ts +2 -0
- package/src/shaders/background_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/background_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/circle.fragment.glsl.g.ts +2 -0
- package/src/shaders/circle.vertex.glsl.g.ts +2 -0
- package/src/shaders/clipping_mask.fragment.glsl.g.ts +2 -0
- package/src/shaders/clipping_mask.vertex.glsl.g.ts +2 -0
- package/src/shaders/collision_box.fragment.glsl.g.ts +2 -0
- package/src/shaders/collision_box.vertex.glsl.g.ts +2 -0
- package/src/shaders/collision_circle.fragment.glsl.g.ts +2 -0
- package/src/shaders/collision_circle.vertex.glsl.g.ts +2 -0
- package/src/shaders/debug.fragment.glsl.g.ts +2 -0
- package/src/shaders/debug.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_outline.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_outline.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_outline_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_outline_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/heatmap.fragment.glsl.g.ts +2 -0
- package/src/shaders/heatmap.vertex.glsl.g.ts +2 -0
- package/src/shaders/heatmap_texture.fragment.glsl.g.ts +2 -0
- package/src/shaders/heatmap_texture.vertex.glsl.g.ts +2 -0
- package/src/shaders/hillshade.fragment.glsl.g.ts +2 -0
- package/src/shaders/hillshade.vertex.glsl.g.ts +2 -0
- package/src/shaders/hillshade_prepare.fragment.glsl.g.ts +2 -0
- package/src/shaders/hillshade_prepare.vertex.glsl.g.ts +2 -0
- package/src/shaders/line.fragment.glsl.g.ts +2 -0
- package/src/shaders/line.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_gradient.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_gradient.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_sdf.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_sdf.vertex.glsl.g.ts +2 -0
- package/src/shaders/raster.fragment.glsl.g.ts +2 -0
- package/src/shaders/raster.vertex.glsl.g.ts +2 -0
- package/src/shaders/shaders.ts +52 -55
- package/src/shaders/symbol_icon.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_icon.vertex.glsl.g.ts +2 -0
- package/src/shaders/symbol_sdf.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_sdf.vertex.glsl.g.ts +2 -0
- package/src/shaders/symbol_text_and_icon.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_text_and_icon.vertex.glsl.g.ts +2 -0
- package/src/source/canvas_source.test.ts +11 -12
- package/src/source/canvas_source.ts +4 -4
- package/src/source/geojson_source.test.ts +2 -1
- package/src/source/geojson_source.ts +1 -1
- package/src/source/geojson_worker_source.ts +23 -23
- package/src/source/geojson_wrapper.ts +8 -8
- package/src/source/image_source.test.ts +153 -0
- package/src/source/image_source.ts +6 -6
- package/src/source/pixels_to_tile_units.ts +6 -6
- package/src/source/query_features.ts +20 -20
- package/src/source/raster_dem_tile_source.test.ts +4 -3
- package/src/source/raster_dem_tile_source.ts +1 -1
- package/src/source/raster_tile_source.test.ts +4 -3
- package/src/source/raster_tile_source.ts +1 -1
- package/src/source/rtl_text_plugin.ts +10 -10
- package/src/source/source.ts +29 -29
- package/src/source/source_cache.test.ts +33 -1
- package/src/source/source_cache.ts +7 -5
- package/src/source/source_state.ts +1 -1
- package/src/source/tile.test.ts +3 -3
- package/src/source/tile.ts +15 -15
- package/src/source/tile_cache.test.ts +6 -4
- package/src/source/tile_cache.ts +6 -6
- package/src/source/tile_id.test.ts +10 -13
- package/src/source/tile_id.ts +2 -2
- package/src/source/vector_tile_source.test.ts +17 -5
- package/src/source/vector_tile_source.ts +4 -5
- package/src/source/vector_tile_worker_source.test.ts +4 -4
- package/src/source/vector_tile_worker_source.ts +5 -5
- package/src/source/worker.test.ts +1 -1
- package/src/source/worker.ts +22 -22
- package/src/source/worker_source.ts +56 -56
- package/src/source/worker_tile.ts +4 -4
- package/src/style/evaluation_parameters.ts +3 -3
- package/src/style/format_section_override.test.ts +1 -1
- package/src/style/light.ts +10 -10
- package/src/style/load_glyph_range.test.ts +3 -5
- package/src/style/load_glyph_range.ts +6 -6
- package/src/style/load_sprite.ts +5 -4
- package/src/style/pauseable_placement.ts +1 -1
- package/src/style/properties.ts +70 -70
- package/src/style/query_utils.ts +7 -7
- package/src/style/style.test.ts +26 -15
- package/src/style/style.ts +30 -30
- package/src/style/style_glyph.ts +8 -8
- package/src/style/style_image.ts +58 -58
- package/src/style/style_layer/background_style_layer.ts +2 -2
- package/src/style/style_layer/{background_style_layer_properties.ts → background_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/circle_style_layer.ts +10 -10
- package/src/style/style_layer/{circle_style_layer_properties.ts → circle_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/custom_style_layer.ts +19 -19
- package/src/style/style_layer/fill_extrusion_style_layer.ts +11 -11
- package/src/style/style_layer/{fill_extrusion_style_layer_properties.ts → fill_extrusion_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/fill_style_layer.ts +9 -9
- package/src/style/style_layer/{fill_style_layer_properties.ts → fill_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/heatmap_style_layer.ts +2 -2
- package/src/style/style_layer/{heatmap_style_layer_properties.ts → heatmap_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/hillshade_style_layer.ts +2 -2
- package/src/style/style_layer/{hillshade_style_layer_properties.ts → hillshade_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/line_style_layer.ts +9 -9
- package/src/style/style_layer/{line_style_layer_properties.ts → line_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/raster_style_layer.ts +2 -2
- package/src/style/style_layer/{raster_style_layer_properties.ts → raster_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/symbol_style_layer.ts +26 -7
- package/src/style/style_layer/{symbol_style_layer_properties.ts → symbol_style_layer_properties.g.ts} +6 -0
- package/src/style/style_layer.ts +10 -10
- package/src/style/style_layer_index.ts +3 -3
- package/src/style/validate_style.ts +15 -15
- package/src/style-spec/CHANGELOG.md +6 -0
- package/src/style-spec/error/validation_error.ts +1 -1
- package/src/style-spec/expression/compound_expression.ts +3 -3
- package/src/style-spec/expression/definitions/format.ts +11 -11
- package/src/style-spec/expression/definitions/interpolate.ts +5 -5
- package/src/style-spec/expression/definitions/match.ts +2 -2
- package/src/style-spec/expression/definitions/number_format.ts +11 -11
- package/src/style-spec/expression/expression.ts +8 -8
- package/src/style-spec/expression/index.ts +97 -97
- package/src/style-spec/expression/parsing_context.ts +11 -11
- package/src/style-spec/expression/types/collator.ts +9 -9
- package/src/style-spec/expression/types/resolved_image.ts +2 -2
- package/src/style-spec/expression/types.ts +14 -14
- package/src/style-spec/expression/values.ts +1 -1
- package/src/style-spec/feature_filter/index.ts +66 -66
- package/src/style-spec/function/convert.ts +3 -3
- package/src/style-spec/package.json +1 -1
- package/src/style-spec/reference/v8.json +68 -2
- package/src/style-spec/style-spec.ts +44 -44
- package/src/style-spec/types.ts +2 -0
- package/src/style-spec/util/color_spaces.ts +8 -8
- package/src/style-spec/util/result.ts +4 -4
- package/src/style-spec/validate/validate_filter.ts +58 -58
- package/src/style-spec/validate/validate_source.ts +63 -63
- package/src/style-spec/visit.ts +11 -11
- package/src/symbol/collision_feature.test.ts +1 -1
- package/src/symbol/collision_feature.ts +10 -10
- package/src/symbol/collision_index.ts +43 -43
- package/src/symbol/cross_tile_symbol_index.ts +17 -17
- package/src/symbol/get_anchors.ts +16 -16
- package/src/symbol/grid_index.test.ts +42 -19
- package/src/symbol/grid_index.ts +69 -40
- package/src/symbol/placement.ts +124 -95
- package/src/symbol/projection.ts +30 -30
- package/src/symbol/quads.ts +30 -30
- package/src/symbol/shaping.ts +160 -160
- package/src/symbol/symbol_layout.ts +119 -119
- package/src/symbol/symbol_size.ts +29 -29
- package/src/symbol/symbol_style_layer.test.ts +49 -2
- package/src/types/cancelable.ts +1 -1
- package/src/types/tilejson.ts +13 -13
- package/src/ui/anchor.ts +1 -1
- package/src/ui/camera.test.ts +9 -9
- package/src/ui/camera.ts +26 -18
- package/src/ui/control/attribution_control.test.ts +51 -16
- package/src/ui/control/attribution_control.ts +35 -16
- package/src/ui/control/control.ts +40 -40
- package/src/ui/control/fullscreen_control.ts +1 -1
- package/src/ui/control/geolocate_control.test.ts +1 -1
- package/src/ui/control/geolocate_control.ts +102 -102
- package/src/ui/control/logo_control.test.ts +5 -4
- package/src/ui/control/navigation_control.ts +3 -3
- package/src/ui/control/scale_control.test.ts +2 -2
- package/src/ui/control/scale_control.ts +5 -5
- package/src/ui/events.ts +289 -200
- package/src/ui/handler/box_zoom.test.ts +1 -1
- package/src/ui/handler/box_zoom.ts +1 -1
- package/src/ui/handler/dblclick_zoom.test.ts +1 -1
- package/src/ui/handler/drag_pan.test.ts +1 -1
- package/src/ui/handler/drag_rotate.test.ts +1 -1
- package/src/ui/handler/keyboard.test.ts +1 -1
- package/src/ui/handler/keyboard.ts +51 -51
- package/src/ui/handler/map_event.test.ts +1 -1
- package/src/ui/handler/map_event.ts +1 -1
- package/src/ui/handler/mouse.ts +1 -1
- package/src/ui/handler/mouse_rotate.test.ts +1 -1
- package/src/ui/handler/scroll_zoom.test.ts +3 -2
- package/src/ui/handler/scroll_zoom.ts +9 -9
- package/src/ui/handler/shim/drag_pan.ts +4 -4
- package/src/ui/handler/shim/drag_rotate.ts +1 -1
- package/src/ui/handler/shim/touch_zoom_rotate.ts +1 -1
- package/src/ui/handler/tap_recognizer.ts +4 -4
- package/src/ui/handler/touch_pan.ts +2 -2
- package/src/ui/handler/touch_zoom_rotate.test.ts +1 -1
- package/src/ui/handler/touch_zoom_rotate.ts +1 -1
- package/src/ui/handler_inertia.ts +6 -6
- package/src/ui/handler_manager.ts +44 -44
- package/src/ui/map/isMoving.test.ts +1 -1
- package/src/ui/map/isRotating.test.ts +1 -1
- package/src/ui/map/isZooming.test.ts +1 -1
- package/src/ui/map.test.ts +87 -14
- package/src/ui/map.ts +138 -108
- package/src/ui/map_events.test.ts +1 -1
- package/src/ui/marker.test.ts +12 -12
- package/src/ui/marker.ts +37 -37
- package/src/ui/popup.test.ts +7 -7
- package/src/ui/popup.ts +9 -9
- package/src/util/actor.test.ts +41 -10
- package/src/util/actor.ts +8 -8
- package/src/util/ajax.test.ts +214 -0
- package/src/util/ajax.ts +51 -30
- package/src/util/browser.ts +1 -1
- package/src/util/classify_rings.test.ts +1 -1
- package/src/util/color_ramp.ts +5 -5
- package/src/util/config.ts +2 -2
- package/src/util/dispatcher.ts +1 -1
- package/src/util/dom.ts +2 -2
- package/src/util/evented.ts +1 -1
- package/src/util/find_pole_of_inaccessibility.ts +3 -3
- package/src/util/image.ts +5 -5
- package/src/util/performance.ts +7 -7
- package/src/util/request_manager.ts +4 -4
- package/src/util/resolve_tokens.ts +4 -4
- package/src/util/struct_array.test.ts +1 -1
- package/src/util/struct_array.ts +15 -15
- package/src/util/task_queue.ts +3 -3
- package/src/util/test/util.ts +14 -0
- package/src/util/tile_request_cache.ts +3 -3
- package/src/util/transferable_grid_index.ts +4 -4
- package/src/util/util.ts +8 -8
- package/src/util/web_worker.ts +4 -68
- package/src/util/web_worker_transfer.test.ts +3 -0
- package/src/util/web_worker_transfer.ts +21 -17
- package/src/util/worker_pool.ts +1 -1
- package/build/.eslintrc +0 -21
- package/build/glsl_to_js.js +0 -12
- package/build/post-ts-build.js +0 -43
- package/build/release-notes.md.ejs +0 -8
- package/build/test/build-tape.js +0 -17
- package/build/web_worker_replacement.js +0 -5
- package/dist/package.json +0 -1
- package/src/style-spec/validate_spec.test.ts +0 -29
- package/src/symbol/shaping.test.ts +0 -392
- package/src/types/glsl.d.ts +0 -4
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
+
export default '#ifdef GL_ES\nprecision highp float;\n#endif\nuniform lowp float u_device_pixel_ratio;uniform vec2 u_texsize;uniform float u_fade;uniform mediump vec3 u_scale;uniform sampler2D u_image;varying vec2 v_normal;varying vec2 v_width2;varying float v_linesofar;varying float v_gamma_scale;varying float v_width;\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\n#pragma mapbox: define lowp float pixel_ratio_from\n#pragma mapbox: define lowp float pixel_ratio_to\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\n#pragma mapbox: initialize lowp float pixel_ratio_from\n#pragma mapbox: initialize lowp float pixel_ratio_to\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float tileZoomRatio=u_scale.x;float fromScale=u_scale.y;float toScale=u_scale.z;vec2 display_size_a=(pattern_br_a-pattern_tl_a)/pixel_ratio_from;vec2 display_size_b=(pattern_br_b-pattern_tl_b)/pixel_ratio_to;vec2 pattern_size_a=vec2(display_size_a.x*fromScale/tileZoomRatio,display_size_a.y);vec2 pattern_size_b=vec2(display_size_b.x*toScale/tileZoomRatio,display_size_b.y);float aspect_a=display_size_a.y/v_width;float aspect_b=display_size_b.y/v_width;float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);float x_a=mod(v_linesofar/pattern_size_a.x*aspect_a,1.0);float x_b=mod(v_linesofar/pattern_size_b.x*aspect_b,1.0);float y=0.5*v_normal.y+0.5;vec2 texel_size=1.0/u_texsize;vec2 pos_a=mix(pattern_tl_a*texel_size-texel_size,pattern_br_a*texel_size+texel_size,vec2(x_a,y));vec2 pos_b=mix(pattern_tl_b*texel_size-texel_size,pattern_br_b*texel_size+texel_size,vec2(x_b,y));vec4 color=mix(texture2D(u_image,pos_a),texture2D(u_image,pos_b),u_fade);gl_FragColor=color*alpha*opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
+
export default '\n#define scale 0.015873016\n#define LINE_DISTANCE_SCALE 2.0\nattribute vec2 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform vec2 u_units_to_pixels;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;varying vec2 v_normal;varying vec2 v_width2;varying float v_linesofar;varying float v_gamma_scale;varying float v_width;\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float offset\n#pragma mapbox: define mediump float gapwidth\n#pragma mapbox: define mediump float width\n#pragma mapbox: define lowp float floorwidth\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\n#pragma mapbox: define lowp float pixel_ratio_from\n#pragma mapbox: define lowp float pixel_ratio_to\nvoid main() {\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float offset\n#pragma mapbox: initialize mediump float gapwidth\n#pragma mapbox: initialize mediump float width\n#pragma mapbox: initialize lowp float floorwidth\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\n#pragma mapbox: initialize lowp float pixel_ratio_from\n#pragma mapbox: initialize lowp float pixel_ratio_to\nfloat ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;float a_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*LINE_DISTANCE_SCALE;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);vec4 projected_extrude=u_matrix*vec4(dist/u_ratio,0.0,0.0);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.0,1.0)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_linesofar=a_linesofar;v_width2=vec2(outset,inset);v_width=floorwidth;}';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
+
export default 'uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;uniform float u_sdfgamma;uniform float u_mix;varying vec2 v_normal;varying vec2 v_width2;varying vec2 v_tex_a;varying vec2 v_tex_b;varying float v_gamma_scale;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define mediump float width\n#pragma mapbox: define lowp float floorwidth\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump float width\n#pragma mapbox: initialize lowp float floorwidth\nfloat dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);float sdfdist_a=texture2D(u_image,v_tex_a).a;float sdfdist_b=texture2D(u_image,v_tex_b).a;float sdfdist=mix(sdfdist_a,sdfdist_b,u_mix);alpha*=smoothstep(0.5-u_sdfgamma/floorwidth,0.5+u_sdfgamma/floorwidth,sdfdist);gl_FragColor=color*(alpha*opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
+
export default '\n#define scale 0.015873016\n#define LINE_DISTANCE_SCALE 2.0\nattribute vec2 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_patternscale_a;uniform float u_tex_y_a;uniform vec2 u_patternscale_b;uniform float u_tex_y_b;uniform vec2 u_units_to_pixels;varying vec2 v_normal;varying vec2 v_width2;varying vec2 v_tex_a;varying vec2 v_tex_b;varying float v_gamma_scale;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define mediump float gapwidth\n#pragma mapbox: define lowp float offset\n#pragma mapbox: define mediump float width\n#pragma mapbox: define lowp float floorwidth\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump float gapwidth\n#pragma mapbox: initialize lowp float offset\n#pragma mapbox: initialize mediump float width\n#pragma mapbox: initialize lowp float floorwidth\nfloat ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;float a_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*LINE_DISTANCE_SCALE;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);vec4 projected_extrude=u_matrix*vec4(dist/u_ratio,0.0,0.0);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.0,1.0)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_tex_a=vec2(a_linesofar*u_patternscale_a.x/floorwidth,normal.y*u_patternscale_a.y+u_tex_y_a);v_tex_b=vec2(a_linesofar*u_patternscale_b.x/floorwidth,normal.y*u_patternscale_b.y+u_tex_y_b);v_width2=vec2(outset,inset);}';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
+
export default 'uniform float u_fade_t;uniform float u_opacity;uniform sampler2D u_image0;uniform sampler2D u_image1;varying vec2 v_pos0;varying vec2 v_pos1;uniform float u_brightness_low;uniform float u_brightness_high;uniform float u_saturation_factor;uniform float u_contrast_factor;uniform vec3 u_spin_weights;void main() {vec4 color0=texture2D(u_image0,v_pos0);vec4 color1=texture2D(u_image1,v_pos1);if (color0.a > 0.0) {color0.rgb=color0.rgb/color0.a;}if (color1.a > 0.0) {color1.rgb=color1.rgb/color1.a;}vec4 color=mix(color0,color1,u_fade_t);color.a*=u_opacity;vec3 rgb=color.rgb;rgb=vec3(dot(rgb,u_spin_weights.xyz),dot(rgb,u_spin_weights.zxy),dot(rgb,u_spin_weights.yzx));float average=(color.r+color.g+color.b)/3.0;rgb+=(average-rgb)*u_saturation_factor;rgb=(rgb-0.5)*u_contrast_factor+0.5;vec3 u_high_vec=vec3(u_brightness_low,u_brightness_low,u_brightness_low);vec3 u_low_vec=vec3(u_brightness_high,u_brightness_high,u_brightness_high);gl_FragColor=vec4(mix(u_high_vec,u_low_vec,rgb)*color.a,color.a);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
+
export default 'uniform mat4 u_matrix;uniform vec2 u_tl_parent;uniform float u_scale_parent;uniform float u_buffer_scale;attribute vec2 a_pos;attribute vec2 a_texture_pos;varying vec2 v_pos0;varying vec2 v_pos1;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);v_pos0=(((a_texture_pos/8192.0)-0.5)/u_buffer_scale )+0.5;v_pos1=(v_pos0*u_scale_parent)+u_tl_parent;}';
|
package/src/shaders/shaders.ts
CHANGED
|
@@ -1,58 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
import
|
|
29
|
-
import
|
|
30
|
-
import
|
|
31
|
-
import
|
|
32
|
-
import
|
|
33
|
-
import
|
|
34
|
-
import
|
|
35
|
-
import
|
|
36
|
-
import
|
|
37
|
-
import
|
|
38
|
-
import
|
|
39
|
-
import
|
|
40
|
-
import
|
|
41
|
-
import
|
|
42
|
-
import
|
|
43
|
-
import
|
|
44
|
-
import
|
|
45
|
-
import
|
|
46
|
-
import
|
|
47
|
-
import
|
|
48
|
-
import
|
|
49
|
-
import
|
|
50
|
-
import
|
|
51
|
-
import
|
|
52
|
-
import
|
|
53
|
-
import symbolSDFVert from './symbol_sdf.vertex.glsl';
|
|
54
|
-
import symbolTextAndIconFrag from './symbol_text_and_icon.fragment.glsl';
|
|
55
|
-
import symbolTextAndIconVert from './symbol_text_and_icon.vertex.glsl';
|
|
1
|
+
import preludeFrag from './_prelude.fragment.glsl.g';
|
|
2
|
+
import preludeVert from './_prelude.vertex.glsl.g';
|
|
3
|
+
import backgroundFrag from './background.fragment.glsl.g';
|
|
4
|
+
import backgroundVert from './background.vertex.glsl.g';
|
|
5
|
+
import backgroundPatternFrag from './background_pattern.fragment.glsl.g';
|
|
6
|
+
import backgroundPatternVert from './background_pattern.vertex.glsl.g';
|
|
7
|
+
import circleFrag from './circle.fragment.glsl.g';
|
|
8
|
+
import circleVert from './circle.vertex.glsl.g';
|
|
9
|
+
import clippingMaskFrag from './clipping_mask.fragment.glsl.g';
|
|
10
|
+
import clippingMaskVert from './clipping_mask.vertex.glsl.g';
|
|
11
|
+
import heatmapFrag from './heatmap.fragment.glsl.g';
|
|
12
|
+
import heatmapVert from './heatmap.vertex.glsl.g';
|
|
13
|
+
import heatmapTextureFrag from './heatmap_texture.fragment.glsl.g';
|
|
14
|
+
import heatmapTextureVert from './heatmap_texture.vertex.glsl.g';
|
|
15
|
+
import collisionBoxFrag from './collision_box.fragment.glsl.g';
|
|
16
|
+
import collisionBoxVert from './collision_box.vertex.glsl.g';
|
|
17
|
+
import collisionCircleFrag from './collision_circle.fragment.glsl.g';
|
|
18
|
+
import collisionCircleVert from './collision_circle.vertex.glsl.g';
|
|
19
|
+
import debugFrag from './debug.fragment.glsl.g';
|
|
20
|
+
import debugVert from './debug.vertex.glsl.g';
|
|
21
|
+
import fillFrag from './fill.fragment.glsl.g';
|
|
22
|
+
import fillVert from './fill.vertex.glsl.g';
|
|
23
|
+
import fillOutlineFrag from './fill_outline.fragment.glsl.g';
|
|
24
|
+
import fillOutlineVert from './fill_outline.vertex.glsl.g';
|
|
25
|
+
import fillOutlinePatternFrag from './fill_outline_pattern.fragment.glsl.g';
|
|
26
|
+
import fillOutlinePatternVert from './fill_outline_pattern.vertex.glsl.g';
|
|
27
|
+
import fillPatternFrag from './fill_pattern.fragment.glsl.g';
|
|
28
|
+
import fillPatternVert from './fill_pattern.vertex.glsl.g';
|
|
29
|
+
import fillExtrusionFrag from './fill_extrusion.fragment.glsl.g';
|
|
30
|
+
import fillExtrusionVert from './fill_extrusion.vertex.glsl.g';
|
|
31
|
+
import fillExtrusionPatternFrag from './fill_extrusion_pattern.fragment.glsl.g';
|
|
32
|
+
import fillExtrusionPatternVert from './fill_extrusion_pattern.vertex.glsl.g';
|
|
33
|
+
import hillshadePrepareFrag from './hillshade_prepare.fragment.glsl.g';
|
|
34
|
+
import hillshadePrepareVert from './hillshade_prepare.vertex.glsl.g';
|
|
35
|
+
import hillshadeFrag from './hillshade.fragment.glsl.g';
|
|
36
|
+
import hillshadeVert from './hillshade.vertex.glsl.g';
|
|
37
|
+
import lineFrag from './line.fragment.glsl.g';
|
|
38
|
+
import lineVert from './line.vertex.glsl.g';
|
|
39
|
+
import lineGradientFrag from './line_gradient.fragment.glsl.g';
|
|
40
|
+
import lineGradientVert from './line_gradient.vertex.glsl.g';
|
|
41
|
+
import linePatternFrag from './line_pattern.fragment.glsl.g';
|
|
42
|
+
import linePatternVert from './line_pattern.vertex.glsl.g';
|
|
43
|
+
import lineSDFFrag from './line_sdf.fragment.glsl.g';
|
|
44
|
+
import lineSDFVert from './line_sdf.vertex.glsl.g';
|
|
45
|
+
import rasterFrag from './raster.fragment.glsl.g';
|
|
46
|
+
import rasterVert from './raster.vertex.glsl.g';
|
|
47
|
+
import symbolIconFrag from './symbol_icon.fragment.glsl.g';
|
|
48
|
+
import symbolIconVert from './symbol_icon.vertex.glsl.g';
|
|
49
|
+
import symbolSDFFrag from './symbol_sdf.fragment.glsl.g';
|
|
50
|
+
import symbolSDFVert from './symbol_sdf.vertex.glsl.g';
|
|
51
|
+
import symbolTextAndIconFrag from './symbol_text_and_icon.fragment.glsl.g';
|
|
52
|
+
import symbolTextAndIconVert from './symbol_text_and_icon.vertex.glsl.g';
|
|
56
53
|
|
|
57
54
|
export default {
|
|
58
55
|
prelude: compile(preludeFrag, preludeVert),
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
+
export default 'uniform sampler2D u_texture;varying vec2 v_tex;varying float v_fade_opacity;\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize lowp float opacity\nlowp float alpha=opacity*v_fade_opacity;gl_FragColor=texture2D(u_texture,v_tex)*alpha;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
+
export default 'const float PI=3.141592653589793;attribute vec4 a_pos_offset;attribute vec4 a_data;attribute vec4 a_pixeloffset;attribute vec3 a_projected_pos;attribute float a_fade_opacity;uniform bool u_is_size_zoom_constant;uniform bool u_is_size_feature_constant;uniform highp float u_size_t;uniform highp float u_size;uniform highp float u_camera_to_center_distance;uniform highp float u_pitch;uniform bool u_rotate_symbol;uniform highp float u_aspect_ratio;uniform float u_fade_change;uniform mat4 u_matrix;uniform mat4 u_label_plane_matrix;uniform mat4 u_coord_matrix;uniform bool u_is_text;uniform bool u_pitch_with_map;uniform vec2 u_texsize;varying vec2 v_tex;varying float v_fade_opacity;\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize lowp float opacity\nvec2 a_pos=a_pos_offset.xy;vec2 a_offset=a_pos_offset.zw;vec2 a_tex=a_data.xy;vec2 a_size=a_data.zw;float a_size_min=floor(a_size[0]*0.5);vec2 a_pxoffset=a_pixeloffset.xy;vec2 a_minFontScale=a_pixeloffset.zw/256.0;highp float segment_angle=-a_projected_pos[2];float size;if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {size=mix(a_size_min,a_size[1],u_size_t)/128.0;} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {size=a_size_min/128.0;} else {size=u_size;}vec4 projectedPoint=u_matrix*vec4(a_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float distance_ratio=u_pitch_with_map ?\ncamera_to_anchor_distance/u_camera_to_center_distance :\nu_camera_to_center_distance/camera_to_anchor_distance;highp float perspective_ratio=clamp(0.5+0.5*distance_ratio,0.0,4.0);size*=perspective_ratio;float fontScale=u_is_text ? size/24.0 : size;highp float symbol_rotation=0.0;if (u_rotate_symbol) {vec4 offsetProjectedPoint=u_matrix*vec4(a_pos+vec2(1,0),0,1);vec2 a=projectedPoint.xy/projectedPoint.w;vec2 b=offsetProjectedPoint.xy/offsetProjectedPoint.w;symbol_rotation=atan((b.y-a.y)/u_aspect_ratio,b.x-a.x);}highp float angle_sin=sin(segment_angle+symbol_rotation);highp float angle_cos=cos(segment_angle+symbol_rotation);mat2 rotation_matrix=mat2(angle_cos,-1.0*angle_sin,angle_sin,angle_cos);vec4 projected_pos=u_label_plane_matrix*vec4(a_projected_pos.xy,0.0,1.0);gl_Position=u_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matrix*(a_offset/32.0*max(a_minFontScale,fontScale)+a_pxoffset/16.0),0.0,1.0);v_tex=a_tex/u_texsize;vec2 fade_opacity=unpack_opacity(a_fade_opacity);float fade_change=fade_opacity[1] > 0.5 ? u_fade_change :-u_fade_change;v_fade_opacity=max(0.0,min(1.0,fade_opacity[0]+fade_change));}';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
+
export default '#define SDF_PX 8.0\nuniform bool u_is_halo;uniform sampler2D u_texture;uniform highp float u_gamma_scale;uniform lowp float u_device_pixel_ratio;uniform bool u_is_text;varying vec2 v_data0;varying vec3 v_data1;\n#pragma mapbox: define highp vec4 fill_color\n#pragma mapbox: define highp vec4 halo_color\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float halo_width\n#pragma mapbox: define lowp float halo_blur\nvoid main() {\n#pragma mapbox: initialize highp vec4 fill_color\n#pragma mapbox: initialize highp vec4 halo_color\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float halo_width\n#pragma mapbox: initialize lowp float halo_blur\nfloat EDGE_GAMMA=0.105/u_device_pixel_ratio;vec2 tex=v_data0.xy;float gamma_scale=v_data1.x;float size=v_data1.y;float fade_opacity=v_data1[2];float fontScale=u_is_text ? size/24.0 : size;lowp vec4 color=fill_color;highp float gamma=EDGE_GAMMA/(fontScale*u_gamma_scale);lowp float buff=(256.0-64.0)/256.0;if (u_is_halo) {color=halo_color;gamma=(halo_blur*1.19/SDF_PX+EDGE_GAMMA)/(fontScale*u_gamma_scale);buff=(6.0-halo_width/fontScale)/SDF_PX;}lowp float dist=texture2D(u_texture,tex).a;highp float gamma_scaled=gamma*gamma_scale;highp float alpha=smoothstep(buff-gamma_scaled,buff+gamma_scaled,dist);gl_FragColor=color*(alpha*opacity*fade_opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
+
export default 'const float PI=3.141592653589793;attribute vec4 a_pos_offset;attribute vec4 a_data;attribute vec4 a_pixeloffset;attribute vec3 a_projected_pos;attribute float a_fade_opacity;uniform bool u_is_size_zoom_constant;uniform bool u_is_size_feature_constant;uniform highp float u_size_t;uniform highp float u_size;uniform mat4 u_matrix;uniform mat4 u_label_plane_matrix;uniform mat4 u_coord_matrix;uniform bool u_is_text;uniform bool u_pitch_with_map;uniform highp float u_pitch;uniform bool u_rotate_symbol;uniform highp float u_aspect_ratio;uniform highp float u_camera_to_center_distance;uniform float u_fade_change;uniform vec2 u_texsize;varying vec2 v_data0;varying vec3 v_data1;\n#pragma mapbox: define highp vec4 fill_color\n#pragma mapbox: define highp vec4 halo_color\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float halo_width\n#pragma mapbox: define lowp float halo_blur\nvoid main() {\n#pragma mapbox: initialize highp vec4 fill_color\n#pragma mapbox: initialize highp vec4 halo_color\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float halo_width\n#pragma mapbox: initialize lowp float halo_blur\nvec2 a_pos=a_pos_offset.xy;vec2 a_offset=a_pos_offset.zw;vec2 a_tex=a_data.xy;vec2 a_size=a_data.zw;float a_size_min=floor(a_size[0]*0.5);vec2 a_pxoffset=a_pixeloffset.xy;highp float segment_angle=-a_projected_pos[2];float size;if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {size=mix(a_size_min,a_size[1],u_size_t)/128.0;} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {size=a_size_min/128.0;} else {size=u_size;}vec4 projectedPoint=u_matrix*vec4(a_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float distance_ratio=u_pitch_with_map ?\ncamera_to_anchor_distance/u_camera_to_center_distance :\nu_camera_to_center_distance/camera_to_anchor_distance;highp float perspective_ratio=clamp(0.5+0.5*distance_ratio,0.0,4.0);size*=perspective_ratio;float fontScale=u_is_text ? size/24.0 : size;highp float symbol_rotation=0.0;if (u_rotate_symbol) {vec4 offsetProjectedPoint=u_matrix*vec4(a_pos+vec2(1,0),0,1);vec2 a=projectedPoint.xy/projectedPoint.w;vec2 b=offsetProjectedPoint.xy/offsetProjectedPoint.w;symbol_rotation=atan((b.y-a.y)/u_aspect_ratio,b.x-a.x);}highp float angle_sin=sin(segment_angle+symbol_rotation);highp float angle_cos=cos(segment_angle+symbol_rotation);mat2 rotation_matrix=mat2(angle_cos,-1.0*angle_sin,angle_sin,angle_cos);vec4 projected_pos=u_label_plane_matrix*vec4(a_projected_pos.xy,0.0,1.0);gl_Position=u_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matrix*(a_offset/32.0*fontScale+a_pxoffset),0.0,1.0);float gamma_scale=gl_Position.w;vec2 fade_opacity=unpack_opacity(a_fade_opacity);float fade_change=fade_opacity[1] > 0.5 ? u_fade_change :-u_fade_change;float interpolated_fade_opacity=max(0.0,min(1.0,fade_opacity[0]+fade_change));v_data0=a_tex/u_texsize;v_data1=vec3(gamma_scale,size,interpolated_fade_opacity);}';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
+
export default '#define SDF_PX 8.0\n#define SDF 1.0\n#define ICON 0.0\nuniform bool u_is_halo;uniform sampler2D u_texture;uniform sampler2D u_texture_icon;uniform highp float u_gamma_scale;uniform lowp float u_device_pixel_ratio;varying vec4 v_data0;varying vec4 v_data1;\n#pragma mapbox: define highp vec4 fill_color\n#pragma mapbox: define highp vec4 halo_color\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float halo_width\n#pragma mapbox: define lowp float halo_blur\nvoid main() {\n#pragma mapbox: initialize highp vec4 fill_color\n#pragma mapbox: initialize highp vec4 halo_color\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float halo_width\n#pragma mapbox: initialize lowp float halo_blur\nfloat fade_opacity=v_data1[2];if (v_data1.w==ICON) {vec2 tex_icon=v_data0.zw;lowp float alpha=opacity*fade_opacity;gl_FragColor=texture2D(u_texture_icon,tex_icon)*alpha;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\nreturn;}vec2 tex=v_data0.xy;float EDGE_GAMMA=0.105/u_device_pixel_ratio;float gamma_scale=v_data1.x;float size=v_data1.y;float fontScale=size/24.0;lowp vec4 color=fill_color;highp float gamma=EDGE_GAMMA/(fontScale*u_gamma_scale);lowp float buff=(256.0-64.0)/256.0;if (u_is_halo) {color=halo_color;gamma=(halo_blur*1.19/SDF_PX+EDGE_GAMMA)/(fontScale*u_gamma_scale);buff=(6.0-halo_width/fontScale)/SDF_PX;}lowp float dist=texture2D(u_texture,tex).a;highp float gamma_scaled=gamma*gamma_scale;highp float alpha=smoothstep(buff-gamma_scaled,buff+gamma_scaled,dist);gl_FragColor=color*(alpha*opacity*fade_opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// This file is generated. Edit build/generate-shaders.ts, then run `npm run codegen`.
|
|
2
|
+
export default 'const float PI=3.141592653589793;attribute vec4 a_pos_offset;attribute vec4 a_data;attribute vec3 a_projected_pos;attribute float a_fade_opacity;uniform bool u_is_size_zoom_constant;uniform bool u_is_size_feature_constant;uniform highp float u_size_t;uniform highp float u_size;uniform mat4 u_matrix;uniform mat4 u_label_plane_matrix;uniform mat4 u_coord_matrix;uniform bool u_is_text;uniform bool u_pitch_with_map;uniform highp float u_pitch;uniform bool u_rotate_symbol;uniform highp float u_aspect_ratio;uniform highp float u_camera_to_center_distance;uniform float u_fade_change;uniform vec2 u_texsize;uniform vec2 u_texsize_icon;varying vec4 v_data0;varying vec4 v_data1;\n#pragma mapbox: define highp vec4 fill_color\n#pragma mapbox: define highp vec4 halo_color\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float halo_width\n#pragma mapbox: define lowp float halo_blur\nvoid main() {\n#pragma mapbox: initialize highp vec4 fill_color\n#pragma mapbox: initialize highp vec4 halo_color\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float halo_width\n#pragma mapbox: initialize lowp float halo_blur\nvec2 a_pos=a_pos_offset.xy;vec2 a_offset=a_pos_offset.zw;vec2 a_tex=a_data.xy;vec2 a_size=a_data.zw;float a_size_min=floor(a_size[0]*0.5);float is_sdf=a_size[0]-2.0*a_size_min;highp float segment_angle=-a_projected_pos[2];float size;if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {size=mix(a_size_min,a_size[1],u_size_t)/128.0;} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {size=a_size_min/128.0;} else {size=u_size;}vec4 projectedPoint=u_matrix*vec4(a_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float distance_ratio=u_pitch_with_map ?\ncamera_to_anchor_distance/u_camera_to_center_distance :\nu_camera_to_center_distance/camera_to_anchor_distance;highp float perspective_ratio=clamp(0.5+0.5*distance_ratio,0.0,4.0);size*=perspective_ratio;float fontScale=size/24.0;highp float symbol_rotation=0.0;if (u_rotate_symbol) {vec4 offsetProjectedPoint=u_matrix*vec4(a_pos+vec2(1,0),0,1);vec2 a=projectedPoint.xy/projectedPoint.w;vec2 b=offsetProjectedPoint.xy/offsetProjectedPoint.w;symbol_rotation=atan((b.y-a.y)/u_aspect_ratio,b.x-a.x);}highp float angle_sin=sin(segment_angle+symbol_rotation);highp float angle_cos=cos(segment_angle+symbol_rotation);mat2 rotation_matrix=mat2(angle_cos,-1.0*angle_sin,angle_sin,angle_cos);vec4 projected_pos=u_label_plane_matrix*vec4(a_projected_pos.xy,0.0,1.0);gl_Position=u_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matrix*(a_offset/32.0*fontScale),0.0,1.0);float gamma_scale=gl_Position.w;vec2 fade_opacity=unpack_opacity(a_fade_opacity);float fade_change=fade_opacity[1] > 0.5 ? u_fade_change :-u_fade_change;float interpolated_fade_opacity=max(0.0,min(1.0,fade_opacity[0]+fade_change));v_data0.xy=a_tex/u_texsize;v_data0.zw=a_tex/u_texsize_icon;v_data1=vec4(gamma_scale,size,interpolated_fade_opacity,is_sdf);}';
|
|
@@ -2,7 +2,6 @@ import CanvasSource from '../source/canvas_source';
|
|
|
2
2
|
import Transform from '../geo/transform';
|
|
3
3
|
import {Event, Evented} from '../util/evented';
|
|
4
4
|
import {extend} from '../util/util';
|
|
5
|
-
import {stub as sinonStub} from 'sinon';
|
|
6
5
|
|
|
7
6
|
import type Dispatcher from '../util/dispatcher';
|
|
8
7
|
|
|
@@ -62,27 +61,27 @@ describe('CanvasSource', () => {
|
|
|
62
61
|
});
|
|
63
62
|
|
|
64
63
|
test('self-validates', () => {
|
|
65
|
-
const stub =
|
|
64
|
+
const stub = jest.spyOn(console, 'error');
|
|
66
65
|
createSource({coordinates: []});
|
|
67
|
-
expect(stub
|
|
68
|
-
stub.
|
|
66
|
+
expect(stub).toHaveBeenCalled();
|
|
67
|
+
stub.mockReset();
|
|
69
68
|
|
|
70
69
|
createSource({coordinates: 'asdf'});
|
|
71
|
-
expect(stub
|
|
72
|
-
stub.
|
|
70
|
+
expect(stub).toHaveBeenCalled();
|
|
71
|
+
stub.mockReset();
|
|
73
72
|
|
|
74
73
|
createSource({animate: 8});
|
|
75
|
-
expect(stub
|
|
76
|
-
stub.
|
|
74
|
+
expect(stub).toHaveBeenCalled();
|
|
75
|
+
stub.mockReset();
|
|
77
76
|
|
|
78
77
|
createSource({canvas: {}});
|
|
79
|
-
expect(stub
|
|
80
|
-
stub.
|
|
78
|
+
expect(stub).toHaveBeenCalled();
|
|
79
|
+
stub.mockReset();
|
|
81
80
|
|
|
82
81
|
const canvasEl = window.document.createElement('canvas');
|
|
83
82
|
createSource({canvas: canvasEl});
|
|
84
|
-
expect(stub
|
|
85
|
-
stub.
|
|
83
|
+
expect(stub).not.toHaveBeenCalled();
|
|
84
|
+
stub.mockReset();
|
|
86
85
|
|
|
87
86
|
});
|
|
88
87
|
|
|
@@ -11,10 +11,10 @@ import type Dispatcher from '../util/dispatcher';
|
|
|
11
11
|
import type {Evented} from '../util/evented';
|
|
12
12
|
|
|
13
13
|
export type CanvasSourceSpecification = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
'type': 'canvas';
|
|
15
|
+
'coordinates': [[number, number], [number, number], [number, number], [number, number]];
|
|
16
|
+
'animate'?: boolean;
|
|
17
|
+
'canvas': string | HTMLCanvasElement;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -318,7 +318,8 @@ describe('GeoJSONSource#update', () => {
|
|
|
318
318
|
|
|
319
319
|
const source = new GeoJSONSource('id', {data: {}} as GeoJSONSourceOptions, mockDispatcher, undefined);
|
|
320
320
|
source.map = {
|
|
321
|
-
transform: {} as Transform
|
|
321
|
+
transform: {} as Transform,
|
|
322
|
+
getPixelRatio() { return 1; }
|
|
322
323
|
} as any;
|
|
323
324
|
|
|
324
325
|
source.on('data', (e) => {
|
|
@@ -299,7 +299,7 @@ class GeoJSONSource extends Evented implements Source {
|
|
|
299
299
|
maxZoom: this.maxzoom,
|
|
300
300
|
tileSize: this.tileSize,
|
|
301
301
|
source: this.id,
|
|
302
|
-
pixelRatio:
|
|
302
|
+
pixelRatio: this.map.getPixelRatio(),
|
|
303
303
|
showCollisionBoxes: this.map.showCollisionBoxes,
|
|
304
304
|
promoteId: this.promoteId
|
|
305
305
|
};
|
|
@@ -23,24 +23,24 @@ import type {RequestParameters, ResponseCallback} from '../util/ajax';
|
|
|
23
23
|
import type {Callback} from '../types/callback';
|
|
24
24
|
|
|
25
25
|
export type LoadGeoJSONParameters = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
request?: RequestParameters;
|
|
27
|
+
data?: string;
|
|
28
|
+
source: string;
|
|
29
|
+
cluster: boolean;
|
|
30
|
+
superclusterOptions?: any;
|
|
31
|
+
geojsonVtOptions?: any;
|
|
32
|
+
clusterProperties?: any;
|
|
33
|
+
filter?: Array<unknown>;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
export type LoadGeoJSON = (params: LoadGeoJSONParameters, callback: ResponseCallback<any>) => void;
|
|
37
37
|
|
|
38
38
|
export interface GeoJSONIndex {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
getTile(z: number, x: number, y: number): any;
|
|
40
|
+
// supercluster methods
|
|
41
|
+
getClusterExpansionZoom(clusterId: number): number;
|
|
42
|
+
getChildren(clusterId: number): Array<GeoJSON.Feature>;
|
|
43
|
+
getLeaves(clusterId: number, limit: number, offset: number): Array<GeoJSON.Feature>;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
function loadGeoJSONTile(params: WorkerTileParameters, callback: LoadVectorDataCallback): (() => void) | void {
|
|
@@ -89,8 +89,8 @@ export type SourceState = // Source empty or data loaded
|
|
|
89
89
|
class GeoJSONWorkerSource extends VectorTileWorkerSource {
|
|
90
90
|
_state: SourceState;
|
|
91
91
|
_pendingCallback: Callback<{
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
resourceTiming?: {[_: string]: Array<PerformanceResourceTiming>};
|
|
93
|
+
abandoned?: boolean;
|
|
94
94
|
}>;
|
|
95
95
|
_pendingLoadDataParams: LoadGeoJSONParameters;
|
|
96
96
|
_geoJSONIndex: GeoJSONIndex;
|
|
@@ -126,8 +126,8 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
|
|
|
126
126
|
* @private
|
|
127
127
|
*/
|
|
128
128
|
loadData(params: LoadGeoJSONParameters, callback: Callback<{
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
resourceTiming?: {[_: string]: Array<PerformanceResourceTiming>};
|
|
130
|
+
abandoned?: boolean;
|
|
131
131
|
}>) {
|
|
132
132
|
if (this._pendingCallback) {
|
|
133
133
|
// Tell the foreground the previous call has been abandoned
|
|
@@ -285,7 +285,7 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
|
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
removeSource(params: {
|
|
288
|
-
|
|
288
|
+
source: string;
|
|
289
289
|
}, callback: WorkerTileCallback) {
|
|
290
290
|
if (this._pendingCallback) {
|
|
291
291
|
// Don't leak callbacks
|
|
@@ -295,7 +295,7 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
|
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
getClusterExpansionZoom(params: {
|
|
298
|
-
|
|
298
|
+
clusterId: number;
|
|
299
299
|
}, callback: Callback<number>) {
|
|
300
300
|
try {
|
|
301
301
|
callback(null, this._geoJSONIndex.getClusterExpansionZoom(params.clusterId));
|
|
@@ -305,7 +305,7 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
getClusterChildren(params: {
|
|
308
|
-
|
|
308
|
+
clusterId: number;
|
|
309
309
|
}, callback: Callback<Array<GeoJSON.Feature>>) {
|
|
310
310
|
try {
|
|
311
311
|
callback(null, this._geoJSONIndex.getChildren(params.clusterId));
|
|
@@ -315,9 +315,9 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
|
|
|
315
315
|
}
|
|
316
316
|
|
|
317
317
|
getClusterLeaves(params: {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
318
|
+
clusterId: number;
|
|
319
|
+
limit: number;
|
|
320
|
+
offset: number;
|
|
321
321
|
}, callback: Callback<Array<GeoJSON.Feature>>) {
|
|
322
322
|
try {
|
|
323
323
|
callback(null, this._geoJSONIndex.getLeaves(params.clusterId, params.limit, params.offset));
|
|
@@ -8,15 +8,15 @@ import EXTENT from '../data/extent';
|
|
|
8
8
|
// The feature type used by geojson-vt and supercluster. Should be extracted to
|
|
9
9
|
// global type and used in module definitions for those two modules.
|
|
10
10
|
export type Feature = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
type: 1;
|
|
12
|
+
id: any;
|
|
13
|
+
tags: {[_: string]: string | number | boolean};
|
|
14
|
+
geometry: Array<[number, number]>;
|
|
15
15
|
} | {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
type: 2 | 3;
|
|
17
|
+
id: any;
|
|
18
|
+
tags: {[_: string]: string | number | boolean};
|
|
19
|
+
geometry: Array<Array<[number, number]>>;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
class FeatureWrapper implements VectorTileFeature {
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import ImageSource from './image_source';
|
|
2
|
+
import {Evented} from '../util/evented';
|
|
3
|
+
import Transform from '../geo/transform';
|
|
4
|
+
import {extend} from '../util/util';
|
|
5
|
+
import {fakeXhr} from 'nise';
|
|
6
|
+
import {RequestManager} from '../util/request_manager';
|
|
7
|
+
import Dispatcher from '../util/dispatcher';
|
|
8
|
+
import {stubAjaxGetImage} from '../util/test/util';
|
|
9
|
+
|
|
10
|
+
function createSource(options) {
|
|
11
|
+
options = extend({
|
|
12
|
+
coordinates: [[0, 0], [1, 0], [1, 1], [0, 1]]
|
|
13
|
+
}, options);
|
|
14
|
+
|
|
15
|
+
const source = new ImageSource('id', options, {send() {}} as any as Dispatcher, options.eventedParent);
|
|
16
|
+
return source;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class StubMap extends Evented {
|
|
20
|
+
transform: Transform;
|
|
21
|
+
_requestManager: RequestManager;
|
|
22
|
+
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
this.transform = new Transform();
|
|
26
|
+
this._requestManager = {
|
|
27
|
+
transformRequest: (url) => {
|
|
28
|
+
return {url};
|
|
29
|
+
}
|
|
30
|
+
} as any as RequestManager;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe('ImageSource', () => {
|
|
35
|
+
const requests = [];
|
|
36
|
+
fakeXhr.useFakeXMLHttpRequest().onCreate = (req) => { requests.push(req); };
|
|
37
|
+
stubAjaxGetImage(undefined);
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
global.fetch = null;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const respond = () => {
|
|
43
|
+
const req = requests.shift();
|
|
44
|
+
req.setStatus(200);
|
|
45
|
+
req.response = new ArrayBuffer(1);
|
|
46
|
+
req.onload();
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
test('constructor', () => {
|
|
50
|
+
const source = createSource({url : '/image.png'});
|
|
51
|
+
|
|
52
|
+
expect(source.minzoom).toBe(0);
|
|
53
|
+
expect(source.maxzoom).toBe(22);
|
|
54
|
+
expect(source.tileSize).toBe(512);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('fires dataloading event', () => {
|
|
58
|
+
const source = createSource({url : '/image.png'});
|
|
59
|
+
source.on('dataloading', (e) => {
|
|
60
|
+
expect(e.dataType).toBe('source');
|
|
61
|
+
});
|
|
62
|
+
source.onAdd(new StubMap() as any);
|
|
63
|
+
respond();
|
|
64
|
+
expect(source.image).toBeTruthy();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('transforms url request', () => {
|
|
68
|
+
const source = createSource({url : '/image.png'});
|
|
69
|
+
const map = new StubMap() as any;
|
|
70
|
+
const spy = jest.spyOn(map._requestManager, 'transformRequest');
|
|
71
|
+
source.onAdd(map);
|
|
72
|
+
respond();
|
|
73
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
74
|
+
expect(spy.mock.calls[0][0]).toBe('/image.png');
|
|
75
|
+
expect(spy.mock.calls[0][1]).toBe('Image');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('updates url from updateImage', () => {
|
|
79
|
+
const source = createSource({url : '/image.png'});
|
|
80
|
+
const map = new StubMap() as any;
|
|
81
|
+
const spy = jest.spyOn(map._requestManager, 'transformRequest');
|
|
82
|
+
source.onAdd(map);
|
|
83
|
+
respond();
|
|
84
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
85
|
+
expect(spy.mock.calls[0][0]).toBe('/image.png');
|
|
86
|
+
expect(spy.mock.calls[0][1]).toBe('Image');
|
|
87
|
+
source.updateImage({url: '/image2.png'});
|
|
88
|
+
respond();
|
|
89
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
|
90
|
+
expect(spy.mock.calls[1][0]).toBe('/image2.png');
|
|
91
|
+
expect(spy.mock.calls[1][1]).toBe('Image');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('sets coordinates', () => {
|
|
95
|
+
const source = createSource({url : '/image.png'});
|
|
96
|
+
const map = new StubMap() as any;
|
|
97
|
+
source.onAdd(map);
|
|
98
|
+
respond();
|
|
99
|
+
const beforeSerialized = source.serialize();
|
|
100
|
+
expect(beforeSerialized.coordinates).toEqual([[0, 0], [1, 0], [1, 1], [0, 1]]);
|
|
101
|
+
source.setCoordinates([[0, 0], [-1, 0], [-1, -1], [0, -1]]);
|
|
102
|
+
const afterSerialized = source.serialize();
|
|
103
|
+
expect(afterSerialized.coordinates).toEqual([[0, 0], [-1, 0], [-1, -1], [0, -1]]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('sets coordinates via updateImage', () => {
|
|
107
|
+
const source = createSource({url : '/image.png'});
|
|
108
|
+
const map = new StubMap() as any;
|
|
109
|
+
source.onAdd(map);
|
|
110
|
+
respond();
|
|
111
|
+
const beforeSerialized = source.serialize();
|
|
112
|
+
expect(beforeSerialized.coordinates).toEqual([[0, 0], [1, 0], [1, 1], [0, 1]]);
|
|
113
|
+
source.updateImage({
|
|
114
|
+
url: '/image2.png',
|
|
115
|
+
coordinates: [[0, 0], [-1, 0], [-1, -1], [0, -1]]
|
|
116
|
+
});
|
|
117
|
+
respond();
|
|
118
|
+
const afterSerialized = source.serialize();
|
|
119
|
+
expect(afterSerialized.coordinates).toEqual([[0, 0], [-1, 0], [-1, -1], [0, -1]]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('fires data event when content is loaded', done => {
|
|
123
|
+
const source = createSource({url : '/image.png'});
|
|
124
|
+
source.on('data', (e) => {
|
|
125
|
+
if (e.dataType === 'source' && e.sourceDataType === 'content') {
|
|
126
|
+
expect(typeof source.tileID == 'object').toBeTruthy();
|
|
127
|
+
done();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
source.onAdd(new StubMap() as any);
|
|
131
|
+
respond();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('fires data event when metadata is loaded', done => {
|
|
135
|
+
const source = createSource({url : '/image.png'});
|
|
136
|
+
source.on('data', (e) => {
|
|
137
|
+
if (e.dataType === 'source' && e.sourceDataType === 'metadata') {
|
|
138
|
+
done();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
source.onAdd(new StubMap() as any);
|
|
142
|
+
respond();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('serialize url and coordinates', () => {
|
|
146
|
+
const source = createSource({url: '/image.png'});
|
|
147
|
+
|
|
148
|
+
const serialized = source.serialize();
|
|
149
|
+
expect(serialized.type).toBe('image');
|
|
150
|
+
expect(serialized.url).toBe('/image.png');
|
|
151
|
+
expect(serialized.coordinates).toEqual([[0, 0], [1, 0], [1, 1], [0, 1]]);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -2,7 +2,7 @@ import {CanonicalTileID} from './tile_id';
|
|
|
2
2
|
import {Event, ErrorEvent, Evented} from '../util/evented';
|
|
3
3
|
import {getImage, ResourceType} from '../util/ajax';
|
|
4
4
|
import EXTENT from '../data/extent';
|
|
5
|
-
import {RasterBoundsArray} from '../data/array_types';
|
|
5
|
+
import {RasterBoundsArray} from '../data/array_types.g';
|
|
6
6
|
import rasterBoundsAttributes from '../data/raster_bounds_attributes';
|
|
7
7
|
import SegmentVector from '../data/segment';
|
|
8
8
|
import Texture from '../render/texture';
|
|
@@ -143,8 +143,8 @@ class ImageSource extends Evented implements Source {
|
|
|
143
143
|
* @returns {ImageSource} this
|
|
144
144
|
*/
|
|
145
145
|
updateImage(options: {
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
url: string;
|
|
147
|
+
coordinates?: Coordinates;
|
|
148
148
|
}) {
|
|
149
149
|
if (!this.image || !options.url) {
|
|
150
150
|
return this;
|
|
@@ -299,9 +299,9 @@ export function getCoordinatesCenterTileID(coords: Array<MercatorCoordinate>) {
|
|
|
299
299
|
const tilesAtZoom = Math.pow(2, zoom);
|
|
300
300
|
|
|
301
301
|
return new CanonicalTileID(
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
302
|
+
zoom,
|
|
303
|
+
Math.floor((minX + maxX) / 2 * tilesAtZoom),
|
|
304
|
+
Math.floor((minY + maxY) / 2 * tilesAtZoom));
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
export default ImageSource;
|
|
@@ -15,12 +15,12 @@ import type {OverscaledTileID} from './tile_id';
|
|
|
15
15
|
* @private
|
|
16
16
|
*/
|
|
17
17
|
export default function(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
tile: {
|
|
19
|
+
tileID: OverscaledTileID;
|
|
20
|
+
tileSize: number;
|
|
21
|
+
},
|
|
22
|
+
pixelValue: number,
|
|
23
|
+
z: number
|
|
24
24
|
): number {
|
|
25
25
|
return pixelValue * (EXTENT / (tile.tileSize * Math.pow(2, z - tile.tileID.overscaledZ)));
|
|
26
26
|
}
|