mapserver/static/js/components/Map.js

56 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-09-18 12:53:58 +03:00
import layerManager from '../LayerManager.js';
import { createMap } from '../map/MapFactory.js';
2019-09-18 12:53:58 +03:00
function setupMap(vnode){
const map = createMap(
vnode.dom,
layerManager.getCurrentLayer().id,
+vnode.attrs.zoom,
+vnode.attrs.lat,
+vnode.attrs.lon
);
2019-09-18 12:53:58 +03:00
vnode.state.map = map;
2019-09-18 12:53:58 +03:00
function updateHash(){
const center = map.getCenter();
const layerId = layerManager.getCurrentLayer().id;
2019-09-18 12:53:58 +03:00
m.route.set(`/map/${layerId}/${map.getZoom()}/` +
`${Math.floor(center.lng)}/${Math.floor(center.lat)}`);
}
2019-09-18 12:53:58 +03:00
map.on('zoomend', updateHash);
map.on('moveend', updateHash);
2019-11-26 10:42:00 +03:00
return map;
2019-09-18 12:53:58 +03:00
}
2019-09-18 12:53:58 +03:00
export default {
view(){
return m("div", { class: "full-screen" });
},
2019-09-18 12:53:58 +03:00
oncreate(vnode){
2019-11-26 10:42:00 +03:00
this.map = setupMap(vnode);
},
onupdate(vnode){
2019-09-18 12:53:58 +03:00
if (vnode.attrs.layerId != layerManager.getCurrentLayer().id){
//layer changed, recreate map
2019-11-26 10:42:00 +03:00
this.map.remove();
2019-09-18 12:53:58 +03:00
layerManager.setLayerId(vnode.attrs.layerId);
setupMap(vnode);
} else {
//position/zoom change
2019-11-26 10:42:00 +03:00
//this.map.setView([+vnode.attrs.lat, +vnode.attrs.lon], +vnode.attrs.zoom);
2019-09-18 12:53:58 +03:00
}
},
2019-11-26 13:05:24 +03:00
onremove(){
2019-11-26 10:42:00 +03:00
this.map.remove();
}
2019-09-01 13:06:47 +03:00
};