Optimize geojsonsource: do not calculate all tiles when unneeded
This commit is contained in:
parent
5d4e98dcf9
commit
4fd233e557
1 changed files with 47 additions and 43 deletions
|
@ -50,7 +50,7 @@ export default class GeoJsonSource implements FeatureSource {
|
||||||
* @param locationControl
|
* @param locationControl
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
public static ConstructMultiSource(flayers: { isDisplayed: UIEventSource<boolean>, layerDef: LayerConfig }[], locationControl: UIEventSource<Loc>): GeoJsonSource[] {
|
public static ConstructMultiSource(flayers: { isDisplayed: UIEventSource<boolean>, layerDef: LayerConfig }[], locationControl: UIEventSource<Loc>): FeatureSource[] {
|
||||||
|
|
||||||
const flayersPerSource = new Map<string, { isDisplayed: UIEventSource<boolean>, layerDef: LayerConfig }[]>();
|
const flayersPerSource = new Map<string, { isDisplayed: UIEventSource<boolean>, layerDef: LayerConfig }[]>();
|
||||||
for (const flayer of flayers) {
|
for (const flayer of flayers) {
|
||||||
|
@ -65,7 +65,7 @@ export default class GeoJsonSource implements FeatureSource {
|
||||||
flayersPerSource.get(url).push(flayer)
|
flayersPerSource.get(url).push(flayer)
|
||||||
}
|
}
|
||||||
|
|
||||||
const sources: GeoJsonSource[] = []
|
const sources: FeatureSource[] = []
|
||||||
|
|
||||||
flayersPerSource.forEach((flayers, key) => {
|
flayersPerSource.forEach((flayers, key) => {
|
||||||
if (flayers.length == 1) {
|
if (flayers.length == 1) {
|
||||||
|
@ -112,7 +112,19 @@ export default class GeoJsonSource implements FeatureSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
const neededTiles = locationControl.map(
|
const neededTiles = locationControl.map(
|
||||||
_ => {
|
location => {
|
||||||
|
if (!flayer.isDisplayed.data) {
|
||||||
|
// No need to download! - the layer is disabled
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location.zoom < flayer.layerDef.minzoom ||
|
||||||
|
location.zoom > flayer.layerDef.maxzoom) {
|
||||||
|
// No need to download! - the layer is disabled
|
||||||
|
console.log("Not loading layers for " + url, "zoom" + location.zoom, " not between", flayer.layerDef.minzoom, "and", flayer.layerDef.maxzoom)
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
// Yup, this is cheating to just get the bounds here
|
// Yup, this is cheating to just get the bounds here
|
||||||
const bounds = State.state.leafletMap.data.getBounds()
|
const bounds = State.state.leafletMap.data.getBounds()
|
||||||
const tileRange = Utils.TileRangeBetween(zoomLevel, bounds.getNorth(), bounds.getEast(), bounds.getSouth(), bounds.getWest())
|
const tileRange = Utils.TileRangeBetween(zoomLevel, bounds.getNorth(), bounds.getEast(), bounds.getSouth(), bounds.getWest())
|
||||||
|
@ -126,14 +138,6 @@ export default class GeoJsonSource implements FeatureSource {
|
||||||
if (needed === undefined) {
|
if (needed === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!flayer.isDisplayed.data) {
|
|
||||||
// No need to download! - the layer is disabled
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (locationControl.data.zoom < flayer.layerDef.minzoom) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
needed.forEach(neededTile => {
|
needed.forEach(neededTile => {
|
||||||
if (loadedTiles.has(neededTile)) {
|
if (loadedTiles.has(neededTile)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue