Skip to content
Snippets Groups Projects
Commit 5b3aeff2 authored by Hugo SUBTIL's avatar Hugo SUBTIL
Browse files

feat: add mdm pop-up and marker display refacto

parent 9ff17fa9
No related branches found
No related tags found
2 merge requests!31Recette,!23feat: add mdm pop-up and marker display refacto
...@@ -64,9 +64,21 @@ ...@@ -64,9 +64,21 @@
margin-left: -21px !important; margin-left: -21px !important;
} }
::ng-deep .leaflet-left {
right: 0;
left: unset;
.leaflet-control {
margin-left: 0;
margin-right: 10px;
}
}
/*** POP-UP ***/
::ng-deep .leaflet-popup { ::ng-deep .leaflet-popup {
padding: 8px 10px 8px 10px;
border-radius: 6px; border-radius: 6px;
@include background-hash;
padding: 0 0 4px 4px;
bottom: -15px !important;
h1 { h1 {
color: $grey-1; color: $grey-1;
@include cn-bold-20; @include cn-bold-20;
...@@ -84,21 +96,19 @@ ...@@ -84,21 +96,19 @@
button { button {
@include btn-search-filter; @include btn-search-filter;
@include cn-bold-14; @include cn-bold-14;
width: 149px;
} }
} }
span { span {
display: inline-block; display: inline-block;
} }
} }
::ng-deep .leaflet-popup-content-wrapper {
::ng-deep .leaflet-left { box-shadow: unset;
right: 0; border-radius: 6px;
left: unset; border: 1px solid $grey-4;
.leaflet-control { }
margin-left: 0; ::ng-deep .leaflet-popup-tip-container {
margin-right: 10px; display: none;
}
} }
@media print { @media print {
......
...@@ -29,6 +29,8 @@ import { GeojsonService } from '../../services/geojson.service'; ...@@ -29,6 +29,8 @@ import { GeojsonService } from '../../services/geojson.service';
import { MapService } from '../services/map.service'; import { MapService } from '../services/map.service';
import { NgxLeafletLocateComponent } from '@runette/ngx-leaflet-locate'; import { NgxLeafletLocateComponent } from '@runette/ngx-leaflet-locate';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { GeoJsonProperties } from '../models/geoJsonProperties.model';
import { MarkerType } from './markerType.enum';
@Component({ @Component({
selector: 'app-map', selector: 'app-map',
...@@ -109,7 +111,13 @@ export class MapComponent implements OnChanges { ...@@ -109,7 +111,13 @@ export class MapComponent implements OnChanges {
structureListe.forEach((element: Structure) => { structureListe.forEach((element: Structure) => {
this.getCoord(element.voie).subscribe((coord: GeoJson) => { this.getCoord(element.voie).subscribe((coord: GeoJson) => {
this.mapService this.mapService
.createMarker(coord.geometry.getLon(), coord.geometry.getLat(), element.id, this.buildToolTip(element)) .createMarker(
coord.geometry.getLon(),
coord.geometry.getLat(),
MarkerType.structure,
element.id,
this.buildToolTip(element)
)
.addTo(this.map) .addTo(this.map)
// store structure before user click on button // store structure before user click on button
.on('popupopen', () => { .on('popupopen', () => {
...@@ -147,6 +155,10 @@ export class MapComponent implements OnChanges { ...@@ -147,6 +155,10 @@ export class MapComponent implements OnChanges {
); );
} }
private buildMdmPopUp(mdmProperties: GeoJsonProperties): string {
return `<h1>${mdmProperties.nom}</h1><p>${mdmProperties.adresse}</p>`;
}
/** /**
* Get coord with a street reference * Get coord with a street reference
* @param idVoie Street reference * @param idVoie Street reference
...@@ -210,7 +222,15 @@ export class MapComponent implements OnChanges { ...@@ -210,7 +222,15 @@ export class MapComponent implements OnChanges {
private initMDMLayer(): void { private initMDMLayer(): void {
this.geoJsonService.getMDMGeoJson().subscribe((res) => { this.geoJsonService.getMDMGeoJson().subscribe((res) => {
res.forEach((mdm) => { res.forEach((mdm) => {
this.mapService.createMDMMarker(mdm.geometry.getLon(), mdm.geometry.getLat()).addTo(this.map); this.mapService
.createMarker(
mdm.geometry.getLon(),
mdm.geometry.getLat(),
MarkerType.mdm,
null,
this.buildMdmPopUp(mdm.properties)
)
.addTo(this.map);
}); });
}); });
} }
......
export enum MarkerType {
structure = 0,
mdm = 1,
}
...@@ -2,6 +2,9 @@ export class GeoJsonProperties { ...@@ -2,6 +2,9 @@ export class GeoJsonProperties {
public city: string; public city: string;
public country: string; public country: string;
public name: string; public name: string;
public nom: string;
public postcode: string; public postcode: string;
public state: string; public state: string;
public adresse: string;
public ville: string;
} }
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { DivIcon, divIcon, Map } from 'leaflet'; import { DivIcon, divIcon, Map } from 'leaflet';
import { Marker } from 'leaflet'; import { Marker } from 'leaflet';
import { MarkerType } from '../components/markerType.enum';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
...@@ -33,8 +34,11 @@ export class MapService { ...@@ -33,8 +34,11 @@ export class MapService {
}); });
constructor() {} constructor() {}
public createMarker(lat: number, lon: number, id: number, tooltip?: string): Marker { public createMarker(lat: number, lon: number, markerType: MarkerType, id?: number, tooltip?: string): Marker {
const marker = new Marker([lat, lon], { icon: this.markerIcon }); const marker = new Marker([lat, lon], {
icon: this.getMarkerIcon(markerType),
attribution: this.getLayerAttributton(markerType),
});
marker.on('mouseclick', (evt) => { marker.on('mouseclick', (evt) => {
evt.target.openPopup(); evt.target.openPopup();
}); });
...@@ -44,14 +48,35 @@ export class MapService { ...@@ -44,14 +48,35 @@ export class MapService {
autoPan: false, autoPan: false,
}); });
} }
MapService.markersList[id] = marker;
return this.bindMouseEventOnMarker(marker, this.markerIcon, this.markerIconHover); if (id) {
MapService.markersList[id] = marker;
}
return this.bindMouseEventOnMarker(marker, this.getMarkerIcon(markerType), this.getMarkerIconHover(markerType));
}
private getLayerAttributton(markerType: MarkerType): string {
if (markerType === MarkerType.mdm) {
return 'mdm';
} else {
return 'structure';
}
} }
public createMDMMarker(lat: number, lon: number): Marker { private getMarkerIcon(markerType: MarkerType): DivIcon {
const marker = new Marker([lat, lon], { icon: this.markerIconMdm, attribution: 'mdm' }); if (markerType === MarkerType.mdm) {
return this.markerIconMdm;
} else {
return this.markerIcon;
}
}
return this.bindMouseEventOnMarker(marker, this.markerIconMdm, this.markerIconMdmHover); private getMarkerIconHover(markerType: MarkerType): DivIcon {
if (markerType === MarkerType.mdm) {
return this.markerIconMdmHover;
} else {
return this.markerIconHover;
}
} }
private bindMouseEventOnMarker(marker: Marker, regularIcon: DivIcon, hoverIcon: DivIcon): Marker { private bindMouseEventOnMarker(marker: Marker, regularIcon: DivIcon, hoverIcon: DivIcon): Marker {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment