Множественые изменения в форматировани и добален функционал добавления В ИЗБРАННОЕ
This commit is contained in:
parent
0f97e00cfe
commit
2a253676b4
|
|
@ -165,7 +165,7 @@ abstract class Model
|
|||
$ready[$row[$this->_primaryKey_]] = isset($params['asArray'])&&$params['asArray'] ? $row : new $calledClass($row);
|
||||
}
|
||||
|
||||
return $ready;
|
||||
return (isset($params['limit'])&&$params['limit']==1) ? array_shift($ready) : $ready;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -45,7 +45,12 @@ class IndexController extends Controller
|
|||
if (App::$user && App::$user->id)
|
||||
{
|
||||
$routes = Route::model()->getByAuthor(App::$user->id);
|
||||
}
|
||||
self::addVar('user', App::$user->id);
|
||||
}
|
||||
else
|
||||
{
|
||||
self::addVar('user', '0');
|
||||
}
|
||||
|
||||
self::addVar('isAdmin', (int)(App::$user && App::$user->isAdmin == 1) );
|
||||
|
||||
|
|
@ -152,4 +157,10 @@ class IndexController extends Controller
|
|||
print($xml->asXML());
|
||||
}
|
||||
|
||||
static function actionTest()
|
||||
{
|
||||
|
||||
var_dump( Favorite::model()->getAllMy() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ class JsonController extends Controller
|
|||
$point->categoryIcon = $categories[$point->categoryId]['icon'];
|
||||
$point->categoryName = $categories[$point->categoryId]['name'];
|
||||
$point->photosCount = $photosCount;
|
||||
$point->inFavorites = Favorite::model()->checkIsMy($id);
|
||||
|
||||
self::renderPartial('json.php', $point->getValues());
|
||||
} else
|
||||
|
|
@ -306,4 +307,15 @@ class JsonController extends Controller
|
|||
self::renderPartial('json.php', $coords);
|
||||
}
|
||||
|
||||
static function actionAddRemoveFavorites()
|
||||
{
|
||||
$id = (int) App::getParam('id');
|
||||
if (!$id || !App::$user)
|
||||
{
|
||||
App::error404();
|
||||
}
|
||||
|
||||
self::renderPartial('json.php', boolval(Favorite::addRemove($id)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
class Favorite extends Model
|
||||
{
|
||||
function __construct($fromArray = array())
|
||||
{
|
||||
$this->_tableName_ = 'favorites';
|
||||
parent::__construct($fromArray);
|
||||
$this->setRelation('user', 'userId', 'User', 'id', self::TO_ONE);
|
||||
$this->setRelation('point', 'pointId', 'Point', 'id', self::TO_ONE);
|
||||
}
|
||||
|
||||
static function model()
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
public static function addRemove($pointId)
|
||||
{
|
||||
if (!App::$user || !App::$user->id || !$pointId)
|
||||
return false;
|
||||
|
||||
$res = self::model()->getAll(array('where' => '`userId` = '.(int)App::$user->id.' AND `pointId` = '.(int)$pointId, 'limit'=>1));
|
||||
|
||||
if ($res)
|
||||
{
|
||||
return boolval(Favorite::model()->delete($res->id));
|
||||
} else {
|
||||
return Favorite::model()->add(array('userId'=>App::$user->id, 'pointId'=>$pointId));
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllMy()
|
||||
{
|
||||
if (!App::$user || !App::$user->id)
|
||||
return false;
|
||||
|
||||
return $this->getAll(array('where' => '`userId` = '.(int)App::$user->id));
|
||||
}
|
||||
|
||||
public function checkIsMy($pointId)
|
||||
{
|
||||
if (!App::$user || !App::$user->id || !$pointId)
|
||||
return false;
|
||||
|
||||
return boolval($this->getAll(array('where' => '`userId` = '.(int)App::$user->id.' AND `pointId` = '.(int)$pointId)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -46,36 +46,6 @@
|
|||
<?= isset($content) && !empty($content) ? $content : 'No content =(' ?>
|
||||
<?= self::renderPartial('modals/about.php', array(), true) ?>
|
||||
<?= self::renderPartial('modals/howToUse.php', array(), true) ?>
|
||||
<?php if (App::getConfig('metrika')): ?>
|
||||
<!-- Yandex.Metrika counter -->
|
||||
<script type="text/javascript">
|
||||
(function(d, w, c) {
|
||||
(w[c] = w[c] || []).push(function() {
|
||||
try {
|
||||
w.yaCounter24682772 = new Ya.Metrika({id: 24682772,
|
||||
trackLinks: true});
|
||||
} catch (e) {
|
||||
}
|
||||
});
|
||||
|
||||
var n = d.getElementsByTagName("script")[0],
|
||||
s = d.createElement("script"),
|
||||
f = function() {
|
||||
n.parentNode.insertBefore(s, n);
|
||||
};
|
||||
s.type = "text/javascript";
|
||||
s.async = true;
|
||||
s.src = (d.location.protocol == "https:" ? "https:" : "http:") + "//mc.yandex.ru/metrika/watch.js";
|
||||
|
||||
if (w.opera == "[object Opera]") {
|
||||
d.addEventListener("DOMContentLoaded", f, false);
|
||||
} else {
|
||||
f();
|
||||
}
|
||||
})(document, window, "yandex_metrika_callbacks");
|
||||
</script>
|
||||
<noscript><div><img src="//mc.yandex.ru/watch/24682772" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
|
||||
<!-- /Yandex.Metrika counter -->
|
||||
<?php endif; ?>
|
||||
<?= self::renderPartial('metrika.php', array(), true) ?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php if (App::getConfig('metrika')): ?>
|
||||
<!-- Yandex.Metrika counter -->
|
||||
<script type="text/javascript">
|
||||
(function (d, w, c) {
|
||||
(w[c] = w[c] || []).push(function () {
|
||||
try {
|
||||
w.yaCounter24682772 = new Ya.Metrika({id: 24682772,
|
||||
trackLinks: true});
|
||||
} catch (e) {
|
||||
}
|
||||
});
|
||||
|
||||
var n = d.getElementsByTagName("script")[0],
|
||||
s = d.createElement("script"),
|
||||
f = function () {
|
||||
n.parentNode.insertBefore(s, n);
|
||||
};
|
||||
s.type = "text/javascript";
|
||||
s.async = true;
|
||||
s.src = (d.location.protocol == "https:" ? "https:" : "http:") + "//mc.yandex.ru/metrika/watch.js";
|
||||
|
||||
if (w.opera == "[object Opera]") {
|
||||
d.addEventListener("DOMContentLoaded", f, false);
|
||||
} else {
|
||||
f();
|
||||
}
|
||||
})(document, window, "yandex_metrika_callbacks");
|
||||
</script>
|
||||
<noscript><div><img src="//mc.yandex.ru/watch/24682772" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
|
||||
<!-- /Yandex.Metrika counter -->
|
||||
<?php endif; ?>
|
||||
|
|
@ -27,6 +27,11 @@ div.add {cursor: pointer;}
|
|||
#addPointModal .extraImage .type.button:hover {background-color: #ddd;}
|
||||
#addPointModal .extraImage .input-group-addon.type.button {border-left: 0px;}
|
||||
|
||||
div.leaflet-popup-content div.control {margin-top: 7px;}
|
||||
div.leaflet-popup-content button span.label {display: none; font-size: 90%; font-weight: normal; color: #333;}
|
||||
div.leaflet-popup-content button:hover {min-width: 150px;}
|
||||
div.leaflet-popup-content button:hover span.label {display: inline;}
|
||||
|
||||
.form-group .error {display: none;}
|
||||
.form-group.has-error .error {display: inline-block;}
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 916 B |
Binary file not shown.
|
After Width: | Height: | Size: 595 B |
Binary file not shown.
|
After Width: | Height: | Size: 917 B |
Binary file not shown.
|
After Width: | Height: | Size: 852 B |
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
function loadGif($imgname)
|
||||
{
|
||||
$res = array();
|
||||
$im = @imagecreatefromgif($imgname);
|
||||
|
||||
$b = imagecolorat($im, 0, 0);
|
||||
$w = imagecolorat($im, 3, 3);
|
||||
|
||||
$digits = array(
|
||||
0 => array($b,$b,$b,$w,$b,$b),
|
||||
1 => array($w,$w,$w,$b,$w,$w),
|
||||
2 => array($b,$w,$b,$b,$b,$w),
|
||||
3 => array($b,$w,$b,$b,$w,$b),
|
||||
4 => array($w,$b,$b,$b,$w,$b),
|
||||
5 => array($b,$b,$w,$b,$w,$b),
|
||||
6 => array($b,$b,$w,$b,$b,$b),
|
||||
7 => array($b,$w,$b,$w,$w,$b),
|
||||
8 => array($b,$b,$b,$b,$b,$b),
|
||||
9 => array($b,$b,$b,$b,$w,$b),
|
||||
);
|
||||
|
||||
if($im)
|
||||
{
|
||||
for ($index = 0; $index < 10; $index++) {
|
||||
$block = 0;
|
||||
if ($index >= 3) $block++;
|
||||
if ($index >= 6) $block++;
|
||||
if ($index >= 9) $block++;
|
||||
|
||||
$x = 78 - 5*$index - 2*$block;
|
||||
$y = 72;
|
||||
|
||||
$digit = array(
|
||||
imagecolorat($im, $x+1, $y),
|
||||
imagecolorat($im, $x, $y+1),
|
||||
imagecolorat($im, $x+3, $y+1),
|
||||
imagecolorat($im, $x+2, $y+2),
|
||||
imagecolorat($im, $x, $y+3),
|
||||
imagecolorat($im, $x+3, $y+3),
|
||||
);
|
||||
|
||||
$d = array_search($digit, $digits);
|
||||
|
||||
if ($d !== false) {
|
||||
$res[] = array_search($digit, $digits);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return implode('', array_reverse($res));
|
||||
}
|
||||
|
||||
for ($index = 0; $index <= 2; $index++) {
|
||||
print loadGif('/home/web/poi/public/hit'.$index.'.gif');
|
||||
print '<br/>';
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 855 B |
|
|
@ -104,3 +104,20 @@ function showImage(id)
|
|||
|
||||
$('#imageModal').modal('show');
|
||||
}
|
||||
|
||||
function addRemoveFavorite(id)
|
||||
{
|
||||
if (user != '0')
|
||||
{
|
||||
$.ajax({
|
||||
url: "/json/addRemoveFavorites/id/" + id,
|
||||
success: function(data) {
|
||||
if (data){
|
||||
// Тут переключалку классов звёздочки
|
||||
$('#myFavoritesButton').toggleClass('glyphicon glyphicon-star-empty').toggleClass('glyphicon glyphicon-star');
|
||||
}
|
||||
}});
|
||||
} else {
|
||||
alert('Для выполнения действия необходимо войти.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
294
public/js/map.js
294
public/js/map.js
|
|
@ -16,9 +16,9 @@ var defaultZoom = 13;
|
|||
|
||||
categories.im = L.icon({
|
||||
iconUrl: '/ico/man.png',
|
||||
iconSize: [32, 37],
|
||||
iconAnchor: [16, 37],
|
||||
popupAnchor: [0, 1]
|
||||
iconSize: [32, 37],
|
||||
iconAnchor: [16, 37],
|
||||
popupAnchor: [0, 1]
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -26,7 +26,7 @@ categories.im = L.icon({
|
|||
/**
|
||||
* Инициализируем яндекс-карты и узнаём расположение пользователя.
|
||||
*/
|
||||
ymaps.ready(function(){
|
||||
ymaps.ready(function () {
|
||||
lat = ymaps.geolocation.latitude;
|
||||
lng = ymaps.geolocation.longitude;
|
||||
init(lat, lng);
|
||||
|
|
@ -41,11 +41,11 @@ ymaps.ready(function(){
|
|||
* @returns true
|
||||
*/
|
||||
function init(lat, lng) {
|
||||
myMap = L.map('map',{zoomControl: false}).setView([lat, lng], defaultZoom);
|
||||
myMap = L.map('map', {zoomControl: false}).setView([lat, lng], defaultZoom);
|
||||
markers = new L.MarkerClusterGroup({showCoverageOnHover: false, maxClusterRadius: 45});
|
||||
|
||||
layers['quest'] = L.tileLayer('http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png', {attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',maxZoom: 18});
|
||||
layers['osm'] = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery ©</a>',maxZoom: 18});
|
||||
layers['quest'] = L.tileLayer('http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png', {attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>', maxZoom: 18});
|
||||
layers['osm'] = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery ©</a>', maxZoom: 18});
|
||||
layers['google'] = new L.Google('HYBRID');
|
||||
layers['yandexMap'] = new L.Yandex();
|
||||
layers['yandex'] = new L.Yandex('hybrid');
|
||||
|
|
@ -53,14 +53,14 @@ function init(lat, lng) {
|
|||
|
||||
initCategories(); // getPoints внутри
|
||||
|
||||
myMap.on('click', function(e) {
|
||||
myMap.on('click', function (e) {
|
||||
if (!myMap._popup) {
|
||||
if (status == statusHunting)
|
||||
{
|
||||
$('#addPointId').remove();
|
||||
$('#addPointForm input:text').val('');
|
||||
$('#addPointForm textarea').val('');
|
||||
$("#addPointCategoryId option" ).attr('selected', null);
|
||||
$("#addPointCategoryId option").attr('selected', null);
|
||||
$('#addPointLat').val(e.latlng.lat);
|
||||
$('#addPointLng').val(e.latlng.lng);
|
||||
|
||||
|
|
@ -86,15 +86,17 @@ function init(lat, lng) {
|
|||
$("#wayPoints").disableSelection();
|
||||
$("#imgsContainer").sortable();
|
||||
|
||||
myMap.on('moveend', function(e) {
|
||||
if (!myMap._popup && $('#boxRoute').css('display') == 'none')
|
||||
{
|
||||
history.pushState({}, document.title, "/?lat=" + myMap.getCenter().lat + "&lng=" + myMap.getCenter().lng + "&zoom=" + myMap.getZoom());
|
||||
document.title = pointsCount+' или даже больше поводов не сидеть дома';
|
||||
}
|
||||
});
|
||||
myMap.on('moveend', function (e) {
|
||||
if (!myMap._popup && $('#boxRoute').css('display') == 'none')
|
||||
{
|
||||
history.pushState({}, document.title, "/?lat=" + myMap.getCenter().lat + "&lng=" + myMap.getCenter().lng + "&zoom=" + myMap.getZoom());
|
||||
document.title = pointsCount + ' или даже больше поводов не сидеть дома';
|
||||
}
|
||||
});
|
||||
|
||||
$('.filterSelector').bind('change', function(){filter()});
|
||||
$('.filterSelector').bind('change', function () {
|
||||
filter()
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -110,7 +112,9 @@ function constructPoint(data)
|
|||
|
||||
points[id] = L.marker(
|
||||
[data['lat'], data['lng']], {icon: categories[data['categoryId']], title: data['name'], id: id, categoryId: data['categoryId']}
|
||||
).on('click', function(e){showInfo(e.target.options.id);});
|
||||
).on('click', function (e) {
|
||||
showInfo(e.target.options.id);
|
||||
});
|
||||
|
||||
return points[id];
|
||||
}
|
||||
|
|
@ -123,7 +127,7 @@ function initPoints()
|
|||
{
|
||||
$.ajax({
|
||||
url: "/json/points/",
|
||||
success: function(data) {
|
||||
success: function (data) {
|
||||
for (var k in data) {
|
||||
markers.addLayer(constructPoint(data[k]));
|
||||
}
|
||||
|
|
@ -160,43 +164,33 @@ function initPoints()
|
|||
*/
|
||||
function showInfo(id)
|
||||
{
|
||||
marker = points[id];
|
||||
marker = points[id];
|
||||
|
||||
if (!(id in points) || marker.options.description == undefined)
|
||||
{
|
||||
marker.bindPopup("Загрузка...").openPopup();
|
||||
$.ajax({
|
||||
url: "/json/point/id/" + id,
|
||||
success: function(data) {
|
||||
success: function (data) {
|
||||
pointsSources[id] = data;
|
||||
if (typeof(data.images) == 'object')
|
||||
if (typeof (data.images) == 'object')
|
||||
{
|
||||
ph = '<div style="position: relative;">';
|
||||
photos = '<div style="position: relative;">';
|
||||
|
||||
if (data.images.length > 1)
|
||||
ph += '<div class="photosCount"><span class="glyphicon glyphicon-camera"></span> <b>+' + (data.photosCount-1) + '</b></div>';
|
||||
photos += '<div class="photosCount"><span class="glyphicon glyphicon-camera"></span> <b>+' + (data.photosCount - 1) + '</b></div>';
|
||||
|
||||
ph += '<img src="/photos/small/' + data.img + '" onclick="showImage(\''+ id +'\')" />';
|
||||
ph += '</div>';
|
||||
photos += '<img src="/photos/small/' + data.img + '" onclick="showImage(\'' + id + '\')" />';
|
||||
photos += '</div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
ph = '<img src="' + data.img + '" onclick="showImage(\''+ id +'\')" />';
|
||||
photos = '<img src="' + data.img + '" onclick="showImage(\'' + id + '\')" />';
|
||||
}
|
||||
|
||||
description = '<div class="infoCard">' +
|
||||
'<h3>' + data.name + '</h3>' +
|
||||
ph +
|
||||
'<button type="button" class="btn btn-default btn-xs" onclick="addToRoute(' + id + ')">' +
|
||||
'<span class="glyphicon glyphicon-plus"></span> Добавить в маршрут' +
|
||||
'</button><br/>';
|
||||
|
||||
if (isAdmin == '1')
|
||||
{
|
||||
description = description + '<button type="button" class="btn btn-default btn-xs" onclick="editPoint(' + id + ')">' +
|
||||
'<span class="glyphicon glyphicon-pencil"></span> Редактировать' +
|
||||
'</button><br/>';
|
||||
}
|
||||
photos;
|
||||
|
||||
description = description + data.descriptionHtml;
|
||||
//description = description + ' <a href="/page/point/id/' + id + '" target="blank">Подробнее...</a>';
|
||||
|
|
@ -207,17 +201,29 @@ function showInfo(id)
|
|||
}
|
||||
|
||||
description = description + '</div><div class="clear"></div>';
|
||||
|
||||
marker.options.description = description;
|
||||
marker.bindPopup(marker.options.description, {maxWidth: 500, maxHeight: 300});
|
||||
|
||||
markers.zoomToShowLayer(marker,function() {
|
||||
description = description + '<div class="btn-group control">';
|
||||
description = description + '<button type="button" class="btn btn-default" onclick="addToRoute(' + id + ')"><span class="glyphicon glyphicon-map-marker"></span> <span class="label">В маршрут</span></button>';
|
||||
description = description + '<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-ok"></span> <span class="label">Был здесь</span></button>';
|
||||
description = description + '<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-thumbs-up"></span> <span class="label">Нравится</span></button>';
|
||||
description = description + '<button type="button" class="btn btn-default" onclick="addRemoveFavorite(' + id + ')"><span id="myFavoritesButton" class="glyphicon glyphicon-star' + (data.inFavorites ? '' : '-empty') + ' "></span> <span class="label">Хочу посетить</span></button>';
|
||||
|
||||
if (isAdmin == '1')
|
||||
{
|
||||
description = description + '<button type="button" class="btn btn-default" onclick="editPoint(' + id + ')"><span class="glyphicon glyphicon-pencil"></span> <span class="label">Редактировать</span></button>';
|
||||
}
|
||||
description = description + '</div>';
|
||||
|
||||
marker.options.description = description;
|
||||
marker.bindPopup(marker.options.description, {maxWidth: 500, maxHeight: 300});
|
||||
|
||||
markers.zoomToShowLayer(marker, function () {
|
||||
marker.openPopup();
|
||||
history.pushState({}, document.title, "/?point=" + id);
|
||||
|
||||
bounds = myMap.getBounds();
|
||||
diff = (bounds._northEast.lat - bounds._southWest.lat)/4;
|
||||
myMap.setView([points[id]._latlng.lat+diff, points[id]._latlng.lng], myMap.getZoom());
|
||||
diff = (bounds._northEast.lat - bounds._southWest.lat) / 4;
|
||||
myMap.setView([points[id]._latlng.lat + diff, points[id]._latlng.lng], myMap.getZoom());
|
||||
|
||||
history.pushState({}, document.title, "/?point=" + id);
|
||||
document.title = data.name;
|
||||
|
|
@ -226,8 +232,8 @@ function showInfo(id)
|
|||
});
|
||||
} else {
|
||||
bounds = myMap.getBounds();
|
||||
diff = (bounds._northEast.lat - bounds._southWest.lat)/4;
|
||||
myMap.setView([points[id]._latlng.lat+diff, points[id]._latlng.lng], myMap.getZoom());
|
||||
diff = (bounds._northEast.lat - bounds._southWest.lat) / 4;
|
||||
myMap.setView([points[id]._latlng.lat + diff, points[id]._latlng.lng], myMap.getZoom());
|
||||
|
||||
history.pushState({}, document.title, "/?point=" + id);
|
||||
document.title = points[id].options.title;
|
||||
|
|
@ -236,11 +242,11 @@ function showInfo(id)
|
|||
|
||||
function showRandomPoint()
|
||||
{
|
||||
roundIndex = Math.floor(Math.random()*points.length);
|
||||
roundIndex = Math.floor(Math.random() * points.length);
|
||||
runner = 0;
|
||||
for(var key in points)
|
||||
for (var key in points)
|
||||
{
|
||||
if(runner++ >= roundIndex)
|
||||
if (runner++ >= roundIndex)
|
||||
return showInfo(key);
|
||||
}
|
||||
}
|
||||
|
|
@ -253,17 +259,17 @@ function initCategories()
|
|||
{
|
||||
$.ajax({
|
||||
url: "/json/categories/",
|
||||
success: function(data) {
|
||||
for (var k in data) {
|
||||
categories[data[k]['id']] = L.icon({
|
||||
iconUrl: data[k]['icon'],
|
||||
iconSize: [32, 37],
|
||||
iconAnchor: [16, 37],
|
||||
popupAnchor: [0, 1]
|
||||
});
|
||||
}
|
||||
success: function (data) {
|
||||
for (var k in data) {
|
||||
categories[data[k]['id']] = L.icon({
|
||||
iconUrl: data[k]['icon'],
|
||||
iconSize: [32, 37],
|
||||
iconAnchor: [16, 37],
|
||||
popupAnchor: [0, 1]
|
||||
});
|
||||
}
|
||||
|
||||
initPoints();
|
||||
initPoints();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -281,15 +287,15 @@ function searchAdderess()
|
|||
data: {
|
||||
search: $('#addressField').val()
|
||||
},
|
||||
success: function(data)
|
||||
success: function (data)
|
||||
{
|
||||
if (data.lat && data.lng)
|
||||
{
|
||||
myMap.setView([data.lat, data.lng], defaultZoom);
|
||||
L.popup()
|
||||
.setLatLng([data.lat, data.lng])
|
||||
.setContent('Координаты: lat:'+data.lat+' lng:'+data.lng)
|
||||
.openOn(myMap);
|
||||
.setLatLng([data.lat, data.lng])
|
||||
.setContent('Координаты: lat:' + data.lat + ' lng:' + data.lng)
|
||||
.openOn(myMap);
|
||||
} else
|
||||
{
|
||||
alert('Ничего не найдено.');
|
||||
|
|
@ -304,7 +310,7 @@ function searchAdderess()
|
|||
*/
|
||||
function showMeOnTheMap()
|
||||
{
|
||||
navigator.geolocation.getCurrentPosition(function(pos) {
|
||||
navigator.geolocation.getCurrentPosition(function (pos) {
|
||||
coords = [pos.coords.latitude, pos.coords.longitude];
|
||||
myMap.removeLayer(points.im);
|
||||
points.im.setLatLng(coords).addTo(myMap);
|
||||
|
|
@ -321,7 +327,7 @@ function activateAddPoint()
|
|||
$('#addPointButton').toggleClass('active');
|
||||
if ($('#addPointButton').hasClass('active'))
|
||||
{
|
||||
$('.extraImage','#imgsContainer').remove();
|
||||
$('.extraImage', '#imgsContainer').remove();
|
||||
addNewImage();
|
||||
$('#map').css('cursor', 'crosshair');
|
||||
setStatus(statusHunting)
|
||||
|
|
@ -342,33 +348,33 @@ function activateAddPoint()
|
|||
function addPoint()
|
||||
{
|
||||
$('.form-group').removeClass('has-error');
|
||||
if (status != statusSendingToServer)
|
||||
{
|
||||
if (status != statusSendingToServer)
|
||||
{
|
||||
setStatus(statusSendingToServer)
|
||||
id = $('#addPointId').length ? $('#addPointId').val() : 0;
|
||||
hasImages = false;
|
||||
$("input[name='imgs[]']", '#addPointForm').each(function(){
|
||||
if ( $(this).val().length > 10)
|
||||
$("input[name='imgs[]']", '#addPointForm').each(function () {
|
||||
if ($(this).val().length > 10)
|
||||
hasImages = true;
|
||||
});
|
||||
$("input[name='photos[]']", '#addPointForm').each(function(){
|
||||
if ( $(this).val().length > 5)
|
||||
$("input[name='photos[]']", '#addPointForm').each(function () {
|
||||
if ($(this).val().length > 5)
|
||||
hasImages = true;
|
||||
})
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/json/addpoint/",
|
||||
data: {
|
||||
name: $('#addPointName').val(),
|
||||
img: hasImages ? 1 : 0,
|
||||
description: $('#addPointDescription').val(),
|
||||
categoryId: $('#addPointCategoryId').val(),
|
||||
source: $('#addPointSource').val(),
|
||||
lat: $('#addPointLat').val(),
|
||||
lng: $('#addPointLng').val(),
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/json/addpoint/",
|
||||
data: {
|
||||
name: $('#addPointName').val(),
|
||||
img: hasImages ? 1 : 0,
|
||||
description: $('#addPointDescription').val(),
|
||||
categoryId: $('#addPointCategoryId').val(),
|
||||
source: $('#addPointSource').val(),
|
||||
lat: $('#addPointLat').val(),
|
||||
lng: $('#addPointLng').val(),
|
||||
id: id
|
||||
},
|
||||
success: function(data) {
|
||||
},
|
||||
success: function (data) {
|
||||
if ($("input[name='photos[]']").length > 0 || $("input[name='imgs[]']").length > 0)
|
||||
{
|
||||
$('<input type="hidden" id="addPointId" name="id"/>').appendTo('#addPointForm').val(data);
|
||||
|
|
@ -376,77 +382,77 @@ function addPoint()
|
|||
}
|
||||
|
||||
text = id ? 'Точка успешно отредактирована!' : 'Точка успешно добавлена!';
|
||||
if ( id )
|
||||
if (id)
|
||||
{
|
||||
markers.removeLayer(points[id]);
|
||||
}
|
||||
|
||||
balloon = L.popup()
|
||||
.setLatLng([$('#addPointLat').val(), $('#addPointLng').val()])
|
||||
.setContent(text)
|
||||
.openOn(myMap);
|
||||
setTimeout(function() {
|
||||
balloon._close();
|
||||
.setLatLng([$('#addPointLat').val(), $('#addPointLng').val()])
|
||||
.setContent(text)
|
||||
.openOn(myMap);
|
||||
setTimeout(function () {
|
||||
balloon._close();
|
||||
delete balloon;
|
||||
}, 2000);
|
||||
}, 2000);
|
||||
|
||||
obj = {};
|
||||
obj.id = data;
|
||||
obj.name = $('#addPointName').val();
|
||||
obj.lat = $('#addPointLat').val();
|
||||
obj.lng = $('#addPointLng').val();
|
||||
obj.categoryIcon = categories[$('#addPointCategoryId').val()].icon;
|
||||
obj = {};
|
||||
obj.id = data;
|
||||
obj.name = $('#addPointName').val();
|
||||
obj.lat = $('#addPointLat').val();
|
||||
obj.lng = $('#addPointLng').val();
|
||||
obj.categoryIcon = categories[$('#addPointCategoryId').val()].icon;
|
||||
obj.categoryId = $('#addPointCategoryId').val();
|
||||
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
markers.addLayer(constructPoint(obj));
|
||||
}, 2000);
|
||||
}, 2000);
|
||||
|
||||
$('#addPointModal').modal('hide');
|
||||
$('#addPointModal').modal('hide');
|
||||
|
||||
// Clear form
|
||||
$('#addPointForm input').val('');
|
||||
$('#addPointForm textarea').val('');
|
||||
$('.form-group').removeClass('has-error');
|
||||
$('#addPointButton').removeClass('active');
|
||||
// Clear form
|
||||
$('#addPointForm input').val('');
|
||||
$('#addPointForm textarea').val('');
|
||||
$('.form-group').removeClass('has-error');
|
||||
$('#addPointButton').removeClass('active');
|
||||
$('#addPointId').remove();
|
||||
$('#map').css('cursor', 'arrow');
|
||||
setStatus(statusReady);
|
||||
$('#map').css('cursor', 'arrow');
|
||||
setStatus(statusReady);
|
||||
|
||||
return true;
|
||||
},
|
||||
error: function(data) {
|
||||
response = data.responseJSON;
|
||||
message = '';
|
||||
for (var k in response) {
|
||||
if (typeof response[k] !== 'function') {
|
||||
if (k == 1)
|
||||
$('#addPointName').parent().addClass('has-error');
|
||||
else
|
||||
if (k == 2)
|
||||
return true;
|
||||
},
|
||||
error: function (data) {
|
||||
response = data.responseJSON;
|
||||
message = '';
|
||||
for (var k in response) {
|
||||
if (typeof response[k] !== 'function') {
|
||||
if (k == 1)
|
||||
$('#addPointName').parent().addClass('has-error');
|
||||
else
|
||||
if (k == 2)
|
||||
{
|
||||
$('.extraImage', '#addPointForm').addClass('has-error');
|
||||
$('.extraImage', '#addPointForm').addClass('has-error');
|
||||
}
|
||||
else
|
||||
if (k == 3)
|
||||
$('#addPointDescription').parent().addClass('has-error');
|
||||
else
|
||||
message += response[k] + '; ';
|
||||
}
|
||||
}
|
||||
else
|
||||
if (k == 3)
|
||||
$('#addPointDescription').parent().addClass('has-error');
|
||||
else
|
||||
message += response[k] + '; ';
|
||||
}
|
||||
}
|
||||
|
||||
if (message != '')
|
||||
alert(message);
|
||||
if (message != '')
|
||||
alert(message);
|
||||
|
||||
resetStatus();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
alert ('Точка добавляется, нужно немного подождать.');
|
||||
}
|
||||
resetStatus();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
alert('Точка добавляется, нужно немного подождать.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -460,16 +466,16 @@ function editPoint(id)
|
|||
$('<input type="hidden" id="addPointId" name="id"/>').appendTo('#addPointForm').val(id);
|
||||
$('#addPointName').val(pointsSources[id].name);
|
||||
$('#addPointDescription').val(pointsSources[id].description);
|
||||
$("#addPointCategoryId option" ).attr('selected', null);
|
||||
$("#addPointCategoryId option[value='"+pointsSources[id].categoryId+"']" ).attr('selected', 'selected');
|
||||
$("#addPointCategoryId option").attr('selected', null);
|
||||
$("#addPointCategoryId option[value='" + pointsSources[id].categoryId + "']").attr('selected', 'selected');
|
||||
$('#addPointSource').val(pointsSources[id].source);
|
||||
$('#addPointLat').val(pointsSources[id].lat);
|
||||
$('#addPointLng').val(pointsSources[id].lng);
|
||||
|
||||
$('.extraImage','#imgsContainer').remove();
|
||||
$('.extraImage', '#imgsContainer').remove();
|
||||
if (pointsSources[id].images != undefined && pointsSources[id].images.length > 0)
|
||||
{
|
||||
for(var i=0; i < pointsSources[id].images.length; i++)
|
||||
for (var i = 0; i < pointsSources[id].images.length; i++)
|
||||
{
|
||||
addNewImage(pointsSources[id].images[i]);
|
||||
}
|
||||
|
|
@ -499,7 +505,7 @@ function setLayer(name)
|
|||
layer = name;
|
||||
myMap.addLayer(layers[layer]);
|
||||
$('.layers').removeClass('selected');
|
||||
$('.'+layer+'Layer').addClass('selected');
|
||||
$('.' + layer + 'Layer').addClass('selected');
|
||||
$.cookie('mapLayer', layer);
|
||||
}
|
||||
|
||||
|
|
@ -512,11 +518,11 @@ function closePopup()
|
|||
function filter()
|
||||
{
|
||||
var selected = new Array();
|
||||
$('.filterSelector:checked').each(function(i, e){
|
||||
$('.filterSelector:checked').each(function (i, e) {
|
||||
selected.push($(e).val());
|
||||
});
|
||||
|
||||
for(var key in points)
|
||||
for (var key in points)
|
||||
{
|
||||
if (selected.length == 0 || points[key].options.categoryId == undefined || selected.indexOf(points[key].options.categoryId) != -1)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue