diff --git a/ground/controllers/JsonController.php b/ground/controllers/JsonController.php index a0d232e..2dbacac 100644 --- a/ground/controllers/JsonController.php +++ b/ground/controllers/JsonController.php @@ -10,17 +10,22 @@ class JsonController extends Controller { $points = new Point(); $points = $points->getAll(); - + $categories = new Category(); $categories = $categories->getAll(); - - foreach ($points as &$point) { - $point['categoryIcon'] = $categories[$point['categoryId']]['icon']; - $point['categoryName'] = $categories[$point['categoryId']]['name']; + + $result = array(); + + foreach ($points as $point) { + $result[$point['id']]['id'] = $point['id']; + $result[$point['id']]['name'] = $point['name']; + $result[$point['id']]['lat'] = $point['lat']; + $result[$point['id']]['lng'] = $point['lng']; + $result[$point['id']]['categoryIcon'] = $categories[$point['categoryId']]['icon']; } - + self::renderPartial('json.php', array( - 'data' => $points, + 'data' => $result, )); } diff --git a/public/css/style.css b/public/css/style.css index a8c26cb..4a0d295 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -9,7 +9,7 @@ html {height: 100%;} body {margin: 0; padding: 0; height: 100%;} div#map {width: 100%; position: absolute; top: 0; bottom: 50px;} -div.infoCard {width: 400px;} +div.infoCard h3 {text-align: center; margin-top: 0;} div.infoCard img {width: 200px; float: left; margin: 0 10px 5px 0;} div.header {display: block; position: absolute; top: 0; left: 110px; border-radius: 0 0 5px 5px; z-index: 1000; background-color: #FFF; padding: 5px 10px;} div.header h1 {display: inline; color: #333;} diff --git a/public/js/main.js b/public/js/main.js index 9f9e6a6..a389e28 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -5,6 +5,7 @@ ymaps.ready(init); var myMap; var categories; +var points = Array(); function init() { myMap = new ymaps.Map("map", { @@ -43,18 +44,22 @@ function getPoints() url: "/json/points/", success: function(data){ for(var k in data) { - myPlacemark = new ymaps.Placemark( + id = data[k]['id']; + points[id] = new ymaps.Placemark( [data[k]['lat'], data[k]['lng']], { hintContent: data[k]['name'], - balloonContent: - '
' + - '' + - '

'+data[k]['name']+'

' + - data[k]['description'] + - ' Подробнее...
' - },{iconImageHref: data[k]['categoryIcon'], iconImageSize: [32, 37]}); + id: id + },{ + iconImageHref: data[k]['categoryIcon'], + iconImageSize: [32, 37], + openEmptyBalloon: true, + balloonCloseButton: false + }); - myMap.geoObjects.add(myPlacemark); + points[id].events.add('click', function (e) { + showInfo(e.get('target').properties.get('id')); + }); + myMap.geoObjects.add(points[id]); } } }); @@ -62,6 +67,26 @@ function getPoints() return true; } +function showInfo(id) +{ + if (!(id in points) || points[id].properties.get('balloonContent') == undefined) + { + points[id].properties.set('balloonContent', 'Загрузка...'); + $.ajax({ + url: "/json/point/id/" + id, + success: function(data) { + description = '
' + + '

' + data.name + '

' + + '' + + data.description + + ' Подробнее...
' + points[id].properties.set('balloonContent', description); + } + }); + } + return true; +} + function initCategories() { $.ajax({