Housekeeping: formatting

This commit is contained in:
Pieter Vander Vennet 2024-02-20 13:33:38 +01:00
parent 9d53a45f9a
commit 1528dfaae1
168 changed files with 3332 additions and 4560 deletions

View file

@ -45,12 +45,7 @@ export default class LayoutSource extends FeatureSourceMerger {
})
)
const overpassSource = LayoutSource.setupOverpass(
osmLayers,
bounds,
zoom,
featureSwitches
)
const overpassSource = LayoutSource.setupOverpass(osmLayers, bounds, zoom, featureSwitches)
const osmApiSource = LayoutSource.setupOsmApiSource(
osmLayers,

View file

@ -156,7 +156,7 @@ export class GeoOperations {
const intersection = GeoOperations.calculateIntersection(
feature,
otherFeature,
featureBBox,
featureBBox
)
if (intersection === null) {
continue
@ -195,7 +195,7 @@ export class GeoOperations {
console.error(
"Could not correctly calculate the overlap of ",
feature,
": unsupported type",
": unsupported type"
)
return result
}
@ -224,7 +224,7 @@ export class GeoOperations {
*/
public static inside(
pointCoordinate: [number, number] | Feature<Point>,
feature: Feature,
feature: Feature
): boolean {
// ray-casting algorithm based on
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
@ -302,7 +302,7 @@ export class GeoOperations {
*/
public static nearestPoint(
way: Feature<LineString>,
point: [number, number],
point: [number, number]
): Feature<
Point,
{
@ -324,11 +324,11 @@ export class GeoOperations {
public static forceLineString(way: Feature<LineString | Polygon>): Feature<LineString>
public static forceLineString(
way: Feature<MultiLineString | MultiPolygon>,
way: Feature<MultiLineString | MultiPolygon>
): Feature<MultiLineString>
public static forceLineString(
way: Feature<LineString | MultiLineString | Polygon | MultiPolygon>,
way: Feature<LineString | MultiLineString | Polygon | MultiPolygon>
): Feature<LineString | MultiLineString> {
if (way.geometry.type === "Polygon") {
way = { ...way }
@ -345,9 +345,12 @@ export class GeoOperations {
return <any>way
}
public static toCSV(features: Feature[] | FeatureCollection, options?: {
ignoreTags?: RegExp
}): string {
public static toCSV(
features: Feature[] | FeatureCollection,
options?: {
ignoreTags?: RegExp
}
): string {
const headerValuesSeen = new Set<string>()
const headerValuesOrdered: string[] = []
@ -455,7 +458,7 @@ export class GeoOperations {
*/
public static LineIntersections(
feature: Feature<LineString | MultiLineString | Polygon | MultiPolygon>,
otherFeature: Feature<LineString | MultiLineString | Polygon | MultiPolygon>,
otherFeature: Feature<LineString | MultiLineString | Polygon | MultiPolygon>
): [number, number][] {
return turf
.lineIntersect(feature, otherFeature)
@ -492,7 +495,7 @@ export class GeoOperations {
locations:
| Feature<LineString>
| Feature<Point, { date?: string; altitude?: number | string }>[],
title?: string,
title?: string
) {
title = title?.trim()
if (title === undefined || title === "") {
@ -513,7 +516,7 @@ export class GeoOperations {
type: "Point",
coordinates: p,
},
},
}
)
}
for (const l of locationsWithMeta) {
@ -528,7 +531,7 @@ export class GeoOperations {
trackPoints.push(trkpt)
}
const header =
"<gpx version=\"1.1\" creator=\"mapcomplete.org\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">"
'<gpx version="1.1" creator="mapcomplete.org" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">'
return (
header +
"\n<name>" +
@ -546,7 +549,7 @@ export class GeoOperations {
*/
public static toGpxPoints(
locations: Feature<Point, { date?: string; altitude?: number | string }>[],
title?: string,
title?: string
) {
title = title?.trim()
if (title === undefined || title === "") {
@ -567,7 +570,7 @@ export class GeoOperations {
trackPoints.push(trkpt)
}
const header =
"<gpx version=\"1.1\" creator=\"mapcomplete.org\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">"
'<gpx version="1.1" creator="mapcomplete.org" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">'
return (
header +
"\n<name>" +
@ -655,7 +658,7 @@ export class GeoOperations {
},
},
distanceMeter,
{ units: "meters" },
{ units: "meters" }
).geometry.coordinates
}
@ -690,7 +693,7 @@ export class GeoOperations {
*/
static completelyWithin(
feature: Feature<Geometry, any>,
possiblyEnclosingFeature: Feature<Polygon | MultiPolygon, any>,
possiblyEnclosingFeature: Feature<Polygon | MultiPolygon, any>
): boolean {
return booleanWithin(feature, possiblyEnclosingFeature)
}
@ -746,7 +749,14 @@ export class GeoOperations {
*/
public static featureToCoordinateWithRenderingType(
feature: Feature,
location: "point" | "centroid" | "start" | "end" | "projected_centerpoint" | "polygon_centerpoint" | string,
location:
| "point"
| "centroid"
| "start"
| "end"
| "projected_centerpoint"
| "polygon_centerpoint"
| string
): [number, number] | undefined {
switch (location) {
case "point":
@ -772,7 +782,7 @@ export class GeoOperations {
const centerpoint = GeoOperations.centerpointCoordinates(feature)
const projected = GeoOperations.nearestPoint(
<Feature<LineString>>feature,
centerpoint,
centerpoint
)
return <[number, number]>projected.geometry.coordinates
}
@ -949,7 +959,7 @@ export class GeoOperations {
* GeoOperations.bearingToHuman(46) // => "NE"
*/
public static bearingToHuman(
bearing: number,
bearing: number
): "N" | "NE" | "E" | "SE" | "S" | "SW" | "W" | "NW" {
while (bearing < 0) {
bearing += 360
@ -975,7 +985,7 @@ export class GeoOperations {
*
*/
public static bearingToHumanRelative(
bearing: number,
bearing: number
):
| "straight"
| "slight_right"
@ -1000,12 +1010,12 @@ export class GeoOperations {
private static pointInPolygonCoordinates(
x: number,
y: number,
coordinates: [number, number][][],
coordinates: [number, number][][]
): boolean {
const inside = GeoOperations.pointWithinRing(
x,
y,
/*This is the outer ring of the polygon */ coordinates[0],
/*This is the outer ring of the polygon */ coordinates[0]
)
if (!inside) {
return false
@ -1014,7 +1024,7 @@ export class GeoOperations {
const inHole = GeoOperations.pointWithinRing(
x,
y,
coordinates[i], /* These are inner rings, aka holes*/
coordinates[i] /* These are inner rings, aka holes*/
)
if (inHole) {
return false
@ -1052,7 +1062,7 @@ export class GeoOperations {
feature,
otherFeature,
featureBBox: BBox,
otherFeatureBBox?: BBox,
otherFeatureBBox?: BBox
): number {
if (feature.geometry.type === "LineString") {
otherFeatureBBox = otherFeatureBBox ?? BBox.get(otherFeature)
@ -1101,7 +1111,7 @@ export class GeoOperations {
let intersection = turf.lineSlice(
turf.point(intersectionPointsArray[0]),
turf.point(intersectionPointsArray[1]),
feature,
feature
)
if (intersection == null) {
@ -1122,7 +1132,7 @@ export class GeoOperations {
otherFeature,
feature,
otherFeatureBBox,
featureBBox,
featureBBox
)
}
@ -1142,7 +1152,7 @@ export class GeoOperations {
console.log("Applying fallback intersection...")
const intersection = turf.intersect(
turf.truncate(feature),
turf.truncate(otherFeature),
turf.truncate(otherFeature)
)
if (intersection == null) {
return null

View file

@ -364,7 +364,7 @@ export default class UserRelatedState {
[translationMode]
)
this.mangroveIdentity.getKeyId().addCallbackAndRun(kid => {
this.mangroveIdentity.getKeyId().addCallbackAndRun((kid) => {
amendedPrefs.data["mangrove_kid"] = kid
amendedPrefs.ping()
})

View file

@ -1,14 +1,42 @@
import { Utils } from "../../Utils"
/** This code is autogenerated - do not edit. Edit ./assets/layers/usersettings/usersettings.json instead */
export class ThemeMetaTagging {
public static readonly themeName = "usersettings"
public static readonly themeName = "usersettings"
public metaTaggging_for_usersettings(feat: {properties: Record<string, string>}) {
Utils.AddLazyProperty(feat.properties, '_mastodon_candidate_md', () => feat.properties._description.match(/\[[^\]]*\]\((.*(mastodon|en.osm.town).*)\).*/)?.at(1) )
Utils.AddLazyProperty(feat.properties, '_d', () => feat.properties._description?.replace(/&lt;/g,'<')?.replace(/&gt;/g,'>') ?? '' )
Utils.AddLazyProperty(feat.properties, '_mastodon_candidate_a', () => (feat => {const e = document.createElement('div');e.innerHTML = feat.properties._d;return Array.from(e.getElementsByTagName("a")).filter(a => a.href.match(/mastodon|en.osm.town/) !== null)[0]?.href }) (feat) )
Utils.AddLazyProperty(feat.properties, '_mastodon_link', () => (feat => {const e = document.createElement('div');e.innerHTML = feat.properties._d;return Array.from(e.getElementsByTagName("a")).filter(a => a.getAttribute("rel")?.indexOf('me') >= 0)[0]?.href})(feat) )
Utils.AddLazyProperty(feat.properties, '_mastodon_candidate', () => feat.properties._mastodon_candidate_md ?? feat.properties._mastodon_candidate_a )
feat.properties['__current_backgroun'] = 'initial_value'
}
}
public metaTaggging_for_usersettings(feat: { properties: Record<string, string> }) {
Utils.AddLazyProperty(feat.properties, "_mastodon_candidate_md", () =>
feat.properties._description
.match(/\[[^\]]*\]\((.*(mastodon|en.osm.town).*)\).*/)
?.at(1)
)
Utils.AddLazyProperty(
feat.properties,
"_d",
() => feat.properties._description?.replace(/&lt;/g, "<")?.replace(/&gt;/g, ">") ?? ""
)
Utils.AddLazyProperty(feat.properties, "_mastodon_candidate_a", () =>
((feat) => {
const e = document.createElement("div")
e.innerHTML = feat.properties._d
return Array.from(e.getElementsByTagName("a")).filter(
(a) => a.href.match(/mastodon|en.osm.town/) !== null
)[0]?.href
})(feat)
)
Utils.AddLazyProperty(feat.properties, "_mastodon_link", () =>
((feat) => {
const e = document.createElement("div")
e.innerHTML = feat.properties._d
return Array.from(e.getElementsByTagName("a")).filter(
(a) => a.getAttribute("rel")?.indexOf("me") >= 0
)[0]?.href
})(feat)
)
Utils.AddLazyProperty(
feat.properties,
"_mastodon_candidate",
() => feat.properties._mastodon_candidate_md ?? feat.properties._mastodon_candidate_a
)
feat.properties["__current_backgroun"] = "initial_value"
}
}

View file

@ -432,6 +432,6 @@ export class And extends TagsFilter {
}
asMapboxExpression(): ExpressionSpecification {
return ["all", ...this.and.map(t => t.asMapboxExpression())]
return ["all", ...this.and.map((t) => t.asMapboxExpression())]
}
}

View file

@ -13,7 +13,7 @@ export default class ComparingTag implements TagsFilter {
key: string,
predicate: (value: string | undefined) => boolean,
representation: "<" | ">" | "<=" | ">=",
boundary: string,
boundary: string
) {
this._key = key
this._predicate = predicate

View file

@ -291,6 +291,6 @@ export class Or extends TagsFilter {
}
asMapboxExpression(): ExpressionSpecification {
return ["any", ...this.or.map(t => t.asMapboxExpression())]
return ["any", ...this.or.map((t) => t.asMapboxExpression())]
}
}

View file

@ -360,8 +360,8 @@ export class RegexTag extends TagsFilter {
}
asMapboxExpression(): ExpressionSpecification {
if(typeof this.key=== "string" && typeof this.value === "string" ) {
return [this.invert ? "!=" : "==", ["get",this.key], this.value]
if (typeof this.key === "string" && typeof this.value === "string") {
return [this.invert ? "!=" : "==", ["get", this.key], this.value]
}
throw "TODO"
}

View file

@ -65,7 +65,7 @@ export class Tag extends TagsFilter {
asOverpass(): string[] {
if (this.value === "") {
// NOT having this key
return ["[!\"" + this.key + "\"]"]
return ['[!"' + this.key + '"]']
}
return [`["${this.key}"="${this.value}"]`]
}
@ -83,7 +83,7 @@ export class Tag extends TagsFilter {
asHumanString(
linkToWiki?: boolean,
shorten?: boolean,
currentProperties?: Record<string, string>,
currentProperties?: Record<string, string>
) {
let v = this.value
if (typeof v !== "string") {
@ -170,12 +170,7 @@ export class Tag extends TagsFilter {
asMapboxExpression(): ExpressionSpecification {
if (this.value === "") {
return [
"any",
["!", ["has", this.key]],
["==", ["get", this.key], ""],
]
return ["any", ["!", ["has", this.key]], ["==", ["get", this.key], ""]]
}
return ["==", ["get", this.key], this.value]
}

View file

@ -24,8 +24,6 @@ export class MangroveIdentity {
const pem = await MangroveReviews.publicToPem(keypair.publicKey)
key_id.setData(pem)
})
}
/**
@ -48,7 +46,7 @@ export class MangroveIdentity {
* Only called to create a review.
*/
async getKeypair(): Promise<CryptoKeyPair> {
if(this.keypair.data ?? "" === ""){
if (this.keypair.data ?? "" === "") {
// We want to create a review, but it seems like no key has been setup at this moment
// We create the key
try {
@ -66,33 +64,36 @@ export class MangroveIdentity {
return this.key_id
}
private allReviewsById : UIEventSource<(Review & {kid: string, signature: string})[]>= undefined
private allReviewsById: UIEventSource<(Review & { kid: string; signature: string })[]> =
undefined
/**
* Gets all reviews that are made for the current identity.
*/
public getAllReviews(): Store<(Review & {kid: string, signature: string})[]>{
if(this.allReviewsById !== undefined){
public getAllReviews(): Store<(Review & { kid: string; signature: string })[]> {
if (this.allReviewsById !== undefined) {
return this.allReviewsById
}
this.allReviewsById = new UIEventSource( [])
this.key_id.map(pem => {
if(pem === undefined){
this.allReviewsById = new UIEventSource([])
this.key_id.map((pem) => {
if (pem === undefined) {
return []
}
MangroveReviews.getReviews({
kid: pem
}).then(allReviews => {
this.allReviewsById.setData(allReviews.reviews.map(r => ({
...r, ...r.payload
})))
kid: pem,
}).then((allReviews) => {
this.allReviewsById.setData(
allReviews.reviews.map((r) => ({
...r,
...r.payload,
}))
)
})
})
return this.allReviewsById
}
addReview(review: Review & {kid, signature}) {
addReview(review: Review & { kid; signature }) {
this.allReviewsById?.setData(this.allReviewsById?.data?.concat([review]))
}
}
@ -225,8 +226,15 @@ export default class FeatureReviews {
* The given review is uploaded to mangrove.reviews and added to the list of known reviews
*/
public async createReview(review: Omit<Review, "sub">): Promise<void> {
if(review.opinion !== undefined && review.opinion.length > FeatureReviews .REVIEW_OPINION_MAX_LENGTH){
throw "Opinion too long, should be at most "+FeatureReviews.REVIEW_OPINION_MAX_LENGTH+" characters long"
if (
review.opinion !== undefined &&
review.opinion.length > FeatureReviews.REVIEW_OPINION_MAX_LENGTH
) {
throw (
"Opinion too long, should be at most " +
FeatureReviews.REVIEW_OPINION_MAX_LENGTH +
" characters long"
)
}
const r: Review = {
sub: this.subjectUri.data,
@ -242,13 +250,11 @@ export default class FeatureReviews {
signature: jwt,
madeByLoggedInUser: new ImmutableStore(true),
}
this._reviews.data.push( reviewWithKid)
this._reviews.data.push(reviewWithKid)
this._reviews.ping()
this._identity.addReview(reviewWithKid)
}
/**
* Adds given reviews to the 'reviews'-UI-eventsource
* @param reviews