Skip to content

Как отцентрировать карту по скоплению близлежащих маркеров? #257

Closed Answered by daniluk4000
svk-man asked this question in Q&A (2.x)
Discussion options

You must be logged in to vote

Хаюшки! Кроме geoObjects всё просто, и промис вам не нужен.

<template>
    <yandex-map v-model="map">...</yandex-map>
</template>

<script setup lang="ts">
import { shallowRef } from 'vue';
import type { YMap } from '@yandex/ymaps3-types';

const map = shallowRef<YMap | null>(null);

const recenter = () => {
  if (!map.value) return;

  //setTimeout это был костыль наверное?
  map.value.setLocation({ bounds: getAllMarkersBounds() }).then(() => {
    if (map.value!.zoom > 16) { map.value!.setLocation({ zoom: 16 }) }
  })
}

watch([map, currentCity], () => {
    recenter();
});
</script>

По поводу geoObjects и getAllMarkersBounds. Я не знаю простых способов получить эту информацию в Картах …

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@svk-man
Comment options

@daniluk4000
Comment options

@svk-man
Comment options

Answer selected by svk-man
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants