phpvms/resources/js/maps/base_map.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
* Before you edit these, read the documentation on how these files are compiled:
2020-09-05 01:32:39 +08:00
* https://docs.phpvms.net/developers/building-assets
*
* Edits here don't take place until you compile these assets and then upload them.
2020-10-23 20:08:41 +08:00
* Available providers: https://leaflet-extras.github.io/leaflet-providers/preview/
*/
2018-05-15 03:14:27 +08:00
const leaflet = require('leaflet');
2018-05-15 03:14:27 +08:00
require('leaflet-providers');
export default (_opts) => {
const opts = Object.assign({
render_elem: 'map',
center: [29.98139, -95.33374],
zoom: 5,
maxZoom: 10,
layers: [],
set_marker: false,
2020-10-23 20:08:41 +08:00
leafletOptions: {},
}, _opts);
2020-10-23 20:08:41 +08:00
const leafletOptions = Object.assign({
center: opts.center,
zoom: opts.zoom,
scrollWheelZoom: false,
2020-10-23 20:08:41 +08:00
providers: {},
}, opts.leafletOptions);
2020-10-23 20:08:41 +08:00
// Check if any providers are listed; if not, set the default
if (Object.entries(leafletOptions.providers).length === 0) {
leafletOptions.providers = {
'Esri.WorldStreetMap': {},
};
}
const map = leaflet.map('map', leafletOptions);
// eslint-disable-next-line guard-for-in,no-restricted-syntax
for (const key in leafletOptions.providers) {
leaflet.tileLayer
.provider(key, leafletOptions.providers[key])
.addTo(map);
}
return map;
};