| 50 | } |
| 51 | |
| 52 | queryRenderedFeatures(geometry, options, cb) { |
| 53 | if (!this.l7layer || !this.l7layer.isVisible()) { |
| 54 | return cb([]); |
| 55 | } |
| 56 | let box = geometry; |
| 57 | if (geometry instanceof mapboxgl.Point || typeof geometry[0] === 'number') { |
| 58 | const point = mapboxgl.Point.convert(geometry); |
| 59 | // fix 两个点一样查出来的结果不对 |
| 60 | box = [point, [point.x - 1, point.y - 1]]; |
| 61 | } |
| 62 | box = box.map((item) => { |
| 63 | const point = mapboxgl.Point.convert(item); |
| 64 | return [point.x, point.y]; |
| 65 | }); |
| 66 | const [x1, y1, x2, y2] = box.flat(); |
| 67 | const _this = this; |
| 68 | this.l7layer.boxSelect([Math.min(x1, x2), Math.min(y1, y2), Math.max(x1, x2), Math.max(y1, y2)], (features) => { |
| 69 | const nextFeatures = features || []; |
| 70 | const { layerCapture = true } = options || {}; |
| 71 | if (layerCapture) { |
| 72 | cb( |
| 73 | nextFeatures.map((item) => { |
| 74 | return { |
| 75 | ...item, |
| 76 | layer: _this.getLayer() |
| 77 | }; |
| 78 | }) |
| 79 | ); |
| 80 | return; |
| 81 | } |
| 82 | cb(nextFeatures); |
| 83 | }); |
| 84 | } |
| 85 | |
| 86 | _formateEvent(e) { |
| 87 | return { |