Guest User

Untitled

a guest
Oct 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. var getPointData = function (index) {
  2. return {
  3. balloonContentBody: 'балун <strong>метки ' + index + '</strong>',
  4. clusterCaption: 'метка <strong>' + index + '</strong>'
  5. };
  6. }
  7.  
  8. ymaps.ready(function () {
  9. var myMap = new ymaps.Map('map', {
  10. center: [48.548043,66.904544],
  11. zoom: 15
  12. }, {
  13. searchControlProvider: 'yandex#search'
  14. }),
  15. clusterer = new ymaps.Clusterer({
  16. preset: 'islands#invertedVioletClusterIcons',
  17. clusterHideIconOnBalloonOpen: false,
  18. geoObjectHideIconOnBalloonOpen: false
  19. });
  20.  
  21. /**
  22. * Кластеризатор расширяет коллекцию, что позволяет использовать один обработчик
  23. * для обработки событий всех геообъектов.
  24. * Меняю цвет иконок и кластеров при наведении.
  25. */
  26. clusterer.events
  27. // Слушаю сразу несколько событий, указывая их имена в массиве.
  28. .add(['mouseenter', 'mouseleave'], function (e) {
  29. var target = e.get('target'),
  30. type = e.get('type');
  31. if (typeof target.getGeoObjects != 'undefined') {
  32. // Событие произошло на кластере.
  33. if (type == 'mouseenter') {
  34. target.options.set('preset', 'islands#invertedPinkClusterIcons');
  35. } else {
  36. target.options.set('preset', 'islands#invertedVioletClusterIcons');
  37. }
  38. } else {
  39. // Событие произошло на геообъекте.
  40. if (type == 'mouseenter') {
  41. target.options.set('preset', 'islands#pinkIcon');
  42. } else {
  43. target.options.set('preset', 'islands#violetIcon');
  44. }
  45. }
  46. });
  47.  
  48.  
  49. var getPointData = function (index) {
  50. return {
  51. balloonContentBody: 'балун <strong>метки ' + index + '</strong>',
  52. clusterCaption: 'метка <strong>' + index + '</strong>'
  53. };
  54. },
  55. getPointOptions = function () {
  56. return {
  57. preset: 'islands#violetIcon'
  58. };
  59. },
  60. points = [
  61.  
  62. @foreach($objects as $object)
  63. [
  64. {{ $object->latitude.','.$object->longitude }}
  65. ],
  66. @endforeach
  67.  
  68. ],
  69. geoObjects = [];
  70.  
  71. for(var i = 0, len = points.length; i < len; i++) {
  72. geoObjects[i] = new ymaps.Placemark(points[i], getPointData(i), getPointOptions());
  73. }
  74.  
  75. clusterer.add(geoObjects);
  76. myMap.geoObjects.add(clusterer);
  77.  
  78. myMap.setBounds(clusterer.getBounds(), {
  79. checkZoomRange: true
  80. });
  81. });
  82.  
  83. [
  84. ['latitude,longitude'], // координаты 1
  85. ['latitude,longitude'] // координаты 2
  86. ...
  87. ]
  88.  
  89. @foreach($objects as $object)
  90. {
  91. balloonContentBody: {{ $object->balloonContentBody }}
  92. clusterCaption: {{ $object->clusterCaption }},
  93. coordinates: '{{ $object->latitude.','.$object->longitude }}'
  94. },
  95. @endforeach
  96.  
  97. for(var i = 0, len = points.length; i < len; i++) {
  98. geoObjects[i] = new ymaps.Placemark(points[i], getPointData(i), getPointOptions());
  99. }
  100.  
  101. for(var i = 0, len = points.length; i < len; i++) {
  102. geoObjects[i] = new ymaps.Placemark(
  103. points[i].coordinates,
  104. getPointData(points[i].balloonContentBody, points[i].clusterCaption),
  105. getPointOptions()
  106. );
  107. }
  108.  
  109. var getPointData = function (balloonContentBody, clusterCaption) {
  110. return {
  111. balloonContentBody: 'балун <strong>метки ' + balloonContentBody + '</strong>',
  112. clusterCaption: 'метка <strong>' + clusterCaption + '</strong>'
  113. };
  114. },
Add Comment
Please, Sign In to add comment