PageSourceSearch

https://dubaienergy.netlify.app/src/draw/handler/Draw.Polygon.js

js dubaienergy.netlify.app collected 2026-10-03 10:40:40 UTC 3,279 bytes, 129 lines download raw bytes

vendor: 3,279 bytes, lines 1-129
1/**
2 * @class L.Draw.Polygon
3 * @aka Draw.Polygon
4 * @inherits L.Draw.Polyline
5 */
6L.Draw.Polygon = L.Draw.Polyline.extend({
7	statics: {
8		TYPE: 'polygon'
9	},
10
11	Poly: L.Polygon,
12
13	options: {
14		showArea: false,
15		showLength: false,
16		shapeOptions: {
17			stroke: true,
18			color: '#3388ff',
19			weight: 4,
20			opacity: 0.5,
21			fill: true,
22			fillColor: null, //same as color by default
23			fillOpacity: 0.2,
24			clickable: true
25		},
26		// Whether to use the metric measurement system (truthy) or not (falsy).
27		// Also defines the units to use for the metric system as an array of
28		// strings (e.g. `['ha', 'm']`).
29		metric: true,
30		feet: true, // When not metric, to use feet instead of yards for display.
31		nautic: false, // When not metric, not feet use nautic mile for display
32		// Defines the precision for each type of unit (e.g. {km: 2, ft: 0}
33		precision: {}
34	},
35
36	// @method initialize(): void
37	initialize: function (map, options) {
38		L.Draw.Polyline.prototype.initialize.call(this, map, options);
39
40		// Save the type so super can fire, need to do this as cannot do this.TYPE :(
41		this.type = L.Draw.Polygon.TYPE;
42	},
43
44	_updateFinishHandler: function () {
45		var markerCount = this._markers.length;
46
47		// The first marker should have a click handler to close the polygon
48		if (markerCount === 1) {
49			this._markers[0].on('click', this._finishShape, this);
50		}
51
52		// Add and update the double click handler
53		if (markerCount > 2) {
54			this._markers[markerCount - 1].on('dblclick', this._finishShape, this);
55			// Only need to remove handler if has been added before
56			if (markerCount > 3) {
57				this._markers[markerCount - 2].off('dblclick', this._finishShape, this);
58			}
59		}
60	},
61
62	_getTooltipText: function () {
63		var text, subtext;
64
65		if (this._markers.length === 0) {
66			text = L.drawLocal.draw.handlers.polygon.tooltip.start;
67		} else if (this._markers.length < 3) {
68			text = L.drawLocal.draw.handlers.polygon.tooltip.cont;
69			subtext = this._getMeasurementString();
70		} else {
71			text = L.drawLocal.draw.handlers.polygon.tooltip.end;
72			subtext = this._getMeasurementString();
73		}
74
75		return {
76			text: text,
77			subtext: subtext
78		};
79	},
80
81	_getMeasurementString: function () {
82		var area = this._area,
83			measurementString = '';
84
85
86		if (!area && !this.options.showLength) {
87			return null;
88		}
89
90		if (this.options.showLength) {
91			measurementString = L.Draw.Polyline.prototype._getMeasurementString.call(this);
92		}
93
94		if (area) {
95			measurementString += '<br>' + L.GeometryUtil.readableArea(area, this.options.metric, this.options.precision);
96		}
97
98		return measurementString;
99	},
100
101	_shapeIsValid: function () {
102		return this._markers.length >= 3;
103	},
104
105	_vertexChanged: function (latlng, added) {
106		var latLngs;
107
108		// Check to see if we should show the area
109		if (!this.options.allowIntersection && this.options.showArea) {
110			latLngs = this._poly.getLatLngs();
111
112			this._area = L.GeometryUtil.geodesicArea(latLngs);
113		}
114
115		L.Draw.Polyline.prototype._vertexChanged.call(this, latlng, added);
116	},
117
118	_cleanUpShape: function () {
119		var markerCount = this._markers.length;
120
121		if (markerCount > 0) {
122			this._markers[0].off('click', this._finishShape, this);
123
124			if (markerCount > 2) {
125				this._markers[markerCount - 1].off('dblclick', this._finishShape, this);
126			}
127		}
128	}
129});

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.