Skip to content
Snippets Groups Projects
Commit b0912bba authored by Jérémie BRISON's avatar Jérémie BRISON
Browse files

Merge branch 'feat/mdm-markers' into 'dev'

feat: add mdm pop-up and marker display refacto

See merge request web-et-numerique/pamn_plateforme-des-acteurs-de-la-mediation-numerique/pamn_client!23
parents 87921294 5b3aeff2
No related branches found
No related tags found
2 merge requests!31Recette,!23feat: add mdm pop-up and marker display refacto
......@@ -62,9 +62,21 @@
}
}
::ng-deep .leaflet-left {
right: 0;
left: unset;
.leaflet-control {
margin-left: 0;
margin-right: 10px;
}
}
/*** POP-UP ***/
::ng-deep .leaflet-popup {
padding: 8px 10px 8px 10px;
border-radius: 6px;
@include background-hash;
padding: 0 0 4px 4px;
bottom: -15px !important;
h1 {
color: $grey-1;
@include cn-bold-20;
......@@ -82,21 +94,19 @@
button {
@include btn-search-filter;
@include cn-bold-14;
width: 149px;
}
}
span {
display: inline-block;
}
}
::ng-deep .leaflet-left {
right: 0;
left: unset;
.leaflet-control {
margin-left: 0;
margin-right: 10px;
}
::ng-deep .leaflet-popup-content-wrapper {
box-shadow: unset;
border-radius: 6px;
border: 1px solid $grey-4;
}
::ng-deep .leaflet-popup-tip-container {
display: none;
}
@media print {
......
......@@ -29,6 +29,8 @@ import { GeojsonService } from '../../services/geojson.service';
import { MapService } from '../services/map.service';
import { NgxLeafletLocateComponent } from '@runette/ngx-leaflet-locate';
import * as _ from 'lodash';
import { GeoJsonProperties } from '../models/geoJsonProperties.model';
import { MarkerType } from './markerType.enum';
@Component({
selector: 'app-map',
......@@ -109,7 +111,13 @@ export class MapComponent implements OnChanges {
structureListe.forEach((element: Structure) => {
this.getCoord(element.n, element.voie, element.commune).subscribe((coord: GeoJson) => {
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)
// store structure before user click on button
.on('popupopen', () => {
......@@ -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
* @param idVoie Street reference
......@@ -210,7 +222,15 @@ export class MapComponent implements OnChanges {
private initMDMLayer(): void {
this.geoJsonService.getMDMGeoJson().subscribe((res) => {
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 {
public city: string;
public country: string;
public name: string;
public nom: string;
public postcode: string;
public state: string;
public adresse: string;
public ville: string;
}
import { Injectable } from '@angular/core';
import { DivIcon, divIcon, Map } from 'leaflet';
import { Marker } from 'leaflet';
import { MarkerType } from '../components/markerType.enum';
@Injectable({
providedIn: 'root',
......@@ -35,8 +36,11 @@ export class MapService {
});
constructor() {}
public createMarker(lat: number, lon: number, id: number, tooltip?: string): Marker {
const marker = new Marker([lat, lon], { icon: this.markerIcon });
public createMarker(lat: number, lon: number, markerType: MarkerType, id?: number, tooltip?: string): Marker {
const marker = new Marker([lat, lon], {
icon: this.getMarkerIcon(markerType),
attribution: this.getLayerAttributton(markerType),
});
marker.on('mouseclick', (evt) => {
evt.target.openPopup();
});
......@@ -46,14 +50,35 @@ export class MapService {
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 {
const marker = new Marker([lat, lon], { icon: this.markerIconMdm, attribution: 'mdm' });
private getMarkerIcon(markerType: MarkerType): DivIcon {
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 {
......
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