2017-12-27 05:26:12 +08:00
|
|
|
const phpvms = (function() {
|
2017-12-20 05:19:06 +08:00
|
|
|
|
2017-12-20 07:30:30 +08:00
|
|
|
const draw_base_map = (opts) => {
|
2017-12-20 05:19:06 +08:00
|
|
|
|
2017-12-21 01:28:21 +08:00
|
|
|
opts = _.defaults(opts, {
|
|
|
|
render_elem: 'map',
|
|
|
|
zoom: 12,
|
|
|
|
layers: [],
|
|
|
|
set_marker: false,
|
|
|
|
});
|
|
|
|
|
2017-12-20 07:30:30 +08:00
|
|
|
/*var openaip_airspace_labels = new L.TileLayer.WMS(
|
|
|
|
"http://{s}.tile.maps.openaip.net/geowebcache/service/wms", {
|
|
|
|
maxZoom: 14,
|
|
|
|
minZoom: 12,
|
|
|
|
layers: 'openaip_approved_airspaces_labels',
|
|
|
|
tileSize: 1024,
|
|
|
|
detectRetina: true,
|
|
|
|
subdomains: '12',
|
|
|
|
format: 'image/png',
|
|
|
|
transparent: true
|
|
|
|
});
|
2017-12-20 05:19:06 +08:00
|
|
|
|
2017-12-20 07:30:30 +08:00
|
|
|
openaip_airspace_labels.addTo(map);*/
|
2017-12-20 05:19:06 +08:00
|
|
|
|
2017-12-20 07:30:30 +08:00
|
|
|
const opencyclemap_phys_osm = new L.TileLayer(
|
|
|
|
'http://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png?apikey=f09a38fa87514de4890fc96e7fe8ecb1', {
|
|
|
|
maxZoom: 14,
|
|
|
|
minZoom: 4,
|
|
|
|
format: 'image/png',
|
|
|
|
transparent: true
|
|
|
|
});
|
2017-12-20 05:19:06 +08:00
|
|
|
|
2017-12-20 07:30:30 +08:00
|
|
|
const openaip_cached_basemap = new L.TileLayer("http://{s}.tile.maps.openaip.net/geowebcache/service/tms/1.0.0/openaip_basemap@EPSG%3A900913@png/{z}/{x}/{y}.png", {
|
2017-12-20 05:19:06 +08:00
|
|
|
maxZoom: 14,
|
2017-12-20 07:30:30 +08:00
|
|
|
minZoom: 4,
|
|
|
|
tms: true,
|
2017-12-20 05:19:06 +08:00
|
|
|
detectRetina: true,
|
|
|
|
subdomains: '12',
|
|
|
|
format: 'image/png',
|
|
|
|
transparent: true
|
|
|
|
});
|
|
|
|
|
2017-12-20 07:30:30 +08:00
|
|
|
const openaip_basemap_phys_osm = L.featureGroup([opencyclemap_phys_osm, openaip_cached_basemap]);
|
2017-12-20 05:19:06 +08:00
|
|
|
|
2017-12-20 07:30:30 +08:00
|
|
|
let map = L.map('map', {
|
|
|
|
layers: [openaip_basemap_phys_osm],
|
|
|
|
zoom: opts.zoom,
|
|
|
|
scrollWheelZoom: false,
|
2017-12-20 05:19:06 +08:00
|
|
|
});
|
|
|
|
|
2017-12-20 07:30:30 +08:00
|
|
|
const attrib = L.control.attribution({position: 'bottomleft'});
|
|
|
|
attrib.addAttribution("<a href=\"https://www.thunderforest.com\" target=\"_blank\" style=\"\">Thunderforest</a>");
|
|
|
|
attrib.addAttribution("<a href=\"https://www.openaip.net\" target=\"_blank\" style=\"\">openAIP</a>");
|
|
|
|
attrib.addAttribution("<a href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\" style=\"\">OpenStreetMap</a> contributors");
|
|
|
|
attrib.addAttribution("<a href=\"https://www.openweathermap.org\" target=\"_blank\" style=\"\">OpenWeatherMap</a>");
|
|
|
|
|
|
|
|
attrib.addTo(map);
|
|
|
|
|
|
|
|
return map;
|
2017-12-21 01:28:21 +08:00
|
|
|
};
|
2017-12-20 07:30:30 +08:00
|
|
|
|
2017-12-25 07:38:38 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show some popup text when a feature is clicked on
|
|
|
|
* @param feature
|
|
|
|
* @param layer
|
|
|
|
*/
|
|
|
|
const onFeaturePointClick = (feature, layer) => {
|
|
|
|
let popup_html = "";
|
|
|
|
if (feature.properties && feature.properties.popup) {
|
|
|
|
popup_html += feature.properties.popup;
|
|
|
|
}
|
|
|
|
|
|
|
|
layer.bindPopup(popup_html);
|
|
|
|
};
|
|
|
|
|
2017-12-27 05:26:12 +08:00
|
|
|
const pointToLayer = function (feature, latlng) {
|
|
|
|
return L.circleMarker(latlng, {
|
|
|
|
radius: 12,
|
|
|
|
fillColor: "#ff7800",
|
|
|
|
color: "#000",
|
|
|
|
weight: 1,
|
|
|
|
opacity: 1,
|
|
|
|
fillOpacity: 0.8
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-12-20 07:30:30 +08:00
|
|
|
return {
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param opts
|
|
|
|
*/
|
|
|
|
render_route_map: (opts) => {
|
2017-12-21 01:28:21 +08:00
|
|
|
|
2017-12-20 07:30:30 +08:00
|
|
|
opts = _.defaults(opts, {
|
2017-12-25 07:38:38 +08:00
|
|
|
route_points: null,
|
|
|
|
planned_route_line: null, // [ {name, lat, lon}, {name, lat, lon} ];
|
2017-12-27 05:26:12 +08:00
|
|
|
actual_route_points: null,
|
2017-12-25 07:38:38 +08:00
|
|
|
actual_route_line: null,
|
2017-12-21 01:28:21 +08:00
|
|
|
center: [],
|
|
|
|
render_elem: 'map',
|
|
|
|
overlay_elem: '',
|
|
|
|
zoom: 5,
|
2017-12-21 09:12:39 +08:00
|
|
|
geodesic: true,
|
2017-12-21 01:28:21 +08:00
|
|
|
layers: [],
|
|
|
|
set_marker: false,
|
2017-12-20 07:30:30 +08:00
|
|
|
});
|
2017-12-21 01:28:21 +08:00
|
|
|
|
|
|
|
let map = draw_base_map(opts);
|
|
|
|
|
2017-12-27 05:26:12 +08:00
|
|
|
//if(opts.geodesic) {
|
2017-12-21 09:12:39 +08:00
|
|
|
let geodesicLayer = L.geodesic([], {
|
|
|
|
weight: 7,
|
2017-12-27 05:26:12 +08:00
|
|
|
opacity: 0.9,
|
|
|
|
color: '#36b123',
|
2017-12-21 09:12:39 +08:00
|
|
|
steps: 50,
|
|
|
|
wrap: false,
|
|
|
|
}).addTo(map);
|
|
|
|
|
2017-12-25 07:38:38 +08:00
|
|
|
geodesicLayer.geoJson(opts.planned_route_line);
|
2017-12-21 09:12:39 +08:00
|
|
|
map.fitBounds(geodesicLayer.getBounds());
|
2017-12-27 05:26:12 +08:00
|
|
|
|
|
|
|
if(opts.actual_route_line !== null) {
|
|
|
|
let geodesicLayer = L.geodesic([], {
|
|
|
|
weight: 7,
|
|
|
|
opacity: 0.9,
|
|
|
|
color: '#172aea',
|
|
|
|
steps: 50,
|
|
|
|
wrap: false,
|
|
|
|
}).addTo(map);
|
|
|
|
|
|
|
|
geodesicLayer.geoJson(opts.actual_route_line);
|
|
|
|
map.fitBounds(geodesicLayer.getBounds());
|
|
|
|
}
|
|
|
|
/*} else {
|
2017-12-25 07:38:38 +08:00
|
|
|
let route = L.geoJSON(opts.planned_route_line, {
|
2017-12-21 09:12:39 +08:00
|
|
|
"color": "#ff7800",
|
2017-12-27 05:26:12 +08:00
|
|
|
"weight": 7,
|
|
|
|
"opacity": 0.9
|
2017-12-21 09:12:39 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
route.addTo(map);
|
|
|
|
map.fitBounds(route.getBounds());
|
2017-12-27 05:26:12 +08:00
|
|
|
|
|
|
|
if(opts.actual_route_line !== null) {
|
|
|
|
let route = L.geoJSON(opts.actual_route_line, {
|
|
|
|
"color": "#36b123",
|
|
|
|
"weight": 7,
|
|
|
|
"opacity": 0.9
|
|
|
|
});
|
|
|
|
|
|
|
|
route.addTo(map);
|
|
|
|
map.fitBounds(route.getBounds());
|
|
|
|
}
|
|
|
|
}*/
|
2017-12-25 07:38:38 +08:00
|
|
|
|
|
|
|
// Draw the route points after
|
|
|
|
if (opts.route_points !== null) {
|
|
|
|
console.log(opts.route_points);
|
|
|
|
let route_points = L.geoJSON(opts.route_points, {
|
|
|
|
onEachFeature: onFeaturePointClick,
|
2017-12-27 05:26:12 +08:00
|
|
|
pointToLayer: pointToLayer,
|
|
|
|
style: {
|
|
|
|
"color": "#36b123",
|
|
|
|
"weight": 5,
|
|
|
|
"opacity": 0.65,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
route_points.addTo(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(opts.actual_route_points !== null) {
|
|
|
|
let route_points = L.geoJSON(opts.actual_route_points, {
|
|
|
|
onEachFeature: onFeaturePointClick,
|
|
|
|
pointToLayer: pointToLayer,
|
2017-12-25 07:38:38 +08:00
|
|
|
style: {
|
2017-12-27 05:26:12 +08:00
|
|
|
"color": "#172aea",
|
2017-12-25 07:38:38 +08:00
|
|
|
"weight": 5,
|
|
|
|
"opacity": 0.65,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
route_points.addTo(map);
|
|
|
|
}
|
2017-12-20 07:30:30 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render a map with the airspace, etc around a given set of coords
|
|
|
|
* e.g, the airport map
|
|
|
|
* @param opts
|
|
|
|
*/
|
|
|
|
render_airspace_map: (opts) => {
|
|
|
|
opts = _.defaults(opts, {
|
|
|
|
render_elem: 'map',
|
|
|
|
overlay_elem: '',
|
|
|
|
lat: 0,
|
|
|
|
lon: 0,
|
|
|
|
zoom: 12,
|
|
|
|
layers: [],
|
|
|
|
set_marker: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
let map = draw_base_map(opts);
|
|
|
|
const coords = [opts.lat, opts.lon];
|
|
|
|
console.log('Applying coords', coords);
|
|
|
|
|
|
|
|
map.setView(coords, opts.zoom);
|
|
|
|
if (opts.set_marker === true) {
|
|
|
|
L.marker(coords).addTo(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|