Skip to content

Commit

Permalink
Add small lights feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Ergo Enn committed Jan 26, 2022
1 parent c59e938 commit e472efe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
17 changes: 17 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
<input name="real-colors" type="checkbox">
Show real colors
</label>
<label>
<input name="real-distances" type="checkbox">
Show real distance
</label>
</div>
<a href="https://github.com/geodienst/lighthousemap"><img
style="position: absolute; top: 0; right: 0; border: 0; z-index: 1000"
Expand Down Expand Up @@ -204,6 +208,7 @@
interactive: false,
title: feat.properties.tags['name'],
radius: (parseFloat(data['seamark:light:range'], 10) || 1) * 1852,
realDistance: (parseFloat(data['seamark:light:range'], 10) || 1) * 1852,
sequence: sequence,
stroke: false,
fillOpacity: 0.5,
Expand All @@ -229,6 +234,15 @@
useRealColors = this.checked;
});


let useRealDistances = true;

document.querySelector('input[name=real-distances]').checked = useRealColors;

document.querySelector('input[name=real-distances]').addEventListener('change', function (e) {
useRealDistances = this.checked;
});

lights.then(layer => {
let draw = function (t) {
layer.eachVisibleLayer(layerGroup => {
Expand All @@ -238,6 +252,7 @@
try {
var state = marker.options.sequence.state(t);
marker.setColor(state ? (useRealColors ? state : '#FF0') : false);
marker.setUseRealDistance(useRealDistances);
} catch (e) {
console.error(e)
}
Expand All @@ -256,6 +271,8 @@

lights.catch(e => console.error(e));



</script>
</body>

Expand Down
16 changes: 15 additions & 1 deletion leaflet.light.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
L.Light = L.SemiCircle.extend({
setColor(color) {
options:{
realDistance: 1852,
useRealDistance: true
},

setColor: function(color) {
if (this._color !== color) {
this._color = color;
L.Path.prototype.setStyle.call(this, {fill: !!color, fillColor: color});
}
},
setUseRealDistance: function(b) {
if(b != this.useRealDistance){
if(b)
this.setRadius(this.realDistance);
else
this.setRadius(500);
this.useRealDistance = b;
}
}
});

Expand Down

0 comments on commit e472efe

Please sign in to comment.