Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/tilelayer select #681

Merged
merged 2 commits into from
Nov 7, 2024
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
67 changes: 65 additions & 2 deletions apps/admin-server/src/pages/projects/[project]/settings/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useForm } from 'react-hook-form';
import { Button } from '@/components/ui/button';
import {
Form,
FormControl,
FormControl, FormDescription,
FormField,
FormItem,
FormLabel,
Expand Down Expand Up @@ -36,6 +36,8 @@ const formSchema = z.object({
maxZoom: z.string().optional(),
minZoom: z.string().optional(),
areaId: z.string().optional(),
tilesVariant: z.string().optional(),
customUrl: z.string().optional(),
});

export default function ProjectSettingsMap() {
Expand All @@ -51,6 +53,8 @@ export default function ProjectSettingsMap() {
minZoom: data?.config?.map?.minZoom || '7',
maxZoom: data?.config?.map?.maxZoom || '20',
areaId: data?.config?.map?.areaId || '',
tilesVariant: data?.config?.map?.tilesVariant || 'nlmaps',
customUrl: data?.config?.map?.customUrl || '',
}
},
[data, areas]
Expand All @@ -72,6 +76,8 @@ export default function ProjectSettingsMap() {
areaId: values.areaId,
minZoom: values.minZoom,
maxZoom: values.maxZoom,
tilesVariant: values.tilesVariant,
customUrl: values.customUrl,
},
});
if (project) {
Expand All @@ -98,6 +104,14 @@ export default function ProjectSettingsMap() {
}
}, [ form.watch('minZoom'), form.watch('maxZoom') ] );

const tileLayerOptions = [
{ value: 'nlmaps', label: 'Nederlandse Kaart' },
{ value: 'amaps', label: 'Amsterdam Kaart' },
{ value: 'openstreetmaps', label: 'OpenStreetMap' },
{ value: 'n3s', label: 'CartoDB Light' },
rudivanhierden marked this conversation as resolved.
Show resolved Hide resolved
{ value: 'custom', label: 'Aangepaste Kaart' },
];

return (
<div>
<PageLayout
Expand All @@ -122,7 +136,7 @@ export default function ProjectSettingsMap() {
<Separator className="my-4" />
<form
onSubmit={form.handleSubmit(onSubmit)}
className="lg:w-fit grid grid-cols-1 lg:grid-cols-2 gap-x-4 gap-y-8">
className="lg:w-2/3 grid grid-cols-1 lg:grid-cols-2 gap-x-4 gap-y-8">

<FormField
control={form.control}
Expand Down Expand Up @@ -169,6 +183,55 @@ export default function ProjectSettingsMap() {
noSelection="&nbsp;"
/>

<FormField
control={form.control}
name="tilesVariant"
render={({ field }) => (
<FormItem>
<FormLabel>
Welke weergave van de kaart wil je gebruiken?
</FormLabel>
<Select
onValueChange={field.onChange}
value={field.value || 'nlmaps'}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Selecteer een kaartweergave" />
</SelectTrigger>
</FormControl>
<SelectContent>
{tileLayerOptions.map(option => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>

{form.watch('tilesVariant') === 'custom' && (
<FormField
control={form.control}
name="customUrl"
render={({ field }) => (
<FormItem className="col-span-1">
<FormLabel>
Aangepaste URL
</FormLabel>
<FormDescription>{`Voer de URL in voor de aangepaste kaartweergave. Bijvoorbeeld: https://example.com/tiles/{z}/{x}/{y}.png`}</FormDescription>
<FormControl>
<Input placeholder="https://example.com/tiles/{z}/{x}/{y}.png" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
)}

<Button
type="submit"
className="w-fit col-span-full"
Expand Down
4 changes: 4 additions & 0 deletions packages/leaflet-map/src/base-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ const BaseMap = ({
center.lat && center.lng
? { lat: center.lat, lng: center.lng }
: { lat: 52.37104644463586, lng: 4.900402911007405 };

tilesVariant = props?.map?.tilesVariant || tilesVariant ||'nlmaps';
const customUrlSetting = tilesVariant === 'custom' ? props?.map?.customUrl : undefined;


// clustering geeft errors; ik begrijp niet waarom: het gebeurd alleen in de gebuilde widgets, niet in de dev componenten
Expand Down Expand Up @@ -375,6 +378,7 @@ const BaseMap = ({
// ToDo: waarom kan ik die niet gewoon als props meesturen
const tileLayerProps = {
tilesVariant,
customUrlSetting,
tiles,
minZoom,
maxZoom,
Expand Down
3 changes: 2 additions & 1 deletion packages/leaflet-map/src/tile-layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default function TileLayer({
tiles = null,
minZoom = 0,
maxZoom = 25,
customUrl = '',
...props
}: MapTilesProps) {

Expand Down Expand Up @@ -52,7 +53,7 @@ export default function TileLayer({
maxZoom={ typeof maxZoom != 'undefined' ? maxZoom : 19 }
minZoom={ typeof minZoom != 'undefined' ? minZoom : 0 }
subdomains={tiles && tiles.subdomains || ''}
url={tiles && tiles.url || 'https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0/standaard/EPSG:3857/{z}/{x}/{y}.png'}
url={customUrl || 'https://service.pdok.nl/brt/achtergrondkaart/wmts/v2_0/standaard/EPSG:3857/{z}/{x}/{y}.png'}
/>)

default:
Expand Down
1 change: 1 addition & 0 deletions packages/leaflet-map/src/types/map-tiles-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type MapTiles = {

export type MapTilesProps = {
tilesVariant?: string,
customUrl?: string,
tiles?: MapTiles | null,
minZoom?: number,
maxZoom?: number,
Expand Down
2 changes: 2 additions & 0 deletions packages/types/project-setting-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,7 @@ export type ProjectSettingProps = {
minZoom: string;
maxZoom: string;
areaId: string;
tilesVariant?: string;
customUrl?: string;
};
};
Loading