@mapwhit/tilerenderer 0.51.0 → 0.52.0
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/min/package.json +1 -1
- package/package.json +13 -9
- package/src/data/array_types.js +1 -1
- package/src/data/bucket/circle_bucket.js +4 -1
- package/src/data/bucket/fill_bucket.js +5 -1
- package/src/data/bucket/fill_extrusion_bucket.js +5 -1
- package/src/data/bucket/line_bucket.js +5 -1
- package/src/data/bucket/symbol_bucket.js +3 -2
- package/src/geo/transform.js +1 -1
- package/src/index.js +2 -2
- package/src/render/glyph_atlas.js +1 -1
- package/src/render/image_atlas.js +1 -1
- package/src/render/image_manager.js +1 -1
- package/src/source/geojson_source.js +3 -2
- package/src/source/geojson_worker_source.js +4 -4
- package/src/source/geojson_wrapper.js +1 -1
- package/src/source/image_source.js +2 -2
- package/src/source/raster_tile_source.js +1 -1
- package/src/source/rtl_text_plugin.js +1 -1
- package/src/source/source_cache.js +2 -2
- package/src/source/tile.js +1 -1
- package/src/source/vector_tile_source.js +3 -2
- package/src/source/vector_tile_worker_source.js +1 -0
- package/src/source/worker_tile.js +8 -6
- package/src/style/evaluation_parameters.js +6 -4
- package/src/style/light.js +1 -1
- package/src/style/properties.js +4 -0
- package/src/style/query_utils.js +1 -1
- package/src/style/style.js +80 -3
- package/src/style/style_layer/circle_style_layer.js +1 -1
- package/src/style/style_layer/fill_extrusion_style_layer.js +1 -1
- package/src/style/style_layer/line_style_layer.js +1 -1
- package/src/style/style_layer.js +34 -2
- package/src/style-spec/feature_filter/index.js +13 -4
- package/src/style-spec/reference/v8.json +53 -13
- package/src/symbol/anchor.js +1 -1
- package/src/symbol/clip_line.js +1 -1
- package/src/symbol/collision_feature.js +1 -1
- package/src/symbol/collision_index.js +1 -1
- package/src/symbol/projection.js +1 -1
- package/src/symbol/quads.js +1 -1
- package/src/ui/camera.js +2 -2
- package/src/ui/map.js +27 -5
- package/src/util/config.js +1 -1
- package/src/util/find_pole_of_inaccessibility.js +1 -1
- package/src/util/intersection_tests.js +1 -1
- package/src/util/transfer_registry.js +1 -0
- package/src/worker.js +4 -0
- package/build/min/src/shaders/_prelude.fragment.glsl.txt +0 -13
- package/build/min/src/shaders/_prelude.vertex.glsl.txt +0 -14
- package/build/min/src/shaders/background.fragment.glsl.txt +0 -5
- package/build/min/src/shaders/background.vertex.glsl.txt +0 -1
- package/build/min/src/shaders/background_pattern.fragment.glsl.txt +0 -5
- package/build/min/src/shaders/background_pattern.vertex.glsl.txt +0 -1
- package/build/min/src/shaders/circle.fragment.glsl.txt +0 -20
- package/build/min/src/shaders/circle.vertex.glsl.txt +0 -17
- package/build/min/src/shaders/clipping_mask.fragment.glsl.txt +0 -1
- package/build/min/src/shaders/clipping_mask.vertex.glsl.txt +0 -1
- package/build/min/src/shaders/collision_box.fragment.glsl.txt +0 -1
- package/build/min/src/shaders/collision_box.vertex.glsl.txt +0 -1
- package/build/min/src/shaders/collision_circle.fragment.glsl.txt +0 -1
- package/build/min/src/shaders/collision_circle.vertex.glsl.txt +0 -1
- package/build/min/src/shaders/debug.fragment.glsl.txt +0 -1
- package/build/min/src/shaders/debug.vertex.glsl.txt +0 -1
- package/build/min/src/shaders/fill.fragment.glsl.txt +0 -10
- package/build/min/src/shaders/fill.vertex.glsl.txt +0 -7
- package/build/min/src/shaders/fill_extrusion.fragment.glsl.txt +0 -5
- package/build/min/src/shaders/fill_extrusion.vertex.glsl.txt +0 -9
- package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.txt +0 -15
- package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.txt +0 -11
- package/build/min/src/shaders/fill_outline.fragment.glsl.txt +0 -10
- package/build/min/src/shaders/fill_outline.vertex.glsl.txt +0 -7
- package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.txt +0 -13
- package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.txt +0 -9
- package/build/min/src/shaders/fill_pattern.fragment.glsl.txt +0 -13
- package/build/min/src/shaders/fill_pattern.vertex.glsl.txt +0 -9
- package/build/min/src/shaders/heatmap.fragment.glsl.txt +0 -10
- package/build/min/src/shaders/heatmap.vertex.glsl.txt +0 -8
- package/build/min/src/shaders/heatmap_texture.fragment.glsl.txt +0 -5
- package/build/min/src/shaders/heatmap_texture.vertex.glsl.txt +0 -1
- package/build/min/src/shaders/hillshade.fragment.glsl.txt +0 -7
- package/build/min/src/shaders/hillshade.vertex.glsl.txt +0 -1
- package/build/min/src/shaders/hillshade_prepare.fragment.glsl.txt +0 -8
- package/build/min/src/shaders/hillshade_prepare.vertex.glsl.txt +0 -1
- package/build/min/src/shaders/line.fragment.glsl.txt +0 -12
- package/build/min/src/shaders/line.vertex.glsl.txt +0 -17
- package/build/min/src/shaders/line_gradient.fragment.glsl.txt +0 -10
- package/build/min/src/shaders/line_gradient.vertex.glsl.txt +0 -16
- package/build/min/src/shaders/line_pattern.fragment.glsl.txt +0 -15
- package/build/min/src/shaders/line_pattern.vertex.glsl.txt +0 -20
- package/build/min/src/shaders/line_sdf.fragment.glsl.txt +0 -17
- package/build/min/src/shaders/line_sdf.vertex.glsl.txt +0 -20
- package/build/min/src/shaders/raster.fragment.glsl.txt +0 -5
- package/build/min/src/shaders/raster.vertex.glsl.txt +0 -1
- package/build/min/src/shaders/symbol_icon.fragment.glsl.txt +0 -9
- package/build/min/src/shaders/symbol_icon.vertex.glsl.txt +0 -5
- package/build/min/src/shaders/symbol_sdf.fragment.glsl.txt +0 -19
- package/build/min/src/shaders/symbol_sdf.vertex.glsl.txt +0 -13
- package/src/util/evented.js +0 -182
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
uniform vec2 u_texsize;uniform float u_fade;uniform sampler2D u_image;varying vec2 v_pos_a;varying vec2 v_pos_b;
|
|
2
|
-
#pragma mapbox: define lowp float opacity
|
|
3
|
-
#pragma mapbox: define lowp vec4 pattern_from
|
|
4
|
-
#pragma mapbox: define lowp vec4 pattern_to
|
|
5
|
-
void main(){
|
|
6
|
-
#pragma mapbox: initialize lowp float opacity
|
|
7
|
-
#pragma mapbox: initialize mediump vec4 pattern_from
|
|
8
|
-
#pragma mapbox: initialize mediump vec4 pattern_to
|
|
9
|
-
vec2 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;vec2 imagecoord=mod(v_pos_a,1.);vec2 pos=mix(pattern_tl_a/u_texsize,pattern_br_a/u_texsize,imagecoord);vec4 color1=texture2D(u_image,pos);vec2 imagecoord_b=mod(v_pos_b,1.);vec2 pos2=mix(pattern_tl_b/u_texsize,pattern_br_b/u_texsize,imagecoord_b);vec4 color2=texture2D(u_image,pos2);gl_FragColor=mix(color1,color2,u_fade)*opacity;
|
|
10
|
-
#ifdef OVERDRAW_INSPECTOR
|
|
11
|
-
gl_FragColor=vec4(1.);
|
|
12
|
-
#endif
|
|
13
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
uniform mat4 u_matrix;uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform vec4 u_scale;attribute vec2 a_pos;varying vec2 v_pos_a;varying vec2 v_pos_b;
|
|
2
|
-
#pragma mapbox: define lowp float opacity
|
|
3
|
-
#pragma mapbox: define lowp vec4 pattern_from
|
|
4
|
-
#pragma mapbox: define lowp vec4 pattern_to
|
|
5
|
-
void main(){
|
|
6
|
-
#pragma mapbox: initialize lowp float opacity
|
|
7
|
-
#pragma mapbox: initialize mediump vec4 pattern_from
|
|
8
|
-
#pragma mapbox: initialize mediump vec4 pattern_to
|
|
9
|
-
vec2 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 pixelRatio=u_scale.x;float tileZoomRatio=u_scale.y;float fromScale=u_scale.z;float toScale=u_scale.w;vec2 display_size_a=vec2((pattern_br_a.x-pattern_tl_a.x)/pixelRatio,(pattern_br_a.y-pattern_tl_a.y)/pixelRatio);vec2 display_size_b=vec2((pattern_br_b.x-pattern_tl_b.x)/pixelRatio,(pattern_br_b.y-pattern_tl_b.y)/pixelRatio);gl_Position=u_matrix*vec4(a_pos,0,1);v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,fromScale*display_size_a,tileZoomRatio,a_pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,toScale*display_size_b,tileZoomRatio,a_pos);}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#pragma mapbox: define highp float weight
|
|
2
|
-
uniform highp float u_intensity;varying vec2 v_extrude;
|
|
3
|
-
#define GAUSS_COEF 0.3989422804014327
|
|
4
|
-
void main(){
|
|
5
|
-
#pragma mapbox: initialize highp float weight
|
|
6
|
-
float d=-0.5*3.*3.*dot(v_extrude,v_extrude);float val=weight*u_intensity*GAUSS_COEF*exp(d);gl_FragColor=vec4(val,1.,1.,1.);
|
|
7
|
-
#ifdef OVERDRAW_INSPECTOR
|
|
8
|
-
gl_FragColor=vec4(1.);
|
|
9
|
-
#endif
|
|
10
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
#pragma mapbox: define highp float weight
|
|
2
|
-
#pragma mapbox: define mediump float radius
|
|
3
|
-
uniform mat4 u_matrix;uniform float u_extrude_scale;uniform float u_opacity;uniform float u_intensity;attribute vec2 a_pos;varying vec2 v_extrude;const highp float ZERO=1./255./16.;
|
|
4
|
-
#define GAUSS_COEF 0.3989422804014327
|
|
5
|
-
void main(void){
|
|
6
|
-
#pragma mapbox: initialize highp float weight
|
|
7
|
-
#pragma mapbox: initialize mediump float radius
|
|
8
|
-
vec2 unscaled_extrude=vec2(mod(a_pos,2.)*2.-1.);float S=sqrt(-2.*log(ZERO/weight/u_intensity/GAUSS_COEF))/3.;v_extrude=S*unscaled_extrude;vec2 extrude=v_extrude*radius*u_extrude_scale;vec4 pos=vec4(floor(a_pos*0.5)+extrude,0,1);gl_Position=u_matrix*pos;}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
uniform sampler2D u_image;uniform sampler2D u_color_ramp;uniform float u_opacity;varying vec2 v_pos;void main(){float t=texture2D(u_image,v_pos).r;vec4 color=texture2D(u_color_ramp,vec2(t,0.5));gl_FragColor=color*u_opacity;
|
|
2
|
-
#ifdef OVERDRAW_INSPECTOR
|
|
3
|
-
gl_FragColor=vec4(0.);
|
|
4
|
-
#endif
|
|
5
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
uniform mat4 u_matrix;uniform vec2 u_world;attribute vec2 a_pos;varying vec2 v_pos;void main(){gl_Position=u_matrix*vec4(a_pos*u_world,0,1);v_pos.x=a_pos.x;v_pos.y=1.-a_pos.y;}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
uniform sampler2D u_image;varying vec2 v_pos;uniform vec2 u_latrange;uniform vec2 u_light;uniform vec4 u_shadow;uniform vec4 u_highlight;uniform vec4 u_accent;
|
|
2
|
-
#define PI 3.141592653589793
|
|
3
|
-
void main(){vec4 pixel=texture2D(u_image,v_pos);vec2 deriv=((pixel.rg*2.)-1.);float scaleFactor=cos(radians((u_latrange[0]-u_latrange[1])*(1.-v_pos.y)+u_latrange[1]));float slope=atan(1.25*length(deriv)/scaleFactor);float aspect=deriv.x!=0.?atan(deriv.y,-deriv.x):PI/2.*(deriv.y>0.?1.:-1.);float intensity=u_light.x;float azimuth=u_light.y+PI;float base=1.875-intensity*1.75;float maxValue=0.5*PI;float scaledSlope=intensity!=0.5?((pow(base,slope)-1.)/(pow(base,maxValue)-1.))*maxValue:slope;float accent=cos(scaledSlope);vec4 accent_color=(1.-accent)*u_accent*clamp(intensity*2.,0.,1.);float shade=abs(mod((aspect+azimuth)/PI+0.5,2.)-1.);vec4 shade_color=mix(u_shadow,u_highlight,shade)*sin(scaledSlope)*clamp(intensity*2.,0.,1.);gl_FragColor=accent_color*(1.-shade_color.a)+shade_color;
|
|
4
|
-
#ifdef OVERDRAW_INSPECTOR
|
|
5
|
-
gl_FragColor=vec4(1.);
|
|
6
|
-
#endif
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
uniform mat4 u_matrix;attribute vec2 a_pos;attribute vec2 a_texture_pos;varying vec2 v_pos;void main(){gl_Position=u_matrix*vec4(a_pos,0,1);v_pos=a_texture_pos/8192.;}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
#ifdef GL_ES
|
|
2
|
-
precision highp float;
|
|
3
|
-
#endif
|
|
4
|
-
uniform sampler2D u_image;varying vec2 v_pos;uniform vec2 u_dimension;uniform float u_zoom;uniform float u_maxzoom;float getElevation(vec2 coord,float bias){vec4 data=texture2D(u_image,coord)*255.;return(data.r+data.g*256.+data.b*256.*256.)/4.;}void main(){vec2 epsilon=1./u_dimension;float a=getElevation(v_pos+vec2(-epsilon.x,-epsilon.y),0.);float b=getElevation(v_pos+vec2(0,-epsilon.y),0.);float c=getElevation(v_pos+vec2(epsilon.x,-epsilon.y),0.);float d=getElevation(v_pos+vec2(-epsilon.x,0),0.);float e=getElevation(v_pos,0.);float f=getElevation(v_pos+vec2(epsilon.x,0),0.);float g=getElevation(v_pos+vec2(-epsilon.x,epsilon.y),0.);float h=getElevation(v_pos+vec2(0,epsilon.y),0.);float i=getElevation(v_pos+vec2(epsilon.x,epsilon.y),0.);float exaggeration=u_zoom<2.?0.4:u_zoom<4.5?0.35:0.3;vec2 deriv=vec2((c+f+f+i)-(a+d+d+g),(g+h+h+i)-(a+b+b+c))/pow(2.,(u_zoom-u_maxzoom)*exaggeration+19.2562-u_zoom);gl_FragColor=clamp(vec4(deriv.x/2.+0.5,deriv.y/2.+0.5,1.,1.),0.,1.);
|
|
5
|
-
#ifdef OVERDRAW_INSPECTOR
|
|
6
|
-
gl_FragColor=vec4(1.);
|
|
7
|
-
#endif
|
|
8
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
uniform mat4 u_matrix;uniform vec2 u_dimension;attribute vec2 a_pos;attribute vec2 a_texture_pos;varying vec2 v_pos;void main(){gl_Position=u_matrix*vec4(a_pos,0,1);vec2 epsilon=1./u_dimension;float scale=(u_dimension.x-2.)/u_dimension.x;v_pos=(a_texture_pos/8192.)*scale+epsilon;}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
#pragma mapbox: define highp vec4 color
|
|
2
|
-
#pragma mapbox: define lowp float blur
|
|
3
|
-
#pragma mapbox: define lowp float opacity
|
|
4
|
-
varying vec2 v_width2;varying vec2 v_normal;varying float v_gamma_scale;void main(){
|
|
5
|
-
#pragma mapbox: initialize highp vec4 color
|
|
6
|
-
#pragma mapbox: initialize lowp float blur
|
|
7
|
-
#pragma mapbox: initialize lowp float opacity
|
|
8
|
-
float dist=length(v_normal)*v_width2.s;float blur2=(blur+1./DEVICE_PIXEL_RATIO)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.,1.);gl_FragColor=color*(alpha*opacity);
|
|
9
|
-
#ifdef OVERDRAW_INSPECTOR
|
|
10
|
-
gl_FragColor=vec4(1.);
|
|
11
|
-
#endif
|
|
12
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#define ANTIALIASING 1.0 / DEVICE_PIXEL_RATIO / 2.0
|
|
2
|
-
#define scale 0.015873016
|
|
3
|
-
attribute vec4 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform mediump float u_ratio;uniform vec2 u_gl_units_to_pixels;varying vec2 v_normal;varying vec2 v_width2;varying float v_gamma_scale;varying highp float v_linesofar;
|
|
4
|
-
#pragma mapbox: define highp vec4 color
|
|
5
|
-
#pragma mapbox: define lowp float blur
|
|
6
|
-
#pragma mapbox: define lowp float opacity
|
|
7
|
-
#pragma mapbox: define mediump float gapwidth
|
|
8
|
-
#pragma mapbox: define lowp float offset
|
|
9
|
-
#pragma mapbox: define mediump float width
|
|
10
|
-
void main(){
|
|
11
|
-
#pragma mapbox: initialize highp vec4 color
|
|
12
|
-
#pragma mapbox: initialize lowp float blur
|
|
13
|
-
#pragma mapbox: initialize lowp float opacity
|
|
14
|
-
#pragma mapbox: initialize mediump float gapwidth
|
|
15
|
-
#pragma mapbox: initialize lowp float offset
|
|
16
|
-
#pragma mapbox: initialize mediump float width
|
|
17
|
-
vec2 a_extrude=a_data.xy-128.;float a_direction=mod(a_data.z,4.)-1.;v_linesofar=(floor(a_data.z/4.)+a_data.w*64.)*2.;vec2 pos=a_pos_normal.xy;mediump vec2 normal=a_pos_normal.zw;v_normal=normal;gapwidth=gapwidth/2.;float halfwidth=width/2.;offset=-1.*offset;float inset=gapwidth+(gapwidth>0.?ANTIALIASING:0.);float outset=gapwidth+halfwidth*(gapwidth>0.?2.:1.)+(halfwidth==0.?0.:ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.-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.);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.,1.)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_gl_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_width2=vec2(outset,inset);}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#pragma mapbox: define lowp float blur
|
|
2
|
-
#pragma mapbox: define lowp float opacity
|
|
3
|
-
uniform sampler2D u_image;varying vec2 v_width2;varying vec2 v_normal;varying float v_gamma_scale;varying highp float v_lineprogress;void main(){
|
|
4
|
-
#pragma mapbox: initialize lowp float blur
|
|
5
|
-
#pragma mapbox: initialize lowp float opacity
|
|
6
|
-
float dist=length(v_normal)*v_width2.s;float blur2=(blur+1./DEVICE_PIXEL_RATIO)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.,1.);vec4 color=texture2D(u_image,vec2(v_lineprogress,0.5));gl_FragColor=color*(alpha*opacity);
|
|
7
|
-
#ifdef OVERDRAW_INSPECTOR
|
|
8
|
-
gl_FragColor=vec4(1.);
|
|
9
|
-
#endif
|
|
10
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#define MAX_LINE_DISTANCE 32767.0
|
|
2
|
-
#define ANTIALIASING 1.0 / DEVICE_PIXEL_RATIO / 2.0
|
|
3
|
-
#define scale 0.015873016
|
|
4
|
-
attribute vec4 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform mediump float u_ratio;uniform vec2 u_gl_units_to_pixels;varying vec2 v_normal;varying vec2 v_width2;varying float v_gamma_scale;varying highp float v_lineprogress;
|
|
5
|
-
#pragma mapbox: define lowp float blur
|
|
6
|
-
#pragma mapbox: define lowp float opacity
|
|
7
|
-
#pragma mapbox: define mediump float gapwidth
|
|
8
|
-
#pragma mapbox: define lowp float offset
|
|
9
|
-
#pragma mapbox: define mediump float width
|
|
10
|
-
void main(){
|
|
11
|
-
#pragma mapbox: initialize lowp float blur
|
|
12
|
-
#pragma mapbox: initialize lowp float opacity
|
|
13
|
-
#pragma mapbox: initialize mediump float gapwidth
|
|
14
|
-
#pragma mapbox: initialize lowp float offset
|
|
15
|
-
#pragma mapbox: initialize mediump float width
|
|
16
|
-
vec2 a_extrude=a_data.xy-128.;float a_direction=mod(a_data.z,4.)-1.;v_lineprogress=(floor(a_data.z/4.)+a_data.w*64.)*2./MAX_LINE_DISTANCE;vec2 pos=a_pos_normal.xy;mediump vec2 normal=a_pos_normal.zw;v_normal=normal;gapwidth=gapwidth/2.;float halfwidth=width/2.;offset=-1.*offset;float inset=gapwidth+(gapwidth>0.?ANTIALIASING:0.);float outset=gapwidth+halfwidth*(gapwidth>0.?2.:1.)+(halfwidth==0.?0.:ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.-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.);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.,1.)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_gl_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_width2=vec2(outset,inset);}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
uniform vec2 u_texsize;uniform float u_fade;uniform mediump vec4 u_scale;uniform sampler2D u_image;varying vec2 v_normal;varying vec2 v_width2;varying float v_linesofar;varying float v_gamma_scale;
|
|
2
|
-
#pragma mapbox: define lowp vec4 pattern_from
|
|
3
|
-
#pragma mapbox: define lowp vec4 pattern_to
|
|
4
|
-
#pragma mapbox: define lowp float blur
|
|
5
|
-
#pragma mapbox: define lowp float opacity
|
|
6
|
-
void main(){
|
|
7
|
-
#pragma mapbox: initialize mediump vec4 pattern_from
|
|
8
|
-
#pragma mapbox: initialize mediump vec4 pattern_to
|
|
9
|
-
#pragma mapbox: initialize lowp float blur
|
|
10
|
-
#pragma mapbox: initialize lowp float opacity
|
|
11
|
-
vec2 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 pixelRatio=u_scale.x;float tileZoomRatio=u_scale.y;float fromScale=u_scale.z;float toScale=u_scale.w;vec2 display_size_a=vec2((pattern_br_a.x-pattern_tl_a.x)/pixelRatio,(pattern_br_a.y-pattern_tl_a.y)/pixelRatio);vec2 display_size_b=vec2((pattern_br_b.x-pattern_tl_b.x)/pixelRatio,(pattern_br_b.y-pattern_tl_b.y)/pixelRatio);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 dist=length(v_normal)*v_width2.s;float blur2=(blur+1./DEVICE_PIXEL_RATIO)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.,1.);float x_a=mod(v_linesofar/pattern_size_a.x,1.);float x_b=mod(v_linesofar/pattern_size_b.x,1.);float y_a=0.5+(v_normal.y*clamp(v_width2.s,0.,(pattern_size_a.y+2.)/2.)/pattern_size_a.y);float y_b=0.5+(v_normal.y*clamp(v_width2.s,0.,(pattern_size_b.y+2.)/2.)/pattern_size_b.y);vec2 pos_a=mix(pattern_tl_a/u_texsize,pattern_br_a/u_texsize,vec2(x_a,y_a));vec2 pos_b=mix(pattern_tl_b/u_texsize,pattern_br_b/u_texsize,vec2(x_b,y_b));vec4 color=mix(texture2D(u_image,pos_a),texture2D(u_image,pos_b),u_fade);gl_FragColor=color*alpha*opacity;
|
|
12
|
-
#ifdef OVERDRAW_INSPECTOR
|
|
13
|
-
gl_FragColor=vec4(1.);
|
|
14
|
-
#endif
|
|
15
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#define scale 0.015873016
|
|
2
|
-
#define LINE_DISTANCE_SCALE 2.0
|
|
3
|
-
#define ANTIALIASING 1.0 / DEVICE_PIXEL_RATIO / 2.0
|
|
4
|
-
attribute vec4 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform vec2 u_gl_units_to_pixels;uniform mediump float u_ratio;varying vec2 v_normal;varying vec2 v_width2;varying float v_linesofar;varying float v_gamma_scale;
|
|
5
|
-
#pragma mapbox: define lowp float blur
|
|
6
|
-
#pragma mapbox: define lowp float opacity
|
|
7
|
-
#pragma mapbox: define lowp float offset
|
|
8
|
-
#pragma mapbox: define mediump float gapwidth
|
|
9
|
-
#pragma mapbox: define mediump float width
|
|
10
|
-
#pragma mapbox: define lowp vec4 pattern_from
|
|
11
|
-
#pragma mapbox: define lowp vec4 pattern_to
|
|
12
|
-
void main(){
|
|
13
|
-
#pragma mapbox: initialize lowp float blur
|
|
14
|
-
#pragma mapbox: initialize lowp float opacity
|
|
15
|
-
#pragma mapbox: initialize lowp float offset
|
|
16
|
-
#pragma mapbox: initialize mediump float gapwidth
|
|
17
|
-
#pragma mapbox: initialize mediump float width
|
|
18
|
-
#pragma mapbox: initialize mediump vec4 pattern_from
|
|
19
|
-
#pragma mapbox: initialize mediump vec4 pattern_to
|
|
20
|
-
vec2 a_extrude=a_data.xy-128.;float a_direction=mod(a_data.z,4.)-1.;float a_linesofar=(floor(a_data.z/4.)+a_data.w*64.)*LINE_DISTANCE_SCALE;vec2 pos=a_pos_normal.xy;mediump vec2 normal=a_pos_normal.zw;v_normal=normal;gapwidth=gapwidth/2.;float halfwidth=width/2.;offset=-1.*offset;float inset=gapwidth+(gapwidth>0.?ANTIALIASING:0.);float outset=gapwidth+halfwidth*(gapwidth>0.?2.:1.)+(halfwidth==0.?0.:ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.-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.);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.,1.)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_gl_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_linesofar=a_linesofar;v_width2=vec2(outset,inset);}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
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;
|
|
2
|
-
#pragma mapbox: define highp vec4 color
|
|
3
|
-
#pragma mapbox: define lowp float blur
|
|
4
|
-
#pragma mapbox: define lowp float opacity
|
|
5
|
-
#pragma mapbox: define mediump float width
|
|
6
|
-
#pragma mapbox: define lowp float floorwidth
|
|
7
|
-
void main(){
|
|
8
|
-
#pragma mapbox: initialize highp vec4 color
|
|
9
|
-
#pragma mapbox: initialize lowp float blur
|
|
10
|
-
#pragma mapbox: initialize lowp float opacity
|
|
11
|
-
#pragma mapbox: initialize mediump float width
|
|
12
|
-
#pragma mapbox: initialize lowp float floorwidth
|
|
13
|
-
float dist=length(v_normal)*v_width2.s;float blur2=(blur+1./DEVICE_PIXEL_RATIO)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.,1.);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);
|
|
14
|
-
#ifdef OVERDRAW_INSPECTOR
|
|
15
|
-
gl_FragColor=vec4(1.);
|
|
16
|
-
#endif
|
|
17
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#define scale 0.015873016
|
|
2
|
-
#define LINE_DISTANCE_SCALE 2.0
|
|
3
|
-
#define ANTIALIASING 1.0 / DEVICE_PIXEL_RATIO / 2.0
|
|
4
|
-
attribute vec4 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform mediump float u_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_gl_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;
|
|
5
|
-
#pragma mapbox: define highp vec4 color
|
|
6
|
-
#pragma mapbox: define lowp float blur
|
|
7
|
-
#pragma mapbox: define lowp float opacity
|
|
8
|
-
#pragma mapbox: define mediump float gapwidth
|
|
9
|
-
#pragma mapbox: define lowp float offset
|
|
10
|
-
#pragma mapbox: define mediump float width
|
|
11
|
-
#pragma mapbox: define lowp float floorwidth
|
|
12
|
-
void main(){
|
|
13
|
-
#pragma mapbox: initialize highp vec4 color
|
|
14
|
-
#pragma mapbox: initialize lowp float blur
|
|
15
|
-
#pragma mapbox: initialize lowp float opacity
|
|
16
|
-
#pragma mapbox: initialize mediump float gapwidth
|
|
17
|
-
#pragma mapbox: initialize lowp float offset
|
|
18
|
-
#pragma mapbox: initialize mediump float width
|
|
19
|
-
#pragma mapbox: initialize lowp float floorwidth
|
|
20
|
-
vec2 a_extrude=a_data.xy-128.;float a_direction=mod(a_data.z,4.)-1.;float a_linesofar=(floor(a_data.z/4.)+a_data.w*64.)*LINE_DISTANCE_SCALE;vec2 pos=a_pos_normal.xy;mediump vec2 normal=a_pos_normal.zw;v_normal=normal;gapwidth=gapwidth/2.;float halfwidth=width/2.;offset=-1.*offset;float inset=gapwidth+(gapwidth>0.?ANTIALIASING:0.);float outset=gapwidth+halfwidth*(gapwidth>0.?2.:1.)+(halfwidth==0.?0.:ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.-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.);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.,1.)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_gl_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);}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
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.){color0.rgb=color0.rgb/color0.a;}if(color1.a>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.;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);
|
|
2
|
-
#ifdef OVERDRAW_INSPECTOR
|
|
3
|
-
gl_FragColor=vec4(1.);
|
|
4
|
-
#endif
|
|
5
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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.5)/u_buffer_scale)+0.5;v_pos1=(v_pos0*u_scale_parent)+u_tl_parent;}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
uniform sampler2D u_texture;
|
|
2
|
-
#pragma mapbox: define lowp float opacity
|
|
3
|
-
varying vec2 v_tex;varying float v_fade_opacity;void main(){
|
|
4
|
-
#pragma mapbox: initialize lowp float opacity
|
|
5
|
-
lowp float alpha=opacity*v_fade_opacity;gl_FragColor=texture2D(u_texture,v_tex)*alpha;
|
|
6
|
-
#ifdef OVERDRAW_INSPECTOR
|
|
7
|
-
gl_FragColor=vec4(1.);
|
|
8
|
-
#endif
|
|
9
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
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 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;
|
|
2
|
-
#pragma mapbox: define lowp float opacity
|
|
3
|
-
uniform mat4 u_matrix;uniform mat4 u_label_plane_matrix;uniform mat4 u_gl_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;void main(){
|
|
4
|
-
#pragma mapbox: initialize lowp float opacity
|
|
5
|
-
vec2 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;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[0],a_size[1],u_size_t)/10.;}else if(u_is_size_zoom_constant&&!u_is_size_feature_constant){size=a_size[0]/10.;}else if(!u_is_size_zoom_constant&&u_is_size_feature_constant){size=u_size;}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?camera_to_anchor_distance/u_camera_to_center_distance:u_camera_to_center_distance/camera_to_anchor_distance;highp float perspective_ratio=clamp(0.5+0.5*distance_ratio,0.,4.);size*=perspective_ratio;float fontScale=u_is_text?size/24.:size;highp float symbol_rotation=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.*angle_sin,angle_sin,angle_cos);vec4 projected_pos=u_label_plane_matrix*vec4(a_projected_pos.xy,0.,1.);gl_Position=u_gl_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matrix*(a_offset/32.*fontScale),0.,1.);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.,min(1.,fade_opacity[0]+fade_change));}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#define SDF_PX 8.0
|
|
2
|
-
#define EDGE_GAMMA 0.105/DEVICE_PIXEL_RATIO
|
|
3
|
-
uniform bool u_is_halo;
|
|
4
|
-
#pragma mapbox: define highp vec4 fill_color
|
|
5
|
-
#pragma mapbox: define highp vec4 halo_color
|
|
6
|
-
#pragma mapbox: define lowp float opacity
|
|
7
|
-
#pragma mapbox: define lowp float halo_width
|
|
8
|
-
#pragma mapbox: define lowp float halo_blur
|
|
9
|
-
uniform sampler2D u_texture;uniform highp float u_gamma_scale;uniform bool u_is_text;varying vec2 v_data0;varying vec3 v_data1;void main(){
|
|
10
|
-
#pragma mapbox: initialize highp vec4 fill_color
|
|
11
|
-
#pragma mapbox: initialize highp vec4 halo_color
|
|
12
|
-
#pragma mapbox: initialize lowp float opacity
|
|
13
|
-
#pragma mapbox: initialize lowp float halo_width
|
|
14
|
-
#pragma mapbox: initialize lowp float halo_blur
|
|
15
|
-
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.:size;lowp vec4 color=fill_color;highp float gamma=EDGE_GAMMA/(fontScale*u_gamma_scale);lowp float buff=(256.-64.)/256.;if(u_is_halo){color=halo_color;gamma=(halo_blur*1.19/SDF_PX+EDGE_GAMMA)/(fontScale*u_gamma_scale);buff=(6.-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);
|
|
16
|
-
#ifdef OVERDRAW_INSPECTOR
|
|
17
|
-
gl_FragColor=vec4(1.);
|
|
18
|
-
#endif
|
|
19
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
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;
|
|
2
|
-
#pragma mapbox: define highp vec4 fill_color
|
|
3
|
-
#pragma mapbox: define highp vec4 halo_color
|
|
4
|
-
#pragma mapbox: define lowp float opacity
|
|
5
|
-
#pragma mapbox: define lowp float halo_width
|
|
6
|
-
#pragma mapbox: define lowp float halo_blur
|
|
7
|
-
uniform mat4 u_matrix;uniform mat4 u_label_plane_matrix;uniform mat4 u_gl_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;void main(){
|
|
8
|
-
#pragma mapbox: initialize highp vec4 fill_color
|
|
9
|
-
#pragma mapbox: initialize highp vec4 halo_color
|
|
10
|
-
#pragma mapbox: initialize lowp float opacity
|
|
11
|
-
#pragma mapbox: initialize lowp float halo_width
|
|
12
|
-
#pragma mapbox: initialize lowp float halo_blur
|
|
13
|
-
vec2 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;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[0],a_size[1],u_size_t)/10.;}else if(u_is_size_zoom_constant&&!u_is_size_feature_constant){size=a_size[0]/10.;}else if(!u_is_size_zoom_constant&&u_is_size_feature_constant){size=u_size;}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?camera_to_anchor_distance/u_camera_to_center_distance:u_camera_to_center_distance/camera_to_anchor_distance;highp float perspective_ratio=clamp(0.5+0.5*distance_ratio,0.,4.);size*=perspective_ratio;float fontScale=u_is_text?size/24.:size;highp float symbol_rotation=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.*angle_sin,angle_sin,angle_cos);vec4 projected_pos=u_label_plane_matrix*vec4(a_projected_pos.xy,0.,1.);gl_Position=u_gl_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matrix*(a_offset/32.*fontScale),0.,1.);float gamma_scale=gl_Position.w;vec2 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;float interpolated_fade_opacity=max(0.,min(1.,fade_opacity[0]+fade_change));v_data0=vec2(tex.x,tex.y);v_data1=vec3(gamma_scale,size,interpolated_fade_opacity);}
|
package/src/util/evented.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
class Event {
|
|
2
|
-
constructor(type, data) {
|
|
3
|
-
Object.assign(this, data);
|
|
4
|
-
this.type = type;
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
class ErrorEvent extends Event {
|
|
9
|
-
constructor(error, data) {
|
|
10
|
-
super('error', Object.assign({ error }, data));
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Methods mixed in to other classes for event capabilities.
|
|
16
|
-
*
|
|
17
|
-
* @mixin Evented
|
|
18
|
-
*/
|
|
19
|
-
class Evented {
|
|
20
|
-
#listeners;
|
|
21
|
-
#oneTimeListeners;
|
|
22
|
-
#parent;
|
|
23
|
-
#parentData;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Adds a listener to a specified event type.
|
|
27
|
-
*
|
|
28
|
-
* @param {string} type The event type to add a listen for.
|
|
29
|
-
* @param {Function} listener The function to be called when the event is fired.
|
|
30
|
-
* The listener function is called with the data object passed to `fire`,
|
|
31
|
-
* extended with `target` and `type` properties.
|
|
32
|
-
* @returns {Object} `this`
|
|
33
|
-
*/
|
|
34
|
-
on(type, listener) {
|
|
35
|
-
this.#listeners ??= listeners();
|
|
36
|
-
this.#listeners.add(type, listener);
|
|
37
|
-
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Removes a previously registered event listener.
|
|
43
|
-
*
|
|
44
|
-
* @param {string} type The event type to remove listeners for.
|
|
45
|
-
* @param {Function} listener The listener function to remove.
|
|
46
|
-
* @returns {Object} `this`
|
|
47
|
-
*/
|
|
48
|
-
off(type, listener) {
|
|
49
|
-
this.#listeners?.remove(type, listener);
|
|
50
|
-
this.#oneTimeListeners?.remove(type, listener);
|
|
51
|
-
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Adds a listener that will be called only once to a specified event type.
|
|
57
|
-
*
|
|
58
|
-
* The listener will be called first time the event fires after the listener is registered.
|
|
59
|
-
*
|
|
60
|
-
* @param {string} type The event type to listen for.
|
|
61
|
-
* @param {Function} listener The function to be called when the event is fired the first time.
|
|
62
|
-
* @returns {Object} `this`
|
|
63
|
-
*/
|
|
64
|
-
once(type, listener) {
|
|
65
|
-
this.#oneTimeListeners ??= listeners({ once: true });
|
|
66
|
-
this.#oneTimeListeners.add(type, listener);
|
|
67
|
-
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
fire(event) {
|
|
72
|
-
// Compatibility with (type: string, properties: Object) signature from previous versions.
|
|
73
|
-
// See https://github.com/mapbox/mapbox-gl-js/issues/6522,
|
|
74
|
-
// https://github.com/mapbox/mapbox-gl-draw/issues/766
|
|
75
|
-
if (typeof event === 'string') {
|
|
76
|
-
event = new Event(event, arguments[1]);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const { type } = event;
|
|
80
|
-
|
|
81
|
-
if (this.listens(type)) {
|
|
82
|
-
event.target = this;
|
|
83
|
-
this.#listeners?.fire(type, this, event);
|
|
84
|
-
this.#oneTimeListeners?.fire(type, this, event);
|
|
85
|
-
|
|
86
|
-
const parent = this.#parent;
|
|
87
|
-
if (parent) {
|
|
88
|
-
const data = typeof this.#parentData === 'function' ? this.#parentData() : this.#parentData;
|
|
89
|
-
Object.assign(event, data);
|
|
90
|
-
parent.fire(event);
|
|
91
|
-
}
|
|
92
|
-
} else if (event instanceof ErrorEvent) {
|
|
93
|
-
// To ensure that no error events are dropped, print them to the
|
|
94
|
-
// console if they have no listeners.
|
|
95
|
-
console.error(event.error);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.
|
|
103
|
-
*
|
|
104
|
-
* @param {string} type The event type
|
|
105
|
-
* @returns {boolean} `true` if there is at least one registered listener for specified event type, `false` otherwise
|
|
106
|
-
*/
|
|
107
|
-
listens(type) {
|
|
108
|
-
return this.#listeners?.listens(type) || this.#oneTimeListeners?.listens(type) || this.#parent?.listens(type);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Bubble all events fired by this instance of Evented to this parent instance of Evented.
|
|
113
|
-
*
|
|
114
|
-
* @returns {Object} `this`
|
|
115
|
-
*/
|
|
116
|
-
setEventedParent(parent, data) {
|
|
117
|
-
this.#parent = parent;
|
|
118
|
-
this.#parentData = data;
|
|
119
|
-
|
|
120
|
-
return this;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
module.exports = {
|
|
125
|
-
Event,
|
|
126
|
-
ErrorEvent,
|
|
127
|
-
Evented
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
function listeners({ once } = {}) {
|
|
131
|
-
const bag = new Map();
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
add,
|
|
135
|
-
remove,
|
|
136
|
-
fire,
|
|
137
|
-
listens
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
function add(type, listener) {
|
|
141
|
-
const list = bag.get(type);
|
|
142
|
-
if (!list) {
|
|
143
|
-
bag.set(type, [listener]);
|
|
144
|
-
} else if (!list.includes(listener)) {
|
|
145
|
-
list.push(listener);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function remove(type, listener) {
|
|
150
|
-
const list = bag.get(type);
|
|
151
|
-
if (!list) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
const index = list.indexOf(listener);
|
|
155
|
-
if (index !== -1) {
|
|
156
|
-
list.splice(index, 1);
|
|
157
|
-
}
|
|
158
|
-
if (list.length === 0) {
|
|
159
|
-
bag.delete(type);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function fire(type, thisArg, data) {
|
|
164
|
-
let list = bag.get(type);
|
|
165
|
-
if (!list || list.length === 0) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if (once) {
|
|
169
|
-
bag.delete(type);
|
|
170
|
-
} else {
|
|
171
|
-
// make sure adding or removing listeners inside other listeners won't cause an infinite loop
|
|
172
|
-
list = list.slice();
|
|
173
|
-
}
|
|
174
|
-
for (const listener of list) {
|
|
175
|
-
listener.call(thisArg, data);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function listens(type) {
|
|
180
|
-
return bag.get(type)?.length > 0;
|
|
181
|
-
}
|
|
182
|
-
}
|