feat(map): add organization color scheme and improve map controls
This commit is contained in:
@@ -16,6 +16,8 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
class EventMapController extends AbstractFrontendModuleController
|
||||
{
|
||||
private const MAP_STYLE_URL = 'https://maps.mummert.media/metadaten/world-light.json';
|
||||
private const DEFAULT_CENTER_MODE = 'markers';
|
||||
private const DEFAULT_EVENT_COLOR = '#BC5067';
|
||||
|
||||
public function __construct(
|
||||
private readonly MapModuleDataProvider $mapModuleDataProvider,
|
||||
@@ -26,15 +28,69 @@ class EventMapController extends AbstractFrontendModuleController
|
||||
{
|
||||
$containerId = sprintf('eventmanager-map-%d', (int) ($model->id ?? 0));
|
||||
$dataElementId = sprintf('%s-data', $containerId);
|
||||
$filterWrapperId = sprintf('%s-filter', $containerId);
|
||||
$filterGroupId = sprintf('%s-filter-group', $containerId);
|
||||
$showOrganizations = '1' === (string) ($model->mapShowOrganizations ?? '');
|
||||
$showExternalOrganizations = '1' === (string) ($model->mapShowExternalOrganizations ?? '');
|
||||
$showEvents = '1' === (string) ($model->mapShowEvents ?? '');
|
||||
$centerMode = (string) ($model->mapCenterMode ?? self::DEFAULT_CENTER_MODE);
|
||||
$eventColor = $this->normalizeHexColor((string) ($model->mapEventColor ?? self::DEFAULT_EVENT_COLOR));
|
||||
$organizationColorScheme = trim((string) ($model->mapOrganizationColorScheme ?? ''));
|
||||
|
||||
if (!in_array($centerMode, ['markers', 'custom'], true)) {
|
||||
$centerMode = self::DEFAULT_CENTER_MODE;
|
||||
}
|
||||
|
||||
$template->set('mapContainerId', $containerId);
|
||||
$template->set('mapDataElementId', $dataElementId);
|
||||
$template->set('mapFilterWrapperId', $filterWrapperId);
|
||||
$template->set('mapFilterGroupId', $filterGroupId);
|
||||
$template->set('mapStyleUrl', self::MAP_STYLE_URL);
|
||||
$template->set('mapCenterMode', $centerMode);
|
||||
$template->set('mapEventColor', $eventColor);
|
||||
$template->set('mapOrganizationColorScheme', $organizationColorScheme);
|
||||
$template->set('mapCenterLat', trim((string) ($model->mapCenterLat ?? '')));
|
||||
$template->set('mapCenterLng', trim((string) ($model->mapCenterLng ?? '')));
|
||||
$template->set('mapCenterZoom', (int) ($model->mapCenterZoom ?? 12));
|
||||
$template->set('mapItemsJson', json_encode(
|
||||
$this->mapModuleDataProvider->getMapItems(),
|
||||
$this->mapModuleDataProvider->getMapItems($showOrganizations, $showEvents, $showExternalOrganizations),
|
||||
\JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_APOS | \JSON_HEX_QUOT | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR,
|
||||
));
|
||||
$template->set('mapOrganizationTags', $this->mapModuleDataProvider->getOrganizationTags());
|
||||
|
||||
return $template->getResponse();
|
||||
}
|
||||
|
||||
private function normalizeHexColor(string $value): string
|
||||
{
|
||||
$normalized = strtoupper(trim($value));
|
||||
|
||||
if (preg_match('/^#[0-9A-F]{6}$/', $normalized)) {
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
if (preg_match('/^[0-9A-F]{6}$/', $normalized)) {
|
||||
return '#'.$normalized;
|
||||
}
|
||||
|
||||
if (preg_match('/^#[0-9A-F]{3}$/', $normalized)) {
|
||||
return sprintf(
|
||||
'#%1$s%1$s%2$s%2$s%3$s%3$s',
|
||||
$normalized[1],
|
||||
$normalized[2],
|
||||
$normalized[3],
|
||||
);
|
||||
}
|
||||
|
||||
if (preg_match('/^[0-9A-F]{3}$/', $normalized)) {
|
||||
return sprintf(
|
||||
'#%1$s%1$s%2$s%2$s%3$s%3$s',
|
||||
$normalized[0],
|
||||
$normalized[1],
|
||||
$normalized[2],
|
||||
);
|
||||
}
|
||||
|
||||
return self::DEFAULT_EVENT_COLOR;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user