From 9a33041ac4b0b5d5f38a46a7586be5c7efe5b6a8 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Thu, 3 Nov 2011 13:59:54 +0000 Subject: [PATCH] hide marker tooltip when map center changes; when hiding a tooltip, don't remove but detach it, so that when it is shown again, its oxid is still present on its dom element --- source/Ox.UI/js/Map/Ox.Map.js | 6 +++++- source/Ox.UI/js/Map/Ox.MapMarker.js | 23 ++++++++++++++--------- source/Ox.UI/js/Window/Ox.Tooltip.js | 6 +++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/source/Ox.UI/js/Map/Ox.Map.js b/source/Ox.UI/js/Map/Ox.Map.js index 38e66e50..78ed3530 100644 --- a/source/Ox.UI/js/Map/Ox.Map.js +++ b/source/Ox.UI/js/Map/Ox.Map.js @@ -526,6 +526,11 @@ Ox.Map = function(options, self) { } function centerChanged() { + var tooltip = $('.OxMapMarkerTooltip'); + if (tooltip.length) { + Ox.print('??', tooltip[0].className, $(tooltip[0]).data('oxid')); + Ox.UI.elements[$(tooltip[0]).data('oxid')].hide(); + } self.center = self.map.getCenter(); self.centerChanged = true; } @@ -867,7 +872,6 @@ Ox.Map = function(options, self) { function mapChanged() { // gets called after panning or zooming Ox.print('mapChanged'); - var bounds; if (self.boundsChanged) { var bounds = self.map.getBounds(), southWest = bounds.getSouthWest(), diff --git a/source/Ox.UI/js/Map/Ox.MapMarker.js b/source/Ox.UI/js/Map/Ox.MapMarker.js index 4386f301..1e4ebfae 100644 --- a/source/Ox.UI/js/Map/Ox.MapMarker.js +++ b/source/Ox.UI/js/Map/Ox.MapMarker.js @@ -187,7 +187,10 @@ Ox.MapMarker = function(options) { var offset = that.map.offset(), xy = that.map.overlayView.getProjection() .fromLatLngToContainerPixel(e.latLng); - that.tooltip.show(offset.left + xy.x - 4, offset.top + xy.y + 20); + that.tooltip.show( + offset.left + Math.round(xy.x) - 4, + offset.top + Math.round(xy.y) + 20 + ); } function mouseout() { @@ -234,15 +237,17 @@ Ox.MapMarker = function(options) { function setTooltip() { var country = Ox.getCountryByGeoname(that.place.geoname); + that.tooltip && that.tooltip.remove(); that.tooltip = Ox.Tooltip({ - title: '' - + '
' - + that.place.name - + (country && country.name != that.place.name ? ', ' + country.name : '') - + '
' - }); + title: '' + + '
' + + that.place.name + + (country && country.name != that.place.name ? ', ' + country.name : '') + + '
' + }) + .addClass('OxMapMarkerTooltip'); } /*@ diff --git a/source/Ox.UI/js/Window/Ox.Tooltip.js b/source/Ox.UI/js/Window/Ox.Tooltip.js index 9f20a539..46176516 100644 --- a/source/Ox.UI/js/Window/Ox.Tooltip.js +++ b/source/Ox.UI/js/Window/Ox.Tooltip.js @@ -37,10 +37,10 @@ Ox.Tooltip = function(options, self) { that.animate({ opacity: 0 }, 250, function() { - that.removeElement(); + that.detach(); }); } else { - that.removeElement(); + that.detach(); } } return that; @@ -58,7 +58,7 @@ Ox.Tooltip = function(options, self) { self.x = x; self.y = y } - $('.OxTooltip').remove(); // fixme: don't use DOM + $('.OxTooltip').detach(); // fixme: don't use DOM that.appendTo(Ox.UI.$body); width = that.width(); height = that.height();