small performance updates

This commit is contained in:
surrim 2022-05-19 01:33:23 +01:00 committed by onli
parent 88219cc40f
commit 5c76099088

View file

@ -1,7 +1,7 @@
const dateToColor = date => { const dateToColor = date => {
const minDate = new Date(date.getFullYear(), date.getMonth() - 1, 0); const minDate = new Date(date.getFullYear(), date.getMonth() - 1, 0);
const maxDate = new Date(date.getFullYear(), date.getMonth(), 0); const maxDate = new Date(date.getFullYear(), date.getMonth(), 0);
return "hsl(" + ((date.getTime() - minDate.getTime()) / (maxDate.getTime() - minDate.getTime())) + "turn, 100%, 50%)" return "hsl(" + ((date.getTime() - minDate.getTime()) / (maxDate.getTime() - minDate.getTime())).toFixed(3) + "turn, 100%, 50%)"
}; };
window.addEventListener("load", () => { window.addEventListener("load", () => {
@ -56,14 +56,16 @@ window.addEventListener("load", () => {
.map(feature => ol.sphere.getLength(feature.getGeometry())) .map(feature => ol.sphere.getLength(feature.getGeometry()))
.reduce((a, b) => a + b, 0); .reduce((a, b) => a + b, 0);
}); });
const color = dateToColor(new Date(upload.date * 1000));
const lineDash = upload.date * 1000 > Date.now() ? [3, 6] : undefined;
const layer = new ol.layer.VectorImage({ const layer = new ol.layer.VectorImage({
source: source, source: source,
style: feature => feature.getGeometry().getType() === "MultiLineString" style: feature => feature.getGeometry().getType() === "MultiLineString"
? new ol.style.Style({ ? new ol.style.Style({
stroke: new ol.style.Stroke({ stroke: new ol.style.Stroke({
color: dateToColor(new Date(upload.date * 1000)), color: color,
width: 3, width: 3,
lineDash: upload.date * 1000 > Date.now() ? [3, 6] : undefined lineDash: lineDash
}) })
}) })
: undefined : undefined