mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-08-16 16:45:22 +00:00
Allow previously created popups to be used with bindPopup
This commit is contained in:
41
debug/tests/reuse_popups.html
Normal file
41
debug/tests/reuse_popups.html
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Leaflet debug page</title>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="../../dist/leaflet.css" />
|
||||||
|
<!--[if lte IE 8]><link rel="stylesheet" href="../../dist/leaflet.ie.css" /><![endif]-->
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="../css/screen.css" />
|
||||||
|
<script type="text/javascript" src="../../build/deps.js"></script>
|
||||||
|
<script src="../leaflet-include.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="map" style="width: 800px; height: 600px; border: 1px solid #ccc"></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var map = L.map('map');
|
||||||
|
|
||||||
|
var marker = L.marker([51.5, -0.09])
|
||||||
|
.bindPopup("<b>Hello world!</b><br />I am a popup.")
|
||||||
|
.addTo(map);
|
||||||
|
//.openPopup();
|
||||||
|
|
||||||
|
var marker2 = L.marker([51.525, -0.09])
|
||||||
|
.addTo(map);
|
||||||
|
|
||||||
|
map.setView([51.505, -0.09], 13);
|
||||||
|
|
||||||
|
var cloudmade = L.tileLayer('http://{s}.tile.cloudmade.com/{key}/{styleId}/256/{z}/{x}/{y}.png', {
|
||||||
|
attribution: 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade',
|
||||||
|
maxZoom: 18,
|
||||||
|
key: 'BC9A493B41014CAABB98F0471D759707',
|
||||||
|
styleId: 997
|
||||||
|
}).addTo(map);
|
||||||
|
|
||||||
|
var a_popup = L.popup().setContent('Previously created')
|
||||||
|
|
||||||
|
marker2.bindPopup(a_popup);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -37,8 +37,13 @@ L.Marker.include({
|
|||||||
.on('move', this._movePopup, this);
|
.on('move', this._movePopup, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._popup = new L.Popup(options, this)
|
if (content instanceof L.Popup) {
|
||||||
.setContent(content);
|
L.setOptions(content, options);
|
||||||
|
this._popup = content;
|
||||||
|
} else {
|
||||||
|
this._popup = new L.Popup(options, this)
|
||||||
|
.setContent(content);
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user