mirror of
https://github.com/heyarne/berliner-winter.git
synced 2026-05-06 19:23:39 +02:00
Use OverlappingMarkerSpiderfier
This commit is contained in:
parent
d7d78b7fc4
commit
4510f01a78
1 changed files with 27 additions and 6 deletions
|
|
@ -1,5 +1,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
import $ from 'jquery'
|
import $ from 'jquery'
|
||||||
|
|
||||||
|
import './lib/oms.min'
|
||||||
|
|
||||||
import filter from './filter'
|
import filter from './filter'
|
||||||
import colorUtils from './colors'
|
import colorUtils from './colors'
|
||||||
|
|
||||||
|
|
@ -17,6 +20,20 @@ class Visualization {
|
||||||
this.data = data
|
this.data = data
|
||||||
this.colors = colors
|
this.colors = colors
|
||||||
|
|
||||||
|
// set up OMS
|
||||||
|
this.oms = new OverlappingMarkerSpiderfier(map, {
|
||||||
|
keepSpiderfied: true,
|
||||||
|
circleSpiralSwitchover: 12,
|
||||||
|
})
|
||||||
|
|
||||||
|
var popup = new L.Popup();
|
||||||
|
this.oms.addListener('click', function (marker) {
|
||||||
|
popup.setContent(marker.description.replace(/\n/g, '<br>'))
|
||||||
|
popup.setLatLng(marker.getLatLng())
|
||||||
|
map.openPopup(popup)
|
||||||
|
})
|
||||||
|
|
||||||
|
// set up markers
|
||||||
this._markers = new Map()
|
this._markers = new Map()
|
||||||
this.setupMarkers()
|
this.setupMarkers()
|
||||||
}
|
}
|
||||||
|
|
@ -123,16 +140,19 @@ class Visualization {
|
||||||
var marker = L.marker([incident.lat, incident.lng], options)
|
var marker = L.marker([incident.lat, incident.lng], options)
|
||||||
.addTo(this.map)
|
.addTo(this.map)
|
||||||
|
|
||||||
|
marker.description = incident.description
|
||||||
|
|
||||||
var color = colorUtils.hexToRGB(this._pickColor(incident))
|
var color = colorUtils.hexToRGB(this._pickColor(incident))
|
||||||
$(marker._icon).css({
|
$(marker._icon).css({
|
||||||
borderColor: `rgba(${color[0]},${color[1]},${color[2]},.5)`,
|
borderColor: `rgba(${color[0]},${color[1]},${color[2]},.5)`,
|
||||||
backgroundColor: `rgba(${color[0]},${color[1]},${color[2]},.2)`
|
backgroundColor: `rgba(${color[0]},${color[1]},${color[2]},.2)`
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.oms.addMarker(marker)
|
||||||
this._markers.set(incident, marker)
|
this._markers.set(incident, marker)
|
||||||
})
|
})
|
||||||
|
|
||||||
return this;
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -146,12 +166,13 @@ class Visualization {
|
||||||
incidents = this.data
|
incidents = this.data
|
||||||
|
|
||||||
for (var [incident, marker] of this._markers)
|
for (var [incident, marker] of this._markers)
|
||||||
if (incidents.indexOf(incident) == -1)
|
if (incidents.indexOf(incident) == -1) {
|
||||||
this.map.removeLayer(marker)
|
this.map.removeLayer(marker)
|
||||||
else
|
this.oms.removeMarker(marker)
|
||||||
marker
|
} else {
|
||||||
.addTo(this.map)
|
this.map.addLayer(marker)
|
||||||
.bindPopup(incident.description.replace(/\n/g, '<br>'))
|
this.oms.addMarker(marker)
|
||||||
|
}
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue