Skip to content

Commit 848c107

Browse files
author
Arman Badalyan
committed
geophystech#305 Buildings Legends
1 parent 7aca92d commit 848c107

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/components/maps/Buildings.vue

+22-13
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,34 @@
8686
8787
damageLevels.sort((a, b) => a - b)
8888
89-
if (!this.$el.querySelector('.map-legend'))
89+
let buildingsLegendsElem = this.$el.querySelector('.buildings-legends')
90+
let addLegends = function(legendsElem)
9091
{
91-
const legend = window.L.control({ position: 'bottomright' })
92-
93-
legend.onAdd = map => {
94-
95-
let div = window.L.DomUtil.create('div', 'map-legend buildings-legends')
96-
let buildingsLegends = ''
92+
let buildingsLegends = ''
9793
98-
damageLevels.forEach(dLevel => {
99-
buildingsLegends +=
100-
`<div class="buildings-legend">
94+
damageLevels.forEach(dLevel => {
95+
buildingsLegends +=
96+
`<div class="buildings-legend">
10197
<span style="background: ${buildingColor(dLevel)}"></span>
10298
<span>d-${dLevel}</span>
10399
</div>`
104-
})
100+
})
101+
102+
legendsElem.innerHTML = buildingsLegends
103+
}
105104
106-
div.innerHTML = buildingsLegends
107-
return div
105+
if (buildingsLegendsElem)
106+
{
107+
addLegends(buildingsLegendsElem)
108+
}
109+
else
110+
{
111+
const legend = window.L.control({ position: 'bottomright' })
112+
113+
legend.onAdd = map => {
114+
let legendsElem = window.L.DomUtil.create('div', 'map-legend buildings-legends')
115+
addLegends(legendsElem)
116+
return legendsElem
108117
}
109118
110119
legend.addTo(this.map.object)

0 commit comments

Comments
 (0)