Rafik73
Rafik73

Reputation: 51

The map is not displayed after clicking

I have a problem displaying the map in the div container. When I click the div 'fire', the div 'map' shows but does not display the map. If I zoom in (Chrome ctrl and +) the map appears. If I set the display to block, the map loads into the container. How to make the map appear after clicking 'fire'?

PHP:

echo '<div id="site"> ';
echo '<div id="map" style="width:600px;height:400px;display:none;background:red;"> ';
echo '</div>';
echo '<div id="fire" style="width:200px;height:100px;background:black;"> show me!';
echo '</div>';
echo '</div>';

JS:

    var pdf_map_source_loaded_source = new ol.source.OSM();
    var pdf_map_source = new ol.layer.Tile({source: pdf_map_source_loaded_source , zIndex:9999});

        //*********************************************************************************        
         var pdf_view = new ol.View({
            center: ol.proj.transform([20.328150146900917 , 51.75598647643658], 'EPSG:4326', 'EPSG:3857'),
                        rotation: 0,
                        zoom: 10
          });

    //********************************************************************************* 

                // Map
                var pdf_map = new ol.Map({ 
                           target: 'map',
                                    layers: [
                                 pdf_map_source 
                                 ]
                         ,


                    view: pdf_view
               });

    //---------------------------------------------------- fire event ------------------------------------------------

         $(document).on("click","#fire", function () {
            $('#map').show(1);
            });

with display: block the map is displayed after refreshing the page:

echo '<div id="map" style="width:600px;height:400px;display:block;background:red;"> ';

Upvotes: 0

Views: 78

Answers (1)

Mike
Mike

Reputation: 17907

If you have to create the map before making the map div visible try

     $(document).on("click","#fire", function () {
        $('#map').show(1);
          pdf_map.updateSize();
        });

Upvotes: 2

Related Questions