vendor: 6,548 bytes, lines 1-272
1L.Edit = L.Edit || {}; 2 3/** 4 * @class L.Edit.Polyline 5 * @aka L.Edit.Poly 6 * @aka Edit.Poly 7 */ 8L.Edit.Poly = L.Handler.extend({ 9 // @method initialize(): void 10 initialize: function (poly) { 11 12 this.latlngs = [poly._latlngs]; 13 if (poly._holes) { 14 this.latlngs = this.latlngs.concat(poly._holes); 15 } 16 17 this._poly = poly; 18 19 this._poly.on('revert-edited', this._updateLatLngs, this); 20 }, 21 22 // Compatibility method to normalize Poly* objects 23 // between 0.7.x and 1.0+ 24 _defaultShape: function () { 25 if (!L.Polyline._flat) { 26 return this._poly._latlngs; 27 } 28 return L.Polyline._flat(this._poly._latlngs) ? this._poly._latlngs : this._poly._latlngs[0]; 29 }, 30 31 _eachVertexHandler: function (callback) { 32 for (var i = 0; i < this._verticesHandlers.length; i++) { 33 callback(this._verticesHandlers[i]); 34 } 35 }, 36 37 // @method addHooks(): void 38 // Add listener hooks to this handler 39 addHooks: function () { 40 this._initHandlers(); 41 this._eachVertexHandler(function (handler) { 42 handler.addHooks(); 43 }); 44 }, 45 46 // @method removeHooks(): void 47 // Remove listener hooks from this handler 48 removeHooks: function () { 49 this._eachVertexHandler(function (handler) { 50 handler.removeHooks(); 51 }); 52 }, 53 54 // @method updateMarkers(): void 55 // Fire an update for each vertex handler 56 updateMarkers: function () { 57 this._eachVertexHandler(function (handler) { 58 handler.updateMarkers(); 59 }); 60 }, 61 62 _initHandlers: function () { 63 this._verticesHandlers = []; 64 for (var i = 0; i < this.latlngs.length; i++) { 65 this._verticesHandlers.push(new L.Edit.PolyVerticesEdit(this._poly, this.latlngs[i], this._poly.options.poly)); 66 } 67 }, 68 69 _updateLatLngs: function (e) { 70 this.latlngs = [e.layer._latlngs]; 71 if (e.layer._holes) { 72 this.latlngs = this.latlngs.concat(e.layer._holes); 73 } 74 } 75 76}); 77 78/** 79 * @class L.Edit.PolyVerticesEdit 80 * @aka Edit.PolyVerticesEdit 81 */ 82L.Edit.PolyVerticesEdit = L.Handler.extend({ 83 options: { 84 icon: new L.DivIcon({ 85 iconSize: new L.Point(8, 8), 86 className: 'leaflet-div-icon leaflet-editing-icon' 87 }), 88 touchIcon: new L.DivIcon({ 89 iconSize: new L.Point(20, 20), 90 className: 'leaflet-div-icon leaflet-editing-icon leaflet-touch-icon' 91 }), 92 drawError: { 93 color: '#b00b00', 94 timeout: 1000 95 } 96 97 98 }, 99 100 // @method intialize(): void 101 initialize: function (poly, latlngs, options) { 102 // if touch, switch to touch icon 103 if (L.Browser.touch) { 104 this.options.icon = this.options.touchIcon; 105 } 106 this._poly = poly; 107 108 if (options && options.drawError) { 109 options.drawError = L.Util.extend({}, this.options.drawError, options.drawError); 110 } 111 112 this._latlngs = latlngs; 113 114 L.setOptions(this, options); 115 }, 116 117 // Compatibility method to normalize Poly* objects 118 // between 0.7.x and 1.0+ 119 _defaultShape: function () { 120 if (!L.Polyline._flat) { 121 return this._latlngs; 122 } 123 return L.Polyline._flat(this._latlngs) ? this._latlngs : this._latlngs[0]; 124 }, 125 126 // @method addHooks(): void 127 // Add listener hooks to this handler. 128 addHooks: function () { 129 var poly = this._poly; 130 var path = poly._path; 131 132 if (!(poly instanceof L.Polygon)) { 133 poly.options.fill = false; 134 if (poly.options.editing) { 135 poly.options.editing.fill = false; 136 } 137 } 138 139 if (path) { 140 if (poly.options.editing && poly.options.editing.className) { 141 if (poly.options.original.className) { 142 poly.options.original.className.split(' ').forEach(function (className) { 143 L.DomUtil.removeClass(path, className); 144 }); 145 } 146 poly.options.editing.className.split(' ').forEach(function (className) { 147 L.DomUtil.addClass(path, className); 148 }); 149 } 150 } 151 152 poly.setStyle(poly.options.editing); 153 154 if (this._poly._map) { 155 156 this._map = this._poly._map; // Set map 157 158 if (!this._markerGroup) { 159 this._initMarkers(); 160 } 161 this._poly._map.addLayer(this._markerGroup); 162 } 163 }, 164 165 // @method removeHooks(): void 166 // Remove listener hooks from this handler. 167 removeHooks: function () { 168 var poly = this._poly; 169 var path = poly._path; 170 171 if (path) { 172 if (poly.options.editing && poly.options.editing.className) { 173 poly.options.editing.className.split(' ').forEach(function (className) { 174 L.DomUtil.removeClass(path, className); 175 }); 176 if (poly.options.original.className) { 177 poly.options.original.className.split(' ').forEach(function (className) { 178 L.DomUtil.addClass(path, className); 179 }); 180 } 181 } 182 } 183 184 poly.setStyle(poly.options.original); 185 186 if (poly._map) { 187 poly._map.removeLayer(this._markerGroup); 188 delete this._markerGroup; 189 delete this._markers; 190 } 191 }, 192 193 // @method updateMarkers(): void 194 // Clear markers and update their location 195 updateMarkers: function () { 196 this._markerGroup.clearLayers(); 197 this._initMarkers(); 198 }, 199 200 _initMarkers: function () { 201 if (!this._markerGroup) { 202 this._markerGroup = new L.LayerGroup(); 203 } 204 this._markers = []; 205 206 var latlngs = this._defaultShape(), 207 i, j, len, marker; 208 209 for (i = 0, len = latlngs.length; i < len; i++) { 210 211 marker = this._createMarker(latlngs[i], i); 212 marker.on('click', this._onMarkerClick, this); 213 marker.on('contextmenu', this._onContextMenu, this); 214 this._markers.push(marker); 215 } 216 217 var markerLeft, markerRight; 218 219 for (i = 0, j = len - 1; i < len; j = i++) { 220 if (i === 0 && !(L.Polygon && (this._poly instanceof L.Polygon))) { 221 continue; 222 } 223 224 markerLeft = this._markers[j]; 225 markerRight = this._markers[i]; 226 227 this._createMiddleMarker(markerLeft, markerRight); 228 this._updatePrevNext(markerLeft, markerRight); 229 } 230 }, 231 232 _createMarker: function (latlng, index) { 233 // Extending L.Marker in TouchEvents.js to include touch. 234 var marker = new L.Marker.Touch(latlng, { 235 draggable: true, 236 icon: this.options.icon, 237 }); 238 239 marker._origLatLng = latlng; 240 marker._index = index; 241 242 marker 243 .on('dragstart', this._onMarkerDragStart, this) 244 .on('drag', this._onMarkerDrag, this) 245 .on('dragend', this._fireEdit, this) 246 .on('touchmove', this._onTouchMove, this) 247 .on('touchend', this._fireEdit, this) 248 .on('MSPointerMove', this._onTouchMove, this) 249 .on('MSPointerUp', this._fireEdit, this); 250 251 this._markerGroup.addLayer(marker); 252 253 return marker; 254 }, 255 256 _onMarkerDragStart: function () { 257 this._poly.fire('editstart'); 258 }, 259 260 _spliceLatLngs: function () { 261 var latlngs = this._defaultShape(); 262 var removed = [].splice.apply(latlngs, arguments); 263 this._poly._convertLatLngs(latlngs, true); 264 this._poly.redraw(); 265 return removed; 266 }, 267 268 _removeMarker: function (marker) { 269 var i = marker._index; 270 271 this._markerGroup.removeLayer(marker); 272 this._markers.splice(i, 1);
273 this._spliceLatLngs(i, 1); 274 this._updateIndexes(i, -1); 275 276 marker 277 .off('dragstart', this._onMarkerDragStart, this) 278 .off('drag', this._onMarkerDrag, this) 279 .off('dragend', this._fireEdit, this) 280 .off('touchmove', this._onMarkerDrag, this) 281 .off('touchend', this._fireEdit, this) 282 .off('click', this._onMarkerClick, this) 283 .off('MSPointerMove', this._onTouchMove, this) 284 .off('MSPointerUp', this._fireEdit, this); 285 }, 286 287 _fireEdit: function () { 288 this._poly.edited = true; 289 this._poly.fire('edit'); 290 this._poly._map.fire(L.Draw.Event.EDITVERTEX, {layers: this._markerGroup, poly: this._poly}); 291 }, 292 293 _onMarkerDrag: function (e) { 294 var marker = e.target; 295 var poly = this._poly; 296 297 L.extend(marker._origLatLng, marker._latlng); 298 299 if (marker._middleLeft) { 300 marker._middleLeft.setLatLng(this._getMiddleLatLng(marker._prev, marker)); 301 } 302 if (marker._middleRight) { 303 marker._middleRight.setLatLng(this._getMiddleLatLng(marker, marker._next)); 304 } 305 306 if (poly.options.poly) { 307 var tooltip = poly._map._editTooltip; // Access the tooltip 308 309 // If we don't allow intersections and the polygon intersects 310 if (!poly.options.poly.allowIntersection && poly.intersects()) { 311 312 var originalColor = poly.options.color; 313 poly.setStyle({color: this.options.drawError.color}); 314 315 // Manually trigger 'dragend' behavior on marker we are about to remove 316 // WORKAROUND: introduced in 1.0.0-rc2, may be related to #4484 317 if (L.version.indexOf('0.7') !== 0) { 318 marker.dragging._draggable._onUp(e); 319 } 320 this._onMarkerClick(e); // Remove violating marker 321 // FIXME: Reset the marker to it's original position (instead of remove) 322 323 if (tooltip) { 324 tooltip.updateContent({ 325 text: L.drawLocal.draw.handlers.polyline.error 326 }); 327 } 328 329 // Reset everything back to normal after a second 330 setTimeout(function () { 331 poly.setStyle({color: originalColor}); 332 if (tooltip) { 333 tooltip.updateContent({ 334 text: L.drawLocal.edit.handlers.edit.tooltip.text, 335 subtext: L.drawLocal.edit.handlers.edit.tooltip.subtext 336 }); 337 } 338 }, 1000); 339 } 340 } 341 //refresh the bounds when draging 342 this._poly._bounds._southWest = L.latLng(Infinity, Infinity); 343 this._poly._bounds._northEast = L.latLng(-Infinity, -Infinity); 344 var latlngs = this._poly.getLatLngs(); 345 this._poly._convertLatLngs(latlngs, true); 346 this._poly.redraw(); 347 this._poly.fire('editdrag'); 348 }, 349 350 _onMarkerClick: function (e) { 351 352 var minPoints = L.Polygon && (this._poly instanceof L.Polygon) ? 4 : 3, 353 marker = e.target; 354 355 // If removing this point would create an invalid polyline/polygon don't remove 356 if (this._defaultShape().length < minPoints) { 357 return; 358 } 359 360 // remove the marker 361 this._removeMarker(marker); 362 363 // update prev/next links of adjacent markers 364 this._updatePrevNext(marker._prev, marker._next); 365 366 // remove ghost markers near the removed marker 367 if (marker._middleLeft) { 368 this._markerGroup.removeLayer(marker._middleLeft); 369 } 370 if (marker._middleRight) { 371 this._markerGroup.removeLayer(marker._middleRight); 372 } 373 374 // create a ghost marker in place of the removed one 375 if (marker._prev && marker._next) { 376 this._createMiddleMarker(marker._prev, marker._next); 377 378 } else if (!marker._prev) { 379 marker._next._middleLeft = null; 380 381 } else if (!marker._next) { 382 marker._prev._middleRight = null; 383 } 384 385 this._fireEdit(); 386 }, 387 388 _onContextMenu: function (e) { 389 var marker = e.target; 390 var poly = this._poly; 391 this._poly._map.fire(L.Draw.Event.MARKERCONTEXT, {marker: marker, layers: this._markerGroup, poly: this._poly}); 392 L.DomEvent.stopPropagation; 393 }, 394 395 _onTouchMove: function (e) { 396 397 var layerPoint = this._map.mouseEventToLayerPoint(e.originalEvent.touches[0]), 398 latlng = this._map.layerPointToLatLng(layerPoint), 399 marker = e.target; 400 401 L.extend(marker._origLatLng, latlng); 402 403 if (marker._middleLeft) { 404 marker._middleLeft.setLatLng(this._getMiddleLatLng(marker._prev, marker)); 405 } 406 if (marker._middleRight) { 407 marker._middleRight.setLatLng(this._getMiddleLatLng(marker, marker._next)); 408 } 409 410 this._poly.redraw(); 411 this.updateMarkers(); 412 }, 413 414 _updateIndexes: function (index, delta) { 415 this._markerGroup.eachLayer(function (marker) { 416 if (marker._index > index) { 417 marker._index += delta; 418 } 419 }); 420 }, 421 422 _createMiddleMarker: function (marker1, marker2) { 423 var latlng = this._getMiddleLatLng(marker1, marker2), 424 marker = this._createMarker(latlng), 425 onClick, 426 onDragStart, 427 onDragEnd; 428 429 marker.setOpacity(0.6); 430 431 marker1._middleRight = marker2._middleLeft = marker; 432 433 onDragStart = function () { 434 marker.off('touchmove', onDragStart, this); 435 var i = marker2._index; 436 437 marker._index = i; 438 439 marker 440 .off('click', onClick, this) 441 .on('click', this._onMarkerClick, this); 442 443 latlng.lat = marker.getLatLng().lat; 444 latlng.lng = marker.getLatLng().lng;
vendor: 1,791 bytes, lines 445-527
445 this._spliceLatLngs(i, 0, latlng); 446 this._markers.splice(i, 0, marker); 447 448 marker.setOpacity(1); 449 450 this._updateIndexes(i, 1); 451 marker2._index++; 452 this._updatePrevNext(marker1, marker); 453 this._updatePrevNext(marker, marker2); 454 455 this._poly.fire('editstart'); 456 }; 457 458 onDragEnd = function () { 459 marker.off('dragstart', onDragStart, this); 460 marker.off('dragend', onDragEnd, this); 461 marker.off('touchmove', onDragStart, this); 462 463 this._createMiddleMarker(marker1, marker); 464 this._createMiddleMarker(marker, marker2); 465 }; 466 467 onClick = function () { 468 onDragStart.call(this); 469 onDragEnd.call(this); 470 this._fireEdit(); 471 }; 472 473 marker 474 .on('click', onClick, this) 475 .on('dragstart', onDragStart, this) 476 .on('dragend', onDragEnd, this) 477 .on('touchmove', onDragStart, this); 478 479 this._markerGroup.addLayer(marker); 480 }, 481 482 _updatePrevNext: function (marker1, marker2) { 483 if (marker1) { 484 marker1._next = marker2; 485 } 486 if (marker2) { 487 marker2._prev = marker1; 488 } 489 }, 490 491 _getMiddleLatLng: function (marker1, marker2) { 492 var map = this._poly._map, 493 p1 = map.project(marker1.getLatLng()), 494 p2 = map.project(marker2.getLatLng()); 495 496 return map.unproject(p1._add(p2)._divideBy(2)); 497 } 498}); 499 500L.Polyline.addInitHook(function () { 501 502 // Check to see if handler has already been initialized. This is to support versions of Leaflet that still have L.Handler.PolyEdit 503 if (this.editing) { 504 return; 505 } 506 507 if (L.Edit.Poly) { 508 509 this.editing = new L.Edit.Poly(this); 510 511 if (this.options.editable) { 512 this.editing.enable(); 513 } 514 } 515 516 this.on('add', function () { 517 if (this.editing && this.editing.enabled()) { 518 this.editing.addHooks(); 519 } 520 }); 521 522 this.on('remove', function () { 523 if (this.editing && this.editing.enabled()) { 524 this.editing.removeHooks(); 525 } 526 }); 527});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.