0

Подскажите, можно ли в yandex картах сделать привязку радиуса к маркеру или наоборот. По аналогии (как пример Google maps)

<http://jsfiddle.net/kjy112/k6hVa/>

1

1 ответ 1

1

Да, можно. Грязный код будет выглядеть примерно так:

var myCircle = new ymaps.Circle([[55.847, 37.6],10000]);

var circleCenter = myCircle.geometry.getCoordinates();
myMap.geoObjects.add(myCircle);

var center = new ymaps.Placemark(circleCenter, {}, {draggable: true});
var edge = new ymaps.Placemark([55.847, 38.6], {}, {draggable: true});
var projection = myMap.options.get('projection');
var coordSystem = projection.getCoordSystem();
var distance = coordSystem.getDistance(edge.geometry.getCoordinates(), circleCenter);

myCircle.geometry.setRadius(distance);

center.events.add('geometrychange', function() {
  var coords = center.geometry.getCoordinates();
  var offset = [coords[0] - circleCenter[0], coords[1] - circleCenter[1]];
  var edgeCoords = edge.geometry.getCoordinates();
  edge.geometry.setCoordinates([edgeCoords[0] + offset[0], edgeCoords[1] + offset[1]]);
  myCircle.geometry.setCoordinates(coords);
  circleCenter = coords;
});

edge.events.add('geometrychange', function() {
  var coords = edge.geometry.getCoordinates();
  var distance = coordSystem.getDistance(coords, circleCenter);
  myCircle.geometry.setRadius(distance);
})
myMap.geoObjects
.add(center).add(edge);

Пример: https://jsfiddle.net/2rg540Lc/

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.