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 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   - 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 238 } else if (latlng1.lng < -180) {
223 239 latlng1.lng = -180;
224 240 }
225 241
226   - const maxLatitude = Projection.SphericalMercator['MAX_LATITUDE'];
227 242 if(latlng1.lat > maxLatitude){
228 243 latlng1.lat = maxLatitude;
229 244 }else if(latlng1.lat < -maxLatitude + polygonOffset){
... ... @@ -235,25 +250,6 @@ export default abstract class LeafletMap {
235 250 const latlng3 = L.latLng(latlng1.lat - polygonOffset, latlng1.lng);
236 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 253 if (e.type === 'dragend' && mousePositionOnMap) {
258 254 const newPolygon = L.polygon(mousePositionOnMap).addTo(this.map);
259 255 this.addPolygons.push(newPolygon);
... ...