Карту под спойлером изменяет масштабы

veleg
На сайте с 30.01.2011
Offline
142
720

Запихивая карту под спойлер, изменяется масштаб.

Юзаю leafletsjs

Собсна весь код:

Бери, вставляй, проверяй

<link rel="stylesheet" href="http://stopom.ru/wp-content/themes/wt_tera/maps/leaflet.css" />
<script src="http://stopom.ru/wp-content/themes/wt_tera/maps/leaflet.js"></script>

<script type="text/javascript">var coords = [ L.latLng(43.47103,40.5337), L.latLng(43.47155,40.53335), L.latLng(43.47174,40.53262),];</script>
<details>
<summary>Текст</summary>
<div id="map" style=" width: 720px; height: 480px;"></div>
</details>

<script type="text/javascript">

var map = L.map('map');
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '',
center: [43.47392,40.50802],
maxZoom: 15,
scrollWheelZoom:false,
}).addTo(map);

var line = L.polyline(coords, {
distanceMarkers: { showAll: 10, cssClass: 'some-other-class' }
});
var line = L.polyline(coords, {
distanceMarkers: { lazy: true }
});
L.marker([43.47509,40.5064]).addTo(map)
.bindPopup('Озеро Малая Рица')
.openPopup();
map.fitBounds(line.getBounds());
map.addLayer(line);
L.marker([43.47103,40.5337]).addTo(map)
.bindPopup('Озеро Рица')
.openPopup();
map.fitBounds(line.getBounds());
map.addLayer(line);

</script>

Без спойлера, отображается как надо.

Как закрепить масштаб?

Фигачу Телеграм-ботов ( https://teleg.run/veleg )
tommy-gung
На сайте с 22.11.2006
Offline
287
#1

инициализируй карту при раскрытии спойлера

Здесь не могла быть ваша реклама
veleg
На сайте с 30.01.2011
Offline
142
#2
tommy-gung:
инициализируй карту при раскрытии спойлера

с js туговато. Могу править только совсем явные ващи. Можно пример если не сложно?

Samail
На сайте с 10.05.2007
Offline
361
#3

Так можно:


<link rel="stylesheet" href="http://stopom.ru/wp-content/themes/wt_tera/maps/leaflet.css" />
<script src="http://stopom.ru/wp-content/themes/wt_tera/maps/leaflet.js"></script>

<script type="text/javascript">var coords = [ L.latLng(43.47103,40.5337), L.latLng(43.47155,40.53335), L.latLng(43.47174,40.53262),];</script>
<details
<summary onClick="setTimeout(function() {mp();}, 100);">Текст</summary>
<div id="map" style=" width: 720px; height: 480px;"></div>
</details>

<script type="text/javascript">
function mp() {
var map = L.map('map');
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '',
center: [43.47392,40.50802],
maxZoom: 15,
scrollWheelZoom:false,
}).addTo(map);

var line = L.polyline(coords, {
distanceMarkers: { showAll: 10, cssClass: 'some-other-class' }
});
var line = L.polyline(coords, {
distanceMarkers: { lazy: true }
});
L.marker([43.47509,40.5064]).addTo(map)
.bindPopup('Озеро Малая Рица')
.openPopup();
map.fitBounds(line.getBounds());
map.addLayer(line);
L.marker([43.47103,40.5337]).addTo(map)
.bindPopup('Озеро Рица')
.openPopup();
map.fitBounds(line.getBounds());
map.addLayer(line);
}
</script>
veleg
На сайте с 30.01.2011
Offline
142
#4

Благодарю, все работает.

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий