Skip to content

Commit ada1c3e

Browse files
authored
Merge pull request #68 from thekid/feature/preview-image-markers
Show preview images instead of marker icons on map
2 parents 80a2f1b + 79846a9 commit ada1c3e

File tree

7 files changed

+49
-18
lines changed

7 files changed

+49
-18
lines changed

src/main/handlebars/content.handlebars

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ parent: feed
4242
<script src="/assets/{{asset 'mapping.js'}}" defer></script>
4343
<script type="module">
4444
{{&use 'mapping'}}
45-
const mapping = new Mapping('/static/marker.png');
45+
const mapping = new Mapping();
4646
4747
{{#each item.locations}}
48-
mapping.mark(null, {{lon}}, {{lat}}, `{{name}}`);
48+
{{#with (wrap item.images @index)}}
49+
mapping.mark(null, {{lon}}, {{lat}}, `{{name}}`, '/image/{{item.slug}}/thumb-{{name}}.webp');
50+
{{/with}}
4951
{{/each}}
5052
5153
mapping.project(document.querySelector('#map'));

src/main/handlebars/journey.handlebars

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ parent: feed
8383
<script src="/assets/{{asset 'mapping.js'}}" defer></script>
8484
<script type="module">
8585
{{&use 'mapping'}}
86-
const mapping = new Mapping('/static/marker.png');
86+
const mapping = new Mapping();
8787
8888
{{#each itinerary}}
8989
{{#each locations}}
90-
mapping.mark('#{{scroll slug}}', {{lon}}, {{lat}}, `{{title}}: {{name}}`);
90+
{{#with (wrap images @index)}}
91+
mapping.mark('#{{scroll slug}}', {{lon}}, {{lat}}, `{{title}}: {{../name}}`, '/image/{{slug}}/thumb-{{name}}.webp');
92+
{{/with}}
9193
{{/each}}
9294
{{/each}}
9395

src/main/handlebars/journeys.handlebars

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232
<script src="/assets/{{asset 'mapping.js'}}" defer></script>
3333
<script type="module">
3434
{{&use 'mapping'}}
35-
const mapping = new Mapping('/static/marker.png');
35+
const mapping = new Mapping();
3636
3737
{{#each journeys}}
3838
{{#each locations}}
39-
mapping.mark('/journey/{{slug}}', {{lon}}, {{lat}}, `{{title}}: {{name}}`);
39+
{{#with (wrap images @index)}}
40+
mapping.mark('/journey/{{slug}}', {{lon}}, {{lat}}, `{{title}}: {{../name}}`, '/image/{{slug}}/thumb-{{name}}.webp');
41+
{{/with}}
4042
{{/each}}
4143
{{/each}}
4244

src/main/handlebars/layout.handlebars

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,15 @@
557557
}
558558
}
559559
560+
.marker {
561+
width: 1.9rem;
562+
height: 1.9rem;
563+
border-radius: 50%;
564+
border: .15rem solid white;
565+
box-shadow: .25rem .25rem 1rem rgb(0 0 0 / .2);
566+
object-fit: cover;
567+
}
568+
560569
#map {
561570
margin-top: 1rem;
562571
width: 100%;

src/main/js/mapping.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
class Mapping {
2-
#list = [];
3-
4-
/** Creates new map using given marker images */
5-
constructor(image) {
6-
this.style = new ol.style.Style({image: new ol.style.Icon(({src: image}))})
7-
}
2+
#features = [];
3+
#markers = [];
84

95
/** Add marker and link at a given position */
10-
mark(link, lon, lat, name) {
6+
mark(link, lon, lat, name, uri) {
7+
const $image = document.createElement('img');
8+
$image.src = uri;
9+
$image.alt = name;
10+
$image.classList.add('marker');
11+
12+
const overlay = new ol.Overlay({
13+
position: ol.proj.fromLonLat([lon, lat]),
14+
positioning: 'center-center',
15+
element: $image,
16+
stopEvent: false
17+
});
18+
this.#markers.push(overlay);
19+
1120
const marker = new ol.Feature({
1221
geometry : new ol.geom.Point(ol.proj.fromLonLat([lon, lat])),
1322
link : link,
1423
name : name
1524
});
16-
marker.setStyle(this.style);
17-
this.#list.push(marker);
25+
26+
this.#features.push(marker);
1827
}
1928

2029
/** Escape input for use in HTML */
@@ -24,13 +33,17 @@ class Mapping {
2433

2534
/** Project this map on to a given DOM element */
2635
project($element) {
27-
const source = new ol.source.Vector({features: this.#list});
2836
const map = new ol.Map({
2937
target: $element,
3038
layers: [new ol.layer.Tile({source: new ol.source.OSM()})]
3139
});
32-
map.addLayer(new ol.layer.Vector({source: source}));
33-
map.getView().fit(source.getExtent(), {padding: [32, 32, 32, 32], minResolution: 30});
40+
for (const overlay of this.#markers) {
41+
map.addOverlay(overlay);
42+
}
43+
44+
const features = new ol.source.Vector({features: this.#features});
45+
map.addLayer(new ol.layer.Vector({source: features}));
46+
map.getView().fit(features.getExtent(), {padding: [32, 32, 32, 32], minResolution: 30});
3447

3548
const $popup = $element.querySelector('.popup');
3649
map.on('movestart', event => {

src/main/php/de/thekid/dialog/Helpers.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public function helpers() {
5959
}
6060
return $r;
6161
};
62+
yield 'wrap' => function($node, $context, $options) {
63+
return $options[0][$options[1] % sizeof($options[0])];
64+
};
6265
yield 'sign' => function($node, $context, $options) {
6366
return $this->signing?->sign($options[0]);
6467
};

src/main/webapp/static/marker.png

-8.25 KB
Binary file not shown.

0 commit comments

Comments
 (0)