MapRasterSeries

Type module

Data item

MapRasterSeries uses data items of type IMapRasterSeriesDataItem.

Sources

Items from MapRasterSeries can be imported/included and used via following ways.

/**
 * --------------------------------------------------------
 * Import via: MapRasterSeries.ts
 * Access items like: $maprasterseries.myVariable
 *                    $maprasterseries.myFunction()
 * --------------------------------------------------------
 */
import * as $maprasterseries from "@amcharts/amcharts5/MapRasterSeries";

Variables

rasterProgram
#

Type IRasterProgram | undefined

failedGeneration
#

Type number

Default -1

VERTEX
#

Type "#version 300 es
void main() {
vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2)); gl_Position = vec4(p * 2.0 - 1.0, 0.0, 1.0); }"

Default #version 300 es
void main() {
&nbsp;&nbsp;
vec2 p = vec2(float((gl_VertexID &lt;&lt; 1) & 2),
&nbsp;&nbsp;float(gl_VertexID & 2));
gl_Position = vec4(p * 2.0 - 1.0,
&nbsp;&nbsp;0.0,
&nbsp;&nbsp;1.0);

}

RADIANS
#

Type number

Default Math.PI / 180

ORTHOGRAPHIC
#

Type ...

Default 0

NATURAL_EARTH_TOP
#

Type 1.4223905067305962

Default 1.4223905067305962

NATURAL_EARTH
#

Type 4

Default 4

MOVING
#

Type 250

Default 250

MERCATOR
#

Type 2

Default 2

M
#

Type number

Default Math.sqrt(3) / 2

INV_TWO_PI
#

Type number

Default 1 / (2 * Math.PI)

INV_PI
#

Type number

Default 1 / Math.PI

HALF_PI
#

Type number

Default Math.PI / 2

FRAGMENT
#

Type string

Default #version 300 es
precision highp float;
uniform sampler2D u_image;
uniform sampler2D u_night;
uniform float u_height;
uniform float u_resolution;
uniform vec2 u_translate;
uniform float u_scale;
uniform mat3 u_rotation;
uniform int u_kind;
uniform int u_dayNight;
uniform vec3 u_sun;
uniform float u_twilight;
out vec4 color;

const float PI = 3.141592653589793;
const float EQUAL_EARTH_TOP = ${
&nbsp;&nbsp;EQUAL_EARTH_TOP
};
const float NATURAL_EARTH_TOP = ${
&nbsp;&nbsp;NATURAL_EARTH_TOP
};

// Equal Earth: the latitude of the row at raw y,
and the longitude a unit of raw x covers there
vec2 equalEarthRow(float y) {
&nbsp;&nbsp;
const float A1 = 1.340264,
&nbsp;&nbsp;A2 = -0.081106,
&nbsp;&nbsp;A3 = 0.000893,
&nbsp;&nbsp;A4 = 0.003796,
&nbsp;&nbsp;M = 0.8660254037844386;
float l = y;
for (int i = 0; i &lt; 8; i++) {
&nbsp;&nbsp;&nbsp;&nbsp;
float l2 = l * l;
float l6 = l2 * l2 * l2;
l -= (l * (A1 + A2 * l2 + l6 * (A3 + A4 * l2)) - y) / (A1 + 3.0 * A2 * l2 + l6 * (7.0 * A3 + 9.0 * A4 * l2));

&nbsp;&nbsp;}
float l2 = l * l;
float l6 = l2 * l2 * l2;
return vec2(asin(clamp(sin(l) / M,
&nbsp;&nbsp;-1.0,
&nbsp;&nbsp;1.0)),
&nbsp;&nbsp;M * (A1 + 3.0 * A2 * l2 + l6 * (7.0 * A3 + 9.0 * A4 * l2)) / cos(l));

}

// Natural Earth,
likewise
vec2 naturalEarthRow(float y) {
&nbsp;&nbsp;
float phi = y;
for (int i = 0; i &lt; 12; i++) {
&nbsp;&nbsp;&nbsp;&nbsp;
float p2 = phi * phi;
float p4 = p2 * p2;
phi -= (phi * (1.007226 + p2 * (0.015085 + p4 * (-0.044475 + 0.028874 * p2 - 0.005916 * p4))) - y) / (1.007226 + p2 * (0.045255 + p4 * (-0.311325 + 0.259866 * p2 - 0.065076 * p4)));

&nbsp;&nbsp;}
float p2 = phi * phi;
return vec2(phi,
&nbsp;&nbsp;1.0 / (0.8707 + p2 * (-0.131979 + p2 * (-0.013791 + p2 * p2 * p2 * (0.003971 - 0.001529 * p2)))));

}

void main() {
&nbsp;&nbsp;
vec2 css = vec2(gl_FragCoord.x,
&nbsp;&nbsp;u_height - gl_FragCoord.y) / u_resolution;
vec2 p = vec2(css.x - u_translate.x,
&nbsp;&nbsp;u_translate.y - css.y) / u_scale;
vec3 v;
float alpha;
if (u_kind == 0) {
&nbsp;&nbsp;&nbsp;&nbsp;
float r = length(p);
float edge = 0.5 / (u_scale * u_resolution);
alpha = clamp((1.0 + edge - r) / (2.0 * edge),
&nbsp;&nbsp;&nbsp;&nbsp;0.0,
&nbsp;&nbsp;&nbsp;&nbsp;1.0);
v = vec3(sqrt(max(0.0,
&nbsp;&nbsp;&nbsp;&nbsp;1.0 - r * r)),
&nbsp;&nbsp;&nbsp;&nbsp;p.x,
&nbsp;&nbsp;&nbsp;&nbsp;p.y);

&nbsp;&nbsp;}
else if (u_kind &gt;= 3) {
&nbsp;&nbsp;&nbsp;&nbsp;
// Rows off the map are clamped onto it,
&nbsp;&nbsp;&nbsp;&nbsp;so the iteration stays finite
float limit = u_kind == 3 ? EQUAL_EARTH_TOP : NATURAL_EARTH_TOP;
float y = clamp(p.y,
&nbsp;&nbsp;&nbsp;&nbsp;-limit,
&nbsp;&nbsp;&nbsp;&nbsp;limit);
vec2 row = u_kind == 3 ? equalEarthRow(y) : naturalEarthRow(y);
float phi = clamp(row.x,
&nbsp;&nbsp;&nbsp;&nbsp;-PI / 2.0,
&nbsp;&nbsp;&nbsp;&nbsp;PI / 2.0);
float lambda = p.x * row.y;
// The curved sides are anti-aliased half a pixel either side
float edge = max(fwidth(lambda),
&nbsp;&nbsp;&nbsp;&nbsp;1e-6);
alpha = abs(p.y) &lt;= limit ? clamp((PI - abs(lambda)) / edge + 0.5,
&nbsp;&nbsp;&nbsp;&nbsp;0.0,
&nbsp;&nbsp;&nbsp;&nbsp;1.0) : 0.0;
lambda = clamp(lambda,
&nbsp;&nbsp;&nbsp;&nbsp;-PI,
&nbsp;&nbsp;&nbsp;&nbsp;PI);
v = vec3(cos(phi) * cos(lambda),
&nbsp;&nbsp;&nbsp;&nbsp;cos(phi) * sin(lambda),
&nbsp;&nbsp;&nbsp;&nbsp;sin(phi));

&nbsp;&nbsp;}
else {
&nbsp;&nbsp;&nbsp;&nbsp;
float phi = u_kind == 2 ? 2.0 * atan(exp(p.y)) - PI / 2.0 : p.y;
alpha = abs(p.x) &lt;= PI && abs(phi) &lt;= PI / 2.0 ? 1.0 : 0.0;
v = vec3(cos(phi) * cos(p.x),
&nbsp;&nbsp;&nbsp;&nbsp;cos(phi) * sin(p.x),
&nbsp;&nbsp;&nbsp;&nbsp;sin(phi));

&nbsp;&nbsp;}
v = u_rotation * v;
vec2 uv = vec2(atan(v.y,
&nbsp;&nbsp;v.x) / (2.0 * PI) + 0.5,
&nbsp;&nbsp;0.5 - asin(clamp(v.z,
&nbsp;&nbsp;-1.0,
&nbsp;&nbsp;1.0)) / PI);

// Gradients without the jump where longitude wraps round
vec2 wrapped = vec2(fract(uv.x + 0.5),
&nbsp;&nbsp;uv.y);
vec2 dx = dFdx(uv);
vec2 dy = dFdy(uv);
vec2 dxWrapped = dFdx(wrapped);
vec2 dyWrapped = dFdy(wrapped);
if (abs(dxWrapped.x) + abs(dyWrapped.x) &lt; abs(dx.x) + abs(dy.x)) {
&nbsp;&nbsp;&nbsp;&nbsp;
dx = dxWrapped;
dy = dyWrapped;

&nbsp;&nbsp;}
vec4 day = textureGrad(u_image,
&nbsp;&nbsp;uv,
&nbsp;&nbsp;dx,
&nbsp;&nbsp;dy);

// The sine of the sun's height there: day above the twilight band,
&nbsp;&nbsp;night below
if (u_dayNight == 1) {
&nbsp;&nbsp;&nbsp;&nbsp;
float t = smoothstep(-u_twilight,
&nbsp;&nbsp;&nbsp;&nbsp;u_twilight,
&nbsp;&nbsp;&nbsp;&nbsp;dot(normalize(v),
&nbsp;&nbsp;&nbsp;&nbsp;u_sun));
day = mix(textureGrad(u_night,
&nbsp;&nbsp;&nbsp;&nbsp;uv,
&nbsp;&nbsp;&nbsp;&nbsp;dx,
&nbsp;&nbsp;&nbsp;&nbsp;dy),
&nbsp;&nbsp;&nbsp;&nbsp;day,
&nbsp;&nbsp;&nbsp;&nbsp;t);

&nbsp;&nbsp;}
color = day * alpha;

}

EQUIRECTANGULAR
#

Type 1

Default 1

EQUAL_EARTH_TOP
#

Type 1.3173627591574133

Default 1.3173627591574133

EQUAL_EARTH
#

Type 3

Default 3

DEGREES
#

Type number

Default 180 / Math.PI

A4
#

Type 0.003796

Default 0.003796

A3
#

Type 0.000893

Default 0.000893

A2
#

Type -0.081106

Default -0.081106

A1
#

Type 1.340264

Default 1.340264

Functions

detectKind(

projection: GeoProjection,
matrix: Array

)

#

Returns void

Which raw inverse reproduces the projection, if any: a few raw points go through it and back through the projection itself.

getProgram(

shared: ISharedGL

)

#

Returns void

inverseRotation(

projection: GeoProjection

)

#

Returns Array

Takes a vector from the projection's rotated frame back to geographic coordinates: columns are the rotated frame's axes, column-major.

mixPixels(

a: number,
b: number,
t: number

)

#

Returns number

rawRow(

kind: number,
y: number

)

#

Returns void

For a projection whose parallels are straight lines: the latitude of the row at raw y, and how much longitude a unit of raw x covers there.

undefined off the map.

rawToVector(

kind: number,
x: number,
y: number

)

#

Returns void

Unit vector for a point in raw projected coordinates, or undefined off the projection.

sampleBilinear(

level: IRasterLevel,
u: number,
v: number

)

#

Returns number

sampleNearest(

level: IRasterLevel,
u: number,
v: number

)

#

Returns number

smoothstep(

edge0: number,
edge1: number,
x: number

)

#

Returns number

toVector(

lambda: number,
phi: number

)

#

Returns void