/var/www/doncode.com.ua/www/views/user/js
Edit: /var/www/doncode.com.ua/www/views/user/js/map.yandex.js (6659B)
var map;
var start;
var finish;
var route;
var last_adreses = new Array();
var myObjectManager;
function init_map () {
map = new ymaps.Map('map', {
center: [city_la, city_lo],
zoom: city_zoom
});
carsCollection = new ymaps.GeoObjectCollection(null, {
preset: 'islands#blueIcon'
});
start = null;
finish = null;
route = null;
addEvents();
}
function addEvents(){
// Будем отслеживать изменение уровня масштабирования карты
map.events.add('boundschange', function (event) {
if (event.get('newZoom') != event.get('oldZoom')) {
if (typeof(callback_zoom) == "function") {
console.log('RUN CALLBACK: callback_zoom');
callback_zoom(event.get('newZoom'));
}
}
if (event.get('newCenter') != event.get('oldCenter')) {
if (typeof(callback_center) == "function") {
console.log('RUN CALLBACK: callback_center');
callback_center(event.get('newCenter'));
}
}
//console.log(event);
});
}
function geo_query(query,callback){
var url = "http://geocode-maps.yandex.ru/1.x/?format=json&results=1&geocode="+query;
$.get(url,function(json){
var ret = json.response.GeoObjectCollection.featureMember;
var result = ret[0].GeoObject.Point.pos.split(' ');
var point = new Array(result[1],result[0]);
if (callback) {
console.log('RUN CALLBACK: callback_geo_query');
callback_geo_query(point);
}
},'json');
}
function map_point(coords,name,baloon){
window[name] = new ymaps.Placemark(coords, { iconContent: baloon }, { preset: 'islands#darkblueStretchyIcon',draggable: false });
map.geoObjects.add(window[name]);
}
function del_map_point(name){
map.geoObjects.remove(window[name]);
}
function car_point(coords,baloon){
//carsCollection.add(collection);
map.geoObjects.remove(carsCollection);
carsCollection.add(new ymaps.Placemark(coords, { iconContent: baloon }, { preset: 'islands#dotCircleIcon',draggable: false }));
map.geoObjects.add(carsCollection);
}
function del_car_points(){
map.geoObjects.remove(carsCollection);
carsCollection.removeAll();
}
function setA(address){
// alert(address);
if (typeof(map) != "object") {
return;
}
last_adreses = new Array(address);
map.geoObjects.removeAll();
var myGeocoder = ymaps.geocode(address);
myGeocoder.then(
function (res) {
start = new ymaps.Placemark(res.geoObjects.get(0).geometry.getCoordinates(), { iconContent: 'А' }, { preset: 'islands#violetStretchyIcon',draggable: false });
map.geoObjects.add(start);
if (typeof(callback_start_point) == "function") {
console.log('RUN CALLBACK: callback_start_point setA');
callback_start_point(res.geoObjects.get(0).geometry.getCoordinates());
}
}
);
}
function getRoute(adreses){
if (typeof(map) != "object") {
return;
}
if(arraysEqual(last_adreses,adreses)){
console.log('adreses equal');
return;
}
last_adreses = adreses;
// console.log('START getRoute');
// console.log(adreses);
// Объявляем набор опорных точек, и массив индексов транзитных точек.
var referencePoints = adreses;
map.geoObjects.removeAll();
// Создаем мультимаршрут и настраиваем его внешний вид с помощью опций.
var multiRoute = new ymaps.multiRouter.MultiRoute({
referencePoints: referencePoints,
params: { results: 2 }
}, {
// Внешний вид путевых точек.
wayPointStartIconColor: "#0000FF",
// Задаем собственную картинку для последней путевой точки.
//wayPointFinishIconLayout: "default#image",
//wayPointFinishIconImageHref: "images/sokolniki.png",
//wayPointFinishIconImageSize: [30, 30],
//wayPointFinishIconImageOffset: [-15, -15],
// Внешний вид транзитных точек.
viaPointIconRadius: 7,
viaPointIconFillColor: "#000088",
viaPointActiveIconFillColor: "#E63E92",
// Транзитные точки можно перетаскивать, при этом
// маршрут будет перестраиваться.
viaPointDraggable: false,
// Внешний вид точечных маркеров под путевыми точками.
pinIconFillColor: "#000088",
pinActiveIconFillColor: "#E63E92",
// Внешний вид линии маршрута.
routeStrokeWidth: 2,
routeStrokeColor: "#000088",
routeActiveStrokeWidth: 6,
routeActiveStrokeColor: "#0000FF",
// Автоматически устанавливать границы карты так, чтобы маршрут был виден целиком.
boundsAutoApply: true
});
multiRoute.model.events.add("requestsuccess", function (event) {
if (typeof(callback_distance) == "function") {
console.log('RUN CALLBACK: callback_distance');
callback_distance((multiRoute.getRoutes().get(0).properties.get("distance").value / 1000).toFixed(2));
}
if (typeof(callback_start_point) == "function") {
console.log('RUN CALLBACK: callback_start_point');
callback_start_point(multiRoute.getWayPoints().get(0).model.geometry.getCoordinates());
}
});
//console.log(multiRoute.getRoutes().get(0).properties.get("distance").value);
//var distance = Math.round(multiRoute.getLength() / 1000);
//alert(distance);
/* ymaps.modules.require([
'MultiRouteColorizer'
], function (MultiRouteColorizer) {
// Создаем объект, раскрашивающий линии сегментов маршрута.
new MultiRouteColorizer(multiRoute);
});
*/ // Добавляем мультимаршрут на карту.
map.geoObjects.add(multiRoute);
// console.log('END getRoute');
}
// Doncode Utils
function arraysEqual(a, b) {
if (a === b) return true;
if (a == null || b == null) return false;
if (a.length != b.length) return false;
for (var i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) return false;
}
return true;
}