I understand with the creation of components with joomla and ran into a problem.
The problem is as follows. Print labels on Yandex map through objectManager, therefore it is necessary to retrieve data from the site in JSON format.
To test did view.josn.php (in haste, then store it in the controller) The very conclusion: http://test.joomlazen.com/index.php?option=com_jz_location&view=ymap&format=json
Code:
class JZLocationViewYmap extends JViewLegacy {
public function getMapObject($data) {
$item = new stdClass();
$item->type = 'Feature';
$item->id = $data->id;
$item->geometry = new stdClass();
$item->geometry->type = 'Point';
$item->geometry->coordinates = '[55.831903,37.411961]';
$item->properties = new stdClass();
$item->properties->balloonContent = 'Content';
$item->properties->clusterCaption = 'Cluste';
$item->properties->hintContent = 'Hint';
return $item;
}
public function getMapFeatures() {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select('*')
->from($db->quoteName('#__k2_items','a'))
->group($db->quoteName('a.id'))
->order('a.id DESC')
;
$db->setQuery($query);
$rows = $db->loadObjectList();
if ($rows) {
foreach ($rows as $row) {
$main[] = $this->getMapObject($row);
}
return $main;
}
return false;
}
public function display($tpl = NULL) {
$app = JFactory::getApplication();
$app->setHeader('Content-Type', 'application/json; charset=utf-8');
$data = new stdClass();
$data->type = "FeatureCollection";
$data->features = $this->getMapFeatures();
echo json_encode($data);
}
And, accordingly, the output created for the convenience of a simple html (Example taken from the Sandbox on Yandex MAP) P.S the website made the Access-Control-Allow-Origin: "*"
<!DOCTYPE html>
<html>
<head>
<title>Примеры. Добавление на карту большо числа объектов</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Если вы используете API локально, то в URL ресурса необходимо указывать протокол в стандартном виде (http://...)-->
<script src="http://api-maps.yandex.ru/2.1/?lang=ru-RU" type="text/javascript"></script>
<script src="http://yandex.st/jquery/2.1.0/jquery.min.js" type="text/javascript"></script>
<script>
ymaps.ready(init);
function init () {
var myMap = new ymaps.Map('map', {
center: [55.831903,37.411961],
zoom: 10
}, {
searchControlProvider: 'yandex#search'
}),
objectManager = new ymaps.ObjectManager({
// Чтобы метки начали кластеризоваться, выставляем опцию.
clusterize: true,
// ObjectManager принимает те же опции, что и кластеризатор.
gridSize: 32
});
// Чтобы задать опции одиночным объектам и кластерам,
// обратимся к дочерним коллекциям ObjectManager.
objectManager.objects.options.set('preset', 'islands#greenDotIcon');
objectManager.clusters.options.set('preset', 'islands#greenClusterIcons');
myMap.geoObjects.add(objectManager);
$.ajax({
url: 'http://test.joomlazen.com/index.php?option=com_jz_location&view=ymap&format=json'
}).done(function(data) {
objectManager.add(data);
});
}</script>
<style>
html, body, #map {
width: 100%; height: 100%; padding: 0; margin: 0;
}
</style>
</head>
<body>
<div id="map"></div>
</body>
</html>
To be honest with Ajax and JSON is not very friendly. so please help to understand. Thanks in advance and sorry for my English using google translator
</div>