Leaflet Map not fully loaded when i open inspect element it will load fully
Below is the function which call on onclick event
function drawMapFromWms(latt,longt){
document.getElementById('hrymap').innerHTML = "";
document.getElementById('hrymap').innerHTML = "<div id='map'></div>";
map = L.map('map').setView([29.0,76.776695], 8);
L.tileLayer.wms("http://example.com", {
layers:'india3',
format: 'image/png',
transparent: true,
attribution:"dummy"
}).addTo(map);
L.tileLayer.wms("http://example.com", {
layers:'hrcm_roads',
format: 'image/png',
transparent: true,
attribution:"dummy"
}).addTo(map);
var marker = L.marker([latt,longt]).addTo(map);
$("#detail_content").css({'display':'block'});
}
Here is the modal div which map div created
<div id="detail_content" class="w3-modal">
<div class="w3-modal-content">
<div class="w3-container">
<span onclick="document.getElementById('detail_content').style.display='none'" class="w3-button w3-display-topright">×</span>
<div class="modal-info">
<div id="hrymap">
</div>
</div>
</div>
</div>
</div>
</div>
And finally function is call
Problem is when i click the button the map is loaded partially like below image
and after inspect element it will loaded fully like below image.
javascript user-interface leaflet maps inspect
add a comment |
Below is the function which call on onclick event
function drawMapFromWms(latt,longt){
document.getElementById('hrymap').innerHTML = "";
document.getElementById('hrymap').innerHTML = "<div id='map'></div>";
map = L.map('map').setView([29.0,76.776695], 8);
L.tileLayer.wms("http://example.com", {
layers:'india3',
format: 'image/png',
transparent: true,
attribution:"dummy"
}).addTo(map);
L.tileLayer.wms("http://example.com", {
layers:'hrcm_roads',
format: 'image/png',
transparent: true,
attribution:"dummy"
}).addTo(map);
var marker = L.marker([latt,longt]).addTo(map);
$("#detail_content").css({'display':'block'});
}
Here is the modal div which map div created
<div id="detail_content" class="w3-modal">
<div class="w3-modal-content">
<div class="w3-container">
<span onclick="document.getElementById('detail_content').style.display='none'" class="w3-button w3-display-topright">×</span>
<div class="modal-info">
<div id="hrymap">
</div>
</div>
</div>
</div>
</div>
</div>
And finally function is call
Problem is when i click the button the map is loaded partially like below image
and after inspect element it will loaded fully like below image.
javascript user-interface leaflet maps inspect
Possible duplicate of Why isn't my map completely showing?
– peeebeee
Jan 2 at 15:34
add a comment |
Below is the function which call on onclick event
function drawMapFromWms(latt,longt){
document.getElementById('hrymap').innerHTML = "";
document.getElementById('hrymap').innerHTML = "<div id='map'></div>";
map = L.map('map').setView([29.0,76.776695], 8);
L.tileLayer.wms("http://example.com", {
layers:'india3',
format: 'image/png',
transparent: true,
attribution:"dummy"
}).addTo(map);
L.tileLayer.wms("http://example.com", {
layers:'hrcm_roads',
format: 'image/png',
transparent: true,
attribution:"dummy"
}).addTo(map);
var marker = L.marker([latt,longt]).addTo(map);
$("#detail_content").css({'display':'block'});
}
Here is the modal div which map div created
<div id="detail_content" class="w3-modal">
<div class="w3-modal-content">
<div class="w3-container">
<span onclick="document.getElementById('detail_content').style.display='none'" class="w3-button w3-display-topright">×</span>
<div class="modal-info">
<div id="hrymap">
</div>
</div>
</div>
</div>
</div>
</div>
And finally function is call
Problem is when i click the button the map is loaded partially like below image
and after inspect element it will loaded fully like below image.
javascript user-interface leaflet maps inspect
Below is the function which call on onclick event
function drawMapFromWms(latt,longt){
document.getElementById('hrymap').innerHTML = "";
document.getElementById('hrymap').innerHTML = "<div id='map'></div>";
map = L.map('map').setView([29.0,76.776695], 8);
L.tileLayer.wms("http://example.com", {
layers:'india3',
format: 'image/png',
transparent: true,
attribution:"dummy"
}).addTo(map);
L.tileLayer.wms("http://example.com", {
layers:'hrcm_roads',
format: 'image/png',
transparent: true,
attribution:"dummy"
}).addTo(map);
var marker = L.marker([latt,longt]).addTo(map);
$("#detail_content").css({'display':'block'});
}
Here is the modal div which map div created
<div id="detail_content" class="w3-modal">
<div class="w3-modal-content">
<div class="w3-container">
<span onclick="document.getElementById('detail_content').style.display='none'" class="w3-button w3-display-topright">×</span>
<div class="modal-info">
<div id="hrymap">
</div>
</div>
</div>
</div>
</div>
</div>
And finally function is call
Problem is when i click the button the map is loaded partially like below image
and after inspect element it will loaded fully like below image.
javascript user-interface leaflet maps inspect
javascript user-interface leaflet maps inspect
asked Jan 1 at 9:19
sumit kundansumit kundan
176
176
Possible duplicate of Why isn't my map completely showing?
– peeebeee
Jan 2 at 15:34
add a comment |
Possible duplicate of Why isn't my map completely showing?
– peeebeee
Jan 2 at 15:34
Possible duplicate of Why isn't my map completely showing?
– peeebeee
Jan 2 at 15:34
Possible duplicate of Why isn't my map completely showing?
– peeebeee
Jan 2 at 15:34
add a comment |
3 Answers
3
active
oldest
votes
As it is created on the fly, your map may not be aware of the size of its container.
Try
map.invalidateSize();
not working with this method
– sumit kundan
Jan 1 at 10:22
Can you reorganize your code so that your map element is created when the page loads ? this will work (yafred.github.io/leaflet-tests/20161209-map-in-a-dialog)
– YaFred
Jan 1 at 13:03
not working in this method also. dialog loaded perfetcly but map height width is not loaded fully
– sumit kundan
Jan 2 at 5:14
Do you mean the example does not work for you ?
– YaFred
Jan 2 at 8:48
add a comment |
You are not initializing the map correctly. You never set the center. Pass a map options argument as your second argument. Should be like:
var map = L.map('map', {center:[29.0, 76.776695], zoom:8});
Here's the docs.
After reading your comment, I believe that it's because the CSS associated with the HTML class
attribute is overriding your less specific CSS. Personally, I would just use more specific CSS, like:
div.modal-info>div#hrymap>div#map.leaflet-container{
width:868px; height:650px;
}
instead of
#map{
width:868px; height:650px;
}
By the way
document.getElementById('hrymap').innerHTML = "";
and
document.getElementById('hrymap').innerHTML = "<div id='map'></div>";
are both assignment. Why do the first one? And why not $('#hrymap').html("<div id='map'></div>")
? When using jQuery, just use it.
If the CSS way doesn't work, try:
$("<div id='map'></div>").appendTo('#hrymap').css({width:'868px', height:'650px'});
Keep in mind that when using using .appendTo()
, following jQuery methods will effect the jQuery selector before .appendTo()
, while jQuery methods following append()
would effect the append()
.
Of course, once again, you should create the HTML structure as much as you can, without using JavaScript. Only do things on the fly when you have to.
i did same but its not working still same problem. Map loaded fully when i open the inspect element
– sumit kundan
Jan 1 at 10:21
In my case map is loaded on boostrap modal may b that is creating a problem
– sumit kundan
Jan 1 at 10:23
not working in my case did same as you suggest
– sumit kundan
Jan 1 at 11:12
when i tried to add appendTo then its give me an error identifier starts immediately after numeric literal
– sumit kundan
Jan 1 at 11:17
I forgot the quotes. If you are putting that in a function that is getting called on a user event you may want to use$('#hrymap').html('')
first, so you're not appending multiples of the same div, because.appendTo
and.append
are like+=
.
– PHPglue
Jan 2 at 8:32
add a comment |
setTimeout(function(){ map.invalidateSize(true)}, 300);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994295%2fleaflet-map-not-fully-loaded-when-i-open-inspect-element-it-will-load-fully%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
As it is created on the fly, your map may not be aware of the size of its container.
Try
map.invalidateSize();
not working with this method
– sumit kundan
Jan 1 at 10:22
Can you reorganize your code so that your map element is created when the page loads ? this will work (yafred.github.io/leaflet-tests/20161209-map-in-a-dialog)
– YaFred
Jan 1 at 13:03
not working in this method also. dialog loaded perfetcly but map height width is not loaded fully
– sumit kundan
Jan 2 at 5:14
Do you mean the example does not work for you ?
– YaFred
Jan 2 at 8:48
add a comment |
As it is created on the fly, your map may not be aware of the size of its container.
Try
map.invalidateSize();
not working with this method
– sumit kundan
Jan 1 at 10:22
Can you reorganize your code so that your map element is created when the page loads ? this will work (yafred.github.io/leaflet-tests/20161209-map-in-a-dialog)
– YaFred
Jan 1 at 13:03
not working in this method also. dialog loaded perfetcly but map height width is not loaded fully
– sumit kundan
Jan 2 at 5:14
Do you mean the example does not work for you ?
– YaFred
Jan 2 at 8:48
add a comment |
As it is created on the fly, your map may not be aware of the size of its container.
Try
map.invalidateSize();
As it is created on the fly, your map may not be aware of the size of its container.
Try
map.invalidateSize();
answered Jan 1 at 9:58
YaFredYaFred
5,59821632
5,59821632
not working with this method
– sumit kundan
Jan 1 at 10:22
Can you reorganize your code so that your map element is created when the page loads ? this will work (yafred.github.io/leaflet-tests/20161209-map-in-a-dialog)
– YaFred
Jan 1 at 13:03
not working in this method also. dialog loaded perfetcly but map height width is not loaded fully
– sumit kundan
Jan 2 at 5:14
Do you mean the example does not work for you ?
– YaFred
Jan 2 at 8:48
add a comment |
not working with this method
– sumit kundan
Jan 1 at 10:22
Can you reorganize your code so that your map element is created when the page loads ? this will work (yafred.github.io/leaflet-tests/20161209-map-in-a-dialog)
– YaFred
Jan 1 at 13:03
not working in this method also. dialog loaded perfetcly but map height width is not loaded fully
– sumit kundan
Jan 2 at 5:14
Do you mean the example does not work for you ?
– YaFred
Jan 2 at 8:48
not working with this method
– sumit kundan
Jan 1 at 10:22
not working with this method
– sumit kundan
Jan 1 at 10:22
Can you reorganize your code so that your map element is created when the page loads ? this will work (yafred.github.io/leaflet-tests/20161209-map-in-a-dialog)
– YaFred
Jan 1 at 13:03
Can you reorganize your code so that your map element is created when the page loads ? this will work (yafred.github.io/leaflet-tests/20161209-map-in-a-dialog)
– YaFred
Jan 1 at 13:03
not working in this method also. dialog loaded perfetcly but map height width is not loaded fully
– sumit kundan
Jan 2 at 5:14
not working in this method also. dialog loaded perfetcly but map height width is not loaded fully
– sumit kundan
Jan 2 at 5:14
Do you mean the example does not work for you ?
– YaFred
Jan 2 at 8:48
Do you mean the example does not work for you ?
– YaFred
Jan 2 at 8:48
add a comment |
You are not initializing the map correctly. You never set the center. Pass a map options argument as your second argument. Should be like:
var map = L.map('map', {center:[29.0, 76.776695], zoom:8});
Here's the docs.
After reading your comment, I believe that it's because the CSS associated with the HTML class
attribute is overriding your less specific CSS. Personally, I would just use more specific CSS, like:
div.modal-info>div#hrymap>div#map.leaflet-container{
width:868px; height:650px;
}
instead of
#map{
width:868px; height:650px;
}
By the way
document.getElementById('hrymap').innerHTML = "";
and
document.getElementById('hrymap').innerHTML = "<div id='map'></div>";
are both assignment. Why do the first one? And why not $('#hrymap').html("<div id='map'></div>")
? When using jQuery, just use it.
If the CSS way doesn't work, try:
$("<div id='map'></div>").appendTo('#hrymap').css({width:'868px', height:'650px'});
Keep in mind that when using using .appendTo()
, following jQuery methods will effect the jQuery selector before .appendTo()
, while jQuery methods following append()
would effect the append()
.
Of course, once again, you should create the HTML structure as much as you can, without using JavaScript. Only do things on the fly when you have to.
i did same but its not working still same problem. Map loaded fully when i open the inspect element
– sumit kundan
Jan 1 at 10:21
In my case map is loaded on boostrap modal may b that is creating a problem
– sumit kundan
Jan 1 at 10:23
not working in my case did same as you suggest
– sumit kundan
Jan 1 at 11:12
when i tried to add appendTo then its give me an error identifier starts immediately after numeric literal
– sumit kundan
Jan 1 at 11:17
I forgot the quotes. If you are putting that in a function that is getting called on a user event you may want to use$('#hrymap').html('')
first, so you're not appending multiples of the same div, because.appendTo
and.append
are like+=
.
– PHPglue
Jan 2 at 8:32
add a comment |
You are not initializing the map correctly. You never set the center. Pass a map options argument as your second argument. Should be like:
var map = L.map('map', {center:[29.0, 76.776695], zoom:8});
Here's the docs.
After reading your comment, I believe that it's because the CSS associated with the HTML class
attribute is overriding your less specific CSS. Personally, I would just use more specific CSS, like:
div.modal-info>div#hrymap>div#map.leaflet-container{
width:868px; height:650px;
}
instead of
#map{
width:868px; height:650px;
}
By the way
document.getElementById('hrymap').innerHTML = "";
and
document.getElementById('hrymap').innerHTML = "<div id='map'></div>";
are both assignment. Why do the first one? And why not $('#hrymap').html("<div id='map'></div>")
? When using jQuery, just use it.
If the CSS way doesn't work, try:
$("<div id='map'></div>").appendTo('#hrymap').css({width:'868px', height:'650px'});
Keep in mind that when using using .appendTo()
, following jQuery methods will effect the jQuery selector before .appendTo()
, while jQuery methods following append()
would effect the append()
.
Of course, once again, you should create the HTML structure as much as you can, without using JavaScript. Only do things on the fly when you have to.
i did same but its not working still same problem. Map loaded fully when i open the inspect element
– sumit kundan
Jan 1 at 10:21
In my case map is loaded on boostrap modal may b that is creating a problem
– sumit kundan
Jan 1 at 10:23
not working in my case did same as you suggest
– sumit kundan
Jan 1 at 11:12
when i tried to add appendTo then its give me an error identifier starts immediately after numeric literal
– sumit kundan
Jan 1 at 11:17
I forgot the quotes. If you are putting that in a function that is getting called on a user event you may want to use$('#hrymap').html('')
first, so you're not appending multiples of the same div, because.appendTo
and.append
are like+=
.
– PHPglue
Jan 2 at 8:32
add a comment |
You are not initializing the map correctly. You never set the center. Pass a map options argument as your second argument. Should be like:
var map = L.map('map', {center:[29.0, 76.776695], zoom:8});
Here's the docs.
After reading your comment, I believe that it's because the CSS associated with the HTML class
attribute is overriding your less specific CSS. Personally, I would just use more specific CSS, like:
div.modal-info>div#hrymap>div#map.leaflet-container{
width:868px; height:650px;
}
instead of
#map{
width:868px; height:650px;
}
By the way
document.getElementById('hrymap').innerHTML = "";
and
document.getElementById('hrymap').innerHTML = "<div id='map'></div>";
are both assignment. Why do the first one? And why not $('#hrymap').html("<div id='map'></div>")
? When using jQuery, just use it.
If the CSS way doesn't work, try:
$("<div id='map'></div>").appendTo('#hrymap').css({width:'868px', height:'650px'});
Keep in mind that when using using .appendTo()
, following jQuery methods will effect the jQuery selector before .appendTo()
, while jQuery methods following append()
would effect the append()
.
Of course, once again, you should create the HTML structure as much as you can, without using JavaScript. Only do things on the fly when you have to.
You are not initializing the map correctly. You never set the center. Pass a map options argument as your second argument. Should be like:
var map = L.map('map', {center:[29.0, 76.776695], zoom:8});
Here's the docs.
After reading your comment, I believe that it's because the CSS associated with the HTML class
attribute is overriding your less specific CSS. Personally, I would just use more specific CSS, like:
div.modal-info>div#hrymap>div#map.leaflet-container{
width:868px; height:650px;
}
instead of
#map{
width:868px; height:650px;
}
By the way
document.getElementById('hrymap').innerHTML = "";
and
document.getElementById('hrymap').innerHTML = "<div id='map'></div>";
are both assignment. Why do the first one? And why not $('#hrymap').html("<div id='map'></div>")
? When using jQuery, just use it.
If the CSS way doesn't work, try:
$("<div id='map'></div>").appendTo('#hrymap').css({width:'868px', height:'650px'});
Keep in mind that when using using .appendTo()
, following jQuery methods will effect the jQuery selector before .appendTo()
, while jQuery methods following append()
would effect the append()
.
Of course, once again, you should create the HTML structure as much as you can, without using JavaScript. Only do things on the fly when you have to.
edited Jan 2 at 8:29
answered Jan 1 at 9:53
PHPgluePHPglue
7,75111024
7,75111024
i did same but its not working still same problem. Map loaded fully when i open the inspect element
– sumit kundan
Jan 1 at 10:21
In my case map is loaded on boostrap modal may b that is creating a problem
– sumit kundan
Jan 1 at 10:23
not working in my case did same as you suggest
– sumit kundan
Jan 1 at 11:12
when i tried to add appendTo then its give me an error identifier starts immediately after numeric literal
– sumit kundan
Jan 1 at 11:17
I forgot the quotes. If you are putting that in a function that is getting called on a user event you may want to use$('#hrymap').html('')
first, so you're not appending multiples of the same div, because.appendTo
and.append
are like+=
.
– PHPglue
Jan 2 at 8:32
add a comment |
i did same but its not working still same problem. Map loaded fully when i open the inspect element
– sumit kundan
Jan 1 at 10:21
In my case map is loaded on boostrap modal may b that is creating a problem
– sumit kundan
Jan 1 at 10:23
not working in my case did same as you suggest
– sumit kundan
Jan 1 at 11:12
when i tried to add appendTo then its give me an error identifier starts immediately after numeric literal
– sumit kundan
Jan 1 at 11:17
I forgot the quotes. If you are putting that in a function that is getting called on a user event you may want to use$('#hrymap').html('')
first, so you're not appending multiples of the same div, because.appendTo
and.append
are like+=
.
– PHPglue
Jan 2 at 8:32
i did same but its not working still same problem. Map loaded fully when i open the inspect element
– sumit kundan
Jan 1 at 10:21
i did same but its not working still same problem. Map loaded fully when i open the inspect element
– sumit kundan
Jan 1 at 10:21
In my case map is loaded on boostrap modal may b that is creating a problem
– sumit kundan
Jan 1 at 10:23
In my case map is loaded on boostrap modal may b that is creating a problem
– sumit kundan
Jan 1 at 10:23
not working in my case did same as you suggest
– sumit kundan
Jan 1 at 11:12
not working in my case did same as you suggest
– sumit kundan
Jan 1 at 11:12
when i tried to add appendTo then its give me an error identifier starts immediately after numeric literal
– sumit kundan
Jan 1 at 11:17
when i tried to add appendTo then its give me an error identifier starts immediately after numeric literal
– sumit kundan
Jan 1 at 11:17
I forgot the quotes. If you are putting that in a function that is getting called on a user event you may want to use
$('#hrymap').html('')
first, so you're not appending multiples of the same div, because .appendTo
and .append
are like +=
.– PHPglue
Jan 2 at 8:32
I forgot the quotes. If you are putting that in a function that is getting called on a user event you may want to use
$('#hrymap').html('')
first, so you're not appending multiples of the same div, because .appendTo
and .append
are like +=
.– PHPglue
Jan 2 at 8:32
add a comment |
setTimeout(function(){ map.invalidateSize(true)}, 300);
add a comment |
setTimeout(function(){ map.invalidateSize(true)}, 300);
add a comment |
setTimeout(function(){ map.invalidateSize(true)}, 300);
setTimeout(function(){ map.invalidateSize(true)}, 300);
answered Jan 2 at 11:14
sumit kundansumit kundan
176
176
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53994295%2fleaflet-map-not-fully-loaded-when-i-open-inspect-element-it-will-load-fully%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Why isn't my map completely showing?
– peeebeee
Jan 2 at 15:34