N
N
Nikolay2016-07-07 16:02:57
JavaScript
Nikolay, 2016-07-07 16:02:57

Why can't the map be shown on click?

Hello!
Please tell me what the problem might be:
We have: We
load the div1 layer with ajax , this layer has a link link and another hidden layer div2 , when you click on the link (we get the map layer id from the link) we show the hidden div2 layer and initialize the map .

<div id="div1">
  <a href="#" id="link"><!-- По клику на эту ссылку мы создаём/показываем карту --></a>
  <div id="div2"><!-- Сюда грузится карта --></div>
</div>

Code snippet:
function init() {
    var myMap
        tcName = $(this).attr('class'),
        tid = tcName.split(/\s+/)[1];
        // ... и другие переменные

    $('#show_fmap').bind({
        click: function(e) {
           e.preventDefault();

           // здесь идёт код (если надо, могу выложить)

           myMap = new ymaps.Map(tid, {
               center: [55.75399400, 37.62209300],
               zoom: 9,
               controls: ["trafficControl", "typeSelector", "rulerControl"]
           });
           // здесь идёт код (если надо, могу выложить)
    });
}
​
ymaps.ready(init);

On my local server (server on apache, page without ajax) everything works great.
In production (server on nginx, page just with ajax) everything can:
  • don't work
  • work the first time
  • work times from 10 (after "refresh")

I'm at a loss: is it because of ajax, or what's wrong with the server? x_x

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IceJOKER, 2016-07-07
@iNickolay

You have some strange code, but here are the steps how to do it:
1. Initially hide the map display button
2. In the function call, initshow the button and hang the handler (you can hang the handler earlier, but I don’t see the point until the map is prepared)
3. On click, we create a map and show it.
If you do everything correctly and in order, then everything should work correctly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question