Answer the question
In order to leave comments, you need to log in
How to implement clustering in yandex.map bitrix?
Bitrix has a standard bitrix:map.yandex.view component, I have already put my icons there.
It remains to configure clustering.
I read this dev.1c-bitrix.ru/community/webdev/user/17090/blog/13131
But the previous version of the computer is used there. so it doesn't work for me.
The code shows that the new clustering component is enabled.
However, it is not clear how to enable it?
script.js ->
if (!window.BX_YMapAddPlacemark)
{
window.BX_YMapAddPlacemark = function(map, arPlacemark)
{
if (null == map)
return false;
if(!arPlacemark.LAT || !arPlacemark.LON)
return false;
var props = {};
if (null != arPlacemark.TEXT && arPlacemark.TEXT.length > 0)
{
var value_view = '';
if (arPlacemark.TEXT.length > 0)
{
var rnpos = arPlacemark.TEXT.indexOf("\n");
value_view = rnpos <= 0 ? arPlacemark.TEXT : arPlacemark.TEXT.substring(0, rnpos);
}
props.balloonContent = arPlacemark.TEXT.replace(/\n/g, '<br />');
props.hintContent = value_view;
}
var obPlacemark = new ymaps.Placemark(
[arPlacemark.LAT, arPlacemark.LON],
props,
{
balloonCloseButton: true,
iconImageHref:"/places/marker_sw_small.png"
}
);
map.geoObjects.add(obPlacemark);
return obPlacemark;
}
}
if (!window.BX_YMapAddPolyline)
{
window.BX_YMapAddPolyline = function(map, arPolyline)
{
if (null == map)
return false;
if (null != arPolyline.POINTS && arPolyline.POINTS.length > 1)
{
var arPoints = [];
for (var i = 0, len = arPolyline.POINTS.length; i < len; i++)
{
arPoints.push([arPolyline.POINTS[i].LAT, arPolyline.POINTS[i].LON]);
}
}
else
{
return false;
}
var obParams = {clickable: true};
if (null != arPolyline.STYLE)
{
obParams.strokeColor = arPolyline.STYLE.strokeColor;
obParams.strokeWidth = arPolyline.STYLE.strokeWidth;
}
var obPolyline = new ymaps.Polyline(
arPoints, {balloonContent: arPolyline.TITLE}, obParams
);
map.geoObjects.add(obPolyline);
return obPolyline;
}
}
<script type="text/javascript">
function BX_SetPlacemarks_<?echo $arParams['MAP_ID']?>(map)
{
<?if(count($arResult['POSITION']['PLACEMARKS'])>1):?>
//clusterer = new ymaps.Clusterer();
//clusterer.add(arObjects.PLACEMARKS);
//map.geoObjects.add(clusterer);
<?endif;?>
if(typeof window["BX_YMapAddPlacemark"] != 'function')
{
/* If component's result was cached as html,
* script.js will not been loaded next time.
* let's do it manualy.
*/
(function(d, s, id)
{
var js, bx_ym = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "<?=$templateFolder.'/script.js'?>";
bx_ym.parentNode.insertBefore(js, bx_ym);
}(document, 'script', 'bx-ya-map-js'));
var ymWaitIntervalId = setInterval( function(){
if(typeof window["BX_YMapAddPlacemark"] == 'function')
{
BX_SetPlacemarks_<?echo $arParams['MAP_ID']?>(map);
clearInterval(ymWaitIntervalId);
}
}, 300
);
return;
}
var arObjects = {PLACEMARKS:[],POLYLINES:[]};
<?
if (is_array($arResult['POSITION']['PLACEMARKS']) && ($cnt = count($arResult['POSITION']['PLACEMARKS']))):
for($i = 0; $i < $cnt; $i++):
?>
arObjects.PLACEMARKS[arObjects.PLACEMARKS.length] = BX_YMapAddPlacemark(map, <?echo CUtil::PhpToJsObject($arResult['POSITION']['PLACEMARKS'][$i])?>);
<?
endfor;
endif;
if (is_array($arResult['POSITION']['POLYLINES']) && ($cnt = count($arResult['POSITION']['POLYLINES']))):
for($i = 0; $i < $cnt; $i++):
?>
arObjects.POLYLINES[arObjects.POLYLINES.length] = BX_YMapAddPolyline(map, <?echo CUtil::PhpToJsObject($arResult['POSITION']['POLYLINES'][$i])?>);
<?
endfor;
endif;
if ($arParams['ONMAPREADY']):
?>
if (window.<?echo $arParams['ONMAPREADY']?>)
{
window.<?echo $arParams['ONMAPREADY']?>(map, arObjects);
}
<?
endif;
?>
}
</script>
Answer the question
In order to leave comments, you need to log in
After carefully digging into this solution dev.1c-bitrix.ru/community/webdev/user/17090/blog/13131, everything worked fine.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question