Merge branch 'main' into serverside-geocoding

This commit is contained in:
Anton Tranelis 2025-11-17 17:26:28 +01:00 committed by GitHub
commit a20123cb5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 147 additions and 198 deletions

View File

@ -56,6 +56,7 @@ import MapContainer from './pages/MapContainer'
import { getBottomRoutes, routes } from './routes/sidebar' import { getBottomRoutes, routes } from './routes/sidebar'
import { config } from './config' import { config } from './config'
import { InviteApi } from './api/inviteApi' import { InviteApi } from './api/inviteApi'
import { MapPinIcon } from '@heroicons/react/24/solid'
const userApi = new UserApi() const userApi = new UserApi()
const inviteApi = new InviteApi(userApi) const inviteApi = new InviteApi(userApi)
@ -139,14 +140,19 @@ function App() {
?.filter((l: LayerProps) => l.listed) ?.filter((l: LayerProps) => l.listed)
.map((l: LayerProps) => ({ .map((l: LayerProps) => ({
path: '/' + l.name, // url path: '/' + l.name, // url
icon: ( icon: l.markerIcon?.image ? (
<SVG <SVG
src={`${config.apiUrl}assets/${l.markerIcon.image_outline ?? l.markerIcon.image}`} src={`${config.apiUrl}assets/${l.markerIcon.image_outline ?? l.markerIcon.image}`}
className='tw:w-6 tw:h-6' style={{
width: `${(l.markerIcon.size ?? 18) * 1.3}px`,
height: `${(l.markerIcon.size ?? 18) * 1.3}px`,
}}
preProcessor={(code: string) => preProcessor={(code: string) =>
code.replace(/stroke=".*?"/g, 'stroke="currentColor"') code.replace(/stroke=".*?"/g, 'stroke="currentColor"')
} }
/> />
) : (
<MapPinIcon className='tw:w-6 tw:h-6' />
), ),
name: l.name, // name that appear in Sidebar name: l.name, // name that appear in Sidebar
color: l.menuColor, color: l.menuColor,

View File

@ -16,7 +16,7 @@
"template": "{{id}}" "template": "{{id}}"
}, },
"readonly": false, "readonly": false,
"required": true, "required": false,
"sort": 2, "sort": 2,
"special": [ "special": [
"m2o" "m2o"

View File

@ -37,7 +37,7 @@
"name": "markerShape", "name": "markerShape",
"table": "layers", "table": "layers",
"data_type": "character varying", "data_type": "character varying",
"default_value": null, "default_value": "circle",
"max_length": 255, "max_length": 255,
"numeric_precision": null, "numeric_precision": null,
"numeric_scale": null, "numeric_scale": null,

View File

@ -1,47 +0,0 @@
{
"collection": "marker_icons",
"field": "image_outline",
"type": "uuid",
"meta": {
"collection": "marker_icons",
"conditions": null,
"display": null,
"display_options": null,
"field": "image_outline",
"group": null,
"hidden": false,
"interface": "file-image",
"note": null,
"options": {
"folder": "f255d3a7-8ecc-4ee0-b584-dee753317415"
},
"readonly": false,
"required": false,
"sort": 4,
"special": [
"file"
],
"translations": null,
"validation": null,
"validation_message": null,
"width": "half"
},
"schema": {
"name": "image_outline",
"table": "marker_icons",
"data_type": "uuid",
"default_value": null,
"max_length": null,
"numeric_precision": null,
"numeric_scale": null,
"is_nullable": true,
"is_unique": false,
"is_indexed": false,
"is_primary_key": false,
"is_generated": false,
"generation_expression": null,
"has_auto_increment": false,
"foreign_key_table": "directus_files",
"foreign_key_column": "id"
}
}

View File

@ -1,43 +0,0 @@
{
"collection": "marker_icons",
"field": "size_outline",
"type": "decimal",
"meta": {
"collection": "marker_icons",
"conditions": null,
"display": null,
"display_options": null,
"field": "size_outline",
"group": null,
"hidden": false,
"interface": "input",
"note": null,
"options": null,
"readonly": false,
"required": false,
"sort": 5,
"special": null,
"translations": null,
"validation": null,
"validation_message": null,
"width": "half"
},
"schema": {
"name": "size_outline",
"table": "marker_icons",
"data_type": "numeric",
"default_value": null,
"max_length": null,
"numeric_precision": 10,
"numeric_scale": 5,
"is_nullable": true,
"is_unique": false,
"is_indexed": false,
"is_primary_key": false,
"is_generated": false,
"generation_expression": null,
"has_auto_increment": false,
"foreign_key_table": null,
"foreign_key_column": null
}
}

View File

@ -1,25 +0,0 @@
{
"collection": "marker_icons",
"field": "image_outline",
"related_collection": "directus_files",
"meta": {
"junction_field": null,
"many_collection": "marker_icons",
"many_field": "image_outline",
"one_allowed_collections": null,
"one_collection": "directus_files",
"one_collection_field": null,
"one_deselect_action": "nullify",
"one_field": null,
"sort_field": null
},
"schema": {
"table": "marker_icons",
"column": "image_outline",
"foreign_key_table": "directus_files",
"foreign_key_column": "id",
"constraint_name": "marker_icons_image_outline_foreign",
"on_update": "NO ACTION",
"on_delete": "SET NULL"
}
}

View File

@ -64,7 +64,7 @@ export function SideBar({ routes, bottomRoutes }: { routes: Route[]; bottomRoute
}} }}
> >
<div <div
className='tw:p-1.5 tw:rounded-selector tw:text-white' className='tw:p-1.5 tw:rounded-selector tw:text-white tw:h-9 tw:w-9 tw:flex tw:items-center tw:justify-center'
style={{ backgroundColor: route.color ?? '#777' }} style={{ backgroundColor: route.color ?? '#777' }}
> >
{route.icon} {route.icon}

View File

@ -41,6 +41,9 @@ export const Layer = ({
const setItemsApi = useSetItemsApi() const setItemsApi = useSetItemsApi()
const setItemsData = useSetItemsData() const setItemsData = useSetItemsData()
// Ensure markerShape has a valid value, default to 'circle' if null or empty
const normalizedMarkerShape = markerShape || 'circle'
const addTag = useAddTag() const addTag = useAddTag()
const [newTagsToAdd] = useState<Tag[]>([]) const [newTagsToAdd] = useState<Tag[]>([])
const [tagsReady] = useState<boolean>(false) const [tagsReady] = useState<boolean>(false)
@ -55,7 +58,7 @@ export const Layer = ({
menuText, menuText,
menuColor, menuColor,
markerIcon, markerIcon,
markerShape, markerShape: normalizedMarkerShape,
markerDefaultColor, markerDefaultColor,
markerDefaultColor2, markerDefaultColor2,
api, api,
@ -79,7 +82,7 @@ export const Layer = ({
menuText, menuText,
menuColor, menuColor,
markerIcon, markerIcon,
markerShape, markerShape: normalizedMarkerShape,
markerDefaultColor, markerDefaultColor,
markerDefaultColor2, markerDefaultColor2,
api, api,
@ -116,7 +119,7 @@ export const Layer = ({
name, name,
markerDefaultColor, markerDefaultColor,
markerDefaultColor2, markerDefaultColor2,
markerShape, markerShape: normalizedMarkerShape,
markerIcon, markerIcon,
menuText, menuText,
}} }}

View File

@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-non-null-assertion */ /* eslint-disable @typescript-eslint/no-non-null-assertion */
import { MapPinIcon } from '@heroicons/react/24/solid'
import { useState } from 'react' import { useState } from 'react'
import SVG from 'react-inlinesvg' import SVG from 'react-inlinesvg'
@ -94,13 +95,18 @@ export default function AddButton({
e.preventDefault() e.preventDefault()
}} }}
> >
{layer.markerIcon?.image ? (
<img <img
src={appState.assetsApi.url + layer.markerIcon.image} src={appState.assetsApi.url + layer.markerIcon.image}
style={{ style={{
filter: 'invert(100%) brightness(200%)', filter: 'invert(100%) brightness(200%)',
width: `${(layer.markerIcon.size ?? 18) * 1.3}px`, width: `${(layer.markerIcon.size ?? 18) * 1.3}px`,
height: `${(layer.markerIcon.size ?? 18) * 1.3}px`,
}} }}
/> />
) : (
<MapPinIcon className='tw:w-6 tw:h-6' style={{ color: '#ffffff' }} />
)}
</button> </button>
</div> </div>
</a> </a>

View File

@ -11,7 +11,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-call */
import FlagIcon from '@heroicons/react/24/outline/FlagIcon' import FlagIcon from '@heroicons/react/24/outline/FlagIcon'
import MagnifyingGlassIcon from '@heroicons/react/24/outline/MagnifyingGlassIcon' import MapPinIcon from '@heroicons/react/24/outline/MapPinIcon'
import axios from 'axios' import axios from 'axios'
import { LatLng, LatLngBounds, marker } from 'leaflet' import { LatLng, LatLngBounds, marker } from 'leaflet'
import { useRef, useState } from 'react' import { useRef, useState } from 'react'
@ -167,14 +167,32 @@ export const SearchControl = () => {
{itemsResults.length > 0 && tagsResults.length > 0 && ( {itemsResults.length > 0 && tagsResults.length > 0 && (
<hr className='tw:opacity-50'></hr> <hr className='tw:opacity-50'></hr>
)} )}
{itemsResults.slice(0, 5).map((item) => ( {itemsResults.slice(0, 5).map((item) => {
// Calculate color using the same logic as PopupView
const itemTags =
item.text
?.match(/#[^\s#]+/g)
?.map((tag) =>
tags.find((t) => t.name.toLowerCase() === tag.slice(1).toLowerCase()),
)
.filter(Boolean) ?? []
let color1 = item.layer?.markerDefaultColor ?? '#777'
if (item.color) {
color1 = item.color
} else if (itemTags[0]) {
color1 = itemTags[0].color
}
return (
<div <div
key={item.id} key={item.id}
className='tw:cursor-pointer tw:hover:font-bold tw:flex tw:flex-row' className='tw:cursor-pointer tw:hover:font-bold tw:flex tw:flex-row tw:items-center tw:gap-2'
data-cy='search-item-result' data-cy='search-item-result'
onClick={() => { onClick={() => {
const marker = Object.entries(leafletRefs).find((r) => r[1].item === item)?.[1] const marker = Object.entries(leafletRefs).find(
.marker (r) => r[1].item === item,
)?.[1].marker
if (marker) { if (marker) {
navigate(`/${item.id}?${new URLSearchParams(window.location.search)}`) navigate(`/${item.id}?${new URLSearchParams(window.location.search)}`)
} else { } else {
@ -184,15 +202,19 @@ export const SearchControl = () => {
} }
}} }}
> >
{item.layer?.markerIcon.image ? ( {item.layer?.markerIcon?.image ? (
<div <div
className='tw:w-7 tw:h-full tw:flex tw:justify-center tw:items-center' className='tw:p-1.5 tw:rounded-selector tw:text-white tw:h-7 tw:w-7 tw:flex tw:items-center tw:justify-center tw:flex-shrink-0 tw:overflow-hidden'
style={{ backgroundColor: color1 }}
data-cy='search-item-icon' data-cy='search-item-icon'
> >
<SVG <SVG
src={appState.assetsApi.url + item.layer.markerIcon.image} src={appState.assetsApi.url + item.layer.markerIcon.image}
className='tw:text-current tw:mr-2 tw:mt-0' className='tw:text-current tw:max-w-full tw:max-h-full'
style={{ width: `${(item.layer.markerIcon.size ?? 18) * 1.2}px` }} style={{
width: `${item.layer.markerIcon.size ?? 18}px`,
height: `${item.layer.markerIcon.size ?? 18}px`,
}}
preProcessor={(code: string): string => { preProcessor={(code: string): string => {
code = code.replace(/fill=".*?"/g, 'fill="currentColor"') code = code.replace(/fill=".*?"/g, 'fill="currentColor"')
code = code.replace(/stroke=".*?"/g, 'stroke="currentColor"') code = code.replace(/stroke=".*?"/g, 'stroke="currentColor"')
@ -201,22 +223,29 @@ export const SearchControl = () => {
/> />
</div> </div>
) : ( ) : (
<div className='tw:w-7' data-cy='search-item-icon-placeholder' /> <div
className='tw:w-7 tw:h-7 tw:flex-shrink-0'
data-cy='search-item-icon-placeholder'
/>
)} )}
<div> <div className='tw:flex tw:flex-col tw:min-w-0'>
<div className='tw:text-sm tw:overflow-hidden tw:text-ellipsis tw:whitespace-nowrap tw:max-w-[17rem]'> <div className='tw:text-sm tw:font-bold tw:overflow-hidden tw:text-ellipsis tw:whitespace-nowrap'>
{item.name} {item.name}
</div> </div>
<div className='tw:text-xs tw:overflow-hidden tw:text-ellipsis tw:whitespace-nowrap'>
{item.text}
</div> </div>
</div> </div>
))} </div>
)
})}
{Array.from(geoResults).length > 0 && {Array.from(geoResults).length > 0 &&
(itemsResults.length > 0 || tagsResults.length > 0) && ( (itemsResults.length > 0 || tagsResults.length > 0) && (
<hr className='tw:opacity-50'></hr> <hr className='tw:opacity-50'></hr>
)} )}
{Array.from(geoResults).map((geo) => ( {Array.from(geoResults).map((geo) => (
<div <div
className='tw:flex tw:flex-row tw:hover:font-bold tw:cursor-pointer' className='tw:flex tw:flex-row tw:items-center tw:hover:font-bold tw:cursor-pointer tw:gap-2'
data-cy='search-geo-result' data-cy='search-geo-result'
key={Math.random()} key={Math.random()}
onClick={() => { onClick={() => {
@ -249,19 +278,21 @@ export const SearchControl = () => {
hide() hide()
}} }}
> >
<MagnifyingGlassIcon <div className='tw:h-7 tw:w-7 tw:flex tw:items-center tw:justify-center tw:flex-shrink-0'>
className='tw:text-current tw:mr-2 tw:mt-0 tw:w-5' <MapPinIcon
className='tw:text-current tw:w-5 tw:h-5'
data-cy='search-geo-icon' data-cy='search-geo-icon'
/> />
<div> </div>
<div className='tw:flex tw:flex-col tw:min-w-0'>
<div <div
className='tw:text-sm tw:overflow-hidden tw:text-ellipsis tw:whitespace-nowrap tw:max-w-[17rem]' className='tw:text-sm tw:font-bold tw:overflow-hidden tw:text-ellipsis tw:whitespace-nowrap'
data-cy='search-geo-name' data-cy='search-geo-name'
> >
{geo?.properties.name ? geo?.properties.name : value} {geo?.properties.name ? geo?.properties.name : value}
</div> </div>
<div <div
className='tw:text-xs tw:overflow-hidden tw:text-ellipsis tw:whitespace-nowrap tw:max-w-[17rem]' className='tw:text-xs tw:overflow-hidden tw:text-ellipsis tw:whitespace-nowrap'
data-cy='search-geo-details' data-cy='search-geo-details'
> >
{geo?.properties?.city && `${capitalizeFirstLetter(geo?.properties?.city)}, `}{' '} {geo?.properties?.city && `${capitalizeFirstLetter(geo?.properties?.city)}, `}{' '}
@ -281,7 +312,7 @@ export const SearchControl = () => {
))} ))}
{isGeoCoordinate(value) && ( {isGeoCoordinate(value) && (
<div <div
className='tw:flex tw:flex-row tw:hover:font-bold tw:cursor-pointer' className='tw:flex tw:flex-row tw:items-center tw:hover:font-bold tw:cursor-pointer tw:gap-2'
data-cy='search-coordinate-result' data-cy='search-coordinate-result'
onClick={() => { onClick={() => {
marker( marker(
@ -306,19 +337,21 @@ export const SearchControl = () => {
) )
}} }}
> >
<div className='tw:h-7 tw:w-7 tw:flex tw:items-center tw:justify-center tw:flex-shrink-0'>
<FlagIcon <FlagIcon
className='tw:text-current tw:mr-2 tw:mt-0 tw:w-4' className='tw:text-current tw:w-5 tw:h-5'
data-cy='search-coordinate-icon' data-cy='search-coordinate-icon'
/> />
<div> </div>
<div className='tw:flex tw:flex-col tw:min-w-0'>
<div <div
className='tw:text-sm tw:overflow-hidden tw:text-ellipsis tw:whitespace-nowrap tw:max-w-[17rem]' className='tw:text-sm tw:font-bold tw:overflow-hidden tw:text-ellipsis tw:whitespace-nowrap'
data-cy='search-coordinate-text' data-cy='search-coordinate-text'
> >
{value} {value}
</div> </div>
<div <div
className='tw:text-xs tw:overflow-hidden tw:text-ellipsis tw:whitespace-nowrap tw:max-w-[17rem]' className='tw:text-xs tw:overflow-hidden tw:text-ellipsis tw:whitespace-nowrap'
data-cy='search-coordinate-label' data-cy='search-coordinate-label'
> >
{'Coordiante'} {'Coordiante'}

View File

@ -6,7 +6,7 @@ export const TagsControl = () => {
const removeFilterTag = useRemoveFilterTag() const removeFilterTag = useRemoveFilterTag()
return ( return (
<div className='tw:flex tw:flex-wrap tw:mt-4 tw:w-[calc(100vw-2rem)] tw:max-w-xs'> <div className='tw:flex tw:flex-wrap tw:mt-4 tw:w-[calc(100vw-2rem)] tw:max-w-xs tw:relative'>
{filterTags.map((tag) => ( {filterTags.map((tag) => (
<div <div
key={tag.id} key={tag.id}

View File

@ -33,7 +33,8 @@ export const useNavigationUrl = (coordinates?: [number, number]) => {
export const useShareLogic = (item?: Item) => { export const useShareLogic = (item?: Item) => {
const shareUrl = window.location.href const shareUrl = window.location.href
const shareTitle = item?.name ?? 'Utopia Map Item' const shareTitle = item?.name ?? 'Utopia Map Item'
const inviteLink = item?.secrets const inviteLink =
item?.secrets && item.secrets.length > 0
? `${window.location.origin}/invite/${item.secrets[0].secret}` ? `${window.location.origin}/invite/${item.secrets[0].secret}`
: shareUrl : shareUrl

View File

@ -85,7 +85,9 @@ export function HeaderView({
onConfirm={deleteCallback ?? (() => undefined)} onConfirm={deleteCallback ?? (() => undefined)}
/> />
{showQrButton && (
<QRModal item={item} isOpen={qrModalOpen} onClose={() => setQrModalOpen(false)} /> <QRModal item={item} isOpen={qrModalOpen} onClose={() => setQrModalOpen(false)} />
)}
</> </>
) )
} }

View File

@ -5,6 +5,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-call */
import Markdown from 'react-markdown' import Markdown from 'react-markdown'
import { Link as RouterLink } from 'react-router-dom'
import remarkBreaks from 'remark-breaks' import remarkBreaks from 'remark-breaks'
import { useAddFilterTag } from '#components/Map/hooks/useFilter' import { useAddFilterTag } from '#components/Map/hooks/useFilter'
@ -46,7 +47,9 @@ export const TextView = ({
innerText = replacedText = rawText innerText = replacedText = rawText
} else if (text === undefined) { } else if (text === undefined) {
// Field was omitted by backend (no permission) // Field was omitted by backend (no permission)
innerText = replacedText = `Login to see this ${item?.layer?.item_default_name ?? 'item'}` innerText = replacedText = `[Login](/login) to see this ${
item?.layer?.item_default_name ?? 'item'
}`
} else if (text === null || text === '') { } else if (text === null || text === '') {
// Field is not set or empty - show nothing // Field is not set or empty - show nothing
innerText = '' innerText = ''
@ -127,7 +130,12 @@ export const TextView = ({
else return children else return children
} }
// Default: Link // Internal Link (React Router)
if (href.startsWith('/')) {
return <RouterLink to={href}>{children}</RouterLink>
}
// External Link
return ( return (
<a href={href} target='_blank' rel='noreferrer'> <a href={href} target='_blank' rel='noreferrer'>
{children} {children}

View File

@ -133,6 +133,7 @@ function UtopiaMap({
maplibreStyle={maplibreStyle} maplibreStyle={maplibreStyle}
zoomOffset={zoomOffset} zoomOffset={zoomOffset}
tileSize={tileSize} tileSize={tileSize}
showZoomControl={showZoomControl}
> >
{children} {children}
</UtopiaMapInner> </UtopiaMapInner>

View File

@ -64,6 +64,7 @@ export function UtopiaMapInner({
maplibreStyle, maplibreStyle,
zoomOffset = 0, zoomOffset = 0,
tileSize = 256, tileSize = 256,
showZoomControl,
}: { }: {
children?: React.ReactNode children?: React.ReactNode
geo?: GeoJsonObject geo?: GeoJsonObject
@ -81,6 +82,7 @@ export function UtopiaMapInner({
maplibreStyle?: string maplibreStyle?: string
zoomOffset?: number zoomOffset?: number
tileSize?: number tileSize?: number
showZoomControl?: boolean
}) { }) {
const selectNewItemPosition = useSelectPosition() const selectNewItemPosition = useSelectPosition()
const setSelectNewItemPosition = useSetSelectPosition() const setSelectNewItemPosition = useSetSelectPosition()
@ -285,7 +287,9 @@ export function UtopiaMapInner({
<Outlet /> <Outlet />
<Control position='topLeft' zIndex='1000' absolute> <Control position='topLeft' zIndex='1000' absolute>
<SearchControl /> <SearchControl />
<div className={`${showZoomControl ? 'tw:pl-14' : ''}`}>
<TagsControl /> <TagsControl />
</div>
</Control> </Control>
<Control position='bottomLeft' zIndex='999' absolute> <Control position='bottomLeft' zIndex='999' absolute>
{showFullscreenControl && <FullscreenControl />} {showFullscreenControl && <FullscreenControl />}

View File

@ -40,7 +40,7 @@ const MarkerIconFactory = (
) => { ) => {
if (icon) if (icon)
return divIcon({ return divIcon({
html: `<div class="svg-container">${createSvg(shape, color1, color2)}<img class="overlay-svg" style="width: ${icon.size ? icon.size : '12.5'}px; filter: invert(1) brightness(2);" src="${`${assetsURL ?? ''}` + icon.image}"></div>`, html: `<div class="svg-container">${createSvg(shape, color1, color2)}<img class="overlay-svg" style="width: ${icon.size ? icon.size : '12.5'}px; height: ${icon.size ? icon.size : '12.5'}px; filter: invert(1) brightness(2);" src="${`${assetsURL ?? ''}` + icon.image}"></div>`,
iconAnchor: [17, 40], iconAnchor: [17, 40],
popupAnchor: [0, -40], popupAnchor: [0, -40],
iconSize: new Point(40, 46), iconSize: new Point(40, 46),

View File

@ -13,8 +13,8 @@ export interface LayerProps {
name: string name: string
menuColor: string menuColor: string
menuText: string menuText: string
markerIcon: MarkerIcon markerIcon?: MarkerIcon
markerShape: string markerShape?: string
markerDefaultColor: string markerDefaultColor: string
markerDefaultColor2?: string markerDefaultColor2?: string
api?: ItemsApi<Item> api?: ItemsApi<Item>