forked from MapComplete/MapComplete
Reformat all files with prettier
This commit is contained in:
parent
e22d189376
commit
b541d3eab4
382 changed files with 50893 additions and 35566 deletions
|
@ -1,87 +1,83 @@
|
|||
import {expect} from 'chai'
|
||||
import {Utils} from "../../../Utils";
|
||||
import UserRelatedState from "../../../Logic/State/UserRelatedState";
|
||||
import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig";
|
||||
import SelectedElementTagsUpdater from "../../../Logic/Actors/SelectedElementTagsUpdater";
|
||||
import { expect } from "chai"
|
||||
import { Utils } from "../../../Utils"
|
||||
import UserRelatedState from "../../../Logic/State/UserRelatedState"
|
||||
import LayoutConfig from "../../../Models/ThemeConfig/LayoutConfig"
|
||||
import SelectedElementTagsUpdater from "../../../Logic/Actors/SelectedElementTagsUpdater"
|
||||
|
||||
import * as bookcaseJson from "../../../assets/generated/themes/bookcases.json"
|
||||
import {UIEventSource} from "../../../Logic/UIEventSource";
|
||||
import Loc from "../../../Models/Loc";
|
||||
import SelectedFeatureHandler from "../../../Logic/Actors/SelectedFeatureHandler";
|
||||
import {ElementStorage} from "../../../Logic/ElementStorage";
|
||||
import { UIEventSource } from "../../../Logic/UIEventSource"
|
||||
import Loc from "../../../Models/Loc"
|
||||
import SelectedFeatureHandler from "../../../Logic/Actors/SelectedFeatureHandler"
|
||||
import { ElementStorage } from "../../../Logic/ElementStorage"
|
||||
|
||||
const latestTags = {
|
||||
"amenity": "public_bookcase",
|
||||
"books": "children;adults",
|
||||
"capacity": "25",
|
||||
"description": "Deze boekenruilkast vindt je recht tegenover de Pim Pam Poem",
|
||||
amenity: "public_bookcase",
|
||||
books: "children;adults",
|
||||
capacity: "25",
|
||||
description: "Deze boekenruilkast vindt je recht tegenover de Pim Pam Poem",
|
||||
"image:0": "https://i.imgur.com/Z8a69UG.jpg",
|
||||
"name": "Stubbekwartier-buurtbibliotheek",
|
||||
"nobrand": "yes",
|
||||
"opening_hours": "24/7",
|
||||
"operator": "Huisbewoner",
|
||||
"public_bookcase:type": "reading_box"
|
||||
name: "Stubbekwartier-buurtbibliotheek",
|
||||
nobrand: "yes",
|
||||
opening_hours: "24/7",
|
||||
operator: "Huisbewoner",
|
||||
"public_bookcase:type": "reading_box",
|
||||
}
|
||||
|
||||
Utils.injectJsonDownloadForTests(
|
||||
"https://www.openstreetmap.org/api/0.6/node/5568693115",
|
||||
{
|
||||
"version": "0.6",
|
||||
"generator": "CGImap 0.8.5 (1815943 spike-06.openstreetmap.org)",
|
||||
"copyright": "OpenStreetMap and contributors",
|
||||
"attribution": "http://www.openstreetmap.org/copyright",
|
||||
"license": "http://opendatacommons.org/licenses/odbl/1-0/",
|
||||
"elements": [{
|
||||
"type": "node",
|
||||
"id": 5568693115,
|
||||
"lat": 51.2179199,
|
||||
"lon": 3.2154662,
|
||||
"timestamp": "2021-08-21T16:22:55Z",
|
||||
"version": 6,
|
||||
"changeset": 110034454,
|
||||
"user": "Pieter Vander Vennet",
|
||||
"uid": 3818858,
|
||||
"tags": latestTags
|
||||
}]
|
||||
}
|
||||
)
|
||||
Utils.injectJsonDownloadForTests("https://www.openstreetmap.org/api/0.6/node/5568693115", {
|
||||
version: "0.6",
|
||||
generator: "CGImap 0.8.5 (1815943 spike-06.openstreetmap.org)",
|
||||
copyright: "OpenStreetMap and contributors",
|
||||
attribution: "http://www.openstreetmap.org/copyright",
|
||||
license: "http://opendatacommons.org/licenses/odbl/1-0/",
|
||||
elements: [
|
||||
{
|
||||
type: "node",
|
||||
id: 5568693115,
|
||||
lat: 51.2179199,
|
||||
lon: 3.2154662,
|
||||
timestamp: "2021-08-21T16:22:55Z",
|
||||
version: 6,
|
||||
changeset: 110034454,
|
||||
user: "Pieter Vander Vennet",
|
||||
uid: 3818858,
|
||||
tags: latestTags,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
it("should download the latest version", () => {
|
||||
const state = new UserRelatedState(new LayoutConfig(<any> bookcaseJson, true))
|
||||
it("should download the latest version", () => {
|
||||
const state = new UserRelatedState(new LayoutConfig(<any>bookcaseJson, true))
|
||||
const feature = {
|
||||
"type": "Feature",
|
||||
"id": "node/5568693115",
|
||||
"properties": {
|
||||
"amenity": "public_bookcase",
|
||||
"books": "children;adults",
|
||||
"capacity": "25",
|
||||
"description": "Deze boekenruilkast vindt je recht tegenover de Pim Pam Poem",
|
||||
type: "Feature",
|
||||
id: "node/5568693115",
|
||||
properties: {
|
||||
amenity: "public_bookcase",
|
||||
books: "children;adults",
|
||||
capacity: "25",
|
||||
description: "Deze boekenruilkast vindt je recht tegenover de Pim Pam Poem",
|
||||
"image:0": "https://i.imgur.com/Z8a69UG.jpg",
|
||||
"name": "OUTDATED NAME",
|
||||
"nobrand": "yes",
|
||||
"opening_hours": "24/7",
|
||||
"operator": "Huisbewoner",
|
||||
name: "OUTDATED NAME",
|
||||
nobrand: "yes",
|
||||
opening_hours: "24/7",
|
||||
operator: "Huisbewoner",
|
||||
"public_bookcase:type": "reading_box",
|
||||
"id": "node/5568693115",
|
||||
"_lat": "51.2179199",
|
||||
"_lon": "3.2154662",
|
||||
"fixme": "SOME FIXME"
|
||||
id: "node/5568693115",
|
||||
_lat: "51.2179199",
|
||||
_lon: "3.2154662",
|
||||
fixme: "SOME FIXME",
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Point",
|
||||
"coordinates": [
|
||||
3.2154662,
|
||||
51.2179199
|
||||
]
|
||||
geometry: {
|
||||
type: "Point",
|
||||
coordinates: [3.2154662, 51.2179199],
|
||||
},
|
||||
"bbox": {
|
||||
"maxLat": 51.2179199,
|
||||
"maxLon": 3.2154662,
|
||||
"minLat": 51.2179199,
|
||||
"minLon": 3.2154662
|
||||
bbox: {
|
||||
maxLat: 51.2179199,
|
||||
maxLon: 3.2154662,
|
||||
minLat: 51.2179199,
|
||||
minLon: 3.2154662,
|
||||
},
|
||||
"_lon": 3.2154662,
|
||||
"_lat": 51.2179199
|
||||
_lon: 3.2154662,
|
||||
_lat: 51.2179199,
|
||||
}
|
||||
state.allElements.addOrGetElement(feature)
|
||||
SelectedElementTagsUpdater.installCallback(state)
|
||||
|
@ -96,7 +92,6 @@ it("should download the latest version", () => {
|
|||
expect(feature.properties.name).deep.equal("Stubbekwartier-buurtbibliotheek")
|
||||
// The fixme should be removed
|
||||
expect(feature.properties.fixme).deep.equal(undefined)
|
||||
|
||||
})
|
||||
it("Hash without selected element should download geojson from OSM-API", async () => {
|
||||
const hash = new UIEventSource("node/5568693115")
|
||||
|
@ -104,11 +99,10 @@ it("Hash without selected element should download geojson from OSM-API", async (
|
|||
const loc = new UIEventSource<Loc>({
|
||||
lat: 0,
|
||||
lon: 0,
|
||||
zoom: 0
|
||||
zoom: 0,
|
||||
})
|
||||
|
||||
|
||||
loc.addCallback(_ => {
|
||||
loc.addCallback((_) => {
|
||||
expect(selected.data.properties.id).deep.equal("node/5568693115")
|
||||
expect(loc.data.zoom).deep.equal(14)
|
||||
expect(loc.data.lat).deep.equal(51.2179199)
|
||||
|
@ -119,8 +113,6 @@ it("Hash without selected element should download geojson from OSM-API", async (
|
|||
allElements: new ElementStorage(),
|
||||
featurePipeline: undefined,
|
||||
locationControl: loc,
|
||||
layoutToUse: undefined
|
||||
layoutToUse: undefined,
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,209 +1,126 @@
|
|||
import {describe} from 'mocha'
|
||||
import {expect} from 'chai'
|
||||
import CreateMultiPolygonWithPointReuseAction from "../../../Logic/Osm/Actions/CreateMultiPolygonWithPointReuseAction";
|
||||
import {Tag} from "../../../Logic/Tags/Tag";
|
||||
import {Changes} from "../../../Logic/Osm/Changes";
|
||||
import { describe } from "mocha"
|
||||
import { expect } from "chai"
|
||||
import CreateMultiPolygonWithPointReuseAction from "../../../Logic/Osm/Actions/CreateMultiPolygonWithPointReuseAction"
|
||||
import { Tag } from "../../../Logic/Tags/Tag"
|
||||
import { Changes } from "../../../Logic/Osm/Changes"
|
||||
|
||||
describe("CreateMultiPolygonWithPointReuseAction", () => {
|
||||
|
||||
it("should produce a correct changeset", () => {
|
||||
|
||||
async () => {
|
||||
|
||||
const feature = {
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"osm_id": "41097039",
|
||||
"size_grb_building": "1374.89",
|
||||
"addr:housenumber": "53",
|
||||
"addr:street": "Startelstraat",
|
||||
"building": "house",
|
||||
"source:geometry:entity": "Gbg",
|
||||
"source:geometry:date": "2014-04-28",
|
||||
"source:geometry:oidn": "150044",
|
||||
"source:geometry:uidn": "5403181",
|
||||
"H_DTM_MIN": "50.35",
|
||||
"H_DTM_GEM": "50.97",
|
||||
"H_DSM_MAX": "59.40",
|
||||
"H_DSM_P99": "59.09",
|
||||
"HN_MAX": "8.43",
|
||||
"HN_P99": "8.12",
|
||||
"detection_method": "derived from OSM landuse: farmyard",
|
||||
"auto_target_landuse": "farmyard",
|
||||
"size_source_landuse": "8246.28",
|
||||
"auto_building": "farm",
|
||||
"id": "41097039",
|
||||
"_lat": "50.84633355000016",
|
||||
"_lon": "5.262964150000011",
|
||||
"_layer": "grb",
|
||||
"_length": "185.06002152312757",
|
||||
"_length:km": "0.2",
|
||||
"_now:date": "2022-02-22",
|
||||
"_now:datetime": "2022-02-22 10:15:51",
|
||||
"_loaded:date": "2022-02-22",
|
||||
"_loaded:datetime": "2022-02-22 10:15:51",
|
||||
"_geometry:type": "Polygon",
|
||||
"_intersects_with_other_features": "",
|
||||
"_country": "be",
|
||||
"_overlaps_with_buildings": "[]",
|
||||
"_overlap_percentage": "null",
|
||||
"_grb_date": "2014-04-28",
|
||||
"_grb_ref": "Gbg/150044",
|
||||
"_building:min_level": "",
|
||||
"_surface": "548.1242491529038",
|
||||
"_surface:ha": "0",
|
||||
"_reverse_overlap_percentage": "null",
|
||||
"_imported_osm_object_found": "false",
|
||||
"_imported_osm_still_fresh": "false",
|
||||
"_target_building_type": "house"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": <[number, number][][]>[
|
||||
[
|
||||
[
|
||||
5.262684300000043,
|
||||
50.84624409999995
|
||||
],
|
||||
[
|
||||
5.262777500000024,
|
||||
50.84620759999988
|
||||
],
|
||||
[
|
||||
5.262798899999998,
|
||||
50.84621390000019
|
||||
],
|
||||
[
|
||||
5.262999799999994,
|
||||
50.84619519999999
|
||||
],
|
||||
[
|
||||
5.263107500000007,
|
||||
50.84618920000014
|
||||
],
|
||||
[
|
||||
5.263115,
|
||||
50.84620990000026
|
||||
],
|
||||
[
|
||||
5.26310279999998,
|
||||
50.84623050000014
|
||||
],
|
||||
[
|
||||
5.263117999999977,
|
||||
50.846247400000166
|
||||
],
|
||||
[
|
||||
5.263174599999989,
|
||||
50.84631019999971
|
||||
],
|
||||
[
|
||||
5.263166999999989,
|
||||
50.84631459999995
|
||||
],
|
||||
[
|
||||
5.263243999999979,
|
||||
50.84640239999989
|
||||
],
|
||||
[
|
||||
5.2631607000000065,
|
||||
50.84643459999996
|
||||
],
|
||||
[
|
||||
5.26313309999997,
|
||||
50.84640089999985
|
||||
],
|
||||
[
|
||||
5.262907499999996,
|
||||
50.84647790000018
|
||||
],
|
||||
[
|
||||
5.2628939999999576,
|
||||
50.846463699999774
|
||||
],
|
||||
[
|
||||
5.262872100000033,
|
||||
50.846440700000294
|
||||
],
|
||||
[
|
||||
5.262784699999991,
|
||||
50.846348899999924
|
||||
],
|
||||
[
|
||||
5.262684300000043,
|
||||
50.84624409999995
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
5.262801899999976,
|
||||
50.84623269999982
|
||||
],
|
||||
[
|
||||
5.2629535000000285,
|
||||
50.84638830000012
|
||||
],
|
||||
[
|
||||
5.263070700000018,
|
||||
50.84634720000008
|
||||
],
|
||||
[
|
||||
5.262998000000025,
|
||||
50.84626279999982
|
||||
],
|
||||
[
|
||||
5.263066799999966,
|
||||
50.84623959999975
|
||||
],
|
||||
[
|
||||
5.263064000000004,
|
||||
50.84623330000007
|
||||
],
|
||||
[
|
||||
5.263009599999997,
|
||||
50.84623730000026
|
||||
],
|
||||
[
|
||||
5.263010199999956,
|
||||
50.84621629999986
|
||||
],
|
||||
[
|
||||
5.262801899999976,
|
||||
50.84623269999982
|
||||
]
|
||||
]
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
const innerRings = [...feature.geometry.coordinates]
|
||||
innerRings.splice(0, 1)
|
||||
|
||||
const action = new CreateMultiPolygonWithPointReuseAction(
|
||||
[new Tag("building", "yes")],
|
||||
feature.geometry.coordinates[0],
|
||||
innerRings,
|
||||
undefined,
|
||||
[],
|
||||
"import"
|
||||
)
|
||||
const descriptions = await action.Perform(new Changes())
|
||||
|
||||
const ways= descriptions.filter(d => d.type === "way")
|
||||
expect(ways[0].id == -18, "unexpected id").true
|
||||
expect(ways[1].id == -27, "unexpected id").true
|
||||
const outer = ways[0].changes["coordinates"]
|
||||
expect(outer).deep.equal(feature.geometry.coordinates[0])
|
||||
const inner = ways[1].changes["coordinates"]
|
||||
expect(inner).deep.equal(feature.geometry.coordinates[1])
|
||||
const members = <{type: string, role: string, ref: number}[]> descriptions.find(d => d.type === "relation").changes["members"]
|
||||
expect(members[0].role, "incorrect role").eq("outer")
|
||||
expect(members[1].role, "incorrect role").eq("inner")
|
||||
expect(members[0].type , "incorrect type").eq("way")
|
||||
expect(members[1].type , "incorrect type").eq("way")
|
||||
expect(members[0].ref, "incorrect id").eq(-18)
|
||||
expect(members[1].ref , "incorrect id").eq(-27)
|
||||
it("should produce a correct changeset", () => {
|
||||
;async () => {
|
||||
const feature = {
|
||||
type: "Feature",
|
||||
properties: {
|
||||
osm_id: "41097039",
|
||||
size_grb_building: "1374.89",
|
||||
"addr:housenumber": "53",
|
||||
"addr:street": "Startelstraat",
|
||||
building: "house",
|
||||
"source:geometry:entity": "Gbg",
|
||||
"source:geometry:date": "2014-04-28",
|
||||
"source:geometry:oidn": "150044",
|
||||
"source:geometry:uidn": "5403181",
|
||||
H_DTM_MIN: "50.35",
|
||||
H_DTM_GEM: "50.97",
|
||||
H_DSM_MAX: "59.40",
|
||||
H_DSM_P99: "59.09",
|
||||
HN_MAX: "8.43",
|
||||
HN_P99: "8.12",
|
||||
detection_method: "derived from OSM landuse: farmyard",
|
||||
auto_target_landuse: "farmyard",
|
||||
size_source_landuse: "8246.28",
|
||||
auto_building: "farm",
|
||||
id: "41097039",
|
||||
_lat: "50.84633355000016",
|
||||
_lon: "5.262964150000011",
|
||||
_layer: "grb",
|
||||
_length: "185.06002152312757",
|
||||
"_length:km": "0.2",
|
||||
"_now:date": "2022-02-22",
|
||||
"_now:datetime": "2022-02-22 10:15:51",
|
||||
"_loaded:date": "2022-02-22",
|
||||
"_loaded:datetime": "2022-02-22 10:15:51",
|
||||
"_geometry:type": "Polygon",
|
||||
_intersects_with_other_features: "",
|
||||
_country: "be",
|
||||
_overlaps_with_buildings: "[]",
|
||||
_overlap_percentage: "null",
|
||||
_grb_date: "2014-04-28",
|
||||
_grb_ref: "Gbg/150044",
|
||||
"_building:min_level": "",
|
||||
_surface: "548.1242491529038",
|
||||
"_surface:ha": "0",
|
||||
_reverse_overlap_percentage: "null",
|
||||
_imported_osm_object_found: "false",
|
||||
_imported_osm_still_fresh: "false",
|
||||
_target_building_type: "house",
|
||||
},
|
||||
geometry: {
|
||||
type: "Polygon",
|
||||
coordinates: <[number, number][][]>[
|
||||
[
|
||||
[5.262684300000043, 50.84624409999995],
|
||||
[5.262777500000024, 50.84620759999988],
|
||||
[5.262798899999998, 50.84621390000019],
|
||||
[5.262999799999994, 50.84619519999999],
|
||||
[5.263107500000007, 50.84618920000014],
|
||||
[5.263115, 50.84620990000026],
|
||||
[5.26310279999998, 50.84623050000014],
|
||||
[5.263117999999977, 50.846247400000166],
|
||||
[5.263174599999989, 50.84631019999971],
|
||||
[5.263166999999989, 50.84631459999995],
|
||||
[5.263243999999979, 50.84640239999989],
|
||||
[5.2631607000000065, 50.84643459999996],
|
||||
[5.26313309999997, 50.84640089999985],
|
||||
[5.262907499999996, 50.84647790000018],
|
||||
[5.2628939999999576, 50.846463699999774],
|
||||
[5.262872100000033, 50.846440700000294],
|
||||
[5.262784699999991, 50.846348899999924],
|
||||
[5.262684300000043, 50.84624409999995],
|
||||
],
|
||||
[
|
||||
[5.262801899999976, 50.84623269999982],
|
||||
[5.2629535000000285, 50.84638830000012],
|
||||
[5.263070700000018, 50.84634720000008],
|
||||
[5.262998000000025, 50.84626279999982],
|
||||
[5.263066799999966, 50.84623959999975],
|
||||
[5.263064000000004, 50.84623330000007],
|
||||
[5.263009599999997, 50.84623730000026],
|
||||
[5.263010199999956, 50.84621629999986],
|
||||
[5.262801899999976, 50.84623269999982],
|
||||
],
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
const innerRings = [...feature.geometry.coordinates]
|
||||
innerRings.splice(0, 1)
|
||||
|
||||
const action = new CreateMultiPolygonWithPointReuseAction(
|
||||
[new Tag("building", "yes")],
|
||||
feature.geometry.coordinates[0],
|
||||
innerRings,
|
||||
undefined,
|
||||
[],
|
||||
"import"
|
||||
)
|
||||
const descriptions = await action.Perform(new Changes())
|
||||
|
||||
const ways = descriptions.filter((d) => d.type === "way")
|
||||
expect(ways[0].id == -18, "unexpected id").true
|
||||
expect(ways[1].id == -27, "unexpected id").true
|
||||
const outer = ways[0].changes["coordinates"]
|
||||
expect(outer).deep.equal(feature.geometry.coordinates[0])
|
||||
const inner = ways[1].changes["coordinates"]
|
||||
expect(inner).deep.equal(feature.geometry.coordinates[1])
|
||||
const members = <{ type: string; role: string; ref: number }[]>(
|
||||
descriptions.find((d) => d.type === "relation").changes["members"]
|
||||
)
|
||||
expect(members[0].role, "incorrect role").eq("outer")
|
||||
expect(members[1].role, "incorrect role").eq("inner")
|
||||
expect(members[0].type, "incorrect type").eq("way")
|
||||
expect(members[1].type, "incorrect type").eq("way")
|
||||
expect(members[0].ref, "incorrect id").eq(-18)
|
||||
expect(members[1].ref, "incorrect id").eq(-27)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue