2020-09-04 23:50:05 +08:00
|
|
|
/**
|
|
|
|
* 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
|
2020-09-04 23:50:05 +08:00
|
|
|
*
|
|
|
|
* 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/
|
2020-09-04 23:50:05 +08:00
|
|
|
*/
|
2018-05-15 03:14:27 +08:00
|
|
|
|
2018-03-28 07:18:25 +08:00
|
|
|
const leaflet = require('leaflet');
|
2018-05-15 03:14:27 +08:00
|
|
|
require('leaflet-providers');
|
2018-03-13 06:30:52 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
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: {},
|
2019-08-30 20:08:00 +08:00
|
|
|
}, _opts);
|
|
|
|
|
2020-10-23 20:08:41 +08:00
|
|
|
const leafletOptions = Object.assign({
|
2019-08-30 20:08:00 +08:00
|
|
|
center: opts.center,
|
|
|
|
zoom: opts.zoom,
|
|
|
|
scrollWheelZoom: false,
|
2020-10-23 20:08:41 +08:00
|
|
|
providers: {},
|
|
|
|
}, opts.leafletOptions);
|
2019-08-30 20:08:00 +08:00
|
|
|
|
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);
|
|
|
|
}
|
2019-08-30 20:08:00 +08:00
|
|
|
|
|
|
|
return map;
|
2018-03-13 06:30:52 +08:00
|
|
|
};
|