/* * 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: '
' + '

Название:
' + '

' + '

URL изображения:
' + '

' + '

Описание:
' + '

' + '

Тип:
' + '' + '

Источник:
' + '

' + '' + '' + '' + '
' }); } 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: '
' + '' + '

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

' + data[k]['description'] + ' Подробнее...
' },{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 + ''; } } }); 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() { var userLat = 0; var userLng = 0; navigator.geolocation.getCurrentPosition(function(pos) { userLat = pos.coords.latitude; userLng = pos.coords.longitude; myMap.geoObjects.add( new ymaps.Placemark( [userLat, userLng], { balloonContentHeader: ymaps.geolocation.country, balloonContent: ymaps.geolocation.city, balloonContentFooter: ymaps.geolocation.region }, { iconImageHref: '/ico/man.png', iconImageSize: [32, 37] } ) ); }, function(){ userLat = ymaps.geolocation.latitude; userLng = ymaps.geolocation.longitude; myMap.geoObjects.add( new ymaps.Placemark( [userLat, userLng], { balloonContentHeader: ymaps.geolocation.country, balloonContent: ymaps.geolocation.city, balloonContentFooter: ymaps.geolocation.region }, { iconImageHref: '/ico/man.png', iconImageSize: [32, 37] } ) ); }); }