...
|
...
|
@@ -206,55 +206,30 @@ export default abstract class LeafletMap { |
206
|
206
|
|
207
|
207
|
addPolygonControl() {
|
208
|
208
|
if (this.options.showPolygon && this.options.editablePolygon) {
|
209
|
|
- let mousePositionOnMap: L.LatLng[];
|
|
209
|
+ let polygonPoints: L.LatLng[];
|
210
|
210
|
let addPolygon: L.Control;
|
211
|
|
- let latlng1: LatLng;
|
|
211
|
+ let mousePositionOnMap: LatLng;
|
212
|
212
|
this.map.on('mousemove', (e: L.LeafletMouseEvent) => {
|
213
|
|
- latlng1 = e.latlng;
|
|
213
|
+ mousePositionOnMap = e.latlng;
|
214
|
214
|
});
|
215
|
215
|
|
216
|
216
|
const dragListener = (e: L.DragEndEvent) => {
|
217
|
217
|
const polygonOffset = this.options.provider === MapProviders.image ? 10 : 0.01;
|
218
|
218
|
|
219
|
|
- if(this.options.provider === MapProviders.image) {
|
220
|
|
- latlng1.lng += polygonOffset;
|
221
|
|
- latlng1.lat -= polygonOffset;
|
222
|
|
- let convert = this.convertToCustomFormat(latlng1);
|
223
|
|
- latlng1.lat = convert['latitude'];
|
224
|
|
- latlng1.lng = convert['longitude'];
|
|
219
|
+ let convert = this.convertToCustomFormat(mousePositionOnMap,polygonOffset);
|
|
220
|
+ mousePositionOnMap.lat = convert[this.options.latKeyName];
|
|
221
|
+ mousePositionOnMap.lng = convert[this.options.lngKeyName];
|
225
|
222
|
|
226
|
|
- if (convert['xPos'] !== 0) {
|
227
|
|
- latlng1.lng -= polygonOffset;
|
228
|
|
- }
|
229
|
|
-
|
230
|
|
- if (convert['yPos'] !== 0) {
|
231
|
|
- latlng1.lat += polygonOffset;
|
232
|
|
- }
|
233
|
|
- } else {
|
234
|
|
- const maxLatitude = Projection.SphericalMercator['MAX_LATITUDE'];
|
235
|
|
-
|
236
|
|
- if (latlng1.lng > 180 - polygonOffset) {
|
237
|
|
- latlng1.lng = 180 - polygonOffset;
|
238
|
|
- } else if (latlng1.lng < -180) {
|
239
|
|
- latlng1.lng = -180;
|
240
|
|
- }
|
241
|
|
-
|
242
|
|
- if(latlng1.lat > maxLatitude){
|
243
|
|
- latlng1.lat = maxLatitude;
|
244
|
|
- }else if(latlng1.lat < -maxLatitude + polygonOffset){
|
245
|
|
- latlng1.lat = -maxLatitude + polygonOffset;
|
246
|
|
- }
|
247
|
|
- }
|
|
223
|
+ const latlng1 = mousePositionOnMap;
|
|
224
|
+ const latlng2 = L.latLng(mousePositionOnMap.lat, mousePositionOnMap.lng + polygonOffset);
|
|
225
|
+ const latlng3 = L.latLng(mousePositionOnMap.lat - polygonOffset, mousePositionOnMap.lng);
|
|
226
|
+ polygonPoints = [latlng1, latlng2, latlng3];
|
248
|
227
|
|
249
|
|
- const latlng2 = L.latLng(latlng1.lat, latlng1.lng + polygonOffset);
|
250
|
|
- const latlng3 = L.latLng(latlng1.lat - polygonOffset, latlng1.lng);
|
251
|
|
- mousePositionOnMap = [latlng1, latlng2, latlng3];
|
252
|
|
-
|
253
|
|
- if (e.type === 'dragend' && mousePositionOnMap) {
|
254
|
|
- const newPolygon = L.polygon(mousePositionOnMap).addTo(this.map);
|
|
228
|
+ if (e.type === 'dragend' && polygonPoints) {
|
|
229
|
+ const newPolygon = L.polygon(polygonPoints).addTo(this.map);
|
255
|
230
|
this.addPolygons.push(newPolygon);
|
256
|
231
|
const datasourcesList = document.createElement('div');
|
257
|
|
- const customLatLng = {[this.options.polygonKeyName]: this.convertToPolygonFormat(mousePositionOnMap)};
|
|
232
|
+ const customLatLng = {[this.options.polygonKeyName]: this.convertToPolygonFormat(polygonPoints)};
|
258
|
233
|
const header = document.createElement('p');
|
259
|
234
|
header.appendChild(document.createTextNode('Select entity:'));
|
260
|
235
|
header.setAttribute('style', 'font-size: 14px; margin: 8px 0');
|
...
|
...
|
@@ -448,12 +423,27 @@ export default abstract class LeafletMap { |
448
|
423
|
}).filter(el => !!el);
|
449
|
424
|
}
|
450
|
425
|
|
451
|
|
- convertToCustomFormat(position: L.LatLng): object {
|
452
|
|
- if (position.lng > 180) {
|
453
|
|
- position.lng = 180;
|
|
426
|
+
|
|
427
|
+ checkLngLat(position: L.LatLng, polygonOffset: number = 0){
|
|
428
|
+ const maxLatitude = Projection.SphericalMercator['MAX_LATITUDE'];
|
|
429
|
+ const minLatitude = -maxLatitude;
|
|
430
|
+ if (position.lng > 180 - polygonOffset) {
|
|
431
|
+ position.lng = 180 - polygonOffset;
|
454
|
432
|
} else if (position.lng < -180) {
|
455
|
|
- position.lng = -180;
|
|
433
|
+ position.lng= -180;
|
456
|
434
|
}
|
|
435
|
+
|
|
436
|
+ if(position.lat > maxLatitude){
|
|
437
|
+ position.lat = maxLatitude;
|
|
438
|
+ }else if(position.lat < minLatitude + polygonOffset){
|
|
439
|
+ position.lat = minLatitude + polygonOffset;
|
|
440
|
+ }
|
|
441
|
+ return position;
|
|
442
|
+ }
|
|
443
|
+
|
|
444
|
+ convertToCustomFormat(position: L.LatLng, polygonOffset: number = 0): object {
|
|
445
|
+ position = this.checkLngLat(position,polygonOffset)
|
|
446
|
+
|
457
|
447
|
return {
|
458
|
448
|
[this.options.latKeyName]: position.lat,
|
459
|
449
|
[this.options.lngKeyName]: position.lng
|
...
|
...
|
@@ -762,6 +752,11 @@ export default abstract class LeafletMap { |
762
|
752
|
if (e === undefined || (e.type !== 'editable:vertex:dragend' && e.type !== 'editable:vertex:deleted')) {
|
763
|
753
|
return;
|
764
|
754
|
}
|
|
755
|
+ if(this.options.provider !== MapProviders.image) {
|
|
756
|
+ for (let key in e.layer._latlngs[0]) {
|
|
757
|
+ e.layer._latlngs[0][key] = this.checkLngLat(e.layer._latlngs[0][key]);
|
|
758
|
+ }
|
|
759
|
+ }
|
765
|
760
|
this.savePolygonLocation({ ...data, ...this.convertPolygonToCustomFormat(e.layer._latlngs) }).subscribe();
|
766
|
761
|
}
|
767
|
762
|
|
...
|
...
|
|