Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@ Yandex Maps API as an Angular JS direcitive.
Добавляет Яндекс-карту на страницу. Размеры карты определяются размерами элемента, их можно задать в css. При
создании нужно указать два обязательных атрибута:

* **center**(Array) - массив из двух чисел, широта и долгота центра карты
* **zoom**(Number) - число, от 0 до 23, масштаб карты. Во избежание ошибок нужно задавать разрешенный масштаб для
* **center**(Array / String)
В случае указания строки 'auto', будет произведено автоматическое определение месторасположения пользователя
В противном случае необходимо указать массив из двух чисел - широта и долгота центра карты

* **zoom**(Number / String)
В случае указания строки 'auto' будет автоматически вычислен масштаб, которые необходимо установить карте
для того, чтобы полностью отобразить переданную область. Режим 'auto' работает исключительно в паре с
автоматическим получением center
В противном случае указывается число от 0 до 23 - масштаб карты. Во избежание ошибок нужно задавать разрешенный масштаб для
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Документация не совпадает с актуальной реализацией в коде

указанной области

####Тег ymap-marker:
Expand Down
33 changes: 32 additions & 1 deletion angular-ymaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ angular.module('ymaps', [])
}
}, 100));
}
function locateAuto(ymaps, continueCallback) {
if ($scope.autocenter) {
ymaps.geolocation.get({ timeout: 2000 }).then(function (res) {
var mapParams = {
center: res.geoObjects.position,
bounds: res.geoObjects.get(0).properties.get('boundedBy'),
zoom: $scope.zoom
};
if ($scope.autozoom) {
var mapContainer = $element[0].getBoundingClientRect();
mapParams.zoom = ymaps.util.bounds
.getCenterAndZoom(
mapParams.bounds,
[mapContainer.width, mapContainer.height]
).zoom;
}
continueCallback(mapParams);
}, function () {});
}
}
var self = this;
ymapsLoader.ready(function(ymaps) {
self.addMarker = function(coordinates, properties, options) {
Expand Down Expand Up @@ -162,7 +182,15 @@ angular.module('ymaps', [])
});
updatingBounds = false;
});

locateAuto(ymaps, function(mapParams) {
var lst = updatingBounds;
updatingBounds = false;
$scope.$apply(function() {
$scope.center = mapParams.center;
$scope.zoom = mapParams.zoom;
});
updatingBounds = lst;
});
});
}])
.directive('yandexMap', ['ymapsLoader', function (ymapsLoader) {
Expand All @@ -172,6 +200,9 @@ angular.module('ymaps', [])
terminal: true,
transclude: true,
scope: {
autocenter: '=',
autozoom: '=',

center: '=',
zoom: '='
},
Expand Down