我正在使用传单创建游戏地图,到目前为止,除了将地图居中之外,其他所有功能都可以正常工作。我希望地图在浏览器中垂直居中。
有没有办法解决这个问题?
我尝试更改//声明地图对象下的L.latLng,但这不能解决问题。
这是我当前的设置方式:
// Variables
var mapSW = [608, 8026],
mapNE = [7574, 146];
// Declare Map Object
var map = L.map('map', {
center: L.latLng(0, 0),
zoom: 4
});
// Reference the tiles
L.tileLayer('maps/velen/{z}/{x}/{y}.png', {
minZoom: 2,
maxZoom: 5,
continuousWorld: false,
noWrap: true,
crs: L.CRS.Simple,
}).addTo(map);
map.setMaxBounds(new L.LatLngBounds(
map.unproject(mapSW, map.getMaxZoom()),
map.unproject(mapNE, map.getMaxZoom())
));
// Icons
var locat = L.icon({
iconUrl: 'images/locat_marker.png',
iconSize: [24, 30],
iconAnchor: [5, 30],
popupAnchor: [5, 44],
});
var quest_marker_lvl1 = L.icon({
iconUrl: 'images/quest_marker_lvl_0.png',
iconSize: [67, 39],
iconAnchor: [5, 39],
popupAnchor: [0, -39],
});
// Markers and Popups
// LatLng
var refmarker = L.marker([0, 0], {
draggable: true,
}).addTo(map);
refmarker.bindPopup('');
refmarker.on('dragend', function(e) {
refmarker.getPopup().setContent('Clicked ' +
refmarker.getLatLng().toString() + '<br />'
+ 'Pixels ' +map.project(refmarker.getLatLng(),
map.getMaxZoom().toString()))
.openOn(map);
});
// Pixels
// Locations
var popupContent = "Hanged Man's Tree";
var popupOptions =
{
autoClose: false,
closeOnClick: false,
closeButton : false,
'className' : 'locat_marker' // classname for another popup
}
var locat_hanged_mans_tree = L.marker(map.unproject([2172, 1924],
map.getMaxZoom()), {icon: locat})
.bindPopup(popupContent, popupOptions).addTo(map).openPopup();
// Quests lvl 1
var quest_fake_pass = L.marker(map.unproject([2033, 1693],
map.getMaxZoom()), {icon: quest_marker_lvl1})
.bindPopup("Fake Pass");
var quest_thou_shall_not_pass = L.marker(map.unproject([2089, 1717],
map.getMaxZoom()), {icon: quest_marker_lvl1})
.bindPopup("Thou Shall Not Pass");
// Layer Groups
var lg_quests = L.layerGroup([quest_fake_pass,
quest_thou_shall_not_pass]).addTo(map);
var lg_locat = L.layerGroup([locat_hanged_mans_tree]).addTo(map);
var baseLayers = {
};
var overlays = {
"Quests" : lg_quests,
"Locations" : lg_locat
};
// Add layer control
L.control.layers(baseLayers, overlays).addTo(map);