Добавлена карта + вывод точек на неё
This commit is contained in:
parent
ce24c29882
commit
9c20aad4b6
|
|
@ -4,8 +4,27 @@ abstract class Controller
|
|||
{
|
||||
|
||||
static $layout = 'layout.php';
|
||||
static private $styles = array();
|
||||
static private $scripts = array();
|
||||
|
||||
static function renderPartial($template, $data, $return = false)
|
||||
|
||||
static function addStyle($name)
|
||||
{
|
||||
if (array_search($name, self::$styles) === FALSE )
|
||||
{
|
||||
self::$styles[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
static function addScript($name)
|
||||
{
|
||||
if (array_search($name, self::$scripts) === FALSE )
|
||||
{
|
||||
self::$scripts[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
static function renderPartial($template, $data, $return = false)
|
||||
{
|
||||
if (!file_exists(App::getBasedir() . 'views/' . $template))
|
||||
return 'Template not found';
|
||||
|
|
@ -31,7 +50,12 @@ abstract class Controller
|
|||
static function render($template, $data, $return = false)
|
||||
{
|
||||
$content = self::renderPartial($template, $data, true);
|
||||
$result = self::renderPartial(self::$layout, array('content' => $content), true);
|
||||
|
||||
$result = self::renderPartial(self::$layout, array(
|
||||
'content' => $content,
|
||||
'styles' => self::$styles,
|
||||
'scripts' => self::$scripts,
|
||||
), true);
|
||||
|
||||
if ($return)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,6 +8,11 @@ class IndexController extends Controller
|
|||
*/
|
||||
static function actionIndex()
|
||||
{
|
||||
self::addScript('/js/jquery-2.1.0.min.js');
|
||||
self::addScript('http://api-maps.yandex.ru/2.0-stable/?load=package.standard&lang=ru-RU&mode=release');
|
||||
self::addScript('/js/main.js');
|
||||
self::addStyle('/css/style.css');
|
||||
|
||||
$category = new Category();
|
||||
|
||||
self::render('indexTemplate.php', array(
|
||||
|
|
|
|||
|
|
@ -1,6 +1 @@
|
|||
Категории точек:
|
||||
<ul>
|
||||
<?php foreach ($category as $val): ?>
|
||||
<li><img src="<?=$val['icon']?>" /> #<?=$val['id']?> - <?=$val['name']?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<div id="map"></div>
|
||||
|
|
@ -1,6 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title><?=App::getConfig('title')?></title>
|
||||
|
||||
<?php if ($styles): ?>
|
||||
<?php foreach ($styles as $style): ?>
|
||||
<link href="<?= $style ?>" media="all" rel="stylesheet" type="text/css" />
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($scripts): ?>
|
||||
<?php foreach ($scripts as $script): ?>
|
||||
<script src="<?= $script ?>" type="text/javascript"></script>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1><?=App::getConfig('title')?></h1>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
Document : style
|
||||
Created on : 03.04.2014, 10:51:45
|
||||
Author : all4dk
|
||||
Description:
|
||||
Purpose of the stylesheet follows.
|
||||
*/
|
||||
|
||||
html {height: 100%;}
|
||||
body {margin: 0; padding: 0; height: 100%;}
|
||||
div#map {width: 100%; height: 100%;}
|
||||
div.infoCard {width: 400px;}
|
||||
div.infoCard img {width: 200px; float: left; margin: 0 10px 5px 0;}
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
ymaps.ready(init);
|
||||
var myMap;
|
||||
|
||||
function init() {
|
||||
myMap = new ymaps.Map("map", {
|
||||
center: [59.9, 30.3],
|
||||
zoom: 11,
|
||||
behaviors: ['default', 'scrollZoom']
|
||||
});
|
||||
|
||||
myMap.controls.add('mapTools');
|
||||
myMap.controls.add('typeSelector');
|
||||
myMap.controls.add('smallZoomControl');
|
||||
myMap.controls.add('scaleLine');
|
||||
|
||||
// myPlacemark = new ymaps.Placemark([59.977822,30.283677], {
|
||||
// hintContent: 'Дом Ирен Адлер',
|
||||
// balloonContent: '<div class="infoCard"><img src="http://www.blog-fiesta.com/uploads/slider_image/image/15162/v800_1289474719dacha_gaus.jpg" /><h3>Дом Ирен Адлер</h3> Дача Гаусвальд - редкий, даже по мировым меркам, пример деревянного здания в стиле модерн. Построенное для жены знаменитого булочного мастера в конце XIX века, в XXI столетии оно медленно разрушается из-за банального грибка. <a href="http://www.blog-fiesta.com/sights/dacha-gausvald/">Подробнее...</a></div>'
|
||||
// });
|
||||
// myMap.geoObjects.add(myPlacemark);
|
||||
|
||||
getPoints();
|
||||
|
||||
myMap.events.add('click', function (e) {
|
||||
if (!myMap.balloon.isOpen()) {
|
||||
var coords = e.get('coordPosition');
|
||||
myMap.balloon.open(coords, {
|
||||
contentHeader:'Событие!',
|
||||
contentBody:'<p>Кто-то щелкнул по карте.</p>' +
|
||||
'<p>Координаты щелчка: ' + [
|
||||
coords[0].toPrecision(6),
|
||||
coords[1].toPrecision(6)
|
||||
].join(', ') + '</p>',
|
||||
contentFooter:'<sup>Щелкните еще раз</sup>'
|
||||
});
|
||||
}
|
||||
else {
|
||||
myMap.balloon.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getPoints()
|
||||
{
|
||||
$.ajax({
|
||||
url: "/json/points/",
|
||||
success: function(data){
|
||||
for(var k in data) {
|
||||
myPlacemark = new ymaps.Placemark(
|
||||
[data[k]['lat'], data[k]['lng']], {
|
||||
hintContent: data[k]['name'],
|
||||
balloonContent:
|
||||
'<div class="infoCard">' +
|
||||
'<img src="'+data[k]['img']+'" />' +
|
||||
'<h3>'+data[k]['name']+'</h3>' +
|
||||
data[k]['description'] +
|
||||
' <a href="'+data[k]['source']+'" target="blank">Подробнее...</a></div>'
|
||||
});
|
||||
myMap.geoObjects.add(myPlacemark);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
Loading…
Reference in New Issue