地图在点击后未显示。

huangapple go评论126阅读模式
英文:

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;"> ';
英文:

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 &#39;&lt;div id=&quot;site&quot;&gt; &#39;;
echo &#39;&lt;div id=&quot;map&quot; style=&quot;width:600px;height:400px;display:none;background:red;&quot;&gt; &#39;;
echo &#39;&lt;/div&gt;&#39;;
echo &#39;&lt;div id=&quot;fire&quot; style=&quot;width:200px;height:100px;background:black;&quot;&gt; show me!&#39;;
echo &#39;&lt;/div&gt;&#39;;
echo &#39;&lt;/div&gt;&#39;;

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], &#39;EPSG:4326&#39;, &#39;EPSG:3857&#39;),
    					rotation: 0,
                        zoom: 10
          });
    	
    //********************************************************************************* 
    	
                // Map
                var pdf_map = new ol.Map({ 
    			           target: &#39;map&#39;,
    				                layers: [
    							 pdf_map_source 
            				     ]
    					 ,
                    
                    
                    view: pdf_view
               });
    
    //---------------------------------------------------- fire event ------------------------------------------------
    
         $(document).on(&quot;click&quot;,&quot;#fire&quot;, function () {
        	$(&#39;#map&#39;).show(1);
    	    });

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

echo &#39;&lt;div id=&quot;map&quot; style=&quot;width:600px;height:400px;display:block;background:red;&quot;&gt; &#39;;

答案1

得分: 2

如果您必须在使地图 div 可见之前创建地图,请尝试:

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

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

     $(document).on(&quot;click&quot;,&quot;#fire&quot;, function () {
        $(&#39;#map&#39;).show(1);
          pdf_map.updateSize();
        });

huangapple
  • 本文由 发表于 2020年1月7日 00:11:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/59615360.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定