Skip to content

Commit

Permalink
Använd tooltip igen och göra hela tooltip klickbar
Browse files Browse the repository at this point in the history
  • Loading branch information
bonny committed Jul 2, 2024
1 parent 04a756d commit c3d6fea
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 29 deletions.
12 changes: 8 additions & 4 deletions app/Http/Controllers/ApiEventsMapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
use App\CrimeEvent;
use Cache;

class ApiEventsMapController extends Controller
{
class ApiEventsMapController extends Controller {
/**
* Hämta data för eventsMap-komponenten.
*/
public function index() {
$cacheSeconds = 5 * 60;
$daysBack = 3;
$cacheKey = __METHOD__ . "_{$daysBack}";

$events = Cache::remember($cacheKey, $cacheSeconds, function () use ($daysBack) {
return CrimeEvent::orderBy("created_at", "desc")
->where('created_at', '>=', now()->subDays($daysBack))
Expand All @@ -26,14 +25,19 @@ public function index() {
"data" => [],
];

// create array with data is a format more suited for app and web
/**
* Create array with data is a format more suited for app and web
* @var array<CrimeEvent> $events
* @var CrimeEvent $item
*/
foreach ($events as $item) {
$event = [
"id" => $item->id,
'time' => $item->getParsedDateInFormat('%H:%M'),
'time_human' => $item->getParsedDateFormattedForHumans(),
'headline' => $item->getHeadline(),
"type" => $item->parsed_title,
"locations" => $item->getLocationString(includeAdministrativeAreaLevel1Locations: false),
"lat" => (float) $item->location_lat,
"lng" => (float) $item->location_lng,
"image" => $item->getStaticImageSrc(320, 320, 2),
Expand Down
1 change: 0 additions & 1 deletion app/View/Components/EventsMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function __construct(
*/
public function render(): View|Closure|string
{
//dd($this->mapSize);
return view('components.events-map');
}
}
30 changes: 27 additions & 3 deletions public/css/events-map.css
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ body.map-is-expanded .SiteHeader {
flex-direction: column;
gap: var(--default-margin-third);
width: 225px;
max-width: 90vw;
/* Remove leaflet default margins */
margin: -14px -26px -13px -21px;
}

.EventsMap-markerTooltip-image {
Expand All @@ -174,19 +175,42 @@ body.map-is-expanded .SiteHeader {
border-radius: 5px;
}

.EventsMap-markerTooltip-innerContent {
display: flex;
flex-direction: column;
gap: var(--default-margin-third);
margin: var(--default-margin-half);
}

.EventsMap-markerTooltip-link::after {
content: "";
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
}

.EventsMap-markerTooltip-headline {
font-size: var(--font-size-small);
font-weight: 500;
margin: 0;
white-space: normal;
}

.EventsMap-markerTooltip-locations {
font-size: var(--font-size-small);
line-height: 1;
margin: 0;
white-space: normal;
}

.EventsMap-markerTooltip-text {
font-size: var(--font-size-small);
white-space: normal;
}

.EventsMap-marker-content {
/* .EventsMap-marker-content {
display: flex;
flex-direction: row;
gap: var(--default-margin);
Expand All @@ -206,7 +230,7 @@ body.map-is-expanded .SiteHeader {
.EventsMap-marker-contentText a {
display: block;
}
} */

.EventsMap a {
color: inherit;
Expand Down
1 change: 1 addition & 0 deletions public/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
--font-size-medium-2: 1.15rem;
--font-size-large: 1.5rem;
--font-size-small: 0.9rem;
--font-size-xsmall: 0.75rem;
--border-radius-normal: 10px;
/* Breakpoints 667px, 1024px */
--breakpoint-medium: 667px;
Expand Down
38 changes: 17 additions & 21 deletions public/js/events-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,31 +234,27 @@ class EventsMap {
L.marker([event.lat, event.lng], {
icon: getLayerIcon(null, map, "", ""),
crimeEventData: event,
})
.bindTooltip(
`
}).bindPopup(
`
<div class="EventsMap-markerTooltip">
<img class="EventsMap-markerTooltip-image" src="${event.image}" alt="">
<h1 class="EventsMap-markerTooltip-headline">${event.headline}</h1>
<div class="EventsMap-markerTooltip-text">${event.time_human}${event.type}</div>
<div class="EventsMap-markerTooltip-innerContent">
<div class="EventsMap-markerTooltip-locations">${event.locations}</div>
<h1 class="EventsMap-markerTooltip-headline">
<a class="EventsMap-markerTooltip-link" href="${event.permalink}" target="_blank">
${event.headline}
</a>
</h1>
<div class="EventsMap-markerTooltip-text">${event.time_human}${event.type}</div>
</div>
</div>
`,
{ direction: "bottom", permanent: false }
)
// .bindPopup(
// `
// <div class="EventsMap-marker-content">
// <a target="_blank" href="${event.permalink}?utm_source=brottsplatskartan&utm_medium=maplink" class="EventsMap-marker-contentText EventsMap-marker-contentLink">
// ${event.time_human} • ${event.type}
// <strong>${event.headline}</strong>
// <!-- <div class="EventsMap-marker-contentLinkIcon">Läs mer →</div> -->
// </a>
// </div> `
// )
.on("click", function (evt) {
const link = evt.target.options.crimeEventData.permalink + "?utm_source=brottsplatskartan&utm_medium=maplink";
window.open(link, "_blank");
});
{ direction: "bottom", permanent: false }
);
// .on("click", function (evt) {
// const link = evt.target.options.crimeEventData.permalink + "?utm_source=brottsplatskartan&utm_medium=maplink";
// window.open(link, "_blank");
// });

markers.push(oneMarker);
});
Expand Down

0 comments on commit c3d6fea

Please sign in to comment.