From 28e9a84da2d035fb5396e3a3deb80f416ab12706 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 23 Aug 2007 14:49:42 +0000 Subject: [PATCH] Fix automatic size detection for map popups. --- app/views/user/account.rhtml | 5 +---- public/javascripts/map.js | 31 +++++++++++++++++++++++-------- public/stylesheets/site.css | 24 ++++-------------------- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/app/views/user/account.rhtml b/app/views/user/account.rhtml index 99253471d..f405e0b3c 100644 --- a/app/views/user/account.rhtml +++ b/app/views/user/account.rhtml @@ -14,10 +14,7 @@

Update home location when I click on the map? checked="checked" <% end %> id="updatehome" />

-
- <% # This now just used to detect the width/height required for the popup. %> -

-
+
<%= submit_tag 'Save Changes' %> diff --git a/public/javascripts/map.js b/public/javascripts/map.js index 4816f762b..2f7d52e58 100644 --- a/public/javascripts/map.js +++ b/public/javascripts/map.js @@ -73,17 +73,11 @@ function addMarkerToMap(position, icon, description) { } function openMapPopup(marker, description) { -// var box = document.createElement("div"); -// box.innerHTML = description; -// box.style.display = 'none'; -// box.style.width = "200px"; -// document.body.appendChild(box); - closeMapPopup(); popup = new OpenLayers.Popup.AnchoredBubble("popup", marker.lonlat, - new OpenLayers.Size(200, 50), - "

" + description + "

", + sizeMapPopup(description), + "

" + description + "

", marker.icon, true); popup.setBackgroundColor("#E3FFC5"); map.addPopup(popup); @@ -98,6 +92,27 @@ function closeMapPopup() { } } +function sizeMapPopup(text) { + var box = document.createElement("div"); + + box.innerHTML = text; + box.style.visibility = "hidden"; + box.style.position = "absolute"; + box.style.top = "0px"; + box.style.left = "0px"; + box.style.width = "200px"; + box.style.height = "auto"; + + document.body.appendChild(box); + + var width = box.offsetWidth; + var height = box.offsetHeight; + + document.body.removeChild(box); + + return new OpenLayers.Size(width + 30, height + 24); +} + function removeMarkerFromMap(marker){ markers.removeMarker(marker); } diff --git a/public/stylesheets/site.css b/public/stylesheets/site.css index 2579e8a27..feb32318f 100644 --- a/public/stylesheets/site.css +++ b/public/stylesheets/site.css @@ -529,26 +529,10 @@ input { white-space: nowrap; } -/** - * This now just used to detect the width/height required for the popup. - */ -#map p#highlightinfo { - visibility : hidden; - position : absolute; - z-index : 10000; - background : white; - border : 1px solid black; - left : 50px; - top : 5px; - margin : 0px; - padding : 2px; -} - -#map p#highlightinfo p, #popup p { - margin : 0; - padding : 2px; - } - +#map #popup p { + margin : 0; + padding : 2px; +} /**State of the Map */ -- 2.43.2