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
109
test.ts
109
test.ts
|
@ -1,90 +1,25 @@
|
|||
import MangroveReviewsOfFeature, { MangroveIdentity } from "./Logic/Web/MangroveReviews"
|
||||
import { Feature, Point } from "geojson"
|
||||
import { OsmTags } from "./Models/OsmFeature"
|
||||
import { VariableUiElement } from "./UI/Base/VariableUIElement"
|
||||
import ContactLink from "./UI/BigComponents/ContactLink.svelte"
|
||||
import SvelteUIElement from "./UI/Base/SvelteUIElement"
|
||||
import { Utils } from "./Utils"
|
||||
import List from "./UI/Base/List"
|
||||
import { UIEventSource } from "./Logic/UIEventSource"
|
||||
import UserRelatedState from "./Logic/State/UserRelatedState"
|
||||
import { GeoOperations } from "./Logic/GeoOperations"
|
||||
import { Tiles } from "./Models/TileRange"
|
||||
import { Stores } from "./Logic/UIEventSource"
|
||||
|
||||
const feature: Feature<Point, OsmTags> = {
|
||||
type: "Feature",
|
||||
id: "node/6739848322",
|
||||
properties: {
|
||||
"addr:city": "San Diego",
|
||||
"addr:housenumber": "2816",
|
||||
"addr:postcode": "92106",
|
||||
"addr:street": "Historic Decatur Road",
|
||||
"addr:unit": "116",
|
||||
amenity: "restaurant",
|
||||
cuisine: "burger",
|
||||
delivery: "yes",
|
||||
"diet:halal": "no",
|
||||
"diet:vegetarian": "yes",
|
||||
dog: "yes",
|
||||
image: "https://i.imgur.com/AQlGNHQ.jpg",
|
||||
internet_access: "wlan",
|
||||
"internet_access:fee": "no",
|
||||
"internet_access:ssid": "Public-stinebrewingCo",
|
||||
microbrewery: "yes",
|
||||
name: "Stone Brewing World Bistro & Gardens",
|
||||
opening_hours: "Mo-Fr, Su 11:30-21:00; Sa 11:30-22:00",
|
||||
organic: "no",
|
||||
"payment:cards": "yes",
|
||||
"payment:cash": "yes",
|
||||
"service:electricity": "ask",
|
||||
takeaway: "yes",
|
||||
website: "https://www.stonebrewing.com/visit/bistros/liberty-station",
|
||||
wheelchair: "designated",
|
||||
"_last_edit:contributor": "Drew Dowling",
|
||||
"_last_edit:timestamp": "2023-01-11T23:22:28Z",
|
||||
id: "node/6739848322",
|
||||
timestamp: "2023-01-11T23:22:28Z",
|
||||
user: "Drew Dowling",
|
||||
_backend: "https://www.openstreetmap.org",
|
||||
_lat: "32.7404614",
|
||||
_lon: "-117.211684",
|
||||
_layer: "food",
|
||||
_length: "0",
|
||||
"_length:km": "0.0",
|
||||
"_now:date": "2023-01-20",
|
||||
"_now:datetime": "2023-01-20 17:46:54",
|
||||
"_loaded:date": "2023-01-20",
|
||||
"_loaded:datetime": "2023-01-20 17:46:54",
|
||||
"_geometry:type": "Point",
|
||||
_surface: "0",
|
||||
"_surface:ha": "0",
|
||||
_country: "us",
|
||||
},
|
||||
geometry: {
|
||||
type: "Point",
|
||||
coordinates: [0, 0],
|
||||
},
|
||||
}
|
||||
const state = new UserRelatedState(undefined)
|
||||
|
||||
state.allElements.addOrGetElement(feature)
|
||||
|
||||
const reviews = MangroveReviewsOfFeature.construct(feature, state)
|
||||
|
||||
reviews.reviews.addCallbackAndRun((r) => {
|
||||
console.log("Reviews are:", r)
|
||||
})
|
||||
window.setTimeout(async () => {
|
||||
await reviews.createReview({
|
||||
opinion: "Cool bar",
|
||||
rating: 90,
|
||||
metadata: {
|
||||
nickname: "Pietervdvn",
|
||||
},
|
||||
})
|
||||
console.log("Submitted review")
|
||||
}, 1000)
|
||||
|
||||
new VariableUiElement(
|
||||
reviews.reviews.map(
|
||||
(reviews) =>
|
||||
new List(
|
||||
reviews.map((r) => r.rating + "% " + r.opinion + " (" + r.metadata.nickname + ")")
|
||||
)
|
||||
async function main() {
|
||||
const location: [number, number] = [3.21, 51.2]
|
||||
const t = Tiles.embedded_tile(location[1], location[0], 6)
|
||||
const url = `https://raw.githubusercontent.com/pietervdvn/MapComplete-data/main/community_index/tile_${t.z}_${t.x}_${t.y}.geojson`
|
||||
const be = Stores.FromPromise(Utils.downloadJson(url)).mapD(
|
||||
(data) => data.features.find((f) => GeoOperations.inside(location, f)).properties
|
||||
)
|
||||
).AttachTo("maindiv")
|
||||
new SvelteUIElement(ContactLink, { country: be }).AttachTo("maindiv")
|
||||
/*
|
||||
const links = data.features
|
||||
.filter((f) => GeoOperations.inside(location, f))
|
||||
.map((f) => new SvelteUIElement(ContactLink, { country: f.properties }))
|
||||
new List(links).AttachTo("maindiv")
|
||||
//*/
|
||||
}
|
||||
|
||||
main().then((_) => {})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue