Commit 6932a32b876c16931926c1e15cafc0ffcb04422d

Authored by Kalutka Zhenya
1 parent 385b1484

change polygon script for image map, Refactoring

@@ -216,14 +216,29 @@ export default abstract class LeafletMap { @@ -216,14 +216,29 @@ export default abstract class LeafletMap {
216 const dragListener = (e: L.DragEndEvent) => { 216 const dragListener = (e: L.DragEndEvent) => {
217 const polygonOffset = this.options.provider === MapProviders.image ? 10 : 0.01; 217 const polygonOffset = this.options.provider === MapProviders.image ? 10 : 0.01;
218 218
219 - if(this.options.provider !== MapProviders.image) {  
220 - if (latlng1.lng > 180-polygonOffset) {  
221 - latlng1.lng = 180-polygonOffset; 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'];
  225 +
  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;
222 } else if (latlng1.lng < -180) { 238 } else if (latlng1.lng < -180) {
223 latlng1.lng = -180; 239 latlng1.lng = -180;
224 } 240 }
225 241
226 - const maxLatitude = Projection.SphericalMercator['MAX_LATITUDE'];  
227 if(latlng1.lat > maxLatitude){ 242 if(latlng1.lat > maxLatitude){
228 latlng1.lat = maxLatitude; 243 latlng1.lat = maxLatitude;
229 }else if(latlng1.lat < -maxLatitude + polygonOffset){ 244 }else if(latlng1.lat < -maxLatitude + polygonOffset){
@@ -235,25 +250,6 @@ export default abstract class LeafletMap { @@ -235,25 +250,6 @@ export default abstract class LeafletMap {
235 const latlng3 = L.latLng(latlng1.lat - polygonOffset, latlng1.lng); 250 const latlng3 = L.latLng(latlng1.lat - polygonOffset, latlng1.lng);
236 mousePositionOnMap = [latlng1, latlng2, latlng3]; 251 mousePositionOnMap = [latlng1, latlng2, latlng3];
237 252
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 -  
257 if (e.type === 'dragend' && mousePositionOnMap) { 253 if (e.type === 'dragend' && mousePositionOnMap) {
258 const newPolygon = L.polygon(mousePositionOnMap).addTo(this.map); 254 const newPolygon = L.polygon(mousePositionOnMap).addTo(this.map);
259 this.addPolygons.push(newPolygon); 255 this.addPolygons.push(newPolygon);