ymaps.ready(function () { var mapTypes = ['yandex#map', 'yandex#satellite', 'yandex#hybrid', 'yandex#publicMap', 'yandex#publicMapHybrid'], map = new ymaps.Map($('#map')[0], { center:[ parseFloat(<?= $request_lat?>), parseFloat(<?= $request_lng?>)], zoom:parseInt(<?= $request_zoom?>), type: mapTypes[<?= $request_mtype ? $request_mtype : 0?>] });
ymaps.layout.storage.add('voina#icon', ymaps.templateLayoutFactory.createClass( '<div style="position: absolute; width: 28px; height: 36px; overflow: hidden;z-index: 0; ">' + '<div style="position:absolute;width:20px;height:20px;overflow:hidden;top:4px;left:4px">' + '<img src="/img/new_buttons_21.png" style="position:absolute;left:$[properties.iconOffset]px;"></div>' + '<img src="/img/buttons7.gif" style="position: absolute; left: -264px; top: -70px; "></div>' ));
ymaps.layout.storage.add('voina#cluster', ymaps.templateLayoutFactory.createClass( '<div style="position: absolute; margin: -26px 0 0 -26px; width: 58px; height: 58px; overflow: hidden;z-index: 0; ">' + '<div style="z-index:800;position: absolute; width: 58px; height: 58px; text-align: center; font-size: 13px; line-height: 58px;">$[properties.geoObjects.length]</div>' + '<img src="/img/cluster_big.png" style="position: absolute;"></div>'));
var $container = map.panes.get('layers').getElement(),
stMapTypes = {'yandex#map' : 'map', 'yandex#satellite' : 'sat', 'yandex#hybrid' : 'sat,ski', 'yandex#publicMap' : 'pmap'}, center = map.getCenter(),
size = [650, 450],
mapUrl = 'http://static-maps.yandex.ru/1.x/?ll='+center[1]+','+center[0]+ '&z='+map.getZoom()+'&l='+stMapTypes[map.getType()]+ '&size='+size[0]+','+size[1];
$('<div></div>').css({ position: 'absolute', left: -Math.round(size[0] / 2)+'px', top: -Math.round(size[1] / 2)+'px', zIndex: 800}).
wrapInner($('<img>').attr({'src':mapUrl, width: size[0], height: size[1], border: '0'})).
prependTo($container);
map.events.removeAll();
var len = window.data.length; if (len) { for (var i = 0, markers = [ ], properties, latLng; i < len; i++) { latLng = [parseFloat(window.data[i][1]), parseFloat(window.data[i][2])]; markers.push( new ymaps.Placemark(latLng, { iconOffset: -window.data[i][5] * 20 - 1 }, { iconLayout:'voina#icon', iconOffset: [1, 2], openBalloonOnClick: false })); }
var clusterer = new ymaps.Clusterer({margin: [20]});
clusterer.options.set('clusterIconLayout', 'voina#cluster');
clusterer.createCluster = function (center, geoObjects) { var cluster = ymaps.Clusterer.prototype.createCluster.call(this, center, geoObjects); // cluster.events.add('click', function(e) { e.stopImmediatePropagation(); e.preventDefault(); return false; }); return cluster; };
clusterer.add(markers);
clusterer.events.removeAll();
map.geoObjects.add(clusterer); } });
Source: https://habr.com/ru/post/150061/
All Articles