]> git.openstreetmap.org Git - rails.git/commitdiff
Fix automatic size detection for map popups.
authorTom Hughes <tom@compton.nu>
Thu, 23 Aug 2007 14:49:42 +0000 (14:49 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 23 Aug 2007 14:49:42 +0000 (14:49 +0000)
app/views/user/account.rhtml
public/javascripts/map.js
public/stylesheets/site.css

index 99253471d1f38b7ee0efac428d776563f1badb7e..f405e0b3cf5d0a09bb9ecb2e659980b3f58b6d40 100644 (file)
 
   <tr><td></td><td>
   <p>Update home location when I click on the map? <input type="checkbox" value="1" <% unless @user.home_lat and @user.home_lon %> checked="checked" <% end %> id="updatehome" /> </p>
-  <div id="map" style="border: 1px solid black; position: relative; width : 90%; height : 300px;">
-    <% # This now just used to detect the width/height required for the popup. %>
-    <p id="highlightinfo"></p>
-  </div>
+  <div id="map" style="border: 1px solid black; position: relative; width : 90%; height : 300px;"></div>
   </td></tr>
 </table>
 <%= submit_tag 'Save Changes' %>
index 4816f762bdf2e2ad4e297838afd6c97c28c36c51..2f7d52e589b380ee99eb24b62a2e02484e04b38f 100644 (file)
@@ -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),
-                                               "<p>" + description + "</p>",
+                                               sizeMapPopup(description),
+                                               "<p style='padding-right: 28px'>" + description + "</p>",
                                                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);
 }
index 2579e8a27a40b355e0c4f0db0d8eb7373447a1b4..feb32318f962ac8da5172883b536f8a1e10dcff0 100644 (file)
@@ -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 */