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

feat(map): clean code and remove ign map because of heavy loading

parent 0daaf7c3
No related branches found
No related tags found
2 merge requests!11Recette,!5Map poc
<div class="content-container"> <div fxLayout="row">
<div class="section-container"> <p fxFlex="30%">temp</p>
<app-map></app-map> <app-map fxFlex="70%" [toogleToolTipIds]="[1, 2]"></app-map>
</div>
</div> </div>
<div <div id="map" leaflet [leafletOptions]="mapOptions" (leafletMapReady)="onMapReady($event)"></div>
id="map" <leaflet-locate-control [map]="map" [options]="locateOptions"></leaflet-locate-control>
leaflet
[leafletOptions]="mapOptions"
[leafletLayersControl]="layersControl"
(leafletMapReady)="onMapReady($event)"
></div>
<leaflet-locate-control
[map]="map"
[options]="locateOptions"
(location$)="onNewLocation($event)"
></leaflet-locate-control>
@import '../../../assets/scss/color'; @import '../../../assets/scss/color';
@import '../../../assets/scss/layout';
#map { #map {
height: 600px; height: calc(100vh - #{$header-height} - #{$footer-height});
width: 100%;
} }
::ng-deep .fa-map-marker { ::ng-deep .fa-map-marker {
......
import { Component, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { latLng, MapOptions, tileLayer, Map, Marker, icon, CRS, TileLayer, LatLngBounds } from 'leaflet'; import { latLng, MapOptions, tileLayer, Map, CRS, TileLayer, LatLngBounds } from 'leaflet';
import { MapService } from '../services/map.service';
declare const L: any; // Leaflet
@Component({ @Component({
selector: 'app-map', selector: 'app-map',
templateUrl: './map.component.html', templateUrl: './map.component.html',
styleUrls: ['./map.component.scss'], styleUrls: ['./map.component.scss'],
}) })
export class MapComponent implements OnInit { export class MapComponent implements OnInit {
@Input() public toogleToolTipIds: Array<number> = [];
public map: Map; public map: Map;
public mapOptions: MapOptions; public mapOptions: MapOptions;
public layersControl = {}; // Init locate options
public locateOptions = { public locateOptions = {
flyTo: false, flyTo: false,
keepCurrentZoomLevel: true, keepCurrentZoomLevel: true,
...@@ -21,22 +22,29 @@ export class MapComponent implements OnInit { ...@@ -21,22 +22,29 @@ export class MapComponent implements OnInit {
clickBehavior: { inView: 'stop', outOfView: 'setView', inViewNotFollowing: 'setView' }, clickBehavior: { inView: 'stop', outOfView: 'setView', inViewNotFollowing: 'setView' },
}; };
constructor() {} constructor(private mapService: MapService) {}
ngOnInit(): void { ngOnInit(): void {
this.initializeMapOptions(); this.initializeMapOptions();
} }
/**
* Add marker when map is ready to be showned
* @param map
*/
public onMapReady(map: Map): void { public onMapReady(map: Map): void {
this.map = map; this.map = map;
this.addSampleMarker(); this.addMarker();
} this.toggleToolTip(this.toogleToolTipIds);
public onNewLocation(e: Location): void {
console.log(e);
} }
/**
* Init map options :
* - Metropole bounds based on a WMS service hosted by data.grandlyon.com
* - Map Layer based on open street maps
*/
private initializeMapOptions(): void { private initializeMapOptions(): void {
// Init WMS service with param from data.grandlyon.com
const metroMaps = new TileLayer.WMS('https://download.data.grandlyon.com/wms/grandlyon', { const metroMaps = new TileLayer.WMS('https://download.data.grandlyon.com/wms/grandlyon', {
crs: CRS.EPSG4326, crs: CRS.EPSG4326,
transparent: true, transparent: true,
...@@ -55,64 +63,32 @@ export class MapComponent implements OnInit { ...@@ -55,64 +63,32 @@ export class MapComponent implements OnInit {
width: 256, width: 256,
height: 256, height: 256,
}; };
const ignMaps = new TileLayer.WMS('https://data.grandlyon.com/api/query/map/ign', {
crs: CRS.EPSG4326,
transparent: true,
format: 'image/png',
attribution: 'Map data © OpenStreetMap contributors',
version: '1.1.1',
});
ignMaps.wmsParams = {
format: 'image/png',
styles: 'normal',
transparent: true,
version: '1.1.1',
layers: 'ORTHOIMAGERY.ORTHOPHOTOS.BDORTHO',
service: 'WMS',
request: 'GetMap',
width: 512,
height: 512,
};
const carteLayer = tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { const carteLayer = tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18, maxZoom: 18,
attribution: 'Map data © OpenStreetMap contributors', attribution: 'Map data © OpenStreetMap contributors',
}); });
// Center is set on townhall
this.layersControl = { // Zoom is blocked on 11 to prevent people to zoom out from metropole
baseLayers: {
Carte: carteLayer,
Satellite: ignMaps,
},
overlays: {
'Contours métropole': metroMaps,
},
};
this.mapOptions = { this.mapOptions = {
center: latLng(45.764043, 4.835659), center: latLng(45.764043, 4.835659),
zoom: 12, zoom: 11,
minZoom: 11,
layers: [carteLayer, metroMaps], layers: [carteLayer, metroMaps],
}; };
} }
private addSampleMarker(): void { /**
const marker = new Marker([45.764043, 4.835659]).setIcon( * Toogle all tooltips given in parameters
icon({ */
iconSize: [35, 41], public toggleToolTip(ids: Array<number>): void {
iconAnchor: [13, 41], ids.forEach((id) => {
iconUrl: '../../../assets/img/ic_marker.png', this.mapService.toogleToolTip(id);
}) });
); }
marker.addTo(this.map);
const marker2 = new Marker([45.764043, 4.935659]).setIcon( private addMarker(): void {
icon({ //TODO: Replace with real data
iconSize: [35, 41], this.map = this.mapService.addMarker(this.map, 45.764043, 4.835659, 1);
iconAnchor: [13, 41], this.map = this.mapService.addMarker(this.map, 45.764043, 4.935659, 2);
iconUrl: '../../../assets/img/ic_marker.png',
})
);
marker2.addTo(this.map);
marker.bindTooltip('<p>Hello <br/>World !</p>');
} }
} }
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { icon, Marker, Map } from 'leaflet';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class MapService { export class MapService {
private markersList = {};
constructor() {} constructor() {}
public addMarker(map: Map, lat: number, lon: number, id: number): Map {
const marker = new Marker([lat, lon]).setIcon(
icon({
iconSize: [35, 41],
iconAnchor: [13, 41],
iconUrl: '../../../assets/img/ic_marker.png',
})
);
marker.bindTooltip('<p>Hello <br/>World !</p>'); //TODO: replace with real data
marker.addTo(map);
this.markersList[id] = marker;
return map;
}
public toogleToolTip(id: number): void {
this.getMarker(id).toggleTooltip();
}
public setToolTip(id: number): void {
this.getMarker(id).bindTooltip('<p>Hello <br/>World 2!</p>');
}
public getMarker(id: number): Marker {
return this.markersList[id];
}
} }
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
"extends": "./tsconfig.json", "extends": "./tsconfig.json",
"compilerOptions": { "compilerOptions": {
"outDir": "./out-tsc/app", "outDir": "./out-tsc/app",
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"types": ["node"] "types": ["node"]
}, },
"files": ["src/main.ts", "src/polyfills.ts"], "files": ["src/main.ts", "src/polyfills.ts"],
......
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