@mapbox/mapbox-gl-style-spec 13.12.0 → 13.13.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/CHANGELOG.md +13 -0
- package/dist/index.es.js +1201 -297
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1201 -297
- package/dist/index.js.map +1 -1
- package/expression/compound_expression.js +5 -5
- package/expression/definitions/assertion.js +3 -4
- package/expression/definitions/at.js +3 -3
- package/expression/definitions/case.js +3 -6
- package/expression/definitions/coalesce.js +3 -4
- package/expression/definitions/coercion.js +3 -4
- package/expression/definitions/collator.js +5 -5
- package/expression/definitions/comparison.js +3 -3
- package/expression/definitions/format.js +3 -3
- package/expression/definitions/format_section_override.js +3 -4
- package/expression/definitions/image.js +6 -8
- package/expression/definitions/in.js +4 -4
- package/expression/definitions/index.js +4 -2
- package/expression/definitions/interpolate.js +3 -4
- package/expression/definitions/length.js +3 -3
- package/expression/definitions/let.js +3 -3
- package/expression/definitions/literal.js +2 -2
- package/expression/definitions/match.js +3 -6
- package/expression/definitions/number_format.js +3 -3
- package/expression/definitions/step.js +3 -4
- package/expression/definitions/var.js +2 -2
- package/expression/definitions/within.js +297 -0
- package/expression/evaluation_context.js +12 -1
- package/expression/expression.js +3 -5
- package/expression/index.js +24 -19
- package/expression/is_constant.js +5 -1
- package/expression/parsing_context.js +3 -0
- package/expression/scope.js +1 -1
- package/expression/types/resolved_image.js +2 -1
- package/feature_filter/convert.js +1 -1
- package/feature_filter/index.js +10 -5
- package/flow-typed/vector-tile.js +2 -2
- package/package.json +2 -1
- package/reference/v8.json +10 -1
- package/style-spec.js +1 -1
- package/types.js +2 -2
- package/validate/validate_expression.js +1 -1
- package/visit.js +2 -2
package/dist/index.es.js
CHANGED
|
@@ -1000,7 +1000,7 @@ var layout_symbol = {
|
|
|
1000
1000
|
},
|
|
1001
1001
|
"symbol-sort-key": {
|
|
1002
1002
|
type: "number",
|
|
1003
|
-
doc: "Sorts features in ascending order based on this value. Features with
|
|
1003
|
+
doc: "Sorts features in ascending order based on this value. Features with lower sort keys are drawn and placed first. When `icon-allow-overlap` or `text-allow-overlap` is `false`, features with a lower sort key will have priority during placement. When `icon-allow-overlap` or `text-allow-overlap` is set to `true`, features with a higher sort key will overlap over features with a lower sort key.",
|
|
1004
1004
|
"sdk-support": {
|
|
1005
1005
|
"basic functionality": {
|
|
1006
1006
|
js: "0.53.0",
|
|
@@ -3367,6 +3367,15 @@ var expression_name = {
|
|
|
3367
3367
|
}
|
|
3368
3368
|
}
|
|
3369
3369
|
},
|
|
3370
|
+
within: {
|
|
3371
|
+
doc: "Returns `true` if the feature being evaluated is inside the pre-defined geometry boundary, `false` otherwise. The expression has one argument which must be a valid GeoJSON Polygon/Multi-Polygon object. The expression only evaluates on `Point` or `LineString` feature. For `Point` feature, The expression will return false if any point of the feature is on the boundary or outside the boundary. For `LineString` feature, the expression will return false if the line is fully outside the boundary, or the line is partially intersecting the boundary, which means either part of the line is outside of the boundary, or end point of the line lies on the boundary.",
|
|
3372
|
+
group: "Decision",
|
|
3373
|
+
"sdk-support": {
|
|
3374
|
+
"basic functionality": {
|
|
3375
|
+
js: "1.9.0"
|
|
3376
|
+
}
|
|
3377
|
+
}
|
|
3378
|
+
},
|
|
3370
3379
|
"is-supported-script": {
|
|
3371
3380
|
doc: "Returns `true` if the input string is expected to render legibly. Returns `false` if the input string contains sections that cannot be rendered without potential loss of meaning (e.g. Indic scripts that require complex text shaping, or right-to-left scripts if the the `mapbox-gl-rtl-text` plugin is not in use in Mapbox GL JS).",
|
|
3372
3381
|
group: "String",
|
|
@@ -8014,6 +8023,9 @@ ResolvedImage.prototype.toString = function toString() {
|
|
|
8014
8023
|
return this.name;
|
|
8015
8024
|
};
|
|
8016
8025
|
ResolvedImage.fromString = function fromString(name) {
|
|
8026
|
+
if (!name) {
|
|
8027
|
+
return null;
|
|
8028
|
+
}
|
|
8017
8029
|
return new ResolvedImage({
|
|
8018
8030
|
name: name,
|
|
8019
8031
|
available: false
|
|
@@ -8160,8 +8172,8 @@ Literal.prototype.evaluate = function evaluate() {
|
|
|
8160
8172
|
};
|
|
8161
8173
|
Literal.prototype.eachChild = function eachChild() {
|
|
8162
8174
|
};
|
|
8163
|
-
Literal.prototype.
|
|
8164
|
-
return
|
|
8175
|
+
Literal.prototype.outputDefined = function outputDefined() {
|
|
8176
|
+
return true;
|
|
8165
8177
|
};
|
|
8166
8178
|
Literal.prototype.serialize = function serialize() {
|
|
8167
8179
|
if (this.type.kind === 'array' || this.type.kind === 'object') {
|
|
@@ -8252,11 +8264,10 @@ Assertion.prototype.evaluate = function evaluate(ctx) {
|
|
|
8252
8264
|
Assertion.prototype.eachChild = function eachChild(fn) {
|
|
8253
8265
|
this.args.forEach(fn);
|
|
8254
8266
|
};
|
|
8255
|
-
Assertion.prototype.
|
|
8256
|
-
|
|
8257
|
-
|
|
8258
|
-
|
|
8259
|
-
}));
|
|
8267
|
+
Assertion.prototype.outputDefined = function outputDefined() {
|
|
8268
|
+
return this.args.every(function (arg) {
|
|
8269
|
+
return arg.outputDefined();
|
|
8270
|
+
});
|
|
8260
8271
|
};
|
|
8261
8272
|
Assertion.prototype.serialize = function serialize() {
|
|
8262
8273
|
var type = this.type;
|
|
@@ -8364,8 +8375,8 @@ FormatExpression.prototype.eachChild = function eachChild(fn) {
|
|
|
8364
8375
|
}
|
|
8365
8376
|
}
|
|
8366
8377
|
};
|
|
8367
|
-
FormatExpression.prototype.
|
|
8368
|
-
return
|
|
8378
|
+
FormatExpression.prototype.outputDefined = function outputDefined() {
|
|
8379
|
+
return false;
|
|
8369
8380
|
};
|
|
8370
8381
|
FormatExpression.prototype.serialize = function serialize() {
|
|
8371
8382
|
var serialized = ['format'];
|
|
@@ -8403,20 +8414,17 @@ ImageExpression.parse = function parse(args, context) {
|
|
|
8403
8414
|
};
|
|
8404
8415
|
ImageExpression.prototype.evaluate = function evaluate(ctx) {
|
|
8405
8416
|
var evaluatedImageName = this.input.evaluate(ctx);
|
|
8406
|
-
var
|
|
8407
|
-
if (
|
|
8408
|
-
available =
|
|
8417
|
+
var value = ResolvedImage.fromString(evaluatedImageName);
|
|
8418
|
+
if (value && ctx.availableImages) {
|
|
8419
|
+
value.available = ctx.availableImages.indexOf(evaluatedImageName) > -1;
|
|
8409
8420
|
}
|
|
8410
|
-
return
|
|
8411
|
-
name: evaluatedImageName,
|
|
8412
|
-
available: available
|
|
8413
|
-
});
|
|
8421
|
+
return value;
|
|
8414
8422
|
};
|
|
8415
8423
|
ImageExpression.prototype.eachChild = function eachChild(fn) {
|
|
8416
8424
|
fn(this.input);
|
|
8417
8425
|
};
|
|
8418
|
-
ImageExpression.prototype.
|
|
8419
|
-
return
|
|
8426
|
+
ImageExpression.prototype.outputDefined = function outputDefined() {
|
|
8427
|
+
return false;
|
|
8420
8428
|
};
|
|
8421
8429
|
ImageExpression.prototype.serialize = function serialize() {
|
|
8422
8430
|
return [
|
|
@@ -8509,11 +8517,10 @@ Coercion.prototype.evaluate = function evaluate(ctx) {
|
|
|
8509
8517
|
Coercion.prototype.eachChild = function eachChild(fn) {
|
|
8510
8518
|
this.args.forEach(fn);
|
|
8511
8519
|
};
|
|
8512
|
-
Coercion.prototype.
|
|
8513
|
-
|
|
8514
|
-
|
|
8515
|
-
|
|
8516
|
-
}));
|
|
8520
|
+
Coercion.prototype.outputDefined = function outputDefined() {
|
|
8521
|
+
return this.args.every(function (arg) {
|
|
8522
|
+
return arg.outputDefined();
|
|
8523
|
+
});
|
|
8517
8524
|
};
|
|
8518
8525
|
Coercion.prototype.serialize = function serialize() {
|
|
8519
8526
|
if (this.type.kind === 'formatted') {
|
|
@@ -8547,6 +8554,7 @@ var EvaluationContext = function EvaluationContext() {
|
|
|
8547
8554
|
this.formattedSection = null;
|
|
8548
8555
|
this._parseColorCache = {};
|
|
8549
8556
|
this.availableImages = null;
|
|
8557
|
+
this.canonical = null;
|
|
8550
8558
|
};
|
|
8551
8559
|
EvaluationContext.prototype.id = function id() {
|
|
8552
8560
|
return this.feature && 'id' in this.feature ? this.feature.id : null;
|
|
@@ -8554,6 +8562,12 @@ EvaluationContext.prototype.id = function id() {
|
|
|
8554
8562
|
EvaluationContext.prototype.geometryType = function geometryType() {
|
|
8555
8563
|
return this.feature ? typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : this.feature.type : null;
|
|
8556
8564
|
};
|
|
8565
|
+
EvaluationContext.prototype.geometry = function geometry() {
|
|
8566
|
+
return this.feature && 'geometry' in this.feature ? this.feature.geometry : null;
|
|
8567
|
+
};
|
|
8568
|
+
EvaluationContext.prototype.canonicalID = function canonicalID() {
|
|
8569
|
+
return this.canonical;
|
|
8570
|
+
};
|
|
8557
8571
|
EvaluationContext.prototype.properties = function properties() {
|
|
8558
8572
|
return this.feature && this.feature.properties || {};
|
|
8559
8573
|
};
|
|
@@ -8577,8 +8591,8 @@ CompoundExpression.prototype.evaluate = function evaluate(ctx) {
|
|
|
8577
8591
|
CompoundExpression.prototype.eachChild = function eachChild(fn) {
|
|
8578
8592
|
this.args.forEach(fn);
|
|
8579
8593
|
};
|
|
8580
|
-
CompoundExpression.prototype.
|
|
8581
|
-
return
|
|
8594
|
+
CompoundExpression.prototype.outputDefined = function outputDefined() {
|
|
8595
|
+
return false;
|
|
8582
8596
|
};
|
|
8583
8597
|
CompoundExpression.prototype.serialize = function serialize() {
|
|
8584
8598
|
return [this.name].concat(this.args.map(function (arg) {
|
|
@@ -8712,8 +8726,8 @@ CollatorExpression.prototype.eachChild = function eachChild(fn) {
|
|
|
8712
8726
|
fn(this.locale);
|
|
8713
8727
|
}
|
|
8714
8728
|
};
|
|
8715
|
-
CollatorExpression.prototype.
|
|
8716
|
-
return
|
|
8729
|
+
CollatorExpression.prototype.outputDefined = function outputDefined() {
|
|
8730
|
+
return false;
|
|
8717
8731
|
};
|
|
8718
8732
|
CollatorExpression.prototype.serialize = function serialize() {
|
|
8719
8733
|
var options = {};
|
|
@@ -8728,94 +8742,1119 @@ CollatorExpression.prototype.serialize = function serialize() {
|
|
|
8728
8742
|
];
|
|
8729
8743
|
};
|
|
8730
8744
|
|
|
8731
|
-
|
|
8732
|
-
|
|
8733
|
-
|
|
8734
|
-
|
|
8735
|
-
|
|
8736
|
-
|
|
8737
|
-
|
|
8738
|
-
|
|
8739
|
-
|
|
8740
|
-
|
|
8741
|
-
|
|
8745
|
+
/*
|
|
8746
|
+
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
|
|
8747
|
+
*
|
|
8748
|
+
* Redistribution and use in source and binary forms, with or without
|
|
8749
|
+
* modification, are permitted provided that the following conditions
|
|
8750
|
+
* are met:
|
|
8751
|
+
* 1. Redistributions of source code must retain the above copyright
|
|
8752
|
+
* notice, this list of conditions and the following disclaimer.
|
|
8753
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
|
8754
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
8755
|
+
* documentation and/or other materials provided with the distribution.
|
|
8756
|
+
*
|
|
8757
|
+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
|
8758
|
+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
8759
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
8760
|
+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
|
8761
|
+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
8762
|
+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
8763
|
+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
8764
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
8765
|
+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
8766
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
8767
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
8768
|
+
*
|
|
8769
|
+
* Ported from Webkit
|
|
8770
|
+
* http://svn.webkit.org/repository/webkit/trunk/Source/WebCore/platform/graphics/UnitBezier.h
|
|
8771
|
+
*/
|
|
8772
|
+
|
|
8773
|
+
var unitbezier = UnitBezier;
|
|
8774
|
+
|
|
8775
|
+
function UnitBezier(p1x, p1y, p2x, p2y) {
|
|
8776
|
+
// Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1).
|
|
8777
|
+
this.cx = 3.0 * p1x;
|
|
8778
|
+
this.bx = 3.0 * (p2x - p1x) - this.cx;
|
|
8779
|
+
this.ax = 1.0 - this.cx - this.bx;
|
|
8780
|
+
|
|
8781
|
+
this.cy = 3.0 * p1y;
|
|
8782
|
+
this.by = 3.0 * (p2y - p1y) - this.cy;
|
|
8783
|
+
this.ay = 1.0 - this.cy - this.by;
|
|
8784
|
+
|
|
8785
|
+
this.p1x = p1x;
|
|
8786
|
+
this.p1y = p2y;
|
|
8787
|
+
this.p2x = p2x;
|
|
8788
|
+
this.p2y = p2y;
|
|
8789
|
+
}
|
|
8790
|
+
|
|
8791
|
+
UnitBezier.prototype.sampleCurveX = function(t) {
|
|
8792
|
+
// `ax t^3 + bx t^2 + cx t' expanded using Horner's rule.
|
|
8793
|
+
return ((this.ax * t + this.bx) * t + this.cx) * t;
|
|
8794
|
+
};
|
|
8795
|
+
|
|
8796
|
+
UnitBezier.prototype.sampleCurveY = function(t) {
|
|
8797
|
+
return ((this.ay * t + this.by) * t + this.cy) * t;
|
|
8798
|
+
};
|
|
8799
|
+
|
|
8800
|
+
UnitBezier.prototype.sampleCurveDerivativeX = function(t) {
|
|
8801
|
+
return (3.0 * this.ax * t + 2.0 * this.bx) * t + this.cx;
|
|
8802
|
+
};
|
|
8803
|
+
|
|
8804
|
+
UnitBezier.prototype.solveCurveX = function(x, epsilon) {
|
|
8805
|
+
if (typeof epsilon === 'undefined') { epsilon = 1e-6; }
|
|
8806
|
+
|
|
8807
|
+
var t0, t1, t2, x2, i;
|
|
8808
|
+
|
|
8809
|
+
// First try a few iterations of Newton's method -- normally very fast.
|
|
8810
|
+
for (t2 = x, i = 0; i < 8; i++) {
|
|
8811
|
+
|
|
8812
|
+
x2 = this.sampleCurveX(t2) - x;
|
|
8813
|
+
if (Math.abs(x2) < epsilon) { return t2; }
|
|
8814
|
+
|
|
8815
|
+
var d2 = this.sampleCurveDerivativeX(t2);
|
|
8816
|
+
if (Math.abs(d2) < 1e-6) { break; }
|
|
8817
|
+
|
|
8818
|
+
t2 = t2 - x2 / d2;
|
|
8819
|
+
}
|
|
8820
|
+
|
|
8821
|
+
// Fall back to the bisection method for reliability.
|
|
8822
|
+
t0 = 0.0;
|
|
8823
|
+
t1 = 1.0;
|
|
8824
|
+
t2 = x;
|
|
8825
|
+
|
|
8826
|
+
if (t2 < t0) { return t0; }
|
|
8827
|
+
if (t2 > t1) { return t1; }
|
|
8828
|
+
|
|
8829
|
+
while (t0 < t1) {
|
|
8830
|
+
|
|
8831
|
+
x2 = this.sampleCurveX(t2);
|
|
8832
|
+
if (Math.abs(x2 - x) < epsilon) { return t2; }
|
|
8833
|
+
|
|
8834
|
+
if (x > x2) {
|
|
8835
|
+
t0 = t2;
|
|
8836
|
+
} else {
|
|
8837
|
+
t1 = t2;
|
|
8838
|
+
}
|
|
8839
|
+
|
|
8840
|
+
t2 = (t1 - t0) * 0.5 + t0;
|
|
8841
|
+
}
|
|
8842
|
+
|
|
8843
|
+
// Failure.
|
|
8844
|
+
return t2;
|
|
8845
|
+
};
|
|
8846
|
+
|
|
8847
|
+
UnitBezier.prototype.solve = function(x, epsilon) {
|
|
8848
|
+
return this.sampleCurveY(this.solveCurveX(x, epsilon));
|
|
8849
|
+
};
|
|
8850
|
+
|
|
8851
|
+
function deepEqual(a, b) {
|
|
8852
|
+
if (Array.isArray(a)) {
|
|
8853
|
+
if (!Array.isArray(b) || a.length !== b.length) {
|
|
8742
8854
|
return false;
|
|
8743
8855
|
}
|
|
8856
|
+
for (var i = 0; i < a.length; i++) {
|
|
8857
|
+
if (!deepEqual(a[i], b[i])) {
|
|
8858
|
+
return false;
|
|
8859
|
+
}
|
|
8860
|
+
}
|
|
8861
|
+
return true;
|
|
8744
8862
|
}
|
|
8745
|
-
|
|
8746
|
-
|
|
8747
|
-
|
|
8748
|
-
result = false;
|
|
8863
|
+
if (typeof a === 'object' && a !== null && b !== null) {
|
|
8864
|
+
if (!(typeof b === 'object')) {
|
|
8865
|
+
return false;
|
|
8749
8866
|
}
|
|
8750
|
-
|
|
8751
|
-
|
|
8752
|
-
}
|
|
8753
|
-
function isStateConstant(e) {
|
|
8754
|
-
if (e instanceof CompoundExpression) {
|
|
8755
|
-
if (e.name === 'feature-state') {
|
|
8867
|
+
var keys = Object.keys(a);
|
|
8868
|
+
if (keys.length !== Object.keys(b).length) {
|
|
8756
8869
|
return false;
|
|
8757
8870
|
}
|
|
8758
|
-
|
|
8759
|
-
|
|
8760
|
-
|
|
8761
|
-
|
|
8762
|
-
result = false;
|
|
8871
|
+
for (var key in a) {
|
|
8872
|
+
if (!deepEqual(a[key], b[key])) {
|
|
8873
|
+
return false;
|
|
8874
|
+
}
|
|
8763
8875
|
}
|
|
8764
|
-
|
|
8765
|
-
return result;
|
|
8766
|
-
}
|
|
8767
|
-
function isGlobalPropertyConstant(e, properties) {
|
|
8768
|
-
if (e instanceof CompoundExpression && properties.indexOf(e.name) >= 0) {
|
|
8769
|
-
return false;
|
|
8876
|
+
return true;
|
|
8770
8877
|
}
|
|
8771
|
-
|
|
8772
|
-
e.eachChild(function (arg) {
|
|
8773
|
-
if (result && !isGlobalPropertyConstant(arg, properties)) {
|
|
8774
|
-
result = false;
|
|
8775
|
-
}
|
|
8776
|
-
});
|
|
8777
|
-
return result;
|
|
8878
|
+
return a === b;
|
|
8778
8879
|
}
|
|
8779
8880
|
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
|
|
8785
|
-
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
|
|
8791
|
-
|
|
8881
|
+
//
|
|
8882
|
+
|
|
8883
|
+
/**
|
|
8884
|
+
* constrain n to the given range, excluding the minimum, via modular arithmetic
|
|
8885
|
+
*
|
|
8886
|
+
* @param n value
|
|
8887
|
+
* @param min the minimum value to be returned, exclusive
|
|
8888
|
+
* @param max the maximum value to be returned, inclusive
|
|
8889
|
+
* @returns constrained number
|
|
8890
|
+
* @private
|
|
8891
|
+
*/
|
|
8892
|
+
function wrap(n , min , max ) {
|
|
8893
|
+
var d = max - min;
|
|
8894
|
+
var w = ((n - min) % d + d) % d + min;
|
|
8895
|
+
return (w === min) ? max : w;
|
|
8896
|
+
}
|
|
8897
|
+
|
|
8898
|
+
//
|
|
8899
|
+
|
|
8900
|
+
|
|
8901
|
+
|
|
8902
|
+
/**
|
|
8903
|
+
* A `LngLatBounds` object represents a geographical bounding box,
|
|
8904
|
+
* defined by its southwest and northeast points in longitude and latitude.
|
|
8905
|
+
*
|
|
8906
|
+
* If no arguments are provided to the constructor, a `null` bounding box is created.
|
|
8907
|
+
*
|
|
8908
|
+
* Note that any Mapbox GL method that accepts a `LngLatBounds` object as an argument or option
|
|
8909
|
+
* can also accept an `Array` of two {@link LngLatLike} constructs and will perform an implicit conversion.
|
|
8910
|
+
* This flexible type is documented as {@link LngLatBoundsLike}.
|
|
8911
|
+
*
|
|
8912
|
+
* @param {LngLatLike} [sw] The southwest corner of the bounding box.
|
|
8913
|
+
* @param {LngLatLike} [ne] The northeast corner of the bounding box.
|
|
8914
|
+
* @example
|
|
8915
|
+
* var sw = new mapboxgl.LngLat(-73.9876, 40.7661);
|
|
8916
|
+
* var ne = new mapboxgl.LngLat(-73.9397, 40.8002);
|
|
8917
|
+
* var llb = new mapboxgl.LngLatBounds(sw, ne);
|
|
8918
|
+
*/
|
|
8919
|
+
var LngLatBounds = function LngLatBounds(sw , ne ) {
|
|
8920
|
+
if (!sw) ; else if (ne) {
|
|
8921
|
+
this.setSouthWest(sw).setNorthEast(ne);
|
|
8922
|
+
} else if (sw.length === 4) {
|
|
8923
|
+
this.setSouthWest([sw[0], sw[1]]).setNorthEast([sw[2], sw[3]]);
|
|
8924
|
+
} else {
|
|
8925
|
+
this.setSouthWest(sw[0]).setNorthEast(sw[1]);
|
|
8792
8926
|
}
|
|
8793
|
-
return new Var(name, context.scope.get(name));
|
|
8794
8927
|
};
|
|
8795
|
-
|
|
8796
|
-
|
|
8928
|
+
|
|
8929
|
+
/**
|
|
8930
|
+
* Set the northeast corner of the bounding box
|
|
8931
|
+
*
|
|
8932
|
+
* @param {LngLatLike} ne a {@link LngLatLike} object describing the northeast corner of the bounding box.
|
|
8933
|
+
* @returns {LngLatBounds} `this`
|
|
8934
|
+
*/
|
|
8935
|
+
LngLatBounds.prototype.setNorthEast = function setNorthEast (ne ) {
|
|
8936
|
+
this._ne = ne instanceof LngLat ? new LngLat(ne.lng, ne.lat) : LngLat.convert(ne);
|
|
8937
|
+
return this;
|
|
8797
8938
|
};
|
|
8798
|
-
|
|
8939
|
+
|
|
8940
|
+
/**
|
|
8941
|
+
* Set the southwest corner of the bounding box
|
|
8942
|
+
*
|
|
8943
|
+
* @param {LngLatLike} sw a {@link LngLatLike} object describing the southwest corner of the bounding box.
|
|
8944
|
+
* @returns {LngLatBounds} `this`
|
|
8945
|
+
*/
|
|
8946
|
+
LngLatBounds.prototype.setSouthWest = function setSouthWest (sw ) {
|
|
8947
|
+
this._sw = sw instanceof LngLat ? new LngLat(sw.lng, sw.lat) : LngLat.convert(sw);
|
|
8948
|
+
return this;
|
|
8799
8949
|
};
|
|
8800
|
-
|
|
8801
|
-
|
|
8950
|
+
|
|
8951
|
+
/**
|
|
8952
|
+
* Extend the bounds to include a given LngLatLike or LngLatBoundsLike.
|
|
8953
|
+
*
|
|
8954
|
+
* @param {LngLatLike|LngLatBoundsLike} obj object to extend to
|
|
8955
|
+
* @returns {LngLatBounds} `this`
|
|
8956
|
+
*/
|
|
8957
|
+
LngLatBounds.prototype.extend = function extend (obj ) {
|
|
8958
|
+
var sw = this._sw,
|
|
8959
|
+
ne = this._ne;
|
|
8960
|
+
var sw2, ne2;
|
|
8961
|
+
|
|
8962
|
+
if (obj instanceof LngLat) {
|
|
8963
|
+
sw2 = obj;
|
|
8964
|
+
ne2 = obj;
|
|
8965
|
+
|
|
8966
|
+
} else if (obj instanceof LngLatBounds) {
|
|
8967
|
+
sw2 = obj._sw;
|
|
8968
|
+
ne2 = obj._ne;
|
|
8969
|
+
|
|
8970
|
+
if (!sw2 || !ne2) { return this; }
|
|
8971
|
+
|
|
8972
|
+
} else {
|
|
8973
|
+
if (Array.isArray(obj)) {
|
|
8974
|
+
if (obj.length === 4 || obj.every(Array.isArray)) {
|
|
8975
|
+
var lngLatBoundsObj = ((obj ) );
|
|
8976
|
+
return this.extend(LngLatBounds.convert(lngLatBoundsObj));
|
|
8977
|
+
} else {
|
|
8978
|
+
var lngLatObj = ((obj ) );
|
|
8979
|
+
return this.extend(LngLat.convert(lngLatObj));
|
|
8980
|
+
}
|
|
8981
|
+
}
|
|
8982
|
+
return this;
|
|
8983
|
+
}
|
|
8984
|
+
|
|
8985
|
+
if (!sw && !ne) {
|
|
8986
|
+
this._sw = new LngLat(sw2.lng, sw2.lat);
|
|
8987
|
+
this._ne = new LngLat(ne2.lng, ne2.lat);
|
|
8988
|
+
|
|
8989
|
+
} else {
|
|
8990
|
+
sw.lng = Math.min(sw2.lng, sw.lng);
|
|
8991
|
+
sw.lat = Math.min(sw2.lat, sw.lat);
|
|
8992
|
+
ne.lng = Math.max(ne2.lng, ne.lng);
|
|
8993
|
+
ne.lat = Math.max(ne2.lat, ne.lat);
|
|
8994
|
+
}
|
|
8995
|
+
|
|
8996
|
+
return this;
|
|
8802
8997
|
};
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
8998
|
+
|
|
8999
|
+
/**
|
|
9000
|
+
* Returns the geographical coordinate equidistant from the bounding box's corners.
|
|
9001
|
+
*
|
|
9002
|
+
* @returns {LngLat} The bounding box's center.
|
|
9003
|
+
* @example
|
|
9004
|
+
* var llb = new mapboxgl.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
|
|
9005
|
+
* llb.getCenter(); // = LngLat {lng: -73.96365, lat: 40.78315}
|
|
9006
|
+
*/
|
|
9007
|
+
LngLatBounds.prototype.getCenter = function getCenter () {
|
|
9008
|
+
return new LngLat((this._sw.lng + this._ne.lng) / 2, (this._sw.lat + this._ne.lat) / 2);
|
|
8808
9009
|
};
|
|
8809
9010
|
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8817
|
-
|
|
8818
|
-
|
|
9011
|
+
/**
|
|
9012
|
+
* Returns the southwest corner of the bounding box.
|
|
9013
|
+
*
|
|
9014
|
+
* @returns {LngLat} The southwest corner of the bounding box.
|
|
9015
|
+
*/
|
|
9016
|
+
LngLatBounds.prototype.getSouthWest = function getSouthWest () { return this._sw; };
|
|
9017
|
+
|
|
9018
|
+
/**
|
|
9019
|
+
* Returns the northeast corner of the bounding box.
|
|
9020
|
+
*
|
|
9021
|
+
* @returns {LngLat} The northeast corner of the bounding box.
|
|
9022
|
+
*/
|
|
9023
|
+
LngLatBounds.prototype.getNorthEast = function getNorthEast () { return this._ne; };
|
|
9024
|
+
|
|
9025
|
+
/**
|
|
9026
|
+
* Returns the northwest corner of the bounding box.
|
|
9027
|
+
*
|
|
9028
|
+
* @returns {LngLat} The northwest corner of the bounding box.
|
|
9029
|
+
*/
|
|
9030
|
+
LngLatBounds.prototype.getNorthWest = function getNorthWest () { return new LngLat(this.getWest(), this.getNorth()); };
|
|
9031
|
+
|
|
9032
|
+
/**
|
|
9033
|
+
* Returns the southeast corner of the bounding box.
|
|
9034
|
+
*
|
|
9035
|
+
* @returns {LngLat} The southeast corner of the bounding box.
|
|
9036
|
+
*/
|
|
9037
|
+
LngLatBounds.prototype.getSouthEast = function getSouthEast () { return new LngLat(this.getEast(), this.getSouth()); };
|
|
9038
|
+
|
|
9039
|
+
/**
|
|
9040
|
+
* Returns the west edge of the bounding box.
|
|
9041
|
+
*
|
|
9042
|
+
* @returns {number} The west edge of the bounding box.
|
|
9043
|
+
*/
|
|
9044
|
+
LngLatBounds.prototype.getWest = function getWest () { return this._sw.lng; };
|
|
9045
|
+
|
|
9046
|
+
/**
|
|
9047
|
+
* Returns the south edge of the bounding box.
|
|
9048
|
+
*
|
|
9049
|
+
* @returns {number} The south edge of the bounding box.
|
|
9050
|
+
*/
|
|
9051
|
+
LngLatBounds.prototype.getSouth = function getSouth () { return this._sw.lat; };
|
|
9052
|
+
|
|
9053
|
+
/**
|
|
9054
|
+
* Returns the east edge of the bounding box.
|
|
9055
|
+
*
|
|
9056
|
+
* @returns {number} The east edge of the bounding box.
|
|
9057
|
+
*/
|
|
9058
|
+
LngLatBounds.prototype.getEast = function getEast () { return this._ne.lng; };
|
|
9059
|
+
|
|
9060
|
+
/**
|
|
9061
|
+
* Returns the north edge of the bounding box.
|
|
9062
|
+
*
|
|
9063
|
+
* @returns {number} The north edge of the bounding box.
|
|
9064
|
+
*/
|
|
9065
|
+
LngLatBounds.prototype.getNorth = function getNorth () { return this._ne.lat; };
|
|
9066
|
+
|
|
9067
|
+
/**
|
|
9068
|
+
* Returns the bounding box represented as an array.
|
|
9069
|
+
*
|
|
9070
|
+
* @returns {Array<Array<number>>} The bounding box represented as an array, consisting of the
|
|
9071
|
+
* southwest and northeast coordinates of the bounding represented as arrays of numbers.
|
|
9072
|
+
* @example
|
|
9073
|
+
* var llb = new mapboxgl.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
|
|
9074
|
+
* llb.toArray(); // = [[-73.9876, 40.7661], [-73.9397, 40.8002]]
|
|
9075
|
+
*/
|
|
9076
|
+
LngLatBounds.prototype.toArray = function toArray () {
|
|
9077
|
+
return [this._sw.toArray(), this._ne.toArray()];
|
|
9078
|
+
};
|
|
9079
|
+
|
|
9080
|
+
/**
|
|
9081
|
+
* Return the bounding box represented as a string.
|
|
9082
|
+
*
|
|
9083
|
+
* @returns {string} The bounding box represents as a string of the format
|
|
9084
|
+
* `'LngLatBounds(LngLat(lng, lat), LngLat(lng, lat))'`.
|
|
9085
|
+
* @example
|
|
9086
|
+
* var llb = new mapboxgl.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
|
|
9087
|
+
* llb.toString(); // = "LngLatBounds(LngLat(-73.9876, 40.7661), LngLat(-73.9397, 40.8002))"
|
|
9088
|
+
*/
|
|
9089
|
+
LngLatBounds.prototype.toString = function toString () {
|
|
9090
|
+
return ("LngLatBounds(" + (this._sw.toString()) + ", " + (this._ne.toString()) + ")");
|
|
9091
|
+
};
|
|
9092
|
+
|
|
9093
|
+
/**
|
|
9094
|
+
* Check if the bounding box is an empty/`null`-type box.
|
|
9095
|
+
*
|
|
9096
|
+
* @returns {boolean} True if bounds have been defined, otherwise false.
|
|
9097
|
+
*/
|
|
9098
|
+
LngLatBounds.prototype.isEmpty = function isEmpty () {
|
|
9099
|
+
return !(this._sw && this._ne);
|
|
9100
|
+
};
|
|
9101
|
+
|
|
9102
|
+
/**
|
|
9103
|
+
* Check if the point is within the bounding box.
|
|
9104
|
+
*
|
|
9105
|
+
* @param {LngLatLike} lnglat geographic point to check against.
|
|
9106
|
+
* @returns {boolean} True if the point is within the bounding box.
|
|
9107
|
+
*/
|
|
9108
|
+
LngLatBounds.prototype.contains = function contains (lnglat ) {
|
|
9109
|
+
var ref = LngLat.convert(lnglat);
|
|
9110
|
+
var lng = ref.lng;
|
|
9111
|
+
var lat = ref.lat;
|
|
9112
|
+
|
|
9113
|
+
var containsLatitude = this._sw.lat <= lat && lat <= this._ne.lat;
|
|
9114
|
+
var containsLongitude = this._sw.lng <= lng && lng <= this._ne.lng;
|
|
9115
|
+
if (this._sw.lng > this._ne.lng) { // wrapped coordinates
|
|
9116
|
+
containsLongitude = this._sw.lng >= lng && lng >= this._ne.lng;
|
|
9117
|
+
}
|
|
9118
|
+
|
|
9119
|
+
return containsLatitude && containsLongitude;
|
|
9120
|
+
};
|
|
9121
|
+
|
|
9122
|
+
/**
|
|
9123
|
+
* Converts an array to a `LngLatBounds` object.
|
|
9124
|
+
*
|
|
9125
|
+
* If a `LngLatBounds` object is passed in, the function returns it unchanged.
|
|
9126
|
+
*
|
|
9127
|
+
* Internally, the function calls `LngLat#convert` to convert arrays to `LngLat` values.
|
|
9128
|
+
*
|
|
9129
|
+
* @param {LngLatBoundsLike} input An array of two coordinates to convert, or a `LngLatBounds` object to return.
|
|
9130
|
+
* @returns {LngLatBounds} A new `LngLatBounds` object, if a conversion occurred, or the original `LngLatBounds` object.
|
|
9131
|
+
* @example
|
|
9132
|
+
* var arr = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
|
|
9133
|
+
* var llb = mapboxgl.LngLatBounds.convert(arr);
|
|
9134
|
+
* llb; // = LngLatBounds {_sw: LngLat {lng: -73.9876, lat: 40.7661}, _ne: LngLat {lng: -73.9397, lat: 40.8002}}
|
|
9135
|
+
*/
|
|
9136
|
+
LngLatBounds.convert = function convert (input ) {
|
|
9137
|
+
if (!input || input instanceof LngLatBounds) { return input; }
|
|
9138
|
+
return new LngLatBounds(input);
|
|
9139
|
+
};
|
|
9140
|
+
|
|
9141
|
+
//
|
|
9142
|
+
|
|
9143
|
+
/*
|
|
9144
|
+
* Approximate radius of the earth in meters.
|
|
9145
|
+
* Uses the WGS-84 approximation. The radius at the equator is ~6378137 and at the poles is ~6356752. https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84
|
|
9146
|
+
* 6371008.8 is one published "average radius" see https://en.wikipedia.org/wiki/Earth_radius#Mean_radius, or ftp://athena.fsv.cvut.cz/ZFG/grs80-Moritz.pdf p.4
|
|
9147
|
+
*/
|
|
9148
|
+
var earthRadius = 6371008.8;
|
|
9149
|
+
|
|
9150
|
+
/**
|
|
9151
|
+
* A `LngLat` object represents a given longitude and latitude coordinate, measured in degrees.
|
|
9152
|
+
*
|
|
9153
|
+
* Mapbox GL uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.
|
|
9154
|
+
*
|
|
9155
|
+
* Note that any Mapbox GL method that accepts a `LngLat` object as an argument or option
|
|
9156
|
+
* can also accept an `Array` of two numbers and will perform an implicit conversion.
|
|
9157
|
+
* This flexible type is documented as {@link LngLatLike}.
|
|
9158
|
+
*
|
|
9159
|
+
* @param {number} lng Longitude, measured in degrees.
|
|
9160
|
+
* @param {number} lat Latitude, measured in degrees.
|
|
9161
|
+
* @example
|
|
9162
|
+
* var ll = new mapboxgl.LngLat(-73.9749, 40.7736);
|
|
9163
|
+
* @see [Get coordinates of the mouse pointer](https://www.mapbox.com/mapbox-gl-js/example/mouse-position/)
|
|
9164
|
+
* @see [Display a popup](https://www.mapbox.com/mapbox-gl-js/example/popup/)
|
|
9165
|
+
* @see [Highlight features within a bounding box](https://www.mapbox.com/mapbox-gl-js/example/using-box-queryrenderedfeatures/)
|
|
9166
|
+
* @see [Create a timeline animation](https://www.mapbox.com/mapbox-gl-js/example/timeline-animation/)
|
|
9167
|
+
*/
|
|
9168
|
+
var LngLat = function LngLat(lng , lat ) {
|
|
9169
|
+
if (isNaN(lng) || isNaN(lat)) {
|
|
9170
|
+
throw new Error(("Invalid LngLat object: (" + lng + ", " + lat + ")"));
|
|
9171
|
+
}
|
|
9172
|
+
this.lng = +lng;
|
|
9173
|
+
this.lat = +lat;
|
|
9174
|
+
if (this.lat > 90 || this.lat < -90) {
|
|
9175
|
+
throw new Error('Invalid LngLat latitude value: must be between -90 and 90');
|
|
9176
|
+
}
|
|
9177
|
+
};
|
|
9178
|
+
|
|
9179
|
+
/**
|
|
9180
|
+
* Returns a new `LngLat` object whose longitude is wrapped to the range (-180, 180).
|
|
9181
|
+
*
|
|
9182
|
+
* @returns {LngLat} The wrapped `LngLat` object.
|
|
9183
|
+
* @example
|
|
9184
|
+
* var ll = new mapboxgl.LngLat(286.0251, 40.7736);
|
|
9185
|
+
* var wrapped = ll.wrap();
|
|
9186
|
+
* wrapped.lng; // = -73.9749
|
|
9187
|
+
*/
|
|
9188
|
+
LngLat.prototype.wrap = function wrap$1 () {
|
|
9189
|
+
return new LngLat(wrap(this.lng, -180, 180), this.lat);
|
|
9190
|
+
};
|
|
9191
|
+
|
|
9192
|
+
/**
|
|
9193
|
+
* Returns the coordinates represented as an array of two numbers.
|
|
9194
|
+
*
|
|
9195
|
+
* @returns {Array<number>} The coordinates represeted as an array of longitude and latitude.
|
|
9196
|
+
* @example
|
|
9197
|
+
* var ll = new mapboxgl.LngLat(-73.9749, 40.7736);
|
|
9198
|
+
* ll.toArray(); // = [-73.9749, 40.7736]
|
|
9199
|
+
*/
|
|
9200
|
+
LngLat.prototype.toArray = function toArray () {
|
|
9201
|
+
return [this.lng, this.lat];
|
|
9202
|
+
};
|
|
9203
|
+
|
|
9204
|
+
/**
|
|
9205
|
+
* Returns the coordinates represent as a string.
|
|
9206
|
+
*
|
|
9207
|
+
* @returns {string} The coordinates represented as a string of the format `'LngLat(lng, lat)'`.
|
|
9208
|
+
* @example
|
|
9209
|
+
* var ll = new mapboxgl.LngLat(-73.9749, 40.7736);
|
|
9210
|
+
* ll.toString(); // = "LngLat(-73.9749, 40.7736)"
|
|
9211
|
+
*/
|
|
9212
|
+
LngLat.prototype.toString = function toString () {
|
|
9213
|
+
return ("LngLat(" + (this.lng) + ", " + (this.lat) + ")");
|
|
9214
|
+
};
|
|
9215
|
+
|
|
9216
|
+
/**
|
|
9217
|
+
* Returns the approximate distance between a pair of coordinates in meters
|
|
9218
|
+
* Uses the Haversine Formula (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159)
|
|
9219
|
+
*
|
|
9220
|
+
* @param {LngLat} lngLat coordinates to compute the distance to
|
|
9221
|
+
* @returns {number} Distance in meters between the two coordinates.
|
|
9222
|
+
* @example
|
|
9223
|
+
* var new_york = new mapboxgl.LngLat(-74.0060, 40.7128);
|
|
9224
|
+
* var los_angeles = new mapboxgl.LngLat(-118.2437, 34.0522);
|
|
9225
|
+
* new_york.distanceTo(los_angeles); // = 3935751.690893987, "true distance" using a non-spherical approximation is ~3966km
|
|
9226
|
+
*/
|
|
9227
|
+
LngLat.prototype.distanceTo = function distanceTo (lngLat ) {
|
|
9228
|
+
var rad = Math.PI / 180;
|
|
9229
|
+
var lat1 = this.lat * rad;
|
|
9230
|
+
var lat2 = lngLat.lat * rad;
|
|
9231
|
+
var a = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos((lngLat.lng - this.lng) * rad);
|
|
9232
|
+
|
|
9233
|
+
var maxMeters = earthRadius * Math.acos(Math.min(a, 1));
|
|
9234
|
+
return maxMeters;
|
|
9235
|
+
};
|
|
9236
|
+
|
|
9237
|
+
/**
|
|
9238
|
+
* Returns a `LngLatBounds` from the coordinates extended by a given `radius`. The returned `LngLatBounds` completely contains the `radius`.
|
|
9239
|
+
*
|
|
9240
|
+
* @param {number} [radius=0] Distance in meters from the coordinates to extend the bounds.
|
|
9241
|
+
* @returns {LngLatBounds} A new `LngLatBounds` object representing the coordinates extended by the `radius`.
|
|
9242
|
+
* @example
|
|
9243
|
+
* var ll = new mapboxgl.LngLat(-73.9749, 40.7736);
|
|
9244
|
+
* ll.toBounds(100).toArray(); // = [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]
|
|
9245
|
+
*/
|
|
9246
|
+
LngLat.prototype.toBounds = function toBounds (radius) {
|
|
9247
|
+
if ( radius === void 0 ) radius = 0;
|
|
9248
|
+
|
|
9249
|
+
var earthCircumferenceInMetersAtEquator = 40075017;
|
|
9250
|
+
var latAccuracy = 360 * radius / earthCircumferenceInMetersAtEquator,
|
|
9251
|
+
lngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * this.lat);
|
|
9252
|
+
|
|
9253
|
+
return new LngLatBounds(new LngLat(this.lng - lngAccuracy, this.lat - latAccuracy),
|
|
9254
|
+
new LngLat(this.lng + lngAccuracy, this.lat + latAccuracy));
|
|
9255
|
+
};
|
|
9256
|
+
|
|
9257
|
+
/**
|
|
9258
|
+
* Converts an array of two numbers or an object with `lng` and `lat` or `lon` and `lat` properties
|
|
9259
|
+
* to a `LngLat` object.
|
|
9260
|
+
*
|
|
9261
|
+
* If a `LngLat` object is passed in, the function returns it unchanged.
|
|
9262
|
+
*
|
|
9263
|
+
* @param {LngLatLike} input An array of two numbers or object to convert, or a `LngLat` object to return.
|
|
9264
|
+
* @returns {LngLat} A new `LngLat` object, if a conversion occurred, or the original `LngLat` object.
|
|
9265
|
+
* @example
|
|
9266
|
+
* var arr = [-73.9749, 40.7736];
|
|
9267
|
+
* var ll = mapboxgl.LngLat.convert(arr);
|
|
9268
|
+
* ll; // = LngLat {lng: -73.9749, lat: 40.7736}
|
|
9269
|
+
*/
|
|
9270
|
+
LngLat.convert = function convert (input ) {
|
|
9271
|
+
if (input instanceof LngLat) {
|
|
9272
|
+
return input;
|
|
9273
|
+
}
|
|
9274
|
+
if (Array.isArray(input) && (input.length === 2 || input.length === 3)) {
|
|
9275
|
+
return new LngLat(Number(input[0]), Number(input[1]));
|
|
9276
|
+
}
|
|
9277
|
+
if (!Array.isArray(input) && typeof input === 'object' && input !== null) {
|
|
9278
|
+
return new LngLat(
|
|
9279
|
+
// flow can't refine this to have one of lng or lat, so we have to cast to any
|
|
9280
|
+
Number('lng' in input ? (input ).lng : (input ).lon),
|
|
9281
|
+
Number(input.lat)
|
|
9282
|
+
);
|
|
9283
|
+
}
|
|
9284
|
+
throw new Error("`LngLatLike` argument must be specified as a LngLat instance, an object {lng: <lng>, lat: <lat>}, an object {lon: <lng>, lat: <lat>}, or an array of [<lng>, <lat>]");
|
|
9285
|
+
};
|
|
9286
|
+
|
|
9287
|
+
//
|
|
9288
|
+
|
|
9289
|
+
|
|
9290
|
+
/*
|
|
9291
|
+
* The average circumference of the world in meters.
|
|
9292
|
+
*/
|
|
9293
|
+
var earthCircumfrence = 2 * Math.PI * earthRadius; // meters
|
|
9294
|
+
|
|
9295
|
+
/*
|
|
9296
|
+
* The circumference at a line of latitude in meters.
|
|
9297
|
+
*/
|
|
9298
|
+
function circumferenceAtLatitude(latitude ) {
|
|
9299
|
+
return earthCircumfrence * Math.cos(latitude * Math.PI / 180);
|
|
9300
|
+
}
|
|
9301
|
+
|
|
9302
|
+
function mercatorXfromLng(lng ) {
|
|
9303
|
+
return (180 + lng) / 360;
|
|
9304
|
+
}
|
|
9305
|
+
|
|
9306
|
+
function mercatorYfromLat(lat ) {
|
|
9307
|
+
return (180 - (180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360)))) / 360;
|
|
9308
|
+
}
|
|
9309
|
+
|
|
9310
|
+
function mercatorZfromAltitude(altitude , lat ) {
|
|
9311
|
+
return altitude / circumferenceAtLatitude(lat);
|
|
9312
|
+
}
|
|
9313
|
+
|
|
9314
|
+
function lngFromMercatorX(x ) {
|
|
9315
|
+
return x * 360 - 180;
|
|
9316
|
+
}
|
|
9317
|
+
|
|
9318
|
+
function latFromMercatorY(y ) {
|
|
9319
|
+
var y2 = 180 - y * 360;
|
|
9320
|
+
return 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
|
|
9321
|
+
}
|
|
9322
|
+
|
|
9323
|
+
function altitudeFromMercatorZ(z , y ) {
|
|
9324
|
+
return z * circumferenceAtLatitude(latFromMercatorY(y));
|
|
9325
|
+
}
|
|
9326
|
+
|
|
9327
|
+
/**
|
|
9328
|
+
* Determine the Mercator scale factor for a given latitude, see
|
|
9329
|
+
* https://en.wikipedia.org/wiki/Mercator_projection#Scale_factor
|
|
9330
|
+
*
|
|
9331
|
+
* At the equator the scale factor will be 1, which increases at higher latitudes.
|
|
9332
|
+
*
|
|
9333
|
+
* @param {number} lat Latitude
|
|
9334
|
+
* @returns {number} scale factor
|
|
9335
|
+
* @private
|
|
9336
|
+
*/
|
|
9337
|
+
function mercatorScale(lat ) {
|
|
9338
|
+
return 1 / Math.cos(lat * Math.PI / 180);
|
|
9339
|
+
}
|
|
9340
|
+
|
|
9341
|
+
/**
|
|
9342
|
+
* A `MercatorCoordinate` object represents a projected three dimensional position.
|
|
9343
|
+
*
|
|
9344
|
+
* `MercatorCoordinate` uses the web mercator projection ([EPSG:3857](https://epsg.io/3857)) with slightly different units:
|
|
9345
|
+
* - the size of 1 unit is the width of the projected world instead of the "mercator meter"
|
|
9346
|
+
* - the origin of the coordinate space is at the north-west corner instead of the middle
|
|
9347
|
+
*
|
|
9348
|
+
* For example, `MercatorCoordinate(0, 0, 0)` is the north-west corner of the mercator world and
|
|
9349
|
+
* `MercatorCoordinate(1, 1, 0)` is the south-east corner. If you are familiar with
|
|
9350
|
+
* [vector tiles](https://github.com/mapbox/vector-tile-spec) it may be helpful to think
|
|
9351
|
+
* of the coordinate space as the `0/0/0` tile with an extent of `1`.
|
|
9352
|
+
*
|
|
9353
|
+
* The `z` dimension of `MercatorCoordinate` is conformal. A cube in the mercator coordinate space would be rendered as a cube.
|
|
9354
|
+
*
|
|
9355
|
+
* @param {number} x The x component of the position.
|
|
9356
|
+
* @param {number} y The y component of the position.
|
|
9357
|
+
* @param {number} z The z component of the position.
|
|
9358
|
+
* @example
|
|
9359
|
+
* var nullIsland = new mapboxgl.MercatorCoordinate(0.5, 0.5, 0);
|
|
9360
|
+
*
|
|
9361
|
+
* @see [Add a custom style layer](https://www.mapbox.com/mapbox-gl-js/example/custom-style-layer/)
|
|
9362
|
+
*/
|
|
9363
|
+
var MercatorCoordinate = function MercatorCoordinate(x , y , z) {
|
|
9364
|
+
if ( z === void 0 ) z = 0;
|
|
9365
|
+
|
|
9366
|
+
this.x = +x;
|
|
9367
|
+
this.y = +y;
|
|
9368
|
+
this.z = +z;
|
|
9369
|
+
};
|
|
9370
|
+
|
|
9371
|
+
/**
|
|
9372
|
+
* Project a `LngLat` to a `MercatorCoordinate`.
|
|
9373
|
+
*
|
|
9374
|
+
* @param {LngLatLike} lngLatLike The location to project.
|
|
9375
|
+
* @param {number} altitude The altitude in meters of the position.
|
|
9376
|
+
* @returns {MercatorCoordinate} The projected mercator coordinate.
|
|
9377
|
+
* @example
|
|
9378
|
+
* var coord = mapboxgl.MercatorCoordinate.fromLngLat({ lng: 0, lat: 0}, 0);
|
|
9379
|
+
* coord; // MercatorCoordinate(0.5, 0.5, 0)
|
|
9380
|
+
*/
|
|
9381
|
+
MercatorCoordinate.fromLngLat = function fromLngLat (lngLatLike , altitude) {
|
|
9382
|
+
if ( altitude === void 0 ) altitude = 0;
|
|
9383
|
+
|
|
9384
|
+
var lngLat = LngLat.convert(lngLatLike);
|
|
9385
|
+
|
|
9386
|
+
return new MercatorCoordinate(
|
|
9387
|
+
mercatorXfromLng(lngLat.lng),
|
|
9388
|
+
mercatorYfromLat(lngLat.lat),
|
|
9389
|
+
mercatorZfromAltitude(altitude, lngLat.lat));
|
|
9390
|
+
};
|
|
9391
|
+
|
|
9392
|
+
/**
|
|
9393
|
+
* Returns the `LngLat` for the coordinate.
|
|
9394
|
+
*
|
|
9395
|
+
* @returns {LngLat} The `LngLat` object.
|
|
9396
|
+
* @example
|
|
9397
|
+
* var coord = new mapboxgl.MercatorCoordinate(0.5, 0.5, 0);
|
|
9398
|
+
* var latLng = coord.toLngLat(); // LngLat(0, 0)
|
|
9399
|
+
*/
|
|
9400
|
+
MercatorCoordinate.prototype.toLngLat = function toLngLat () {
|
|
9401
|
+
return new LngLat(
|
|
9402
|
+
lngFromMercatorX(this.x),
|
|
9403
|
+
latFromMercatorY(this.y));
|
|
9404
|
+
};
|
|
9405
|
+
|
|
9406
|
+
/**
|
|
9407
|
+
* Returns the altitude in meters of the coordinate.
|
|
9408
|
+
*
|
|
9409
|
+
* @returns {number} The altitude in meters.
|
|
9410
|
+
* @example
|
|
9411
|
+
* var coord = new mapboxgl.MercatorCoordinate(0, 0, 0.02);
|
|
9412
|
+
* coord.toAltitude(); // 6914.281956295339
|
|
9413
|
+
*/
|
|
9414
|
+
MercatorCoordinate.prototype.toAltitude = function toAltitude () {
|
|
9415
|
+
return altitudeFromMercatorZ(this.z, this.y);
|
|
9416
|
+
};
|
|
9417
|
+
|
|
9418
|
+
/**
|
|
9419
|
+
* Returns the distance of 1 meter in `MercatorCoordinate` units at this latitude.
|
|
9420
|
+
*
|
|
9421
|
+
* For coordinates in real world units using meters, this naturally provides the scale
|
|
9422
|
+
* to transform into `MercatorCoordinate`s.
|
|
9423
|
+
*
|
|
9424
|
+
* @returns {number} Distance of 1 meter in `MercatorCoordinate` units.
|
|
9425
|
+
*/
|
|
9426
|
+
MercatorCoordinate.prototype.meterInMercatorCoordinateUnits = function meterInMercatorCoordinateUnits () {
|
|
9427
|
+
// 1 meter / circumference at equator in meters * Mercator projection scale factor at this latitude
|
|
9428
|
+
return 1 / earthCircumfrence * mercatorScale(latFromMercatorY(this.y));
|
|
9429
|
+
};
|
|
9430
|
+
|
|
9431
|
+
//
|
|
9432
|
+
|
|
9433
|
+
/**
|
|
9434
|
+
* The maximum value of a coordinate in the internal tile coordinate system. Coordinates of
|
|
9435
|
+
* all source features normalized to this extent upon load.
|
|
9436
|
+
*
|
|
9437
|
+
* The value is a consequence of the following:
|
|
9438
|
+
*
|
|
9439
|
+
* * Vertex buffer store positions as signed 16 bit integers.
|
|
9440
|
+
* * One bit is lost for signedness to support tile buffers.
|
|
9441
|
+
* * One bit is lost because the line vertex buffer used to pack 1 bit of other data into the int.
|
|
9442
|
+
* * One bit is lost to support features extending past the extent on the right edge of the tile.
|
|
9443
|
+
* * This leaves us with 2^13 = 8192
|
|
9444
|
+
*
|
|
9445
|
+
* @private
|
|
9446
|
+
* @readonly
|
|
9447
|
+
*/
|
|
9448
|
+
var EXTENT = 8192;
|
|
9449
|
+
|
|
9450
|
+
function updateBBox(bbox, coord) {
|
|
9451
|
+
bbox[0] = Math.min(bbox[0], coord[0]);
|
|
9452
|
+
bbox[1] = Math.min(bbox[1], coord[1]);
|
|
9453
|
+
bbox[2] = Math.max(bbox[2], coord[0]);
|
|
9454
|
+
bbox[3] = Math.max(bbox[3], coord[1]);
|
|
9455
|
+
}
|
|
9456
|
+
function boxWithinBox(bbox1, bbox2) {
|
|
9457
|
+
if (bbox1[0] <= bbox2[0]) {
|
|
9458
|
+
return false;
|
|
9459
|
+
}
|
|
9460
|
+
if (bbox1[2] >= bbox2[2]) {
|
|
9461
|
+
return false;
|
|
9462
|
+
}
|
|
9463
|
+
if (bbox1[1] <= bbox2[1]) {
|
|
9464
|
+
return false;
|
|
9465
|
+
}
|
|
9466
|
+
if (bbox1[3] >= bbox2[3]) {
|
|
9467
|
+
return false;
|
|
9468
|
+
}
|
|
9469
|
+
return true;
|
|
9470
|
+
}
|
|
9471
|
+
function getTileCoordinates(p, canonical) {
|
|
9472
|
+
var coord = MercatorCoordinate.fromLngLat({
|
|
9473
|
+
lng: p[0],
|
|
9474
|
+
lat: p[1]
|
|
9475
|
+
}, 0);
|
|
9476
|
+
var tilesAtZoom = Math.pow(2, canonical.z);
|
|
9477
|
+
return [
|
|
9478
|
+
Math.round(coord.x * tilesAtZoom * EXTENT),
|
|
9479
|
+
Math.round(coord.y * tilesAtZoom * EXTENT)
|
|
9480
|
+
];
|
|
9481
|
+
}
|
|
9482
|
+
function onBoundary(p, p1, p2) {
|
|
9483
|
+
var x1 = p[0] - p1[0];
|
|
9484
|
+
var y1 = p[1] - p1[1];
|
|
9485
|
+
var x2 = p[0] - p2[0];
|
|
9486
|
+
var y2 = p[1] - p2[1];
|
|
9487
|
+
return x1 * y2 - x2 * y1 === 0 && x1 * x2 <= 0 && y1 * y2 <= 0;
|
|
9488
|
+
}
|
|
9489
|
+
function rayIntersect(p, p1, p2) {
|
|
9490
|
+
return p1[1] > p[1] !== p2[1] > p[1] && p[0] < (p2[0] - p1[0]) * (p[1] - p1[1]) / (p2[1] - p1[1]) + p1[0];
|
|
9491
|
+
}
|
|
9492
|
+
function pointWithinPolygon(point, rings) {
|
|
9493
|
+
var inside = false;
|
|
9494
|
+
for (var i = 0, len = rings.length; i < len; i++) {
|
|
9495
|
+
var ring = rings[i];
|
|
9496
|
+
for (var j = 0, len2 = ring.length; j < len2 - 1; j++) {
|
|
9497
|
+
if (onBoundary(point, ring[j], ring[j + 1])) {
|
|
9498
|
+
return false;
|
|
9499
|
+
}
|
|
9500
|
+
if (rayIntersect(point, ring[j], ring[j + 1])) {
|
|
9501
|
+
inside = !inside;
|
|
9502
|
+
}
|
|
9503
|
+
}
|
|
9504
|
+
}
|
|
9505
|
+
return inside;
|
|
9506
|
+
}
|
|
9507
|
+
function pointWithinPolygons(point, polygons) {
|
|
9508
|
+
for (var i = 0; i < polygons.length; i++) {
|
|
9509
|
+
if (pointWithinPolygon(point, polygons[i])) {
|
|
9510
|
+
return true;
|
|
9511
|
+
}
|
|
9512
|
+
}
|
|
9513
|
+
return false;
|
|
9514
|
+
}
|
|
9515
|
+
function perp(v1, v2) {
|
|
9516
|
+
return v1[0] * v2[1] - v1[1] * v2[0];
|
|
9517
|
+
}
|
|
9518
|
+
function twoSided(p1, p2, q1, q2) {
|
|
9519
|
+
var x1 = p1[0] - q1[0];
|
|
9520
|
+
var y1 = p1[1] - q1[1];
|
|
9521
|
+
var x2 = p2[0] - q1[0];
|
|
9522
|
+
var y2 = p2[1] - q1[1];
|
|
9523
|
+
var x3 = q2[0] - q1[0];
|
|
9524
|
+
var y3 = q2[1] - q1[1];
|
|
9525
|
+
if ((x1 * y3 - x3 * y1) * (x2 * y3 - x3 * y2) < 0) {
|
|
9526
|
+
return true;
|
|
9527
|
+
}
|
|
9528
|
+
return false;
|
|
9529
|
+
}
|
|
9530
|
+
function lineIntersectLine(a, b, c, d) {
|
|
9531
|
+
var vectorP = [
|
|
9532
|
+
b[0] - a[0],
|
|
9533
|
+
b[1] - a[1]
|
|
9534
|
+
];
|
|
9535
|
+
var vectorQ = [
|
|
9536
|
+
d[0] - c[0],
|
|
9537
|
+
d[1] - c[1]
|
|
9538
|
+
];
|
|
9539
|
+
if (perp(vectorQ, vectorP) === 0) {
|
|
9540
|
+
return false;
|
|
9541
|
+
}
|
|
9542
|
+
if (twoSided(a, b, c, d) && twoSided(c, d, a, b)) {
|
|
9543
|
+
return true;
|
|
9544
|
+
}
|
|
9545
|
+
return false;
|
|
9546
|
+
}
|
|
9547
|
+
function lineIntersectPolygon(p1, p2, polygon) {
|
|
9548
|
+
for (var i = 0, list = polygon; i < list.length; i += 1) {
|
|
9549
|
+
var ring = list[i];
|
|
9550
|
+
for (var j = 0; j < ring.length - 1; ++j) {
|
|
9551
|
+
if (lineIntersectLine(p1, p2, ring[j], ring[j + 1])) {
|
|
9552
|
+
return true;
|
|
9553
|
+
}
|
|
9554
|
+
}
|
|
9555
|
+
}
|
|
9556
|
+
return false;
|
|
9557
|
+
}
|
|
9558
|
+
function lineStringWithinPolygon(line, polygon) {
|
|
9559
|
+
for (var i = 0; i < line.length; ++i) {
|
|
9560
|
+
if (!pointWithinPolygon(line[i], polygon)) {
|
|
9561
|
+
return false;
|
|
9562
|
+
}
|
|
9563
|
+
}
|
|
9564
|
+
for (var i$1 = 0; i$1 < line.length - 1; ++i$1) {
|
|
9565
|
+
if (lineIntersectPolygon(line[i$1], line[i$1 + 1], polygon)) {
|
|
9566
|
+
return false;
|
|
9567
|
+
}
|
|
9568
|
+
}
|
|
9569
|
+
return true;
|
|
9570
|
+
}
|
|
9571
|
+
function lineStringWithinPolygons(line, polygons) {
|
|
9572
|
+
for (var i = 0; i < polygons.length; i++) {
|
|
9573
|
+
if (lineStringWithinPolygon(line, polygons[i])) {
|
|
9574
|
+
return true;
|
|
9575
|
+
}
|
|
9576
|
+
}
|
|
9577
|
+
return false;
|
|
9578
|
+
}
|
|
9579
|
+
function getTilePolygon(coordinates, bbox, canonical) {
|
|
9580
|
+
var polygon = [];
|
|
9581
|
+
for (var i = 0; i < coordinates.length; i++) {
|
|
9582
|
+
var ring = [];
|
|
9583
|
+
for (var j = 0; j < coordinates[i].length; j++) {
|
|
9584
|
+
var coord = getTileCoordinates(coordinates[i][j], canonical);
|
|
9585
|
+
updateBBox(bbox, coord);
|
|
9586
|
+
ring.push(coord);
|
|
9587
|
+
}
|
|
9588
|
+
polygon.push(ring);
|
|
9589
|
+
}
|
|
9590
|
+
return polygon;
|
|
9591
|
+
}
|
|
9592
|
+
function getTilePolygons(coordinates, bbox, canonical) {
|
|
9593
|
+
var polygons = [];
|
|
9594
|
+
for (var i = 0; i < coordinates.length; i++) {
|
|
9595
|
+
var polygon = getTilePolygon(coordinates[i], bbox, canonical);
|
|
9596
|
+
polygons.push(polygon);
|
|
9597
|
+
}
|
|
9598
|
+
return polygons;
|
|
9599
|
+
}
|
|
9600
|
+
function pointsWithinPolygons(ctx, polygonGeometry) {
|
|
9601
|
+
var pointBBox = [
|
|
9602
|
+
Infinity,
|
|
9603
|
+
Infinity,
|
|
9604
|
+
-Infinity,
|
|
9605
|
+
-Infinity
|
|
9606
|
+
];
|
|
9607
|
+
var polyBBox = [
|
|
9608
|
+
Infinity,
|
|
9609
|
+
Infinity,
|
|
9610
|
+
-Infinity,
|
|
9611
|
+
-Infinity
|
|
9612
|
+
];
|
|
9613
|
+
var canonical = ctx.canonicalID();
|
|
9614
|
+
var shifts = [
|
|
9615
|
+
canonical.x * EXTENT,
|
|
9616
|
+
canonical.y * EXTENT
|
|
9617
|
+
];
|
|
9618
|
+
var tilePoints = [];
|
|
9619
|
+
for (var i$1 = 0, list$1 = ctx.geometry(); i$1 < list$1.length; i$1 += 1) {
|
|
9620
|
+
var points = list$1[i$1];
|
|
9621
|
+
for (var i = 0, list = points; i < list.length; i += 1) {
|
|
9622
|
+
var point = list[i];
|
|
9623
|
+
var p = [
|
|
9624
|
+
point.x + shifts[0],
|
|
9625
|
+
point.y + shifts[1]
|
|
9626
|
+
];
|
|
9627
|
+
updateBBox(pointBBox, p);
|
|
9628
|
+
tilePoints.push(p);
|
|
9629
|
+
}
|
|
9630
|
+
}
|
|
9631
|
+
if (polygonGeometry.type === 'Polygon') {
|
|
9632
|
+
var tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
|
|
9633
|
+
if (!boxWithinBox(pointBBox, polyBBox)) {
|
|
9634
|
+
return false;
|
|
9635
|
+
}
|
|
9636
|
+
for (var i$2 = 0, list$2 = tilePoints; i$2 < list$2.length; i$2 += 1) {
|
|
9637
|
+
var point$1 = list$2[i$2];
|
|
9638
|
+
if (!pointWithinPolygon(point$1, tilePolygon)) {
|
|
9639
|
+
return false;
|
|
9640
|
+
}
|
|
9641
|
+
}
|
|
9642
|
+
}
|
|
9643
|
+
if (polygonGeometry.type === 'MultiPolygon') {
|
|
9644
|
+
var tilePolygons = getTilePolygons(polygonGeometry.coordinates, polyBBox, canonical);
|
|
9645
|
+
if (!boxWithinBox(pointBBox, polyBBox)) {
|
|
9646
|
+
return false;
|
|
9647
|
+
}
|
|
9648
|
+
for (var i$3 = 0, list$3 = tilePoints; i$3 < list$3.length; i$3 += 1) {
|
|
9649
|
+
var point$2 = list$3[i$3];
|
|
9650
|
+
if (!pointWithinPolygons(point$2, tilePolygons)) {
|
|
9651
|
+
return false;
|
|
9652
|
+
}
|
|
9653
|
+
}
|
|
9654
|
+
}
|
|
9655
|
+
return true;
|
|
9656
|
+
}
|
|
9657
|
+
function linesWithinPolygons(ctx, polygonGeometry) {
|
|
9658
|
+
var lineBBox = [
|
|
9659
|
+
Infinity,
|
|
9660
|
+
Infinity,
|
|
9661
|
+
-Infinity,
|
|
9662
|
+
-Infinity
|
|
9663
|
+
];
|
|
9664
|
+
var polyBBox = [
|
|
9665
|
+
Infinity,
|
|
9666
|
+
Infinity,
|
|
9667
|
+
-Infinity,
|
|
9668
|
+
-Infinity
|
|
9669
|
+
];
|
|
9670
|
+
var canonical = ctx.canonicalID();
|
|
9671
|
+
var shifts = [
|
|
9672
|
+
canonical.x * EXTENT,
|
|
9673
|
+
canonical.y * EXTENT
|
|
9674
|
+
];
|
|
9675
|
+
var tileLines = [];
|
|
9676
|
+
for (var i$1 = 0, list$1 = ctx.geometry(); i$1 < list$1.length; i$1 += 1) {
|
|
9677
|
+
var line = list$1[i$1];
|
|
9678
|
+
var tileLine = [];
|
|
9679
|
+
for (var i = 0, list = line; i < list.length; i += 1) {
|
|
9680
|
+
var point = list[i];
|
|
9681
|
+
var p = [
|
|
9682
|
+
point.x + shifts[0],
|
|
9683
|
+
point.y + shifts[1]
|
|
9684
|
+
];
|
|
9685
|
+
updateBBox(lineBBox, p);
|
|
9686
|
+
tileLine.push(p);
|
|
9687
|
+
}
|
|
9688
|
+
tileLines.push(tileLine);
|
|
9689
|
+
}
|
|
9690
|
+
if (polygonGeometry.type === 'Polygon') {
|
|
9691
|
+
var tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
|
|
9692
|
+
if (!boxWithinBox(lineBBox, polyBBox)) {
|
|
9693
|
+
return false;
|
|
9694
|
+
}
|
|
9695
|
+
for (var i$2 = 0, list$2 = tileLines; i$2 < list$2.length; i$2 += 1) {
|
|
9696
|
+
var line$1 = list$2[i$2];
|
|
9697
|
+
if (!lineStringWithinPolygon(line$1, tilePolygon)) {
|
|
9698
|
+
return false;
|
|
9699
|
+
}
|
|
9700
|
+
}
|
|
9701
|
+
}
|
|
9702
|
+
if (polygonGeometry.type === 'MultiPolygon') {
|
|
9703
|
+
var tilePolygons = getTilePolygons(polygonGeometry.coordinates, polyBBox, canonical);
|
|
9704
|
+
if (!boxWithinBox(lineBBox, polyBBox)) {
|
|
9705
|
+
return false;
|
|
9706
|
+
}
|
|
9707
|
+
for (var i$3 = 0, list$3 = tileLines; i$3 < list$3.length; i$3 += 1) {
|
|
9708
|
+
var line$2 = list$3[i$3];
|
|
9709
|
+
if (!lineStringWithinPolygons(line$2, tilePolygons)) {
|
|
9710
|
+
return false;
|
|
9711
|
+
}
|
|
9712
|
+
}
|
|
9713
|
+
}
|
|
9714
|
+
return true;
|
|
9715
|
+
}
|
|
9716
|
+
var Within = function Within(geojson, geometries) {
|
|
9717
|
+
this.type = BooleanType;
|
|
9718
|
+
this.geojson = geojson;
|
|
9719
|
+
this.geometries = geometries;
|
|
9720
|
+
};
|
|
9721
|
+
Within.parse = function parse(args, context) {
|
|
9722
|
+
if (args.length !== 2) {
|
|
9723
|
+
return context.error('\'within\' expression requires exactly one argument, but found ' + (args.length - 1) + ' instead.');
|
|
9724
|
+
}
|
|
9725
|
+
if (isValue(args[1])) {
|
|
9726
|
+
var geojson = args[1];
|
|
9727
|
+
if (geojson.type === 'FeatureCollection') {
|
|
9728
|
+
for (var i = 0; i < geojson.features.length; ++i) {
|
|
9729
|
+
var type = geojson.features[i].geometry.type;
|
|
9730
|
+
if (type === 'Polygon' || type === 'MultiPolygon') {
|
|
9731
|
+
return new Within(geojson, geojson.features[i].geometry);
|
|
9732
|
+
}
|
|
9733
|
+
}
|
|
9734
|
+
} else if (geojson.type === 'Feature') {
|
|
9735
|
+
var type$1 = geojson.geometry.type;
|
|
9736
|
+
if (type$1 === 'Polygon' || type$1 === 'MultiPolygon') {
|
|
9737
|
+
return new Within(geojson, geojson.geometry);
|
|
9738
|
+
}
|
|
9739
|
+
} else if (geojson.type === 'Polygon' || geojson.type === 'MultiPolygon') {
|
|
9740
|
+
return new Within(geojson, geojson);
|
|
9741
|
+
}
|
|
9742
|
+
}
|
|
9743
|
+
return context.error('\'within\' expression requires valid geojson object that contains polygon geometry type.');
|
|
9744
|
+
};
|
|
9745
|
+
Within.prototype.evaluate = function evaluate(ctx) {
|
|
9746
|
+
if (ctx.geometry() != null && ctx.canonicalID() != null) {
|
|
9747
|
+
if (ctx.geometryType() === 'Point') {
|
|
9748
|
+
return pointsWithinPolygons(ctx, this.geometries);
|
|
9749
|
+
} else if (ctx.geometryType() === 'LineString') {
|
|
9750
|
+
return linesWithinPolygons(ctx, this.geometries);
|
|
9751
|
+
}
|
|
9752
|
+
}
|
|
9753
|
+
return false;
|
|
9754
|
+
};
|
|
9755
|
+
Within.prototype.eachChild = function eachChild() {
|
|
9756
|
+
};
|
|
9757
|
+
Within.prototype.outputDefined = function outputDefined() {
|
|
9758
|
+
return true;
|
|
9759
|
+
};
|
|
9760
|
+
Within.prototype.serialize = function serialize() {
|
|
9761
|
+
return [
|
|
9762
|
+
'within',
|
|
9763
|
+
this.geojson
|
|
9764
|
+
];
|
|
9765
|
+
};
|
|
9766
|
+
|
|
9767
|
+
function isFeatureConstant(e) {
|
|
9768
|
+
if (e instanceof CompoundExpression) {
|
|
9769
|
+
if (e.name === 'get' && e.args.length === 1) {
|
|
9770
|
+
return false;
|
|
9771
|
+
} else if (e.name === 'feature-state') {
|
|
9772
|
+
return false;
|
|
9773
|
+
} else if (e.name === 'has' && e.args.length === 1) {
|
|
9774
|
+
return false;
|
|
9775
|
+
} else if (e.name === 'properties' || e.name === 'geometry-type' || e.name === 'id') {
|
|
9776
|
+
return false;
|
|
9777
|
+
} else if (/^filter-/.test(e.name)) {
|
|
9778
|
+
return false;
|
|
9779
|
+
}
|
|
9780
|
+
}
|
|
9781
|
+
if (e instanceof Within) {
|
|
9782
|
+
return false;
|
|
9783
|
+
}
|
|
9784
|
+
var result = true;
|
|
9785
|
+
e.eachChild(function (arg) {
|
|
9786
|
+
if (result && !isFeatureConstant(arg)) {
|
|
9787
|
+
result = false;
|
|
9788
|
+
}
|
|
9789
|
+
});
|
|
9790
|
+
return result;
|
|
9791
|
+
}
|
|
9792
|
+
function isStateConstant(e) {
|
|
9793
|
+
if (e instanceof CompoundExpression) {
|
|
9794
|
+
if (e.name === 'feature-state') {
|
|
9795
|
+
return false;
|
|
9796
|
+
}
|
|
9797
|
+
}
|
|
9798
|
+
var result = true;
|
|
9799
|
+
e.eachChild(function (arg) {
|
|
9800
|
+
if (result && !isStateConstant(arg)) {
|
|
9801
|
+
result = false;
|
|
9802
|
+
}
|
|
9803
|
+
});
|
|
9804
|
+
return result;
|
|
9805
|
+
}
|
|
9806
|
+
function isGlobalPropertyConstant(e, properties) {
|
|
9807
|
+
if (e instanceof CompoundExpression && properties.indexOf(e.name) >= 0) {
|
|
9808
|
+
return false;
|
|
9809
|
+
}
|
|
9810
|
+
var result = true;
|
|
9811
|
+
e.eachChild(function (arg) {
|
|
9812
|
+
if (result && !isGlobalPropertyConstant(arg, properties)) {
|
|
9813
|
+
result = false;
|
|
9814
|
+
}
|
|
9815
|
+
});
|
|
9816
|
+
return result;
|
|
9817
|
+
}
|
|
9818
|
+
|
|
9819
|
+
var Var = function Var(name, boundExpression) {
|
|
9820
|
+
this.type = boundExpression.type;
|
|
9821
|
+
this.name = name;
|
|
9822
|
+
this.boundExpression = boundExpression;
|
|
9823
|
+
};
|
|
9824
|
+
Var.parse = function parse(args, context) {
|
|
9825
|
+
if (args.length !== 2 || typeof args[1] !== 'string') {
|
|
9826
|
+
return context.error('\'var\' expression requires exactly one string literal argument.');
|
|
9827
|
+
}
|
|
9828
|
+
var name = args[1];
|
|
9829
|
+
if (!context.scope.has(name)) {
|
|
9830
|
+
return context.error('Unknown variable "' + name + '". Make sure "' + name + '" has been bound in an enclosing "let" expression before using it.', 1);
|
|
9831
|
+
}
|
|
9832
|
+
return new Var(name, context.scope.get(name));
|
|
9833
|
+
};
|
|
9834
|
+
Var.prototype.evaluate = function evaluate(ctx) {
|
|
9835
|
+
return this.boundExpression.evaluate(ctx);
|
|
9836
|
+
};
|
|
9837
|
+
Var.prototype.eachChild = function eachChild() {
|
|
9838
|
+
};
|
|
9839
|
+
Var.prototype.outputDefined = function outputDefined() {
|
|
9840
|
+
return false;
|
|
9841
|
+
};
|
|
9842
|
+
Var.prototype.serialize = function serialize() {
|
|
9843
|
+
return [
|
|
9844
|
+
'var',
|
|
9845
|
+
this.name
|
|
9846
|
+
];
|
|
9847
|
+
};
|
|
9848
|
+
|
|
9849
|
+
var ParsingContext = function ParsingContext(registry, path, expectedType, scope, errors) {
|
|
9850
|
+
if (path === void 0)
|
|
9851
|
+
path = [];
|
|
9852
|
+
if (scope === void 0)
|
|
9853
|
+
scope = new Scope();
|
|
9854
|
+
if (errors === void 0)
|
|
9855
|
+
errors = [];
|
|
9856
|
+
this.registry = registry;
|
|
9857
|
+
this.path = path;
|
|
8819
9858
|
this.key = path.map(function (part) {
|
|
8820
9859
|
return '[' + part + ']';
|
|
8821
9860
|
}).join('');
|
|
@@ -8921,6 +9960,8 @@ function isConstant(expression) {
|
|
|
8921
9960
|
return false;
|
|
8922
9961
|
} else if (expression instanceof CollatorExpression) {
|
|
8923
9962
|
return false;
|
|
9963
|
+
} else if (expression instanceof Within) {
|
|
9964
|
+
return false;
|
|
8924
9965
|
}
|
|
8925
9966
|
var isTypeAnnotation = expression instanceof Coercion || expression instanceof Assertion;
|
|
8926
9967
|
var childrenConstant = true;
|
|
@@ -9043,11 +10084,10 @@ Step.prototype.eachChild = function eachChild(fn) {
|
|
|
9043
10084
|
fn(expression);
|
|
9044
10085
|
}
|
|
9045
10086
|
};
|
|
9046
|
-
Step.prototype.
|
|
9047
|
-
|
|
9048
|
-
|
|
9049
|
-
|
|
9050
|
-
}));
|
|
10087
|
+
Step.prototype.outputDefined = function outputDefined() {
|
|
10088
|
+
return this.outputs.every(function (out) {
|
|
10089
|
+
return out.outputDefined();
|
|
10090
|
+
});
|
|
9051
10091
|
};
|
|
9052
10092
|
Step.prototype.serialize = function serialize() {
|
|
9053
10093
|
var serialized = [
|
|
@@ -9063,112 +10103,6 @@ Step.prototype.serialize = function serialize() {
|
|
|
9063
10103
|
return serialized;
|
|
9064
10104
|
};
|
|
9065
10105
|
|
|
9066
|
-
/*
|
|
9067
|
-
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
|
|
9068
|
-
*
|
|
9069
|
-
* Redistribution and use in source and binary forms, with or without
|
|
9070
|
-
* modification, are permitted provided that the following conditions
|
|
9071
|
-
* are met:
|
|
9072
|
-
* 1. Redistributions of source code must retain the above copyright
|
|
9073
|
-
* notice, this list of conditions and the following disclaimer.
|
|
9074
|
-
* 2. Redistributions in binary form must reproduce the above copyright
|
|
9075
|
-
* notice, this list of conditions and the following disclaimer in the
|
|
9076
|
-
* documentation and/or other materials provided with the distribution.
|
|
9077
|
-
*
|
|
9078
|
-
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
|
|
9079
|
-
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
9080
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
9081
|
-
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
|
|
9082
|
-
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
9083
|
-
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
9084
|
-
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
9085
|
-
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
9086
|
-
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
9087
|
-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
9088
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
9089
|
-
*
|
|
9090
|
-
* Ported from Webkit
|
|
9091
|
-
* http://svn.webkit.org/repository/webkit/trunk/Source/WebCore/platform/graphics/UnitBezier.h
|
|
9092
|
-
*/
|
|
9093
|
-
|
|
9094
|
-
var unitbezier = UnitBezier;
|
|
9095
|
-
|
|
9096
|
-
function UnitBezier(p1x, p1y, p2x, p2y) {
|
|
9097
|
-
// Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1).
|
|
9098
|
-
this.cx = 3.0 * p1x;
|
|
9099
|
-
this.bx = 3.0 * (p2x - p1x) - this.cx;
|
|
9100
|
-
this.ax = 1.0 - this.cx - this.bx;
|
|
9101
|
-
|
|
9102
|
-
this.cy = 3.0 * p1y;
|
|
9103
|
-
this.by = 3.0 * (p2y - p1y) - this.cy;
|
|
9104
|
-
this.ay = 1.0 - this.cy - this.by;
|
|
9105
|
-
|
|
9106
|
-
this.p1x = p1x;
|
|
9107
|
-
this.p1y = p2y;
|
|
9108
|
-
this.p2x = p2x;
|
|
9109
|
-
this.p2y = p2y;
|
|
9110
|
-
}
|
|
9111
|
-
|
|
9112
|
-
UnitBezier.prototype.sampleCurveX = function(t) {
|
|
9113
|
-
// `ax t^3 + bx t^2 + cx t' expanded using Horner's rule.
|
|
9114
|
-
return ((this.ax * t + this.bx) * t + this.cx) * t;
|
|
9115
|
-
};
|
|
9116
|
-
|
|
9117
|
-
UnitBezier.prototype.sampleCurveY = function(t) {
|
|
9118
|
-
return ((this.ay * t + this.by) * t + this.cy) * t;
|
|
9119
|
-
};
|
|
9120
|
-
|
|
9121
|
-
UnitBezier.prototype.sampleCurveDerivativeX = function(t) {
|
|
9122
|
-
return (3.0 * this.ax * t + 2.0 * this.bx) * t + this.cx;
|
|
9123
|
-
};
|
|
9124
|
-
|
|
9125
|
-
UnitBezier.prototype.solveCurveX = function(x, epsilon) {
|
|
9126
|
-
if (typeof epsilon === 'undefined') { epsilon = 1e-6; }
|
|
9127
|
-
|
|
9128
|
-
var t0, t1, t2, x2, i;
|
|
9129
|
-
|
|
9130
|
-
// First try a few iterations of Newton's method -- normally very fast.
|
|
9131
|
-
for (t2 = x, i = 0; i < 8; i++) {
|
|
9132
|
-
|
|
9133
|
-
x2 = this.sampleCurveX(t2) - x;
|
|
9134
|
-
if (Math.abs(x2) < epsilon) { return t2; }
|
|
9135
|
-
|
|
9136
|
-
var d2 = this.sampleCurveDerivativeX(t2);
|
|
9137
|
-
if (Math.abs(d2) < 1e-6) { break; }
|
|
9138
|
-
|
|
9139
|
-
t2 = t2 - x2 / d2;
|
|
9140
|
-
}
|
|
9141
|
-
|
|
9142
|
-
// Fall back to the bisection method for reliability.
|
|
9143
|
-
t0 = 0.0;
|
|
9144
|
-
t1 = 1.0;
|
|
9145
|
-
t2 = x;
|
|
9146
|
-
|
|
9147
|
-
if (t2 < t0) { return t0; }
|
|
9148
|
-
if (t2 > t1) { return t1; }
|
|
9149
|
-
|
|
9150
|
-
while (t0 < t1) {
|
|
9151
|
-
|
|
9152
|
-
x2 = this.sampleCurveX(t2);
|
|
9153
|
-
if (Math.abs(x2 - x) < epsilon) { return t2; }
|
|
9154
|
-
|
|
9155
|
-
if (x > x2) {
|
|
9156
|
-
t0 = t2;
|
|
9157
|
-
} else {
|
|
9158
|
-
t1 = t2;
|
|
9159
|
-
}
|
|
9160
|
-
|
|
9161
|
-
t2 = (t1 - t0) * 0.5 + t0;
|
|
9162
|
-
}
|
|
9163
|
-
|
|
9164
|
-
// Failure.
|
|
9165
|
-
return t2;
|
|
9166
|
-
};
|
|
9167
|
-
|
|
9168
|
-
UnitBezier.prototype.solve = function(x, epsilon) {
|
|
9169
|
-
return this.sampleCurveY(this.solveCurveX(x, epsilon));
|
|
9170
|
-
};
|
|
9171
|
-
|
|
9172
10106
|
function number(a, b, t) {
|
|
9173
10107
|
return a * (1 - t) + b * t;
|
|
9174
10108
|
}
|
|
@@ -9416,11 +10350,10 @@ Interpolate.prototype.eachChild = function eachChild(fn) {
|
|
|
9416
10350
|
fn(expression);
|
|
9417
10351
|
}
|
|
9418
10352
|
};
|
|
9419
|
-
Interpolate.prototype.
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
}));
|
|
10353
|
+
Interpolate.prototype.outputDefined = function outputDefined() {
|
|
10354
|
+
return this.outputs.every(function (out) {
|
|
10355
|
+
return out.outputDefined();
|
|
10356
|
+
});
|
|
9424
10357
|
};
|
|
9425
10358
|
Interpolate.prototype.serialize = function serialize() {
|
|
9426
10359
|
var interpolation;
|
|
@@ -9514,11 +10447,10 @@ Coalesce.prototype.evaluate = function evaluate(ctx) {
|
|
|
9514
10447
|
Coalesce.prototype.eachChild = function eachChild(fn) {
|
|
9515
10448
|
this.args.forEach(fn);
|
|
9516
10449
|
};
|
|
9517
|
-
Coalesce.prototype.
|
|
9518
|
-
|
|
9519
|
-
|
|
9520
|
-
|
|
9521
|
-
}));
|
|
10450
|
+
Coalesce.prototype.outputDefined = function outputDefined() {
|
|
10451
|
+
return this.args.every(function (arg) {
|
|
10452
|
+
return arg.outputDefined();
|
|
10453
|
+
});
|
|
9522
10454
|
};
|
|
9523
10455
|
Coalesce.prototype.serialize = function serialize() {
|
|
9524
10456
|
var serialized = ['coalesce'];
|
|
@@ -9571,8 +10503,8 @@ Let.parse = function parse(args, context) {
|
|
|
9571
10503
|
}
|
|
9572
10504
|
return new Let(bindings, result);
|
|
9573
10505
|
};
|
|
9574
|
-
Let.prototype.
|
|
9575
|
-
return this.result.
|
|
10506
|
+
Let.prototype.outputDefined = function outputDefined() {
|
|
10507
|
+
return this.result.outputDefined();
|
|
9576
10508
|
};
|
|
9577
10509
|
Let.prototype.serialize = function serialize() {
|
|
9578
10510
|
var serialized = ['let'];
|
|
@@ -9621,8 +10553,8 @@ At.prototype.eachChild = function eachChild(fn) {
|
|
|
9621
10553
|
fn(this.index);
|
|
9622
10554
|
fn(this.input);
|
|
9623
10555
|
};
|
|
9624
|
-
At.prototype.
|
|
9625
|
-
return
|
|
10556
|
+
At.prototype.outputDefined = function outputDefined() {
|
|
10557
|
+
return false;
|
|
9626
10558
|
};
|
|
9627
10559
|
At.prototype.serialize = function serialize() {
|
|
9628
10560
|
return [
|
|
@@ -9663,7 +10595,7 @@ In.parse = function parse(args, context) {
|
|
|
9663
10595
|
In.prototype.evaluate = function evaluate(ctx) {
|
|
9664
10596
|
var needle = this.needle.evaluate(ctx);
|
|
9665
10597
|
var haystack = this.haystack.evaluate(ctx);
|
|
9666
|
-
if (
|
|
10598
|
+
if (needle == null || !haystack) {
|
|
9667
10599
|
return false;
|
|
9668
10600
|
}
|
|
9669
10601
|
if (!isComparableRuntimeValue(needle)) {
|
|
@@ -9678,11 +10610,8 @@ In.prototype.eachChild = function eachChild(fn) {
|
|
|
9678
10610
|
fn(this.needle);
|
|
9679
10611
|
fn(this.haystack);
|
|
9680
10612
|
};
|
|
9681
|
-
In.prototype.
|
|
9682
|
-
return
|
|
9683
|
-
true,
|
|
9684
|
-
false
|
|
9685
|
-
];
|
|
10613
|
+
In.prototype.outputDefined = function outputDefined() {
|
|
10614
|
+
return true;
|
|
9686
10615
|
};
|
|
9687
10616
|
In.prototype.serialize = function serialize() {
|
|
9688
10617
|
return [
|
|
@@ -9772,11 +10701,10 @@ Match.prototype.eachChild = function eachChild(fn) {
|
|
|
9772
10701
|
this.outputs.forEach(fn);
|
|
9773
10702
|
fn(this.otherwise);
|
|
9774
10703
|
};
|
|
9775
|
-
Match.prototype.
|
|
9776
|
-
|
|
9777
|
-
|
|
9778
|
-
|
|
9779
|
-
})).concat(this.otherwise.possibleOutputs());
|
|
10704
|
+
Match.prototype.outputDefined = function outputDefined() {
|
|
10705
|
+
return this.outputs.every(function (out) {
|
|
10706
|
+
return out.outputDefined();
|
|
10707
|
+
}) && this.otherwise.outputDefined();
|
|
9780
10708
|
};
|
|
9781
10709
|
Match.prototype.serialize = function serialize() {
|
|
9782
10710
|
var this$1 = this;
|
|
@@ -9877,13 +10805,12 @@ Case.prototype.eachChild = function eachChild(fn) {
|
|
|
9877
10805
|
}
|
|
9878
10806
|
fn(this.otherwise);
|
|
9879
10807
|
};
|
|
9880
|
-
Case.prototype.
|
|
9881
|
-
|
|
9882
|
-
return (ref = []).concat.apply(ref, this.branches.map(function (ref) {
|
|
10808
|
+
Case.prototype.outputDefined = function outputDefined() {
|
|
10809
|
+
return this.branches.every(function (ref) {
|
|
9883
10810
|
var _ = ref[0];
|
|
9884
10811
|
var out = ref[1];
|
|
9885
|
-
return out.
|
|
9886
|
-
})
|
|
10812
|
+
return out.outputDefined();
|
|
10813
|
+
}) && this.otherwise.outputDefined();
|
|
9887
10814
|
};
|
|
9888
10815
|
Case.prototype.serialize = function serialize() {
|
|
9889
10816
|
var serialized = ['case'];
|
|
@@ -10013,11 +10940,8 @@ function makeComparison(op, compareBasic, compareWithCollator) {
|
|
|
10013
10940
|
fn(this.collator);
|
|
10014
10941
|
}
|
|
10015
10942
|
};
|
|
10016
|
-
Comparison.prototype.
|
|
10017
|
-
return
|
|
10018
|
-
true,
|
|
10019
|
-
false
|
|
10020
|
-
];
|
|
10943
|
+
Comparison.prototype.outputDefined = function outputDefined() {
|
|
10944
|
+
return true;
|
|
10021
10945
|
};
|
|
10022
10946
|
Comparison.prototype.serialize = function serialize() {
|
|
10023
10947
|
var serialized = [op];
|
|
@@ -10109,8 +11033,8 @@ NumberFormat.prototype.eachChild = function eachChild(fn) {
|
|
|
10109
11033
|
fn(this.maxFractionDigits);
|
|
10110
11034
|
}
|
|
10111
11035
|
};
|
|
10112
|
-
NumberFormat.prototype.
|
|
10113
|
-
return
|
|
11036
|
+
NumberFormat.prototype.outputDefined = function outputDefined() {
|
|
11037
|
+
return false;
|
|
10114
11038
|
};
|
|
10115
11039
|
NumberFormat.prototype.serialize = function serialize() {
|
|
10116
11040
|
var options = {};
|
|
@@ -10163,8 +11087,8 @@ Length.prototype.evaluate = function evaluate(ctx) {
|
|
|
10163
11087
|
Length.prototype.eachChild = function eachChild(fn) {
|
|
10164
11088
|
fn(this.input);
|
|
10165
11089
|
};
|
|
10166
|
-
Length.prototype.
|
|
10167
|
-
return
|
|
11090
|
+
Length.prototype.outputDefined = function outputDefined() {
|
|
11091
|
+
return false;
|
|
10168
11092
|
};
|
|
10169
11093
|
Length.prototype.serialize = function serialize() {
|
|
10170
11094
|
var serialized = ['length'];
|
|
@@ -10206,7 +11130,8 @@ var expressions = {
|
|
|
10206
11130
|
'to-color': Coercion,
|
|
10207
11131
|
'to-number': Coercion,
|
|
10208
11132
|
'to-string': Coercion,
|
|
10209
|
-
'var': Var
|
|
11133
|
+
'var': Var,
|
|
11134
|
+
'within': Within
|
|
10210
11135
|
};
|
|
10211
11136
|
function rgba(ctx, ref) {
|
|
10212
11137
|
var r = ref[0];
|
|
@@ -10765,7 +11690,7 @@ CompoundExpression.register(expressions, {
|
|
|
10765
11690
|
BooleanType,
|
|
10766
11691
|
[],
|
|
10767
11692
|
function (ctx) {
|
|
10768
|
-
return ctx.id() !== null;
|
|
11693
|
+
return ctx.id() !== null && ctx.id() !== undefined;
|
|
10769
11694
|
}
|
|
10770
11695
|
],
|
|
10771
11696
|
'filter-type-in': [
|
|
@@ -11194,18 +12119,20 @@ var StyleExpression = function StyleExpression(expression, propertySpec) {
|
|
|
11194
12119
|
this._defaultValue = propertySpec ? getDefaultValue(propertySpec) : null;
|
|
11195
12120
|
this._enumValues = propertySpec && propertySpec.type === 'enum' ? propertySpec.values : null;
|
|
11196
12121
|
};
|
|
11197
|
-
StyleExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, availableImages, formattedSection) {
|
|
12122
|
+
StyleExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection) {
|
|
11198
12123
|
this._evaluator.globals = globals;
|
|
11199
12124
|
this._evaluator.feature = feature;
|
|
11200
12125
|
this._evaluator.featureState = featureState;
|
|
12126
|
+
this._evaluator.canonical = canonical;
|
|
11201
12127
|
this._evaluator.availableImages = availableImages || null;
|
|
11202
12128
|
this._evaluator.formattedSection = formattedSection;
|
|
11203
12129
|
return this.expression.evaluate(this._evaluator);
|
|
11204
12130
|
};
|
|
11205
|
-
StyleExpression.prototype.evaluate = function evaluate(globals, feature, featureState, availableImages, formattedSection) {
|
|
12131
|
+
StyleExpression.prototype.evaluate = function evaluate(globals, feature, featureState, canonical, availableImages, formattedSection) {
|
|
11206
12132
|
this._evaluator.globals = globals;
|
|
11207
12133
|
this._evaluator.feature = feature || null;
|
|
11208
12134
|
this._evaluator.featureState = featureState || null;
|
|
12135
|
+
this._evaluator.canonical = canonical;
|
|
11209
12136
|
this._evaluator.availableImages = availableImages || null;
|
|
11210
12137
|
this._evaluator.formattedSection = formattedSection || null;
|
|
11211
12138
|
try {
|
|
@@ -11245,11 +12172,11 @@ var ZoomConstantExpression = function ZoomConstantExpression(kind, expression) {
|
|
|
11245
12172
|
this._styleExpression = expression;
|
|
11246
12173
|
this.isStateDependent = kind !== 'constant' && !isStateConstant(expression.expression);
|
|
11247
12174
|
};
|
|
11248
|
-
ZoomConstantExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, availableImages, formattedSection) {
|
|
11249
|
-
return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, availableImages, formattedSection);
|
|
12175
|
+
ZoomConstantExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection) {
|
|
12176
|
+
return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
|
|
11250
12177
|
};
|
|
11251
|
-
ZoomConstantExpression.prototype.evaluate = function evaluate(globals, feature, featureState, availableImages, formattedSection) {
|
|
11252
|
-
return this._styleExpression.evaluate(globals, feature, featureState, availableImages, formattedSection);
|
|
12178
|
+
ZoomConstantExpression.prototype.evaluate = function evaluate(globals, feature, featureState, canonical, availableImages, formattedSection) {
|
|
12179
|
+
return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
|
|
11253
12180
|
};
|
|
11254
12181
|
var ZoomDependentExpression = function ZoomDependentExpression(kind, expression, zoomStops, interpolationType) {
|
|
11255
12182
|
this.kind = kind;
|
|
@@ -11258,11 +12185,11 @@ var ZoomDependentExpression = function ZoomDependentExpression(kind, expression,
|
|
|
11258
12185
|
this.isStateDependent = kind !== 'camera' && !isStateConstant(expression.expression);
|
|
11259
12186
|
this.interpolationType = interpolationType;
|
|
11260
12187
|
};
|
|
11261
|
-
ZoomDependentExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, availableImages, formattedSection) {
|
|
11262
|
-
return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, availableImages, formattedSection);
|
|
12188
|
+
ZoomDependentExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection) {
|
|
12189
|
+
return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
|
|
11263
12190
|
};
|
|
11264
|
-
ZoomDependentExpression.prototype.evaluate = function evaluate(globals, feature, featureState, availableImages, formattedSection) {
|
|
11265
|
-
return this._styleExpression.evaluate(globals, feature, featureState, availableImages, formattedSection);
|
|
12191
|
+
ZoomDependentExpression.prototype.evaluate = function evaluate(globals, feature, featureState, canonical, availableImages, formattedSection) {
|
|
12192
|
+
return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
|
|
11266
12193
|
};
|
|
11267
12194
|
ZoomDependentExpression.prototype.interpolationFactor = function interpolationFactor(input, lower, upper) {
|
|
11268
12195
|
if (this.interpolationType) {
|
|
@@ -11708,7 +12635,7 @@ function isExpressionFilter(filter) {
|
|
|
11708
12635
|
case 'has':
|
|
11709
12636
|
return filter.length >= 2 && filter[1] !== '$id' && filter[1] !== '$type';
|
|
11710
12637
|
case 'in':
|
|
11711
|
-
return filter.length >= 3 && Array.isArray(filter[2]);
|
|
12638
|
+
return filter.length >= 3 && (typeof filter[1] !== 'string' || Array.isArray(filter[2]));
|
|
11712
12639
|
case '!in':
|
|
11713
12640
|
case '!has':
|
|
11714
12641
|
case 'none':
|
|
@@ -11748,8 +12675,11 @@ var filterSpec = {
|
|
|
11748
12675
|
};
|
|
11749
12676
|
function createFilter(filter) {
|
|
11750
12677
|
if (filter === null || filter === undefined) {
|
|
11751
|
-
return
|
|
11752
|
-
|
|
12678
|
+
return {
|
|
12679
|
+
filter: function () {
|
|
12680
|
+
return true;
|
|
12681
|
+
},
|
|
12682
|
+
needGeometry: false
|
|
11753
12683
|
};
|
|
11754
12684
|
}
|
|
11755
12685
|
if (!isExpressionFilter(filter)) {
|
|
@@ -11761,8 +12691,12 @@ function createFilter(filter) {
|
|
|
11761
12691
|
return err.key + ': ' + err.message;
|
|
11762
12692
|
}).join(', '));
|
|
11763
12693
|
} else {
|
|
11764
|
-
|
|
11765
|
-
|
|
12694
|
+
var needGeometry = Array.isArray(filter) && filter.length !== 0 && filter[0] === 'within';
|
|
12695
|
+
return {
|
|
12696
|
+
filter: function (globalProperties, feature, canonical) {
|
|
12697
|
+
return compiled.value.evaluate(globalProperties, feature, {}, canonical);
|
|
12698
|
+
},
|
|
12699
|
+
needGeometry: needGeometry
|
|
11766
12700
|
};
|
|
11767
12701
|
}
|
|
11768
12702
|
}
|
|
@@ -12195,36 +13129,6 @@ function derefLayers(layers) {
|
|
|
12195
13129
|
return layers;
|
|
12196
13130
|
}
|
|
12197
13131
|
|
|
12198
|
-
function deepEqual(a, b) {
|
|
12199
|
-
if (Array.isArray(a)) {
|
|
12200
|
-
if (!Array.isArray(b) || a.length !== b.length) {
|
|
12201
|
-
return false;
|
|
12202
|
-
}
|
|
12203
|
-
for (var i = 0; i < a.length; i++) {
|
|
12204
|
-
if (!deepEqual(a[i], b[i])) {
|
|
12205
|
-
return false;
|
|
12206
|
-
}
|
|
12207
|
-
}
|
|
12208
|
-
return true;
|
|
12209
|
-
}
|
|
12210
|
-
if (typeof a === 'object' && a !== null && b !== null) {
|
|
12211
|
-
if (!(typeof b === 'object')) {
|
|
12212
|
-
return false;
|
|
12213
|
-
}
|
|
12214
|
-
var keys = Object.keys(a);
|
|
12215
|
-
if (keys.length !== Object.keys(b).length) {
|
|
12216
|
-
return false;
|
|
12217
|
-
}
|
|
12218
|
-
for (var key in a) {
|
|
12219
|
-
if (!deepEqual(a[key], b[key])) {
|
|
12220
|
-
return false;
|
|
12221
|
-
}
|
|
12222
|
-
}
|
|
12223
|
-
return true;
|
|
12224
|
-
}
|
|
12225
|
-
return a === b;
|
|
12226
|
-
}
|
|
12227
|
-
|
|
12228
13132
|
var operations = {
|
|
12229
13133
|
setStyle: 'setStyle',
|
|
12230
13134
|
addLayer: 'addLayer',
|
|
@@ -12915,7 +13819,7 @@ function validateExpression(options) {
|
|
|
12915
13819
|
});
|
|
12916
13820
|
}
|
|
12917
13821
|
var expressionObj = expression.value.expression || expression.value._styleExpression.expression;
|
|
12918
|
-
if (options.expressionContext === 'property' && options.propertyKey === 'text-font' && expressionObj.
|
|
13822
|
+
if (options.expressionContext === 'property' && options.propertyKey === 'text-font' && !expressionObj.outputDefined()) {
|
|
12919
13823
|
return [new ValidationError(options.key, options.value, 'Invalid data expression for "' + options.propertyKey + '". Output values must be contained as literals within the expression.')];
|
|
12920
13824
|
}
|
|
12921
13825
|
if (options.expressionContext === 'property' && options.propertyType === 'layout' && !isStateConstant(expressionObj)) {
|