Implementation du systmème de symbole sur l'app web
This commit is contained in:
parent
ef1734ccd4
commit
f7e5bb37bf
15 changed files with 599 additions and 190 deletions
123
js/places.js
123
js/places.js
|
|
@ -1,10 +1,11 @@
|
|||
import lunr from "./lib/lunr/lunr.js"
|
||||
import lunrStemmer from "./lib/lunr/lunr.stemmer.support.js"
|
||||
import lunrFr from "./lib/lunr/lunr.fr.js"
|
||||
import { MapSymbol } from "./symbols.js"
|
||||
lunrStemmer(lunr)
|
||||
lunrFr(lunr)
|
||||
|
||||
const FEATURE_I = Symbol("Feature index")
|
||||
const FEATURE_INDEX = Symbol("Feature index")
|
||||
export const FEATURE_ID = Symbol("Feature id")
|
||||
|
||||
/**
|
||||
|
|
@ -92,22 +93,29 @@ export class PlaceDatabase extends EventTarget {
|
|||
let all_ids = []
|
||||
|
||||
if(geojson.type == "Feature"){
|
||||
let featureId = geojson?.properties?.id || geojson?.properties?.[FEATURE_I]
|
||||
let full_id = idPrefix+"#"+featureId
|
||||
|
||||
if(this.featuresById[full_id]){
|
||||
console.warn(`Warning: a feature with ID "${full_id}" already exists in database`)
|
||||
let feature = geojson;
|
||||
if(!(feature instanceof MapFeature)){
|
||||
feature = new MapFeature(geojson)
|
||||
}
|
||||
|
||||
geojson[FEATURE_ID] = full_id
|
||||
this.featuresById[full_id] = geojson
|
||||
if(!feature.id){
|
||||
let full_id = idPrefix+"#"+(geojson?.properties?.id || geojson?.properties?.[FEATURE_INDEX])
|
||||
feature.id = full_id
|
||||
}
|
||||
|
||||
if(this.featuresById[feature.id]){
|
||||
console.warn(`Warning: a feature with ID "${feature.id}" already exists in database`)
|
||||
}
|
||||
|
||||
this.featuresById[feature.id] = feature
|
||||
|
||||
let event = new Event("newfeature")
|
||||
event.ref = full_id
|
||||
event.feature = geojson
|
||||
event.ref = feature.id
|
||||
event.feature = feature
|
||||
this.dispatchEvent(event)
|
||||
|
||||
all_ids.push(full_id)
|
||||
all_ids.push(feature.id)
|
||||
|
||||
} else if(geojson.type == "FeatureCollection") {
|
||||
|
||||
|
|
@ -115,15 +123,15 @@ export class PlaceDatabase extends EventTarget {
|
|||
idPrefix += (idPrefix != "" ? "-" : "")+geojson.name
|
||||
}
|
||||
|
||||
if(geojson?.properties?.[FEATURE_I]){
|
||||
idPrefix += (idPrefix != "" ? "-" : "")+geojson.properties[FEATURE_I]
|
||||
if(geojson?.properties?.[FEATURE_INDEX]){
|
||||
idPrefix += (idPrefix != "" ? "-" : "")+geojson.properties[FEATURE_INDEX]
|
||||
}
|
||||
|
||||
for(let [i, feature] of Object.entries(geojson.features)){
|
||||
|
||||
feature.properties = {
|
||||
...(feature.properties || {}),
|
||||
[FEATURE_I]: i
|
||||
[FEATURE_INDEX]: i
|
||||
}
|
||||
|
||||
let id = this.addFeature(feature, {
|
||||
|
|
@ -159,19 +167,21 @@ export class PlaceDatabase extends EventTarget {
|
|||
this.field("synonyms")
|
||||
|
||||
for(let [id, feature] of Object.entries(database.featuresById)){
|
||||
let synonyms = ""
|
||||
let sym = feature.mapSymbol;
|
||||
|
||||
if(feature.properties["n couchage"] > 0){
|
||||
synonyms += SLEEPING_SYNONYMS.join(" ")
|
||||
let synonyms = []
|
||||
|
||||
if(sym.genericName){
|
||||
synonyms.push(sym.genericName)
|
||||
}
|
||||
|
||||
if(feature.properties["toilettes"]){
|
||||
synonyms += " "+TOILETTES_SYNONYMS.join(" ")
|
||||
if(sym.indexSynonyms){
|
||||
synonyms.push(...sym.indexSynonyms)
|
||||
}
|
||||
|
||||
this.add({
|
||||
id,
|
||||
name: feature.properties.name,
|
||||
name: feature.properties.name || sym.genericName,
|
||||
synonyms
|
||||
})
|
||||
}
|
||||
|
|
@ -213,32 +223,51 @@ export class PlaceDatabase extends EventTarget {
|
|||
|
||||
}
|
||||
|
||||
const SLEEPING_SYNONYMS = [
|
||||
"dodo",
|
||||
"dortoir",
|
||||
"mimir",
|
||||
"dormir",
|
||||
"lit"
|
||||
]
|
||||
const POINT_FEATURE = Symbol("Point feature")
|
||||
|
||||
const TOILETTES_SYNONYMS = [
|
||||
"caca",
|
||||
"pipi",
|
||||
"cabinets",
|
||||
"water-closet",
|
||||
"latrines",
|
||||
"🚽",
|
||||
"double véssé",
|
||||
"chaise percée",
|
||||
"WC",
|
||||
"waters",
|
||||
"toilettes",
|
||||
"toilette",
|
||||
"chiotte",
|
||||
"chiottes",
|
||||
"le trône",
|
||||
"le trones",
|
||||
"pièce mystère",
|
||||
"backroom",
|
||||
"retailleau"
|
||||
]
|
||||
export class MapFeature {
|
||||
constructor(geojson){
|
||||
Object.assign(this, geojson)
|
||||
}
|
||||
|
||||
get id(){
|
||||
return this[FEATURE_ID]
|
||||
}
|
||||
|
||||
set id(value){
|
||||
this[FEATURE_ID] = value
|
||||
}
|
||||
|
||||
get mapSymbol(){
|
||||
return MapSymbol.fromFeature(this)
|
||||
}
|
||||
|
||||
asPoint(){
|
||||
if(!this[POINT_FEATURE]){
|
||||
if(!this.geometry){
|
||||
debugger;
|
||||
}
|
||||
if(this.geometry.type != "Point"){
|
||||
let point_feature = turf.centerOfMass(this)
|
||||
point_feature.properties = this.properties
|
||||
point_feature = new MapSubFeature(point_feature, this)
|
||||
this[POINT_FEATURE] = point_feature
|
||||
} else {
|
||||
this[POINT_FEATURE] = this
|
||||
}
|
||||
}
|
||||
return this[POINT_FEATURE]
|
||||
}
|
||||
}
|
||||
|
||||
const PARENT_FEATURE = Symbol("Parent feature")
|
||||
export class MapSubFeature extends MapFeature {
|
||||
constructor(geojson, parent){
|
||||
super(geojson)
|
||||
this[PARENT_FEATURE] = parent
|
||||
}
|
||||
|
||||
get parentFeature(){
|
||||
return this[PARENT_FEATURE]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue