Commit ff7e14c7 authored by Thomas Frion's avatar Thomas Frion

[WIP] Try to add station layer, but this time we try we geojson

parent 7a0101d6
......@@ -4,6 +4,7 @@ import * as L from 'leaflet';
import * as models from 'src/app/pghm-api/api/models/models';
import { ServiceService } from 'src/app/pghm-api/api/clients/service.service';
import { GendUnitService } from 'src/app/pghm-api/api/clients/gendunit.service';
import { StationService } from 'src/app/pghm-api/api/clients/station.service';
import { environment } from '../../environments/environment';
/**
......@@ -19,10 +20,12 @@ export class MapComponent implements OnInit {
private unit : models.UnitModel;
private map; // The map it self
private marker; // Maker of the user's unit
// Layers
private baseMap; // Base layer of the map (OSM,OTM, IGN,...)
private gendarmeries; // Marker of all Gendarmerie units
private marker; // Maker of the user's unit
private stations;
// Icons for markers
private pghmIcon;
private gendarmerieIcon;
......@@ -31,6 +34,7 @@ export class MapComponent implements OnInit {
constructor(
private serviceApi : ServiceService, // Client to load from api services (OSM, OTM, IGN, ...)
private gendApi : GendUnitService, // Client to load the unit of Gendarmerie
private stationApi : StationService,
)
{
// Here we define the PGHM Logo as a Leaflet icon. We will use it for the marker of the user's unit
......@@ -71,6 +75,8 @@ export class MapComponent implements OnInit {
"<b>Lat: </b>"+ coordinates[0] +", <b>Lng: </b>" + coordinates[1]);
this.gendarmeries = L.layerGroup([]);
this.stations = L.layerGroup([]);
this.getStations();
}
ngOnInit(): void {
......@@ -244,4 +250,19 @@ export class MapComponent implements OnInit {
(err) => {console.log(err);}
);
}
getStations() : void {
this.stationApi.all().then(
(res) => {
res.forEach((e) => {
this.geArea(e.area);
})
},
(err) => {console.log(err)}
);
}
private geArea(area : string) {
console.log(area);
}
}
......@@ -15,27 +15,27 @@ export class GendUnitService extends ApiService<models.GendUnit> implements ICli
}
public all(headers?: HttpHeaders): Promise<models.GendUnit[]> {
return this.get('/services/', headers);
return this.get('/units/gendarmerie/', headers);
}
public one(selector: any, headers?: HttpHeaders): Promise<models.GendUnit> {
return this.read('/services/' + selector, headers);
return this.read('/units/gendarmerie/' + selector, headers);
}
public save(elem: models.GendUnit, headers?: HttpHeaders): Promise<models.GendUnit> {
let result : Promise<models.GendUnit>;
if(elem.id !== undefined){
result = this.update('/services/' + elem.id, JSON.stringify(elem), headers);
result = this.update('/units/gendarmerie/' + elem.id, JSON.stringify(elem), headers);
} else {
result = this.create('/services/', JSON.stringify(elem), headers);
result = this.create('/units/gendarmerie/', JSON.stringify(elem), headers);
}
return result;
}
public remove(elem: models.GendUnit, headers?: HttpHeaders): boolean {
return this.delete('/services/' + elem.id, headers);
return this.delete('/units/gendarmerie/' + elem.id, headers);
}
public async getInBoundaries(boundaries: any, headers?: HttpHeaders): Promise<models.GendUnit[]>{
......
......@@ -19,14 +19,14 @@ export class PoliceService extends ApiService<models.PoliceUnit> implements ICli
}
public one(selector: any, headers?: HttpHeaders): Promise<models.PoliceUnit> {
return this.read('/units/police'+selector, headers);
return this.read('/units/police/'+selector, headers);
}
public save(elem: models.PoliceUnit, headers?: HttpHeaders): Promise<models.PoliceUnit> {
let res : Promise<models.PoliceUnit>;
if(elem.id !== undefined){
res = this.update('/units/police'+elem.id, JSON.stringify(elem), headers);
res = this.update('/units/police/'+elem.id, JSON.stringify(elem), headers);
} else {
res = this.create('/units/police', JSON.stringify(elem), headers);
}
......@@ -35,7 +35,7 @@ export class PoliceService extends ApiService<models.PoliceUnit> implements ICli
}
public remove(elem: models.PoliceUnit, headers?: HttpHeaders): boolean {
return this.delete('/units/police'+elem.id, headers);
return this.delete('/units/police/'+elem.id, headers);
}
public async getInBoundaries(boundaries: any, headers?: HttpHeaders): Promise<models.PoliceUnit[]>{
......
......@@ -15,26 +15,26 @@ export class StationService extends ApiService<models.IStation> implements IClie
}
public all(headers?: HttpHeaders): Promise<models.IStation[]> {
return this.get('/units/police', headers);
return this.get('/stations/', headers);
}
public one(selector: any, headers?: HttpHeaders): Promise<models.IStation> {
return this.read('/units/police'+selector, headers);
return this.read('/stations/'+selector, headers);
}
public save(elem: models.IStation, headers?: HttpHeaders): Promise<models.IStation> {
let res : Promise<models.IStation>;
if(elem.id !== undefined){
res = this.update('/units/police'+elem.id, JSON.stringify(elem), headers);
res = this.update('/stations/'+elem.id, JSON.stringify(elem), headers);
} else {
res = this.create('/units/police', JSON.stringify(elem), headers);
res = this.create('/stations/', JSON.stringify(elem), headers);
}
return res;
}
public remove(elem: models.IStation, headers?: HttpHeaders): boolean {
return this.delete('/units/police'+elem.id, headers);
return this.delete('/stations/'+elem.id, headers);
}
}
......@@ -50,4 +50,4 @@ urlpatterns = [
path('', include('pghm.urls')),
path('', include('unit.urls')),
path('', include('station.urls')),
]
]
\ No newline at end of file
from django.urls import path
from django.urls import path, re_path
from django.conf.urls import url
from station import views
......
......@@ -3,6 +3,7 @@ from rest_framework.views import APIView
from rest_framework.schemas import SchemaGenerator
from rest_framework.response import Response
from django.http import Http404
from django.core.serializers import serialize
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
......@@ -108,6 +109,7 @@ class StationList(APIView):
responses={200: StationSerializer(many=True)},
)
def get(self, request, format=None):
print(format)
stations = Station.objects.all()
serializer = StationSerializer(stations, many = True)
return Response(serializer.data)
......
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