forked from MapComplete/MapComplete
Small tweaks
This commit is contained in:
parent
4fcd3523b7
commit
e904043069
6 changed files with 27 additions and 75 deletions
|
@ -298,16 +298,13 @@ export default class FeaturePipeline {
|
||||||
readonly overpassMaxZoom: UIEventSource<number>,
|
readonly overpassMaxZoom: UIEventSource<number>,
|
||||||
}, useOsmApi: UIEventSource<boolean>): OverpassFeatureSource {
|
}, useOsmApi: UIEventSource<boolean>): OverpassFeatureSource {
|
||||||
const minzoom = Math.min(...state.layoutToUse.layers.map(layer => layer.minzoom))
|
const minzoom = Math.min(...state.layoutToUse.layers.map(layer => layer.minzoom))
|
||||||
const allUpToDateAndZoomSufficient = state.currentBounds.map(bbox => {
|
const overpassIsActive = state.currentBounds.map(bbox => {
|
||||||
if (bbox === undefined) {
|
if (bbox === undefined) {
|
||||||
return true
|
return false
|
||||||
}
|
|
||||||
if (!this.sufficientlyZoomed?.data) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
let zoom = state.locationControl.data.zoom
|
let zoom = state.locationControl.data.zoom
|
||||||
if (zoom < minzoom) {
|
if (zoom < minzoom) {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
if (zoom > 16) {
|
if (zoom > 16) {
|
||||||
zoom = 16
|
zoom = 16
|
||||||
|
@ -315,19 +312,22 @@ export default class FeaturePipeline {
|
||||||
if (zoom < 8) {
|
if (zoom < 8) {
|
||||||
zoom = zoom + 2
|
zoom = zoom + 2
|
||||||
}
|
}
|
||||||
|
|
||||||
const range = bbox.containingTileRange(zoom)
|
const range = bbox.containingTileRange(zoom)
|
||||||
|
if(range.total > 100){
|
||||||
|
return false
|
||||||
|
}
|
||||||
const self = this;
|
const self = this;
|
||||||
const allFreshnesses = Tiles.MapRange(range, (x, y) => self.freshnessForVisibleLayers(zoom, x, y))
|
const allFreshnesses = Tiles.MapRange(range, (x, y) => self.freshnessForVisibleLayers(zoom, x, y))
|
||||||
return !allFreshnesses.some(freshness => freshness === undefined || freshness < this.oldestAllowedDate)
|
return allFreshnesses.some(freshness => freshness === undefined || freshness < this.oldestAllowedDate)
|
||||||
|
|
||||||
}, [state.locationControl])
|
}, [state.locationControl])
|
||||||
|
|
||||||
allUpToDateAndZoomSufficient.addCallbackAndRunD(allUpToDate => console.log("All up to data is: ", allUpToDate))
|
|
||||||
const self = this;
|
const self = this;
|
||||||
const updater = new OverpassFeatureSource(state,
|
const updater = new OverpassFeatureSource(state,
|
||||||
{
|
{
|
||||||
relationTracker: this.relationTracker,
|
relationTracker: this.relationTracker,
|
||||||
isActive: useOsmApi.map(b => !b && !allUpToDateAndZoomSufficient.data, [allUpToDateAndZoomSufficient]),
|
isActive: useOsmApi.map(b => !b && overpassIsActive.data, [overpassIsActive]),
|
||||||
onBboxLoaded: ((bbox, date, downloadedLayers) => {
|
onBboxLoaded: ((bbox, date, downloadedLayers) => {
|
||||||
Tiles.MapRange(bbox.containingTileRange(self.osmSourceZoomLevel), (x, y) => {
|
Tiles.MapRange(bbox.containingTileRange(self.osmSourceZoomLevel), (x, y) => {
|
||||||
downloadedLayers.forEach(layer => {
|
downloadedLayers.forEach(layer => {
|
||||||
|
|
|
@ -14,6 +14,10 @@ export class Tiles {
|
||||||
|
|
||||||
public static MapRange<T>(tileRange: TileRange, f: (x: number, y: number) => T): T[] {
|
public static MapRange<T>(tileRange: TileRange, f: (x: number, y: number) => T): T[] {
|
||||||
const result: T[] = []
|
const result: T[] = []
|
||||||
|
const total = tileRange.total
|
||||||
|
if(total > 5000){
|
||||||
|
throw "Tilerange too big"
|
||||||
|
}
|
||||||
for (let x = tileRange.xstart; x <= tileRange.xend; x++) {
|
for (let x = tileRange.xstart; x <= tileRange.xend; x++) {
|
||||||
for (let y = tileRange.ystart; y <= tileRange.yend; y++) {
|
for (let y = tileRange.ystart; y <= tileRange.yend; y++) {
|
||||||
const t = f(x, y);
|
const t = f(x, y);
|
||||||
|
@ -99,12 +103,6 @@ export class Tiles {
|
||||||
const ystart = Math.min(t0.y, t1.y)
|
const ystart = Math.min(t0.y, t1.y)
|
||||||
const yend = Math.max(t0.y, t1.y)
|
const yend = Math.max(t0.y, t1.y)
|
||||||
const total = (1 + xend - xstart) * (1 + yend - ystart)
|
const total = (1 + xend - xstart) * (1 + yend - ystart)
|
||||||
if(total > 1000){
|
|
||||||
console.trace("Detected a big tilerange which'll be iterated over: zoomlevel", zoomlevel, "bounds:", [[lon0, lat0], [lon1, lat1]])
|
|
||||||
}
|
|
||||||
if(total > 10000){
|
|
||||||
throw "Tilerange too big"
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
xstart: xstart,
|
xstart: xstart,
|
||||||
|
|
|
@ -12,7 +12,7 @@ export default class ThemeIntroductionPanel extends Combine {
|
||||||
constructor(isShown: UIEventSource<boolean>) {
|
constructor(isShown: UIEventSource<boolean>) {
|
||||||
const layout = State.state.layoutToUse
|
const layout = State.state.layoutToUse
|
||||||
|
|
||||||
const languagePicker = LanguagePicker.CreateLanguagePicker(layout.language, Translations.t.general.pickLanguage.Clone())
|
const languagePicker = LanguagePicker.CreateLanguagePicker(layout.language, Translations.t.general.pickLanguage.Clone())
|
||||||
|
|
||||||
const toTheMap = new SubtleButton(
|
const toTheMap = new SubtleButton(
|
||||||
undefined,
|
undefined,
|
||||||
|
@ -54,7 +54,7 @@ export default class ThemeIntroductionPanel extends Combine {
|
||||||
"<br/><br/>",
|
"<br/><br/>",
|
||||||
toTheMap,
|
toTheMap,
|
||||||
loginStatus,
|
loginStatus,
|
||||||
layout.descriptionTail.Clone(),
|
layout.descriptionTail?.Clone(),
|
||||||
"<br/>",
|
"<br/>",
|
||||||
languagePicker,
|
languagePicker,
|
||||||
...layout.CustomCodeSnippets()
|
...layout.CustomCodeSnippets()
|
||||||
|
|
|
@ -22,6 +22,8 @@ export default class ShowDataLayer {
|
||||||
/**
|
/**
|
||||||
* If the selected element triggers, this is used to lookup the correct layer and to open the popup
|
* If the selected element triggers, this is used to lookup the correct layer and to open the popup
|
||||||
* Used to avoid a lot of callbacks on the selected element
|
* Used to avoid a lot of callbacks on the selected element
|
||||||
|
*
|
||||||
|
* Note: the key of this dictionary is 'feature.properties.id+features.geometry.type' as one feature might have multiple presentations
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
private readonly leafletLayersPerId = new Map<string, { feature: any, leafletlayer: any }>()
|
private readonly leafletLayersPerId = new Map<string, { feature: any, leafletlayer: any }>()
|
||||||
|
@ -68,7 +70,7 @@ export default class ShowDataLayer {
|
||||||
if (self._leafletMap.data === undefined) {
|
if (self._leafletMap.data === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const v = self.leafletLayersPerId.get(selected.properties.id)
|
const v = self.leafletLayersPerId.get(selected.properties.id+selected.geometry.type)
|
||||||
if (v === undefined) {
|
if (v === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +85,7 @@ export default class ShowDataLayer {
|
||||||
|
|
||||||
if (feature.id !== feature.properties.id) {
|
if (feature.id !== feature.properties.id) {
|
||||||
// Probably a feature which has renamed
|
// Probably a feature which has renamed
|
||||||
console.trace("Not opening the popup for", feature)
|
console.log("Not opening the popup for", feature, "as probably renamed")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (selected.geometry.type === feature.geometry.type // If a feature is rendered both as way and as point, opening one popup might trigger the other to open, which might trigger the one to open again
|
if (selected.geometry.type === feature.geometry.type // If a feature is rendered both as way and as point, opening one popup might trigger the other to open, which might trigger the one to open again
|
||||||
|
@ -223,10 +225,6 @@ export default class ShowDataLayer {
|
||||||
popup.setContent(`<div style='height: 65vh' id='${id}'>Rendering</div>`)
|
popup.setContent(`<div style='height: 65vh' id='${id}'>Rendering</div>`)
|
||||||
|
|
||||||
leafletLayer.on("popupopen", () => {
|
leafletLayer.on("popupopen", () => {
|
||||||
if(State.state.selectedElement.data?.properties?.id !== feature.properties.id){
|
|
||||||
State.state.selectedElement.setData(feature)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (infobox === undefined) {
|
if (infobox === undefined) {
|
||||||
const tags = State.state.allElements.getEventSourceById(feature.properties.id);
|
const tags = State.state.allElements.getEventSourceById(feature.properties.id);
|
||||||
infobox = new FeatureInfoBox(tags, layer);
|
infobox = new FeatureInfoBox(tags, layer);
|
||||||
|
@ -242,11 +240,16 @@ export default class ShowDataLayer {
|
||||||
|
|
||||||
infobox.AttachTo(id)
|
infobox.AttachTo(id)
|
||||||
infobox.Activate();
|
infobox.Activate();
|
||||||
|
|
||||||
|
|
||||||
|
if(State.state.selectedElement.data?.properties?.id !== feature.properties.id){
|
||||||
|
// x State.state.selectedElement.setData(feature)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Add the feature to the index to open the popup when needed
|
// Add the feature to the index to open the popup when needed
|
||||||
this.leafletLayersPerId.set(feature.properties.id, {feature: feature, leafletlayer: leafletLayer})
|
this.leafletLayersPerId.set(feature.properties.id+feature.geometry.type, {feature: feature, leafletlayer: leafletLayer})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
Utils.ts
3
Utils.ts
|
@ -1,5 +1,4 @@
|
||||||
import * as colors from "./assets/colors.json"
|
import * as colors from "./assets/colors.json"
|
||||||
import {TileRange} from "./Models/TileRange";
|
|
||||||
|
|
||||||
export class Utils {
|
export class Utils {
|
||||||
|
|
||||||
|
@ -238,7 +237,7 @@ export class Utils {
|
||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
static getOrSetDefault<K, V>(dict: Map<K, V>, k: K, v: () => V) {
|
static getOrSetDefault<K, V>(dict: Map<K, V>, k: K, v: () => V) {
|
||||||
let found = dict.get(k);
|
let found = dict.get(k);
|
||||||
if (found !== undefined) {
|
if (found !== undefined) {
|
||||||
|
|
50
test.ts
50
test.ts
|
@ -1,50 +1,2 @@
|
||||||
<<<<<<< HEAD
|
|
||||||
import {Tiles} from "./Models/TileRange";
|
|
||||||
import OsmFeatureSource from "./Logic/FeatureSource/TiledFeatureSource/OsmFeatureSource";
|
|
||||||
import {Utils} from "./Utils";
|
|
||||||
import {AllKnownLayouts} from "./Customizations/AllKnownLayouts";
|
import {AllKnownLayouts} from "./Customizations/AllKnownLayouts";
|
||||||
import LayerConfig from "./Models/ThemeConfig/LayerConfig";
|
import {Translation} from "./UI/i18n/Translation";
|
||||||
|
|
||||||
const allLayers: LayerConfig[] = []
|
|
||||||
const seenIds = new Set<string>()
|
|
||||||
for (const layoutConfig of AllKnownLayouts.layoutsList) {
|
|
||||||
if (layoutConfig.hideFromOverview) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for (const layer of layoutConfig.layers) {
|
|
||||||
if (seenIds.has(layer.id)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
seenIds.add(layer.id)
|
|
||||||
allLayers.push(layer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("All layer ids", allLayers.map(l => l.id))
|
|
||||||
|
|
||||||
const src = new OsmFeatureSource({
|
|
||||||
backend: "https://www.openstreetmap.org",
|
|
||||||
handleTile: tile => console.log("Got tile", tile),
|
|
||||||
allLayers: allLayers
|
|
||||||
})
|
|
||||||
src.LoadTile(16, 33354, 21875).then(geojson => {
|
|
||||||
console.log("Got geojson", geojson);
|
|
||||||
Utils.offerContentsAsDownloadableFile(JSON.stringify(geojson), "test.geojson", {
|
|
||||||
mimetype: "application/vnd.geo+json"
|
|
||||||
})
|
|
||||||
})
|
|
||||||
//*/
|
|
||||||
=======
|
|
||||||
import LocationInput from "./UI/Input/LocationInput";
|
|
||||||
import Loc from "./Models/Loc";
|
|
||||||
import {UIEventSource} from "./Logic/UIEventSource";
|
|
||||||
|
|
||||||
new LocationInput({
|
|
||||||
centerLocation: new UIEventSource<Loc>({
|
|
||||||
lat: 51.1110,
|
|
||||||
lon: 3.3701,
|
|
||||||
zoom : 14
|
|
||||||
})
|
|
||||||
}).SetStyle("height: 500px")
|
|
||||||
.AttachTo("maindiv");
|
|
||||||
>>>>>>> feature/animated-precise-input
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue