Skip to content

Commit

Permalink
Fix polygon and linestring issue due to change in geometry_type naming
Browse files Browse the repository at this point in the history
  • Loading branch information
nobohan committed Nov 29, 2023
1 parent 1bdfc71 commit 10ba37e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions frontend/src/app/dashboard/dashboard.component.ts
Expand Up @@ -456,9 +456,9 @@ export class DashboardComponent implements AfterViewInit {
},
};

const geometryType = features.features[0].geometry.type.toUpperCase();
const geometryType = features.features[0].geometry.type;
switch (geometryType) {
case 'POINT':
case 'Point':
default:
Object.assign(layerOptions, {
pointToLayer: (f: Feature, latlng): L.Marker => {
Expand All @@ -475,7 +475,7 @@ export class DashboardComponent implements AfterViewInit {
this.showLayerPoint = true;
break;

case 'LINESTRING':
case 'LineString':
Object.assign(layerOptions, {
style: (f: Feature) =>
this.isImported(f)
Expand All @@ -487,7 +487,7 @@ export class DashboardComponent implements AfterViewInit {
this.showLayerLine = true;
break;

case 'POLYGON':
case 'Polygon':
Object.assign(layerOptions, {
style: (f: Feature) =>
this.isImported(f)
Expand Down
19 changes: 9 additions & 10 deletions frontend/src/app/programs/base/map/map.component.ts
Expand Up @@ -314,17 +314,16 @@ export abstract class BaseMapComponent implements OnChanges {

const geometryType =
this.program.features[0].properties.geometry_type;

switch (geometryType){
case 'LINESTRING':
switch (geometryType) {
case 'ligne':
this.observationMap.on('mousemove', (e: L.LeafletMouseEvent) => {
if (polyline) {
const lastDrawPoint: L.LatLng = polyline.getLatLngs()[polyline.getLatLngs().length - 1] as L.LatLng;
lineDraw.setLatLngs([lastDrawPoint, e.latlng]);
}
});
break;
case 'POLYGON':
case 'polygone':
this.observationMap.on('mousemove', (e: L.LeafletMouseEvent) => {
if (polygon) {
const coordinates = polygon.getLatLngs() as L.LatLng[][];
Expand Down Expand Up @@ -360,7 +359,7 @@ export abstract class BaseMapComponent implements OnChanges {
}

switch (geometryType) {
case 'POINT':
case 'point':
default:
if (this.newObsMarker !== null) {
this.observationMap.removeLayer(this.newObsMarker);
Expand All @@ -381,7 +380,7 @@ export abstract class BaseMapComponent implements OnChanges {
this.onClick.emit(coords);
break;

case 'LINESTRING':
case 'ligne':
lineDraw.setLatLngs([]);
if (polyline === null) {
if (previousPolyline !== null){
Expand All @@ -408,7 +407,7 @@ export abstract class BaseMapComponent implements OnChanges {
}
break;

case 'POLYGON':
case 'polygone':
lineDraw.setLatLngs([]);
if (polygon === null){
polygon = L.polygon([e.latlng], {
Expand Down Expand Up @@ -476,13 +475,13 @@ export abstract class BaseMapComponent implements OnChanges {

let pointFeatures: FeatureCollection;
switch (geometryType){
case 'POINT':
case 'point':
default:
pointFeatures = this.features;
break;

case 'LINESTRING':
case 'POLYGON':
case 'ligne':
case 'polygone':
this.observationMap.addLayer(
L.geoJSON(this.features, {
style: function (_feature) {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/programs/sites/detail/detail.component.ts
Expand Up @@ -153,14 +153,14 @@ export class SiteDetailComponent
const geometryType = this.site.properties.program.geometry_type;

switch (geometryType) {
case 'POINT':
case 'point':
default:
coord = this.site.geometry.coordinates;
latLng = L.latLng(coord[1], coord[0]);
L.marker(latLng, { icon: markerIcon }).addTo(map);
break;

case 'LINESTRING':
case 'ligne':
coord = this.site.geometry.coordinates[0];
latLng = L.latLng(coord[1], coord[0]);
const lineLatLng = this.site.geometry.coordinates.map(
Expand All @@ -171,7 +171,7 @@ export class SiteDetailComponent
}).addTo(map);
break;

case 'POLYGON':
case 'polygone':
coord = this.site.geometry.coordinates[0][0];
latLng = L.latLng(coord[1], coord[0]);
const polygonLatLng = [this.site.geometry.coordinates[0].map(
Expand Down
Expand Up @@ -79,7 +79,7 @@ export class SiteFormComponent implements AfterViewInit {
if (this.data.updateData) {
this.patchForm(this.data.updateData);
}

this.mapService.coordsChange.subscribe((value) => {
this.coords = value;

Expand Down Expand Up @@ -172,14 +172,15 @@ export class SiteFormComponent implements AfterViewInit {
formMap.setMaxBounds(maxBounds);

const geometryType = this.program.features[0].properties.geometry_type;

let myMarker = null;
let myLine = null;
let myPolygon = null;
let geo_coords = null;

if (this.coords || this.line || this.polygon) { // Set initial observation marker from main map if already spotted
switch (geometryType) {
case 'POINT':
case 'point':
default:
geo_coords = <Point>{
type: 'Point',
Expand All @@ -191,7 +192,7 @@ export class SiteFormComponent implements AfterViewInit {
}).addTo(formMap);
break;

case 'LINESTRING':
case 'ligne':
const coordinates = this.line.getLatLngs() as L.LatLng[];
const positions: Position[] = coordinates.map(c => [c.lng, c.lat])
geo_coords = <LineString>{
Expand All @@ -204,7 +205,7 @@ export class SiteFormComponent implements AfterViewInit {
}).addTo(formMap);
break;

case 'POLYGON':
case 'polygone':
const coordsPolygon = this.polygon.getLatLngs() as L.LatLng[][];
const positionsPolygon = [coordsPolygon[0].map(c => [c.lng, c.lat])] as Position[][];
geo_coords = <Polygon>{
Expand Down

0 comments on commit 10ba37e

Please sign in to comment.