Skip to content

Commit

Permalink
wip: merge
Browse files Browse the repository at this point in the history
  • Loading branch information
rendrom committed Jan 27, 2020
2 parents 8c912df + f5bd704 commit 00ed0a5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
9 changes: 6 additions & 3 deletions packages/vue-ngw-leaflet/src/components/VueNgwLeaflet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import MapAdapter from '@nextgis/leaflet-map-adapter';
import { VueNgwMap } from '@nextgis/vue-ngw-map';

import 'leaflet/dist/leaflet.css';
const iconRetinaUrl = require('leaflet/dist/images/marker-icon-2x.png');
const iconUrl = require('leaflet/dist/images/marker-icon.png');
const shadowUrl = require('leaflet/dist/images/marker-shadow.png');
// @ts-ignore
delete L.Icon.Default.prototype._getIconUrl;

L.Icon.Default.mergeOptions({
iconRetinaUrl: require('leaflet/dist/images/marker-icon-2x.png'),
iconUrl: require('leaflet/dist/images/marker-icon.png'),
shadowUrl: require('leaflet/dist/images/marker-shadow.png')
iconRetinaUrl: iconRetinaUrl.default,
iconUrl: iconUrl.default,
shadowUrl: shadowUrl.default
});

@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class NgwLayersList extends Vue {

private _layers: Array<LayerAdapter | ResourceAdapter> = [];
private __updateItems?: () => Promise<void>;
private __onNgwMapLoad?: Promise<NgwMap>;

@Watch('selection')
setVisibleLayers() {
Expand All @@ -56,22 +57,19 @@ export class NgwLayersList extends Vue {
});
}

mounted() {
const __updateItems = () => this.updateItems();
this.__updateItems = __updateItems;
this.ngwMap.onLoad().then(() => {
this.updateItems();
@Watch('ngwMap')
updateNgwMap() {
console.log(1234);
this.destroy();
this.create();
}

this.ngwMap.emitter.on('layer:add', __updateItems);
this.ngwMap.emitter.on('layer:remove', __updateItems);
});
mounted() {
this.create();
}

beforeDestroy() {
if (this.__updateItems) {
this.ngwMap.emitter.off('layer:add', this.__updateItems);
this.ngwMap.emitter.off('layer:remove', this.__updateItems);
}
this.destroy();
}

render(h: CreateElement): VNode {
Expand Down Expand Up @@ -102,6 +100,30 @@ export class NgwLayersList extends Vue {
return h(VTreeview, data, this.$slots.default);
}

private create() {
this.__onNgwMapLoad = this.ngwMap.onLoad();
setTimeout(() => {
if (this.__onNgwMapLoad) {
this.__onNgwMapLoad.then(() => {
this.destroy();
this.updateItems();
const __updateItems = () => this.updateItems();
this.__updateItems = __updateItems;

this.ngwMap.emitter.on('layer:add', __updateItems);
this.ngwMap.emitter.on('layer:remove', __updateItems);
});
}
});
}

private destroy() {
if (this.__updateItems) {
this.ngwMap.emitter.off('layer:add', this.__updateItems);
this.ngwMap.emitter.off('layer:remove', this.__updateItems);
}
}

@Watch('include')
private async updateItems() {
this.selection = [];
Expand Down

0 comments on commit 00ed0a5

Please sign in to comment.