K
K
kippusen2015-09-29 09:01:00
1C-Bitrix
kippusen, 2015-09-29 09:01:00

How to deal with "cannot read property panTo of undefined" in YaMaps?

Good afternoon.
I'm trying to set up a map in the Bitrix component so that when a city is selected, the map moves to the required coordinates, but I get this error

Uncaught TypeError: Cannot read property 'panTo' of undefined(…)

Please tell me what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kippusen, 2015-09-29
@kippusen

The problem was solved by writing a function in script.js in the map template

function click(map){
  $(".town-select").on('click', 'a', function () {
    map.panTo([$(this).data('coords').split(',')], {flying: true});
  })
}

and call it immediately after adding labels
map.geoObjects.add(obPlacemark);
  click(map);
  return obPlacemark;

A
Andrey Goncharov, 2015-09-29
@agmegadeth

У меня работает такая конструкция. Я не уверен, может быть дело в версии подключенного апи. Вторая версия поддерживает точно panTo.

myMap.panTo([56.13238398110529,40.408], {
    flying: 1
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question