Answer the question
In order to leave comments, you need to log in
Rails 4 + turbolins + yandex map, How to make the map load from turbolinks too?
Actually the question is in the title, now the map works if you reload the page, I tried to use:
$(document).ready(ready)
$(document).on('page:load', ready)
$(document).on('page:update', ready)
var ready = ymaps.ready(init);
var myMap, myPlacemark;
function init(){
var myGeocoder = ymaps.geocode('#{@user.full_address}');
myGeocoder.then(
function (res) {
var coords = res.geoObjects.get(0).geometry.getCoordinates();
myPlacemark = new ymaps.Placemark(coords, {
hintContent: '#{@user.show_nickname}',
balloonContent : '#{@user.show_nickname}; Phone: #{@user.show_phone};'
});
myMap = new ymaps.Map("map", {
center: coords,
zoom: 15
});
myMap.geoObjects. add(myPlacemark);
});
}
Answer the question
In order to leave comments, you need to log in
ymaps.coffee:
window.ya_init = ->
$('.ymap').not('.done').addClass('done').each ->
$m = $(this)
ymaps.geocode($m.data('address'), {results: 1}).then (res) ->
firstGeoObject = res.geoObjects.get(0)
coords = firstGeoObject.geometry.getCoordinates()
map = new ymaps.Map($m[0],
center: coords
zoom: 15,
behaviors: ['default'] #, 'scrollZoom']
)
map.controls.add('zoomControl', { left: 5, top: 5 })
myPlacemark = new ymaps.Placemark(coords)
map.geoObjects.add(myPlacemark)
$ ->
return if $('.ymap').not('.done').length == 0
if window.ymaps
ya_init()
else
$.getScript( "//api-maps.yandex.ru/2.1/?load=package.full&lang=ru-RU&onload=ya_init")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question