From 02947bb42dd8d09efeb5c39a89302e36069a3056 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Sat, 8 Mar 2025 13:35:58 +0000 Subject: [PATCH] labels: work around chromium bug --- html/planeObject.js | 31 ++++++++++--------- html/script.js | 73 +++++++++++++++++++++++---------------------- 2 files changed, 54 insertions(+), 50 deletions(-) diff --git a/html/planeObject.js b/html/planeObject.js index a53b4f0..f9bf241 100644 --- a/html/planeObject.js +++ b/html/planeObject.js @@ -834,17 +834,20 @@ PlaneObject.prototype.updateIcon = function() { let svgKey = fillColor + '!' + this.shape.name + '!' + this.strokeWidth; let labelText = null; - if ( enableLabels && (!multiSelect || (multiSelect && this.selected)) && + if (isNaN(g.enableLabels) || isNaN(g.extendedLabels)) { + console.log(`${g.enableLabels} ${g.extendedLabels}`); + } + if ( g.enableLabels && (!multiSelect || (multiSelect && this.selected)) && ( - (zoomLvl >= labelZoom && this.altitude != "ground" && this.dataSource != "ais") - || (zoomLvl >= labelZoomGround - 2 && this.speed > 5 && !this.fakeHex) - || (zoomLvl >= labelZoomGround + 0 && !this.fakeHex) - || (zoomLvl >= labelZoomGround + 1) + (g.zoomLvl >= labelZoom && this.altitude != "ground" && this.dataSource != "ais") + || (g.zoomLvl >= labelZoomGround - 2 && this.speed > 5 && !this.fakeHex) + || (g.zoomLvl >= labelZoomGround + 0 && !this.fakeHex) + || (g.zoomLvl >= labelZoomGround + 1) || this.selected ) ) { let callsign = ""; - if (this.flight && this.flight.trim() && !(this.dataSource == "ais" && !extendedLabels)) + if (this.flight && this.flight.trim() && !(this.dataSource == "ais" && !g.extendedLabels)) callsign = this.flight.trim(); else if (this.registration) callsign = 'reg: ' + this.registration; @@ -878,7 +881,7 @@ PlaneObject.prototype.updateIcon = function() { labelText += '\nHIJACK'; } } - } else if (extendedLabels == 3) { + } else if (g.extendedLabels == 3) { if (!windLabelsSlim) { labelText += 'Wind' + NBSP; } @@ -905,15 +908,15 @@ PlaneObject.prototype.updateIcon = function() { if (windLabelsSlim && this.wd == null) { labelText = ''; } - } else if (extendedLabels == 2) { + } else if (g.extendedLabels == 2) { labelText += (this.registration ? this.registration : unknown) + NBSP + (this.icaoType ? this.icaoType : unknown) + '\n'; } - if (extendedLabels == 1 || extendedLabels == 2) { + if (g.extendedLabels == 1 || g.extendedLabels == 2) { if ((!this.onGround || (this.speed && this.speed > 18) || (this.selected && !SelectedAllPlanes))) { labelText += speedString + NBSP + NNBSP + altString.padStart(6, NBSP) + '\n'; } } - if (extendedLabels < 3 && !uk_advisory) { + if (g.extendedLabels < 3 && !uk_advisory) { labelText += callsign; } } @@ -1741,11 +1744,11 @@ PlaneObject.prototype.updateMarker = function(moved) { this.scale = iconSize * this.baseScale; this.strokeWidth = outlineWidth * ((this.selected && !SelectedAllPlanes && !onlySelected) ? 0.85 : 0.7) / this.baseScale; - if (!this.marker && (!webgl || enableLabels)) { + if (!this.marker && (!webgl || g.enableLabels)) { this.marker = new ol.Feature(this.olPoint); this.marker.hex = `${this.icao}`; } - if (webgl && !enableLabels && this.marker) { + if (webgl && !g.enableLabels && this.marker) { if (this.marker.visible) { PlaneIconFeatures.removeFeature(this.marker); this.marker.visible = false; @@ -1766,7 +1769,7 @@ PlaneObject.prototype.updateMarker = function(moved) { this.glMarker.set('sy', getSpriteY(this.shape) * glIconSize); } - if (this.marker && (!webgl || enableLabels)) { + if (this.marker && (!webgl || g.enableLabels)) { this.updateIcon(); if (!this.marker.visible) { this.marker.visible = true; @@ -1958,7 +1961,7 @@ PlaneObject.prototype.updateLines = function() { seg.label = true; } else if ( trackLabels || - ((i == 0 || i == this.track_linesegs.length-1 ||seg.leg) && showTrace && enableLabels) + ((i == 0 || i == this.track_linesegs.length-1 ||seg.leg) && showTrace && g.enableLabels) ) { // 0 vertical rate to avoid arrow let altString; diff --git a/html/script.js b/html/script.js index e8e3429..9a3c641 100644 --- a/html/script.js +++ b/html/script.js @@ -58,8 +58,8 @@ let debugRoute = false; let trackLabels = false; let multiSelect = false; let uat_data = null; -let enableLabels = false; -let extendedLabels = 0; +g.enableLabels = false; +g.extendedLabels = 0; let mapIsVisible = true; let onlyMilitary = false; let onlySelected = false; @@ -152,8 +152,8 @@ let shareLink = ''; let CenterLat = 0; let CenterLon = 0; -let zoomLvl = 5; -let zoomLvlCache; +g.zoomLvl = 5; +g.zoomLvlCache; let TrackedAircraft = 0; let globeTrackedAircraft = 0; @@ -650,7 +650,7 @@ function fetchData(options) { return (globeIndexNow[x] - globeIndexNow[y]); }); - if (binCraft && onlyMilitary && zoomLvl < 5.5) { + if (binCraft && onlyMilitary && g.zoomLvl < 5.5) { ac_url.push('data/globeMil_42777' + suffix); } else { @@ -885,7 +885,7 @@ function earlyInitPage() { defaultOverlays.push('uka_shoreham'); MapType_tar1090 = 'carto_light_all'; lineWidth=4; - enableLabels=true; + g.enableLabels=true; } if (usp.has('debugFetch')) { debugFetch = true; @@ -1130,10 +1130,10 @@ function earlyInitPage() { toggleLabels(); } if (usp.has('extendedLabels')) { - extendedLabels = parseInt(usp.getFloat('extendedLabels')); + g.extendedLabels = parseInt(usp.getFloat('extendedLabels')); toggleExtendedLabels({ noIncrement: true }); } else if (loStore['extendedLabels']) { - extendedLabels = parseInt(loStore['extendedLabels']); + g.extendedLabels = parseInt(loStore['extendedLabels']); toggleExtendedLabels({ noIncrement: true }); } if (loStore['trackLabels'] == "true" || usp.has('trackLabels')) { @@ -2469,7 +2469,7 @@ function ol_map_init() { layers: layers_group, view: new ol.View({ center: ol.proj.fromLonLat([CenterLon, CenterLat]), - zoom: zoomLvl, + zoom: g.zoomLvl, multiWorld: true, }), controls: [new ol.control.Zoom({delta: 1, duration: 0, target: 'map_canvas',}), @@ -2716,8 +2716,8 @@ function initMap() { CenterLon = Number(loStore['CenterLon']) || DefaultCenterLon; CenterLat = Number(loStore['CenterLat']) || DefaultCenterLat; //console.log("initMap Centerlat: " + CenterLat); - zoomLvl = Number(loStore['zoomLvl']) || DefaultZoomLvl; - zoomLvlCache = zoomLvl; + g.zoomLvl = Number(loStore['zoomLvl']) || DefaultZoomLvl; + g.zoomLvlCache = g.zoomLvl; if (globeIndex && aggregator) { jQuery('#dump1090_total_history_td').hide(); @@ -4608,10 +4608,10 @@ function resetMap() { // Reset loStore values and map settings loStore['CenterLat'] = CenterLat loStore['CenterLon'] = CenterLon - //loStore['zoomLvl'] = zoomLvl = DefaultZoomLvl; + //loStore['zoomLvl'] = g.zoomLvl = DefaultZoomLvl; // Set and refresh - //OLMap.getView().setZoom(zoomLvl); + //OLMap.getView().setZoom(g.zoomLvl); //console.log('resetMap setting center ' + [CenterLat, CenterLon]); OLMap.getView().setCenter(ol.proj.fromLonLat([CenterLon, CenterLat])); @@ -5001,33 +5001,34 @@ function toggleTableInView(arg) { } function toggleLabels() { - enableLabels = !enableLabels; - loStore['enableLabels'] = enableLabels; + g.enableLabels = !g.enableLabels; + console.log(`${g.enableLabels} ${g.extendedLabels}`); + loStore['enableLabels'] = g.enableLabels; for (let key in g.planesOrdered) { g.planesOrdered[key].updateMarker(); } refreshFeatures(); - buttonActive('#L', enableLabels); + buttonActive('#L', g.enableLabels); if (showTrace) remakeTrails(); } function toggleExtendedLabels(options) { - if (isNaN(extendedLabels)) - extendedLabels = 0; + if (isNaN(g.extendedLabels)) + g.extendedLabels = 0; options = options || {}; if (!options.noIncrement) { - extendedLabels++; + g.extendedLabels++; } - extendedLabels %= 4; + g.extendedLabels %= 4; //console.log(extendedLabels); - loStore['extendedLabels'] = extendedLabels; + loStore['extendedLabels'] = g.extendedLabels; for (let key in g.planesOrdered) { g.planesOrdered[key].updateMarker(); } - buttonActive('#O', extendedLabels); + buttonActive('#O', g.extendedLabels); } function toggleTrackLabels() { @@ -5092,7 +5093,7 @@ function onJump(e) { console.log("jumping to: " + coords[0] + " " + coords[1]); OLMap.getView().setCenter(ol.proj.fromLonLat([coords[1], coords[0]])); - if (zoomLvl >= 7) { + if (g.zoomLvl >= 7) { fetchData({force: true}); } @@ -5523,16 +5524,16 @@ function changeZoom(init) { if (!OLMap) return; - zoomLvl = OLMap.getView().getZoom(); + g.zoomLvl = OLMap.getView().getZoom(); checkScale(); // small zoomstep, no need to change aircraft scaling - if (!init && Math.abs(zoomLvl-zoomLvlCache) < 0.4) + if (!init && Math.abs(g.zoomLvl-g.zoomLvlCache) < 0.4) return; - loStore['zoomLvl'] = zoomLvl; - zoomLvlCache = zoomLvl; + loStore['zoomLvl'] = g.zoomLvl; + g.zoomLvlCache = g.zoomLvl; if (!init && showTrace) updateAddressBar(); @@ -5541,9 +5542,9 @@ function changeZoom(init) { } function checkScale() { - if (zoomLvl > markerZoomDivide) { + if (g.zoomLvl > markerZoomDivide) { iconSize = markerBig; - } else if (zoomLvl > markerZoomDivide - 1) { + } else if (g.zoomLvl > markerZoomDivide - 1) { iconSize = markerSmall; } else { iconSize = markerSmall; @@ -5574,7 +5575,7 @@ function setGlobalScale(scale, init) { } function checkPointermove() { - if ((webgl || zoomLvl > 5.5) && enableMouseover && !onMobile) { + if ((webgl || g.zoomLvl > 5.5) && enableMouseover && !onMobile) { OLMap.on('pointermove', onPointermove); } else { OLMap.un('pointermove', onPointermove); @@ -5768,7 +5769,7 @@ function mapRefresh(redraw) { const plane = g.planesOrdered[i]; delete plane.glMarker; // disable mobile limitations when using webGL - if (plane.selected || (plane.inView && plane.visible && (!onMobile || webgl || (nMapPlanes < 150 && (!plane.onGround || zoomLvl > 10))))) { + if (plane.selected || (plane.inView && plane.visible && (!onMobile || webgl || (nMapPlanes < 150 && (!plane.onGround || g.zoomLvl > 10))))) { addToMap.push(plane); nMapPlanes++; } else { @@ -6285,7 +6286,7 @@ function updateAddressBar() { if (showTrace || replay) { string += (string ? '&' : '?'); - string += 'lat=' + CenterLat.toFixed(3) + '&lon=' + CenterLon.toFixed(3) + '&zoom=' + zoomLvl.toFixed(1); + string += 'lat=' + CenterLat.toFixed(3) + '&lon=' + CenterLon.toFixed(3) + '&zoom=' + g.zoomLvl.toFixed(1); } if (SelPlanes.length > 0 && (showTrace)) { @@ -6509,7 +6510,7 @@ function toggleShowTrace() { const plane = SelPlanes[i]; plane.setNull(); } - selectPlaneByHex(hex, {noDeselect: true, follow: true, zoom: zoomLvl,}); + selectPlaneByHex(hex, {noDeselect: true, follow: true, zoom: g.zoomLvl,}); if (replay) { replayStep(); } @@ -6649,7 +6650,7 @@ function shiftTrace(offset) { jQuery("#histDatePicker").datepicker('setDate', traceDateString); for (let i in SelPlanes) { - selectPlaneByHex(SelPlanes[i].icao, {noDeselect: true, zoom: zoomLvl}); + selectPlaneByHex(SelPlanes[i].icao, {noDeselect: true, zoom: g.zoomLvl}); } updateAddressBar(); @@ -7871,9 +7872,9 @@ function replayStep(arg) { i += 4; let ext; - if (zoomLvl > 10) { + if (g.zoomLvl > 10) { ext = currentExtent(1.6); - } else if (zoomLvl > 8) { + } else if (g.zoomLvl > 8) { ext = currentExtent(1.2); } else { ext = currentExtent(1.1);