2018-03-14 22:07:41 +08:00
|
|
|
const _ = require('lodash')
|
|
|
|
const leaflet = require('leaflet')
|
2018-03-13 06:30:52 +08:00
|
|
|
|
2018-03-14 22:07:41 +08:00
|
|
|
import draw_base_map from './base_map'
|
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
|
|
|
|
* @param opts
|
|
|
|
*/
|
|
|
|
export default (opts) => {
|
2018-03-14 22:07:41 +08:00
|
|
|
opts = _.defaults(opts, {
|
|
|
|
render_elem: 'map',
|
|
|
|
overlay_elem: '',
|
|
|
|
lat: 0,
|
|
|
|
lon: 0,
|
|
|
|
zoom: 12,
|
|
|
|
layers: [],
|
|
|
|
set_marker: false,
|
|
|
|
})
|
2018-03-13 06:30:52 +08:00
|
|
|
|
2018-03-14 22:07:41 +08:00
|
|
|
let map = draw_base_map(opts)
|
|
|
|
const coords = [opts.lat, opts.lon]
|
|
|
|
console.log('Applying coords', coords)
|
2018-03-13 06:30:52 +08:00
|
|
|
|
2018-03-14 22:07:41 +08:00
|
|
|
map.setView(coords, opts.zoom)
|
|
|
|
if (opts.set_marker === true) {
|
|
|
|
leaflet.marker(coords).addTo(map)
|
|
|
|
}
|
2018-03-13 06:30:52 +08:00
|
|
|
|
2018-03-14 22:07:41 +08:00
|
|
|
return map
|
2018-03-13 06:30:52 +08:00
|
|
|
};
|