Skip to content

Commit

Permalink
cherry picks from Master to Release-Erie (#9772)
Browse files Browse the repository at this point in the history
* Cherry pick (mapbox/mapbox-gl-js#9757) to release-erie

* Cherry pick (mapbox/mapbox-gl-js#9753) to release-erie

* Cherry pick (mapbox/mapbox-gl-js#9749) to release-erie

* Cherry pick (mapbox/mapbox-gl-js#9748) to release-erie
  • Loading branch information
sgolbabaei authored Jun 10, 2020
1 parent 0d84a6a commit 8ef30bc
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"potpack": "^1.0.1",
"quickselect": "^2.0.0",
"rw": "^1.3.3",
"supercluster": "^7.0.0",
"supercluster": "^7.1.0",
"tinyqueue": "^2.0.3",
"vt-pbf": "^3.1.1"
},
Expand Down
4 changes: 3 additions & 1 deletion rollup/bundle_prelude.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ if (!shared) {
var sharedChunk = {};
shared(sharedChunk);
mapboxgl = chunk(sharedChunk);
mapboxgl.workerUrl = window.URL.createObjectURL(new Blob([workerBundleString], { type: 'text/javascript' }));
if (typeof window !== 'undefined') {
mapboxgl.workerUrl = window.URL.createObjectURL(new Blob([workerBundleString], { type: 'text/javascript' }));
}
}
}
24 changes: 11 additions & 13 deletions src/data/load_geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ import type Point from '@mapbox/point-geometry';
// While visible coordinates are within [0, EXTENT], tiles may theoretically
// contain cordinates within [-Infinity, Infinity]. Our range is limited by the
// number of bits used to represent the coordinate.
function createBounds(bits) {
return {
min: -1 * Math.pow(2, bits - 1),
max: Math.pow(2, bits - 1) - 1
};
}

const bounds = createBounds(15);
const BITS = 15;
const MAX = Math.pow(2, BITS - 1) - 1;
const MIN = -MAX - 1;

/**
* Loads a geometry from a VectorTileFeature and scales it to the common extent
Expand All @@ -34,13 +29,16 @@ export default function loadGeometry(feature: VectorTileFeature): Array<Array<Po
const point = ring[p];
// round here because mapbox-gl-native uses integers to represent
// points and we need to do the same to avoid renering differences.
point.x = Math.round(point.x * scale);
point.y = Math.round(point.y * scale);
const x = Math.round(point.x * scale);
const y = Math.round(point.y * scale);

point.x = clamp(x, MIN, MAX);
point.y = clamp(y, MIN, MAX);

if (point.x < bounds.min || point.x > bounds.max || point.y < bounds.min || point.y > bounds.max) {
if (x < point.x || x > point.x + 1 || y < point.y || y > point.y + 1) {
// warn when exceeding allowed extent except for the 1-px-off case
// https://github.com/mapbox/mapbox-gl-js/issues/8992
warnOnce('Geometry exceeds allowed extent, reduce your vector tile buffer size');
point.x = clamp(point.x, bounds.min, bounds.max);
point.y = clamp(point.y, bounds.min, bounds.max);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/source/geojson_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class GeoJSONSource extends Evented implements Source {
maxZoom: options.clusterMaxZoom !== undefined ?
Math.min(options.clusterMaxZoom, this.maxzoom - 1) :
(this.maxzoom - 1),
minPoints: Math.max(2, options.clusterMinPoints || 2),
extent: EXTENT,
radius: (options.clusterRadius || 50) * scale,
log: false,
Expand Down
4 changes: 4 additions & 0 deletions src/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@
"type": "number",
"doc": "Max zoom on which to cluster points if clustering is enabled. Defaults to one zoom less than maxzoom (so that last zoom features are not clustered)."
},
"clusterMinPoints": {
"type": "number",
"doc": "Minimum number of points necessary to form a cluster if clustering is enabled. Defaults to `2`."
},
"clusterProperties": {
"type": "*",
"doc": "An object defining custom properties on the generated clusters if clustering is enabled, aggregating values from clustered points. Has the form `{\"property_name\": [operator, map_expression]}`. `operator` is any expression function that accepts at least 2 operands (e.g. `\"+\"` or `\"max\"`) — it accumulates the property value from clusters/points the cluster contains; `map_expression` produces the value of a single point.\n\nExample: `{\"sum\": [\"+\", [\"get\", \"scalerank\"]]}`.\n\nFor more advanced use cases, in place of `operator`, you can use a custom reduce expression that references a special `[\"accumulated\"]` value, e.g.:\n`{\"sum\": [[\"+\", [\"accumulated\"], [\"get\", \"sum\"]], [\"get\", \"scalerank\"]]}`"
Expand Down
14 changes: 8 additions & 6 deletions src/ui/handler_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ class HandlerManager {
const el = this._el;

this._listeners = [
// Bind touchstart and touchmove with passive: false because, even though
// they only fire a map events and therefore could theoretically be
// passive, binding with passive: true causes iOS not to respect
// e.preventDefault() in _other_ handlers, even if they are non-passive
// (see https://bugs.webkit.org/show_bug.cgi?id=184251)
[el, 'touchstart', {passive: false}],
// This needs to be `passive: true` so that a double tap fires two
// pairs of touchstart/end events in iOS Safari 13. If this is set to
// `passive: false` then the second pair of events is only fired if
// preventDefault() is called on the first touchstart. Calling preventDefault()
// undesirably prevents click events.
[el, 'touchstart', {passive: true}],
// This needs to be `passive: false` so that scrolls and pinches can be
// prevented in browsers that don't support `touch-actions: none`, for example iOS Safari 12.
[el, 'touchmove', {passive: false}],
[el, 'touchend', undefined],
[el, 'touchcancel', undefined],
Expand Down
2 changes: 1 addition & 1 deletion src/util/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const exported = {
return linkEl.href;
},

hardwareConcurrency: window.navigator.hardwareConcurrency || 4,
hardwareConcurrency: window.navigator && window.navigator.hardwareConcurrency || 4,

get devicePixelRatio() { return window.devicePixelRatio; },
get prefersReducedMotion(): boolean {
Expand Down
3 changes: 2 additions & 1 deletion src/util/browser/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/* eslint-env browser */
import type {Window} from '../../types/window';

export default (self: Window);
// shim window for the case of requiring the browser bundle in Node
export default typeof self !== 'undefined' ? (self: Window) : (({}: any): Window);
2 changes: 1 addition & 1 deletion src/util/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ DOM.createNS = function (namespaceURI: string, tagName: string) {
return el;
};

const docStyle = window.document.documentElement.style;
const docStyle = window.document && window.document.documentElement.style;

function testProp(props) {
if (!docStyle) return props[0];
Expand Down
5 changes: 5 additions & 0 deletions test/build/min.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ test('can be browserified', (t) => {
});
});

test('evaluates without errors', (t) => {
t.doesNotThrow(() => require(path.join(__dirname, '../../dist/mapbox-gl.js')));
t.end();
});

test('distributed in plain ES5 code', (t) => {
const linter = new Linter();
const messages = linter.verify(minBundle, {
Expand Down
2 changes: 2 additions & 0 deletions test/unit/source/geojson_source.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ test('GeoJSONSource#update', (t) => {
t.equal(message, 'geojson.loadData');
t.deepEqual(params.superclusterOptions, {
maxZoom: 12,
minPoints: 3,
extent: 8192,
radius: 1600,
log: false,
Expand All @@ -190,6 +191,7 @@ test('GeoJSONSource#update', (t) => {
cluster: true,
clusterMaxZoom: 12,
clusterRadius: 100,
clusterMinPoints: 3,
generateId: true
}, mockDispatcher).load();
});
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10299,10 +10299,10 @@ sugarss@^2.0.0:
dependencies:
postcss "^7.0.2"

supercluster@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/supercluster/-/supercluster-7.0.0.tgz#75d474fafb0a055db552ed7bd7bbda583f6ab321"
integrity sha512-8VuHI8ynylYQj7Qf6PBMWy1PdgsnBiIxujOgc9Z83QvJ8ualIYWNx2iMKyKeC4DZI5ntD9tz/CIwwZvIelixsA==
supercluster@^7.1.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/supercluster/-/supercluster-7.1.0.tgz#f0a457426ec0ab95d69c5f03b51e049774b94479"
integrity sha512-LDasImUAFMhTqhK+cUXfy9C2KTUqJ3gucLjmNLNFmKWOnDUBxLFLH9oKuXOTCLveecmxh8fbk8kgh6Q0gsfe2w==
dependencies:
kdbush "^3.0.0"

Expand Down

0 comments on commit 8ef30bc

Please sign in to comment.