2019-08-30 15:30:12 +03:00
|
|
|
import layerManager from '../map/LayerManager.js';
|
|
|
|
import { createMap } from '../map/MapFactory.js';
|
|
|
|
|
|
|
|
export default {
|
2019-09-01 13:06:47 +03:00
|
|
|
view(){
|
2019-08-30 15:30:12 +03:00
|
|
|
return m("div", { class: "full-screen" });
|
|
|
|
},
|
|
|
|
|
|
|
|
oncreate(vnode){
|
|
|
|
|
|
|
|
const map = createMap(
|
|
|
|
vnode.dom,
|
|
|
|
+vnode.attrs.layerId,
|
|
|
|
+vnode.attrs.zoom,
|
|
|
|
+vnode.attrs.lat,
|
|
|
|
+vnode.attrs.lon
|
|
|
|
);
|
|
|
|
|
|
|
|
vnode.state.map = map;
|
|
|
|
|
|
|
|
function updateHash(){
|
|
|
|
const center = map.getCenter();
|
|
|
|
const layerId = layerManager.getCurrentLayer().id;
|
|
|
|
|
|
|
|
m.route.set(`/map/${layerId}/${map.getZoom()}/${center.lng}/${center.lat}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
map.on('zoomend', updateHash);
|
|
|
|
map.on('moveend', updateHash);
|
|
|
|
map.on('baselayerchange', updateHash);
|
|
|
|
},
|
|
|
|
|
2019-09-01 13:06:47 +03:00
|
|
|
onbeforeupdate(newVnode) {
|
2019-08-30 15:30:12 +03:00
|
|
|
const center = newVnode.state.map.getCenter();
|
|
|
|
const newAattrs = newVnode.attrs;
|
|
|
|
|
|
|
|
return newAattrs.layerId != layerManager.getCurrentLayer().id ||
|
|
|
|
newAattrs.zoom != newVnode.state.map.getZoom() ||
|
|
|
|
Math.abs(newAattrs.lat - center.lat) > 0.1 ||
|
|
|
|
Math.abs(newAattrs.lat - center.lat) > 0.1;
|
|
|
|
},
|
|
|
|
|
|
|
|
onupdate(vnode){
|
|
|
|
layerManager.switchLayer(+vnode.attrs.layerId);
|
|
|
|
vnode.state.map.setView([+vnode.attrs.lat, +vnode.attrs.lon], +vnode.attrs.zoom);
|
|
|
|
},
|
|
|
|
|
|
|
|
onremove(vnode){
|
|
|
|
vnode.state.map.remove();
|
|
|
|
}
|
2019-09-01 13:06:47 +03:00
|
|
|
};
|