Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/source/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class Tile {

bucket.update(sourceLayerStates, sourceLayer, this.imageAtlas && this.imageAtlas.patternPositions || {});
const layer = painter && painter.style && painter.style.getLayer(id);
if (layer && layer.paint) {
if (layer) {
this.queryPadding = Math.max(this.queryPadding, layer.queryRadius(bucket));
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/source/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export default class Worker {

setImages(mapId: string, images: Array<string>, callback: WorkerTileCallback) {
this.availableImages[mapId] = images;
for (const workerSource in this.workerSources[mapId]) {
const ws = this.workerSources[mapId][workerSource];
for (const source in ws) {
ws[source].availableImages = images;
}
}
callback();
}

Expand Down
1 change: 1 addition & 0 deletions src/source/worker_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export type WorkerDEMTileCallback = (err: ?Error, result: ?DEMData) => void;
* @param layerIndex
*/
export interface WorkerSource {
availableImages: Array<string>,
// Disabled due to https://github.com/facebook/flow/issues/5208
// constructor(actor: Actor, layerIndex: StyleLayerIndex): WorkerSource;

Expand Down
12 changes: 11 additions & 1 deletion src/style-spec/feature_filter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function createFilter(filter: any): FeatureFilter {
if (compiled.result === 'error') {
throw new Error(compiled.value.map(err => `${err.key}: ${err.message}`).join(', '));
} else {
const needGeometry = Array.isArray(filter) && filter.length !== 0 && filter[0] === 'within';
const needGeometry = geometryNeeded(filter);
return {filter: (globalProperties: GlobalProperties, feature: Feature, canonical?: CanonicalTileID) => compiled.value.evaluate(globalProperties, feature, {}, canonical),
needGeometry};
}
Expand All @@ -96,6 +96,15 @@ function compare(a, b) {
return a < b ? -1 : a > b ? 1 : 0;
}

function geometryNeeded(filter) {
if (!Array.isArray(filter)) return false;
if (filter[0] === 'within') return true;
for (let index = 1; index < filter.length; index++) {
if (geometryNeeded(filter[index])) return true;
}
return false;
}

function convertFilter(filter: ?Array<any>): mixed {
if (!filter) return true;
const op = filter[0];
Expand All @@ -114,6 +123,7 @@ function convertFilter(filter: ?Array<any>): mixed {
op === '!in' ? convertNegation(convertInOp(filter[1], filter.slice(2))) :
op === 'has' ? convertHasOp(filter[1]) :
op === '!has' ? convertNegation(convertHasOp(filter[1])) :
op === 'within' ? filter :
true;
return converted;
}
Expand Down
3 changes: 3 additions & 0 deletions src/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -2450,6 +2450,9 @@
},
"!has": {
"doc": "`[\"!has\", key]` `feature[key]` does not exist"
},
"within": {
"doc": "`[\"within\", object]` feature geometry is within object geometry"
}
},
"doc": "The filter operator."
Expand Down
10 changes: 8 additions & 2 deletions src/style-spec/validate/validate_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,14 @@ function validateNonExpressionFilter(options) {
errors.push(new ValidationError(`${key}[1]`, value[1], `string expected, ${type} found`));
}
break;

case 'within':
type = getType(value[1]);
if (value.length !== 2) {
errors.push(new ValidationError(key, value, `filter array for "${value[0]}" operator must have 2 elements`));
} else if (type !== 'object') {
errors.push(new ValidationError(`${key}[1]`, value[1], `object expected, ${type} found`));
}
break;
}

return errors;
}
8 changes: 4 additions & 4 deletions src/style/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ export class Transitioning<Props: Object> {
this._values = (Object.create(properties.defaultTransitioningPropertyValues): any);
}

possiblyEvaluate(parameters: EvaluationParameters, availableImages?: Array<string>): PossiblyEvaluated<Props> {
possiblyEvaluate(parameters: EvaluationParameters, canonical?: CanonicalTileID, availableImages?: Array<string>): PossiblyEvaluated<Props> {
const result = new PossiblyEvaluated(this._properties); // eslint-disable-line no-use-before-define
for (const property of Object.keys(this._values)) {
result._values[property] = this._values[property].possiblyEvaluate(parameters, availableImages);
result._values[property] = this._values[property].possiblyEvaluate(parameters, canonical, availableImages);
}
return result;
}
Expand Down Expand Up @@ -385,10 +385,10 @@ export class Layout<Props: Object> {
return result;
}

possiblyEvaluate(parameters: EvaluationParameters, availableImages?: Array<string>): PossiblyEvaluated<Props> {
possiblyEvaluate(parameters: EvaluationParameters, canonical?: CanonicalTileID, availableImages?: Array<string>): PossiblyEvaluated<Props> {
const result = new PossiblyEvaluated(this._properties); // eslint-disable-line no-use-before-define
for (const property of Object.keys(this._values)) {
result._values[property] = this._values[property].possiblyEvaluate(parameters, availableImages);
result._values[property] = this._values[property].possiblyEvaluate(parameters, canonical, availableImages);
}
return result;
}
Expand Down
8 changes: 5 additions & 3 deletions src/style/style_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
emitValidationErrors
} from './validate_style';
import {Evented} from '../util/evented';
import {Layout, Transitionable, Transitioning, Properties, PossiblyEvaluatedPropertyValue} from './properties';
import {Layout, Transitionable, Transitioning, Properties, PossiblyEvaluated, PossiblyEvaluatedPropertyValue} from './properties';
import {supportsPropertyExpression} from '../style-spec/util/properties';

import type {FeatureState} from '../style-spec/expression';
Expand Down Expand Up @@ -100,6 +100,8 @@ class StyleLayer extends Evented {
}

this._transitioningPaint = this._transitionablePaint.untransitioned();
//$FlowFixMe
this.paint = new PossiblyEvaluated(properties.paint);
}
}

Expand Down Expand Up @@ -199,10 +201,10 @@ class StyleLayer extends Evented {
}

if (this._unevaluatedLayout) {
(this: any).layout = this._unevaluatedLayout.possiblyEvaluate(parameters, availableImages);
(this: any).layout = this._unevaluatedLayout.possiblyEvaluate(parameters, undefined, availableImages);
}

(this: any).paint = this._transitioningPaint.possiblyEvaluate(parameters, availableImages);
(this: any).paint = this._transitioningPaint.possiblyEvaluate(parameters, undefined, availableImages);
}

serialize() {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/handler/handler_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import assert from 'assert';

export function indexTouches(touches: TouchList, points: Array<Point>) {
export function indexTouches(touches: Array<Touch>, points: Array<Point>) {
assert(touches.length === points.length);
const obj = {};
for (let i = 0; i < touches.length; i++) {
Expand Down
9 changes: 4 additions & 5 deletions src/ui/handler/map_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export class MapEventHandler {
return this._firePreventable(new MapTouchEvent(e.type, this._map, e));
}

touchmove(e: TouchEvent) {
this._map.fire(new MapTouchEvent(e.type, this._map, e));
}

touchend(e: TouchEvent) {
this._map.fire(new MapTouchEvent(e.type, this._map, e));
}
Expand Down Expand Up @@ -114,11 +118,6 @@ export class BlockableMapEventHandler {
this._map.fire(new MapMouseEvent(e.type, this._map, e));
}

touchmove(e: TouchEvent) {
// touchmove map events should not be fired when interaction handlers (pan, rotate, etc) are active
this._map.fire(new MapTouchEvent(e.type, this._map, e));
}

mousedown() {
this._delayContextMenu = true;
}
Expand Down
20 changes: 10 additions & 10 deletions src/ui/handler/tap_drag_zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@ export default class TapDragZoomHandler {
this._tap.reset();
}

touchstart(e: TouchEvent, points: Array<Point>) {
touchstart(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
if (this._swipePoint) return;

if (this._tapTime && e.timeStamp - this._tapTime > MAX_TAP_INTERVAL) {
this.reset();
}

if (!this._tapTime) {
this._tap.touchstart(e, points);
} else if (e.targetTouches.length > 0) {
this._tap.touchstart(e, points, mapTouches);
} else if (mapTouches.length > 0) {
this._swipePoint = points[0];
this._swipeTouch = e.targetTouches[0].identifier;
this._swipeTouch = mapTouches[0].identifier;
}

}

touchmove(e: TouchEvent, points: Array<Point>) {
touchmove(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
if (!this._tapTime) {
this._tap.touchmove(e, points);
this._tap.touchmove(e, points, mapTouches);
} else if (this._swipePoint) {
if (e.targetTouches[0].identifier !== this._swipeTouch) {
if (mapTouches[0].identifier !== this._swipeTouch) {
return;
}

Expand All @@ -67,14 +67,14 @@ export default class TapDragZoomHandler {
}
}

touchend(e: TouchEvent) {
touchend(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
if (!this._tapTime) {
const point = this._tap.touchend(e);
const point = this._tap.touchend(e, points, mapTouches);
if (point) {
this._tapTime = e.timeStamp;
}
} else if (this._swipePoint) {
if (e.targetTouches.length === 0) {
if (mapTouches.length === 0) {
this.reset();
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/ui/handler/tap_recognizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export class SingleTapRecognizer {
this.aborted = false;
}

touchstart(e: TouchEvent, points: Array<Point>) {
touchstart(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {

if (this.centroid || e.targetTouches.length > this.numTouches) {
if (this.centroid || mapTouches.length > this.numTouches) {
this.aborted = true;
}
if (this.aborted) {
Expand All @@ -48,16 +48,16 @@ export class SingleTapRecognizer {
this.startTime = e.timeStamp;
}

if (e.targetTouches.length === this.numTouches) {
if (mapTouches.length === this.numTouches) {
this.centroid = getCentroid(points);
this.touches = indexTouches(e.targetTouches, points);
this.touches = indexTouches(mapTouches, points);
}
}

touchmove(e: TouchEvent, points: Array<Point>) {
touchmove(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
if (this.aborted || !this.centroid) return;

const newTouches = indexTouches(e.targetTouches, points);
const newTouches = indexTouches(mapTouches, points);
for (const id in this.touches) {
const prevPos = this.touches[id];
const pos = newTouches[id];
Expand All @@ -67,12 +67,12 @@ export class SingleTapRecognizer {
}
}

touchend(e: TouchEvent) {
touchend(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
if (!this.centroid || e.timeStamp - this.startTime > MAX_TOUCH_TIME) {
this.aborted = true;
}

if (e.targetTouches.length === 0) {
if (mapTouches.length === 0) {
const centroid = !this.aborted && this.centroid;
this.reset();
if (centroid) return centroid;
Expand Down Expand Up @@ -102,16 +102,16 @@ export class TapRecognizer {
this.singleTap.reset();
}

touchstart(e: TouchEvent, points: Array<Point>) {
this.singleTap.touchstart(e, points);
touchstart(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
this.singleTap.touchstart(e, points, mapTouches);
}

touchmove(e: TouchEvent, points: Array<Point>) {
this.singleTap.touchmove(e, points);
touchmove(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
this.singleTap.touchmove(e, points, mapTouches);
}

touchend(e: TouchEvent) {
const tap = this.singleTap.touchend(e);
touchend(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
const tap = this.singleTap.touchend(e, points, mapTouches);
if (tap) {
const soonEnough = e.timeStamp - this.lastTime < MAX_TAP_INTERVAL;
const closeEnough = !this.lastTap || this.lastTap.dist(tap) < MAX_DIST;
Expand Down
18 changes: 9 additions & 9 deletions src/ui/handler/tap_zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ export default class TapZoomHandler {
this._zoomOut.reset();
}

touchstart(e: TouchEvent, points: Array<Point>) {
this._zoomIn.touchstart(e, points);
this._zoomOut.touchstart(e, points);
touchstart(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
this._zoomIn.touchstart(e, points, mapTouches);
this._zoomOut.touchstart(e, points, mapTouches);
}

touchmove(e: TouchEvent, points: Array<Point>) {
this._zoomIn.touchmove(e, points);
this._zoomOut.touchmove(e, points);
touchmove(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
this._zoomIn.touchmove(e, points, mapTouches);
this._zoomOut.touchmove(e, points, mapTouches);
}

touchend(e: TouchEvent) {
const zoomInPoint = this._zoomIn.touchend(e);
const zoomOutPoint = this._zoomOut.touchend(e);
touchend(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
const zoomInPoint = this._zoomIn.touchend(e, points, mapTouches);
const zoomOutPoint = this._zoomOut.touchend(e, points, mapTouches);

if (zoomInPoint) {
this._active = true;
Expand Down
20 changes: 10 additions & 10 deletions src/ui/handler/touch_pan.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ export default class TouchPanHandler {
this._sum = new Point(0, 0);
}

touchstart(e: TouchEvent, points: Array<Point>) {
return this._calculateTransform(e, points);
touchstart(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
return this._calculateTransform(e, points, mapTouches);
}

touchmove(e: TouchEvent, points: Array<Point>) {
touchmove(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
if (!this._active) return;
e.preventDefault();
return this._calculateTransform(e, points);
return this._calculateTransform(e, points, mapTouches);
}

touchend(e: TouchEvent, points: Array<Point>) {
this._calculateTransform(e, points);
touchend(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
this._calculateTransform(e, points, mapTouches);

if (this._active && e.targetTouches.length < this._minTouches) {
if (this._active && mapTouches.length < this._minTouches) {
this.reset();
}
}
Expand All @@ -46,10 +46,10 @@ export default class TouchPanHandler {
this.reset();
}

_calculateTransform(e: TouchEvent, points: Array<Point>) {
if (e.targetTouches.length > 0) this._active = true;
_calculateTransform(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
if (mapTouches.length > 0) this._active = true;

const touches = indexTouches(e.targetTouches, points);
const touches = indexTouches(mapTouches, points);

const touchPointSum = new Point(0, 0);
const touchDeltaSum = new Point(0, 0);
Expand Down
Loading