@mapbox/mapbox-gl-style-spec 14.25.0-rc.1 → 14.26.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +280 -634
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.es.js +280 -634
- package/dist/index.es.js.map +1 -1
- package/expression/compound_expression.ts +2 -2
- package/expression/definitions/comparison.ts +2 -2
- package/expression/definitions/distance.ts +147 -63
- package/expression/definitions/match.ts +7 -8
- package/expression/is_constant.ts +8 -4
- package/expression/parsing_context.ts +68 -28
- package/function/index.ts +1 -1
- package/package.json +1 -2
- package/reference/v8.json +23 -28
- package/types.ts +8 -7
- package/util/geometry_util.ts +35 -34
- package/util/interpolate.ts +1 -1
- package/validate/validate.ts +3 -2
- package/validate/validate_appearance.ts +5 -4
- package/validate/validate_filter.ts +3 -2
- package/validate/validate_import.ts +3 -2
- package/validate/validate_layer.ts +4 -4
- package/validate/validate_option.ts +4 -5
- package/validate/validate_style.ts +4 -5
package/dist/index.es.js
CHANGED
|
@@ -1294,6 +1294,24 @@ var modelNodeOverride = {
|
|
|
1294
1294
|
doc: "Override the orientation of the model node in euler angles [x, y, z]."
|
|
1295
1295
|
}
|
|
1296
1296
|
};
|
|
1297
|
+
var modelLightOverrides = {
|
|
1298
|
+
"light-ambient-color": {
|
|
1299
|
+
type: "color",
|
|
1300
|
+
doc: "Override the color of ambient lights."
|
|
1301
|
+
},
|
|
1302
|
+
"light-ambient-intensity": {
|
|
1303
|
+
type: "number",
|
|
1304
|
+
doc: "Override the intensity of light-ambient-color (on a scale from 0 to 1)."
|
|
1305
|
+
},
|
|
1306
|
+
"light-directional-color": {
|
|
1307
|
+
type: "color",
|
|
1308
|
+
doc: "Override the color of directional lights."
|
|
1309
|
+
},
|
|
1310
|
+
"light-directional-intensity": {
|
|
1311
|
+
type: "number",
|
|
1312
|
+
doc: "Override the intensity of light-directional-color (on a scale from 0 to 1)."
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1297
1315
|
var modelNodeOverrides = {
|
|
1298
1316
|
"*": {
|
|
1299
1317
|
type: "modelNodeOverride",
|
|
@@ -1364,6 +1382,11 @@ var modelSourceModel = {
|
|
|
1364
1382
|
units: "degrees",
|
|
1365
1383
|
doc: "Orientation of the model in euler angles [x, y, z]."
|
|
1366
1384
|
},
|
|
1385
|
+
lightOverrides: {
|
|
1386
|
+
type: "modelLightOverrides",
|
|
1387
|
+
required: false,
|
|
1388
|
+
doc: "A collection of light overrides."
|
|
1389
|
+
},
|
|
1367
1390
|
nodeOverrides: {
|
|
1368
1391
|
type: "modelNodeOverrides",
|
|
1369
1392
|
required: false,
|
|
@@ -6521,13 +6544,6 @@ var camera = {
|
|
|
6521
6544
|
doc: "Projection where objects are of the same scale regardless of whether they are far away or near to the camera. Parallel lines remains parallel and there is no vanishing point."
|
|
6522
6545
|
}
|
|
6523
6546
|
},
|
|
6524
|
-
transition: true,
|
|
6525
|
-
expression: {
|
|
6526
|
-
interpolated: true,
|
|
6527
|
-
parameters: [
|
|
6528
|
-
"zoom"
|
|
6529
|
-
]
|
|
6530
|
-
},
|
|
6531
6547
|
"sdk-support": {
|
|
6532
6548
|
"basic functionality": {
|
|
6533
6549
|
js: "3.0.0",
|
|
@@ -10516,29 +10532,6 @@ var paint_model = {
|
|
|
10516
10532
|
},
|
|
10517
10533
|
transition: true
|
|
10518
10534
|
},
|
|
10519
|
-
"model-lightmap-intensity": {
|
|
10520
|
-
type: "number",
|
|
10521
|
-
"default": 0,
|
|
10522
|
-
minimum: 0,
|
|
10523
|
-
doc: "Controls the intensity of the model lightmap contribution. Values less than or equal to 0.001 are treated as off.",
|
|
10524
|
-
"private": true,
|
|
10525
|
-
experimental: true,
|
|
10526
|
-
expression: {
|
|
10527
|
-
interpolated: true,
|
|
10528
|
-
parameters: [
|
|
10529
|
-
"zoom"
|
|
10530
|
-
]
|
|
10531
|
-
},
|
|
10532
|
-
"sdk-support": {
|
|
10533
|
-
"basic functionality": {
|
|
10534
|
-
js: "3.25.0",
|
|
10535
|
-
android: "11.25.0",
|
|
10536
|
-
ios: "11.25.0"
|
|
10537
|
-
}
|
|
10538
|
-
},
|
|
10539
|
-
"property-type": "data-constant",
|
|
10540
|
-
transition: true
|
|
10541
|
-
},
|
|
10542
10535
|
"model-type": {
|
|
10543
10536
|
type: "enum",
|
|
10544
10537
|
values: {
|
|
@@ -10959,6 +10952,7 @@ var v8 = {
|
|
|
10959
10952
|
source_video: source_video,
|
|
10960
10953
|
source_image: source_image,
|
|
10961
10954
|
modelNodeOverride: modelNodeOverride,
|
|
10955
|
+
modelLightOverrides: modelLightOverrides,
|
|
10962
10956
|
modelNodeOverrides: modelNodeOverrides,
|
|
10963
10957
|
modelMaterialOverride: modelMaterialOverride,
|
|
10964
10958
|
modelMaterialOverrides: modelMaterialOverrides,
|
|
@@ -14003,7 +13997,7 @@ class CompoundExpression {
|
|
|
14003
13997
|
overloadParams.push(params);
|
|
14004
13998
|
overloadIndex++;
|
|
14005
13999
|
if (signatureContext === null) {
|
|
14006
|
-
signatureContext =
|
|
14000
|
+
signatureContext = context._forkForSignature();
|
|
14007
14001
|
} else {
|
|
14008
14002
|
signatureContext.errors.length = 0;
|
|
14009
14003
|
}
|
|
@@ -14766,485 +14760,6 @@ class Within {
|
|
|
14766
14760
|
}
|
|
14767
14761
|
}
|
|
14768
14762
|
|
|
14769
|
-
const factors = {
|
|
14770
|
-
kilometers: 1,
|
|
14771
|
-
miles: 1000 / 1609.344,
|
|
14772
|
-
nauticalmiles: 1000 / 1852,
|
|
14773
|
-
meters: 1000,
|
|
14774
|
-
metres: 1000,
|
|
14775
|
-
yards: 1000 / 0.9144,
|
|
14776
|
-
feet: 1000 / 0.3048,
|
|
14777
|
-
inches: 1000 / 0.0254
|
|
14778
|
-
};
|
|
14779
|
-
|
|
14780
|
-
// Values that define WGS84 ellipsoid model of the Earth
|
|
14781
|
-
const RE = 6378.137; // equatorial radius
|
|
14782
|
-
const FE = 1 / 298.257223563; // flattening
|
|
14783
|
-
|
|
14784
|
-
const E2 = FE * (2 - FE);
|
|
14785
|
-
const RAD = Math.PI / 180;
|
|
14786
|
-
|
|
14787
|
-
/**
|
|
14788
|
-
* A collection of very fast approximations to common geodesic measurements. Useful for performance-sensitive code that measures things on a city scale.
|
|
14789
|
-
*/
|
|
14790
|
-
class CheapRuler {
|
|
14791
|
-
/**
|
|
14792
|
-
* Creates a ruler object from tile coordinates (y and z).
|
|
14793
|
-
*
|
|
14794
|
-
* @param {number} y
|
|
14795
|
-
* @param {number} z
|
|
14796
|
-
* @param {keyof typeof factors} [units='kilometers']
|
|
14797
|
-
* @returns {CheapRuler}
|
|
14798
|
-
* @example
|
|
14799
|
-
* const ruler = cheapRuler.fromTile(1567, 12);
|
|
14800
|
-
* //=ruler
|
|
14801
|
-
*/
|
|
14802
|
-
static fromTile(y, z, units) {
|
|
14803
|
-
const n = Math.PI * (1 - 2 * (y + 0.5) / Math.pow(2, z));
|
|
14804
|
-
const lat = Math.atan(0.5 * (Math.exp(n) - Math.exp(-n))) / RAD;
|
|
14805
|
-
return new CheapRuler(lat, units);
|
|
14806
|
-
}
|
|
14807
|
-
|
|
14808
|
-
/**
|
|
14809
|
-
* Multipliers for converting between units.
|
|
14810
|
-
*
|
|
14811
|
-
* @example
|
|
14812
|
-
* // convert 50 meters to yards
|
|
14813
|
-
* 50 * CheapRuler.units.yards / CheapRuler.units.meters;
|
|
14814
|
-
*/
|
|
14815
|
-
static get units() {
|
|
14816
|
-
return factors;
|
|
14817
|
-
}
|
|
14818
|
-
|
|
14819
|
-
/**
|
|
14820
|
-
* Creates a ruler instance for very fast approximations to common geodesic measurements around a certain latitude.
|
|
14821
|
-
*
|
|
14822
|
-
* @param {number} lat latitude
|
|
14823
|
-
* @param {keyof typeof factors} [units='kilometers']
|
|
14824
|
-
* @example
|
|
14825
|
-
* const ruler = cheapRuler(35.05, 'miles');
|
|
14826
|
-
* //=ruler
|
|
14827
|
-
*/
|
|
14828
|
-
constructor(lat, units) {
|
|
14829
|
-
if (lat === undefined) throw new Error('No latitude given.');
|
|
14830
|
-
if (units && !factors[units]) throw new Error(`Unknown unit ${ units }. Use one of: ${ Object.keys(factors).join(', ')}`);
|
|
14831
|
-
|
|
14832
|
-
// Curvature formulas from https://en.wikipedia.org/wiki/Earth_radius#Meridional
|
|
14833
|
-
const m = RAD * RE * (units ? factors[units] : 1);
|
|
14834
|
-
const coslat = Math.cos(lat * RAD);
|
|
14835
|
-
const w2 = 1 / (1 - E2 * (1 - coslat * coslat));
|
|
14836
|
-
const w = Math.sqrt(w2);
|
|
14837
|
-
|
|
14838
|
-
// multipliers for converting longitude and latitude degrees into distance
|
|
14839
|
-
this.kx = m * w * coslat; // based on normal radius of curvature
|
|
14840
|
-
this.ky = m * w * w2 * (1 - E2); // based on meridonal radius of curvature
|
|
14841
|
-
}
|
|
14842
|
-
|
|
14843
|
-
/**
|
|
14844
|
-
* Given two points of the form [longitude, latitude], returns the distance.
|
|
14845
|
-
*
|
|
14846
|
-
* @param {[number, number]} a point [longitude, latitude]
|
|
14847
|
-
* @param {[number, number]} b point [longitude, latitude]
|
|
14848
|
-
* @returns {number} distance
|
|
14849
|
-
* @example
|
|
14850
|
-
* const distance = ruler.distance([30.5, 50.5], [30.51, 50.49]);
|
|
14851
|
-
* //=distance
|
|
14852
|
-
*/
|
|
14853
|
-
distance(a, b) {
|
|
14854
|
-
const dx = wrap(a[0] - b[0]) * this.kx;
|
|
14855
|
-
const dy = (a[1] - b[1]) * this.ky;
|
|
14856
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
14857
|
-
}
|
|
14858
|
-
|
|
14859
|
-
/**
|
|
14860
|
-
* Returns the bearing between two points in angles.
|
|
14861
|
-
*
|
|
14862
|
-
* @param {[number, number]} a point [longitude, latitude]
|
|
14863
|
-
* @param {[number, number]} b point [longitude, latitude]
|
|
14864
|
-
* @returns {number} bearing
|
|
14865
|
-
* @example
|
|
14866
|
-
* const bearing = ruler.bearing([30.5, 50.5], [30.51, 50.49]);
|
|
14867
|
-
* //=bearing
|
|
14868
|
-
*/
|
|
14869
|
-
bearing(a, b) {
|
|
14870
|
-
const dx = wrap(b[0] - a[0]) * this.kx;
|
|
14871
|
-
const dy = (b[1] - a[1]) * this.ky;
|
|
14872
|
-
return Math.atan2(dx, dy) / RAD;
|
|
14873
|
-
}
|
|
14874
|
-
|
|
14875
|
-
/**
|
|
14876
|
-
* Returns a new point given distance and bearing from the starting point.
|
|
14877
|
-
*
|
|
14878
|
-
* @param {[number, number]} p point [longitude, latitude]
|
|
14879
|
-
* @param {number} dist distance
|
|
14880
|
-
* @param {number} bearing
|
|
14881
|
-
* @returns {[number, number]} point [longitude, latitude]
|
|
14882
|
-
* @example
|
|
14883
|
-
* const point = ruler.destination([30.5, 50.5], 0.1, 90);
|
|
14884
|
-
* //=point
|
|
14885
|
-
*/
|
|
14886
|
-
destination(p, dist, bearing) {
|
|
14887
|
-
const a = bearing * RAD;
|
|
14888
|
-
return this.offset(p,
|
|
14889
|
-
Math.sin(a) * dist,
|
|
14890
|
-
Math.cos(a) * dist);
|
|
14891
|
-
}
|
|
14892
|
-
|
|
14893
|
-
/**
|
|
14894
|
-
* Returns a new point given easting and northing offsets (in ruler units) from the starting point.
|
|
14895
|
-
*
|
|
14896
|
-
* @param {[number, number]} p point [longitude, latitude]
|
|
14897
|
-
* @param {number} dx easting
|
|
14898
|
-
* @param {number} dy northing
|
|
14899
|
-
* @returns {[number, number]} point [longitude, latitude]
|
|
14900
|
-
* @example
|
|
14901
|
-
* const point = ruler.offset([30.5, 50.5], 10, 10);
|
|
14902
|
-
* //=point
|
|
14903
|
-
*/
|
|
14904
|
-
offset(p, dx, dy) {
|
|
14905
|
-
return [
|
|
14906
|
-
p[0] + dx / this.kx,
|
|
14907
|
-
p[1] + dy / this.ky
|
|
14908
|
-
];
|
|
14909
|
-
}
|
|
14910
|
-
|
|
14911
|
-
/**
|
|
14912
|
-
* Given a line (an array of points), returns the total line distance.
|
|
14913
|
-
*
|
|
14914
|
-
* @param {[number, number][]} points [longitude, latitude]
|
|
14915
|
-
* @returns {number} total line distance
|
|
14916
|
-
* @example
|
|
14917
|
-
* const length = ruler.lineDistance([
|
|
14918
|
-
* [-67.031, 50.458], [-67.031, 50.534],
|
|
14919
|
-
* [-66.929, 50.534], [-66.929, 50.458]
|
|
14920
|
-
* ]);
|
|
14921
|
-
* //=length
|
|
14922
|
-
*/
|
|
14923
|
-
lineDistance(points) {
|
|
14924
|
-
let total = 0;
|
|
14925
|
-
for (let i = 0; i < points.length - 1; i++) {
|
|
14926
|
-
total += this.distance(points[i], points[i + 1]);
|
|
14927
|
-
}
|
|
14928
|
-
return total;
|
|
14929
|
-
}
|
|
14930
|
-
|
|
14931
|
-
/**
|
|
14932
|
-
* Given a polygon (an array of rings, where each ring is an array of points), returns the area.
|
|
14933
|
-
*
|
|
14934
|
-
* @param {[number, number][][]} polygon
|
|
14935
|
-
* @returns {number} area value in the specified units (square kilometers by default)
|
|
14936
|
-
* @example
|
|
14937
|
-
* const area = ruler.area([[
|
|
14938
|
-
* [-67.031, 50.458], [-67.031, 50.534], [-66.929, 50.534],
|
|
14939
|
-
* [-66.929, 50.458], [-67.031, 50.458]
|
|
14940
|
-
* ]]);
|
|
14941
|
-
* //=area
|
|
14942
|
-
*/
|
|
14943
|
-
area(polygon) {
|
|
14944
|
-
let sum = 0;
|
|
14945
|
-
|
|
14946
|
-
for (let i = 0; i < polygon.length; i++) {
|
|
14947
|
-
const ring = polygon[i];
|
|
14948
|
-
|
|
14949
|
-
for (let j = 0, len = ring.length, k = len - 1; j < len; k = j++) {
|
|
14950
|
-
sum += wrap(ring[j][0] - ring[k][0]) * (ring[j][1] + ring[k][1]) * (i ? -1 : 1);
|
|
14951
|
-
}
|
|
14952
|
-
}
|
|
14953
|
-
|
|
14954
|
-
return (Math.abs(sum) / 2) * this.kx * this.ky;
|
|
14955
|
-
}
|
|
14956
|
-
|
|
14957
|
-
/**
|
|
14958
|
-
* Returns the point at a specified distance along the line.
|
|
14959
|
-
*
|
|
14960
|
-
* @param {[number, number][]} line
|
|
14961
|
-
* @param {number} dist distance
|
|
14962
|
-
* @returns {[number, number]} point [longitude, latitude]
|
|
14963
|
-
* @example
|
|
14964
|
-
* const point = ruler.along(line, 2.5);
|
|
14965
|
-
* //=point
|
|
14966
|
-
*/
|
|
14967
|
-
along(line, dist) {
|
|
14968
|
-
let sum = 0;
|
|
14969
|
-
|
|
14970
|
-
if (dist <= 0) return line[0];
|
|
14971
|
-
|
|
14972
|
-
for (let i = 0; i < line.length - 1; i++) {
|
|
14973
|
-
const p0 = line[i];
|
|
14974
|
-
const p1 = line[i + 1];
|
|
14975
|
-
const d = this.distance(p0, p1);
|
|
14976
|
-
sum += d;
|
|
14977
|
-
if (sum > dist) return interpolate$1(p0, p1, (dist - (sum - d)) / d);
|
|
14978
|
-
}
|
|
14979
|
-
|
|
14980
|
-
return line[line.length - 1];
|
|
14981
|
-
}
|
|
14982
|
-
|
|
14983
|
-
/**
|
|
14984
|
-
* Returns the distance from a point `p` to a line segment `a` to `b`.
|
|
14985
|
-
*
|
|
14986
|
-
* @pointToSegmentDistance
|
|
14987
|
-
* @param {[number, number]} p point [longitude, latitude]
|
|
14988
|
-
* @param {[number, number]} a segment point 1 [longitude, latitude]
|
|
14989
|
-
* @param {[number, number]} b segment point 2 [longitude, latitude]
|
|
14990
|
-
* @returns {number} distance
|
|
14991
|
-
* @example
|
|
14992
|
-
* const distance = ruler.pointToSegmentDistance([-67.04, 50.5], [-67.05, 50.57], [-67.03, 50.54]);
|
|
14993
|
-
* //=distance
|
|
14994
|
-
*/
|
|
14995
|
-
pointToSegmentDistance(p, a, b) {
|
|
14996
|
-
let [x, y] = a;
|
|
14997
|
-
let dx = wrap(b[0] - x) * this.kx;
|
|
14998
|
-
let dy = (b[1] - y) * this.ky;
|
|
14999
|
-
|
|
15000
|
-
if (dx !== 0 || dy !== 0) {
|
|
15001
|
-
const t = (wrap(p[0] - x) * this.kx * dx + (p[1] - y) * this.ky * dy) / (dx * dx + dy * dy);
|
|
15002
|
-
|
|
15003
|
-
if (t > 1) {
|
|
15004
|
-
x = b[0];
|
|
15005
|
-
y = b[1];
|
|
15006
|
-
|
|
15007
|
-
} else if (t > 0) {
|
|
15008
|
-
x += (dx / this.kx) * t;
|
|
15009
|
-
y += (dy / this.ky) * t;
|
|
15010
|
-
}
|
|
15011
|
-
}
|
|
15012
|
-
|
|
15013
|
-
dx = wrap(p[0] - x) * this.kx;
|
|
15014
|
-
dy = (p[1] - y) * this.ky;
|
|
15015
|
-
|
|
15016
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
15017
|
-
}
|
|
15018
|
-
|
|
15019
|
-
/**
|
|
15020
|
-
* Returns an object of the form {point, index, t}, where point is closest point on the line
|
|
15021
|
-
* from the given point, index is the start index of the segment with the closest point,
|
|
15022
|
-
* and t is a parameter from 0 to 1 that indicates where the closest point is on that segment.
|
|
15023
|
-
*
|
|
15024
|
-
* @param {[number, number][]} line
|
|
15025
|
-
* @param {[number, number]} p point [longitude, latitude]
|
|
15026
|
-
* @returns {{point: [number, number], index: number, t: number}} {point, index, t}
|
|
15027
|
-
* @example
|
|
15028
|
-
* const point = ruler.pointOnLine(line, [-67.04, 50.5]).point;
|
|
15029
|
-
* //=point
|
|
15030
|
-
*/
|
|
15031
|
-
pointOnLine(line, p) {
|
|
15032
|
-
let minDist = Infinity;
|
|
15033
|
-
let minX = line[0][0];
|
|
15034
|
-
let minY = line[0][1];
|
|
15035
|
-
let minI = 0;
|
|
15036
|
-
let minT = 0;
|
|
15037
|
-
|
|
15038
|
-
for (let i = 0; i < line.length - 1; i++) {
|
|
15039
|
-
|
|
15040
|
-
let x = line[i][0];
|
|
15041
|
-
let y = line[i][1];
|
|
15042
|
-
let dx = wrap(line[i + 1][0] - x) * this.kx;
|
|
15043
|
-
let dy = (line[i + 1][1] - y) * this.ky;
|
|
15044
|
-
let t = 0;
|
|
15045
|
-
|
|
15046
|
-
if (dx !== 0 || dy !== 0) {
|
|
15047
|
-
t = (wrap(p[0] - x) * this.kx * dx + (p[1] - y) * this.ky * dy) / (dx * dx + dy * dy);
|
|
15048
|
-
|
|
15049
|
-
if (t > 1) {
|
|
15050
|
-
x = line[i + 1][0];
|
|
15051
|
-
y = line[i + 1][1];
|
|
15052
|
-
|
|
15053
|
-
} else if (t > 0) {
|
|
15054
|
-
x += (dx / this.kx) * t;
|
|
15055
|
-
y += (dy / this.ky) * t;
|
|
15056
|
-
}
|
|
15057
|
-
}
|
|
15058
|
-
|
|
15059
|
-
dx = wrap(p[0] - x) * this.kx;
|
|
15060
|
-
dy = (p[1] - y) * this.ky;
|
|
15061
|
-
|
|
15062
|
-
const sqDist = dx * dx + dy * dy;
|
|
15063
|
-
if (sqDist < minDist) {
|
|
15064
|
-
minDist = sqDist;
|
|
15065
|
-
minX = x;
|
|
15066
|
-
minY = y;
|
|
15067
|
-
minI = i;
|
|
15068
|
-
minT = t;
|
|
15069
|
-
}
|
|
15070
|
-
}
|
|
15071
|
-
|
|
15072
|
-
return {
|
|
15073
|
-
point: [minX, minY],
|
|
15074
|
-
index: minI,
|
|
15075
|
-
t: Math.max(0, Math.min(1, minT))
|
|
15076
|
-
};
|
|
15077
|
-
}
|
|
15078
|
-
|
|
15079
|
-
/**
|
|
15080
|
-
* Returns a part of the given line between the start and the stop points (or their closest points on the line).
|
|
15081
|
-
*
|
|
15082
|
-
* @param {[number, number]} start point [longitude, latitude]
|
|
15083
|
-
* @param {[number, number]} stop point [longitude, latitude]
|
|
15084
|
-
* @param {[number, number][]} line
|
|
15085
|
-
* @returns {[number, number][]} line part of a line
|
|
15086
|
-
* @example
|
|
15087
|
-
* const line2 = ruler.lineSlice([-67.04, 50.5], [-67.05, 50.56], line1);
|
|
15088
|
-
* //=line2
|
|
15089
|
-
*/
|
|
15090
|
-
lineSlice(start, stop, line) {
|
|
15091
|
-
let p1 = this.pointOnLine(line, start);
|
|
15092
|
-
let p2 = this.pointOnLine(line, stop);
|
|
15093
|
-
|
|
15094
|
-
if (p1.index > p2.index || (p1.index === p2.index && p1.t > p2.t)) {
|
|
15095
|
-
const tmp = p1;
|
|
15096
|
-
p1 = p2;
|
|
15097
|
-
p2 = tmp;
|
|
15098
|
-
}
|
|
15099
|
-
|
|
15100
|
-
const slice = [p1.point];
|
|
15101
|
-
|
|
15102
|
-
const l = p1.index + 1;
|
|
15103
|
-
const r = p2.index;
|
|
15104
|
-
|
|
15105
|
-
if (!equals(line[l], slice[0]) && l <= r)
|
|
15106
|
-
slice.push(line[l]);
|
|
15107
|
-
|
|
15108
|
-
for (let i = l + 1; i <= r; i++) {
|
|
15109
|
-
slice.push(line[i]);
|
|
15110
|
-
}
|
|
15111
|
-
|
|
15112
|
-
if (!equals(line[r], p2.point))
|
|
15113
|
-
slice.push(p2.point);
|
|
15114
|
-
|
|
15115
|
-
return slice;
|
|
15116
|
-
}
|
|
15117
|
-
|
|
15118
|
-
/**
|
|
15119
|
-
* Returns a part of the given line between the start and the stop points indicated by distance along the line.
|
|
15120
|
-
*
|
|
15121
|
-
* @param {number} start start distance
|
|
15122
|
-
* @param {number} stop stop distance
|
|
15123
|
-
* @param {[number, number][]} line
|
|
15124
|
-
* @returns {[number, number][]} part of a line
|
|
15125
|
-
* @example
|
|
15126
|
-
* const line2 = ruler.lineSliceAlong(10, 20, line1);
|
|
15127
|
-
* //=line2
|
|
15128
|
-
*/
|
|
15129
|
-
lineSliceAlong(start, stop, line) {
|
|
15130
|
-
let sum = 0;
|
|
15131
|
-
const slice = [];
|
|
15132
|
-
|
|
15133
|
-
for (let i = 0; i < line.length - 1; i++) {
|
|
15134
|
-
const p0 = line[i];
|
|
15135
|
-
const p1 = line[i + 1];
|
|
15136
|
-
const d = this.distance(p0, p1);
|
|
15137
|
-
|
|
15138
|
-
sum += d;
|
|
15139
|
-
|
|
15140
|
-
if (sum > start && slice.length === 0) {
|
|
15141
|
-
slice.push(interpolate$1(p0, p1, (start - (sum - d)) / d));
|
|
15142
|
-
}
|
|
15143
|
-
|
|
15144
|
-
if (sum >= stop) {
|
|
15145
|
-
slice.push(interpolate$1(p0, p1, (stop - (sum - d)) / d));
|
|
15146
|
-
return slice;
|
|
15147
|
-
}
|
|
15148
|
-
|
|
15149
|
-
if (sum > start) slice.push(p1);
|
|
15150
|
-
}
|
|
15151
|
-
|
|
15152
|
-
return slice;
|
|
15153
|
-
}
|
|
15154
|
-
|
|
15155
|
-
/**
|
|
15156
|
-
* Given a point, returns a bounding box object ([w, s, e, n]) created from the given point buffered by a given distance.
|
|
15157
|
-
*
|
|
15158
|
-
* @param {[number, number]} p point [longitude, latitude]
|
|
15159
|
-
* @param {number} buffer
|
|
15160
|
-
* @returns {[number, number, number, number]} bbox ([w, s, e, n])
|
|
15161
|
-
* @example
|
|
15162
|
-
* const bbox = ruler.bufferPoint([30.5, 50.5], 0.01);
|
|
15163
|
-
* //=bbox
|
|
15164
|
-
*/
|
|
15165
|
-
bufferPoint(p, buffer) {
|
|
15166
|
-
const v = buffer / this.ky;
|
|
15167
|
-
const h = buffer / this.kx;
|
|
15168
|
-
return [
|
|
15169
|
-
p[0] - h,
|
|
15170
|
-
p[1] - v,
|
|
15171
|
-
p[0] + h,
|
|
15172
|
-
p[1] + v
|
|
15173
|
-
];
|
|
15174
|
-
}
|
|
15175
|
-
|
|
15176
|
-
/**
|
|
15177
|
-
* Given a bounding box, returns the box buffered by a given distance.
|
|
15178
|
-
*
|
|
15179
|
-
* @param {[number, number, number, number]} bbox ([w, s, e, n])
|
|
15180
|
-
* @param {number} buffer
|
|
15181
|
-
* @returns {[number, number, number, number]} bbox ([w, s, e, n])
|
|
15182
|
-
* @example
|
|
15183
|
-
* const bbox = ruler.bufferBBox([30.5, 50.5, 31, 51], 0.2);
|
|
15184
|
-
* //=bbox
|
|
15185
|
-
*/
|
|
15186
|
-
bufferBBox(bbox, buffer) {
|
|
15187
|
-
const v = buffer / this.ky;
|
|
15188
|
-
const h = buffer / this.kx;
|
|
15189
|
-
return [
|
|
15190
|
-
bbox[0] - h,
|
|
15191
|
-
bbox[1] - v,
|
|
15192
|
-
bbox[2] + h,
|
|
15193
|
-
bbox[3] + v
|
|
15194
|
-
];
|
|
15195
|
-
}
|
|
15196
|
-
|
|
15197
|
-
/**
|
|
15198
|
-
* Returns true if the given point is inside in the given bounding box, otherwise false.
|
|
15199
|
-
*
|
|
15200
|
-
* @param {[number, number]} p point [longitude, latitude]
|
|
15201
|
-
* @param {[number, number, number, number]} bbox ([w, s, e, n])
|
|
15202
|
-
* @returns {boolean}
|
|
15203
|
-
* @example
|
|
15204
|
-
* const inside = ruler.insideBBox([30.5, 50.5], [30, 50, 31, 51]);
|
|
15205
|
-
* //=inside
|
|
15206
|
-
*/
|
|
15207
|
-
insideBBox(p, bbox) { // eslint-disable-line
|
|
15208
|
-
return wrap(p[0] - bbox[0]) >= 0 &&
|
|
15209
|
-
wrap(p[0] - bbox[2]) <= 0 &&
|
|
15210
|
-
p[1] >= bbox[1] &&
|
|
15211
|
-
p[1] <= bbox[3];
|
|
15212
|
-
}
|
|
15213
|
-
}
|
|
15214
|
-
|
|
15215
|
-
/**
|
|
15216
|
-
* @param {[number, number]} a
|
|
15217
|
-
* @param {[number, number]} b
|
|
15218
|
-
*/
|
|
15219
|
-
function equals(a, b) {
|
|
15220
|
-
return a[0] === b[0] && a[1] === b[1];
|
|
15221
|
-
}
|
|
15222
|
-
|
|
15223
|
-
/**
|
|
15224
|
-
* @param {[number, number]} a
|
|
15225
|
-
* @param {[number, number]} b
|
|
15226
|
-
* @param {number} t
|
|
15227
|
-
* @returns {[number, number]}
|
|
15228
|
-
*/
|
|
15229
|
-
function interpolate$1(a, b, t) {
|
|
15230
|
-
const dx = wrap(b[0] - a[0]);
|
|
15231
|
-
const dy = b[1] - a[1];
|
|
15232
|
-
return [
|
|
15233
|
-
a[0] + dx * t,
|
|
15234
|
-
a[1] + dy * t
|
|
15235
|
-
];
|
|
15236
|
-
}
|
|
15237
|
-
|
|
15238
|
-
/**
|
|
15239
|
-
* normalize a degree value into [-180..180] range
|
|
15240
|
-
* @param {number} deg
|
|
15241
|
-
*/
|
|
15242
|
-
function wrap(deg) {
|
|
15243
|
-
while (deg < -180) deg += 360;
|
|
15244
|
-
while (deg > 180) deg -= 360;
|
|
15245
|
-
return deg;
|
|
15246
|
-
}
|
|
15247
|
-
|
|
15248
14763
|
class TinyQueue {
|
|
15249
14764
|
constructor(data = [], compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0)) {
|
|
15250
14765
|
this.data = data;
|
|
@@ -15318,6 +14833,77 @@ class TinyQueue {
|
|
|
15318
14833
|
|
|
15319
14834
|
var EXTENT = 8192;
|
|
15320
14835
|
|
|
14836
|
+
const RE = 6378.137;
|
|
14837
|
+
const FE = 1 / 298.257223563;
|
|
14838
|
+
const E2 = FE * (2 - FE);
|
|
14839
|
+
const RAD = Math.PI / 180;
|
|
14840
|
+
function lngLatScale(lat) {
|
|
14841
|
+
const m = RAD * RE * 1e3;
|
|
14842
|
+
const coslat = Math.cos(lat * RAD);
|
|
14843
|
+
const w2 = 1 / (1 - E2 * (1 - coslat * coslat));
|
|
14844
|
+
const w = Math.sqrt(w2);
|
|
14845
|
+
return [m * w * coslat, m * w * w2 * (1 - E2)];
|
|
14846
|
+
}
|
|
14847
|
+
function wrapLng(deg) {
|
|
14848
|
+
while (deg < -180) deg += 360;
|
|
14849
|
+
while (deg > 180) deg -= 360;
|
|
14850
|
+
return deg;
|
|
14851
|
+
}
|
|
14852
|
+
function rulerDistance(a, b, kx, ky) {
|
|
14853
|
+
const dx = wrapLng(a[0] - b[0]) * kx;
|
|
14854
|
+
const dy = (a[1] - b[1]) * ky;
|
|
14855
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
14856
|
+
}
|
|
14857
|
+
function rulerPointToSegmentDistance(p, a, b, kx, ky) {
|
|
14858
|
+
let x = a[0];
|
|
14859
|
+
let y = a[1];
|
|
14860
|
+
let dx = wrapLng(b[0] - x) * kx;
|
|
14861
|
+
let dy = (b[1] - y) * ky;
|
|
14862
|
+
if (dx !== 0 || dy !== 0) {
|
|
14863
|
+
const t = (wrapLng(p[0] - x) * kx * dx + (p[1] - y) * ky * dy) / (dx * dx + dy * dy);
|
|
14864
|
+
if (t > 1) {
|
|
14865
|
+
x = b[0];
|
|
14866
|
+
y = b[1];
|
|
14867
|
+
} else if (t > 0) {
|
|
14868
|
+
x += dx / kx * t;
|
|
14869
|
+
y += dy / ky * t;
|
|
14870
|
+
}
|
|
14871
|
+
}
|
|
14872
|
+
dx = wrapLng(p[0] - x) * kx;
|
|
14873
|
+
dy = (p[1] - y) * ky;
|
|
14874
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
14875
|
+
}
|
|
14876
|
+
function rulerPointOnLine(line, p, kx, ky) {
|
|
14877
|
+
let minDist = Infinity;
|
|
14878
|
+
let minX = line[0][0];
|
|
14879
|
+
let minY = line[0][1];
|
|
14880
|
+
for (let i = 0; i < line.length - 1; i++) {
|
|
14881
|
+
let x = line[i][0];
|
|
14882
|
+
let y = line[i][1];
|
|
14883
|
+
let dx = wrapLng(line[i + 1][0] - x) * kx;
|
|
14884
|
+
let dy = (line[i + 1][1] - y) * ky;
|
|
14885
|
+
let t = 0;
|
|
14886
|
+
if (dx !== 0 || dy !== 0) {
|
|
14887
|
+
t = (wrapLng(p[0] - x) * kx * dx + (p[1] - y) * ky * dy) / (dx * dx + dy * dy);
|
|
14888
|
+
if (t > 1) {
|
|
14889
|
+
x = line[i + 1][0];
|
|
14890
|
+
y = line[i + 1][1];
|
|
14891
|
+
} else if (t > 0) {
|
|
14892
|
+
x += dx / kx * t;
|
|
14893
|
+
y += dy / ky * t;
|
|
14894
|
+
}
|
|
14895
|
+
}
|
|
14896
|
+
dx = wrapLng(p[0] - x) * kx;
|
|
14897
|
+
dy = (p[1] - y) * ky;
|
|
14898
|
+
const sqDist = dx * dx + dy * dy;
|
|
14899
|
+
if (sqDist < minDist) {
|
|
14900
|
+
minDist = sqDist;
|
|
14901
|
+
minX = x;
|
|
14902
|
+
minY = y;
|
|
14903
|
+
}
|
|
14904
|
+
}
|
|
14905
|
+
return [minX, minY];
|
|
14906
|
+
}
|
|
15321
14907
|
function compareMax(a, b) {
|
|
15322
14908
|
return b.dist - a.dist;
|
|
15323
14909
|
}
|
|
@@ -15383,7 +14969,7 @@ function getPolygonBBox(polygon) {
|
|
|
15383
14969
|
}
|
|
15384
14970
|
return bbox;
|
|
15385
14971
|
}
|
|
15386
|
-
function bboxToBBoxDistance(bbox1, bbox2,
|
|
14972
|
+
function bboxToBBoxDistance(bbox1, bbox2, kx, ky) {
|
|
15387
14973
|
if (isDefaultBBOX(bbox1) || isDefaultBBOX(bbox2)) {
|
|
15388
14974
|
return NaN;
|
|
15389
14975
|
}
|
|
@@ -15401,7 +14987,7 @@ function bboxToBBoxDistance(bbox1, bbox2, ruler) {
|
|
|
15401
14987
|
if (bbox1[3] < bbox2[1]) {
|
|
15402
14988
|
dy = bbox2[1] - bbox1[3];
|
|
15403
14989
|
}
|
|
15404
|
-
return
|
|
14990
|
+
return rulerDistance([0, 0], [dx, dy], kx, ky);
|
|
15405
14991
|
}
|
|
15406
14992
|
function getLngLatPoint(coord, canonical, extent = EXTENT) {
|
|
15407
14993
|
const tilesAtZoom = Math.pow(2, canonical.z);
|
|
@@ -15416,30 +15002,30 @@ function getLngLatPoints(coordinates, canonical) {
|
|
|
15416
15002
|
}
|
|
15417
15003
|
return coords;
|
|
15418
15004
|
}
|
|
15419
|
-
function pointToLineDistance(point, line,
|
|
15420
|
-
const nearestPoint =
|
|
15421
|
-
return
|
|
15005
|
+
function pointToLineDistance(point, line, kx, ky) {
|
|
15006
|
+
const nearestPoint = rulerPointOnLine(line, point, kx, ky);
|
|
15007
|
+
return rulerDistance(point, nearestPoint, kx, ky);
|
|
15422
15008
|
}
|
|
15423
|
-
function pointsToLineDistance(points, rangeA, line, rangeB,
|
|
15009
|
+
function pointsToLineDistance(points, rangeA, line, rangeB, kx, ky) {
|
|
15424
15010
|
const subLine = line.slice(rangeB[0], rangeB[1] + 1);
|
|
15425
15011
|
let dist = Infinity;
|
|
15426
15012
|
for (let i = rangeA[0]; i <= rangeA[1]; ++i) {
|
|
15427
|
-
if ((dist = Math.min(dist, pointToLineDistance(points[i], subLine,
|
|
15013
|
+
if ((dist = Math.min(dist, pointToLineDistance(points[i], subLine, kx, ky))) === 0) return 0;
|
|
15428
15014
|
}
|
|
15429
15015
|
return dist;
|
|
15430
15016
|
}
|
|
15431
|
-
function segmentToSegmentDistance(p1, p2, q1, q2,
|
|
15017
|
+
function segmentToSegmentDistance(p1, p2, q1, q2, kx, ky) {
|
|
15432
15018
|
const dist1 = Math.min(
|
|
15433
|
-
|
|
15434
|
-
|
|
15019
|
+
rulerPointToSegmentDistance(p1, q1, q2, kx, ky),
|
|
15020
|
+
rulerPointToSegmentDistance(p2, q1, q2, kx, ky)
|
|
15435
15021
|
);
|
|
15436
15022
|
const dist2 = Math.min(
|
|
15437
|
-
|
|
15438
|
-
|
|
15023
|
+
rulerPointToSegmentDistance(q1, p1, p2, kx, ky),
|
|
15024
|
+
rulerPointToSegmentDistance(q2, p1, p2, kx, ky)
|
|
15439
15025
|
);
|
|
15440
15026
|
return Math.min(dist1, dist2);
|
|
15441
15027
|
}
|
|
15442
|
-
function lineToLineDistance(line1, range1, line2, range2,
|
|
15028
|
+
function lineToLineDistance(line1, range1, line2, range2, kx, ky) {
|
|
15443
15029
|
if (!isRangeSafe(range1, line1.length) || !isRangeSafe(range2, line2.length)) {
|
|
15444
15030
|
return NaN;
|
|
15445
15031
|
}
|
|
@@ -15447,24 +15033,24 @@ function lineToLineDistance(line1, range1, line2, range2, ruler) {
|
|
|
15447
15033
|
for (let i = range1[0]; i < range1[1]; ++i) {
|
|
15448
15034
|
for (let j = range2[0]; j < range2[1]; ++j) {
|
|
15449
15035
|
if (segmentIntersectSegment(line1[i], line1[i + 1], line2[j], line2[j + 1])) return 0;
|
|
15450
|
-
dist = Math.min(dist, segmentToSegmentDistance(line1[i], line1[i + 1], line2[j], line2[j + 1],
|
|
15036
|
+
dist = Math.min(dist, segmentToSegmentDistance(line1[i], line1[i + 1], line2[j], line2[j + 1], kx, ky));
|
|
15451
15037
|
}
|
|
15452
15038
|
}
|
|
15453
15039
|
return dist;
|
|
15454
15040
|
}
|
|
15455
|
-
function pointsToPointsDistance(pointSet1, range1, pointSet2, range2,
|
|
15041
|
+
function pointsToPointsDistance(pointSet1, range1, pointSet2, range2, kx, ky) {
|
|
15456
15042
|
if (!isRangeSafe(range1, pointSet1.length) || !isRangeSafe(range2, pointSet2.length)) {
|
|
15457
15043
|
return NaN;
|
|
15458
15044
|
}
|
|
15459
15045
|
let dist = Infinity;
|
|
15460
15046
|
for (let i = range1[0]; i <= range1[1]; ++i) {
|
|
15461
15047
|
for (let j = range2[0]; j <= range2[1]; ++j) {
|
|
15462
|
-
if ((dist = Math.min(dist,
|
|
15048
|
+
if ((dist = Math.min(dist, rulerDistance(pointSet1[i], pointSet2[j], kx, ky))) === 0) return dist;
|
|
15463
15049
|
}
|
|
15464
15050
|
}
|
|
15465
15051
|
return dist;
|
|
15466
15052
|
}
|
|
15467
|
-
function pointToPolygonDistance(point, polygon,
|
|
15053
|
+
function pointToPolygonDistance(point, polygon, kx, ky) {
|
|
15468
15054
|
if (pointWithinPolygon(
|
|
15469
15055
|
point,
|
|
15470
15056
|
polygon,
|
|
@@ -15479,13 +15065,13 @@ function pointToPolygonDistance(point, polygon, ruler) {
|
|
|
15479
15065
|
return NaN;
|
|
15480
15066
|
}
|
|
15481
15067
|
if (ring[0] !== ring[ringLen - 1]) {
|
|
15482
|
-
if ((dist = Math.min(dist,
|
|
15068
|
+
if ((dist = Math.min(dist, rulerPointToSegmentDistance(point, ring[ringLen - 1], ring[0], kx, ky))) === 0) return dist;
|
|
15483
15069
|
}
|
|
15484
|
-
if ((dist = Math.min(dist, pointToLineDistance(point, ring,
|
|
15070
|
+
if ((dist = Math.min(dist, pointToLineDistance(point, ring, kx, ky))) === 0) return dist;
|
|
15485
15071
|
}
|
|
15486
15072
|
return dist;
|
|
15487
15073
|
}
|
|
15488
|
-
function lineToPolygonDistance(line, range, polygon,
|
|
15074
|
+
function lineToPolygonDistance(line, range, polygon, kx, ky) {
|
|
15489
15075
|
if (!isRangeSafe(range, line.length)) {
|
|
15490
15076
|
return NaN;
|
|
15491
15077
|
}
|
|
@@ -15502,7 +15088,7 @@ function lineToPolygonDistance(line, range, polygon, ruler) {
|
|
|
15502
15088
|
for (const ring of polygon) {
|
|
15503
15089
|
for (let j = 0, len = ring.length, k = len - 1; j < len; k = j++) {
|
|
15504
15090
|
if (segmentIntersectSegment(line[i], line[i + 1], ring[k], ring[j])) return 0;
|
|
15505
|
-
dist = Math.min(dist, segmentToSegmentDistance(line[i], line[i + 1], ring[k], ring[j],
|
|
15091
|
+
dist = Math.min(dist, segmentToSegmentDistance(line[i], line[i + 1], ring[k], ring[j], kx, ky));
|
|
15506
15092
|
}
|
|
15507
15093
|
}
|
|
15508
15094
|
}
|
|
@@ -15521,10 +15107,10 @@ function polygonIntersect(polygon1, polygon2) {
|
|
|
15521
15107
|
}
|
|
15522
15108
|
return false;
|
|
15523
15109
|
}
|
|
15524
|
-
function polygonToPolygonDistance(polygon1, polygon2,
|
|
15110
|
+
function polygonToPolygonDistance(polygon1, polygon2, kx, ky, currentMiniDist = Infinity) {
|
|
15525
15111
|
const bbox1 = getPolygonBBox(polygon1);
|
|
15526
15112
|
const bbox2 = getPolygonBBox(polygon2);
|
|
15527
|
-
if (currentMiniDist !== Infinity && bboxToBBoxDistance(bbox1, bbox2,
|
|
15113
|
+
if (currentMiniDist !== Infinity && bboxToBBoxDistance(bbox1, bbox2, kx, ky) >= currentMiniDist) {
|
|
15528
15114
|
return currentMiniDist;
|
|
15529
15115
|
}
|
|
15530
15116
|
if (boxWithinBox(bbox1, bbox2)) {
|
|
@@ -15538,20 +15124,20 @@ function polygonToPolygonDistance(polygon1, polygon2, ruler, currentMiniDist = I
|
|
|
15538
15124
|
for (const ring2 of polygon2) {
|
|
15539
15125
|
for (let j = 0, len2 = ring2.length, k = len2 - 1; j < len2; k = j++) {
|
|
15540
15126
|
if (segmentIntersectSegment(ring1[l], ring1[i], ring2[k], ring2[j])) return 0;
|
|
15541
|
-
dist = Math.min(dist, segmentToSegmentDistance(ring1[l], ring1[i], ring2[k], ring2[j],
|
|
15127
|
+
dist = Math.min(dist, segmentToSegmentDistance(ring1[l], ring1[i], ring2[k], ring2[j], kx, ky));
|
|
15542
15128
|
}
|
|
15543
15129
|
}
|
|
15544
15130
|
}
|
|
15545
15131
|
}
|
|
15546
15132
|
return dist;
|
|
15547
15133
|
}
|
|
15548
|
-
function updateQueue(distQueue, miniDist,
|
|
15134
|
+
function updateQueue(distQueue, miniDist, kx, ky, pointSet1, pointSet2, r1, r2) {
|
|
15549
15135
|
if (r1 === null || r2 === null) return;
|
|
15550
|
-
const tempDist = bboxToBBoxDistance(getBBox(pointSet1, r1), getBBox(pointSet2, r2),
|
|
15136
|
+
const tempDist = bboxToBBoxDistance(getBBox(pointSet1, r1), getBBox(pointSet2, r2), kx, ky);
|
|
15551
15137
|
if (tempDist < miniDist) distQueue.push({ dist: tempDist, range1: r1, range2: r2 });
|
|
15552
15138
|
}
|
|
15553
|
-
function pointSetToPolygonDistance(pointSets, isLine, polygon,
|
|
15554
|
-
let miniDist = Math.min(
|
|
15139
|
+
function pointSetToPolygonDistance(pointSets, isLine, polygon, kx, ky, currentMiniDist = Infinity) {
|
|
15140
|
+
let miniDist = Math.min(rulerDistance(pointSets[0], polygon[0][0], kx, ky), currentMiniDist);
|
|
15555
15141
|
if (miniDist === 0) return miniDist;
|
|
15556
15142
|
const initialDistPair = {
|
|
15557
15143
|
dist: 0,
|
|
@@ -15568,30 +15154,30 @@ function pointSetToPolygonDistance(pointSets, isLine, polygon, ruler, currentMin
|
|
|
15568
15154
|
if (getRangeSize(range) <= setThreshold) {
|
|
15569
15155
|
if (!isRangeSafe(range, pointSets.length)) return NaN;
|
|
15570
15156
|
if (isLine) {
|
|
15571
|
-
const tempDist = lineToPolygonDistance(pointSets, range, polygon,
|
|
15157
|
+
const tempDist = lineToPolygonDistance(pointSets, range, polygon, kx, ky);
|
|
15572
15158
|
if ((miniDist = Math.min(miniDist, tempDist)) === 0) return miniDist;
|
|
15573
15159
|
} else {
|
|
15574
15160
|
for (let i = range[0]; i <= range[1]; ++i) {
|
|
15575
|
-
const tempDist = pointToPolygonDistance(pointSets[i], polygon,
|
|
15161
|
+
const tempDist = pointToPolygonDistance(pointSets[i], polygon, kx, ky);
|
|
15576
15162
|
if ((miniDist = Math.min(miniDist, tempDist)) === 0) return miniDist;
|
|
15577
15163
|
}
|
|
15578
15164
|
}
|
|
15579
15165
|
} else {
|
|
15580
15166
|
const newRanges = splitRange(range, isLine);
|
|
15581
15167
|
if (newRanges[0] !== null) {
|
|
15582
|
-
const tempDist = bboxToBBoxDistance(getBBox(pointSets, newRanges[0]), polyBBox,
|
|
15168
|
+
const tempDist = bboxToBBoxDistance(getBBox(pointSets, newRanges[0]), polyBBox, kx, ky);
|
|
15583
15169
|
if (tempDist < miniDist) distQueue.push({ dist: tempDist, range1: newRanges[0], range2: [0, 0] });
|
|
15584
15170
|
}
|
|
15585
15171
|
if (newRanges[1] !== null) {
|
|
15586
|
-
const tempDist = bboxToBBoxDistance(getBBox(pointSets, newRanges[1]), polyBBox,
|
|
15172
|
+
const tempDist = bboxToBBoxDistance(getBBox(pointSets, newRanges[1]), polyBBox, kx, ky);
|
|
15587
15173
|
if (tempDist < miniDist) distQueue.push({ dist: tempDist, range1: newRanges[1], range2: [0, 0] });
|
|
15588
15174
|
}
|
|
15589
15175
|
}
|
|
15590
15176
|
}
|
|
15591
15177
|
return miniDist;
|
|
15592
15178
|
}
|
|
15593
|
-
function pointSetsDistance(pointSet1, isLine1, pointSet2, isLine2,
|
|
15594
|
-
let miniDist = Math.min(currentMiniDist,
|
|
15179
|
+
function pointSetsDistance(pointSet1, isLine1, pointSet2, isLine2, kx, ky, currentMiniDist = Infinity) {
|
|
15180
|
+
let miniDist = Math.min(currentMiniDist, rulerDistance(pointSet1[0], pointSet2[0], kx, ky));
|
|
15595
15181
|
if (miniDist === 0) return miniDist;
|
|
15596
15182
|
const initialDistPair = {
|
|
15597
15183
|
dist: 0,
|
|
@@ -15611,52 +15197,52 @@ function pointSetsDistance(pointSet1, isLine1, pointSet2, isLine2, ruler, curren
|
|
|
15611
15197
|
return NaN;
|
|
15612
15198
|
}
|
|
15613
15199
|
if (isLine1 && isLine2) {
|
|
15614
|
-
miniDist = Math.min(miniDist, lineToLineDistance(pointSet1, rangeA, pointSet2, rangeB,
|
|
15200
|
+
miniDist = Math.min(miniDist, lineToLineDistance(pointSet1, rangeA, pointSet2, rangeB, kx, ky));
|
|
15615
15201
|
} else if (!isLine1 && !isLine2) {
|
|
15616
|
-
miniDist = Math.min(miniDist, pointsToPointsDistance(pointSet1, rangeA, pointSet2, rangeB,
|
|
15202
|
+
miniDist = Math.min(miniDist, pointsToPointsDistance(pointSet1, rangeA, pointSet2, rangeB, kx, ky));
|
|
15617
15203
|
} else if (isLine1 && !isLine2) {
|
|
15618
|
-
miniDist = Math.min(miniDist, pointsToLineDistance(pointSet2, rangeB, pointSet1, rangeA,
|
|
15204
|
+
miniDist = Math.min(miniDist, pointsToLineDistance(pointSet2, rangeB, pointSet1, rangeA, kx, ky));
|
|
15619
15205
|
} else if (!isLine1 && isLine2) {
|
|
15620
|
-
miniDist = Math.min(miniDist, pointsToLineDistance(pointSet1, rangeA, pointSet2, rangeB,
|
|
15206
|
+
miniDist = Math.min(miniDist, pointsToLineDistance(pointSet1, rangeA, pointSet2, rangeB, kx, ky));
|
|
15621
15207
|
}
|
|
15622
15208
|
if (miniDist === 0) return miniDist;
|
|
15623
15209
|
} else {
|
|
15624
15210
|
const newRangesA = splitRange(rangeA, isLine1);
|
|
15625
15211
|
const newRangesB = splitRange(rangeB, isLine2);
|
|
15626
|
-
updateQueue(distQueue, miniDist,
|
|
15627
|
-
updateQueue(distQueue, miniDist,
|
|
15628
|
-
updateQueue(distQueue, miniDist,
|
|
15629
|
-
updateQueue(distQueue, miniDist,
|
|
15212
|
+
updateQueue(distQueue, miniDist, kx, ky, pointSet1, pointSet2, newRangesA[0], newRangesB[0]);
|
|
15213
|
+
updateQueue(distQueue, miniDist, kx, ky, pointSet1, pointSet2, newRangesA[0], newRangesB[1]);
|
|
15214
|
+
updateQueue(distQueue, miniDist, kx, ky, pointSet1, pointSet2, newRangesA[1], newRangesB[0]);
|
|
15215
|
+
updateQueue(distQueue, miniDist, kx, ky, pointSet1, pointSet2, newRangesA[1], newRangesB[1]);
|
|
15630
15216
|
}
|
|
15631
15217
|
}
|
|
15632
15218
|
return miniDist;
|
|
15633
15219
|
}
|
|
15634
|
-
function pointSetToLinesDistance(pointSet, isLine, lines,
|
|
15220
|
+
function pointSetToLinesDistance(pointSet, isLine, lines, kx, ky, currentMiniDist = Infinity) {
|
|
15635
15221
|
let dist = currentMiniDist;
|
|
15636
15222
|
const bbox1 = getBBox(pointSet, [0, pointSet.length - 1]);
|
|
15637
15223
|
for (const line of lines) {
|
|
15638
|
-
if (dist !== Infinity && bboxToBBoxDistance(bbox1, getBBox(line, [0, line.length - 1]),
|
|
15639
|
-
dist = Math.min(dist, pointSetsDistance(pointSet, isLine, line, true,
|
|
15224
|
+
if (dist !== Infinity && bboxToBBoxDistance(bbox1, getBBox(line, [0, line.length - 1]), kx, ky) >= dist) continue;
|
|
15225
|
+
dist = Math.min(dist, pointSetsDistance(pointSet, isLine, line, true, kx, ky, dist));
|
|
15640
15226
|
if (dist === 0) return dist;
|
|
15641
15227
|
}
|
|
15642
15228
|
return dist;
|
|
15643
15229
|
}
|
|
15644
|
-
function pointSetToPolygonsDistance(points, isLine, polygons,
|
|
15230
|
+
function pointSetToPolygonsDistance(points, isLine, polygons, kx, ky, currentMiniDist = Infinity) {
|
|
15645
15231
|
let dist = currentMiniDist;
|
|
15646
15232
|
const bbox1 = getBBox(points, [0, points.length - 1]);
|
|
15647
15233
|
for (const polygon of polygons) {
|
|
15648
|
-
if (dist !== Infinity && bboxToBBoxDistance(bbox1, getPolygonBBox(polygon),
|
|
15649
|
-
const tempDist = pointSetToPolygonDistance(points, isLine, polygon,
|
|
15234
|
+
if (dist !== Infinity && bboxToBBoxDistance(bbox1, getPolygonBBox(polygon), kx, ky) >= dist) continue;
|
|
15235
|
+
const tempDist = pointSetToPolygonDistance(points, isLine, polygon, kx, ky, dist);
|
|
15650
15236
|
if (isNaN(tempDist)) return tempDist;
|
|
15651
15237
|
if ((dist = Math.min(dist, tempDist)) === 0) return dist;
|
|
15652
15238
|
}
|
|
15653
15239
|
return dist;
|
|
15654
15240
|
}
|
|
15655
|
-
function polygonsToPolygonsDistance(polygons1, polygons2,
|
|
15241
|
+
function polygonsToPolygonsDistance(polygons1, polygons2, kx, ky) {
|
|
15656
15242
|
let dist = Infinity;
|
|
15657
15243
|
for (const polygon1 of polygons1) {
|
|
15658
15244
|
for (const polygon2 of polygons2) {
|
|
15659
|
-
const tempDist = polygonToPolygonDistance(polygon1, polygon2,
|
|
15245
|
+
const tempDist = polygonToPolygonDistance(polygon1, polygon2, kx, ky, dist);
|
|
15660
15246
|
if (isNaN(tempDist)) return tempDist;
|
|
15661
15247
|
if ((dist = Math.min(dist, tempDist)) === 0) return dist;
|
|
15662
15248
|
}
|
|
@@ -15670,25 +15256,27 @@ function pointsToGeometryDistance(originGeometry, canonical, geometry) {
|
|
|
15670
15256
|
lngLatPoints.push(getLngLatPoint(point, canonical));
|
|
15671
15257
|
}
|
|
15672
15258
|
}
|
|
15673
|
-
const
|
|
15259
|
+
const [kx, ky] = lngLatScale(lngLatPoints[0][1]);
|
|
15674
15260
|
if (geometry.type === "Point" || geometry.type === "MultiPoint" || geometry.type === "LineString") {
|
|
15675
15261
|
return pointSetsDistance(
|
|
15676
15262
|
lngLatPoints,
|
|
15677
15263
|
false,
|
|
15678
15264
|
geometry.type === "Point" ? [geometry.coordinates] : geometry.coordinates,
|
|
15679
15265
|
geometry.type === "LineString",
|
|
15680
|
-
|
|
15266
|
+
kx,
|
|
15267
|
+
ky
|
|
15681
15268
|
);
|
|
15682
15269
|
}
|
|
15683
15270
|
if (geometry.type === "MultiLineString") {
|
|
15684
|
-
return pointSetToLinesDistance(lngLatPoints, false, geometry.coordinates,
|
|
15271
|
+
return pointSetToLinesDistance(lngLatPoints, false, geometry.coordinates, kx, ky);
|
|
15685
15272
|
}
|
|
15686
15273
|
if (geometry.type === "Polygon" || geometry.type === "MultiPolygon") {
|
|
15687
15274
|
return pointSetToPolygonsDistance(
|
|
15688
15275
|
lngLatPoints,
|
|
15689
15276
|
false,
|
|
15690
15277
|
geometry.type === "Polygon" ? [geometry.coordinates] : geometry.coordinates,
|
|
15691
|
-
|
|
15278
|
+
kx,
|
|
15279
|
+
ky
|
|
15692
15280
|
);
|
|
15693
15281
|
}
|
|
15694
15282
|
return null;
|
|
@@ -15702,19 +15290,20 @@ function linesToGeometryDistance(originGeometry, canonical, geometry) {
|
|
|
15702
15290
|
}
|
|
15703
15291
|
lngLatLines.push(lngLatLine);
|
|
15704
15292
|
}
|
|
15705
|
-
const
|
|
15293
|
+
const [kx, ky] = lngLatScale(lngLatLines[0][0][1]);
|
|
15706
15294
|
if (geometry.type === "Point" || geometry.type === "MultiPoint" || geometry.type === "LineString") {
|
|
15707
15295
|
return pointSetToLinesDistance(
|
|
15708
15296
|
geometry.type === "Point" ? [geometry.coordinates] : geometry.coordinates,
|
|
15709
15297
|
geometry.type === "LineString",
|
|
15710
15298
|
lngLatLines,
|
|
15711
|
-
|
|
15299
|
+
kx,
|
|
15300
|
+
ky
|
|
15712
15301
|
);
|
|
15713
15302
|
}
|
|
15714
15303
|
if (geometry.type === "MultiLineString") {
|
|
15715
15304
|
let dist = Infinity;
|
|
15716
15305
|
for (let i = 0; i < geometry.coordinates.length; i++) {
|
|
15717
|
-
const tempDist = pointSetToLinesDistance(geometry.coordinates[i], true, lngLatLines,
|
|
15306
|
+
const tempDist = pointSetToLinesDistance(geometry.coordinates[i], true, lngLatLines, kx, ky, dist);
|
|
15718
15307
|
if (isNaN(tempDist)) return tempDist;
|
|
15719
15308
|
if ((dist = Math.min(dist, tempDist)) === 0) return dist;
|
|
15720
15309
|
}
|
|
@@ -15727,7 +15316,8 @@ function linesToGeometryDistance(originGeometry, canonical, geometry) {
|
|
|
15727
15316
|
lngLatLines[i],
|
|
15728
15317
|
true,
|
|
15729
15318
|
geometry.type === "Polygon" ? [geometry.coordinates] : geometry.coordinates,
|
|
15730
|
-
|
|
15319
|
+
kx,
|
|
15320
|
+
ky,
|
|
15731
15321
|
dist
|
|
15732
15322
|
);
|
|
15733
15323
|
if (isNaN(tempDist)) return tempDist;
|
|
@@ -15746,19 +15336,20 @@ function polygonsToGeometryDistance(originGeometry, canonical, geometry) {
|
|
|
15746
15336
|
}
|
|
15747
15337
|
lngLatPolygons.push(lngLatPolygon);
|
|
15748
15338
|
}
|
|
15749
|
-
const
|
|
15339
|
+
const [kx, ky] = lngLatScale(lngLatPolygons[0][0][0][1]);
|
|
15750
15340
|
if (geometry.type === "Point" || geometry.type === "MultiPoint" || geometry.type === "LineString") {
|
|
15751
15341
|
return pointSetToPolygonsDistance(
|
|
15752
15342
|
geometry.type === "Point" ? [geometry.coordinates] : geometry.coordinates,
|
|
15753
15343
|
geometry.type === "LineString",
|
|
15754
15344
|
lngLatPolygons,
|
|
15755
|
-
|
|
15345
|
+
kx,
|
|
15346
|
+
ky
|
|
15756
15347
|
);
|
|
15757
15348
|
}
|
|
15758
15349
|
if (geometry.type === "MultiLineString") {
|
|
15759
15350
|
let dist = Infinity;
|
|
15760
15351
|
for (let i = 0; i < geometry.coordinates.length; i++) {
|
|
15761
|
-
const tempDist = pointSetToPolygonsDistance(geometry.coordinates[i], true, lngLatPolygons,
|
|
15352
|
+
const tempDist = pointSetToPolygonsDistance(geometry.coordinates[i], true, lngLatPolygons, kx, ky, dist);
|
|
15762
15353
|
if (isNaN(tempDist)) return tempDist;
|
|
15763
15354
|
if ((dist = Math.min(dist, tempDist)) === 0) return dist;
|
|
15764
15355
|
}
|
|
@@ -15768,7 +15359,8 @@ function polygonsToGeometryDistance(originGeometry, canonical, geometry) {
|
|
|
15768
15359
|
return polygonsToPolygonsDistance(
|
|
15769
15360
|
geometry.type === "Polygon" ? [geometry.coordinates] : geometry.coordinates,
|
|
15770
15361
|
lngLatPolygons,
|
|
15771
|
-
|
|
15362
|
+
kx,
|
|
15363
|
+
ky
|
|
15772
15364
|
);
|
|
15773
15365
|
}
|
|
15774
15366
|
return null;
|
|
@@ -15880,18 +15472,21 @@ function isStateConstant(e) {
|
|
|
15880
15472
|
});
|
|
15881
15473
|
return result;
|
|
15882
15474
|
}
|
|
15883
|
-
function
|
|
15884
|
-
if (e instanceof CompoundExpression && properties.
|
|
15475
|
+
function isGlobalPropertyConstantSet(e, properties) {
|
|
15476
|
+
if (e instanceof CompoundExpression && properties.has(e.name)) {
|
|
15885
15477
|
return false;
|
|
15886
15478
|
}
|
|
15887
15479
|
let result = true;
|
|
15888
15480
|
e.eachChild((arg) => {
|
|
15889
|
-
if (result && !
|
|
15481
|
+
if (result && !isGlobalPropertyConstantSet(arg, properties)) {
|
|
15890
15482
|
result = false;
|
|
15891
15483
|
}
|
|
15892
15484
|
});
|
|
15893
15485
|
return result;
|
|
15894
15486
|
}
|
|
15487
|
+
function isGlobalPropertyConstant(e, properties) {
|
|
15488
|
+
return isGlobalPropertyConstantSet(e, new Set(properties));
|
|
15489
|
+
}
|
|
15895
15490
|
|
|
15896
15491
|
const FQIDSeparator = "";
|
|
15897
15492
|
function makeConfigFQID(id, ownScope, contextScope) {
|
|
@@ -16058,16 +15653,12 @@ class ParsingContext {
|
|
|
16058
15653
|
this.iconImageUseTheme = iconImageUseTheme;
|
|
16059
15654
|
}
|
|
16060
15655
|
get key() {
|
|
16061
|
-
|
|
16062
|
-
|
|
16063
|
-
|
|
16064
|
-
|
|
16065
|
-
const part = path[i];
|
|
16066
|
-
key += typeof part === "string" ? `['${part}']` : `[${part}]`;
|
|
16067
|
-
}
|
|
16068
|
-
this._key = key;
|
|
15656
|
+
let key = "";
|
|
15657
|
+
for (let i = 0; i < this.path.length; i++) {
|
|
15658
|
+
const part = this.path[i];
|
|
15659
|
+
key += typeof part === "string" ? `['${part}']` : `[${part}]`;
|
|
16069
15660
|
}
|
|
16070
|
-
return
|
|
15661
|
+
return key;
|
|
16071
15662
|
}
|
|
16072
15663
|
/**
|
|
16073
15664
|
* @param expr the JSON expression to parse
|
|
@@ -16078,7 +15669,17 @@ class ParsingContext {
|
|
|
16078
15669
|
*/
|
|
16079
15670
|
parse(expr, index, expectedType, bindings, options = {}) {
|
|
16080
15671
|
if (index || expectedType) {
|
|
16081
|
-
|
|
15672
|
+
const prevExpectedType = this.expectedType;
|
|
15673
|
+
const prevScope = this.scope;
|
|
15674
|
+
if (bindings) this.scope = this.scope.concat(bindings);
|
|
15675
|
+
this.expectedType = expectedType || null;
|
|
15676
|
+
const pushed = typeof index === "number";
|
|
15677
|
+
if (pushed) this.path.push(index);
|
|
15678
|
+
const result = this._parse(expr, options);
|
|
15679
|
+
if (pushed) this.path.pop();
|
|
15680
|
+
this.expectedType = prevExpectedType;
|
|
15681
|
+
this.scope = prevScope;
|
|
15682
|
+
return result;
|
|
16082
15683
|
}
|
|
16083
15684
|
return this._parse(expr, options);
|
|
16084
15685
|
}
|
|
@@ -16091,21 +15692,23 @@ class ParsingContext {
|
|
|
16091
15692
|
* @private
|
|
16092
15693
|
*/
|
|
16093
15694
|
parseObjectValue(expr, index, key, expectedType, bindings, options = {}) {
|
|
16094
|
-
|
|
15695
|
+
const prevExpectedType = this.expectedType;
|
|
15696
|
+
const prevScope = this.scope;
|
|
15697
|
+
if (bindings) this.scope = this.scope.concat(bindings);
|
|
15698
|
+
this.expectedType = expectedType || null;
|
|
15699
|
+
this.path.push(index);
|
|
15700
|
+
this.path.push(key);
|
|
15701
|
+
const result = this._parse(expr, options);
|
|
15702
|
+
this.path.pop();
|
|
15703
|
+
this.path.pop();
|
|
15704
|
+
this.expectedType = prevExpectedType;
|
|
15705
|
+
this.scope = prevScope;
|
|
15706
|
+
return result;
|
|
16095
15707
|
}
|
|
16096
15708
|
_parse(expr, options) {
|
|
16097
15709
|
if (expr === null || typeof expr === "string" || typeof expr === "boolean" || typeof expr === "number") {
|
|
16098
15710
|
expr = ["literal", expr];
|
|
16099
15711
|
}
|
|
16100
|
-
function annotate(parsed, type, typeAnnotation) {
|
|
16101
|
-
if (typeAnnotation === "assert") {
|
|
16102
|
-
return new Assertion(type, [parsed]);
|
|
16103
|
-
} else if (typeAnnotation === "coerce") {
|
|
16104
|
-
return new Coercion(type, [parsed]);
|
|
16105
|
-
} else {
|
|
16106
|
-
return parsed;
|
|
16107
|
-
}
|
|
16108
|
-
}
|
|
16109
15712
|
if (Array.isArray(expr)) {
|
|
16110
15713
|
if (expr.length === 0) {
|
|
16111
15714
|
return this.error(`Expected an array with at least one element. If you wanted a literal array, use ["literal", []].`);
|
|
@@ -16154,9 +15757,10 @@ class ParsingContext {
|
|
|
16154
15757
|
* @private
|
|
16155
15758
|
*/
|
|
16156
15759
|
concat(index, key, expectedType, bindings) {
|
|
16157
|
-
let path = typeof index === "number" ? this.path.concat(index) : this.path;
|
|
16158
|
-
path = typeof key === "string" ? path.concat(key) : path;
|
|
16159
15760
|
const scope = bindings ? this.scope.concat(bindings) : this.scope;
|
|
15761
|
+
const path = this.path.slice();
|
|
15762
|
+
if (typeof index === "number") path.push(index);
|
|
15763
|
+
if (typeof key === "string") path.push(key);
|
|
16160
15764
|
return new ParsingContext(
|
|
16161
15765
|
this.registry,
|
|
16162
15766
|
path,
|
|
@@ -16168,6 +15772,24 @@ class ParsingContext {
|
|
|
16168
15772
|
this.iconImageUseTheme
|
|
16169
15773
|
);
|
|
16170
15774
|
}
|
|
15775
|
+
/**
|
|
15776
|
+
* Returns a fresh context that shares the same path position as this one
|
|
15777
|
+
* but has an empty errors array. Used by CompoundExpression to probe
|
|
15778
|
+
* overload signatures without polluting the parent errors list.
|
|
15779
|
+
* @private
|
|
15780
|
+
*/
|
|
15781
|
+
_forkForSignature() {
|
|
15782
|
+
return new ParsingContext(
|
|
15783
|
+
this.registry,
|
|
15784
|
+
this.path.slice(),
|
|
15785
|
+
null,
|
|
15786
|
+
this.scope,
|
|
15787
|
+
[],
|
|
15788
|
+
this._scope,
|
|
15789
|
+
this.options,
|
|
15790
|
+
this.iconImageUseTheme
|
|
15791
|
+
);
|
|
15792
|
+
}
|
|
16171
15793
|
/**
|
|
16172
15794
|
* Push a parsing (or type checking) error into the `this.errors`
|
|
16173
15795
|
* @param error The message
|
|
@@ -16189,6 +15811,30 @@ class ParsingContext {
|
|
|
16189
15811
|
return error;
|
|
16190
15812
|
}
|
|
16191
15813
|
}
|
|
15814
|
+
const CONSTANT_FOLD_EXCLUDED_GLOBALS = /* @__PURE__ */ new Set([
|
|
15815
|
+
"zoom",
|
|
15816
|
+
"heatmap-density",
|
|
15817
|
+
"worldview",
|
|
15818
|
+
"line-progress",
|
|
15819
|
+
"raster-value",
|
|
15820
|
+
"sky-radial-progress",
|
|
15821
|
+
"accumulated",
|
|
15822
|
+
"is-supported-script",
|
|
15823
|
+
"pitch",
|
|
15824
|
+
"distance-from-center",
|
|
15825
|
+
"measure-light",
|
|
15826
|
+
"raster-particle-speed",
|
|
15827
|
+
"is-active-floor"
|
|
15828
|
+
]);
|
|
15829
|
+
function annotate(parsed, type, typeAnnotation) {
|
|
15830
|
+
if (typeAnnotation === "assert") {
|
|
15831
|
+
return new Assertion(type, [parsed]);
|
|
15832
|
+
} else if (typeAnnotation === "coerce") {
|
|
15833
|
+
return new Coercion(type, [parsed]);
|
|
15834
|
+
} else {
|
|
15835
|
+
return parsed;
|
|
15836
|
+
}
|
|
15837
|
+
}
|
|
16192
15838
|
function isConstant(expression) {
|
|
16193
15839
|
if (expression instanceof Var) {
|
|
16194
15840
|
return isConstant(expression.boundExpression);
|
|
@@ -16215,7 +15861,7 @@ function isConstant(expression) {
|
|
|
16215
15861
|
if (!childrenConstant) {
|
|
16216
15862
|
return false;
|
|
16217
15863
|
}
|
|
16218
|
-
return isFeatureConstant(expression) &&
|
|
15864
|
+
return isFeatureConstant(expression) && isGlobalPropertyConstantSet(expression, CONSTANT_FOLD_EXCLUDED_GLOBALS);
|
|
16219
15865
|
}
|
|
16220
15866
|
|
|
16221
15867
|
function findStopLessThanOrEqualTo(stops, input) {
|
|
@@ -16980,24 +16626,23 @@ class Match {
|
|
|
16980
16626
|
if (!Array.isArray(labels)) {
|
|
16981
16627
|
labels = [labels];
|
|
16982
16628
|
}
|
|
16983
|
-
const labelContext = context.concat(i);
|
|
16984
16629
|
if (labels.length === 0) {
|
|
16985
|
-
return
|
|
16630
|
+
return context.error("Expected at least one branch label.", i);
|
|
16986
16631
|
}
|
|
16987
16632
|
for (const label of labels) {
|
|
16988
16633
|
if (typeof label !== "number" && typeof label !== "string") {
|
|
16989
|
-
return
|
|
16634
|
+
return context.error(`Branch labels must be numbers or strings.`, i);
|
|
16990
16635
|
} else if (typeof label === "number" && Math.abs(label) > Number.MAX_SAFE_INTEGER) {
|
|
16991
|
-
return
|
|
16636
|
+
return context.error(`Branch labels must be integers no larger than ${Number.MAX_SAFE_INTEGER}.`, i);
|
|
16992
16637
|
} else if (typeof label === "number" && Math.floor(label) !== label) {
|
|
16993
|
-
return
|
|
16638
|
+
return context.error(`Numeric branch labels must be integer values.`, i);
|
|
16994
16639
|
} else if (!inputType) {
|
|
16995
16640
|
inputType = typeOf(label);
|
|
16996
|
-
} else if (
|
|
16641
|
+
} else if (context.checkSubtype(inputType, typeOf(label), i)) {
|
|
16997
16642
|
return null;
|
|
16998
16643
|
}
|
|
16999
16644
|
if (typeof cases[String(label)] !== "undefined") {
|
|
17000
|
-
return
|
|
16645
|
+
return context.error("Branch labels must be unique.", i);
|
|
17001
16646
|
}
|
|
17002
16647
|
cases[String(label)] = outputs.length;
|
|
17003
16648
|
}
|
|
@@ -17010,7 +16655,7 @@ class Match {
|
|
|
17010
16655
|
if (!input) return null;
|
|
17011
16656
|
const otherwise = context.parse(args.at(-1), args.length - 1, outputType);
|
|
17012
16657
|
if (!otherwise) return null;
|
|
17013
|
-
if (input.type.kind !== "value" && context.
|
|
16658
|
+
if (input.type.kind !== "value" && context.checkSubtype(inputType, input.type, 1)) {
|
|
17014
16659
|
return null;
|
|
17015
16660
|
}
|
|
17016
16661
|
return new Match(inputType, outputType, input, cases, outputs, otherwise);
|
|
@@ -17268,12 +16913,12 @@ function makeComparison(op, compareBasic, compareWithCollator) {
|
|
|
17268
16913
|
let lhs = context.parse(args[1], 1, ValueType);
|
|
17269
16914
|
if (!lhs) return null;
|
|
17270
16915
|
if (!isComparableType(op2, lhs.type)) {
|
|
17271
|
-
return context.
|
|
16916
|
+
return context.error(`"${op2}" comparisons are not supported for type '${toString$1(lhs.type)}'.`, 1);
|
|
17272
16917
|
}
|
|
17273
16918
|
let rhs = context.parse(args[2], 2, ValueType);
|
|
17274
16919
|
if (!rhs) return null;
|
|
17275
16920
|
if (!isComparableType(op2, rhs.type)) {
|
|
17276
|
-
return context.
|
|
16921
|
+
return context.error(`"${op2}" comparisons are not supported for type '${toString$1(rhs.type)}'.`, 2);
|
|
17277
16922
|
}
|
|
17278
16923
|
if (lhs.type.kind !== rhs.type.kind && lhs.type.kind !== "value" && rhs.type.kind !== "value") {
|
|
17279
16924
|
return context.error(`Cannot compare types '${toString$1(lhs.type)}' and '${toString$1(rhs.type)}'.`);
|
|
@@ -18228,7 +17873,7 @@ function createFunction(parameters, propertySpec) {
|
|
|
18228
17873
|
const zoomDependent = zoomAndFeatureDependent || !featureDependent;
|
|
18229
17874
|
const type = parameters.type || (supportsInterpolation(propertySpec) ? "exponential" : "interval");
|
|
18230
17875
|
if (isColor) {
|
|
18231
|
-
parameters =
|
|
17876
|
+
parameters = { ...parameters };
|
|
18232
17877
|
if (parameters.stops) {
|
|
18233
17878
|
parameters.stops = parameters.stops.map((stop) => {
|
|
18234
17879
|
return [stop[0], Color.parse(stop[1])];
|
|
@@ -19887,11 +19532,12 @@ function validateImport(options) {
|
|
|
19887
19532
|
value: value.__line__,
|
|
19888
19533
|
enumerable: false
|
|
19889
19534
|
});
|
|
19890
|
-
let errors = validateObject(
|
|
19535
|
+
let errors = validateObject({
|
|
19536
|
+
...options,
|
|
19891
19537
|
value: importSpec,
|
|
19892
19538
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
19893
19539
|
valueSpec: styleSpec.import
|
|
19894
|
-
})
|
|
19540
|
+
});
|
|
19895
19541
|
if (unbundle(importSpec.id) === "") {
|
|
19896
19542
|
const key2 = `${options.key}.id`;
|
|
19897
19543
|
errors.push(new ValidationError(key2, importSpec, `import id can't be an empty string`));
|
|
@@ -19912,7 +19558,8 @@ function validateOption(options) {
|
|
|
19912
19558
|
const optionValue = options.value;
|
|
19913
19559
|
const isArrayOption = isObject(optionValue) && unbundle(optionValue.array) === true;
|
|
19914
19560
|
const declaredType = !isArrayOption && isObject(optionValue) ? unbundle(optionValue.type) : void 0;
|
|
19915
|
-
return validateObject(
|
|
19561
|
+
return validateObject({
|
|
19562
|
+
...options,
|
|
19916
19563
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
19917
19564
|
valueSpec: styleSpec.option,
|
|
19918
19565
|
objectElementValidators: declaredType ? {
|
|
@@ -19920,11 +19567,9 @@ function validateOption(options) {
|
|
|
19920
19567
|
// expression (array-form). Primitive defaults keep the previous
|
|
19921
19568
|
// permissive validation, mirroring the runtime parser's narrowing
|
|
19922
19569
|
// in style.ts/parser.cpp.
|
|
19923
|
-
default: (elementOptions) => Array.isArray(elementOptions.value) ? validate(
|
|
19924
|
-
valueSpec: Object.assign({}, elementOptions.valueSpec, { type: declaredType })
|
|
19925
|
-
})) : validate(elementOptions)
|
|
19570
|
+
default: (elementOptions) => Array.isArray(elementOptions.value) ? validate({ ...elementOptions, valueSpec: { ...elementOptions.valueSpec, type: declaredType } }) : validate(elementOptions)
|
|
19926
19571
|
} : void 0
|
|
19927
|
-
})
|
|
19572
|
+
});
|
|
19928
19573
|
}
|
|
19929
19574
|
|
|
19930
19575
|
function validateArray(options) {
|
|
@@ -20313,11 +19958,12 @@ function validateEnum(options) {
|
|
|
20313
19958
|
function validateFilter(options) {
|
|
20314
19959
|
if (isExpressionFilter(deepUnbundle(options.value))) {
|
|
20315
19960
|
const layerType = options.layerType || "fill";
|
|
20316
|
-
return validateExpression(
|
|
19961
|
+
return validateExpression({
|
|
19962
|
+
...options,
|
|
20317
19963
|
expressionContext: "filter",
|
|
20318
19964
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
20319
19965
|
valueSpec: options.styleSpec[`filter_${layerType}`]
|
|
20320
|
-
})
|
|
19966
|
+
});
|
|
20321
19967
|
} else {
|
|
20322
19968
|
return validateNonExpressionFilter(options);
|
|
20323
19969
|
}
|
|
@@ -20514,8 +20160,8 @@ function validateAppearance(options) {
|
|
|
20514
20160
|
style: options.style,
|
|
20515
20161
|
styleSpec: options.styleSpec,
|
|
20516
20162
|
objectElementValidators: {
|
|
20517
|
-
condition: (options2) => validateCondition(
|
|
20518
|
-
properties: (options2) => validateProperties(
|
|
20163
|
+
condition: (options2) => validateCondition({ ...options2 }),
|
|
20164
|
+
properties: (options2) => validateProperties({ layer, layerType, ...options2 })
|
|
20519
20165
|
}
|
|
20520
20166
|
});
|
|
20521
20167
|
if (name !== "hidden" && condition === void 0) {
|
|
@@ -20535,15 +20181,15 @@ function validateProperties(options) {
|
|
|
20535
20181
|
errors.push(new ValidationError(options.key, propertyKey, `unknown property "${propertyKey}" for layer type "${layerType}"`));
|
|
20536
20182
|
continue;
|
|
20537
20183
|
}
|
|
20538
|
-
const propertyValidationOptions =
|
|
20184
|
+
const propertyValidationOptions = {
|
|
20185
|
+
...options,
|
|
20539
20186
|
key: `${options.key}.${propertyKey}`,
|
|
20540
|
-
object: properties,
|
|
20541
20187
|
objectKey: propertyKey,
|
|
20542
20188
|
layer,
|
|
20543
20189
|
layerType,
|
|
20544
20190
|
value: properties[propertyKey],
|
|
20545
20191
|
valueSpec: propertyType === "paint" ? paintProperties[propertyKey] : layoutProperties[propertyKey]
|
|
20546
|
-
}
|
|
20192
|
+
};
|
|
20547
20193
|
errors.push(...validateProperty(propertyValidationOptions, propertyType));
|
|
20548
20194
|
}
|
|
20549
20195
|
return errors;
|
|
@@ -20665,7 +20311,7 @@ function validateLayer(options) {
|
|
|
20665
20311
|
});
|
|
20666
20312
|
},
|
|
20667
20313
|
filter(options2) {
|
|
20668
|
-
return validateFilter(
|
|
20314
|
+
return validateFilter({ layerType: type, ...options2 });
|
|
20669
20315
|
},
|
|
20670
20316
|
layout(options2) {
|
|
20671
20317
|
return validateObject({
|
|
@@ -20677,7 +20323,7 @@ function validateLayer(options) {
|
|
|
20677
20323
|
styleSpec: options2.styleSpec,
|
|
20678
20324
|
objectElementValidators: {
|
|
20679
20325
|
"*"(options3) {
|
|
20680
|
-
return validateLayoutProperty(
|
|
20326
|
+
return validateLayoutProperty({ layerType: type, ...options3 });
|
|
20681
20327
|
}
|
|
20682
20328
|
}
|
|
20683
20329
|
});
|
|
@@ -20692,7 +20338,7 @@ function validateLayer(options) {
|
|
|
20692
20338
|
styleSpec: options2.styleSpec,
|
|
20693
20339
|
objectElementValidators: {
|
|
20694
20340
|
"*"(options3) {
|
|
20695
|
-
return validatePaintProperty(
|
|
20341
|
+
return validatePaintProperty({ layerType: type, layer, ...options3 });
|
|
20696
20342
|
}
|
|
20697
20343
|
}
|
|
20698
20344
|
});
|
|
@@ -20704,7 +20350,7 @@ function validateLayer(options) {
|
|
|
20704
20350
|
valueSpec: options2.valueSpec,
|
|
20705
20351
|
style: options2.style,
|
|
20706
20352
|
styleSpec: options2.styleSpec,
|
|
20707
|
-
arrayElementValidator: (options3) => validateAppearance(
|
|
20353
|
+
arrayElementValidator: (options3) => validateAppearance({ layerType: type, layer, ...options3 })
|
|
20708
20354
|
});
|
|
20709
20355
|
const appearances = Array.isArray(options2.value) ? options2.value : [];
|
|
20710
20356
|
const dedupedNames = /* @__PURE__ */ new Set();
|
|
@@ -21266,10 +20912,11 @@ function validate(options, arrayAsExpression = false) {
|
|
|
21266
20912
|
}
|
|
21267
20913
|
return errors2;
|
|
21268
20914
|
}
|
|
21269
|
-
const errors = validateObject(
|
|
20915
|
+
const errors = validateObject({
|
|
20916
|
+
...options,
|
|
21270
20917
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
21271
20918
|
valueSpec: valueSpec.type ? styleSpec[valueSpec.type] : valueSpec
|
|
21272
|
-
})
|
|
20919
|
+
});
|
|
21273
20920
|
return errors;
|
|
21274
20921
|
}
|
|
21275
20922
|
|
|
@@ -21345,12 +20992,11 @@ function validateStyle$2(style, styleSpec = v8, options = {}) {
|
|
|
21345
20992
|
key: options.key || "",
|
|
21346
20993
|
value: style,
|
|
21347
20994
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
21348
|
-
valueSpec:
|
|
21349
|
-
|
|
21350
|
-
styleSpec.$root,
|
|
20995
|
+
valueSpec: {
|
|
20996
|
+
...styleSpec.$root,
|
|
21351
20997
|
// Skip validation of the root properties that are not defined in the style spec (e.g. 'owner').
|
|
21352
|
-
|
|
21353
|
-
|
|
20998
|
+
"*": { type: "*" }
|
|
20999
|
+
},
|
|
21354
21000
|
styleSpec,
|
|
21355
21001
|
style,
|
|
21356
21002
|
objectElementValidators: {
|