More style tweaks, add geoip server

This commit is contained in:
Pieter Vander Vennet 2024-06-17 19:27:21 +02:00
parent 06b6f6d471
commit 66a48daba8
7 changed files with 67 additions and 4754 deletions

View file

@ -34,5 +34,7 @@ lod.mapcomplete.org {
} }
ipinfo.mapcomplete.org { ipinfo.mapcomplete.org {
reverse_proxy 127.0.0.1:2347 reverse_proxy {
to 127.0.0.1:2347
}
} }

View file

@ -24,6 +24,7 @@
"mvt_layer_server": "https://cache.mapcomplete.org/public.{type}_{layer}/{z}/{x}/{y}.pbf", "mvt_layer_server": "https://cache.mapcomplete.org/public.{type}_{layer}/{z}/{x}/{y}.pbf",
"#summary_server": "Should be the endpoint; appending status.json should work", "#summary_server": "Should be the endpoint; appending status.json should work",
"summary_server": "https://cache.mapcomplete.org/", "summary_server": "https://cache.mapcomplete.org/",
"geoip_server":"https://ipinfo.mapcomplete.org/",
"disabled:oauth_credentials": { "disabled:oauth_credentials": {
"##": "DEV", "##": "DEV",
"#": "This client-id is registered by 'MapComplete' on https://master.apis.dev.openstreetmap.org/", "#": "This client-id is registered by 'MapComplete' on https://master.apis.dev.openstreetmap.org/",

File diff suppressed because it is too large Load diff

View file

@ -6,6 +6,8 @@ import Hash from "../Web/Hash"
import OsmObjectDownloader from "../Osm/OsmObjectDownloader" import OsmObjectDownloader from "../Osm/OsmObjectDownloader"
import { OsmObject } from "../Osm/OsmObject" import { OsmObject } from "../Osm/OsmObject"
import Constants from "../../Models/Constants" import Constants from "../../Models/Constants"
import { Utils } from "../../Utils"
import { GeoLocationState } from "../State/GeoLocationState"
/** /**
* This actor is responsible to set the map location. * This actor is responsible to set the map location.
@ -13,6 +15,7 @@ import Constants from "../../Models/Constants"
* - Set the map to the position of the selected element * - Set the map to the position of the selected element
* - Set the map to the position as passed in by the query parameters (if available) * - Set the map to the position as passed in by the query parameters (if available)
* - Set the map to the position remembered in LocalStorage (if available) * - Set the map to the position remembered in LocalStorage (if available)
* - Set the map to what IP-info says (very coarse)
* - Set the map to the layout default * - Set the map to the layout default
* *
* Additionally, it will save the map location to local storage * Additionally, it will save the map location to local storage
@ -22,7 +25,7 @@ export default class InitialMapPositioning {
public location: UIEventSource<{ lon: number; lat: number }> public location: UIEventSource<{ lon: number; lat: number }>
public useTerrain: Store<boolean> public useTerrain: Store<boolean>
constructor(layoutToUse: LayoutConfig) { constructor(layoutToUse: LayoutConfig, geolocationState: GeoLocationState) {
function localStorageSynced( function localStorageSynced(
key: string, key: string,
deflt: number, deflt: number,
@ -52,14 +55,16 @@ export default class InitialMapPositioning {
layoutToUse?.startZoom ?? 1, layoutToUse?.startZoom ?? 1,
"The initial/current zoom level" "The initial/current zoom level"
) )
const defaultLat =layoutToUse?.startLat ?? 0
const lat = localStorageSynced( const lat = localStorageSynced(
"lat", "lat",
layoutToUse?.startLat ?? 0, defaultLat ,
"The initial/current latitude" "The initial/current latitude"
) )
const defaultLon = layoutToUse?.startLon ?? 0
const lon = localStorageSynced( const lon = localStorageSynced(
"lon", "lon",
layoutToUse?.startLon ?? 0, defaultLon ,
"The initial/current longitude of the app" "The initial/current longitude of the app"
) )
@ -72,6 +77,7 @@ export default class InitialMapPositioning {
this.useTerrain = new ImmutableStore<boolean>(layoutToUse.enableTerrain) this.useTerrain = new ImmutableStore<boolean>(layoutToUse.enableTerrain)
if (initialHash?.match(/^(node|way|relation)\/[0-9]+$/)) { if (initialHash?.match(/^(node|way|relation)\/[0-9]+$/)) {
// We pan to the selected element
const [type, id] = initialHash.split("/") const [type, id] = initialHash.split("/")
OsmObjectDownloader.RawDownloadObjectAsync( OsmObjectDownloader.RawDownloadObjectAsync(
type, type,
@ -86,6 +92,19 @@ export default class InitialMapPositioning {
const [lat, lon] = osmObject.centerpoint() const [lat, lon] = osmObject.centerpoint()
this.location.setData({ lon, lat }) this.location.setData({ lon, lat })
}) })
} else if (Constants.GeoIpServer && lat.data === defaultLat && lon.data === defaultLon) {
console.log("Using geoip to determine start location...")
// We use geo-IP to zoom to some location
Utils.downloadJson<{ latitude: number, longitude: number }>(
Constants.GeoIpServer + "ip"
).then(({ longitude, latitude }) => {
if(geolocationState.currentGPSLocation.data !== undefined){
return // We got a geolocation by now, abort
}
console.log("Setting location based on geoip", longitude, latitude)
this.zoom.setData(8)
this.location.setData({ lon: longitude, lat: latitude })
})
} }
} }
} }

View file

@ -163,6 +163,8 @@ export default class Constants {
* This is a MapLibre/MapBox vector tile server which hosts vector tiles for every (official) layer * This is a MapLibre/MapBox vector tile server which hosts vector tiles for every (official) layer
*/ */
public static VectorTileServer: string | undefined = Constants.config.mvt_layer_server public static VectorTileServer: string | undefined = Constants.config.mvt_layer_server
public static GeoIpServer: string | undefined = Constants.config.geoip_server
public static readonly maptilerApiKey = "GvoVAJgu46I5rZapJuAy" public static readonly maptilerApiKey = "GvoVAJgu46I5rZapJuAy"
public static readonly SummaryServer: string = Constants.config.summary_server public static readonly SummaryServer: string = Constants.config.summary_server

View file

@ -158,10 +158,10 @@ export default class ThemeViewState implements SpecialVisualizationState {
layout.id layout.id
) )
this.map = new UIEventSource<MlMap>(undefined) this.map = new UIEventSource<MlMap>(undefined)
const initial = new InitialMapPositioning(layout) const geolocationState = new GeoLocationState()
const initial = new InitialMapPositioning(layout, geolocationState)
this.mapProperties = new MapLibreAdaptor(this.map, initial) this.mapProperties = new MapLibreAdaptor(this.map, initial)
const geolocationState = new GeoLocationState()
this.featureSwitchIsTesting = this.featureSwitches.featureSwitchIsTesting this.featureSwitchIsTesting = this.featureSwitches.featureSwitchIsTesting
this.featureSwitchUserbadge = this.featureSwitches.featureSwitchEnableLogin this.featureSwitchUserbadge = this.featureSwitches.featureSwitchEnableLogin

View file

@ -85,10 +85,11 @@
</script> </script>
{#if theme.id !== personal.id || $unlockedPersonal} {#if theme.id !== personal.id || $unlockedPersonal}
<a class={"button theme-button w-full text-ellipsis"} style="justify-content: start" href={$href}> <a class={"flex w-full items-center text-ellipsis rounded my-2"} href={$href}>
<img src={theme.icon} class="m-1 mr-2 block h-11 w-11 sm:m-2 sm:mr-4" alt="" /> <img src={theme.icon} class="m-1 block h-11 w-11 sm:mr-2" alt="" />
<span class="flex flex-col overflow-hidden text-ellipsis "> <span class="flex flex-col overflow-hidden text-ellipsis font-bold text-xl">
<Tr t={title} /> <Tr cls="underline" t={title} />
<Tr cls="subtle text-base" t={description}/>
{#if selected} {#if selected}
<span class="thanks hidden-on-mobile" aria-hidden="true"> <span class="thanks hidden-on-mobile" aria-hidden="true">