|
@@ -1,10 +1,8 @@
|
|
|
-import {ApplicationRef, ChangeDetectorRef, Component, OnInit} from '@angular/core';
|
|
|
-import {circle, icon, latLng, LatLng, Marker, marker, point, polygon, polyline, Polyline, tileLayer} from 'leaflet';
|
|
|
-import {GeoJSON, LatLngExpression} from 'leaflet';
|
|
|
+import {Component, OnInit} from '@angular/core';
|
|
|
+import {geoJSON, GeoJSON, icon, LatLng, latLng, marker, polyline, tileLayer} from 'leaflet';
|
|
|
import {VttTraceWsService} from './vtt-trace-ws.service';
|
|
|
-import {Feature, GeometryObject, LineString, MultiLineString, Point} from 'geojson';
|
|
|
-import {LeafletCoreDemoModel} from './core-demo.model';
|
|
|
-import {Observable} from 'rxjs/Observable';
|
|
|
+import {Feature, LineString, MultiLineString, Point} from 'geojson';
|
|
|
+import {VttTraceFormNewTraceComponent} from './vtt-trace.formNewTraceComponent';
|
|
|
|
|
|
|
|
|
// Utilise la librairie ngx-leaflet
|
|
@@ -18,7 +16,7 @@ import {Observable} from 'rxjs/Observable';
|
|
|
selector: 'app-vtt-trace',
|
|
|
templateUrl: './vtt-trace.component.html',
|
|
|
styleUrls: ['./vtt-trace.component.css'],
|
|
|
- providers: [VttTraceWsService]
|
|
|
+ providers: [VttTraceWsService, VttTraceFormNewTraceComponent]
|
|
|
})
|
|
|
|
|
|
export class VttTraceComponent implements OnInit {
|
|
@@ -42,14 +40,36 @@ export class VttTraceComponent implements OnInit {
|
|
|
})
|
|
|
};
|
|
|
|
|
|
- // Values to bind to Leaflet Directive
|
|
|
- layersControlOptions = { position: 'bottomright' };
|
|
|
- baseLayers = {
|
|
|
- 'Open Street Map': this.LAYER_OSM.layer,
|
|
|
- 'Open Cycle Map': this.LAYER_OCM.layer
|
|
|
+ geoJSON = {
|
|
|
+ id: 'geoJSON',
|
|
|
+ name: 'Geo JSON Polygon',
|
|
|
+ enabled: true,
|
|
|
+ layer: geoJSON(
|
|
|
+ ({
|
|
|
+ type: 'Polygon',
|
|
|
+ coordinates: [[
|
|
|
+ [-121.6, 46.87],
|
|
|
+ [-121.5, 46.87],
|
|
|
+ [-121.5, 46.93],
|
|
|
+ [-121.6, 46.87]
|
|
|
+ ]]
|
|
|
+ }) as any,
|
|
|
+ {style: () => ({color: '#ff7800'})})
|
|
|
};
|
|
|
|
|
|
|
|
|
+ // Values to bind to Leaflet Directive
|
|
|
+ layersControlOptions = {position: 'bottomright'};
|
|
|
+ layersControl = {
|
|
|
+ baseLayers: {
|
|
|
+ 'Open Street Map': this.LAYER_OSM.layer,
|
|
|
+ 'Open Cycle Map': this.LAYER_OCM.layer
|
|
|
+ },
|
|
|
+ overlays: {
|
|
|
+ GeoJSON: this.geoJSON.layer
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
/*
|
|
|
* This is a specification of the leaflet options
|
|
|
* The reason to duplicate this object is so we can easily render it to the template
|
|
@@ -67,27 +87,28 @@ export class VttTraceComponent implements OnInit {
|
|
|
}
|
|
|
],
|
|
|
zoom: 5,
|
|
|
- center: [ 46, 2 ]
|
|
|
+ center: [46, 2]
|
|
|
};
|
|
|
|
|
|
// Fields for managing the form inputs and binding to leaflet zoom/center
|
|
|
-/*
|
|
|
- model = new LeafletCoreDemoModel(
|
|
|
- this.optionsSpec.center[0],
|
|
|
- this.optionsSpec.center[1],
|
|
|
- this.optionsSpec.zoom
|
|
|
- );
|
|
|
-*/
|
|
|
+ /*
|
|
|
+ model = new LeafletCoreDemoModel(
|
|
|
+ this.optionsSpec.center[0],
|
|
|
+ this.optionsSpec.center[1],
|
|
|
+ this.optionsSpec.zoom
|
|
|
+ );
|
|
|
+ */
|
|
|
zoom: number;
|
|
|
center: LatLng;
|
|
|
latitude: number;
|
|
|
longitude: number;
|
|
|
- zoomLevels: number[] = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ];
|
|
|
+ zoomLevels: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
|
|
|
+
|
|
|
|
|
|
layers = [];
|
|
|
options = {
|
|
|
layers: this.optionsSpec.layers.map((l) => {
|
|
|
- return tileLayer(l.url, { maxZoom: l.maxZoom, attribution: l.attribution });
|
|
|
+ return tileLayer(l.url, {maxZoom: l.maxZoom, attribution: l.attribution});
|
|
|
}),
|
|
|
zoom: this.optionsSpec.zoom,
|
|
|
center: latLng(this.optionsSpec.center[0], this.optionsSpec.center[1])
|
|
@@ -102,10 +123,13 @@ export class VttTraceComponent implements OnInit {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- constructor(private vttTraceWs: VttTraceWsService) { }
|
|
|
+ constructor(private vttTraceWs: VttTraceWsService) {
|
|
|
+ }
|
|
|
|
|
|
ngOnInit() {
|
|
|
this.getMarkersObs();
|
|
|
+ // this.layers.push(newMarker); = L.geoJSON().addTo(map);
|
|
|
+ this.addRoute6();
|
|
|
}
|
|
|
|
|
|
private getMarkersObs() {
|
|
@@ -124,34 +148,71 @@ export class VttTraceComponent implements OnInit {
|
|
|
[feature.geometry.coordinates[0], feature.geometry.coordinates[1]],
|
|
|
{
|
|
|
icon: icon({
|
|
|
- iconSize: [ 25, 41 ],
|
|
|
- iconAnchor: [ 13, 41 ],
|
|
|
+ iconSize: [25, 41],
|
|
|
+ iconAnchor: [13, 41],
|
|
|
iconUrl: 'assets/marker-icon.png',
|
|
|
- shadowUrl: 'assets/marker-shadow.png'
|
|
|
- })
|
|
|
+ shadowUrl: 'assets/marker-shadow.png',
|
|
|
+ }),
|
|
|
+ title: '' + feature.properties.fichier
|
|
|
}
|
|
|
);
|
|
|
|
|
|
- console.log(feature.properties.name);
|
|
|
- console.log('here' + this);
|
|
|
+ console.log(feature.properties.fichier);
|
|
|
+ // console.log('here' + this);
|
|
|
newMarker.bindPopup(feature.properties.name).openPopup();
|
|
|
- newMarker.on('click', this.markerOnClick, newMarker);
|
|
|
+ // newMarker.on('click', this.markerOnClick, newMarker);
|
|
|
+ newMarker.on('click', this.markerOnClick, this);
|
|
|
this.layers.push(newMarker);
|
|
|
}
|
|
|
|
|
|
- markerOnClick(e) {
|
|
|
- console.log(e);
|
|
|
+ zoomAndCenter(latitude, longitude) {
|
|
|
const window: Window = self;
|
|
|
- console.log('parent' + this);
|
|
|
+ // console.log('parent' + this);
|
|
|
+
|
|
|
this.zoom = 15;
|
|
|
console.log(this.zoom);
|
|
|
this.center = latLng(this.latitude, this.longitude);
|
|
|
- //this.options.center = e.latlng;
|
|
|
+ // this.options.center = e.latlng;
|
|
|
+ // console.log(this.center);
|
|
|
+ }
|
|
|
|
|
|
- console.log(this.center);
|
|
|
- const attributes = e.layer.properties;
|
|
|
- console.log(attributes.name, attributes);
|
|
|
+ markerOnClick(e) {
|
|
|
+ const attributes = e.sourceTarget.options;
|
|
|
+ console.log(attributes.title);
|
|
|
// do some stuff…
|
|
|
+ // this.addTrace('' + attributes.title);
|
|
|
+ console.log(attributes);
|
|
|
+ this.options.zoom = 9;
|
|
|
+
|
|
|
+ this.vttTraceWs.getTraceFromFile(attributes.title)
|
|
|
+ .subscribe(data => {
|
|
|
+ // console.log(data);
|
|
|
+ const featureCollection: GeoJSON.FeatureCollection<Point | LineString | MultiLineString> = data
|
|
|
+ // const g = featureCollection.features[0].geometry.coordinates;
|
|
|
+ // console.log(featureCollection.features[0].geometry.coordinates[0]);
|
|
|
+ // this.layers.push(polyline(GeoJSON.coordsToLatLngs(g, 1)));
|
|
|
+ // this.geoJSON.layer.addLayer(polyline(GeoJSON.coordsToLatLngs(g, 1))) ;
|
|
|
+ console.log(this.geoJSON.layer.addData(featureCollection.features[0].geometry));
|
|
|
+ /*this.geoJSON.layer = geoJSON(
|
|
|
+ featureCollection.features[0].geometry as any,
|
|
|
+ { style: () => ({ color: '#ff7800' })});*/
|
|
|
+
|
|
|
+
|
|
|
+ // this.geoJSON.layer = new Layer(polyline(GeoJSON.coordsToLatLngs(g, 1)));
|
|
|
+ // console.log(this.geoJSON.layer.options);
|
|
|
+ });
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ addTrace(fileName: string) {
|
|
|
+ this.vttTraceWs.getTraceFromFile(fileName)
|
|
|
+ .subscribe(data => {
|
|
|
+ console.log(data)
|
|
|
+ const featureCollection: GeoJSON.FeatureCollection<Point | LineString | MultiLineString> = data
|
|
|
+ const g = featureCollection.features[0].geometry.coordinates;
|
|
|
+ console.log(featureCollection.features[0].geometry.coordinates[0]);
|
|
|
+ this.layers.push(polyline(GeoJSON.coordsToLatLngs(g, 1)));
|
|
|
+ });
|
|
|
return false;
|
|
|
}
|
|
|
|