fix problems with info box
error when removing plane, moving outside canvas, weird overlapping marker solution using extents
This commit is contained in:
parent
40614778bc
commit
a1a7d42e90
|
|
@ -1106,55 +1106,31 @@ function refreshHighlighted() {
|
||||||
highlighted = Planes[HighlightedPlane];
|
highlighted = Planes[HighlightedPlane];
|
||||||
}
|
}
|
||||||
|
|
||||||
// no highlighted plane
|
// no highlighted plane or in process of removing plane
|
||||||
if (!highlighted) {
|
if (!highlighted || !highlighted.marker) {
|
||||||
$('#highlighted_infoblock').hide();
|
$('#highlighted_infoblock').fadeOut();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#highlighted_infoblock').show();
|
|
||||||
|
|
||||||
// Get info box position and size
|
|
||||||
var infoBox = $('#highlighted_infoblock');
|
|
||||||
var infoBoxPosition = infoBox.position();
|
|
||||||
if (typeof infoBoxOriginalPosition.top === 'undefined') {
|
|
||||||
infoBoxOriginalPosition.top = infoBoxPosition.top;
|
|
||||||
infoBoxOriginalPosition.left = infoBoxPosition.left;
|
|
||||||
} else {
|
|
||||||
infoBox.css("left", infoBoxOriginalPosition.left);
|
|
||||||
infoBox.css("top", infoBoxOriginalPosition.top);
|
|
||||||
infoBoxPosition = infoBox.position();
|
|
||||||
}
|
|
||||||
var infoBoxExtent = getExtent(infoBoxPosition.left, infoBoxPosition.top, infoBox.outerWidth(), infoBox.outerHeight());
|
|
||||||
|
|
||||||
// Get map size
|
|
||||||
var mapCanvas = $('#map_canvas');
|
|
||||||
var mapExtent = getExtent(0, 0, mapCanvas.width(), mapCanvas.height());
|
|
||||||
|
|
||||||
var marker = highlighted.marker;
|
var marker = highlighted.marker;
|
||||||
|
var infoBox = $('#highlighted_infoblock');
|
||||||
|
var mapCanvas = $('#map_canvas');
|
||||||
|
|
||||||
|
infoBox.fadeIn(100);
|
||||||
|
|
||||||
var markerCoordinates = highlighted.marker.getGeometry().getCoordinates();
|
var markerCoordinates = highlighted.marker.getGeometry().getCoordinates();
|
||||||
var markerPosition = OLMap.getPixelFromCoordinate(markerCoordinates);
|
var markerPosition = OLMap.getPixelFromCoordinate(markerCoordinates);
|
||||||
|
var x = markerPosition[0] + 20;
|
||||||
// Check for overlap
|
var y = markerPosition[1] + 60;
|
||||||
//FIXME TODO: figure out this/remove this check
|
var w = infoBox.outerWidth() + 20;
|
||||||
if (isPointInsideExtent(markerPosition[0], markerPosition[1], infoBoxExtent) || true) {
|
var h = infoBox.outerHeight();
|
||||||
// Array of possible new positions for info box
|
if (x > mapCanvas.width() - w) {
|
||||||
var candidatePositions = [];
|
x -= w + 20;
|
||||||
candidatePositions.push( { x: 40, y: 80 } );
|
}
|
||||||
candidatePositions.push( { x: markerPosition[0] + 20, y: markerPosition[1] + 60 } );
|
if (y > mapCanvas.height() - h) {
|
||||||
|
y -= h;
|
||||||
// Find new position
|
}
|
||||||
for (var i = 0; i < candidatePositions.length; i++) {
|
infoBox.animate({ left: x, top: y }, 500);
|
||||||
var candidatePosition = candidatePositions[i];
|
|
||||||
var candidateExtent = getExtent(candidatePosition.x, candidatePosition.y, infoBox.outerWidth(), infoBox.outerHeight());
|
|
||||||
|
|
||||||
if (!isPointInsideExtent(markerPosition[0], markerPosition[1], candidateExtent) && isPointInsideExtent(candidatePosition.x, candidatePosition.y, mapExtent)) {
|
|
||||||
// Found a new position that doesn't overlap marker - move box to that position
|
|
||||||
infoBox.css("left", candidatePosition.x);
|
|
||||||
infoBox.css("top", candidatePosition.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (highlighted.flight !== null && highlighted.flight !== "") {
|
if (highlighted.flight !== null && highlighted.flight !== "") {
|
||||||
$('#highlighted_callsign').text(highlighted.flight);
|
$('#highlighted_callsign').text(highlighted.flight);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue