Skip to content

Commit 5060952

Browse files
committed
wip: Enhance marker rendering to homogenize map and legend display #795
1 parent f6efdaa commit 5060952

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

map/client/leaflet/ShapeMarker.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@ import _ from 'lodash'
22
import L from 'leaflet'
33
import { utils as coreUtils } from '../../../core/client/index.js'
44

5+
// Defaults marker properties
6+
const defaults = {
7+
shape: 'marker-pin',
8+
width: 28,
9+
height: 36,
10+
icon: {
11+
classes: 'fa fa-circle'
12+
}
13+
}
14+
515
export const ShapeMarker = L.Marker.extend({
616
initialize (latlng, options) {
7-
// set default values
8-
const shape = _.get(options, 'shape', 'marker-pin')
9-
const width = _.get(options, 'width', 28)
10-
const height = _.get(options, 'height', 36)
11-
// create divicon
12-
var icon = L.divIcon({
13-
iconSize: [width, height],
14-
iconAnchor: [width/2, height],
15-
html: coreUtils.createShape(Object.assign({ shape, width, height }, options)),
16-
className: 'dummy'
17+
let _options = _.cloneDeep(options)
18+
// map options from simplespec to SVG shape
19+
if (_options.fillColor) _.set(_options, 'color', options.fillColor)
20+
if (_options.fillOpacity) _.set(_options, 'opacity', options.fillOpacity)
21+
if (_options.color) _.set(_options, 'stroke.color', options.color)
22+
if (_options.weight) _.set(_options, 'stroke.Width', options.weight)
23+
// create the marker with the corredt divIcon
24+
const width = _options.width || defaults.width
25+
const height = _options.height || defaults.height
26+
L.Marker.prototype.initialize.call(this, latlng, {
27+
icon: L.divIcon({
28+
iconSize: [width, height],
29+
iconAnchor: [width/2, height],
30+
html: coreUtils.createShape(_.defaultsDeep(_options, defaults)),
31+
className: ''
32+
})
1733
})
18-
// this.enableDebug = true
19-
L.Marker.prototype.initialize.call(this, latlng, { icon })
2034
}
2135
})
22-
23-
L.shapeMarker = function (latlng, options) {
24-
return new ShapeMarker(latlng, options)
25-
}

map/client/mixins/map/mixin.style.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export const style = {
1919
_.get(this, 'activityOptions.engine.pointStyle'),
2020
leafletOptions.layerStyle,
2121
this.convertFromSimpleStyleSpec(feature.style || feature.properties))
22-
2322
// We allow to template style properties according to feature,
2423
// because it can be slow you have to specify a subset of properties
2524
if (leafletOptions.template) {

0 commit comments

Comments
 (0)