Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var getPointData = function (index) {
- return {
- balloonContentBody: 'балун <strong>метки ' + index + '</strong>',
- clusterCaption: 'метка <strong>' + index + '</strong>'
- };
- }
- ymaps.ready(function () {
- var myMap = new ymaps.Map('map', {
- center: [48.548043,66.904544],
- zoom: 15
- }, {
- searchControlProvider: 'yandex#search'
- }),
- clusterer = new ymaps.Clusterer({
- preset: 'islands#invertedVioletClusterIcons',
- clusterHideIconOnBalloonOpen: false,
- geoObjectHideIconOnBalloonOpen: false
- });
- /**
- * Кластеризатор расширяет коллекцию, что позволяет использовать один обработчик
- * для обработки событий всех геообъектов.
- * Меняю цвет иконок и кластеров при наведении.
- */
- clusterer.events
- // Слушаю сразу несколько событий, указывая их имена в массиве.
- .add(['mouseenter', 'mouseleave'], function (e) {
- var target = e.get('target'),
- type = e.get('type');
- if (typeof target.getGeoObjects != 'undefined') {
- // Событие произошло на кластере.
- if (type == 'mouseenter') {
- target.options.set('preset', 'islands#invertedPinkClusterIcons');
- } else {
- target.options.set('preset', 'islands#invertedVioletClusterIcons');
- }
- } else {
- // Событие произошло на геообъекте.
- if (type == 'mouseenter') {
- target.options.set('preset', 'islands#pinkIcon');
- } else {
- target.options.set('preset', 'islands#violetIcon');
- }
- }
- });
- var getPointData = function (index) {
- return {
- balloonContentBody: 'балун <strong>метки ' + index + '</strong>',
- clusterCaption: 'метка <strong>' + index + '</strong>'
- };
- },
- getPointOptions = function () {
- return {
- preset: 'islands#violetIcon'
- };
- },
- points = [
- @foreach($objects as $object)
- [
- {{ $object->latitude.','.$object->longitude }}
- ],
- @endforeach
- ],
- geoObjects = [];
- for(var i = 0, len = points.length; i < len; i++) {
- geoObjects[i] = new ymaps.Placemark(points[i], getPointData(i), getPointOptions());
- }
- clusterer.add(geoObjects);
- myMap.geoObjects.add(clusterer);
- myMap.setBounds(clusterer.getBounds(), {
- checkZoomRange: true
- });
- });
- [
- ['latitude,longitude'], // координаты 1
- ['latitude,longitude'] // координаты 2
- ...
- ]
- @foreach($objects as $object)
- {
- balloonContentBody: {{ $object->balloonContentBody }}
- clusterCaption: {{ $object->clusterCaption }},
- coordinates: '{{ $object->latitude.','.$object->longitude }}'
- },
- @endforeach
- for(var i = 0, len = points.length; i < len; i++) {
- geoObjects[i] = new ymaps.Placemark(points[i], getPointData(i), getPointOptions());
- }
- for(var i = 0, len = points.length; i < len; i++) {
- geoObjects[i] = new ymaps.Placemark(
- points[i].coordinates,
- getPointData(points[i].balloonContentBody, points[i].clusterCaption),
- getPointOptions()
- );
- }
- var getPointData = function (balloonContentBody, clusterCaption) {
- return {
- balloonContentBody: 'балун <strong>метки ' + balloonContentBody + '</strong>',
- clusterCaption: 'метка <strong>' + clusterCaption + '</strong>'
- };
- },
Add Comment
Please, Sign In to add comment