Hello, I understand the creation of components on joomla and ran into a problem.
The task is as follows. Display tags on the Yandex map through objectManager, therefore you need to receive data from the site in JSON format.
For testing, I made view.josn.php (in haste, then I’ll remove it to the controller) The very conclusion: http://test.joomlazen.com/index.php?option=com_jz_location&view=ymap&format=json
His 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, I created the output for convenience in a simple html (I took an example from the Sandbox on the site made 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> Honestly, I'm not very friendly with Ajax. so please help to understand. Thanks in advance