Created
August 28, 2013 06:52
-
-
Save just-boris/6362862 to your computer and use it in GitHub Desktop.
for discussion http://clubs.ya.ru/mapsapi/replies.xml?item_no=42144
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Не открывается балун</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<script src="//api-maps.yandex.ru/2.0/?load=package.standard,package.clusters&lang=ru-RU" type="text/javascript"></script> | |
<script type="text/javascript"> | |
var markers = [], clusterer; | |
ymaps.ready(init); | |
function init () { | |
var myMap = new ymaps.Map("map", { | |
center: [54.83, 37.11], | |
behaviors: ['default', 'scrollZoom'], | |
zoom: 5 | |
}); | |
myMap.controls.add('zoomControl', { left: 5, top: 10 }); | |
function generateMarkers(tlCorner, brCorner, count) { | |
var deltaLat = tlCorner[0] - brCorner[0], | |
deltaLon = brCorner[1] - tlCorner[1], | |
markers = []; | |
for(var i = 0; i < count; i++) { | |
var lat = brCorner[0] + Math.random()*deltaLat, | |
lon = tlCorner[1] + Math.random()*deltaLon; | |
markers.push([lat, lon]); | |
} | |
return markers; | |
} | |
clusterer = new ymaps.Clusterer({clusterDisableClickZoom: true}); | |
//markers= new ymaps.GeoObjectCollection(); | |
[[54.51,35.90],[55.77,37.49],[55.00,37.76],[53.87,37.08],[55.11,37.18],[57.10,39.83],[56.88,37.11],[53.87,38.81],[56.63,39.02],[54.75,36.36]].forEach(function(coords, index) { | |
var myPlacemark = new ymaps.Placemark(coords, {index: index+1, balloonContent: coords.toString(), balloonContentHeader: 'Метка ' + (index+1)}); | |
clusterer.add(myPlacemark); | |
markers.push(myPlacemark); | |
}); | |
myMap.geoObjects.add(clusterer); | |
} | |
//открыть балун с меткой по индексу | |
function openBalloon(index) { | |
var iterator = clusterer.getIterator(), | |
checkAndOpen = function(object) { | |
if(object.properties.get('index') === index) { | |
marker.state.set('activeObject', object); | |
marker.balloon.open(); | |
} | |
}, | |
marker; | |
while(marker = iterator.getNext()) { | |
if(marker instanceof ymaps.Placemark) { | |
checkAndOpen(marker); | |
} | |
else { | |
marker.properties.getAll().geoObjects.forEach(checkAndOpen); | |
} | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<div id="map" style="width:400px; height:300px"></div> | |
<button onclick="openBalloon(8);">Открыть балун c меткой №8</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment