@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.
Files changed (43) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/index.es.js +1201 -297
  3. package/dist/index.es.js.map +1 -1
  4. package/dist/index.js +1201 -297
  5. package/dist/index.js.map +1 -1
  6. package/expression/compound_expression.js +5 -5
  7. package/expression/definitions/assertion.js +3 -4
  8. package/expression/definitions/at.js +3 -3
  9. package/expression/definitions/case.js +3 -6
  10. package/expression/definitions/coalesce.js +3 -4
  11. package/expression/definitions/coercion.js +3 -4
  12. package/expression/definitions/collator.js +5 -5
  13. package/expression/definitions/comparison.js +3 -3
  14. package/expression/definitions/format.js +3 -3
  15. package/expression/definitions/format_section_override.js +3 -4
  16. package/expression/definitions/image.js +6 -8
  17. package/expression/definitions/in.js +4 -4
  18. package/expression/definitions/index.js +4 -2
  19. package/expression/definitions/interpolate.js +3 -4
  20. package/expression/definitions/length.js +3 -3
  21. package/expression/definitions/let.js +3 -3
  22. package/expression/definitions/literal.js +2 -2
  23. package/expression/definitions/match.js +3 -6
  24. package/expression/definitions/number_format.js +3 -3
  25. package/expression/definitions/step.js +3 -4
  26. package/expression/definitions/var.js +2 -2
  27. package/expression/definitions/within.js +297 -0
  28. package/expression/evaluation_context.js +12 -1
  29. package/expression/expression.js +3 -5
  30. package/expression/index.js +24 -19
  31. package/expression/is_constant.js +5 -1
  32. package/expression/parsing_context.js +3 -0
  33. package/expression/scope.js +1 -1
  34. package/expression/types/resolved_image.js +2 -1
  35. package/feature_filter/convert.js +1 -1
  36. package/feature_filter/index.js +10 -5
  37. package/flow-typed/vector-tile.js +2 -2
  38. package/package.json +2 -1
  39. package/reference/v8.json +10 -1
  40. package/style-spec.js +1 -1
  41. package/types.js +2 -2
  42. package/validate/validate_expression.js +1 -1
  43. package/visit.js +2 -2
package/dist/index.js CHANGED
@@ -1006,7 +1006,7 @@
1006
1006
  },
1007
1007
  "symbol-sort-key": {
1008
1008
  type: "number",
1009
- doc: "Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key when they overlap. Features with a lower sort key will have priority over other features when doing placement.",
1009
+ 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.",
1010
1010
  "sdk-support": {
1011
1011
  "basic functionality": {
1012
1012
  js: "0.53.0",
@@ -3373,6 +3373,15 @@
3373
3373
  }
3374
3374
  }
3375
3375
  },
3376
+ within: {
3377
+ 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.",
3378
+ group: "Decision",
3379
+ "sdk-support": {
3380
+ "basic functionality": {
3381
+ js: "1.9.0"
3382
+ }
3383
+ }
3384
+ },
3376
3385
  "is-supported-script": {
3377
3386
  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).",
3378
3387
  group: "String",
@@ -8020,6 +8029,9 @@
8020
8029
  return this.name;
8021
8030
  };
8022
8031
  ResolvedImage.fromString = function fromString(name) {
8032
+ if (!name) {
8033
+ return null;
8034
+ }
8023
8035
  return new ResolvedImage({
8024
8036
  name: name,
8025
8037
  available: false
@@ -8166,8 +8178,8 @@
8166
8178
  };
8167
8179
  Literal.prototype.eachChild = function eachChild() {
8168
8180
  };
8169
- Literal.prototype.possibleOutputs = function possibleOutputs() {
8170
- return [this.value];
8181
+ Literal.prototype.outputDefined = function outputDefined() {
8182
+ return true;
8171
8183
  };
8172
8184
  Literal.prototype.serialize = function serialize() {
8173
8185
  if (this.type.kind === 'array' || this.type.kind === 'object') {
@@ -8258,11 +8270,10 @@
8258
8270
  Assertion.prototype.eachChild = function eachChild(fn) {
8259
8271
  this.args.forEach(fn);
8260
8272
  };
8261
- Assertion.prototype.possibleOutputs = function possibleOutputs() {
8262
- var ref;
8263
- return (ref = []).concat.apply(ref, this.args.map(function (arg) {
8264
- return arg.possibleOutputs();
8265
- }));
8273
+ Assertion.prototype.outputDefined = function outputDefined() {
8274
+ return this.args.every(function (arg) {
8275
+ return arg.outputDefined();
8276
+ });
8266
8277
  };
8267
8278
  Assertion.prototype.serialize = function serialize() {
8268
8279
  var type = this.type;
@@ -8370,8 +8381,8 @@
8370
8381
  }
8371
8382
  }
8372
8383
  };
8373
- FormatExpression.prototype.possibleOutputs = function possibleOutputs() {
8374
- return [undefined];
8384
+ FormatExpression.prototype.outputDefined = function outputDefined() {
8385
+ return false;
8375
8386
  };
8376
8387
  FormatExpression.prototype.serialize = function serialize() {
8377
8388
  var serialized = ['format'];
@@ -8409,20 +8420,17 @@
8409
8420
  };
8410
8421
  ImageExpression.prototype.evaluate = function evaluate(ctx) {
8411
8422
  var evaluatedImageName = this.input.evaluate(ctx);
8412
- var available = false;
8413
- if (ctx.availableImages && ctx.availableImages.indexOf(evaluatedImageName) > -1) {
8414
- available = true;
8423
+ var value = ResolvedImage.fromString(evaluatedImageName);
8424
+ if (value && ctx.availableImages) {
8425
+ value.available = ctx.availableImages.indexOf(evaluatedImageName) > -1;
8415
8426
  }
8416
- return new ResolvedImage({
8417
- name: evaluatedImageName,
8418
- available: available
8419
- });
8427
+ return value;
8420
8428
  };
8421
8429
  ImageExpression.prototype.eachChild = function eachChild(fn) {
8422
8430
  fn(this.input);
8423
8431
  };
8424
- ImageExpression.prototype.possibleOutputs = function possibleOutputs() {
8425
- return [undefined];
8432
+ ImageExpression.prototype.outputDefined = function outputDefined() {
8433
+ return false;
8426
8434
  };
8427
8435
  ImageExpression.prototype.serialize = function serialize() {
8428
8436
  return [
@@ -8515,11 +8523,10 @@
8515
8523
  Coercion.prototype.eachChild = function eachChild(fn) {
8516
8524
  this.args.forEach(fn);
8517
8525
  };
8518
- Coercion.prototype.possibleOutputs = function possibleOutputs() {
8519
- var ref;
8520
- return (ref = []).concat.apply(ref, this.args.map(function (arg) {
8521
- return arg.possibleOutputs();
8522
- }));
8526
+ Coercion.prototype.outputDefined = function outputDefined() {
8527
+ return this.args.every(function (arg) {
8528
+ return arg.outputDefined();
8529
+ });
8523
8530
  };
8524
8531
  Coercion.prototype.serialize = function serialize() {
8525
8532
  if (this.type.kind === 'formatted') {
@@ -8553,6 +8560,7 @@
8553
8560
  this.formattedSection = null;
8554
8561
  this._parseColorCache = {};
8555
8562
  this.availableImages = null;
8563
+ this.canonical = null;
8556
8564
  };
8557
8565
  EvaluationContext.prototype.id = function id() {
8558
8566
  return this.feature && 'id' in this.feature ? this.feature.id : null;
@@ -8560,6 +8568,12 @@
8560
8568
  EvaluationContext.prototype.geometryType = function geometryType() {
8561
8569
  return this.feature ? typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : this.feature.type : null;
8562
8570
  };
8571
+ EvaluationContext.prototype.geometry = function geometry() {
8572
+ return this.feature && 'geometry' in this.feature ? this.feature.geometry : null;
8573
+ };
8574
+ EvaluationContext.prototype.canonicalID = function canonicalID() {
8575
+ return this.canonical;
8576
+ };
8563
8577
  EvaluationContext.prototype.properties = function properties() {
8564
8578
  return this.feature && this.feature.properties || {};
8565
8579
  };
@@ -8583,8 +8597,8 @@
8583
8597
  CompoundExpression.prototype.eachChild = function eachChild(fn) {
8584
8598
  this.args.forEach(fn);
8585
8599
  };
8586
- CompoundExpression.prototype.possibleOutputs = function possibleOutputs() {
8587
- return [undefined];
8600
+ CompoundExpression.prototype.outputDefined = function outputDefined() {
8601
+ return false;
8588
8602
  };
8589
8603
  CompoundExpression.prototype.serialize = function serialize() {
8590
8604
  return [this.name].concat(this.args.map(function (arg) {
@@ -8718,8 +8732,8 @@
8718
8732
  fn(this.locale);
8719
8733
  }
8720
8734
  };
8721
- CollatorExpression.prototype.possibleOutputs = function possibleOutputs() {
8722
- return [undefined];
8735
+ CollatorExpression.prototype.outputDefined = function outputDefined() {
8736
+ return false;
8723
8737
  };
8724
8738
  CollatorExpression.prototype.serialize = function serialize() {
8725
8739
  var options = {};
@@ -8734,94 +8748,1119 @@
8734
8748
  ];
8735
8749
  };
8736
8750
 
8737
- function isFeatureConstant(e) {
8738
- if (e instanceof CompoundExpression) {
8739
- if (e.name === 'get' && e.args.length === 1) {
8740
- return false;
8741
- } else if (e.name === 'feature-state') {
8742
- return false;
8743
- } else if (e.name === 'has' && e.args.length === 1) {
8744
- return false;
8745
- } else if (e.name === 'properties' || e.name === 'geometry-type' || e.name === 'id') {
8746
- return false;
8747
- } else if (/^filter-/.test(e.name)) {
8751
+ /*
8752
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
8753
+ *
8754
+ * Redistribution and use in source and binary forms, with or without
8755
+ * modification, are permitted provided that the following conditions
8756
+ * are met:
8757
+ * 1. Redistributions of source code must retain the above copyright
8758
+ * notice, this list of conditions and the following disclaimer.
8759
+ * 2. Redistributions in binary form must reproduce the above copyright
8760
+ * notice, this list of conditions and the following disclaimer in the
8761
+ * documentation and/or other materials provided with the distribution.
8762
+ *
8763
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
8764
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8765
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
8766
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
8767
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
8768
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
8769
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
8770
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
8771
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8772
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
8773
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8774
+ *
8775
+ * Ported from Webkit
8776
+ * http://svn.webkit.org/repository/webkit/trunk/Source/WebCore/platform/graphics/UnitBezier.h
8777
+ */
8778
+
8779
+ var unitbezier = UnitBezier;
8780
+
8781
+ function UnitBezier(p1x, p1y, p2x, p2y) {
8782
+ // Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1).
8783
+ this.cx = 3.0 * p1x;
8784
+ this.bx = 3.0 * (p2x - p1x) - this.cx;
8785
+ this.ax = 1.0 - this.cx - this.bx;
8786
+
8787
+ this.cy = 3.0 * p1y;
8788
+ this.by = 3.0 * (p2y - p1y) - this.cy;
8789
+ this.ay = 1.0 - this.cy - this.by;
8790
+
8791
+ this.p1x = p1x;
8792
+ this.p1y = p2y;
8793
+ this.p2x = p2x;
8794
+ this.p2y = p2y;
8795
+ }
8796
+
8797
+ UnitBezier.prototype.sampleCurveX = function(t) {
8798
+ // `ax t^3 + bx t^2 + cx t' expanded using Horner's rule.
8799
+ return ((this.ax * t + this.bx) * t + this.cx) * t;
8800
+ };
8801
+
8802
+ UnitBezier.prototype.sampleCurveY = function(t) {
8803
+ return ((this.ay * t + this.by) * t + this.cy) * t;
8804
+ };
8805
+
8806
+ UnitBezier.prototype.sampleCurveDerivativeX = function(t) {
8807
+ return (3.0 * this.ax * t + 2.0 * this.bx) * t + this.cx;
8808
+ };
8809
+
8810
+ UnitBezier.prototype.solveCurveX = function(x, epsilon) {
8811
+ if (typeof epsilon === 'undefined') { epsilon = 1e-6; }
8812
+
8813
+ var t0, t1, t2, x2, i;
8814
+
8815
+ // First try a few iterations of Newton's method -- normally very fast.
8816
+ for (t2 = x, i = 0; i < 8; i++) {
8817
+
8818
+ x2 = this.sampleCurveX(t2) - x;
8819
+ if (Math.abs(x2) < epsilon) { return t2; }
8820
+
8821
+ var d2 = this.sampleCurveDerivativeX(t2);
8822
+ if (Math.abs(d2) < 1e-6) { break; }
8823
+
8824
+ t2 = t2 - x2 / d2;
8825
+ }
8826
+
8827
+ // Fall back to the bisection method for reliability.
8828
+ t0 = 0.0;
8829
+ t1 = 1.0;
8830
+ t2 = x;
8831
+
8832
+ if (t2 < t0) { return t0; }
8833
+ if (t2 > t1) { return t1; }
8834
+
8835
+ while (t0 < t1) {
8836
+
8837
+ x2 = this.sampleCurveX(t2);
8838
+ if (Math.abs(x2 - x) < epsilon) { return t2; }
8839
+
8840
+ if (x > x2) {
8841
+ t0 = t2;
8842
+ } else {
8843
+ t1 = t2;
8844
+ }
8845
+
8846
+ t2 = (t1 - t0) * 0.5 + t0;
8847
+ }
8848
+
8849
+ // Failure.
8850
+ return t2;
8851
+ };
8852
+
8853
+ UnitBezier.prototype.solve = function(x, epsilon) {
8854
+ return this.sampleCurveY(this.solveCurveX(x, epsilon));
8855
+ };
8856
+
8857
+ function deepEqual(a, b) {
8858
+ if (Array.isArray(a)) {
8859
+ if (!Array.isArray(b) || a.length !== b.length) {
8748
8860
  return false;
8749
8861
  }
8862
+ for (var i = 0; i < a.length; i++) {
8863
+ if (!deepEqual(a[i], b[i])) {
8864
+ return false;
8865
+ }
8866
+ }
8867
+ return true;
8750
8868
  }
8751
- var result = true;
8752
- e.eachChild(function (arg) {
8753
- if (result && !isFeatureConstant(arg)) {
8754
- result = false;
8869
+ if (typeof a === 'object' && a !== null && b !== null) {
8870
+ if (!(typeof b === 'object')) {
8871
+ return false;
8755
8872
  }
8756
- });
8757
- return result;
8758
- }
8759
- function isStateConstant(e) {
8760
- if (e instanceof CompoundExpression) {
8761
- if (e.name === 'feature-state') {
8873
+ var keys = Object.keys(a);
8874
+ if (keys.length !== Object.keys(b).length) {
8762
8875
  return false;
8763
8876
  }
8764
- }
8765
- var result = true;
8766
- e.eachChild(function (arg) {
8767
- if (result && !isStateConstant(arg)) {
8768
- result = false;
8877
+ for (var key in a) {
8878
+ if (!deepEqual(a[key], b[key])) {
8879
+ return false;
8880
+ }
8769
8881
  }
8770
- });
8771
- return result;
8772
- }
8773
- function isGlobalPropertyConstant(e, properties) {
8774
- if (e instanceof CompoundExpression && properties.indexOf(e.name) >= 0) {
8775
- return false;
8882
+ return true;
8776
8883
  }
8777
- var result = true;
8778
- e.eachChild(function (arg) {
8779
- if (result && !isGlobalPropertyConstant(arg, properties)) {
8780
- result = false;
8781
- }
8782
- });
8783
- return result;
8884
+ return a === b;
8784
8885
  }
8785
8886
 
8786
- var Var = function Var(name, boundExpression) {
8787
- this.type = boundExpression.type;
8788
- this.name = name;
8789
- this.boundExpression = boundExpression;
8790
- };
8791
- Var.parse = function parse(args, context) {
8792
- if (args.length !== 2 || typeof args[1] !== 'string') {
8793
- return context.error('\'var\' expression requires exactly one string literal argument.');
8794
- }
8795
- var name = args[1];
8796
- if (!context.scope.has(name)) {
8797
- return context.error('Unknown variable "' + name + '". Make sure "' + name + '" has been bound in an enclosing "let" expression before using it.', 1);
8887
+ //
8888
+
8889
+ /**
8890
+ * constrain n to the given range, excluding the minimum, via modular arithmetic
8891
+ *
8892
+ * @param n value
8893
+ * @param min the minimum value to be returned, exclusive
8894
+ * @param max the maximum value to be returned, inclusive
8895
+ * @returns constrained number
8896
+ * @private
8897
+ */
8898
+ function wrap(n , min , max ) {
8899
+ var d = max - min;
8900
+ var w = ((n - min) % d + d) % d + min;
8901
+ return (w === min) ? max : w;
8902
+ }
8903
+
8904
+ //
8905
+
8906
+
8907
+
8908
+ /**
8909
+ * A `LngLatBounds` object represents a geographical bounding box,
8910
+ * defined by its southwest and northeast points in longitude and latitude.
8911
+ *
8912
+ * If no arguments are provided to the constructor, a `null` bounding box is created.
8913
+ *
8914
+ * Note that any Mapbox GL method that accepts a `LngLatBounds` object as an argument or option
8915
+ * can also accept an `Array` of two {@link LngLatLike} constructs and will perform an implicit conversion.
8916
+ * This flexible type is documented as {@link LngLatBoundsLike}.
8917
+ *
8918
+ * @param {LngLatLike} [sw] The southwest corner of the bounding box.
8919
+ * @param {LngLatLike} [ne] The northeast corner of the bounding box.
8920
+ * @example
8921
+ * var sw = new mapboxgl.LngLat(-73.9876, 40.7661);
8922
+ * var ne = new mapboxgl.LngLat(-73.9397, 40.8002);
8923
+ * var llb = new mapboxgl.LngLatBounds(sw, ne);
8924
+ */
8925
+ var LngLatBounds = function LngLatBounds(sw , ne ) {
8926
+ if (!sw) ; else if (ne) {
8927
+ this.setSouthWest(sw).setNorthEast(ne);
8928
+ } else if (sw.length === 4) {
8929
+ this.setSouthWest([sw[0], sw[1]]).setNorthEast([sw[2], sw[3]]);
8930
+ } else {
8931
+ this.setSouthWest(sw[0]).setNorthEast(sw[1]);
8798
8932
  }
8799
- return new Var(name, context.scope.get(name));
8800
8933
  };
8801
- Var.prototype.evaluate = function evaluate(ctx) {
8802
- return this.boundExpression.evaluate(ctx);
8934
+
8935
+ /**
8936
+ * Set the northeast corner of the bounding box
8937
+ *
8938
+ * @param {LngLatLike} ne a {@link LngLatLike} object describing the northeast corner of the bounding box.
8939
+ * @returns {LngLatBounds} `this`
8940
+ */
8941
+ LngLatBounds.prototype.setNorthEast = function setNorthEast (ne ) {
8942
+ this._ne = ne instanceof LngLat ? new LngLat(ne.lng, ne.lat) : LngLat.convert(ne);
8943
+ return this;
8803
8944
  };
8804
- Var.prototype.eachChild = function eachChild() {
8945
+
8946
+ /**
8947
+ * Set the southwest corner of the bounding box
8948
+ *
8949
+ * @param {LngLatLike} sw a {@link LngLatLike} object describing the southwest corner of the bounding box.
8950
+ * @returns {LngLatBounds} `this`
8951
+ */
8952
+ LngLatBounds.prototype.setSouthWest = function setSouthWest (sw ) {
8953
+ this._sw = sw instanceof LngLat ? new LngLat(sw.lng, sw.lat) : LngLat.convert(sw);
8954
+ return this;
8805
8955
  };
8806
- Var.prototype.possibleOutputs = function possibleOutputs() {
8807
- return [undefined];
8956
+
8957
+ /**
8958
+ * Extend the bounds to include a given LngLatLike or LngLatBoundsLike.
8959
+ *
8960
+ * @param {LngLatLike|LngLatBoundsLike} obj object to extend to
8961
+ * @returns {LngLatBounds} `this`
8962
+ */
8963
+ LngLatBounds.prototype.extend = function extend (obj ) {
8964
+ var sw = this._sw,
8965
+ ne = this._ne;
8966
+ var sw2, ne2;
8967
+
8968
+ if (obj instanceof LngLat) {
8969
+ sw2 = obj;
8970
+ ne2 = obj;
8971
+
8972
+ } else if (obj instanceof LngLatBounds) {
8973
+ sw2 = obj._sw;
8974
+ ne2 = obj._ne;
8975
+
8976
+ if (!sw2 || !ne2) { return this; }
8977
+
8978
+ } else {
8979
+ if (Array.isArray(obj)) {
8980
+ if (obj.length === 4 || obj.every(Array.isArray)) {
8981
+ var lngLatBoundsObj = ((obj ) );
8982
+ return this.extend(LngLatBounds.convert(lngLatBoundsObj));
8983
+ } else {
8984
+ var lngLatObj = ((obj ) );
8985
+ return this.extend(LngLat.convert(lngLatObj));
8986
+ }
8987
+ }
8988
+ return this;
8989
+ }
8990
+
8991
+ if (!sw && !ne) {
8992
+ this._sw = new LngLat(sw2.lng, sw2.lat);
8993
+ this._ne = new LngLat(ne2.lng, ne2.lat);
8994
+
8995
+ } else {
8996
+ sw.lng = Math.min(sw2.lng, sw.lng);
8997
+ sw.lat = Math.min(sw2.lat, sw.lat);
8998
+ ne.lng = Math.max(ne2.lng, ne.lng);
8999
+ ne.lat = Math.max(ne2.lat, ne.lat);
9000
+ }
9001
+
9002
+ return this;
8808
9003
  };
8809
- Var.prototype.serialize = function serialize() {
8810
- return [
8811
- 'var',
8812
- this.name
8813
- ];
9004
+
9005
+ /**
9006
+ * Returns the geographical coordinate equidistant from the bounding box's corners.
9007
+ *
9008
+ * @returns {LngLat} The bounding box's center.
9009
+ * @example
9010
+ * var llb = new mapboxgl.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
9011
+ * llb.getCenter(); // = LngLat {lng: -73.96365, lat: 40.78315}
9012
+ */
9013
+ LngLatBounds.prototype.getCenter = function getCenter () {
9014
+ return new LngLat((this._sw.lng + this._ne.lng) / 2, (this._sw.lat + this._ne.lat) / 2);
8814
9015
  };
8815
9016
 
8816
- var ParsingContext = function ParsingContext(registry, path, expectedType, scope, errors) {
8817
- if (path === void 0)
8818
- path = [];
8819
- if (scope === void 0)
8820
- scope = new Scope();
8821
- if (errors === void 0)
8822
- errors = [];
8823
- this.registry = registry;
8824
- this.path = path;
9017
+ /**
9018
+ * Returns the southwest corner of the bounding box.
9019
+ *
9020
+ * @returns {LngLat} The southwest corner of the bounding box.
9021
+ */
9022
+ LngLatBounds.prototype.getSouthWest = function getSouthWest () { return this._sw; };
9023
+
9024
+ /**
9025
+ * Returns the northeast corner of the bounding box.
9026
+ *
9027
+ * @returns {LngLat} The northeast corner of the bounding box.
9028
+ */
9029
+ LngLatBounds.prototype.getNorthEast = function getNorthEast () { return this._ne; };
9030
+
9031
+ /**
9032
+ * Returns the northwest corner of the bounding box.
9033
+ *
9034
+ * @returns {LngLat} The northwest corner of the bounding box.
9035
+ */
9036
+ LngLatBounds.prototype.getNorthWest = function getNorthWest () { return new LngLat(this.getWest(), this.getNorth()); };
9037
+
9038
+ /**
9039
+ * Returns the southeast corner of the bounding box.
9040
+ *
9041
+ * @returns {LngLat} The southeast corner of the bounding box.
9042
+ */
9043
+ LngLatBounds.prototype.getSouthEast = function getSouthEast () { return new LngLat(this.getEast(), this.getSouth()); };
9044
+
9045
+ /**
9046
+ * Returns the west edge of the bounding box.
9047
+ *
9048
+ * @returns {number} The west edge of the bounding box.
9049
+ */
9050
+ LngLatBounds.prototype.getWest = function getWest () { return this._sw.lng; };
9051
+
9052
+ /**
9053
+ * Returns the south edge of the bounding box.
9054
+ *
9055
+ * @returns {number} The south edge of the bounding box.
9056
+ */
9057
+ LngLatBounds.prototype.getSouth = function getSouth () { return this._sw.lat; };
9058
+
9059
+ /**
9060
+ * Returns the east edge of the bounding box.
9061
+ *
9062
+ * @returns {number} The east edge of the bounding box.
9063
+ */
9064
+ LngLatBounds.prototype.getEast = function getEast () { return this._ne.lng; };
9065
+
9066
+ /**
9067
+ * Returns the north edge of the bounding box.
9068
+ *
9069
+ * @returns {number} The north edge of the bounding box.
9070
+ */
9071
+ LngLatBounds.prototype.getNorth = function getNorth () { return this._ne.lat; };
9072
+
9073
+ /**
9074
+ * Returns the bounding box represented as an array.
9075
+ *
9076
+ * @returns {Array<Array<number>>} The bounding box represented as an array, consisting of the
9077
+ * southwest and northeast coordinates of the bounding represented as arrays of numbers.
9078
+ * @example
9079
+ * var llb = new mapboxgl.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
9080
+ * llb.toArray(); // = [[-73.9876, 40.7661], [-73.9397, 40.8002]]
9081
+ */
9082
+ LngLatBounds.prototype.toArray = function toArray () {
9083
+ return [this._sw.toArray(), this._ne.toArray()];
9084
+ };
9085
+
9086
+ /**
9087
+ * Return the bounding box represented as a string.
9088
+ *
9089
+ * @returns {string} The bounding box represents as a string of the format
9090
+ * `'LngLatBounds(LngLat(lng, lat), LngLat(lng, lat))'`.
9091
+ * @example
9092
+ * var llb = new mapboxgl.LngLatBounds([-73.9876, 40.7661], [-73.9397, 40.8002]);
9093
+ * llb.toString(); // = "LngLatBounds(LngLat(-73.9876, 40.7661), LngLat(-73.9397, 40.8002))"
9094
+ */
9095
+ LngLatBounds.prototype.toString = function toString () {
9096
+ return ("LngLatBounds(" + (this._sw.toString()) + ", " + (this._ne.toString()) + ")");
9097
+ };
9098
+
9099
+ /**
9100
+ * Check if the bounding box is an empty/`null`-type box.
9101
+ *
9102
+ * @returns {boolean} True if bounds have been defined, otherwise false.
9103
+ */
9104
+ LngLatBounds.prototype.isEmpty = function isEmpty () {
9105
+ return !(this._sw && this._ne);
9106
+ };
9107
+
9108
+ /**
9109
+ * Check if the point is within the bounding box.
9110
+ *
9111
+ * @param {LngLatLike} lnglat geographic point to check against.
9112
+ * @returns {boolean} True if the point is within the bounding box.
9113
+ */
9114
+ LngLatBounds.prototype.contains = function contains (lnglat ) {
9115
+ var ref = LngLat.convert(lnglat);
9116
+ var lng = ref.lng;
9117
+ var lat = ref.lat;
9118
+
9119
+ var containsLatitude = this._sw.lat <= lat && lat <= this._ne.lat;
9120
+ var containsLongitude = this._sw.lng <= lng && lng <= this._ne.lng;
9121
+ if (this._sw.lng > this._ne.lng) { // wrapped coordinates
9122
+ containsLongitude = this._sw.lng >= lng && lng >= this._ne.lng;
9123
+ }
9124
+
9125
+ return containsLatitude && containsLongitude;
9126
+ };
9127
+
9128
+ /**
9129
+ * Converts an array to a `LngLatBounds` object.
9130
+ *
9131
+ * If a `LngLatBounds` object is passed in, the function returns it unchanged.
9132
+ *
9133
+ * Internally, the function calls `LngLat#convert` to convert arrays to `LngLat` values.
9134
+ *
9135
+ * @param {LngLatBoundsLike} input An array of two coordinates to convert, or a `LngLatBounds` object to return.
9136
+ * @returns {LngLatBounds} A new `LngLatBounds` object, if a conversion occurred, or the original `LngLatBounds` object.
9137
+ * @example
9138
+ * var arr = [[-73.9876, 40.7661], [-73.9397, 40.8002]];
9139
+ * var llb = mapboxgl.LngLatBounds.convert(arr);
9140
+ * llb; // = LngLatBounds {_sw: LngLat {lng: -73.9876, lat: 40.7661}, _ne: LngLat {lng: -73.9397, lat: 40.8002}}
9141
+ */
9142
+ LngLatBounds.convert = function convert (input ) {
9143
+ if (!input || input instanceof LngLatBounds) { return input; }
9144
+ return new LngLatBounds(input);
9145
+ };
9146
+
9147
+ //
9148
+
9149
+ /*
9150
+ * Approximate radius of the earth in meters.
9151
+ * 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
9152
+ * 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
9153
+ */
9154
+ var earthRadius = 6371008.8;
9155
+
9156
+ /**
9157
+ * A `LngLat` object represents a given longitude and latitude coordinate, measured in degrees.
9158
+ *
9159
+ * Mapbox GL uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.
9160
+ *
9161
+ * Note that any Mapbox GL method that accepts a `LngLat` object as an argument or option
9162
+ * can also accept an `Array` of two numbers and will perform an implicit conversion.
9163
+ * This flexible type is documented as {@link LngLatLike}.
9164
+ *
9165
+ * @param {number} lng Longitude, measured in degrees.
9166
+ * @param {number} lat Latitude, measured in degrees.
9167
+ * @example
9168
+ * var ll = new mapboxgl.LngLat(-73.9749, 40.7736);
9169
+ * @see [Get coordinates of the mouse pointer](https://www.mapbox.com/mapbox-gl-js/example/mouse-position/)
9170
+ * @see [Display a popup](https://www.mapbox.com/mapbox-gl-js/example/popup/)
9171
+ * @see [Highlight features within a bounding box](https://www.mapbox.com/mapbox-gl-js/example/using-box-queryrenderedfeatures/)
9172
+ * @see [Create a timeline animation](https://www.mapbox.com/mapbox-gl-js/example/timeline-animation/)
9173
+ */
9174
+ var LngLat = function LngLat(lng , lat ) {
9175
+ if (isNaN(lng) || isNaN(lat)) {
9176
+ throw new Error(("Invalid LngLat object: (" + lng + ", " + lat + ")"));
9177
+ }
9178
+ this.lng = +lng;
9179
+ this.lat = +lat;
9180
+ if (this.lat > 90 || this.lat < -90) {
9181
+ throw new Error('Invalid LngLat latitude value: must be between -90 and 90');
9182
+ }
9183
+ };
9184
+
9185
+ /**
9186
+ * Returns a new `LngLat` object whose longitude is wrapped to the range (-180, 180).
9187
+ *
9188
+ * @returns {LngLat} The wrapped `LngLat` object.
9189
+ * @example
9190
+ * var ll = new mapboxgl.LngLat(286.0251, 40.7736);
9191
+ * var wrapped = ll.wrap();
9192
+ * wrapped.lng; // = -73.9749
9193
+ */
9194
+ LngLat.prototype.wrap = function wrap$1 () {
9195
+ return new LngLat(wrap(this.lng, -180, 180), this.lat);
9196
+ };
9197
+
9198
+ /**
9199
+ * Returns the coordinates represented as an array of two numbers.
9200
+ *
9201
+ * @returns {Array<number>} The coordinates represeted as an array of longitude and latitude.
9202
+ * @example
9203
+ * var ll = new mapboxgl.LngLat(-73.9749, 40.7736);
9204
+ * ll.toArray(); // = [-73.9749, 40.7736]
9205
+ */
9206
+ LngLat.prototype.toArray = function toArray () {
9207
+ return [this.lng, this.lat];
9208
+ };
9209
+
9210
+ /**
9211
+ * Returns the coordinates represent as a string.
9212
+ *
9213
+ * @returns {string} The coordinates represented as a string of the format `'LngLat(lng, lat)'`.
9214
+ * @example
9215
+ * var ll = new mapboxgl.LngLat(-73.9749, 40.7736);
9216
+ * ll.toString(); // = "LngLat(-73.9749, 40.7736)"
9217
+ */
9218
+ LngLat.prototype.toString = function toString () {
9219
+ return ("LngLat(" + (this.lng) + ", " + (this.lat) + ")");
9220
+ };
9221
+
9222
+ /**
9223
+ * Returns the approximate distance between a pair of coordinates in meters
9224
+ * Uses the Haversine Formula (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159)
9225
+ *
9226
+ * @param {LngLat} lngLat coordinates to compute the distance to
9227
+ * @returns {number} Distance in meters between the two coordinates.
9228
+ * @example
9229
+ * var new_york = new mapboxgl.LngLat(-74.0060, 40.7128);
9230
+ * var los_angeles = new mapboxgl.LngLat(-118.2437, 34.0522);
9231
+ * new_york.distanceTo(los_angeles); // = 3935751.690893987, "true distance" using a non-spherical approximation is ~3966km
9232
+ */
9233
+ LngLat.prototype.distanceTo = function distanceTo (lngLat ) {
9234
+ var rad = Math.PI / 180;
9235
+ var lat1 = this.lat * rad;
9236
+ var lat2 = lngLat.lat * rad;
9237
+ var a = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos((lngLat.lng - this.lng) * rad);
9238
+
9239
+ var maxMeters = earthRadius * Math.acos(Math.min(a, 1));
9240
+ return maxMeters;
9241
+ };
9242
+
9243
+ /**
9244
+ * Returns a `LngLatBounds` from the coordinates extended by a given `radius`. The returned `LngLatBounds` completely contains the `radius`.
9245
+ *
9246
+ * @param {number} [radius=0] Distance in meters from the coordinates to extend the bounds.
9247
+ * @returns {LngLatBounds} A new `LngLatBounds` object representing the coordinates extended by the `radius`.
9248
+ * @example
9249
+ * var ll = new mapboxgl.LngLat(-73.9749, 40.7736);
9250
+ * ll.toBounds(100).toArray(); // = [[-73.97501862141328, 40.77351016847229], [-73.97478137858673, 40.77368983152771]]
9251
+ */
9252
+ LngLat.prototype.toBounds = function toBounds (radius) {
9253
+ if ( radius === void 0 ) radius = 0;
9254
+
9255
+ var earthCircumferenceInMetersAtEquator = 40075017;
9256
+ var latAccuracy = 360 * radius / earthCircumferenceInMetersAtEquator,
9257
+ lngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * this.lat);
9258
+
9259
+ return new LngLatBounds(new LngLat(this.lng - lngAccuracy, this.lat - latAccuracy),
9260
+ new LngLat(this.lng + lngAccuracy, this.lat + latAccuracy));
9261
+ };
9262
+
9263
+ /**
9264
+ * Converts an array of two numbers or an object with `lng` and `lat` or `lon` and `lat` properties
9265
+ * to a `LngLat` object.
9266
+ *
9267
+ * If a `LngLat` object is passed in, the function returns it unchanged.
9268
+ *
9269
+ * @param {LngLatLike} input An array of two numbers or object to convert, or a `LngLat` object to return.
9270
+ * @returns {LngLat} A new `LngLat` object, if a conversion occurred, or the original `LngLat` object.
9271
+ * @example
9272
+ * var arr = [-73.9749, 40.7736];
9273
+ * var ll = mapboxgl.LngLat.convert(arr);
9274
+ * ll; // = LngLat {lng: -73.9749, lat: 40.7736}
9275
+ */
9276
+ LngLat.convert = function convert (input ) {
9277
+ if (input instanceof LngLat) {
9278
+ return input;
9279
+ }
9280
+ if (Array.isArray(input) && (input.length === 2 || input.length === 3)) {
9281
+ return new LngLat(Number(input[0]), Number(input[1]));
9282
+ }
9283
+ if (!Array.isArray(input) && typeof input === 'object' && input !== null) {
9284
+ return new LngLat(
9285
+ // flow can't refine this to have one of lng or lat, so we have to cast to any
9286
+ Number('lng' in input ? (input ).lng : (input ).lon),
9287
+ Number(input.lat)
9288
+ );
9289
+ }
9290
+ 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>]");
9291
+ };
9292
+
9293
+ //
9294
+
9295
+
9296
+ /*
9297
+ * The average circumference of the world in meters.
9298
+ */
9299
+ var earthCircumfrence = 2 * Math.PI * earthRadius; // meters
9300
+
9301
+ /*
9302
+ * The circumference at a line of latitude in meters.
9303
+ */
9304
+ function circumferenceAtLatitude(latitude ) {
9305
+ return earthCircumfrence * Math.cos(latitude * Math.PI / 180);
9306
+ }
9307
+
9308
+ function mercatorXfromLng(lng ) {
9309
+ return (180 + lng) / 360;
9310
+ }
9311
+
9312
+ function mercatorYfromLat(lat ) {
9313
+ return (180 - (180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360)))) / 360;
9314
+ }
9315
+
9316
+ function mercatorZfromAltitude(altitude , lat ) {
9317
+ return altitude / circumferenceAtLatitude(lat);
9318
+ }
9319
+
9320
+ function lngFromMercatorX(x ) {
9321
+ return x * 360 - 180;
9322
+ }
9323
+
9324
+ function latFromMercatorY(y ) {
9325
+ var y2 = 180 - y * 360;
9326
+ return 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
9327
+ }
9328
+
9329
+ function altitudeFromMercatorZ(z , y ) {
9330
+ return z * circumferenceAtLatitude(latFromMercatorY(y));
9331
+ }
9332
+
9333
+ /**
9334
+ * Determine the Mercator scale factor for a given latitude, see
9335
+ * https://en.wikipedia.org/wiki/Mercator_projection#Scale_factor
9336
+ *
9337
+ * At the equator the scale factor will be 1, which increases at higher latitudes.
9338
+ *
9339
+ * @param {number} lat Latitude
9340
+ * @returns {number} scale factor
9341
+ * @private
9342
+ */
9343
+ function mercatorScale(lat ) {
9344
+ return 1 / Math.cos(lat * Math.PI / 180);
9345
+ }
9346
+
9347
+ /**
9348
+ * A `MercatorCoordinate` object represents a projected three dimensional position.
9349
+ *
9350
+ * `MercatorCoordinate` uses the web mercator projection ([EPSG:3857](https://epsg.io/3857)) with slightly different units:
9351
+ * - the size of 1 unit is the width of the projected world instead of the "mercator meter"
9352
+ * - the origin of the coordinate space is at the north-west corner instead of the middle
9353
+ *
9354
+ * For example, `MercatorCoordinate(0, 0, 0)` is the north-west corner of the mercator world and
9355
+ * `MercatorCoordinate(1, 1, 0)` is the south-east corner. If you are familiar with
9356
+ * [vector tiles](https://github.com/mapbox/vector-tile-spec) it may be helpful to think
9357
+ * of the coordinate space as the `0/0/0` tile with an extent of `1`.
9358
+ *
9359
+ * The `z` dimension of `MercatorCoordinate` is conformal. A cube in the mercator coordinate space would be rendered as a cube.
9360
+ *
9361
+ * @param {number} x The x component of the position.
9362
+ * @param {number} y The y component of the position.
9363
+ * @param {number} z The z component of the position.
9364
+ * @example
9365
+ * var nullIsland = new mapboxgl.MercatorCoordinate(0.5, 0.5, 0);
9366
+ *
9367
+ * @see [Add a custom style layer](https://www.mapbox.com/mapbox-gl-js/example/custom-style-layer/)
9368
+ */
9369
+ var MercatorCoordinate = function MercatorCoordinate(x , y , z) {
9370
+ if ( z === void 0 ) z = 0;
9371
+
9372
+ this.x = +x;
9373
+ this.y = +y;
9374
+ this.z = +z;
9375
+ };
9376
+
9377
+ /**
9378
+ * Project a `LngLat` to a `MercatorCoordinate`.
9379
+ *
9380
+ * @param {LngLatLike} lngLatLike The location to project.
9381
+ * @param {number} altitude The altitude in meters of the position.
9382
+ * @returns {MercatorCoordinate} The projected mercator coordinate.
9383
+ * @example
9384
+ * var coord = mapboxgl.MercatorCoordinate.fromLngLat({ lng: 0, lat: 0}, 0);
9385
+ * coord; // MercatorCoordinate(0.5, 0.5, 0)
9386
+ */
9387
+ MercatorCoordinate.fromLngLat = function fromLngLat (lngLatLike , altitude) {
9388
+ if ( altitude === void 0 ) altitude = 0;
9389
+
9390
+ var lngLat = LngLat.convert(lngLatLike);
9391
+
9392
+ return new MercatorCoordinate(
9393
+ mercatorXfromLng(lngLat.lng),
9394
+ mercatorYfromLat(lngLat.lat),
9395
+ mercatorZfromAltitude(altitude, lngLat.lat));
9396
+ };
9397
+
9398
+ /**
9399
+ * Returns the `LngLat` for the coordinate.
9400
+ *
9401
+ * @returns {LngLat} The `LngLat` object.
9402
+ * @example
9403
+ * var coord = new mapboxgl.MercatorCoordinate(0.5, 0.5, 0);
9404
+ * var latLng = coord.toLngLat(); // LngLat(0, 0)
9405
+ */
9406
+ MercatorCoordinate.prototype.toLngLat = function toLngLat () {
9407
+ return new LngLat(
9408
+ lngFromMercatorX(this.x),
9409
+ latFromMercatorY(this.y));
9410
+ };
9411
+
9412
+ /**
9413
+ * Returns the altitude in meters of the coordinate.
9414
+ *
9415
+ * @returns {number} The altitude in meters.
9416
+ * @example
9417
+ * var coord = new mapboxgl.MercatorCoordinate(0, 0, 0.02);
9418
+ * coord.toAltitude(); // 6914.281956295339
9419
+ */
9420
+ MercatorCoordinate.prototype.toAltitude = function toAltitude () {
9421
+ return altitudeFromMercatorZ(this.z, this.y);
9422
+ };
9423
+
9424
+ /**
9425
+ * Returns the distance of 1 meter in `MercatorCoordinate` units at this latitude.
9426
+ *
9427
+ * For coordinates in real world units using meters, this naturally provides the scale
9428
+ * to transform into `MercatorCoordinate`s.
9429
+ *
9430
+ * @returns {number} Distance of 1 meter in `MercatorCoordinate` units.
9431
+ */
9432
+ MercatorCoordinate.prototype.meterInMercatorCoordinateUnits = function meterInMercatorCoordinateUnits () {
9433
+ // 1 meter / circumference at equator in meters * Mercator projection scale factor at this latitude
9434
+ return 1 / earthCircumfrence * mercatorScale(latFromMercatorY(this.y));
9435
+ };
9436
+
9437
+ //
9438
+
9439
+ /**
9440
+ * The maximum value of a coordinate in the internal tile coordinate system. Coordinates of
9441
+ * all source features normalized to this extent upon load.
9442
+ *
9443
+ * The value is a consequence of the following:
9444
+ *
9445
+ * * Vertex buffer store positions as signed 16 bit integers.
9446
+ * * One bit is lost for signedness to support tile buffers.
9447
+ * * One bit is lost because the line vertex buffer used to pack 1 bit of other data into the int.
9448
+ * * One bit is lost to support features extending past the extent on the right edge of the tile.
9449
+ * * This leaves us with 2^13 = 8192
9450
+ *
9451
+ * @private
9452
+ * @readonly
9453
+ */
9454
+ var EXTENT = 8192;
9455
+
9456
+ function updateBBox(bbox, coord) {
9457
+ bbox[0] = Math.min(bbox[0], coord[0]);
9458
+ bbox[1] = Math.min(bbox[1], coord[1]);
9459
+ bbox[2] = Math.max(bbox[2], coord[0]);
9460
+ bbox[3] = Math.max(bbox[3], coord[1]);
9461
+ }
9462
+ function boxWithinBox(bbox1, bbox2) {
9463
+ if (bbox1[0] <= bbox2[0]) {
9464
+ return false;
9465
+ }
9466
+ if (bbox1[2] >= bbox2[2]) {
9467
+ return false;
9468
+ }
9469
+ if (bbox1[1] <= bbox2[1]) {
9470
+ return false;
9471
+ }
9472
+ if (bbox1[3] >= bbox2[3]) {
9473
+ return false;
9474
+ }
9475
+ return true;
9476
+ }
9477
+ function getTileCoordinates(p, canonical) {
9478
+ var coord = MercatorCoordinate.fromLngLat({
9479
+ lng: p[0],
9480
+ lat: p[1]
9481
+ }, 0);
9482
+ var tilesAtZoom = Math.pow(2, canonical.z);
9483
+ return [
9484
+ Math.round(coord.x * tilesAtZoom * EXTENT),
9485
+ Math.round(coord.y * tilesAtZoom * EXTENT)
9486
+ ];
9487
+ }
9488
+ function onBoundary(p, p1, p2) {
9489
+ var x1 = p[0] - p1[0];
9490
+ var y1 = p[1] - p1[1];
9491
+ var x2 = p[0] - p2[0];
9492
+ var y2 = p[1] - p2[1];
9493
+ return x1 * y2 - x2 * y1 === 0 && x1 * x2 <= 0 && y1 * y2 <= 0;
9494
+ }
9495
+ function rayIntersect(p, p1, p2) {
9496
+ 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];
9497
+ }
9498
+ function pointWithinPolygon(point, rings) {
9499
+ var inside = false;
9500
+ for (var i = 0, len = rings.length; i < len; i++) {
9501
+ var ring = rings[i];
9502
+ for (var j = 0, len2 = ring.length; j < len2 - 1; j++) {
9503
+ if (onBoundary(point, ring[j], ring[j + 1])) {
9504
+ return false;
9505
+ }
9506
+ if (rayIntersect(point, ring[j], ring[j + 1])) {
9507
+ inside = !inside;
9508
+ }
9509
+ }
9510
+ }
9511
+ return inside;
9512
+ }
9513
+ function pointWithinPolygons(point, polygons) {
9514
+ for (var i = 0; i < polygons.length; i++) {
9515
+ if (pointWithinPolygon(point, polygons[i])) {
9516
+ return true;
9517
+ }
9518
+ }
9519
+ return false;
9520
+ }
9521
+ function perp(v1, v2) {
9522
+ return v1[0] * v2[1] - v1[1] * v2[0];
9523
+ }
9524
+ function twoSided(p1, p2, q1, q2) {
9525
+ var x1 = p1[0] - q1[0];
9526
+ var y1 = p1[1] - q1[1];
9527
+ var x2 = p2[0] - q1[0];
9528
+ var y2 = p2[1] - q1[1];
9529
+ var x3 = q2[0] - q1[0];
9530
+ var y3 = q2[1] - q1[1];
9531
+ if ((x1 * y3 - x3 * y1) * (x2 * y3 - x3 * y2) < 0) {
9532
+ return true;
9533
+ }
9534
+ return false;
9535
+ }
9536
+ function lineIntersectLine(a, b, c, d) {
9537
+ var vectorP = [
9538
+ b[0] - a[0],
9539
+ b[1] - a[1]
9540
+ ];
9541
+ var vectorQ = [
9542
+ d[0] - c[0],
9543
+ d[1] - c[1]
9544
+ ];
9545
+ if (perp(vectorQ, vectorP) === 0) {
9546
+ return false;
9547
+ }
9548
+ if (twoSided(a, b, c, d) && twoSided(c, d, a, b)) {
9549
+ return true;
9550
+ }
9551
+ return false;
9552
+ }
9553
+ function lineIntersectPolygon(p1, p2, polygon) {
9554
+ for (var i = 0, list = polygon; i < list.length; i += 1) {
9555
+ var ring = list[i];
9556
+ for (var j = 0; j < ring.length - 1; ++j) {
9557
+ if (lineIntersectLine(p1, p2, ring[j], ring[j + 1])) {
9558
+ return true;
9559
+ }
9560
+ }
9561
+ }
9562
+ return false;
9563
+ }
9564
+ function lineStringWithinPolygon(line, polygon) {
9565
+ for (var i = 0; i < line.length; ++i) {
9566
+ if (!pointWithinPolygon(line[i], polygon)) {
9567
+ return false;
9568
+ }
9569
+ }
9570
+ for (var i$1 = 0; i$1 < line.length - 1; ++i$1) {
9571
+ if (lineIntersectPolygon(line[i$1], line[i$1 + 1], polygon)) {
9572
+ return false;
9573
+ }
9574
+ }
9575
+ return true;
9576
+ }
9577
+ function lineStringWithinPolygons(line, polygons) {
9578
+ for (var i = 0; i < polygons.length; i++) {
9579
+ if (lineStringWithinPolygon(line, polygons[i])) {
9580
+ return true;
9581
+ }
9582
+ }
9583
+ return false;
9584
+ }
9585
+ function getTilePolygon(coordinates, bbox, canonical) {
9586
+ var polygon = [];
9587
+ for (var i = 0; i < coordinates.length; i++) {
9588
+ var ring = [];
9589
+ for (var j = 0; j < coordinates[i].length; j++) {
9590
+ var coord = getTileCoordinates(coordinates[i][j], canonical);
9591
+ updateBBox(bbox, coord);
9592
+ ring.push(coord);
9593
+ }
9594
+ polygon.push(ring);
9595
+ }
9596
+ return polygon;
9597
+ }
9598
+ function getTilePolygons(coordinates, bbox, canonical) {
9599
+ var polygons = [];
9600
+ for (var i = 0; i < coordinates.length; i++) {
9601
+ var polygon = getTilePolygon(coordinates[i], bbox, canonical);
9602
+ polygons.push(polygon);
9603
+ }
9604
+ return polygons;
9605
+ }
9606
+ function pointsWithinPolygons(ctx, polygonGeometry) {
9607
+ var pointBBox = [
9608
+ Infinity,
9609
+ Infinity,
9610
+ -Infinity,
9611
+ -Infinity
9612
+ ];
9613
+ var polyBBox = [
9614
+ Infinity,
9615
+ Infinity,
9616
+ -Infinity,
9617
+ -Infinity
9618
+ ];
9619
+ var canonical = ctx.canonicalID();
9620
+ var shifts = [
9621
+ canonical.x * EXTENT,
9622
+ canonical.y * EXTENT
9623
+ ];
9624
+ var tilePoints = [];
9625
+ for (var i$1 = 0, list$1 = ctx.geometry(); i$1 < list$1.length; i$1 += 1) {
9626
+ var points = list$1[i$1];
9627
+ for (var i = 0, list = points; i < list.length; i += 1) {
9628
+ var point = list[i];
9629
+ var p = [
9630
+ point.x + shifts[0],
9631
+ point.y + shifts[1]
9632
+ ];
9633
+ updateBBox(pointBBox, p);
9634
+ tilePoints.push(p);
9635
+ }
9636
+ }
9637
+ if (polygonGeometry.type === 'Polygon') {
9638
+ var tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
9639
+ if (!boxWithinBox(pointBBox, polyBBox)) {
9640
+ return false;
9641
+ }
9642
+ for (var i$2 = 0, list$2 = tilePoints; i$2 < list$2.length; i$2 += 1) {
9643
+ var point$1 = list$2[i$2];
9644
+ if (!pointWithinPolygon(point$1, tilePolygon)) {
9645
+ return false;
9646
+ }
9647
+ }
9648
+ }
9649
+ if (polygonGeometry.type === 'MultiPolygon') {
9650
+ var tilePolygons = getTilePolygons(polygonGeometry.coordinates, polyBBox, canonical);
9651
+ if (!boxWithinBox(pointBBox, polyBBox)) {
9652
+ return false;
9653
+ }
9654
+ for (var i$3 = 0, list$3 = tilePoints; i$3 < list$3.length; i$3 += 1) {
9655
+ var point$2 = list$3[i$3];
9656
+ if (!pointWithinPolygons(point$2, tilePolygons)) {
9657
+ return false;
9658
+ }
9659
+ }
9660
+ }
9661
+ return true;
9662
+ }
9663
+ function linesWithinPolygons(ctx, polygonGeometry) {
9664
+ var lineBBox = [
9665
+ Infinity,
9666
+ Infinity,
9667
+ -Infinity,
9668
+ -Infinity
9669
+ ];
9670
+ var polyBBox = [
9671
+ Infinity,
9672
+ Infinity,
9673
+ -Infinity,
9674
+ -Infinity
9675
+ ];
9676
+ var canonical = ctx.canonicalID();
9677
+ var shifts = [
9678
+ canonical.x * EXTENT,
9679
+ canonical.y * EXTENT
9680
+ ];
9681
+ var tileLines = [];
9682
+ for (var i$1 = 0, list$1 = ctx.geometry(); i$1 < list$1.length; i$1 += 1) {
9683
+ var line = list$1[i$1];
9684
+ var tileLine = [];
9685
+ for (var i = 0, list = line; i < list.length; i += 1) {
9686
+ var point = list[i];
9687
+ var p = [
9688
+ point.x + shifts[0],
9689
+ point.y + shifts[1]
9690
+ ];
9691
+ updateBBox(lineBBox, p);
9692
+ tileLine.push(p);
9693
+ }
9694
+ tileLines.push(tileLine);
9695
+ }
9696
+ if (polygonGeometry.type === 'Polygon') {
9697
+ var tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
9698
+ if (!boxWithinBox(lineBBox, polyBBox)) {
9699
+ return false;
9700
+ }
9701
+ for (var i$2 = 0, list$2 = tileLines; i$2 < list$2.length; i$2 += 1) {
9702
+ var line$1 = list$2[i$2];
9703
+ if (!lineStringWithinPolygon(line$1, tilePolygon)) {
9704
+ return false;
9705
+ }
9706
+ }
9707
+ }
9708
+ if (polygonGeometry.type === 'MultiPolygon') {
9709
+ var tilePolygons = getTilePolygons(polygonGeometry.coordinates, polyBBox, canonical);
9710
+ if (!boxWithinBox(lineBBox, polyBBox)) {
9711
+ return false;
9712
+ }
9713
+ for (var i$3 = 0, list$3 = tileLines; i$3 < list$3.length; i$3 += 1) {
9714
+ var line$2 = list$3[i$3];
9715
+ if (!lineStringWithinPolygons(line$2, tilePolygons)) {
9716
+ return false;
9717
+ }
9718
+ }
9719
+ }
9720
+ return true;
9721
+ }
9722
+ var Within = function Within(geojson, geometries) {
9723
+ this.type = BooleanType;
9724
+ this.geojson = geojson;
9725
+ this.geometries = geometries;
9726
+ };
9727
+ Within.parse = function parse(args, context) {
9728
+ if (args.length !== 2) {
9729
+ return context.error('\'within\' expression requires exactly one argument, but found ' + (args.length - 1) + ' instead.');
9730
+ }
9731
+ if (isValue(args[1])) {
9732
+ var geojson = args[1];
9733
+ if (geojson.type === 'FeatureCollection') {
9734
+ for (var i = 0; i < geojson.features.length; ++i) {
9735
+ var type = geojson.features[i].geometry.type;
9736
+ if (type === 'Polygon' || type === 'MultiPolygon') {
9737
+ return new Within(geojson, geojson.features[i].geometry);
9738
+ }
9739
+ }
9740
+ } else if (geojson.type === 'Feature') {
9741
+ var type$1 = geojson.geometry.type;
9742
+ if (type$1 === 'Polygon' || type$1 === 'MultiPolygon') {
9743
+ return new Within(geojson, geojson.geometry);
9744
+ }
9745
+ } else if (geojson.type === 'Polygon' || geojson.type === 'MultiPolygon') {
9746
+ return new Within(geojson, geojson);
9747
+ }
9748
+ }
9749
+ return context.error('\'within\' expression requires valid geojson object that contains polygon geometry type.');
9750
+ };
9751
+ Within.prototype.evaluate = function evaluate(ctx) {
9752
+ if (ctx.geometry() != null && ctx.canonicalID() != null) {
9753
+ if (ctx.geometryType() === 'Point') {
9754
+ return pointsWithinPolygons(ctx, this.geometries);
9755
+ } else if (ctx.geometryType() === 'LineString') {
9756
+ return linesWithinPolygons(ctx, this.geometries);
9757
+ }
9758
+ }
9759
+ return false;
9760
+ };
9761
+ Within.prototype.eachChild = function eachChild() {
9762
+ };
9763
+ Within.prototype.outputDefined = function outputDefined() {
9764
+ return true;
9765
+ };
9766
+ Within.prototype.serialize = function serialize() {
9767
+ return [
9768
+ 'within',
9769
+ this.geojson
9770
+ ];
9771
+ };
9772
+
9773
+ function isFeatureConstant(e) {
9774
+ if (e instanceof CompoundExpression) {
9775
+ if (e.name === 'get' && e.args.length === 1) {
9776
+ return false;
9777
+ } else if (e.name === 'feature-state') {
9778
+ return false;
9779
+ } else if (e.name === 'has' && e.args.length === 1) {
9780
+ return false;
9781
+ } else if (e.name === 'properties' || e.name === 'geometry-type' || e.name === 'id') {
9782
+ return false;
9783
+ } else if (/^filter-/.test(e.name)) {
9784
+ return false;
9785
+ }
9786
+ }
9787
+ if (e instanceof Within) {
9788
+ return false;
9789
+ }
9790
+ var result = true;
9791
+ e.eachChild(function (arg) {
9792
+ if (result && !isFeatureConstant(arg)) {
9793
+ result = false;
9794
+ }
9795
+ });
9796
+ return result;
9797
+ }
9798
+ function isStateConstant(e) {
9799
+ if (e instanceof CompoundExpression) {
9800
+ if (e.name === 'feature-state') {
9801
+ return false;
9802
+ }
9803
+ }
9804
+ var result = true;
9805
+ e.eachChild(function (arg) {
9806
+ if (result && !isStateConstant(arg)) {
9807
+ result = false;
9808
+ }
9809
+ });
9810
+ return result;
9811
+ }
9812
+ function isGlobalPropertyConstant(e, properties) {
9813
+ if (e instanceof CompoundExpression && properties.indexOf(e.name) >= 0) {
9814
+ return false;
9815
+ }
9816
+ var result = true;
9817
+ e.eachChild(function (arg) {
9818
+ if (result && !isGlobalPropertyConstant(arg, properties)) {
9819
+ result = false;
9820
+ }
9821
+ });
9822
+ return result;
9823
+ }
9824
+
9825
+ var Var = function Var(name, boundExpression) {
9826
+ this.type = boundExpression.type;
9827
+ this.name = name;
9828
+ this.boundExpression = boundExpression;
9829
+ };
9830
+ Var.parse = function parse(args, context) {
9831
+ if (args.length !== 2 || typeof args[1] !== 'string') {
9832
+ return context.error('\'var\' expression requires exactly one string literal argument.');
9833
+ }
9834
+ var name = args[1];
9835
+ if (!context.scope.has(name)) {
9836
+ return context.error('Unknown variable "' + name + '". Make sure "' + name + '" has been bound in an enclosing "let" expression before using it.', 1);
9837
+ }
9838
+ return new Var(name, context.scope.get(name));
9839
+ };
9840
+ Var.prototype.evaluate = function evaluate(ctx) {
9841
+ return this.boundExpression.evaluate(ctx);
9842
+ };
9843
+ Var.prototype.eachChild = function eachChild() {
9844
+ };
9845
+ Var.prototype.outputDefined = function outputDefined() {
9846
+ return false;
9847
+ };
9848
+ Var.prototype.serialize = function serialize() {
9849
+ return [
9850
+ 'var',
9851
+ this.name
9852
+ ];
9853
+ };
9854
+
9855
+ var ParsingContext = function ParsingContext(registry, path, expectedType, scope, errors) {
9856
+ if (path === void 0)
9857
+ path = [];
9858
+ if (scope === void 0)
9859
+ scope = new Scope();
9860
+ if (errors === void 0)
9861
+ errors = [];
9862
+ this.registry = registry;
9863
+ this.path = path;
8825
9864
  this.key = path.map(function (part) {
8826
9865
  return '[' + part + ']';
8827
9866
  }).join('');
@@ -8927,6 +9966,8 @@
8927
9966
  return false;
8928
9967
  } else if (expression instanceof CollatorExpression) {
8929
9968
  return false;
9969
+ } else if (expression instanceof Within) {
9970
+ return false;
8930
9971
  }
8931
9972
  var isTypeAnnotation = expression instanceof Coercion || expression instanceof Assertion;
8932
9973
  var childrenConstant = true;
@@ -9049,11 +10090,10 @@
9049
10090
  fn(expression);
9050
10091
  }
9051
10092
  };
9052
- Step.prototype.possibleOutputs = function possibleOutputs() {
9053
- var ref;
9054
- return (ref = []).concat.apply(ref, this.outputs.map(function (output) {
9055
- return output.possibleOutputs();
9056
- }));
10093
+ Step.prototype.outputDefined = function outputDefined() {
10094
+ return this.outputs.every(function (out) {
10095
+ return out.outputDefined();
10096
+ });
9057
10097
  };
9058
10098
  Step.prototype.serialize = function serialize() {
9059
10099
  var serialized = [
@@ -9069,112 +10109,6 @@
9069
10109
  return serialized;
9070
10110
  };
9071
10111
 
9072
- /*
9073
- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
9074
- *
9075
- * Redistribution and use in source and binary forms, with or without
9076
- * modification, are permitted provided that the following conditions
9077
- * are met:
9078
- * 1. Redistributions of source code must retain the above copyright
9079
- * notice, this list of conditions and the following disclaimer.
9080
- * 2. Redistributions in binary form must reproduce the above copyright
9081
- * notice, this list of conditions and the following disclaimer in the
9082
- * documentation and/or other materials provided with the distribution.
9083
- *
9084
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
9085
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9086
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
9087
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
9088
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
9089
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
9090
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
9091
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
9092
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
9093
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
9094
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9095
- *
9096
- * Ported from Webkit
9097
- * http://svn.webkit.org/repository/webkit/trunk/Source/WebCore/platform/graphics/UnitBezier.h
9098
- */
9099
-
9100
- var unitbezier = UnitBezier;
9101
-
9102
- function UnitBezier(p1x, p1y, p2x, p2y) {
9103
- // Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1).
9104
- this.cx = 3.0 * p1x;
9105
- this.bx = 3.0 * (p2x - p1x) - this.cx;
9106
- this.ax = 1.0 - this.cx - this.bx;
9107
-
9108
- this.cy = 3.0 * p1y;
9109
- this.by = 3.0 * (p2y - p1y) - this.cy;
9110
- this.ay = 1.0 - this.cy - this.by;
9111
-
9112
- this.p1x = p1x;
9113
- this.p1y = p2y;
9114
- this.p2x = p2x;
9115
- this.p2y = p2y;
9116
- }
9117
-
9118
- UnitBezier.prototype.sampleCurveX = function(t) {
9119
- // `ax t^3 + bx t^2 + cx t' expanded using Horner's rule.
9120
- return ((this.ax * t + this.bx) * t + this.cx) * t;
9121
- };
9122
-
9123
- UnitBezier.prototype.sampleCurveY = function(t) {
9124
- return ((this.ay * t + this.by) * t + this.cy) * t;
9125
- };
9126
-
9127
- UnitBezier.prototype.sampleCurveDerivativeX = function(t) {
9128
- return (3.0 * this.ax * t + 2.0 * this.bx) * t + this.cx;
9129
- };
9130
-
9131
- UnitBezier.prototype.solveCurveX = function(x, epsilon) {
9132
- if (typeof epsilon === 'undefined') { epsilon = 1e-6; }
9133
-
9134
- var t0, t1, t2, x2, i;
9135
-
9136
- // First try a few iterations of Newton's method -- normally very fast.
9137
- for (t2 = x, i = 0; i < 8; i++) {
9138
-
9139
- x2 = this.sampleCurveX(t2) - x;
9140
- if (Math.abs(x2) < epsilon) { return t2; }
9141
-
9142
- var d2 = this.sampleCurveDerivativeX(t2);
9143
- if (Math.abs(d2) < 1e-6) { break; }
9144
-
9145
- t2 = t2 - x2 / d2;
9146
- }
9147
-
9148
- // Fall back to the bisection method for reliability.
9149
- t0 = 0.0;
9150
- t1 = 1.0;
9151
- t2 = x;
9152
-
9153
- if (t2 < t0) { return t0; }
9154
- if (t2 > t1) { return t1; }
9155
-
9156
- while (t0 < t1) {
9157
-
9158
- x2 = this.sampleCurveX(t2);
9159
- if (Math.abs(x2 - x) < epsilon) { return t2; }
9160
-
9161
- if (x > x2) {
9162
- t0 = t2;
9163
- } else {
9164
- t1 = t2;
9165
- }
9166
-
9167
- t2 = (t1 - t0) * 0.5 + t0;
9168
- }
9169
-
9170
- // Failure.
9171
- return t2;
9172
- };
9173
-
9174
- UnitBezier.prototype.solve = function(x, epsilon) {
9175
- return this.sampleCurveY(this.solveCurveX(x, epsilon));
9176
- };
9177
-
9178
10112
  function number(a, b, t) {
9179
10113
  return a * (1 - t) + b * t;
9180
10114
  }
@@ -9422,11 +10356,10 @@
9422
10356
  fn(expression);
9423
10357
  }
9424
10358
  };
9425
- Interpolate.prototype.possibleOutputs = function possibleOutputs() {
9426
- var ref;
9427
- return (ref = []).concat.apply(ref, this.outputs.map(function (output) {
9428
- return output.possibleOutputs();
9429
- }));
10359
+ Interpolate.prototype.outputDefined = function outputDefined() {
10360
+ return this.outputs.every(function (out) {
10361
+ return out.outputDefined();
10362
+ });
9430
10363
  };
9431
10364
  Interpolate.prototype.serialize = function serialize() {
9432
10365
  var interpolation;
@@ -9520,11 +10453,10 @@
9520
10453
  Coalesce.prototype.eachChild = function eachChild(fn) {
9521
10454
  this.args.forEach(fn);
9522
10455
  };
9523
- Coalesce.prototype.possibleOutputs = function possibleOutputs() {
9524
- var ref;
9525
- return (ref = []).concat.apply(ref, this.args.map(function (arg) {
9526
- return arg.possibleOutputs();
9527
- }));
10456
+ Coalesce.prototype.outputDefined = function outputDefined() {
10457
+ return this.args.every(function (arg) {
10458
+ return arg.outputDefined();
10459
+ });
9528
10460
  };
9529
10461
  Coalesce.prototype.serialize = function serialize() {
9530
10462
  var serialized = ['coalesce'];
@@ -9577,8 +10509,8 @@
9577
10509
  }
9578
10510
  return new Let(bindings, result);
9579
10511
  };
9580
- Let.prototype.possibleOutputs = function possibleOutputs() {
9581
- return this.result.possibleOutputs();
10512
+ Let.prototype.outputDefined = function outputDefined() {
10513
+ return this.result.outputDefined();
9582
10514
  };
9583
10515
  Let.prototype.serialize = function serialize() {
9584
10516
  var serialized = ['let'];
@@ -9627,8 +10559,8 @@
9627
10559
  fn(this.index);
9628
10560
  fn(this.input);
9629
10561
  };
9630
- At.prototype.possibleOutputs = function possibleOutputs() {
9631
- return [undefined];
10562
+ At.prototype.outputDefined = function outputDefined() {
10563
+ return false;
9632
10564
  };
9633
10565
  At.prototype.serialize = function serialize() {
9634
10566
  return [
@@ -9669,7 +10601,7 @@
9669
10601
  In.prototype.evaluate = function evaluate(ctx) {
9670
10602
  var needle = this.needle.evaluate(ctx);
9671
10603
  var haystack = this.haystack.evaluate(ctx);
9672
- if (!needle || !haystack) {
10604
+ if (needle == null || !haystack) {
9673
10605
  return false;
9674
10606
  }
9675
10607
  if (!isComparableRuntimeValue(needle)) {
@@ -9684,11 +10616,8 @@
9684
10616
  fn(this.needle);
9685
10617
  fn(this.haystack);
9686
10618
  };
9687
- In.prototype.possibleOutputs = function possibleOutputs() {
9688
- return [
9689
- true,
9690
- false
9691
- ];
10619
+ In.prototype.outputDefined = function outputDefined() {
10620
+ return true;
9692
10621
  };
9693
10622
  In.prototype.serialize = function serialize() {
9694
10623
  return [
@@ -9778,11 +10707,10 @@
9778
10707
  this.outputs.forEach(fn);
9779
10708
  fn(this.otherwise);
9780
10709
  };
9781
- Match.prototype.possibleOutputs = function possibleOutputs() {
9782
- var ref;
9783
- return (ref = []).concat.apply(ref, this.outputs.map(function (out) {
9784
- return out.possibleOutputs();
9785
- })).concat(this.otherwise.possibleOutputs());
10710
+ Match.prototype.outputDefined = function outputDefined() {
10711
+ return this.outputs.every(function (out) {
10712
+ return out.outputDefined();
10713
+ }) && this.otherwise.outputDefined();
9786
10714
  };
9787
10715
  Match.prototype.serialize = function serialize() {
9788
10716
  var this$1 = this;
@@ -9883,13 +10811,12 @@
9883
10811
  }
9884
10812
  fn(this.otherwise);
9885
10813
  };
9886
- Case.prototype.possibleOutputs = function possibleOutputs() {
9887
- var ref;
9888
- return (ref = []).concat.apply(ref, this.branches.map(function (ref) {
10814
+ Case.prototype.outputDefined = function outputDefined() {
10815
+ return this.branches.every(function (ref) {
9889
10816
  var _ = ref[0];
9890
10817
  var out = ref[1];
9891
- return out.possibleOutputs();
9892
- })).concat(this.otherwise.possibleOutputs());
10818
+ return out.outputDefined();
10819
+ }) && this.otherwise.outputDefined();
9893
10820
  };
9894
10821
  Case.prototype.serialize = function serialize() {
9895
10822
  var serialized = ['case'];
@@ -10019,11 +10946,8 @@
10019
10946
  fn(this.collator);
10020
10947
  }
10021
10948
  };
10022
- Comparison.prototype.possibleOutputs = function possibleOutputs() {
10023
- return [
10024
- true,
10025
- false
10026
- ];
10949
+ Comparison.prototype.outputDefined = function outputDefined() {
10950
+ return true;
10027
10951
  };
10028
10952
  Comparison.prototype.serialize = function serialize() {
10029
10953
  var serialized = [op];
@@ -10115,8 +11039,8 @@
10115
11039
  fn(this.maxFractionDigits);
10116
11040
  }
10117
11041
  };
10118
- NumberFormat.prototype.possibleOutputs = function possibleOutputs() {
10119
- return [undefined];
11042
+ NumberFormat.prototype.outputDefined = function outputDefined() {
11043
+ return false;
10120
11044
  };
10121
11045
  NumberFormat.prototype.serialize = function serialize() {
10122
11046
  var options = {};
@@ -10169,8 +11093,8 @@
10169
11093
  Length.prototype.eachChild = function eachChild(fn) {
10170
11094
  fn(this.input);
10171
11095
  };
10172
- Length.prototype.possibleOutputs = function possibleOutputs() {
10173
- return [undefined];
11096
+ Length.prototype.outputDefined = function outputDefined() {
11097
+ return false;
10174
11098
  };
10175
11099
  Length.prototype.serialize = function serialize() {
10176
11100
  var serialized = ['length'];
@@ -10212,7 +11136,8 @@
10212
11136
  'to-color': Coercion,
10213
11137
  'to-number': Coercion,
10214
11138
  'to-string': Coercion,
10215
- 'var': Var
11139
+ 'var': Var,
11140
+ 'within': Within
10216
11141
  };
10217
11142
  function rgba(ctx, ref) {
10218
11143
  var r = ref[0];
@@ -10771,7 +11696,7 @@
10771
11696
  BooleanType,
10772
11697
  [],
10773
11698
  function (ctx) {
10774
- return ctx.id() !== null;
11699
+ return ctx.id() !== null && ctx.id() !== undefined;
10775
11700
  }
10776
11701
  ],
10777
11702
  'filter-type-in': [
@@ -11200,18 +12125,20 @@
11200
12125
  this._defaultValue = propertySpec ? getDefaultValue(propertySpec) : null;
11201
12126
  this._enumValues = propertySpec && propertySpec.type === 'enum' ? propertySpec.values : null;
11202
12127
  };
11203
- StyleExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, availableImages, formattedSection) {
12128
+ StyleExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection) {
11204
12129
  this._evaluator.globals = globals;
11205
12130
  this._evaluator.feature = feature;
11206
12131
  this._evaluator.featureState = featureState;
12132
+ this._evaluator.canonical = canonical;
11207
12133
  this._evaluator.availableImages = availableImages || null;
11208
12134
  this._evaluator.formattedSection = formattedSection;
11209
12135
  return this.expression.evaluate(this._evaluator);
11210
12136
  };
11211
- StyleExpression.prototype.evaluate = function evaluate(globals, feature, featureState, availableImages, formattedSection) {
12137
+ StyleExpression.prototype.evaluate = function evaluate(globals, feature, featureState, canonical, availableImages, formattedSection) {
11212
12138
  this._evaluator.globals = globals;
11213
12139
  this._evaluator.feature = feature || null;
11214
12140
  this._evaluator.featureState = featureState || null;
12141
+ this._evaluator.canonical = canonical;
11215
12142
  this._evaluator.availableImages = availableImages || null;
11216
12143
  this._evaluator.formattedSection = formattedSection || null;
11217
12144
  try {
@@ -11251,11 +12178,11 @@
11251
12178
  this._styleExpression = expression;
11252
12179
  this.isStateDependent = kind !== 'constant' && !isStateConstant(expression.expression);
11253
12180
  };
11254
- ZoomConstantExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, availableImages, formattedSection) {
11255
- return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, availableImages, formattedSection);
12181
+ ZoomConstantExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection) {
12182
+ return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
11256
12183
  };
11257
- ZoomConstantExpression.prototype.evaluate = function evaluate(globals, feature, featureState, availableImages, formattedSection) {
11258
- return this._styleExpression.evaluate(globals, feature, featureState, availableImages, formattedSection);
12184
+ ZoomConstantExpression.prototype.evaluate = function evaluate(globals, feature, featureState, canonical, availableImages, formattedSection) {
12185
+ return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
11259
12186
  };
11260
12187
  var ZoomDependentExpression = function ZoomDependentExpression(kind, expression, zoomStops, interpolationType) {
11261
12188
  this.kind = kind;
@@ -11264,11 +12191,11 @@
11264
12191
  this.isStateDependent = kind !== 'camera' && !isStateConstant(expression.expression);
11265
12192
  this.interpolationType = interpolationType;
11266
12193
  };
11267
- ZoomDependentExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, availableImages, formattedSection) {
11268
- return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, availableImages, formattedSection);
12194
+ ZoomDependentExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection) {
12195
+ return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
11269
12196
  };
11270
- ZoomDependentExpression.prototype.evaluate = function evaluate(globals, feature, featureState, availableImages, formattedSection) {
11271
- return this._styleExpression.evaluate(globals, feature, featureState, availableImages, formattedSection);
12197
+ ZoomDependentExpression.prototype.evaluate = function evaluate(globals, feature, featureState, canonical, availableImages, formattedSection) {
12198
+ return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
11272
12199
  };
11273
12200
  ZoomDependentExpression.prototype.interpolationFactor = function interpolationFactor(input, lower, upper) {
11274
12201
  if (this.interpolationType) {
@@ -11714,7 +12641,7 @@
11714
12641
  case 'has':
11715
12642
  return filter.length >= 2 && filter[1] !== '$id' && filter[1] !== '$type';
11716
12643
  case 'in':
11717
- return filter.length >= 3 && Array.isArray(filter[2]);
12644
+ return filter.length >= 3 && (typeof filter[1] !== 'string' || Array.isArray(filter[2]));
11718
12645
  case '!in':
11719
12646
  case '!has':
11720
12647
  case 'none':
@@ -11754,8 +12681,11 @@
11754
12681
  };
11755
12682
  function createFilter(filter) {
11756
12683
  if (filter === null || filter === undefined) {
11757
- return function () {
11758
- return true;
12684
+ return {
12685
+ filter: function () {
12686
+ return true;
12687
+ },
12688
+ needGeometry: false
11759
12689
  };
11760
12690
  }
11761
12691
  if (!isExpressionFilter(filter)) {
@@ -11767,8 +12697,12 @@
11767
12697
  return err.key + ': ' + err.message;
11768
12698
  }).join(', '));
11769
12699
  } else {
11770
- return function (globalProperties, feature) {
11771
- return compiled.value.evaluate(globalProperties, feature);
12700
+ var needGeometry = Array.isArray(filter) && filter.length !== 0 && filter[0] === 'within';
12701
+ return {
12702
+ filter: function (globalProperties, feature, canonical) {
12703
+ return compiled.value.evaluate(globalProperties, feature, {}, canonical);
12704
+ },
12705
+ needGeometry: needGeometry
11772
12706
  };
11773
12707
  }
11774
12708
  }
@@ -12201,36 +13135,6 @@
12201
13135
  return layers;
12202
13136
  }
12203
13137
 
12204
- function deepEqual(a, b) {
12205
- if (Array.isArray(a)) {
12206
- if (!Array.isArray(b) || a.length !== b.length) {
12207
- return false;
12208
- }
12209
- for (var i = 0; i < a.length; i++) {
12210
- if (!deepEqual(a[i], b[i])) {
12211
- return false;
12212
- }
12213
- }
12214
- return true;
12215
- }
12216
- if (typeof a === 'object' && a !== null && b !== null) {
12217
- if (!(typeof b === 'object')) {
12218
- return false;
12219
- }
12220
- var keys = Object.keys(a);
12221
- if (keys.length !== Object.keys(b).length) {
12222
- return false;
12223
- }
12224
- for (var key in a) {
12225
- if (!deepEqual(a[key], b[key])) {
12226
- return false;
12227
- }
12228
- }
12229
- return true;
12230
- }
12231
- return a === b;
12232
- }
12233
-
12234
13138
  var operations = {
12235
13139
  setStyle: 'setStyle',
12236
13140
  addLayer: 'addLayer',
@@ -12921,7 +13825,7 @@
12921
13825
  });
12922
13826
  }
12923
13827
  var expressionObj = expression.value.expression || expression.value._styleExpression.expression;
12924
- if (options.expressionContext === 'property' && options.propertyKey === 'text-font' && expressionObj.possibleOutputs().indexOf(undefined) !== -1) {
13828
+ if (options.expressionContext === 'property' && options.propertyKey === 'text-font' && !expressionObj.outputDefined()) {
12925
13829
  return [new ValidationError(options.key, options.value, 'Invalid data expression for "' + options.propertyKey + '". Output values must be contained as literals within the expression.')];
12926
13830
  }
12927
13831
  if (options.expressionContext === 'property' && options.propertyType === 'layout' && !isStateConstant(expressionObj)) {