Используя Angular2 v4, я пытаюсь создать новую вершину автоматически, пока рисую многоугольник в Leaflet. Я думаю, что эту проблему можно решить, просто установив TRUE, но я не знаю, что это за опция.
Это пример того, что я пытаюсь сделать (используя плагин листовки):
, если вы видите, когда я перетаскиваю какую-то точку, другая «частичная»вершины появляются автоматически.
Как я могу это сделать?
вот мой код:
import * as L from 'leaflet';
import 'leaflet-draw';
import 'leaflet-editable';
private createGeofencePolygonShape(g: Geofence) {
const point: L.LatLng = this.map.getCenter();
const r = 10;
const geofencePoints = new Array<L.LatLng>();
geofencePoints.push(new L.LatLng(0, 0));
geofencePoints.push(new L.LatLng(0, 0));
geofencePoints.push(new L.LatLng(0, 0));
geofencePoints.push(new L.LatLng(0, 0));
geofencePoints.push(new L.LatLng(0, 0));
const radiusM = 350; // no valid points - create default polygon
const crLat = this.geo.geoRadians(point.lat);
const crLon = this.geo.geoRadians(point.lng);
for (let x = 0; x < geofencePoints.length; x++) {
const deg = x * (360.0 / geofencePoints.length);
let radM = radiusM / this.geo.EARTH_RADIUS_METERS;
if ((deg === 0.0) || ((deg > 170.0) && (deg < 190.0))) { radM *= 0.8; }
const xrad = this.geo.geoRadians(deg);
const rrLat = Math.asin(Math.sin(crLat) * Math.cos(radM) + Math.cos(crLat) * Math.sin(radM) * Math.cos(xrad));
const rrLon = crLon + Math.atan2(Math.sin(xrad) * Math.sin(radM) * Math.cos(crLat), Math.cos(radM) - Math.sin(crLat) * Math.sin(rrLat));
if ((x >= 0) && (x < geofencePoints.length)) {
const lat = this.geo.geoDegrees(rrLat);
const lng = this.geo.geoDegrees(rrLon);
geofencePoints[x].lat = lat;
geofencePoints[x].lng = lng;
}
const polygon: L.Polygon = new L.Polygon(geofencePoints); // I Think this line is where I have to define the automatic new vertex
// Something like this:
// const polygon: L.Polygon = new L.Polygon(geofencePoints, {newVertex: true});
this.addingCoordinatesToGeofence(g, polygon);
this.editGeofenceMode = true;
this.geofences_to_draw = [];
this.geofences_to_draw.push(g);
this.drawNewGeofences();
}
}
И вот результат этого кода: