Skip to content

Commit 7f60069

Browse files
committed
Adds a Shape Override to display custom marker icons in the legend #657
1 parent a4334d7 commit 7f60069

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

configure/src/metaconfigs/layer-vector-config.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@
499499
{
500500
"field": "shape",
501501
"name": "Shape",
502-
"description": "The symbol for which to us for this legend entry. Discreet and continuous describe scales. These scales are broken into groups by a change in shape value. For instance, 'discreet, discreet, discreet, circle, discreet, discreet' represents a discreet scales of three colors, a circle and then a discreet scale of two colors.",
502+
"description": "The symbol for which to use for this legend entry. Discreet and continuous describe scales. These scales are broken into groups by a change in shape value. For instance, 'discreet, discreet, discreet, circle, discreet, discreet' represents a discreet scales of three colors, a circle and then a discreet scale of two colors.",
503503
"type": "dropdown",
504504
"width": 5,
505505
"options": [
@@ -517,6 +517,19 @@
517517
"description": "A label description for this legend entry.",
518518
"type": "text",
519519
"width": 3
520+
},
521+
{
522+
"field": "",
523+
"name": "",
524+
"description": "",
525+
"width": 4
526+
},
527+
{
528+
"field": "shapeOverride",
529+
"name": "Shape Override",
530+
"description": "A URL to a custom symbol for which to use for this legend entry. If the path is relative, it will be relative to the mission's directory. This field will override values in the Shape field.",
531+
"type": "text",
532+
"width": 8
520533
}
521534
]
522535
}

configure/src/metaconfigs/layer-vectortile-config.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@
472472
{
473473
"field": "shape",
474474
"name": "Shape",
475-
"description": "The symbol for which to us for this legend entry. Discreet and continuous describe scales. These scales are broken into groups by a change in shape value. For instance, 'discreet, discreet, discreet, circle, discreet, discreet' represents a discreet scales of three colors, a circle and then a discreet scale of two colors.",
475+
"description": "The symbol for which to use for this legend entry. Discreet and continuous describe scales. These scales are broken into groups by a change in shape value. For instance, 'discreet, discreet, discreet, circle, discreet, discreet' represents a discreet scales of three colors, a circle and then a discreet scale of two colors.",
476476
"type": "dropdown",
477477
"width": 5,
478478
"options": [
@@ -490,6 +490,19 @@
490490
"description": "A label description for this legend entry.",
491491
"type": "text",
492492
"width": 3
493+
},
494+
{
495+
"field": "",
496+
"name": "",
497+
"description": "",
498+
"width": 4
499+
},
500+
{
501+
"field": "shapeOverride",
502+
"name": "Shape Override",
503+
"description": "A URL to a custom symbol for which to use for this legend entry. If the path is relative, it will be relative to the mission's directory. This field will override values in the Shape field.",
504+
"type": "text",
505+
"width": 8
493506
}
494507
]
495508
}

src/essence/Tools/Legend/LegendTool.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ function drawLegends(tools, _legend, layerUUID, display_name, opacity) {
217217
let lastContinues = []
218218
let lastShape = ''
219219
for (let d in _legend) {
220-
var shape = _legend[d].shape
220+
var shape = _legend[d].shapeOverride && _legend[d].shapeOverride.trim()
221+
? _legend[d].shapeOverride : _legend[d].shape
221222
if (
222223
shape == 'circle' ||
223224
shape == 'square' ||
@@ -293,6 +294,37 @@ function drawLegends(tools, _legend, layerUUID, display_name, opacity) {
293294
value: _legend[d].value,
294295
})
295296
lastShape = shape
297+
} else if ( String(shape).endsWith('.png') || String(shape).endsWith('.svg')) {
298+
// PNG or SVG markers
299+
var r = c
300+
.append('div')
301+
.attr('class', 'row')
302+
.style('display', 'flex')
303+
.style('margin', '0px 0px 8px 9px')
304+
305+
r.append('div')
306+
.attr('class', layerUUID + '_legendcustom')
307+
.style('width', '24px')
308+
.style('height', '24px')
309+
.style('background', _legend[d].color)
310+
.style('opacity', opacity)
311+
.style('border', `1px solid ${_legend[d].strokecolor}`)
312+
.style('background-image', `url(${L_.missionPath + shape})`)
313+
.style('background-size', 'contain')
314+
.style('background-repeat', 'no-repeat')
315+
316+
r.append('div')
317+
.style('margin-left', '5px')
318+
.style('height', '100%')
319+
.style('line-height', '19px')
320+
.style('font-size', '14px')
321+
.style('overflow', 'hidden')
322+
.style('white-space', 'nowrap')
323+
.style('max-width', '270px')
324+
.style('text-overflow', 'ellipsis')
325+
.attr('title', _legend[d].value)
326+
.text(_legend[d].value)
327+
296328
}
297329
}
298330
if (lastContinues.length > 0) {

0 commit comments

Comments
 (0)