fix: capture map image immediately on "Définir le cadrage" click
All checks were successful
Deploy / Build and Deploy to Production (push) Successful in 21s

Save map data directly via API instead of emit('input') to avoid
draft state. Capture image, clear flag, then reload — the panel
shows the correct image in a single reload.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
isUnknown 2026-02-24 15:26:40 +01:00
parent e806f6ac48
commit 9ea02b2465
4 changed files with 158 additions and 44 deletions

View file

@ -0,0 +1,69 @@
<?php
/**
* PATCH save map data (center, zoom) directly to the page content
*/
return [
'pattern' => 'map-editor/pages/(:all)/mapdata',
'method' => 'PATCH',
'auth' => false,
'action' => function (string $pageId) {
try {
$user = kirby()->user();
if (!$user && !kirby()->option('debug', false)) {
return [
'status' => 'error',
'message' => 'Unauthorized',
'code' => 401
];
}
$page = kirby()->page($pageId);
if (!$page) {
return [
'status' => 'error',
'message' => 'Page not found',
'code' => 404
];
}
if (!$page->permissions()->can('update')) {
return [
'status' => 'error',
'message' => 'Forbidden',
'code' => 403
];
}
$data = kirby()->request()->data();
if (!isset($data['mapdata'])) {
return [
'status' => 'error',
'message' => 'mapdata is required',
'code' => 400
];
}
$page->update([
'mapdata' => $data['mapdata']
]);
return [
'status' => 'success',
'data' => [
'message' => 'Map data saved successfully'
]
];
} catch (Exception $e) {
return [
'status' => 'error',
'message' => $e->getMessage(),
'code' => 500
];
}
}
];