All checks were successful
Deploy / Build and Deploy to Production (push) Successful in 15s
Reorganize routes following design-to-pack pattern: - routes/markers.php: CRUD operations for markers - routes/position.php: Position update (single mode) - routes/image.php: Image capture and regeneration flag management Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
77 lines
2.9 KiB
PHP
77 lines
2.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Map Editor Plugin for Kirby CMS
|
|
*
|
|
* Interactive map editor with MapLibre GL JS for creating
|
|
* print-ready maps with markers and rich content.
|
|
*/
|
|
|
|
Kirby::plugin('geoproject/map-editor', [
|
|
'fields' => [
|
|
'map-editor' => [
|
|
'props' => [
|
|
'defaultCenter' => function ($defaultCenter = [43.836699, 4.360054]) {
|
|
return $defaultCenter;
|
|
},
|
|
'defaultZoom' => function ($defaultZoom = 13) {
|
|
return $defaultZoom;
|
|
},
|
|
'maxMarkers' => function ($maxMarkers = 50) {
|
|
return $maxMarkers;
|
|
},
|
|
'mode' => function ($mode = 'multi') {
|
|
return $mode;
|
|
},
|
|
'latitude' => function ($latitude = null) {
|
|
return $latitude;
|
|
},
|
|
'longitude' => function ($longitude = null) {
|
|
return $longitude;
|
|
},
|
|
'markerIconUrl' => function ($markerIconUrl = null) {
|
|
// Auto-detect marker icon from page files
|
|
if ($markerIconUrl === null && $this->model()) {
|
|
$iconFile = $this->model()->markerIcon()->toFile();
|
|
if ($iconFile) {
|
|
return $iconFile->url();
|
|
}
|
|
}
|
|
return $markerIconUrl;
|
|
},
|
|
'markerIconSize' => function ($markerIconSize = 40) {
|
|
// Auto-detect marker icon size from page
|
|
if ($this->model() && $this->model()->markerIconSize()->isNotEmpty()) {
|
|
return (int) $this->model()->markerIconSize()->value();
|
|
}
|
|
return $markerIconSize;
|
|
}
|
|
]
|
|
]
|
|
],
|
|
'api' => [
|
|
'routes' => [
|
|
require __DIR__ . '/routes/markers.php',
|
|
require __DIR__ . '/routes/position.php',
|
|
require __DIR__ . '/routes/image.php',
|
|
]
|
|
],
|
|
'hooks' => [
|
|
'page.update:after' => function ($newPage, $oldPage) {
|
|
// Mark map page for image regeneration
|
|
if ($newPage->intendedTemplate()->name() === 'map') {
|
|
$markerFile = $newPage->root() . '/.regenerate-map-image';
|
|
file_put_contents($markerFile, time());
|
|
}
|
|
|
|
// If a marker is updated, mark the parent map page for regeneration
|
|
if ($newPage->intendedTemplate()->name() === 'marker') {
|
|
$mapPage = $newPage->parent();
|
|
if ($mapPage && $mapPage->intendedTemplate()->name() === 'map') {
|
|
$markerFile = $mapPage->root() . '/.regenerate-map-image';
|
|
file_put_contents($markerFile, time());
|
|
}
|
|
}
|
|
}
|
|
]
|
|
]);
|