Skip to content

Commit 69c2be4

Browse files
committed
color layer items icon
1 parent a023dbe commit 69c2be4

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

app/assets/stylesheets/modals.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@
249249

250250
.feature-icon {
251251
min-width: 2rem;
252+
height: 2.3rem;
252253
}
253254

254255
.layer-feature-item:hover {
@@ -291,7 +292,7 @@
291292
}
292293

293294
#map-description table td,
294-
#map-description table th,
295+
#map-description table th,
295296
#description-content table td,
296297
#description-content table th {
297298
border: 1px solid #ddd;

app/javascript/maplibre/controls/shared.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export function initLayersModal () {
212212

213213
const icon = document.createElement('span')
214214
icon.classList.add('feature-icon')
215+
icon.classList.add('flex-center')
215216
icon.innerHTML = featureIcon(feature)
216217
listItem.appendChild(icon)
217218
const name = document.createElement('span')

app/javascript/maplibre/feature.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { showElevationChart } from 'maplibre/feature/elevation'
77
import { getFeature, getFeatureSource, layers } from "maplibre/layers/layers"
88
import { wikipediaFeatureDescription } from 'maplibre/layers/wikipedia'
99
import { map } from 'maplibre/map'
10+
import { featureColor } from 'maplibre/styles/styles'
1011
import { marked } from 'marked'
1112

1213
window.marked = marked
@@ -156,24 +157,27 @@ async function featureDescription (feature) {
156157
// set title image according to feature type
157158
export function featureIcon (feature) {
158159
let image = ''
160+
let iconColor = feature.properties['marker-color'] || feature.properties['fill'] || feature.properties['stroke'] || featureColor
161+
if (iconColor === 'transparent') { iconColor = '#c0c0c0' }
162+
let iconColorStyle = `style='color: ${iconColor};'`
159163
if (feature.properties['marker-image-url']) {
160164
image = "<img class='feature-details-icon' src='" + feature.properties['marker-image-url'] + "'>"
161165
} else if (feature.properties['marker-symbol']) {
162166
image = "<img class='feature-details-icon' src='/emojis/noto/" + feature.properties['marker-symbol'] + ".png'>"
163167
} else if (feature.properties['stroke-image-url']) {
164168
image = "<img class='feature-details-icon' src='" + feature.properties['stroke-image-url'] + "'>"
165169
} else if (feature.properties?.route?.profile === "cycling-mountain" || feature.properties?.route?.profile === "bike") {
166-
image = "<i class='bi bi-bicycle fs-3'>"
170+
image = `<i class='bi bi-bicycle fs-3' ${iconColorStyle}>`
167171
} else if (feature.properties?.route?.profile === "driving-car" || feature.properties?.route?.profile === "car") {
168-
image = "<i class='bi bi-car-front fs-3'>"
172+
image = `<i class='bi bi-car-front fs-3' ${iconColorStyle}>`
169173
} else if (feature.properties?.route?.profile === "foot") {
170-
image = "<i class='bi bi-person-walking fs-3'>"
174+
image = `<i class='bi bi-person-walking fs-3' ${iconColorStyle}>`
171175
} else if (feature.geometry.type === "LineString" || feature.geometry.type === "MultiLineString") {
172-
image = "<i class='bi bi-signpost me-2 fs-3'>"
176+
image = `<i class='bi bi-signpost fs-3' ${iconColorStyle}>`
173177
} else if (feature.geometry.type === "Polygon" || feature.geometry.type === "MultiPolygon") {
174-
image = "<span class='feature-details-icon'><i class='bi bi-bounding-box-circles fs-3'></span>"
178+
image = `<i class='bi bi-bounding-box-circles fs-3' ${iconColorStyle}>`
175179
} else if (feature.geometry.type === "Point") {
176-
image = "<i class='bi bi-record-circle fs-3'>"
180+
image = `<i class='bi bi-record-circle fs-3' ${iconColorStyle}></i>`
177181
}
178182
return image
179183
}

0 commit comments

Comments
 (0)