英文:
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 '<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;"> ';
答案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("click","#fire", function () {
$('#map').show(1);
pdf_map.updateSize();
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论