Commit cb0a5534 authored by Kevin Linne's avatar Kevin Linne

Render tags in map view

parent bd3d924a
......@@ -77,5 +77,6 @@ export class MapViewComponent implements AfterViewInit {
modalRef.componentInstance.long = this.mapRendererService.getContextLong();
modalRef.componentInstance.lat = this.mapRendererService.getContextLat();
modalRef.componentInstance.level = this.mapRendererService.selectedLevel.level;
modalRef.result.then(() => {}).catch(() => {}).then(() => this.mapRendererService.drawTags());
}
}
......@@ -24,6 +24,9 @@ import {GenericDataService} from '../generic-data/generic-data.service';
import {AddEditPoiComponent} from '../../components/add-edit/add-edit-poi/add-edit-poi.component';
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
import {AuthService} from '../auth/auth.service';
import {tagModelDefinition} from '../../model-definitions/TagModelDefinition';
import {TagModel} from '../../models/tag.model';
import {AddEditTagComponent} from '../../components/add-edit/add-edit-tag/add-edit-tag.component';
@Injectable()
export class MapRendererService {
......@@ -36,7 +39,8 @@ export class MapRendererService {
private polygons: Polygon[] = [];
private polygonLayers: L.Polygon[] = [];
private map: L.Map;
private markers: Array<[L.Marker, PoiModel]> = [];
private poiMarkers: Array<[L.Marker, PoiModel]> = [];
private tagMarkers: Array<[L.Marker, TagModel]> = [];
private menuPosition: L.LatLng;
constructor(private dataService: GenericDataService,
......@@ -69,6 +73,7 @@ export class MapRendererService {
this.drawBuildings();
this.drawPois();
this.drawTags();
}
setCenterView(): void {
......@@ -104,10 +109,27 @@ export class MapRendererService {
const pois = await this.dataService.get(poiModelDefinition);
pois.forEach((poi: PoiModel) => {
if (poi.levels.length === 0 && !this.selectedBuilding) {
this.addMarker(poi); // general pois like A20, THM
this.addPoiToMap(poi); // general pois like A20, THM
} else if (this.selectedBuilding && this.selectedBuilding.name === poi.building &&
this.selectedLevel && poi.levels.includes(this.selectedLevel.level)) {
this.addMarker(poi);
this.addPoiToMap(poi);
}
});
} catch (err) {
this.error = err.message;
}
}
async drawTags(): Promise<void> {
this.poisShown = true;
try {
const tags = await this.dataService.get(tagModelDefinition);
tags.forEach((tag: TagModel) => {
if (!this.selectedLevel) {
this.addTagToMap(tag); // general pois like A20, THM
} else if (this.selectedLevel.level === tag.floor) {
this.addTagToMap(tag);
}
});
} catch (err) {
......@@ -118,17 +140,27 @@ export class MapRendererService {
togglePois() {
if (this.poisShown) {
this.removePois();
this.removeTags();
} else {
this.drawPois();
this.drawTags();
}
}
removePois() {
this.poisShown = false;
this.markers.forEach((tuple) => {
this.poiMarkers.forEach((tuple) => {
tuple[0].removeFrom(this.map);
});
this.poiMarkers = [];
}
removeTags() {
this.poisShown = false;
this.tagMarkers.forEach((tuple) => {
tuple[0].removeFrom(this.map);
});
this.markers = [];
this.tagMarkers = [];
}
drawLevel() {
......@@ -147,6 +179,8 @@ export class MapRendererService {
this.applyPolygons();
this.removePois();
this.drawPois();
this.removeTags();
this.drawTags();
}
public leaveBuilding(): void {
......@@ -173,7 +207,7 @@ export class MapRendererService {
return this.menuPosition.lng;
}
private addMarker(poi: PoiModel) {
private addPoiToMap(poi: PoiModel) {
let marker: L.Marker;
marker = L.marker([poi.latitude, poi.longitude],
{
......@@ -187,7 +221,24 @@ export class MapRendererService {
});
marker.addTo(this.map);
marker.bindTooltip(poi.name, toolTipOptionsPOI());
this.markers.push([marker, poi]);
this.poiMarkers.push([marker, poi]);
}
private addTagToMap(tag: TagModel) {
let marker: L.Marker;
marker = L.marker([tag.coordinates.lat, tag.coordinates.lng],
{
title: tag.name,
icon: redIcon(),
});
marker.on('click', () => {
if (this.authService.isLoggedIn()) {
this.editTag(tag.getID());
}
});
marker.addTo(this.map);
marker.bindTooltip(tag.name, toolTipOptionsPOI());
this.tagMarkers.push([marker, tag]);
}
private editPoi(id: string) {
......@@ -199,6 +250,15 @@ export class MapRendererService {
});
}
private editTag(id: string) {
const modalRef = this.modalService.open(AddEditTagComponent, {size: 'lg'});
modalRef.componentInstance.id = id;
modalRef.result.then(() => {
this.removeTags();
this.drawTags();
});
}
private clearPolygons() {
this.polygonLayers.forEach((polygonLayer) => this.map.removeLayer(polygonLayer));
this.polygonLayers = [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment