mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Show tooltips automatically based on zoom level.
This commit is contained in:
parent
d884645f37
commit
eb26d54ac1
@ -117,10 +117,16 @@ function iconFor(player) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SHOW_BASE_NAME_AT_ZOOM = 8;
|
||||||
|
|
||||||
function drawControlPoints() {
|
function drawControlPoints() {
|
||||||
controlPointsLayer.clearLayers();
|
controlPointsLayer.clearLayers();
|
||||||
|
var zoom = map.getZoom();
|
||||||
game.controlPoints.forEach((cp) => {
|
game.controlPoints.forEach((cp) => {
|
||||||
L.marker(cp.position, { icon: iconFor(cp.blue) })
|
L.marker(cp.position, { icon: iconFor(cp.blue) })
|
||||||
|
.bindTooltip(`<h3 style="margin: 0;">${cp.name}</h3>`, {
|
||||||
|
permanent: zoom >= SHOW_BASE_NAME_AT_ZOOM,
|
||||||
|
})
|
||||||
.on("click", function () {
|
.on("click", function () {
|
||||||
cp.open_base_menu();
|
cp.open_base_menu();
|
||||||
})
|
})
|
||||||
@ -174,6 +180,8 @@ function drawSupplyRoutes() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SHOW_WAYPOINT_INFO_AT_ZOOM = 9;
|
||||||
|
|
||||||
function drawFlightPlan(flight) {
|
function drawFlightPlan(flight) {
|
||||||
var layer = flight.blue ? blueFlightPlansLayer : redFlightPlansLayer;
|
var layer = flight.blue ? blueFlightPlansLayer : redFlightPlansLayer;
|
||||||
var color = flight.blue ? Colors.Blue : Colors.Red;
|
var color = flight.blue ? Colors.Blue : Colors.Red;
|
||||||
@ -182,6 +190,7 @@ function drawFlightPlan(flight) {
|
|||||||
// coincident with the landing waypoint, so hard to see). We do want to draw
|
// coincident with the landing waypoint, so hard to see). We do want to draw
|
||||||
// the path from it though.
|
// the path from it though.
|
||||||
var points = [flight.flightPlan[0].position];
|
var points = [flight.flightPlan[0].position];
|
||||||
|
var zoom = map.getZoom();
|
||||||
flight.flightPlan.slice(1).forEach((waypoint) => {
|
flight.flightPlan.slice(1).forEach((waypoint) => {
|
||||||
if (!waypoint.isDivert) {
|
if (!waypoint.isDivert) {
|
||||||
points.push(waypoint.position);
|
points.push(waypoint.position);
|
||||||
@ -193,7 +202,7 @@ function drawFlightPlan(flight) {
|
|||||||
`${waypoint.number} ${waypoint.name}<br />` +
|
`${waypoint.number} ${waypoint.name}<br />` +
|
||||||
`${waypoint.altitudeFt} ft ${waypoint.altitudeReference}<br />` +
|
`${waypoint.altitudeFt} ft ${waypoint.altitudeReference}<br />` +
|
||||||
`${waypoint.timing}`,
|
`${waypoint.timing}`,
|
||||||
{ permanent: true }
|
{ permanent: zoom >= SHOW_WAYPOINT_INFO_AT_ZOOM }
|
||||||
)
|
)
|
||||||
.addTo(layer)
|
.addTo(layer)
|
||||||
.addTo(selectedFlightPlansLayer);
|
.addTo(selectedFlightPlansLayer);
|
||||||
@ -244,3 +253,34 @@ function clearAllLayers() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setTooltipZoomThreshold(layerGroup, showAt) {
|
||||||
|
var showing = map.getZoom() >= showAt;
|
||||||
|
map.on("zoomend", function () {
|
||||||
|
var zoom = map.getZoom();
|
||||||
|
if (zoom < showAt && showing) {
|
||||||
|
showing = false;
|
||||||
|
layerGroup.eachLayer(function (layer) {
|
||||||
|
if (layer.getTooltip()) {
|
||||||
|
var tooltip = layer.getTooltip();
|
||||||
|
layer.unbindTooltip().bindTooltip(tooltip, {
|
||||||
|
permanent: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (zoom >= showAt && !showing) {
|
||||||
|
showing = true;
|
||||||
|
layerGroup.eachLayer(function (layer) {
|
||||||
|
if (layer.getTooltip()) {
|
||||||
|
var tooltip = layer.getTooltip();
|
||||||
|
layer.unbindTooltip().bindTooltip(tooltip, {
|
||||||
|
permanent: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setTooltipZoomThreshold(controlPointsLayer, SHOW_BASE_NAME_AT_ZOOM);
|
||||||
|
setTooltipZoomThreshold(selectedFlightPlansLayer, SHOW_WAYPOINT_INFO_AT_ZOOM);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user