* visibleSources * Returns array of known imagery sources that are valid at the given extent and zoom * @return Array
()
| 334 | * @return Array |
| 335 | */ |
| 336 | visibleSources() { |
| 337 | if (!this._imageryIndex) return []; // called before init()? |
| 338 | |
| 339 | const context = this.context; |
| 340 | const viewport = context.viewport; |
| 341 | const extent = viewport.visibleExtent(); |
| 342 | const zoom = viewport.transform.zoom; |
| 343 | |
| 344 | const visible = new Set(); |
| 345 | (this._imageryIndex.query.bbox(extent.rectangle(), true) || []) |
| 346 | .forEach(d => visible.add(d.id)); |
| 347 | |
| 348 | const currSource = this._baseLayer; |
| 349 | const sources = [...this._imageryIndex.sources.values()]; |
| 350 | |
| 351 | // Recheck blocked sources only if we detect new blocklists pulled from the OSM API. |
| 352 | const osm = context.services.osm; |
| 353 | const blocklists = osm?.imageryBlocklists ?? []; |
| 354 | const blocklistChanged = (blocklists.length !== this._checkedBlocklists.length) || |
| 355 | blocklists.some((regex, index) => String(regex) !== this._checkedBlocklists[index]); |
| 356 | |
| 357 | if (blocklistChanged) { |
| 358 | for (const source of sources) { |
| 359 | source.isBlocked = blocklists.some(regex => regex.test(source.template)); |
| 360 | } |
| 361 | this._checkedBlocklists = blocklists.map(regex => String(regex)); |
| 362 | } |
| 363 | |
| 364 | return sources.filter(source => { |
| 365 | if (currSource === source) return true; // always include the current imagery |
| 366 | if (source.isBlocked) return false; // even bundled sources may be blocked - iD#7905 |
| 367 | if (!source.polygon) return true; // always include imagery with worldwide coverage |
| 368 | if (zoom && zoom < 6) return false; // optionally exclude local imagery at low zooms |
| 369 | return visible.has(source.id); // include imagery visible in given extent |
| 370 | }); |
| 371 | } |
| 372 | |
| 373 | |
| 374 | /** |
no test coverage detected