forked from MapComplete/MapComplete
Feature(pwa): add protocol handler
This commit is contained in:
parent
50c2abebdf
commit
de74a5dc08
4 changed files with 43 additions and 17 deletions
|
@ -168,6 +168,7 @@ class GenerateLayouts extends Script {
|
|||
manifest: any
|
||||
whiteIcons: string[]
|
||||
}> {
|
||||
const id = layout.id
|
||||
Translation.forcedLanguage = "en"
|
||||
const icons = []
|
||||
|
||||
|
@ -228,7 +229,7 @@ class GenerateLayouts extends Script {
|
|||
const manifest = {
|
||||
name: ogTitle,
|
||||
short_name: ogTitle,
|
||||
start_url: `${layout.id.toLowerCase()}.html`,
|
||||
start_url: `${id.toLowerCase()}.html`,
|
||||
lang: "en",
|
||||
display: "standalone",
|
||||
background_color: "#fff",
|
||||
|
@ -236,6 +237,12 @@ class GenerateLayouts extends Script {
|
|||
orientation: "portrait-primary, landscape-primary",
|
||||
icons: icons,
|
||||
categories: ["map", "navigation"],
|
||||
"protocol_handlers": [
|
||||
{
|
||||
"protocol": "geo",
|
||||
"url": `/${id.toLowerCase()}.html?geouri=%s`
|
||||
}
|
||||
]
|
||||
}
|
||||
return {
|
||||
manifest,
|
||||
|
|
|
@ -66,6 +66,21 @@ export default class InitialMapPositioning {
|
|||
defaultLon,
|
||||
"The initial/current longitude of the app"
|
||||
)
|
||||
const geouri = QueryParameters.GetQueryParameter("geouri", undefined, "Alternative format to set lat/lon; but with an entire geouri instead. ")
|
||||
console.log("geouri", geouri.data, !!geouri.data)
|
||||
if (geouri.data) {
|
||||
try {
|
||||
const url = new URL("geo:"+decodeURIComponent(geouri.data))
|
||||
const [latN, lonN] = url.pathname.split(",").map(n => parseFloat(n))
|
||||
lat.set(latN)
|
||||
lon.set(lonN)
|
||||
if(url.searchParams.has("q")){
|
||||
QueryParameters.GetQueryParameter("q", undefined).set(url.searchParams.get("q"))
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("Could not parse geoURI:", e)
|
||||
}
|
||||
}
|
||||
|
||||
this.location = new UIEventSource({ lon: lon.data, lat: lat.data })
|
||||
// Note: this syncs only in one direction
|
||||
|
|
|
@ -17,10 +17,11 @@ import { FeatureSource } from "../FeatureSource/FeatureSource"
|
|||
import { Feature } from "geojson"
|
||||
import OpenLocationCodeSearch from "../Search/OpenLocationCodeSearch"
|
||||
import { BBox } from "../BBox"
|
||||
import { QueryParameters } from "../Web/QueryParameters"
|
||||
|
||||
export default class SearchState {
|
||||
public readonly feedback: UIEventSource<Translation> = new UIEventSource<Translation>(undefined)
|
||||
public readonly searchTerm: UIEventSource<string> = new UIEventSource<string>("")
|
||||
public readonly searchTerm: UIEventSource<string>
|
||||
public readonly searchIsFocused = new UIEventSource(false)
|
||||
public readonly suggestions: Store<GeocodeResult[]>
|
||||
public readonly filterSuggestions: Store<FilterSearchResult[]>
|
||||
|
@ -36,6 +37,8 @@ export default class SearchState {
|
|||
constructor(state: ThemeViewState) {
|
||||
this.state = state
|
||||
|
||||
this.searchTerm = QueryParameters.GetQueryParameter("q", "", "The term in the search field")
|
||||
|
||||
this.locationSearchers = [
|
||||
new LocalElementSearch(state, 5),
|
||||
new CoordinateSearch(),
|
||||
|
|
|
@ -16,24 +16,25 @@ export class WithSearchState extends WithVisualFeedbackState {
|
|||
super(theme, mvtAvailableLayers)
|
||||
this.searchState = new SearchState(this)
|
||||
this.initHotkeysSearch()
|
||||
this.displaySearchLayer()
|
||||
|
||||
{
|
||||
// Register the search layer on the map
|
||||
}
|
||||
|
||||
const source = this.searchState.locationResults
|
||||
const flayer = this.layerState.filteredLayers.get("search")
|
||||
this.featureProperties.trackFeatureSource(source)
|
||||
const options: ShowDataLayerOptions & { layer: LayerConfig } = {
|
||||
features: source,
|
||||
doShowLayer: flayer.isDisplayed,
|
||||
layer: flayer.layerDef,
|
||||
metaTags: this.userRelatedState.preferencesAsTags,
|
||||
onClick: (feature) => {
|
||||
this.searchState.clickedOnMap(feature)
|
||||
},
|
||||
}
|
||||
new ShowDataLayer(this.map, options)
|
||||
private displaySearchLayer() {
|
||||
|
||||
const source = this.searchState.locationResults
|
||||
const flayer = this.layerState.filteredLayers.get("search")
|
||||
this.featureProperties.trackFeatureSource(source)
|
||||
const options: ShowDataLayerOptions & { layer: LayerConfig } = {
|
||||
features: source,
|
||||
doShowLayer: flayer.isDisplayed,
|
||||
layer: flayer.layerDef,
|
||||
metaTags: this.userRelatedState.preferencesAsTags,
|
||||
onClick: (feature) => {
|
||||
this.searchState.clickedOnMap(feature)
|
||||
},
|
||||
}
|
||||
new ShowDataLayer(this.map, options)
|
||||
}
|
||||
|
||||
private initHotkeysSearch() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue