Skip to content

Commit 9937093

Browse files
committed
Display alternate attribute names on pop-up. Made polygon lines thinner (reduced opacity).
1 parent 880b909 commit 9937093

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/components/widgets/LivelihoodZonesMap.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ export default {
150150
expression: 'in',
151151
key: 'ADM2_EN',
152152
value: provinceList
153+
},
154+
{ // Attribute name mapping
155+
'ADM2_EN': 'Province',
156+
'ADM3_EN': 'Municipality',
157+
'Legend_v2': 'Legend'
153158
}
154159
)
155160
@@ -297,9 +302,11 @@ export default {
297302
window.MBL.isLoading = false
298303
// window.MBL.toggleHandlers(true)
299304
loadedOnce = true
300-
console.log(`--loaded vector length: ${features.length}`)
301305
that.disabled = false
302306
307+
console.log(`--loaded vector length: ${features.length} from layer ${e.sourceId}`)
308+
console.log(Array.from(features, (x) => x.properties))
309+
303310
if (provinceName) {
304311
colorCodes = Array.from(features.filter(x => x.properties['ADM2_EN'] === provinceName),
305312
(x) => x.properties['Legend_v2']).filter(unique)

static/map.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,10 @@ MapboxMap.prototype.getLegendColorCodes = function () {
182182
* filter.key - {String} attribute name
183183
* filter.value - {String} attribute value OR
184184
* filter.value - {Array} string attribute value(s)
185+
* attributeNames - {Object} key-value pair of alternate names for feature attributes to display on the pop-up
186+
* i.e. { 'ADM2_EN': 'Province', 'ADM3_EN': 'Municipality' }
185187
*/
186-
MapboxMap.prototype.addLayerSource = function (layerName, tilesetName, tilesetUrl, filter) {
188+
MapboxMap.prototype.addLayerSource = function (layerName, tilesetName, tilesetUrl, filter, attributeNames) {
187189
const that = this
188190
const layerID = `${layerName}-layer`
189191
this.isLoading = true
@@ -210,7 +212,7 @@ MapboxMap.prototype.addLayerSource = function (layerName, tilesetName, tilesetUr
210212
'visibility': 'visible'
211213
},
212214
"paint": {
213-
"fill-outline-color": "rgba(0,0,0,1.0)",
215+
"fill-outline-color": "rgba(0,0,0,0.2)",
214216
"fill-color": colorExpression,
215217
"fill-opacity": 1.0,
216218
},
@@ -251,7 +253,12 @@ MapboxMap.prototype.addLayerSource = function (layerName, tilesetName, tilesetUr
251253
// print all data
252254
var content = ""
253255
for(key in e.features[0].properties){
254-
content += `${key}: ${e.features[0].properties[key]}`
256+
let attr = key
257+
if (attributeNames) {
258+
attr = attributeNames[key] ? attributeNames[key] : key
259+
}
260+
261+
content += `${attr}: ${e.features[0].properties[key]}`
255262
content += "<br>"
256263
}
257264

0 commit comments

Comments
 (0)