Instantly share code, notes, and snippets.
Created
April 13, 2017 18:43
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(1)
1
You must be signed in to fork a gist
-
Save 7iomka/f2d2a5aac54a0245d3afba08f1e9a551 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myMap = new ymaps.Map('filial-map', { | |
// При инициализации карты обязательно нужно указать | |
// её центр и коэффициент масштабирования. | |
center: [51.315394, 44.391984], | |
zoom: 5 | |
//controls: ['zoomControl', 'typeSelector'] | |
}); | |
var zoomControl = new ymaps.control.ZoomControl({ | |
options: { | |
size: "auto", | |
adjustMapMargin: true, | |
position: { | |
right: 10, | |
top: 200 | |
} | |
} | |
}); | |
myMap.controls.add(zoomControl); | |
// var myCollection = new ymaps.GeoObjectCollection(); | |
var objectManager = new ymaps.ObjectManager({ | |
// clusterize: true, | |
// geoObjectOpenBalloonOnClick: false | |
}); | |
objectManager.objects.events.add(['click'], function (e) { | |
var objectId = e.get('objectId'); //Твоя цепочка? | |
console.log('objectId',objectId); //Мой..) | |
}); | |
var finalData = { | |
"type": "FeatureCollection", | |
"features": [ | |
] | |
}; | |
var finalDataCounter = 0; | |
for(var i=0; i<data.cities.length; i++){ | |
//alert(data.cities[i].filials.length);//(data.cities[i].filials[0].coords.VALUE); | |
for(var y=0; y<data.cities[i].filials.length; y++){ | |
var coords1 = data.cities[i].filials[y].coords_X.VALUE; | |
var coords2 = data.cities[i].filials[y].coords_Y.VALUE;//data.cities[i].filials[y].coords.VALUE; | |
var isMainOffice = data.cities[i].filials[y].main.VALUE_XML_ID === '1'; | |
var pinIcon; | |
if (isMainOffice) { | |
pinIcon = '/bitrix/templates/newvisa/img/map-pin--main.png'; | |
} else { | |
pinIcon = '/bitrix/templates/newvisa/img/map-pin.png'; | |
} | |
var placemarkOptions = { | |
// balloonPane: 'outerBalloon', | |
// preset: 'islands#dotIcon', | |
// Задаем стиль метки (метка в виде круга). | |
preset: "islands#dotCircleIcon", | |
// iconColor: '#1faee9', | |
iconLayout: 'default#image', | |
iconImageHref: pinIcon, | |
iconImageSize: [33, 51], | |
iconImageOffset: [-16,5, 0], | |
iconOffset: [0, -51], | |
// дополнительно смещаем балун, для открытия над иконкой. | |
balloonOffset: [0, -51], | |
hideIconOnBalloonOpen: false, | |
pane: 'balloon', | |
}; | |
var placeMarkForPush = { | |
type: "Feature", | |
id: finalDataCounter++, | |
geometry: { | |
type: "Point", | |
coordinates: [coords1, coords2] | |
}, | |
properties: { | |
balloonContent: '<strong>'+data.cities[i].city+'</strong><br/><address>'+data.cities[i].city+',<br/>'+data.cities[i].filials[y].address.VALUE+' <br/></address><a href="/">Подробнее</a>' | |
}, | |
options: placemarkOptions | |
} | |
finalData.features.push(placeMarkForPush); | |
} | |
} | |
myMap.geoObjects.add(objectManager); | |
objectManager.add(finalData); | |
// objectManager.objects.events.add(['click'], function(e){ | |
// var objectId = e.get('objectId'); | |
// var object = objectManager.objects.getById(objectId); | |
// var coords = object.geometry.coordinates; | |
// // setTimeout(function() { myMap.panTo(coords); }, 10) | |
// }); | |
// нам нужно расставить идектификаторы согласно созданной коллекции | |
for (var z = 0; z <= finalDataCounter; z++) { | |
$('.level2 .sublevel li').eq(z).data('final-data-id', z); | |
} | |
function go_to(lat,lon,finalDataId){ | |
//Находим объект по id, который получаем при клике по элементу списка | |
var object = objectManager.objects.getById(finalDataId); | |
var coords = object.geometry.coordinates; | |
var objectState = objectManager.getObjectState(finalDataId); | |
myMap.setCenter(coords); | |
myMap.setZoom(18); | |
// закрываем если уже открыт баллун кликом по метке | |
if(myMap.balloon.isOpen()) { | |
myMap.balloon.close(); | |
} | |
// Откроем программно балун на метке с нужным id | |
setTimeout(function() { | |
objectManager.objects.balloon.open(finalDataId); | |
},10); | |
return false; | |
} | |
// myMap.setBounds(objectManager.getBounds(), { | |
// checkZoomRange: true // проверяем наличие тайлов на данном масштабе. | |
// }); | |
$('.level2 .sublevel li').click(function () { | |
loadFilialInfo($(this).attr('data-id')); | |
var address = $('label', this).text().trim(); | |
var filialId = $(this).data('filial-id'); | |
var finalDataId = $(this).data('final-data-id'); | |
console.log(finalDataId); | |
var isMainOffice = $(this).data('main-office'), | |
coord_lat = $(this).attr('data-coords_X'), | |
coord_lon = $(this).attr('data-coords_Y'); | |
// Область видимости геообъекта. | |
go_to(coord_lat, coord_lon, finalDataId); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment