Skip to content

Commit d3495aa

Browse files
committed
Use a SVG marker icon. Allows for custom marker color
1 parent 252108b commit d3495aa

File tree

7 files changed

+15
-9
lines changed

7 files changed

+15
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ mymap:
254254

255255
#### 5.9. `marker`
256256

257-
The color of the marker used, either `dark` or `light` (in case you are using `mapbox.dark` as your tile-layer). Default is `dark`.
257+
The color of the marker used, either `dark`, `light` or your own HEX value. Default is `dark`.
258258

259259
```yaml
260260
mymap:

assets/images/marker-icon-dark.png

-3.52 KB
Binary file not shown.
-3.5 KB
Binary file not shown.

index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/fields.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@
5353
},
5454
),
5555
'computed' => array(
56-
'markerUrl' => function() {
57-
$tint = in_array($this->marker, ['light', 'dark']) ? $this->marker : option('sylvainjule.locator.marker');
58-
return kirby()->url('media') . '/plugins/sylvainjule/locator/images/marker-icon-'. $tint .'.png';
56+
'markerColor' => function() {
57+
return $this->marker ?? option('sylvainjule.locator.marker');
5958
},
6059
'mapbox' => function() {
6160
$idSwap = [

src/assets/svg/marker-icon.svg

Lines changed: 1 addition & 0 deletions
Loading

src/field/Locator.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export default {
7171
}
7272
},
7373
props: {
74-
markerUrl: String,
7574
tiles: String,
7675
center: Object,
7776
zoom: Object,
@@ -81,11 +80,11 @@ export default {
8180
display: [Array, Boolean],
8281
geocoding: String,
8382
liststyle: String,
84-
liststyle: String,
8583
draggable: Boolean,
8684
autocomplete: Boolean,
8785
language: [String, Boolean],
8886
dblclick: String,
87+
markerColor: String,
8988
9089
// general options
9190
label: String,
@@ -102,10 +101,17 @@ export default {
102101
return 'map-'+ this._uid
103102
},
104103
icon() {
104+
let color = this.markerColor
105+
color = color == 'light' ? '#efefef' : color
106+
color = color == 'dark' ? '#161719' : color
107+
108+
let icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 142"><path fill="'+ color +'" d="M60,0A59.68,59.68,0,0,0,27.37,9.62c-.31.19-.61.39-.92.6A55.74,55.74,0,0,0,7.57,30.71,59.75,59.75,0,0,0,2.63,77.35q.45,1.53,1,3a83.85,83.85,0,0,0,20.53,32.08c9.72,9.51,20.75,17.68,31.2,26.45l3.7,3.09h2c4.7-3.67,9.69-7,14-11.1,9.2-8.69,18.47-17.37,26.92-26.77.49-.54,1-1.09,1.44-1.64l.3-.36c.43-.54.86-1.06,1.28-1.6s.9-1.16,1.34-1.76,1-1.31,1.4-2,.8-1.21,1.19-1.82c.06-.09.12-.18.17-.27.36-.56.72-1.14,1.06-1.72l.08-.13c.29-.5.58-1,.86-1.51.46-.82.91-1.64,1.34-2.48a58.77,58.77,0,0,0,5.35-13s0,0,0,0A59.85,59.85,0,0,0,60,0Zm0,37.55a22.23,22.23,0,1,1-22.2,22.33A22.15,22.15,0,0,1,60,37.55Z"/></svg>'
109+
let iconUrl = 'data:image/svg+xml;base64,' + btoa(icon);
110+
105111
return L.icon({
106-
iconUrl: this.markerUrl,
112+
iconUrl: iconUrl,
107113
iconSize: [40, 47],
108-
iconAnchor: [20, 47],
114+
iconAnchor: [20, 47]
109115
})
110116
},
111117
valueExists() {

0 commit comments

Comments
 (0)