73 lines
1.9 KiB
JavaScript
Executable File
73 lines
1.9 KiB
JavaScript
Executable File
ymaps.ready(init);
|
|
|
|
function execCmd(url, func, cls, name) {
|
|
var XHR = ("onload" in new XMLHttpRequest()) ? XMLHttpRequest : XDomainRequest;
|
|
var xhr = new XHR();
|
|
|
|
xhr.onreadystatechange = function() {
|
|
if (xhr.readyState == 4 && xhr.status == 200) {
|
|
func(0,xhr.responseText,cls,name);
|
|
}
|
|
|
|
if (xhr.readyState == 4 && xhr.status != 200) {
|
|
func(-1,xhr.status + ': ' + xhr.statusText);
|
|
}
|
|
};
|
|
|
|
xhr.open('GET', url, true);
|
|
xhr.send();
|
|
}
|
|
|
|
function getPlace(status, json) {
|
|
var place = JSON.parse(json);
|
|
console.log(place);
|
|
|
|
var descr = "<div>"+place.name
|
|
+ '</div><div>'+place.address
|
|
+ '</div><div><a href="'+place.url+'">'
|
|
+ place.url+'</a></div><div>'+place.phone+'</div>';
|
|
|
|
var myMap = getMap(place.x, place.y);
|
|
|
|
// Создаем геообъект с типом геометрии "Точка".
|
|
myGeoObject = getGeoObject(place.x, place.y, place.name, descr);
|
|
myMap.geoObjects.add(myGeoObject);
|
|
}
|
|
|
|
function getGeoObject(x,y, name, descr) {
|
|
return new ymaps.GeoObject({
|
|
// Описание геометрии.
|
|
geometry: {
|
|
type: "Point",
|
|
coordinates: [x, y]
|
|
},
|
|
// Свойства.
|
|
properties: {
|
|
// Контент метки.
|
|
// iconContent: descr,
|
|
hintContent: name,
|
|
balloonContent: descr
|
|
}
|
|
}, {
|
|
// Опции.
|
|
// Иконка метки будет растягиваться под размер ее содержимого.
|
|
preset: 'islands#redIcon',
|
|
// Метку можно перемещать.
|
|
draggable: false
|
|
});
|
|
}
|
|
|
|
function getMap(x, y) {
|
|
return new ymaps.Map("map", {
|
|
center: [x, y],
|
|
zoom: 16
|
|
}, {
|
|
searchControlProvider: 'yandex#search'
|
|
});
|
|
}
|
|
|
|
function init() {
|
|
var url = "/api/getplace/id/"+map_id;
|
|
execCmd(url, getPlace);
|
|
}
|