Leaflet.js: Popup outside map container - Javascript Leaflet

Javascript examples for Leaflet:Pop up

Description

Leaflet.js: Popup outside map container

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <link rel="stylesheet" type="text/css" href="https://npmcdn.com/leaflet@1.0.0-rc.2/dist/leaflet.css"> 
      <script type="text/javascript" src="https://npmcdn.com/leaflet@1.0.0-rc.2/dist/leaflet-src.js"></script> 
      <style id="compiled-css" type="text/css">

#map {/*w ww  . ja v a2 s.co m*/
   width: 200px;
   height: 200px;
   border: 1px solid black;
}
#mypopup {
   z-index: 1000;
   position: absolute;
   top: 0;
   left: 0;
   width: 150px;
   height: 20px;
   background-color: white;
   border: 1px solid black;
}


      </style> 
      <script type="text/javascript">
    window.onload=function(){
var map = L.map("map"),
   pos = [48.85, 2.35],
  marker = L.marker(pos),
  mapContainerPos = document.getElementById("map").getBoundingClientRect(),
  transform = L.DomUtil.setTransform,
  mypopup = document.getElementById("mypopup");
L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png").addTo(map);
map.setView(pos, 12);
map.addLayer(marker);
map.on("move", function () {
   movePopup();
});
movePopup();
function movePopup() {
   var mapContainerRelativePos = map.latLngToContainerPoint(pos),
   x = mapContainerPos.left + mapContainerRelativePos.x,
   y = mapContainerPos.top + mapContainerRelativePos.y;
  transform(mypopup, {x: x, y: y}, 1);
}
    }

      </script> 
   </head> 
   <body> 
      <div id="map"></div> 
      <div id="mypopup">
          My popup 
      </div>  
   </body>
</html>

Related Tutorials