Showing
1 changed file
with
45 additions
and
7 deletions
@@ -16,12 +16,12 @@ | @@ -16,12 +16,12 @@ | ||
16 | 16 | ||
17 | import L, { | 17 | import L, { |
18 | FeatureGroup, | 18 | FeatureGroup, |
19 | - Icon, | 19 | + Icon, LatLng, |
20 | LatLngBounds, | 20 | LatLngBounds, |
21 | LatLngTuple, | 21 | LatLngTuple, |
22 | markerClusterGroup, | 22 | markerClusterGroup, |
23 | MarkerClusterGroup, | 23 | MarkerClusterGroup, |
24 | - MarkerClusterGroupOptions | 24 | + MarkerClusterGroupOptions, Projection |
25 | } from 'leaflet'; | 25 | } from 'leaflet'; |
26 | import tinycolor from 'tinycolor2'; | 26 | import tinycolor from 'tinycolor2'; |
27 | import 'leaflet-providers'; | 27 | import 'leaflet-providers'; |
@@ -208,14 +208,52 @@ export default abstract class LeafletMap { | @@ -208,14 +208,52 @@ export default abstract class LeafletMap { | ||
208 | if (this.options.showPolygon && this.options.editablePolygon) { | 208 | if (this.options.showPolygon && this.options.editablePolygon) { |
209 | let mousePositionOnMap: L.LatLng[]; | 209 | let mousePositionOnMap: L.LatLng[]; |
210 | let addPolygon: L.Control; | 210 | let addPolygon: L.Control; |
211 | + let latlng1: LatLng; | ||
211 | this.map.on('mousemove', (e: L.LeafletMouseEvent) => { | 212 | this.map.on('mousemove', (e: L.LeafletMouseEvent) => { |
212 | - const polygonOffset = this.options.provider === MapProviders.image ? 10 : 0.01; | ||
213 | - const latlng1 = e.latlng; | ||
214 | - const latlng2 = L.latLng(e.latlng.lat, e.latlng.lng + polygonOffset); | ||
215 | - const latlng3 = L.latLng(e.latlng.lat - polygonOffset, e.latlng.lng); | ||
216 | - mousePositionOnMap = [latlng1, latlng2, latlng3]; | 213 | + latlng1 = e.latlng; |
217 | }); | 214 | }); |
215 | + | ||
218 | const dragListener = (e: L.DragEndEvent) => { | 216 | const dragListener = (e: L.DragEndEvent) => { |
217 | + const polygonOffset = this.options.provider === MapProviders.image ? 10 : 0.01; | ||
218 | + | ||
219 | + if(this.options.provider !== MapProviders.image) { | ||
220 | + if (latlng1.lng > 180-polygonOffset) { | ||
221 | + latlng1.lng = 180-polygonOffset; | ||
222 | + } else if (latlng1.lng < -180) { | ||
223 | + latlng1.lng = -180; | ||
224 | + } | ||
225 | + | ||
226 | + const maxLatitude = Projection.SphericalMercator['MAX_LATITUDE']; | ||
227 | + if(latlng1.lat > maxLatitude){ | ||
228 | + latlng1.lat = maxLatitude; | ||
229 | + }else if(latlng1.lat < -maxLatitude + polygonOffset){ | ||
230 | + latlng1.lat = -maxLatitude + polygonOffset; | ||
231 | + } | ||
232 | + } | ||
233 | + | ||
234 | + const latlng2 = L.latLng(latlng1.lat, latlng1.lng + polygonOffset); | ||
235 | + const latlng3 = L.latLng(latlng1.lat - polygonOffset, latlng1.lng); | ||
236 | + mousePositionOnMap = [latlng1, latlng2, latlng3]; | ||
237 | + | ||
238 | + if(this.options.provider === MapProviders.image) { | ||
239 | + for (let i = 0; i < mousePositionOnMap.length; i++) { | ||
240 | + let convert = this.convertToCustomFormat(mousePositionOnMap[i]) | ||
241 | + mousePositionOnMap[i].lat = convert['latitude']; | ||
242 | + mousePositionOnMap[i].lng = convert['longitude']; | ||
243 | + if (convert['xPos']== 1 && (i == 0 || i == 2)) { | ||
244 | + mousePositionOnMap[i].lng -= 10; | ||
245 | + } else if (convert['xPos'] == 0 && i == 1) { | ||
246 | + mousePositionOnMap[i].lng += 10; | ||
247 | + } | ||
248 | + if (convert['yPos']== 0 && i == 2) { | ||
249 | + mousePositionOnMap[i].lat -= 10; | ||
250 | + } else if (convert['yPos'] == 1 && (i == 0 || i == 1)) { | ||
251 | + mousePositionOnMap[i].lat += 10; | ||
252 | + } | ||
253 | + } | ||
254 | + } | ||
255 | + | ||
256 | + | ||
219 | if (e.type === 'dragend' && mousePositionOnMap) { | 257 | if (e.type === 'dragend' && mousePositionOnMap) { |
220 | const newPolygon = L.polygon(mousePositionOnMap).addTo(this.map); | 258 | const newPolygon = L.polygon(mousePositionOnMap).addTo(this.map); |
221 | this.addPolygons.push(newPolygon); | 259 | this.addPolygons.push(newPolygon); |