mapserver/public/js/map/MapFactory.js

49 lines
1.4 KiB
JavaScript
Raw Normal View History

import wsChannel from '../WebSocketChannel.js';
import SimpleCRS from './SimpleCRS.js';
import CoordinatesDisplay from './CoordinatesDisplay.js';
import WorldInfoDisplay from './WorldInfoDisplay.js';
2019-09-18 12:53:58 +03:00
import TopRightControl from './TopRightControl.js';
import Overlaysetup from './Overlaysetup.js';
import CustomOverlay from './CustomOverlay.js';
2019-09-18 12:53:58 +03:00
import RealtimeTileLayer from './RealtimeTileLayer.js';
import config from '../config.js';
2024-06-28 17:38:13 +03:00
const BORDER_BOUNDS = 5000;
export function createMap(node, layerId, zoom, lat, lon){
const cfg = config.get();
const map = L.map(node, {
minZoom: 2,
2019-11-30 19:34:30 +03:00
maxZoom: 12,
center: [lat, lon],
zoom: zoom,
2020-06-18 13:40:29 +03:00
crs: SimpleCRS,
maxBounds: L.latLngBounds(
2024-06-28 17:38:13 +03:00
L.latLng(-31000-BORDER_BOUNDS, -31000-BORDER_BOUNDS),
L.latLng(31000+BORDER_BOUNDS, 31000+BORDER_BOUNDS)
2020-06-18 13:40:29 +03:00
)
});
2019-11-30 19:42:04 +03:00
map.attributionControl.addAttribution('<a href="https://github.com/minetest-mapserver/mapserver">Minetest Mapserver</a>');
2019-09-18 12:53:58 +03:00
var tileLayer = new RealtimeTileLayer(wsChannel, layerId, map);
tileLayer.addTo(map);
//All overlays
2019-09-18 12:53:58 +03:00
var overlays = {};
Overlaysetup(cfg, map, overlays);
CustomOverlay(map, overlays);
new CoordinatesDisplay({ position: 'bottomleft' }).addTo(map);
new WorldInfoDisplay(wsChannel, { position: 'bottomright' }).addTo(map);
2019-09-18 12:53:58 +03:00
new TopRightControl({ position: 'topright' }).addTo(map);
2019-09-18 09:42:11 +03:00
//layer control
2019-09-18 12:53:58 +03:00
L.control.layers({}, overlays, { position: "topright" }).addTo(map);
return map;
}