120 lines
3.7 KiB
JavaScript
120 lines
3.7 KiB
JavaScript
/*
|
|
* Let's GO!
|
|
*/
|
|
|
|
ymaps.ready(init);
|
|
var myMap;
|
|
var categories;
|
|
|
|
function init() {
|
|
myMap = new ymaps.Map("map", {
|
|
center: [59.9, 30.3],
|
|
zoom: 9,
|
|
behaviors: ['default', 'scrollZoom']
|
|
});
|
|
|
|
myMap.controls.add('mapTools');
|
|
myMap.controls.add('typeSelector');
|
|
myMap.controls.add('smallZoomControl');
|
|
myMap.controls.add('scaleLine');
|
|
|
|
initCategories()
|
|
getPoints();
|
|
|
|
myMap.events.add('click', function (e) {
|
|
if (!myMap.balloon.isOpen()) {
|
|
var coords = e.get('coordPosition');
|
|
myMap.balloon.open(coords, {
|
|
contentHeader:'Добавление точки',
|
|
contentBody:
|
|
'<form method="POST" action="/json/addpoint/" width="400px" height="300px">' +
|
|
'<p>Название:<br/>' +
|
|
'<input type="text" id="name" name="name" /></p>' +
|
|
'<p>URL изображения:<br/>' +
|
|
'<input type="text" id="img" name="img" /></p>' +
|
|
'<p>Описание:<br/>' +
|
|
'<textarea id="description" name="description"></textarea></p>' +
|
|
'<p>Тип:<br/>' +
|
|
'<select id="categoryId" name="categoryId">' +
|
|
categories +
|
|
'</select>' +
|
|
'<p>Источник:<br/>' +
|
|
'<input type="text" id="source" name="source" /></p>' +
|
|
|
|
'<input type="hidden" id="lat" name="lat" value="'+coords[0].toPrecision(11)+'" />' +
|
|
'<input type="hidden" id="lng" name="lng" value="'+coords[1].toPrecision(11)+'" />' +
|
|
'<input type="submit" id="add" onclick="addNewPoint()" value="Добавить">' +
|
|
'</form>'
|
|
});
|
|
}
|
|
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>'
|
|
},{iconImageHref: data[k]['categoryIcon'], iconImageSize: [32, 37]});
|
|
|
|
myMap.geoObjects.add(myPlacemark);
|
|
}
|
|
}
|
|
});
|
|
|
|
return true;
|
|
}
|
|
|
|
function initCategories()
|
|
{
|
|
$.ajax({
|
|
url: "/json/categories/",
|
|
success: function(data){
|
|
for(var k in data) {
|
|
categories = categories + '<option value="'+data[k]['id']+'">'+data[k]['name']+'</option>';
|
|
}
|
|
}
|
|
});
|
|
|
|
return true;
|
|
}
|
|
|
|
function searchAdderess()
|
|
{
|
|
var myGeocoder = ymaps.geocode($('#addressField').val());
|
|
myGeocoder.then(
|
|
function (res) {
|
|
myMap.setCenter(res.geoObjects.get(0).geometry.getCoordinates(), 13);
|
|
},
|
|
function (err) {}
|
|
);
|
|
}
|
|
|
|
function showMeOnTheMap()
|
|
{
|
|
myMap.geoObjects.add(
|
|
new ymaps.Placemark(
|
|
[ymaps.geolocation.latitude, ymaps.geolocation.longitude],
|
|
{
|
|
balloonContentHeader: ymaps.geolocation.country,
|
|
balloonContent: ymaps.geolocation.city,
|
|
balloonContentFooter: ymaps.geolocation.region
|
|
},
|
|
{iconImageHref: '/ico/man.png', iconImageSize: [32, 37]}
|
|
)
|
|
);
|
|
}
|