forked from streetcomplete/StreetComplete
-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathOverlaysModule.kt
70 lines (66 loc) · 3.14 KB
/
OverlaysModule.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package de.westnordost.streetcomplete.overlays
import com.russhwolf.settings.ObservableSettings
import de.westnordost.countryboundaries.CountryBoundaries
import de.westnordost.streetcomplete.ApplicationConstants.EE_QUEST_OFFSET
import de.westnordost.osmfeatures.Feature
import de.westnordost.osmfeatures.FeatureDictionary
import de.westnordost.streetcomplete.data.meta.CountryInfo
import de.westnordost.streetcomplete.data.meta.CountryInfos
import de.westnordost.streetcomplete.data.meta.getByLocation
import de.westnordost.streetcomplete.data.osm.mapdata.Element
import de.westnordost.streetcomplete.data.osm.mapdata.LatLon
import de.westnordost.streetcomplete.data.overlays.OverlayRegistry
import de.westnordost.streetcomplete.overlays.custom.CustomOverlay
import de.westnordost.streetcomplete.overlays.address.AddressOverlay
import de.westnordost.streetcomplete.overlays.buildings.BuildingsOverlay
import de.westnordost.streetcomplete.overlays.cycleway.CyclewayOverlay
import de.westnordost.streetcomplete.overlays.places.PlacesOverlay
import de.westnordost.streetcomplete.overlays.restriction.RestrictionOverlay
import de.westnordost.streetcomplete.overlays.sidewalk.SidewalkOverlay
import de.westnordost.streetcomplete.overlays.street_parking.StreetParkingOverlay
import de.westnordost.streetcomplete.overlays.surface.SurfaceOverlay
import de.westnordost.streetcomplete.overlays.things.ThingsOverlay
import de.westnordost.streetcomplete.overlays.way_lit.WayLitOverlay
import de.westnordost.streetcomplete.util.ktx.getFeature
import de.westnordost.streetcomplete.util.ktx.getIds
import org.koin.core.qualifier.named
import org.koin.dsl.module
/* Each overlay is assigned an ordinal. This is used for serialization and is thus never changed,
* even if the order of overlays is changed. */
val overlaysModule = module {
single {
overlaysRegistry(
{ location ->
val countryInfos = get<CountryInfos>()
val countryBoundaries = get<Lazy<CountryBoundaries>>(named("CountryBoundariesLazy")).value
countryInfos.getByLocation(countryBoundaries, location.longitude, location.latitude)
},
{ location ->
val countryBoundaries = get<Lazy<CountryBoundaries>>(named("CountryBoundariesLazy")).value
countryBoundaries.getIds(location).firstOrNull()
},
{ element ->
get<Lazy<FeatureDictionary>>(named("FeatureDictionaryLazy")).value.getFeature(element)
},
get(),
)
}
}
fun overlaysRegistry(
getCountryInfoByLocation: (LatLon) -> CountryInfo,
getCountryCodeByLocation: (LatLon) -> String?,
getFeature: (Element) -> Feature?,
prefs: ObservableSettings,
) = OverlayRegistry(listOf(
0 to WayLitOverlay(),
6 to SurfaceOverlay(),
1 to SidewalkOverlay(),
5 to CyclewayOverlay(getCountryInfoByLocation),
2 to StreetParkingOverlay(),
3 to AddressOverlay(getCountryCodeByLocation),
4 to PlacesOverlay(getFeature),
8 to ThingsOverlay(getFeature),
7 to BuildingsOverlay(),
(EE_QUEST_OFFSET + 1) to RestrictionOverlay(),
(EE_QUEST_OFFSET + 0) to CustomOverlay(prefs),
))