Polygons!
This commit is contained in:
		@@ -7,6 +7,7 @@ export interface MapData {
 | 
				
			|||||||
    circles?: Circle[];
 | 
					    circles?: Circle[];
 | 
				
			||||||
    markers?: Marker[];
 | 
					    markers?: Marker[];
 | 
				
			||||||
    measurements?: Measurement[];
 | 
					    measurements?: Measurement[];
 | 
				
			||||||
 | 
					    polygons?: Polygon[];
 | 
				
			||||||
    polylines?: Polyline[];
 | 
					    polylines?: Polyline[];
 | 
				
			||||||
    rectangles?: Rectangle[];
 | 
					    rectangles?: Rectangle[];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
import {BehaviorSubject} from "rxjs";
 | 
					import {BehaviorSubject} from "rxjs";
 | 
				
			||||||
import {latLngDistance} from "../utils";
 | 
					import {latLngDistance} from "../utils";
 | 
				
			||||||
import {environment} from "../../environments/environment";
 | 
					import {environment} from "../../environments/environment";
 | 
				
			||||||
import {Circle, LatLng, MapSymbol, Marker, Measurement, Polyline, Rectangle} from "../models/mapSymbol";
 | 
					import {Circle, LatLng, MapSymbol, Marker, Measurement, Polygon, Polyline, Rectangle} from "../models/mapSymbol";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
declare const L;
 | 
					declare const L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -27,11 +27,11 @@ export class MapService {
 | 
				
			|||||||
    private readonly map;
 | 
					    private readonly map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private circles = [];
 | 
					    private circles = [];
 | 
				
			||||||
    private drawListener;
 | 
					 | 
				
			||||||
    private markers = [];
 | 
					    private markers = [];
 | 
				
			||||||
    private measurements = [];
 | 
					    private measurements = [];
 | 
				
			||||||
    private mapLayer;
 | 
					    private mapLayer;
 | 
				
			||||||
    private polyline = [];
 | 
					    private polygons = [];
 | 
				
			||||||
 | 
					    private polylines = [];
 | 
				
			||||||
    private rectangles = [];
 | 
					    private rectangles = [];
 | 
				
			||||||
    private weatherLayer;
 | 
					    private weatherLayer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -68,7 +68,8 @@ export class MapService {
 | 
				
			|||||||
            this.circles = this.circles.filter(c => c != c);
 | 
					            this.circles = this.circles.filter(c => c != c);
 | 
				
			||||||
            this.markers = this.markers.filter(m => m != s);
 | 
					            this.markers = this.markers.filter(m => m != s);
 | 
				
			||||||
            this.measurements = this.measurements.filter(m => m != s);
 | 
					            this.measurements = this.measurements.filter(m => m != s);
 | 
				
			||||||
            this.polyline = this.polyline.filter(p => p != s);
 | 
					            this.polygons = this.polygons.filter(p => p != s);
 | 
				
			||||||
 | 
					            this.polylines = this.polylines.filter(p => p != s);
 | 
				
			||||||
            this.rectangles = this.rectangles.filter(r => r != s);
 | 
					            this.rectangles = this.rectangles.filter(r => r != s);
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -77,7 +78,8 @@ export class MapService {
 | 
				
			|||||||
        this.circles.forEach(c => this.delete(c));
 | 
					        this.circles.forEach(c => this.delete(c));
 | 
				
			||||||
        this.markers.forEach(m => this.delete(m));
 | 
					        this.markers.forEach(m => this.delete(m));
 | 
				
			||||||
        this.measurements.forEach(m => this.delete(m));
 | 
					        this.measurements.forEach(m => this.delete(m));
 | 
				
			||||||
        this.polyline.forEach(p => this.delete(p));
 | 
					        this.polygons.forEach(p => this.delete(p));
 | 
				
			||||||
 | 
					        this.polylines.forEach(p => this.delete(p));
 | 
				
			||||||
        this.rectangles.forEach(r => this.delete(r));
 | 
					        this.rectangles.forEach(r => this.delete(r));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -126,10 +128,17 @@ export class MapService {
 | 
				
			|||||||
        return group;
 | 
					        return group;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    newPolygon(p: Polygon) {
 | 
				
			||||||
 | 
					        let polygon = new L.Polygon(p.latlng, Object.assign({}, p)).addTo(this.map);
 | 
				
			||||||
 | 
					        polygon.on('click', e => this.click.next({latlng: {lat: e.latlng.lat, lng: e.latlng.lng}, symbol: p, item: polygon}));
 | 
				
			||||||
 | 
					        if(!p.noDelete) this.polygons.push(polygon);
 | 
				
			||||||
 | 
					        return polygon;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    newPolyline(p: Polyline) {
 | 
					    newPolyline(p: Polyline) {
 | 
				
			||||||
        let polyline = new L.Polyline(p.latlng, Object.assign({}, p)).addTo(this.map);
 | 
					        let polyline = new L.Polyline(p.latlng, Object.assign({}, p)).addTo(this.map);
 | 
				
			||||||
        polyline.on('click', e => this.click.next({latlng: {lat: e.latlng.lat, lng: e.latlng.lng}, symbol: p, item: polyline}));
 | 
					        polyline.on('click', e => this.click.next({latlng: {lat: e.latlng.lat, lng: e.latlng.lng}, symbol: p, item: polyline}));
 | 
				
			||||||
        if(!p.noDelete) this.polyline.push(polyline);
 | 
					        if(!p.noDelete) this.polylines.push(polyline);
 | 
				
			||||||
        return polyline;
 | 
					        return polyline;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
import {Injectable} from "@angular/core";
 | 
					import {Injectable} from "@angular/core";
 | 
				
			||||||
import {AngularFirestore, AngularFirestoreCollection} from "@angular/fire/firestore";
 | 
					import {AngularFirestore, AngularFirestoreCollection} from "@angular/fire/firestore";
 | 
				
			||||||
import {BehaviorSubject, Subscription} from "rxjs";
 | 
					import {BehaviorSubject, Subscription} from "rxjs";
 | 
				
			||||||
import {Circle, MapData, Marker, Measurement, Polyline, Rectangle} from "../models/mapSymbol";
 | 
					import {Circle, MapData, Marker, Measurement, Polygon, Polyline, Rectangle} from "../models/mapSymbol";
 | 
				
			||||||
import * as _ from 'lodash';
 | 
					import * as _ from 'lodash';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Injectable({
 | 
					@Injectable({
 | 
				
			||||||
@@ -43,6 +43,13 @@ export class SyncService {
 | 
				
			|||||||
        this.save();
 | 
					        this.save();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    addPolygon(polygon: Polygon) {
 | 
				
			||||||
 | 
					        let map = this.mapSymbols.value;
 | 
				
			||||||
 | 
					        if(!map.polygons) map.polygons = [];
 | 
				
			||||||
 | 
					        map.polygons.push(polygon);
 | 
				
			||||||
 | 
					        this.save();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    addPolyline(polyline: Polyline) {
 | 
					    addPolyline(polyline: Polyline) {
 | 
				
			||||||
        let map = this.mapSymbols.value;
 | 
					        let map = this.mapSymbols.value;
 | 
				
			||||||
        if(!map.polylines) map.polylines = [];
 | 
					        if(!map.polylines) map.polylines = [];
 | 
				
			||||||
@@ -62,6 +69,7 @@ export class SyncService {
 | 
				
			|||||||
        if(map.circles) symbols.forEach(s => map.circles = map.circles.filter(c => !_.isEqual(s, c)));
 | 
					        if(map.circles) symbols.forEach(s => map.circles = map.circles.filter(c => !_.isEqual(s, c)));
 | 
				
			||||||
        if(map.markers) symbols.forEach(s => map.markers = map.markers.filter(m => !_.isEqual(s, m)));
 | 
					        if(map.markers) symbols.forEach(s => map.markers = map.markers.filter(m => !_.isEqual(s, m)));
 | 
				
			||||||
        if(map.measurements) symbols.forEach(s => map.measurements = map.measurements.filter(m => !_.isEqual(s, m)));
 | 
					        if(map.measurements) symbols.forEach(s => map.measurements = map.measurements.filter(m => !_.isEqual(s, m)));
 | 
				
			||||||
 | 
					        if(map.polygons) symbols.forEach(s => map.polygons = map.polygons.filter(p => !_.isEqual(s , p)));
 | 
				
			||||||
        if(map.polylines) symbols.forEach(s => map.polylines = map.polylines.filter(p => !_.isEqual(s, p)));
 | 
					        if(map.polylines) symbols.forEach(s => map.polylines = map.polylines.filter(p => !_.isEqual(s, p)));
 | 
				
			||||||
        if(map.rectangles) symbols.forEach(s => map.rectangles = map.rectangles.filter(r => !_.isEqual(s, r)));
 | 
					        if(map.rectangles) symbols.forEach(s => map.rectangles = map.rectangles.filter(r => !_.isEqual(s, r)));
 | 
				
			||||||
        this.save();
 | 
					        this.save();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,6 +27,7 @@ export class MapComponent implements OnInit {
 | 
				
			|||||||
    drawColor = '#ff4141';
 | 
					    drawColor = '#ff4141';
 | 
				
			||||||
    isNaN = isNaN;
 | 
					    isNaN = isNaN;
 | 
				
			||||||
    map: MapService;
 | 
					    map: MapService;
 | 
				
			||||||
 | 
					    polygon: any;
 | 
				
			||||||
    position;
 | 
					    position;
 | 
				
			||||||
    positionMarker = {arrow: null, circle: null};
 | 
					    positionMarker = {arrow: null, circle: null};
 | 
				
			||||||
    shareDialog = false;
 | 
					    shareDialog = false;
 | 
				
			||||||
@@ -104,6 +105,20 @@ export class MapComponent implements OnInit {
 | 
				
			|||||||
        })
 | 
					        })
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    startPolygon = () => {
 | 
				
			||||||
 | 
					        let lastPoint;
 | 
				
			||||||
 | 
					        this.sub = this.map.click.pipe(skip(1), finalize(() => this.map.delete(lastPoint))).subscribe(e => {
 | 
				
			||||||
 | 
					            if(!this.polygon) {
 | 
				
			||||||
 | 
					                let p = {latlng: [e.latlng], noDelete: true, color: '#ff4141'};
 | 
				
			||||||
 | 
					                this.polygon = this.map.newPolygon(p)
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                this.polygon.addLatLng(e.latlng);
 | 
				
			||||||
 | 
					                this.map.delete(lastPoint);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            lastPoint = this.map.newMarker({latlng: e.latlng, color: '#ff4141'});
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    startRectangle = menuItem => {
 | 
					    startRectangle = menuItem => {
 | 
				
			||||||
        let lastPoint;
 | 
					        let lastPoint;
 | 
				
			||||||
        this.sub = this.map.click.pipe(skip(1), take(2), finalize(() => this.map.delete(lastPoint))).subscribe(e => {
 | 
					        this.sub = this.map.click.pipe(skip(1), take(2), finalize(() => this.map.delete(lastPoint))).subscribe(e => {
 | 
				
			||||||
@@ -121,6 +136,19 @@ export class MapComponent implements OnInit {
 | 
				
			|||||||
        })
 | 
					        })
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    stopPolygon = () => {
 | 
				
			||||||
 | 
					        if(this.polygon) {
 | 
				
			||||||
 | 
					            let p = {latlng: this.polygon.getLatLngs()[0].map(latlng => ({lat: latlng.lat, lng: latlng.lng})), color: '#ff4141'};
 | 
				
			||||||
 | 
					            this.map.delete(this.polygon);
 | 
				
			||||||
 | 
					            this.polygon = null;
 | 
				
			||||||
 | 
					            this.syncService.addPolygon(p);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (this.sub) {
 | 
				
			||||||
 | 
					            this.sub.unsubscribe();
 | 
				
			||||||
 | 
					            this.sub = null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    unsub = () => {
 | 
					    unsub = () => {
 | 
				
			||||||
        if (this.sub) {
 | 
					        if (this.sub) {
 | 
				
			||||||
            this.sub.unsubscribe();
 | 
					            this.sub.unsubscribe();
 | 
				
			||||||
@@ -133,7 +161,7 @@ export class MapComponent implements OnInit {
 | 
				
			|||||||
        {name: 'Draw', icon: 'create', toggle: true, onEnabled: this.startDrawing, onDisabled: this.unsub},
 | 
					        {name: 'Draw', icon: 'create', toggle: true, onEnabled: this.startDrawing, onDisabled: this.unsub},
 | 
				
			||||||
        {name: 'Circle', icon: 'panorama_fish_eye', toggle: true, onEnabled: this.startCircle, onDisabled: this.unsub},
 | 
					        {name: 'Circle', icon: 'panorama_fish_eye', toggle: true, onEnabled: this.startCircle, onDisabled: this.unsub},
 | 
				
			||||||
        {name: 'Square', icon: 'crop_square', toggle: true, onEnabled: this.startRectangle, onDisabled: this.unsub},
 | 
					        {name: 'Square', icon: 'crop_square', toggle: true, onEnabled: this.startRectangle, onDisabled: this.unsub},
 | 
				
			||||||
        {name: 'Polygon', icon: 'details', toggle: true},
 | 
					        {name: 'Polygon', icon: 'details', toggle: true, onEnabled: this.startPolygon, onDisabled: this.stopPolygon},
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            name: 'Measure',
 | 
					            name: 'Measure',
 | 
				
			||||||
            icon: 'straighten',
 | 
					            icon: 'straighten',
 | 
				
			||||||
@@ -192,6 +220,7 @@ export class MapComponent implements OnInit {
 | 
				
			|||||||
                if (map.circles) map.circles.forEach(c => this.map.newCircle(c));
 | 
					                if (map.circles) map.circles.forEach(c => this.map.newCircle(c));
 | 
				
			||||||
                if (map.markers) map.markers.forEach(m => this.map.newMarker(m));
 | 
					                if (map.markers) map.markers.forEach(m => this.map.newMarker(m));
 | 
				
			||||||
                if (map.measurements) map.measurements.forEach(m => this.map.newMeasurement(m));
 | 
					                if (map.measurements) map.measurements.forEach(m => this.map.newMeasurement(m));
 | 
				
			||||||
 | 
					                if (map.polygons) map.polygons.forEach(p => this.map.newPolygon(p));
 | 
				
			||||||
                if (map.polylines) map.polylines.forEach(p => this.map.newPolyline(p));
 | 
					                if (map.polylines) map.polylines.forEach(p => this.map.newPolyline(p));
 | 
				
			||||||
                if (map.rectangles) map.rectangles.forEach(r => this.map.newRectangle(r));
 | 
					                if (map.rectangles) map.rectangles.forEach(r => this.map.newRectangle(r));
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user