2020-09-04 23:50:05 +08:00
|
|
|
/**
|
|
|
|
* Before you edit these, read the documentation on how these files are compiled:
|
|
|
|
* https://docs.phpvms.net/customize/building-assets
|
|
|
|
*
|
|
|
|
* Edits here don't take place until you compile these assets and then upload them.
|
|
|
|
*/
|
2018-03-28 07:18:25 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
import draw_base_map from './base_map';
|
2018-04-01 04:57:30 +08:00
|
|
|
import { addWMSLayer } from './helpers';
|
2018-03-13 06:30:52 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
const leaflet = require('leaflet');
|
|
|
|
|
2018-03-13 06:30:52 +08:00
|
|
|
/**
|
|
|
|
* Render a map with the airspace, etc around a given set of coords
|
|
|
|
* e.g, the airport map
|
2019-08-30 20:08:00 +08:00
|
|
|
* @param {Object} _opts
|
2018-03-13 06:30:52 +08:00
|
|
|
*/
|
2019-08-30 20:08:00 +08:00
|
|
|
export default (_opts) => {
|
|
|
|
const opts = Object.assign({
|
2018-03-14 22:07:41 +08:00
|
|
|
render_elem: 'map',
|
|
|
|
overlay_elem: '',
|
|
|
|
lat: 0,
|
|
|
|
lon: 0,
|
|
|
|
zoom: 12,
|
|
|
|
layers: [],
|
2018-03-28 07:18:25 +08:00
|
|
|
set_marker: true,
|
2018-04-01 04:57:30 +08:00
|
|
|
marker_popup: '',
|
|
|
|
|
|
|
|
// Passed from the config/maps.php file
|
|
|
|
metar_wms: {
|
2019-08-30 20:08:00 +08:00
|
|
|
url: '',
|
|
|
|
params: {},
|
2018-04-01 04:57:30 +08:00
|
|
|
},
|
2019-08-30 20:08:00 +08:00
|
|
|
}, _opts);
|
2018-03-13 06:30:52 +08:00
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
const map = draw_base_map(opts);
|
2018-04-01 04:57:30 +08:00
|
|
|
const coords = [opts.lat, opts.lon];
|
|
|
|
console.log('Applying coords', coords);
|
2018-03-13 06:30:52 +08:00
|
|
|
|
2018-04-01 04:57:30 +08:00
|
|
|
map.setView(coords, opts.zoom);
|
2018-03-14 22:07:41 +08:00
|
|
|
if (opts.set_marker === true) {
|
2018-04-01 04:57:30 +08:00
|
|
|
leaflet.marker(coords).addTo(map).bindPopup(opts.marker_popup);
|
|
|
|
}
|
|
|
|
|
2019-08-30 20:08:00 +08:00
|
|
|
if (opts.metar_wms.url !== '') {
|
|
|
|
addWMSLayer(map, opts.metar_wms);
|
2018-03-14 22:07:41 +08:00
|
|
|
}
|
2018-03-13 06:30:52 +08:00
|
|
|
|
2018-04-01 04:57:30 +08:00
|
|
|
return map;
|
2018-03-13 06:30:52 +08:00
|
|
|
};
|