1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311 | 1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
114×
114×
114×
114×
114×
1×
1×
2×
2×
2×
2×
1×
2×
2×
2×
1×
1×
36×
36×
36×
36×
1×
43×
1×
3×
1×
2×
2×
2×
2×
1×
30×
30×
30×
30×
30×
30×
30×
47×
47×
47×
47×
47×
30×
1×
1×
1×
1×
1×
1×
1×
1×
2×
2×
2×
2×
1×
1×
2×
2×
2×
2×
2×
2×
1×
42×
1×
2×
1×
114×
28×
86×
86×
86×
86×
86×
86×
1×
55×
55×
55×
1×
10×
10×
10×
10×
10×
17×
17×
10×
17×
17×
10×
| goog.provide('ol.geom.MultiLineString');
goog.require('ol');
goog.require('ol.array');
goog.require('ol.extent');
goog.require('ol.geom.GeometryLayout');
goog.require('ol.geom.GeometryType');
goog.require('ol.geom.LineString');
goog.require('ol.geom.SimpleGeometry');
goog.require('ol.geom.flat.closest');
goog.require('ol.geom.flat.deflate');
goog.require('ol.geom.flat.inflate');
goog.require('ol.geom.flat.interpolate');
goog.require('ol.geom.flat.intersectsextent');
goog.require('ol.geom.flat.simplify');
/**
* @classdesc
* Multi-linestring geometry.
*
* @constructor
* @extends {ol.geom.SimpleGeometry}
* @param {Array.<Array.<ol.Coordinate>>} coordinates Coordinates.
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
* @api
*/
ol.geom.MultiLineString = function(coordinates, opt_layout) {
ol.geom.SimpleGeometry.call(this);
/**
* @type {Array.<number>}
* @private
*/
this.ends_ = [];
/**
* @private
* @type {number}
*/
this.maxDelta_ = -1;
/**
* @private
* @type {number}
*/
this.maxDeltaRevision_ = -1;
this.setCoordinates(coordinates, opt_layout);
};
ol.inherits(ol.geom.MultiLineString, ol.geom.SimpleGeometry);
/**
* Append the passed linestring to the multilinestring.
* @param {ol.geom.LineString} lineString LineString.
* @api
*/
ol.geom.MultiLineString.prototype.appendLineString = function(lineString) {
Iif (!this.flatCoordinates) {
this.flatCoordinates = lineString.getFlatCoordinates().slice();
} else {
ol.array.extend(
this.flatCoordinates, lineString.getFlatCoordinates().slice());
}
this.ends_.push(this.flatCoordinates.length);
this.changed();
};
/**
* Make a complete copy of the geometry.
* @return {!ol.geom.MultiLineString} Clone.
* @override
* @api
*/
ol.geom.MultiLineString.prototype.clone = function() {
var multiLineString = new ol.geom.MultiLineString(null);
multiLineString.setFlatCoordinates(
this.layout, this.flatCoordinates.slice(), this.ends_.slice());
return multiLineString;
};
/**
* @inheritDoc
*/
ol.geom.MultiLineString.prototype.closestPointXY = function(x, y, closestPoint, minSquaredDistance) {
if (minSquaredDistance <
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
return minSquaredDistance;
}
if (this.maxDeltaRevision_ != this.getRevision()) {
this.maxDelta_ = Math.sqrt(ol.geom.flat.closest.getsMaxSquaredDelta(
this.flatCoordinates, 0, this.ends_, this.stride, 0));
this.maxDeltaRevision_ = this.getRevision();
}
return ol.geom.flat.closest.getsClosestPoint(
this.flatCoordinates, 0, this.ends_, this.stride,
this.maxDelta_, false, x, y, closestPoint, minSquaredDistance);
};
/**
* Returns the coordinate at `m` using linear interpolation, or `null` if no
* such coordinate exists.
*
* `opt_extrapolate` controls extrapolation beyond the range of Ms in the
* MultiLineString. If `opt_extrapolate` is `true` then Ms less than the first
* M will return the first coordinate and Ms greater than the last M will
* return the last coordinate.
*
* `opt_interpolate` controls interpolation between consecutive LineStrings
* within the MultiLineString. If `opt_interpolate` is `true` the coordinates
* will be linearly interpolated between the last coordinate of one LineString
* and the first coordinate of the next LineString. If `opt_interpolate` is
* `false` then the function will return `null` for Ms falling between
* LineStrings.
*
* @param {number} m M.
* @param {boolean=} opt_extrapolate Extrapolate. Default is `false`.
* @param {boolean=} opt_interpolate Interpolate. Default is `false`.
* @return {ol.Coordinate} Coordinate.
* @api
*/
ol.geom.MultiLineString.prototype.getCoordinateAtM = function(m, opt_extrapolate, opt_interpolate) {
Iif ((this.layout != ol.geom.GeometryLayout.XYM &&
this.layout != ol.geom.GeometryLayout.XYZM) ||
this.flatCoordinates.length === 0) {
return null;
}
var extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false;
var interpolate = opt_interpolate !== undefined ? opt_interpolate : false;
return ol.geom.flat.interpolate.lineStringsCoordinateAtM(this.flatCoordinates, 0,
this.ends_, this.stride, m, extrapolate, interpolate);
};
/**
* Return the coordinates of the multilinestring.
* @return {Array.<Array.<ol.Coordinate>>} Coordinates.
* @override
* @api
*/
ol.geom.MultiLineString.prototype.getCoordinates = function() {
return ol.geom.flat.inflate.coordinatess(
this.flatCoordinates, 0, this.ends_, this.stride);
};
/**
* @return {Array.<number>} Ends.
*/
ol.geom.MultiLineString.prototype.getEnds = function() {
return this.ends_;
};
/**
* Return the linestring at the specified index.
* @param {number} index Index.
* @return {ol.geom.LineString} LineString.
* @api
*/
ol.geom.MultiLineString.prototype.getLineString = function(index) {
Iif (index < 0 || this.ends_.length <= index) {
return null;
}
var lineString = new ol.geom.LineString(null);
lineString.setFlatCoordinates(this.layout, this.flatCoordinates.slice(
index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]));
return lineString;
};
/**
* Return the linestrings of this multilinestring.
* @return {Array.<ol.geom.LineString>} LineStrings.
* @api
*/
ol.geom.MultiLineString.prototype.getLineStrings = function() {
var flatCoordinates = this.flatCoordinates;
var ends = this.ends_;
var layout = this.layout;
/** @type {Array.<ol.geom.LineString>} */
var lineStrings = [];
var offset = 0;
var i, ii;
for (i = 0, ii = ends.length; i < ii; ++i) {
var end = ends[i];
var lineString = new ol.geom.LineString(null);
lineString.setFlatCoordinates(layout, flatCoordinates.slice(offset, end));
lineStrings.push(lineString);
offset = end;
}
return lineStrings;
};
/**
* @return {Array.<number>} Flat midpoints.
*/
ol.geom.MultiLineString.prototype.getFlatMidpoints = function() {
var midpoints = [];
var flatCoordinates = this.flatCoordinates;
var offset = 0;
var ends = this.ends_;
var stride = this.stride;
var i, ii;
for (i = 0, ii = ends.length; i < ii; ++i) {
var end = ends[i];
var midpoint = ol.geom.flat.interpolate.lineString(
flatCoordinates, offset, end, stride, 0.5);
ol.array.extend(midpoints, midpoint);
offset = end;
}
return midpoints;
};
/**
* @inheritDoc
*/
ol.geom.MultiLineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
var simplifiedFlatCoordinates = [];
var simplifiedEnds = [];
simplifiedFlatCoordinates.length = ol.geom.flat.simplify.douglasPeuckers(
this.flatCoordinates, 0, this.ends_, this.stride, squaredTolerance,
simplifiedFlatCoordinates, 0, simplifiedEnds);
var simplifiedMultiLineString = new ol.geom.MultiLineString(null);
simplifiedMultiLineString.setFlatCoordinates(
ol.geom.GeometryLayout.XY, simplifiedFlatCoordinates, simplifiedEnds);
return simplifiedMultiLineString;
};
/**
* @inheritDoc
* @api
*/
ol.geom.MultiLineString.prototype.getType = function() {
return ol.geom.GeometryType.MULTI_LINE_STRING;
};
/**
* @inheritDoc
* @api
*/
ol.geom.MultiLineString.prototype.intersectsExtent = function(extent) {
return ol.geom.flat.intersectsextent.lineStrings(
this.flatCoordinates, 0, this.ends_, this.stride, extent);
};
/**
* Set the coordinates of the multilinestring.
* @param {Array.<Array.<ol.Coordinate>>} coordinates Coordinates.
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
* @override
* @api
*/
ol.geom.MultiLineString.prototype.setCoordinates = function(coordinates, opt_layout) {
if (!coordinates) {
this.setFlatCoordinates(ol.geom.GeometryLayout.XY, null, this.ends_);
} else {
this.setLayout(opt_layout, coordinates, 2);
Eif (!this.flatCoordinates) {
this.flatCoordinates = [];
}
var ends = ol.geom.flat.deflate.coordinatess(
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
this.changed();
}
};
/**
* @param {ol.geom.GeometryLayout} layout Layout.
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {Array.<number>} ends Ends.
*/
ol.geom.MultiLineString.prototype.setFlatCoordinates = function(layout, flatCoordinates, ends) {
this.setFlatCoordinatesInternal(layout, flatCoordinates);
this.ends_ = ends;
this.changed();
};
/**
* @param {Array.<ol.geom.LineString>} lineStrings LineStrings.
*/
ol.geom.MultiLineString.prototype.setLineStrings = function(lineStrings) {
var layout = this.getLayout();
var flatCoordinates = [];
var ends = [];
var i, ii;
for (i = 0, ii = lineStrings.length; i < ii; ++i) {
var lineString = lineStrings[i];
if (i === 0) {
layout = lineString.getLayout();
}
ol.array.extend(flatCoordinates, lineString.getFlatCoordinates());
ends.push(flatCoordinates.length);
}
this.setFlatCoordinates(layout, flatCoordinates, ends);
};
|