Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions packages/api/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ async function searchLocation(
queryString: string,
lang: string,
cancelToken: CancelToken,
limit?: number
limit?: number,
translations?: {
kantone: string
district: string
}
): Promise<LocationSearchResult[]> {
try {
const locationResponse = await generateAxiosSearchRequest(
Expand All @@ -207,7 +211,9 @@ async function searchLocation(
(result: SearchResponseResult) => !!result.attrs
)
return (
resultWithAttrs.map((location) => parseLocationResult(location, outputProjection)) ?? []
resultWithAttrs.map((location) =>
parseLocationResult(location, outputProjection, translations)
) ?? []
)
} catch (error) {
log.error({
Expand Down Expand Up @@ -400,6 +406,11 @@ interface SearchConfig {
/** The maximum number of results to return */
limit?: number
iconSets?: DrawingIconSet[]
/** Translations for location origin prefixes (e.g., "Ct." for kantone, "District" for district) */
translations?: {
kantone: string
district: string
}
}

let cancelTokenSource: CancelTokenSource | undefined
Expand All @@ -412,6 +423,7 @@ async function search(config: SearchConfig): Promise<SearchResult[]> {
layersToSearch = [],
limit,
iconSets = [],
translations,
} = config

if (!outputProjection) {
Expand Down Expand Up @@ -443,7 +455,8 @@ async function search(config: SearchConfig): Promise<SearchResult[]> {
queryString,
lang,
cancelTokenSource?.token,
limit
limit,
translations
)),
]

Expand Down
7 changes: 7 additions & 0 deletions packages/api/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ const config: UserConfig = {
name: '@swissgeo/api',
},
rollupOptions: {
// Externalize peer dependencies so they use the host application's instances
external: ['axios', 'ol', 'proj4'],
output: {
exports: 'named',
globals: {
axios: 'axios',
ol: 'ol',
proj4: 'proj4',
},
},
},
},
Expand Down
5 changes: 5 additions & 0 deletions packages/coordinates/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ const config: UserConfig = {
},
sourcemap: true,
rollupOptions: {
// Externalize peer dependencies so they use the host application's instances
external: ['proj4', 'ol', 'ol/proj/proj4'],
output: {
exports: 'named',
name: '@swissgeo/coordinates',
globals: {
vue: 'Vue',
proj4: 'proj4',
ol: 'ol',
'ol/proj/proj4': 'ol/proj/proj4',
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { GeoAdminLayer, LayerTimeConfigEntry } from '@swissgeo/layers'

import { layerUtils, timeConfigUtils } from '@swissgeo/layers/utils'
import { markRaw } from 'vue'

import type { LayersStore } from '@/store/modules/layers/types'
import type { ActionDispatcher } from '@/store/types'
Expand All @@ -19,7 +20,10 @@ export default function setLayerConfig(
): void {
const activeLayerBeforeConfigChange = [...this.activeLayers]
if (Array.isArray(config)) {
this.config = [...config]
// Use markRaw to prevent deep reactivity on large config array (performance optimization for DevTools)
// this config will not be mutated partially, only fully replaced when needed
// so this is safe to do (replacing the whole array will still be reactive)
this.config = config.map((layer) => markRaw(layer))
}
this.activeLayers = activeLayerBeforeConfigChange.map((layer) => {
const layerConfig: GeoAdminLayer | undefined = this.getLayerConfigById(layer.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ export default function selectResultEntry(
if (locationEntry.coordinate) {
mapStore.setPinnedLocation(locationEntry.coordinate, dispatcher)
}
this.setSearchQuery(locationEntry.sanitizedTitle.trim(), dispatcher)
this.query = locationEntry.sanitizedTitle.trim()
} else if (entry.resultType === 'FEATURE') {
const featureEntry = entry as LayerFeatureSearchResult
zoomToSearchResult(featureEntry, dispatcher)
if (featureEntry.coordinate) {
mapStore.setPinnedLocation(featureEntry.coordinate, dispatcher)
}

// Automatically select the feature
if (layerUtils.getTopicForIdentifyAndTooltipRequests(featureEntry.layer)) {
Expand All @@ -104,9 +107,11 @@ export default function selectResultEntry(
}
)
.then((feature: LayerFeature) => {
featuresStore.setSelectedFeatures([feature], dispatcher)
if (feature) {
featuresStore.setSelectedFeatures([feature], dispatcher)

uiStore.setFeatureInfoPosition(FeatureInfoPositions.ToolTip, dispatcher)
uiStore.setFeatureInfoPosition(FeatureInfoPositions.ToolTip, dispatcher)
}
})
.catch((error) => {
log.error({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import log, { LogPreDefinedColor } from '@swissgeo/log'
import type { SearchStore } from '@/store/modules/search/types'
import type { ActionDispatcher } from '@/store/types'

import i18n from '@/modules/i18n'
import useI18nStore from '@/store/modules/i18n'
import useLayersStore from '@/store/modules/layers'
import useMapStore from '@/store/modules/map'
Expand All @@ -22,7 +23,6 @@ interface SetSearchQueryOptions {
*/
originUrlParam?: boolean
}

export default function setSearchQuery(
this: SearchStore,
query: string,
Expand Down Expand Up @@ -173,6 +173,10 @@ function performSearch(
layersToSearch: layerStore.visibleLayers,
resolution: positionStore.resolution,
limit: searchStore.autoSelect ? 1 : undefined,
translations: {
kantone: i18n.global.t('ct'),
district: i18n.global.t('district'),
},
})
.then((results) => {
searchStore.results = results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ const swisssearchParamConfig = new UrlParamConfig<string>({
urlParamName: URL_PARAM_NAME_SWISSSEARCH,
// no mutation to watch, we only react to this param if it is there at app start-up
actionsToWatch: [],
extractValueFromStore: () => useSearchStore().query,
// Always return default value so this param never gets re-added to URL by storeToUrl plugin
extractValueFromStore: () => '',
setValuesInStore: (_: RouteLocationNormalizedGeneric, urlParamValue?: string) => {
if (urlParamValue) {
useSearchStore().setSearchQuery(urlParamValue, STORE_DISPATCHER_ROUTER_PLUGIN)
useSearchStore().setSearchQuery(
urlParamValue,
{ originUrlParam: true },
STORE_DISPATCHER_ROUTER_PLUGIN
)
}
},
afterSetValuesInStore: () => removeQueryParamFromHref(URL_PARAM_NAME_SWISSSEARCH),
afterSetValuesInStore: () => {
// Defer removal to next event loop tick to ensure all URL params are processed
// and router state is stable before manually modifying the URL
setTimeout(() => removeQueryParamFromHref(URL_PARAM_NAME_SWISSSEARCH), 0)
},
keepInUrlWhenDefault: false,
valueType: String,
defaultValue: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ const swisssearchAutoSelectParam = new UrlParamConfig<boolean>({
searchStore.setAutoSelect(false, STORE_DISPATCHER_ROUTER_PLUGIN)
}
},
afterSetValuesInStore: () => removeQueryParamFromHref(URL_PARAM_NAME),
extractValueFromStore: () => useSearchStore().autoSelect,
afterSetValuesInStore: () => {
// Defer removal to next event loop tick to ensure all URL params are processed
// and router state is stable before manually modifying the URL
setTimeout(() => removeQueryParamFromHref(URL_PARAM_NAME), 0)
},
// Always return default value so this param never gets re-added to URL by storeToUrl plugin
extractValueFromStore: () => false,
keepInUrlWhenDefault: false,
valueType: Boolean,
defaultValue: false,
Expand Down
Loading
Loading