forked from MapComplete/MapComplete
Adding a community index view with Svelte (WIP)
This commit is contained in:
parent
ad13444883
commit
d30ed22673
10 changed files with 487 additions and 101 deletions
|
@ -2,8 +2,10 @@ import { QueryParameters } from "../Web/QueryParameters"
|
|||
import { BBox } from "../BBox"
|
||||
import Constants from "../../Models/Constants"
|
||||
import { GeoLocationPointProperties, GeoLocationState } from "../State/GeoLocationState"
|
||||
import State from "../../State"
|
||||
import { UIEventSource } from "../UIEventSource"
|
||||
import Loc from "../../Models/Loc"
|
||||
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"
|
||||
import SimpleFeatureSource from "../FeatureSource/Sources/SimpleFeatureSource"
|
||||
|
||||
/**
|
||||
* The geolocation-handler takes a map-location and a geolocation state.
|
||||
|
@ -12,12 +14,24 @@ import { UIEventSource } from "../UIEventSource"
|
|||
*/
|
||||
export default class GeoLocationHandler {
|
||||
public readonly geolocationState: GeoLocationState
|
||||
private readonly _state: State
|
||||
private readonly _state: {
|
||||
currentUserLocation: SimpleFeatureSource
|
||||
layoutToUse: LayoutConfig
|
||||
locationControl: UIEventSource<Loc>
|
||||
selectedElement: UIEventSource<any>
|
||||
leafletMap?: UIEventSource<any>
|
||||
}
|
||||
public readonly mapHasMoved: UIEventSource<boolean> = new UIEventSource<boolean>(false)
|
||||
|
||||
constructor(
|
||||
geolocationState: GeoLocationState,
|
||||
state: State // { locationControl: UIEventSource<Loc>, selectedElement: UIEventSource<any>, leafletMap?: UIEventSource<any> })
|
||||
state: {
|
||||
locationControl: UIEventSource<Loc>
|
||||
currentUserLocation: SimpleFeatureSource
|
||||
layoutToUse: LayoutConfig
|
||||
selectedElement: UIEventSource<any>
|
||||
leafletMap?: UIEventSource<any>
|
||||
}
|
||||
) {
|
||||
this.geolocationState = geolocationState
|
||||
this._state = state
|
||||
|
|
|
@ -209,7 +209,7 @@ export class GeoOperations {
|
|||
* GeoOperations.inside([1.42822265625, 48.61838518688487], multiPolygon) // => false
|
||||
* GeoOperations.inside([4.02099609375, 47.81315451752768], multiPolygon) // => false
|
||||
*/
|
||||
public static inside(pointCoordinate, feature): boolean {
|
||||
public static inside(pointCoordinate: [number, number] | Feature<Point>, feature): boolean {
|
||||
// ray-casting algorithm based on
|
||||
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
||||
|
||||
|
@ -217,8 +217,8 @@ export class GeoOperations {
|
|||
return false
|
||||
}
|
||||
|
||||
if (pointCoordinate.geometry !== undefined) {
|
||||
pointCoordinate = pointCoordinate.geometry.coordinates
|
||||
if (pointCoordinate["geometry"] !== undefined) {
|
||||
pointCoordinate = pointCoordinate["geometry"].coordinates
|
||||
}
|
||||
|
||||
const x: number = pointCoordinate[0]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { Utils } from "../Utils"
|
||||
import { Readable, Subscriber, Unsubscriber } from "svelte/store"
|
||||
|
||||
/**
|
||||
* Various static utils
|
||||
|
@ -88,7 +89,7 @@ export class Stores {
|
|||
}
|
||||
}
|
||||
|
||||
export abstract class Store<T> {
|
||||
export abstract class Store<T> implements Readable<T> {
|
||||
abstract readonly data: T
|
||||
|
||||
/**
|
||||
|
@ -113,6 +114,18 @@ export abstract class Store<T> {
|
|||
abstract map<J>(f: (t: T) => J): Store<J>
|
||||
abstract map<J>(f: (t: T) => J, extraStoresToWatch: Store<any>[]): Store<J>
|
||||
|
||||
public mapD<J>(f: (t: T) => J, extraStoresToWatch: Store<any>[]): Store<J> {
|
||||
return this.map((t) => {
|
||||
if (t === undefined) {
|
||||
return undefined
|
||||
}
|
||||
if (t === null) {
|
||||
return null
|
||||
}
|
||||
return f(t)
|
||||
}, extraStoresToWatch)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a callback function which will run on future data changes
|
||||
*/
|
||||
|
@ -258,6 +271,17 @@ export abstract class Store<T> {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as 'addCallbackAndRun', added to be compatible with Svelte
|
||||
* @param run
|
||||
* @param invalidate
|
||||
*/
|
||||
public subscribe(run: Subscriber<T> & ((value: T) => void), invalidate?): Unsubscriber {
|
||||
// We don't need to do anything with 'invalidate', see
|
||||
// https://github.com/sveltejs/svelte/issues/3859
|
||||
return this.addCallbackAndRun(run)
|
||||
}
|
||||
}
|
||||
|
||||
export class ImmutableStore<T> extends Store<T> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue