Hopefully somebody can help me to centre correct. I'm not sure were the problem comes from, because it seems that the problem only exist on the PC screen and on my mobile screen it is correct.
After I resize the size of the browser window the markers are centred correct. But how to do that automatic?
The problem is shown since I updated from leaflet 0.7 to 1.0.3
On the map are shown several markers and polylines. At the end I try to fit the markers with:
map.fitBounds(myBounds,{maxZoom:10});
map.invalidateSize();
myBounds are the bounds of the markers.
var myBounds = pline2.getBounds();
To test I made this pline between all added markers:
var marker = L.marker(".$event->getLatLonJSArray().", { icon: myIcon, title: '".$title."'}).addTo(map);
pline2.addLatLng(".$event->getLatLonJSArray().");
The map is not centred to the bounds, but the centre is more north from the markers. If zoomed in to much the markers are even out of the viewbox.
If I do invalidateSize() before fitBounds the picture look as underneath. Also than it's corrected afted I resize the browserwindow.
Who can help me with the correct code for centring the map?
Thanks for reaction!
The complete taken from the browser development tools:
<script>
var MapData = 'Map data © OpenStreetMap contributors';
var Imagenary = ' | Imagery © Mapbox';
var osm = L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{
attribution: MapData,
maxZoom: 18
});
var mapbox = L.tileLayer('//{s}.tiles.mapbox.com/v3/oddityoverseer13.ino7n4nl/{z}/{x}/ {y}.png',
{
attribution: MapData + Imagenary,
maxZoom: 18
});
var map = L.map('osm-map'); //.fitWorld().setZoom(10);
osm.addTo(map);
var baseLayers = {
'Mapbox': mapbox,
'OpenStreetMap': osm
};
L.control.layers(baseLayers).addTo(map);
var pline2 = L.polyline([], {color: "black"});var polyline = L.polyline([], {color: 'red', opacity:'0.6'});
var myHtml = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-icon-svg" width="25" height="50"><path class="svg-icon-path" d="M 0.5 13 C 0.5 25 12.5 20 12.5 49.5 C 12.5 20 24.5 25 24.5 12.5 A 6.25 6.25 0 0 0 0.5 12.5 M 2.5 12.5 A 10 10 0 0 1 22.5 12.5 A 10 10 0 0 1 2.5 12.5 Z" stroke-width="1" stroke="red" fill="red"></path></svg>';
var myIcon = L.divIcon({className: 'my-div-icon icon-resi', iconSize: [25,50], iconAnchor: [12.5,50], popupAnchor: [0,-50], html: myHtml });
var marker = L.marker([52.16201,4.50147], { icon: myIcon, title: ' hij zelf: Paulus Dircksz Planjer (–) | Woonplaats: 8 augustus 1650 — Leiden'}).addTo(map);
marker.bindPopup('<span class="label"><i class="icon-selected"></i> hij zelf: </span><span class="NAME" dir="auto" translate="no">Paulus Dircksz <span class="SURN">Planjer</span></span> (<span title=""></span>–<span title=""></span>)<div class="fact_RESI"><span class="label">Woonplaats:</span> <span class="field" dir="auto"><span class="date">8 augustus 1650</span> — <span title="Leiden, Zuid-Holland, Nederland" dir="auto">Leiden</span></span></div>');
polyline.addLatLng([52.16201,4.50147]);
pline2.addLatLng([52.16201,4.50147]);
polyline.addTo(map);
var myHtml = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-icon-svg" width="25" height="50"><path class="svg-icon-path" d="M 0.5 13 C 0.5 25 12.5 20 12.5 49.5 C 12.5 20 24.5 25 24.5 12.5 A 6.25 6.25 0 0 0 0.5 12.5 M 2.5 12.5 A 10 10 0 0 1 22.5 12.5 A 10 10 0 0 1 2.5 12.5 Z" stroke-width="1" stroke="red" fill="red"></path></svg>';
var myIcon = L.divIcon({className: 'my-div-icon icon-resi', iconSize: [25,50], iconAnchor: [12.5,50], popupAnchor: [0,-50], html: myHtml });
var marker = L.marker([52.1624538,4.5015904], { icon: myIcon, title: ' hij zelf: Paulus Dircksz Planjer (–) | Woonplaats: 28 juni 1669 — Leiden'}).addTo(map);
marker.bindPopup('<span class="label"><i class="icon-selected"></i> hij zelf: </span><span class="NAME" dir="auto" translate="no">Paulus Dircksz <span class="SURN">Planjer</span></span> (<span title=""></span>–<span title=""></span>)<div class="fact_RESI"><span class="label">Woonplaats:</span> <span class="field" dir="auto"><span class="date">28 juni 1669</span> — <span title="Leiden, Zuid-Holland, Nederland" dir="auto">Leiden</span></span></div>');
polyline.addLatLng([52.1624538,4.5015904]);
pline2.addLatLng([52.1624538,4.5015904]);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
var polyline = L.polyline([], {color: 'blue', opacity:'0.6'});
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
var polyline = L.polyline([], {color: 'green', opacity:'0.6'});
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
var polyline = L.polyline([], {color: 'purple', opacity:'0.6'});
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
var polyline = L.polyline([], {color: 'orange', opacity:'0.6'});
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
var polyline = L.polyline([], {color: 'darkred', opacity:'0.6'});
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
var polyline = L.polyline([], {color: 'salmon', opacity:'0.6'});
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
var polyline = L.polyline([], {color: 'beige', opacity:'0.6'});
var myHtml = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-icon-svg" width="25" height="50"><path class="svg-icon-path" d="M 0.5 13 C 0.5 25 12.5 20 12.5 49.5 C 12.5 20 24.5 25 24.5 12.5 A 6.25 6.25 0 0 0 0.5 12.5 M 2.5 12.5 A 10 10 0 0 1 22.5 12.5 A 10 10 0 0 1 2.5 12.5 Z" stroke-width="1" stroke="beige" fill="beige"></path></svg>';
var myIcon = L.divIcon({className: 'my-div-icon icon-birt', iconSize: [25,50], iconAnchor: [12.5,50], popupAnchor: [0,-50], html: myHtml });
var marker = L.marker([52.15890,4.49268], { icon: myIcon, title: 'Dochter: Dina Paulusdr Planjer (1661–) | Gedoopt: 6 februari 1661 — Leiden'}).addTo(map);
marker.bindPopup('<span class="label">Dochter: </span><span class="NAME" dir="auto" translate="no">Dina <span class="SURN">Paulusdr Planjer</span></span> (<span title="6 februari 1661">1661</span>–<span title=""></span>)<div class="fact_CHR"><span class="label">Gedoopt:</span> <span class="field" dir="auto"><span class="date">6 februari 1661</span> — <span title="Leiden, Zuid-Holland, Nederland" dir="auto">Leiden</span></span></div>');
polyline.addLatLng([52.15890,4.49268]);
pline2.addLatLng([52.15890,4.49268]);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
var polyline = L.polyline([], {color: 'darkblue', opacity:'0.6'});
var myHtml = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-icon-svg" width="25" height="50"><path class="svg-icon-path" d="M 0.5 13 C 0.5 25 12.5 20 12.5 49.5 C 12.5 20 24.5 25 24.5 12.5 A 6.25 6.25 0 0 0 0.5 12.5 M 2.5 12.5 A 10 10 0 0 1 22.5 12.5 A 10 10 0 0 1 2.5 12.5 Z" stroke-width="1" stroke="darkblue" fill="darkblue"></path></svg>';
var myIcon = L.divIcon({className: 'my-div-icon icon-birt', iconSize: [25,50], iconAnchor: [12.5,50], popupAnchor: [0,-50], html: myHtml });
var marker = L.marker([52.15890,4.49268], { icon: myIcon, title: 'Zoon: Jacobus Paulusz Planjer (1662–) | Gedoopt: 12 maart 1662 — Leiden'}).addTo(map);
marker.bindPopup('<span class="label">Zoon: </span><span class="NAME" dir="auto" translate="no">Jacobus <span class="SURN">Paulusz Planjer</span></span> (<span title="12 maart 1662">1662</span>–<span title=""></span>)<div class="fact_CHR"><span class="label">Gedoopt:</span> <span class="field" dir="auto"><span class="date">12 maart 1662</span> — <span title="Leiden, Zuid-Holland, Nederland" dir="auto">Leiden</span></span></div>');
polyline.addLatLng([52.15890,4.49268]);
pline2.addLatLng([52.15890,4.49268]);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
var polyline = L.polyline([], {color: 'darkgreen', opacity:'0.6'});
var myHtml = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-icon-svg" width="25" height="50"><path class="svg-icon-path" d="M 0.5 13 C 0.5 25 12.5 20 12.5 49.5 C 12.5 20 24.5 25 24.5 12.5 A 6.25 6.25 0 0 0 0.5 12.5 M 2.5 12.5 A 10 10 0 0 1 22.5 12.5 A 10 10 0 0 1 2.5 12.5 Z" stroke-width="1" stroke="darkgreen" fill="darkgreen"></path></svg>';
var myIcon = L.divIcon({className: 'my-div-icon icon-birt', iconSize: [25,50], iconAnchor: [12.5,50], popupAnchor: [0,-50], html: myHtml });
var marker = L.marker([52.15890,4.49268], { icon: myIcon, title: 'Zoon: Paulus Planjer (1664–) | Gedoopt: 23 maart 1664 — Leiden'}).addTo(map);
marker.bindPopup('<span class="label">Zoon: </span><span class="NAME" dir="auto" translate="no">Paulus <span class="SURN">Planjer</span></span> (<span title="23 maart 1664">1664</span>–<span title=""></span>)<div class="fact_CHR"><span class="label">Gedoopt:</span> <span class="field" dir="auto"><span class="date">23 maart 1664</span> — <span title="Leiden, Zuid-Holland, Nederland" dir="auto">Leiden</span></span></div>');
polyline.addLatLng([52.15890,4.49268]);
pline2.addLatLng([52.15890,4.49268]);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
var polyline = L.polyline([], {color: 'cadetblue', opacity:'0.6'});
var myHtml = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-icon-svg" width="25" height="50"><path class="svg-icon-path" d="M 0.5 13 C 0.5 25 12.5 20 12.5 49.5 C 12.5 20 24.5 25 24.5 12.5 A 6.25 6.25 0 0 0 0.5 12.5 M 2.5 12.5 A 10 10 0 0 1 22.5 12.5 A 10 10 0 0 1 2.5 12.5 Z" stroke-width="1" stroke="cadetblue" fill="cadetblue"></path></svg>';
var myIcon = L.divIcon({className: 'my-div-icon icon-birt', iconSize: [25,50], iconAnchor: [12.5,50], popupAnchor: [0,-50], html: myHtml });
var marker = L.marker([52.15890,4.49268], { icon: myIcon, title: 'Zoon: Paulus Planjer (1666–) | Gedoopt: 7 februari 1666 — Leiden'}).addTo(map);
marker.bindPopup('<span class="label">Zoon: </span><span class="NAME" dir="auto" translate="no">Paulus <span class="SURN">Planjer</span></span> (<span title="7 februari 1666">1666</span>–<span title=""></span>)<div class="fact_CHR"><span class="label">Gedoopt:</span> <span class="field" dir="auto"><span class="date">7 februari 1666</span> — <span title="Leiden, Zuid-Holland, Nederland" dir="auto">Leiden</span></span></div>');
polyline.addLatLng([52.15890,4.49268]);
pline2.addLatLng([52.15890,4.49268]);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
var polyline = L.polyline([], {color: 'darkslateblue', opacity:'0.6'});
var myHtml = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="svg-icon-svg" width="25" height="50"><path class="svg-icon-path" d="M 0.5 13 C 0.5 25 12.5 20 12.5 49.5 C 12.5 20 24.5 25 24.5 12.5 A 6.25 6.25 0 0 0 0.5 12.5 M 2.5 12.5 A 10 10 0 0 1 22.5 12.5 A 10 10 0 0 1 2.5 12.5 Z" stroke-width="1" stroke="darkslateblue" fill="darkslateblue"></path></svg>';
var myIcon = L.divIcon({className: 'my-div-icon icon-birt', iconSize: [25,50], iconAnchor: [12.5,50], popupAnchor: [0,-50], html: myHtml });
var marker = L.marker([52.15890,4.49268], { icon: myIcon, title: 'Zoon: Johannes Planjer (1669–) | Gedoopt: 14 april 1669 — Leiden'}).addTo(map);
marker.bindPopup('<span class="label">Zoon: </span><span class="NAME" dir="auto" translate="no">Johannes <span class="SURN">Planjer</span></span> (<span title="14 april 1669">1669</span>–<span title=""></span>)<div class="fact_CHR"><span class="label">Gedoopt:</span> <span class="field" dir="auto"><span class="date">14 april 1669</span> — <span title="Leiden, Zuid-Holland, Nederland" dir="auto">Leiden</span></span></div>');
polyline.addLatLng([52.15890,4.49268]);
pline2.addLatLng([52.15890,4.49268]);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
polyline.addTo(map);
pline2.addTo(map);var myBounds2 = pline2.getBounds();map.fitBounds(myBounds2,{maxZoom:10});
map.invalidateSize();
</script>
Could not reproduce your issue outside of your framework (Webtrees.net?):
http://playground-leaflet.rhcloud.com/huto/1/edit?html,output
What may happen is that your map container size is adjusted several times before and after your code runs.
The fact that everything works fine when you resize your browser window is indeed a very good indicator that Leaflet could not retrieve the correct map container size, and you were probably right trying to execute map.invalidateSize(). However your map container still changes size before and after that, since changing your map view does not results in expected view.
A blind workaround could be to execute the size invalidation and map view change after some delay, hoping that your framework settles down your map container size in the meantime.
setTimeout(function () {
map.invalidateSize();
map.fitBounds(myBounds2, {
maxZoom: 10
});
}, 500); // Adjust the value (in ms)
Of course the proper resolution would be to make sure if the issue comes indeed from map container size being changed, then how to know once the size reaches its final state, and execute the above code at that moment.
If this does not solve your issue, even when using a long delay (like a few seconds), then the issue might be different.
BTW: your new screenshot shows some sort of tabs at the top. In that case, make sure you run invalidateSize after your tab is revealed, and change again the map view after that.
See: Data-toggle tab does not download Leaflet map
I'm using Dokuwiki and want to get rid built-in code box (boxes with grey outline) when using Syntaxhighlighter3.
Appreciate if anyone know how to do this.
Add these lines to the css file (in your case shCore.css)
box-shadow: 0 0 0 0 !important;
The file sxh3\styles\shCore.css ( when the above line is inserted at line 28 ) would like as follows:
.syntaxhighlighter table tbody,
.syntaxhighlighter table thead,
.syntaxhighlighter table caption,
.syntaxhighlighter textarea {
-moz-border-radius: 0 0 0 0 !important;
-webkit-border-radius: 0 0 0 0 !important;
box-shadow: 0 0 0 0 !important; /* <-- this line */
background: none !important;
border: 0 !important;
bottom: auto !important;
float: none !important;
height: auto !important;