Merge pull request #8362 from ahocevar/smart-flat-coordinates

Smart flat coordinates
This commit is contained in:
Andreas Hocevar
2018-07-09 10:27:11 +02:00
committed by GitHub
28 changed files with 321 additions and 478 deletions
+7 -1
View File
@@ -1,5 +1,11 @@
## Upgrade notes ## Upgrade notes
### Next release
#### Geometry constructor and `setCoordinates` no longer accept `null` coordinates
Geometries (`ol/geom/*`) now need to be constructed with valid coordinates (center for `ol/geom/Circle`) as first constructor argument. The same applies to the `setCoordinates()` (`setCenter() for `ol/geom/Circle`) method.
### v5.0.0 ### v5.0.0
#### Renamed `ol/source/TileUTFGrid` to `ol/source/UTFGrid` #### Renamed `ol/source/TileUTFGrid` to `ol/source/UTFGrid`
@@ -170,7 +176,7 @@ The optional this (i.e. opt_this) arguments were removed from the following meth
#### `Map#forEachLayerAtPixel` parameters have changed #### `Map#forEachLayerAtPixel` parameters have changed
If you are using the layer filter, please note that you now have to pass in the layer filter via an `AtPixelOptions` object. If you are not using the layer filter the usage has not changed. If you are using the layer filter, please note that you now have to pass in the layer filter via an `AtPixelOptions` object. If you are not using the layer filter the usage has not changed.
Old syntax: Old syntax:
+28 -10
View File
@@ -360,9 +360,13 @@ Graticule.prototype.getMeridianPoint_ = function(lineString, extent, index) {
extent[1] + Math.abs(extent[1] - extent[3]) * this.lonLabelPosition_, extent[1] + Math.abs(extent[1] - extent[3]) * this.lonLabelPosition_,
clampedBottom, clampedTop); clampedBottom, clampedTop);
const coordinate = [flatCoordinates[0], lat]; const coordinate = [flatCoordinates[0], lat];
const point = this.meridiansLabels_[index] !== undefined ? let point;
this.meridiansLabels_[index].geom : new Point(null); if (index in this.meridiansLabels_) {
point.setCoordinates(coordinate); point = this.meridiansLabels_[index];
point.setCoordinates(coordinate);
} else {
point = new Point(coordinate);
}
return point; return point;
}; };
@@ -408,9 +412,13 @@ Graticule.prototype.getParallelPoint_ = function(lineString, extent, index) {
extent[0] + Math.abs(extent[0] - extent[2]) * this.latLabelPosition_, extent[0] + Math.abs(extent[0] - extent[2]) * this.latLabelPosition_,
clampedLeft, clampedRight); clampedLeft, clampedRight);
const coordinate = [lon, flatCoordinates[1]]; const coordinate = [lon, flatCoordinates[1]];
const point = this.parallelsLabels_[index] !== undefined ? let point;
this.parallelsLabels_[index].geom : new Point(null); if (index in this.parallelsLabels_) {
point.setCoordinates(coordinate); point = this.parallelsLabels_[index];
point.setCoordinates(coordinate);
} else {
point = new Point(coordinate);
}
return point; return point;
}; };
@@ -563,8 +571,13 @@ Graticule.prototype.getMap = function() {
*/ */
Graticule.prototype.getMeridian_ = function(lon, minLat, maxLat, squaredTolerance, index) { Graticule.prototype.getMeridian_ = function(lon, minLat, maxLat, squaredTolerance, index) {
const flatCoordinates = meridian(lon, minLat, maxLat, this.projection_, squaredTolerance); const flatCoordinates = meridian(lon, minLat, maxLat, this.projection_, squaredTolerance);
const lineString = this.meridians_[index] !== undefined ? this.meridians_[index] : new LineString(null); let lineString = this.meridians_[index];
lineString.setFlatCoordinates(GeometryLayout.XY, flatCoordinates); if (!lineString) {
lineString = this.meridians_[index] = new LineString(flatCoordinates, GeometryLayout.XY);
} else {
lineString.setFlatCoordinates(GeometryLayout.XY, flatCoordinates);
lineString.changed();
}
return lineString; return lineString;
}; };
@@ -590,8 +603,13 @@ Graticule.prototype.getMeridians = function() {
*/ */
Graticule.prototype.getParallel_ = function(lat, minLon, maxLon, squaredTolerance, index) { Graticule.prototype.getParallel_ = function(lat, minLon, maxLon, squaredTolerance, index) {
const flatCoordinates = parallel(lat, minLon, maxLon, this.projection_, squaredTolerance); const flatCoordinates = parallel(lat, minLon, maxLon, this.projection_, squaredTolerance);
const lineString = this.parallels_[index] !== undefined ? this.parallels_[index] : new LineString(null); let lineString = this.parallels_[index];
lineString.setFlatCoordinates(GeometryLayout.XY, flatCoordinates); if (!lineString) {
lineString = new LineString(flatCoordinates, GeometryLayout.XY);
} else {
lineString.setFlatCoordinates(GeometryLayout.XY, flatCoordinates);
lineString.changed();
}
return lineString; return lineString;
}; };
+4 -13
View File
@@ -103,8 +103,7 @@ GML3.prototype.readMultiCurve_ = function(node, objectStack) {
const lineStrings = pushParseAndPop([], const lineStrings = pushParseAndPop([],
this.MULTICURVE_PARSERS_, node, objectStack, this); this.MULTICURVE_PARSERS_, node, objectStack, this);
if (lineStrings) { if (lineStrings) {
const multiLineString = new MultiLineString(null); const multiLineString = new MultiLineString(lineStrings);
multiLineString.setLineStrings(lineStrings);
return multiLineString; return multiLineString;
} else { } else {
return undefined; return undefined;
@@ -123,11 +122,7 @@ GML3.prototype.readMultiSurface_ = function(node, objectStack) {
const polygons = pushParseAndPop([], const polygons = pushParseAndPop([],
this.MULTISURFACE_PARSERS_, node, objectStack, this); this.MULTISURFACE_PARSERS_, node, objectStack, this);
if (polygons) { if (polygons) {
const multiPolygon = new MultiPolygon(null); return new MultiPolygon(polygons);
multiPolygon.setPolygons(polygons);
return multiPolygon;
} else {
return undefined;
} }
}; };
@@ -247,7 +242,6 @@ GML3.prototype.readSurface_ = function(node, objectStack) {
const flatLinearRings = pushParseAndPop([null], const flatLinearRings = pushParseAndPop([null],
this.SURFACE_PARSERS_, node, objectStack, this); this.SURFACE_PARSERS_, node, objectStack, this);
if (flatLinearRings && flatLinearRings[0]) { if (flatLinearRings && flatLinearRings[0]) {
const polygon = new Polygon(null);
const flatCoordinates = flatLinearRings[0]; const flatCoordinates = flatLinearRings[0];
const ends = [flatCoordinates.length]; const ends = [flatCoordinates.length];
let i, ii; let i, ii;
@@ -255,9 +249,7 @@ GML3.prototype.readSurface_ = function(node, objectStack) {
extend(flatCoordinates, flatLinearRings[i]); extend(flatCoordinates, flatLinearRings[i]);
ends.push(flatCoordinates.length); ends.push(flatCoordinates.length);
} }
polygon.setFlatCoordinates( return new Polygon(flatCoordinates, GeometryLayout.XYZ, ends);
GeometryLayout.XYZ, flatCoordinates, ends);
return polygon;
} else { } else {
return undefined; return undefined;
} }
@@ -275,8 +267,7 @@ GML3.prototype.readCurve_ = function(node, objectStack) {
const flatCoordinates = pushParseAndPop([null], const flatCoordinates = pushParseAndPop([null],
this.CURVE_PARSERS_, node, objectStack, this); this.CURVE_PARSERS_, node, objectStack, this);
if (flatCoordinates) { if (flatCoordinates) {
const lineString = new LineString(null); const lineString = new LineString(flatCoordinates, GeometryLayout.XYZ);
lineString.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates);
return lineString; return lineString;
} else { } else {
return undefined; return undefined;
+6 -23
View File
@@ -291,9 +291,7 @@ GMLBase.prototype.readFeatureElement = function(node, objectStack) {
GMLBase.prototype.readPoint = function(node, objectStack) { GMLBase.prototype.readPoint = function(node, objectStack) {
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack); const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
if (flatCoordinates) { if (flatCoordinates) {
const point = new Point(null); return new Point(flatCoordinates, GeometryLayout.XYZ);
point.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates);
return point;
} }
}; };
@@ -325,11 +323,7 @@ GMLBase.prototype.readMultiLineString = function(node, objectStack) {
const lineStrings = pushParseAndPop([], const lineStrings = pushParseAndPop([],
this.MULTILINESTRING_PARSERS_, node, objectStack, this); this.MULTILINESTRING_PARSERS_, node, objectStack, this);
if (lineStrings) { if (lineStrings) {
const multiLineString = new MultiLineString(null); return new MultiLineString(lineStrings);
multiLineString.setLineStrings(lineStrings);
return multiLineString;
} else {
return undefined;
} }
}; };
@@ -343,11 +337,7 @@ GMLBase.prototype.readMultiPolygon = function(node, objectStack) {
/** @type {Array.<module:ol/geom/Polygon>} */ /** @type {Array.<module:ol/geom/Polygon>} */
const polygons = pushParseAndPop([], this.MULTIPOLYGON_PARSERS_, node, objectStack, this); const polygons = pushParseAndPop([], this.MULTIPOLYGON_PARSERS_, node, objectStack, this);
if (polygons) { if (polygons) {
const multiPolygon = new MultiPolygon(null); return new MultiPolygon(polygons);
multiPolygon.setPolygons(polygons);
return multiPolygon;
} else {
return undefined;
} }
}; };
@@ -390,8 +380,7 @@ GMLBase.prototype.polygonMemberParser_ = function(node, objectStack) {
GMLBase.prototype.readLineString = function(node, objectStack) { GMLBase.prototype.readLineString = function(node, objectStack) {
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack); const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
if (flatCoordinates) { if (flatCoordinates) {
const lineString = new LineString(null); const lineString = new LineString(flatCoordinates, GeometryLayout.XYZ);
lineString.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates);
return lineString; return lineString;
} else { } else {
return undefined; return undefined;
@@ -425,11 +414,7 @@ GMLBase.prototype.readFlatLinearRing_ = function(node, objectStack) {
GMLBase.prototype.readLinearRing = function(node, objectStack) { GMLBase.prototype.readLinearRing = function(node, objectStack) {
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack); const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
if (flatCoordinates) { if (flatCoordinates) {
const ring = new LinearRing(null); return new LinearRing(flatCoordinates, GeometryLayout.XYZ);
ring.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates);
return ring;
} else {
return undefined;
} }
}; };
@@ -444,7 +429,6 @@ GMLBase.prototype.readPolygon = function(node, objectStack) {
const flatLinearRings = pushParseAndPop([null], const flatLinearRings = pushParseAndPop([null],
this.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this); this.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this);
if (flatLinearRings && flatLinearRings[0]) { if (flatLinearRings && flatLinearRings[0]) {
const polygon = new Polygon(null);
const flatCoordinates = flatLinearRings[0]; const flatCoordinates = flatLinearRings[0];
const ends = [flatCoordinates.length]; const ends = [flatCoordinates.length];
let i, ii; let i, ii;
@@ -452,8 +436,7 @@ GMLBase.prototype.readPolygon = function(node, objectStack) {
extend(flatCoordinates, flatLinearRings[i]); extend(flatCoordinates, flatLinearRings[i]);
ends.push(flatCoordinates.length); ends.push(flatCoordinates.length);
} }
polygon.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates, ends); return new Polygon(flatCoordinates, GeometryLayout.XYZ, ends);
return polygon;
} else { } else {
return undefined; return undefined;
} }
+2 -4
View File
@@ -553,8 +553,7 @@ function readRte(node, objectStack) {
const layoutOptions = /** @type {module:ol/format/GPX~LayoutOptions} */ (values['layoutOptions']); const layoutOptions = /** @type {module:ol/format/GPX~LayoutOptions} */ (values['layoutOptions']);
delete values['layoutOptions']; delete values['layoutOptions'];
const layout = applyLayoutOptions(layoutOptions, flatCoordinates); const layout = applyLayoutOptions(layoutOptions, flatCoordinates);
const geometry = new LineString(null); const geometry = new LineString(flatCoordinates, layout);
geometry.setFlatCoordinates(layout, flatCoordinates);
transformWithOptions(geometry, false, options); transformWithOptions(geometry, false, options);
const feature = new Feature(geometry); const feature = new Feature(geometry);
feature.setProperties(values); feature.setProperties(values);
@@ -585,8 +584,7 @@ function readTrk(node, objectStack) {
const layoutOptions = /** @type {module:ol/format/GPX~LayoutOptions} */ (values['layoutOptions']); const layoutOptions = /** @type {module:ol/format/GPX~LayoutOptions} */ (values['layoutOptions']);
delete values['layoutOptions']; delete values['layoutOptions'];
const layout = applyLayoutOptions(layoutOptions, flatCoordinates, ends); const layout = applyLayoutOptions(layoutOptions, flatCoordinates, ends);
const geometry = new MultiLineString(null); const geometry = new MultiLineString(flatCoordinates, layout, ends);
geometry.setFlatCoordinates(layout, flatCoordinates, ends);
transformWithOptions(geometry, false, options); transformWithOptions(geometry, false, options);
const feature = new Feature(geometry); const feature = new Feature(geometry);
feature.setProperties(values); feature.setProperties(values);
+1 -2
View File
@@ -168,9 +168,8 @@ IGC.prototype.readFeatureFromText = function(text, opt_options) {
if (flatCoordinates.length === 0) { if (flatCoordinates.length === 0) {
return null; return null;
} }
const lineString = new LineString(null);
const layout = altitudeMode == IGCZ.NONE ? GeometryLayout.XYM : GeometryLayout.XYZM; const layout = altitudeMode == IGCZ.NONE ? GeometryLayout.XYM : GeometryLayout.XYZM;
lineString.setFlatCoordinates(layout, flatCoordinates); const lineString = new LineString(flatCoordinates, layout);
const feature = new Feature(transformWithOptions(lineString, false, opt_options)); const feature = new Feature(transformWithOptions(lineString, false, opt_options));
feature.setProperties(properties); feature.setProperties(properties);
return feature; return feature;
+9 -21
View File
@@ -904,9 +904,7 @@ function readGxMultiTrack(node, objectStack) {
if (!lineStrings) { if (!lineStrings) {
return undefined; return undefined;
} }
const multiLineString = new MultiLineString(null); return new MultiLineString(lineStrings);
multiLineString.setLineStrings(lineStrings);
return multiLineString;
} }
@@ -942,9 +940,7 @@ function readGxTrack(node, objectStack) {
for (let i = 0, ii = Math.min(flatCoordinates.length, whens.length); i < ii; ++i) { for (let i = 0, ii = Math.min(flatCoordinates.length, whens.length); i < ii; ++i) {
flatCoordinates[4 * i + 3] = whens[i]; flatCoordinates[4 * i + 3] = whens[i];
} }
const lineString = new LineString(null); return new LineString(flatCoordinates, GeometryLayout.XYZM);
lineString.setFlatCoordinates(GeometryLayout.XYZM, flatCoordinates);
return lineString;
} }
@@ -1025,8 +1021,7 @@ function readLineString(node, objectStack) {
const flatCoordinates = const flatCoordinates =
readFlatCoordinatesFromNode(node, objectStack); readFlatCoordinatesFromNode(node, objectStack);
if (flatCoordinates) { if (flatCoordinates) {
const lineString = new LineString(null); const lineString = new LineString(flatCoordinates, GeometryLayout.XYZ);
lineString.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates);
lineString.setProperties(properties); lineString.setProperties(properties);
return lineString; return lineString;
} else { } else {
@@ -1047,9 +1042,7 @@ function readLinearRing(node, objectStack) {
const flatCoordinates = const flatCoordinates =
readFlatCoordinatesFromNode(node, objectStack); readFlatCoordinatesFromNode(node, objectStack);
if (flatCoordinates) { if (flatCoordinates) {
const polygon = new Polygon(null); const polygon = new Polygon(flatCoordinates, GeometryLayout.XYZ, [flatCoordinates.length]);
polygon.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates,
[flatCoordinates.length]);
polygon.setProperties(properties); polygon.setProperties(properties);
return polygon; return polygon;
} else { } else {
@@ -1109,16 +1102,13 @@ function readMultiGeometry(node, objectStack) {
geometry = geometries[i]; geometry = geometries[i];
extend(flatCoordinates, geometry.getFlatCoordinates()); extend(flatCoordinates, geometry.getFlatCoordinates());
} }
multiGeometry = new MultiPoint(null); multiGeometry = new MultiPoint(flatCoordinates, layout);
multiGeometry.setFlatCoordinates(layout, flatCoordinates);
setCommonGeometryProperties(multiGeometry, geometries); setCommonGeometryProperties(multiGeometry, geometries);
} else if (type == GeometryType.LINE_STRING) { } else if (type == GeometryType.LINE_STRING) {
multiGeometry = new MultiLineString(null); multiGeometry = new MultiLineString(geometries);
multiGeometry.setLineStrings(geometries);
setCommonGeometryProperties(multiGeometry, geometries); setCommonGeometryProperties(multiGeometry, geometries);
} else if (type == GeometryType.POLYGON) { } else if (type == GeometryType.POLYGON) {
multiGeometry = new MultiPolygon(null); multiGeometry = new MultiPolygon(geometries);
multiGeometry.setPolygons(geometries);
setCommonGeometryProperties(multiGeometry, geometries); setCommonGeometryProperties(multiGeometry, geometries);
} else if (type == GeometryType.GEOMETRY_COLLECTION) { } else if (type == GeometryType.GEOMETRY_COLLECTION) {
multiGeometry = new GeometryCollection(geometries); multiGeometry = new GeometryCollection(geometries);
@@ -1146,8 +1136,7 @@ function readPoint(node, objectStack) {
const flatCoordinates = const flatCoordinates =
readFlatCoordinatesFromNode(node, objectStack); readFlatCoordinatesFromNode(node, objectStack);
if (flatCoordinates) { if (flatCoordinates) {
const point = new Point(null); const point = new Point(flatCoordinates, GeometryLayout.XYZ);
point.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates);
point.setProperties(properties); point.setProperties(properties);
return point; return point;
} else { } else {
@@ -1179,14 +1168,13 @@ function readPolygon(node, objectStack) {
const flatLinearRings = pushParseAndPop([null], const flatLinearRings = pushParseAndPop([null],
FLAT_LINEAR_RINGS_PARSERS, node, objectStack); FLAT_LINEAR_RINGS_PARSERS, node, objectStack);
if (flatLinearRings && flatLinearRings[0]) { if (flatLinearRings && flatLinearRings[0]) {
const polygon = new Polygon(null);
const flatCoordinates = flatLinearRings[0]; const flatCoordinates = flatLinearRings[0];
const ends = [flatCoordinates.length]; const ends = [flatCoordinates.length];
for (let i = 1, ii = flatLinearRings.length; i < ii; ++i) { for (let i = 1, ii = flatLinearRings.length; i < ii; ++i) {
extend(flatCoordinates, flatLinearRings[i]); extend(flatCoordinates, flatLinearRings[i]);
ends.push(flatCoordinates.length); ends.push(flatCoordinates.length);
} }
polygon.setFlatCoordinates(GeometryLayout.XYZ, flatCoordinates, ends); const polygon = new Polygon(flatCoordinates, GeometryLayout.XYZ, ends);
polygon.setProperties(properties); polygon.setProperties(properties);
return polygon; return polygon;
} else { } else {
+8 -10
View File
@@ -311,7 +311,7 @@ MVT.prototype.createFeature_ = function(pbf, rawFeature, opt_options) {
values[this.layerName_] = rawFeature.layer.name; values[this.layerName_] = rawFeature.layer.name;
const flatCoordinates = []; const flatCoordinates = [];
let ends = []; const ends = [];
this.readRawGeometry_(pbf, rawFeature, flatCoordinates, ends); this.readRawGeometry_(pbf, rawFeature, flatCoordinates, ends);
const geometryType = getGeometryType(type, ends.length); const geometryType = getGeometryType(type, ends.length);
@@ -333,20 +333,18 @@ MVT.prototype.createFeature_ = function(pbf, rawFeature, opt_options) {
offset = end; offset = end;
} }
if (endss.length > 1) { if (endss.length > 1) {
ends = endss; geom = new MultiPolygon(flatCoordinates, GeometryLayout.XY, endss);
geom = new MultiPolygon(null);
} else { } else {
geom = new Polygon(null); geom = new Polygon(flatCoordinates, GeometryLayout.XY, ends);
} }
} else { } else {
geom = geometryType === GeometryType.POINT ? new Point(null) : geom = geometryType === GeometryType.POINT ? new Point(flatCoordinates, GeometryLayout.XY) :
geometryType === GeometryType.LINE_STRING ? new LineString(null) : geometryType === GeometryType.LINE_STRING ? new LineString(flatCoordinates, GeometryLayout.XY) :
geometryType === GeometryType.POLYGON ? new Polygon(null) : geometryType === GeometryType.POLYGON ? new Polygon(flatCoordinates, GeometryLayout.XY, ends) :
geometryType === GeometryType.MULTI_POINT ? new MultiPoint (null) : geometryType === GeometryType.MULTI_POINT ? new MultiPoint(flatCoordinates, GeometryLayout.XY) :
geometryType === GeometryType.MULTI_LINE_STRING ? new MultiLineString(null) : geometryType === GeometryType.MULTI_LINE_STRING ? new MultiLineString(flatCoordinates, GeometryLayout.XY, ends) :
null; null;
} }
geom.setFlatCoordinates(GeometryLayout.XY, flatCoordinates, ends);
feature = new this.featureClass_(); feature = new this.featureClass_();
if (this.geometryName_) { if (this.geometryName_) {
feature.setGeometryName(this.geometryName_); feature.setGeometryName(this.geometryName_);
+2 -5
View File
@@ -175,12 +175,9 @@ OSMXML.prototype.readFeaturesFromNode = function(node, opt_options) {
let geometry; let geometry;
if (values.ndrefs[0] == values.ndrefs[values.ndrefs.length - 1]) { if (values.ndrefs[0] == values.ndrefs[values.ndrefs.length - 1]) {
// closed way // closed way
geometry = new Polygon(null); geometry = new Polygon(flatCoordinates, GeometryLayout.XY, [flatCoordinates.length]);
geometry.setFlatCoordinates(GeometryLayout.XY, flatCoordinates,
[flatCoordinates.length]);
} else { } else {
geometry = new LineString(null); geometry = new LineString(flatCoordinates, GeometryLayout.XY);
geometry.setFlatCoordinates(GeometryLayout.XY, flatCoordinates);
} }
transformWithOptions(geometry, false, options); transformWithOptions(geometry, false, options);
const feature = new Feature(geometry); const feature = new Feature(geometry);
+8 -1
View File
@@ -858,7 +858,14 @@ Parser.prototype.parseGeometry_ = function() {
if (!parser || !ctor) { if (!parser || !ctor) {
throw new Error('Invalid geometry type: ' + geomType); throw new Error('Invalid geometry type: ' + geomType);
} }
const coordinates = parser.call(this); let coordinates = parser.call(this);
if (!coordinates) {
if (ctor === GeometryConstructor[GeometryType.POINT]) {
coordinates = [NaN, NaN];
} else {
coordinates = [];
}
}
return new ctor(coordinates, this.layout_); return new ctor(coordinates, this.layout_);
} }
} }
+26 -36
View File
@@ -3,7 +3,6 @@
*/ */
import {inherits} from '../util.js'; import {inherits} from '../util.js';
import {createOrUpdate, forEachCorner, intersects} from '../extent.js'; import {createOrUpdate, forEachCorner, intersects} from '../extent.js';
import GeometryLayout from '../geom/GeometryLayout.js';
import GeometryType from '../geom/GeometryType.js'; import GeometryType from '../geom/GeometryType.js';
import SimpleGeometry from '../geom/SimpleGeometry.js'; import SimpleGeometry from '../geom/SimpleGeometry.js';
import {deflateCoordinate} from '../geom/flat/deflate.js'; import {deflateCoordinate} from '../geom/flat/deflate.js';
@@ -13,16 +12,22 @@ import {deflateCoordinate} from '../geom/flat/deflate.js';
* Circle geometry. * Circle geometry.
* *
* @constructor * @constructor
* @extends {module:ol/geom/SimpleGeometry} * @extends {!module:ol/geom/SimpleGeometry}
* @param {module:ol/coordinate~Coordinate} center Center. * @param {!module:ol/coordinate~Coordinate} center Center. (For internal use,
* flat coordinates in combination with `opt_layout` and no `opt_radius` are
* also accepted.)
* @param {number=} opt_radius Radius. * @param {number=} opt_radius Radius.
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
* @api * @api
*/ */
const Circle = function(center, opt_radius, opt_layout) { const Circle = function(center, opt_radius, opt_layout) {
SimpleGeometry.call(this); SimpleGeometry.call(this);
const radius = opt_radius ? opt_radius : 0; if (opt_layout !== undefined && opt_radius === undefined) {
this.setCenterAndRadius(center, radius, opt_layout); this.setFlatCoordinates(opt_layout, center);
} else {
const radius = opt_radius ? opt_radius : 0;
this.setCenterAndRadius(center, radius, opt_layout);
}
}; };
inherits(Circle, SimpleGeometry); inherits(Circle, SimpleGeometry);
@@ -35,9 +40,7 @@ inherits(Circle, SimpleGeometry);
* @api * @api
*/ */
Circle.prototype.clone = function() { Circle.prototype.clone = function() {
const circle = new Circle(null); return new Circle(this.flatCoordinates.slice(), undefined, this.layout);
circle.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
return circle;
}; };
@@ -171,36 +174,33 @@ Circle.prototype.setCenter = function(center) {
flatCoordinates[stride + i] = center[i]; flatCoordinates[stride + i] = center[i];
} }
this.setFlatCoordinates(this.layout, flatCoordinates); this.setFlatCoordinates(this.layout, flatCoordinates);
this.changed();
}; };
/** /**
* Set the center (as {@link module:ol/coordinate~Coordinate coordinate}) and the radius (as * Set the center (as {@link module:ol/coordinate~Coordinate coordinate}) and the radius (as
* number) of the circle. * number) of the circle.
* @param {module:ol/coordinate~Coordinate} center Center. * @param {!module:ol/coordinate~Coordinate} center Center.
* @param {number} radius Radius. * @param {number} radius Radius.
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
* @api * @api
*/ */
Circle.prototype.setCenterAndRadius = function(center, radius, opt_layout) { Circle.prototype.setCenterAndRadius = function(center, radius, opt_layout) {
if (!center) { this.setLayout(opt_layout, center, 0);
this.setFlatCoordinates(GeometryLayout.XY, null); if (!this.flatCoordinates) {
} else { this.flatCoordinates = [];
this.setLayout(opt_layout, center, 0);
if (!this.flatCoordinates) {
this.flatCoordinates = [];
}
/** @type {Array.<number>} */
const flatCoordinates = this.flatCoordinates;
let offset = deflateCoordinate(
flatCoordinates, 0, center, this.stride);
flatCoordinates[offset++] = flatCoordinates[0] + radius;
for (let i = 1, ii = this.stride; i < ii; ++i) {
flatCoordinates[offset++] = flatCoordinates[i];
}
flatCoordinates.length = offset;
this.changed();
} }
/** @type {Array.<number>} */
const flatCoordinates = this.flatCoordinates;
let offset = deflateCoordinate(
flatCoordinates, 0, center, this.stride);
flatCoordinates[offset++] = flatCoordinates[0] + radius;
for (let i = 1, ii = this.stride; i < ii; ++i) {
flatCoordinates[offset++] = flatCoordinates[i];
}
flatCoordinates.length = offset;
this.changed();
}; };
@@ -216,16 +216,6 @@ Circle.prototype.getCoordinates = function() {};
Circle.prototype.setCoordinates = function(coordinates, opt_layout) {}; Circle.prototype.setCoordinates = function(coordinates, opt_layout) {};
/**
* @param {module:ol/geom/GeometryLayout} layout Layout.
* @param {Array.<number>} flatCoordinates Flat coordinates.
*/
Circle.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
this.setFlatCoordinatesInternal(layout, flatCoordinates);
this.changed();
};
/** /**
* Set the radius of the circle. The radius is in the units of the projection. * Set the radius of the circle. The radius is in the units of the projection.
* @param {number} radius Radius. * @param {number} radius Radius.
+17 -29
View File
@@ -22,7 +22,9 @@ import {douglasPeucker} from '../geom/flat/simplify.js';
* *
* @constructor * @constructor
* @extends {module:ol/geom/SimpleGeometry} * @extends {module:ol/geom/SimpleGeometry}
* @param {Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates. * @param {Array.<module:ol/coordinate~Coordinate>|Array.<number>} coordinates
* Coordinates. (For internal use, flat coordinates in combination with
* `opt_layout` are also accepted).
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
* @api * @api
*/ */
@@ -54,7 +56,11 @@ const LineString = function(coordinates, opt_layout) {
*/ */
this.maxDeltaRevision_ = -1; this.maxDeltaRevision_ = -1;
this.setCoordinates(coordinates, opt_layout); if (opt_layout !== undefined && !Array.isArray(coordinates[0])) {
this.setFlatCoordinates(opt_layout, coordinates);
} else {
this.setCoordinates(coordinates, opt_layout);
}
}; };
@@ -83,9 +89,7 @@ LineString.prototype.appendCoordinate = function(coordinate) {
* @api * @api
*/ */
LineString.prototype.clone = function() { LineString.prototype.clone = function() {
const lineString = new LineString(null); return new LineString(this.flatCoordinates.slice(), this.layout);
lineString.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
return lineString;
}; };
@@ -208,10 +212,7 @@ LineString.prototype.getSimplifiedGeometryInternal = function(squaredTolerance)
simplifiedFlatCoordinates.length = douglasPeucker( simplifiedFlatCoordinates.length = douglasPeucker(
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
squaredTolerance, simplifiedFlatCoordinates, 0); squaredTolerance, simplifiedFlatCoordinates, 0);
const simplifiedLineString = new LineString(null); return new LineString(simplifiedFlatCoordinates, GeometryLayout.XY);
simplifiedLineString.setFlatCoordinates(
GeometryLayout.XY, simplifiedFlatCoordinates);
return simplifiedLineString;
}; };
@@ -237,32 +238,19 @@ LineString.prototype.intersectsExtent = function(extent) {
/** /**
* Set the coordinates of the linestring. * Set the coordinates of the linestring.
* @param {Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates. * @param {!Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates.
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
* @override * @override
* @api * @api
*/ */
LineString.prototype.setCoordinates = function(coordinates, opt_layout) { LineString.prototype.setCoordinates = function(coordinates, opt_layout) {
if (!coordinates) { this.setLayout(opt_layout, coordinates, 1);
this.setFlatCoordinates(GeometryLayout.XY, null); if (!this.flatCoordinates) {
} else { this.flatCoordinates = [];
this.setLayout(opt_layout, coordinates, 1);
if (!this.flatCoordinates) {
this.flatCoordinates = [];
}
this.flatCoordinates.length = deflateCoordinates(
this.flatCoordinates, 0, coordinates, this.stride);
this.changed();
} }
}; this.flatCoordinates.length = deflateCoordinates(
this.flatCoordinates, 0, coordinates, this.stride);
/**
* @param {module:ol/geom/GeometryLayout} layout Layout.
* @param {Array.<number>} flatCoordinates Flat coordinates.
*/
LineString.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
this.setFlatCoordinatesInternal(layout, flatCoordinates);
this.changed(); this.changed();
}; };
export default LineString; export default LineString;
+16 -29
View File
@@ -19,7 +19,9 @@ import {douglasPeucker} from '../geom/flat/simplify.js';
* *
* @constructor * @constructor
* @extends {module:ol/geom/SimpleGeometry} * @extends {module:ol/geom/SimpleGeometry}
* @param {Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates. * @param {Array.<module:ol/coordinate~Coordinate>|Array.<number>} coordinates
* Coordinates. (For internal use, flat coordinates in combination with
* `opt_layout` are also accepted.)
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
* @api * @api
*/ */
@@ -39,7 +41,11 @@ const LinearRing = function(coordinates, opt_layout) {
*/ */
this.maxDeltaRevision_ = -1; this.maxDeltaRevision_ = -1;
this.setCoordinates(coordinates, opt_layout); if (opt_layout !== undefined && !Array.isArray(coordinates[0])) {
this.setFlatCoordinates(opt_layout, coordinates);
} else {
this.setCoordinates(coordinates, opt_layout);
}
}; };
@@ -53,9 +59,7 @@ inherits(LinearRing, SimpleGeometry);
* @api * @api
*/ */
LinearRing.prototype.clone = function() { LinearRing.prototype.clone = function() {
const linearRing = new LinearRing(null); return new LinearRing(this.flatCoordinates.slice(), this.layout);
linearRing.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
return linearRing;
}; };
@@ -107,10 +111,7 @@ LinearRing.prototype.getSimplifiedGeometryInternal = function(squaredTolerance)
simplifiedFlatCoordinates.length = douglasPeucker( simplifiedFlatCoordinates.length = douglasPeucker(
this.flatCoordinates, 0, this.flatCoordinates.length, this.stride, this.flatCoordinates, 0, this.flatCoordinates.length, this.stride,
squaredTolerance, simplifiedFlatCoordinates, 0); squaredTolerance, simplifiedFlatCoordinates, 0);
const simplifiedLinearRing = new LinearRing(null); return new LinearRing(simplifiedFlatCoordinates, GeometryLayout.XY);
simplifiedLinearRing.setFlatCoordinates(
GeometryLayout.XY, simplifiedFlatCoordinates);
return simplifiedLinearRing;
}; };
@@ -131,32 +132,18 @@ LinearRing.prototype.intersectsExtent = function(extent) {};
/** /**
* Set the coordinates of the linear ring. * Set the coordinates of the linear ring.
* @param {Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates. * @param {!Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates.
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
* @override * @override
* @api * @api
*/ */
LinearRing.prototype.setCoordinates = function(coordinates, opt_layout) { LinearRing.prototype.setCoordinates = function(coordinates, opt_layout) {
if (!coordinates) { this.setLayout(opt_layout, coordinates, 1);
this.setFlatCoordinates(GeometryLayout.XY, null); if (!this.flatCoordinates) {
} else { this.flatCoordinates = [];
this.setLayout(opt_layout, coordinates, 1);
if (!this.flatCoordinates) {
this.flatCoordinates = [];
}
this.flatCoordinates.length = deflateCoordinates(
this.flatCoordinates, 0, coordinates, this.stride);
this.changed();
} }
}; this.flatCoordinates.length = deflateCoordinates(
this.flatCoordinates, 0, coordinates, this.stride);
/**
* @param {module:ol/geom/GeometryLayout} layout Layout.
* @param {Array.<number>} flatCoordinates Flat coordinates.
*/
LinearRing.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
this.setFlatCoordinatesInternal(layout, flatCoordinates);
this.changed(); this.changed();
}; };
export default LinearRing; export default LinearRing;
+37 -59
View File
@@ -21,11 +21,14 @@ import {douglasPeuckerArray} from '../geom/flat/simplify.js';
* *
* @constructor * @constructor
* @extends {module:ol/geom/SimpleGeometry} * @extends {module:ol/geom/SimpleGeometry}
* @param {Array.<Array.<module:ol/coordinate~Coordinate>>} coordinates Coordinates. * @param {Array.<Array.<module:ol/coordinate~Coordinate>|module:ol/geom~MultiLineString>|Array.<number>} coordinates
* Coordinates or LineString geometries. (For internal use, flat coordinates in
* combination with `opt_layout` and `opt_ends` are also accepted.)
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
* @param {Array.<number>} opt_ends Flat coordinate ends for internal use.
* @api * @api
*/ */
const MultiLineString = function(coordinates, opt_layout) { const MultiLineString = function(coordinates, opt_layout, opt_ends) {
SimpleGeometry.call(this); SimpleGeometry.call(this);
@@ -47,7 +50,26 @@ const MultiLineString = function(coordinates, opt_layout) {
*/ */
this.maxDeltaRevision_ = -1; this.maxDeltaRevision_ = -1;
this.setCoordinates(coordinates, opt_layout); if (Array.isArray(coordinates[0])) {
this.setCoordinates(coordinates, opt_layout);
} else if (opt_layout !== undefined && opt_ends) {
this.setFlatCoordinates(opt_layout, coordinates);
this.ends_ = opt_ends;
} else {
let layout = this.getLayout();
const flatCoordinates = [];
const ends = [];
for (let i = 0, ii = coordinates.length; i < ii; ++i) {
const lineString = coordinates[i];
if (i === 0) {
layout = lineString.getLayout();
}
extend(flatCoordinates, lineString.getFlatCoordinates());
ends.push(flatCoordinates.length);
}
this.setFlatCoordinates(layout, flatCoordinates);
this.ends_ = ends;
}
}; };
@@ -77,10 +99,7 @@ MultiLineString.prototype.appendLineString = function(lineString) {
* @api * @api
*/ */
MultiLineString.prototype.clone = function() { MultiLineString.prototype.clone = function() {
const multiLineString = new MultiLineString(null); return new MultiLineString(this.flatCoordinates.slice(), this.layout, this.ends_.slice());
multiLineString.setFlatCoordinates(
this.layout, this.flatCoordinates.slice(), this.ends_.slice());
return multiLineString;
}; };
@@ -167,10 +186,8 @@ MultiLineString.prototype.getLineString = function(index) {
if (index < 0 || this.ends_.length <= index) { if (index < 0 || this.ends_.length <= index) {
return null; return null;
} }
const lineString = new LineString(null); return new LineString(this.flatCoordinates.slice(
lineString.setFlatCoordinates(this.layout, this.flatCoordinates.slice( index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]), this.layout);
index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]));
return lineString;
}; };
@@ -188,8 +205,7 @@ MultiLineString.prototype.getLineStrings = function() {
let offset = 0; let offset = 0;
for (let i = 0, ii = ends.length; i < ii; ++i) { for (let i = 0, ii = ends.length; i < ii; ++i) {
const end = ends[i]; const end = ends[i];
const lineString = new LineString(null); const lineString = new LineString(flatCoordinates.slice(offset, end), layout);
lineString.setFlatCoordinates(layout, flatCoordinates.slice(offset, end));
lineStrings.push(lineString); lineStrings.push(lineString);
offset = end; offset = end;
} }
@@ -226,10 +242,7 @@ MultiLineString.prototype.getSimplifiedGeometryInternal = function(squaredTolera
simplifiedFlatCoordinates.length = douglasPeuckerArray( simplifiedFlatCoordinates.length = douglasPeuckerArray(
this.flatCoordinates, 0, this.ends_, this.stride, squaredTolerance, this.flatCoordinates, 0, this.ends_, this.stride, squaredTolerance,
simplifiedFlatCoordinates, 0, simplifiedEnds); simplifiedFlatCoordinates, 0, simplifiedEnds);
const simplifiedMultiLineString = new MultiLineString(null); return new MultiLineString(simplifiedFlatCoordinates, GeometryLayout.XY, simplifiedEnds);
simplifiedMultiLineString.setFlatCoordinates(
GeometryLayout.XY, simplifiedFlatCoordinates, simplifiedEnds);
return simplifiedMultiLineString;
}; };
@@ -254,54 +267,19 @@ MultiLineString.prototype.intersectsExtent = function(extent) {
/** /**
* Set the coordinates of the multilinestring. * Set the coordinates of the multilinestring.
* @param {Array.<Array.<module:ol/coordinate~Coordinate>>} coordinates Coordinates. * @param {!Array.<Array.<module:ol/coordinate~Coordinate>>} coordinates Coordinates.
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
* @override * @override
* @api * @api
*/ */
MultiLineString.prototype.setCoordinates = function(coordinates, opt_layout) { MultiLineString.prototype.setCoordinates = function(coordinates, opt_layout) {
if (!coordinates) { this.setLayout(opt_layout, coordinates, 2);
this.setFlatCoordinates(GeometryLayout.XY, null, this.ends_); if (!this.flatCoordinates) {
} else { this.flatCoordinates = [];
this.setLayout(opt_layout, coordinates, 2);
if (!this.flatCoordinates) {
this.flatCoordinates = [];
}
const ends = deflateCoordinatesArray(
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
this.changed();
} }
}; const ends = deflateCoordinatesArray(
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
/**
* @param {module:ol/geom/GeometryLayout} layout Layout.
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {Array.<number>} ends Ends.
*/
MultiLineString.prototype.setFlatCoordinates = function(layout, flatCoordinates, ends) {
this.setFlatCoordinatesInternal(layout, flatCoordinates);
this.ends_ = ends;
this.changed(); this.changed();
}; };
/**
* @param {Array.<module:ol/geom/LineString>} lineStrings LineStrings.
*/
MultiLineString.prototype.setLineStrings = function(lineStrings) {
let layout = this.getLayout();
const flatCoordinates = [];
const ends = [];
for (let i = 0, ii = lineStrings.length; i < ii; ++i) {
const lineString = lineStrings[i];
if (i === 0) {
layout = lineString.getLayout();
}
extend(flatCoordinates, lineString.getFlatCoordinates());
ends.push(flatCoordinates.length);
}
this.setFlatCoordinates(layout, flatCoordinates, ends);
};
export default MultiLineString; export default MultiLineString;
+18 -31
View File
@@ -4,7 +4,6 @@
import {inherits} from '../util.js'; import {inherits} from '../util.js';
import {extend} from '../array.js'; import {extend} from '../array.js';
import {closestSquaredDistanceXY, containsXY} from '../extent.js'; import {closestSquaredDistanceXY, containsXY} from '../extent.js';
import GeometryLayout from '../geom/GeometryLayout.js';
import GeometryType from '../geom/GeometryType.js'; import GeometryType from '../geom/GeometryType.js';
import Point from '../geom/Point.js'; import Point from '../geom/Point.js';
import SimpleGeometry from '../geom/SimpleGeometry.js'; import SimpleGeometry from '../geom/SimpleGeometry.js';
@@ -18,13 +17,19 @@ import {squaredDistance as squaredDx} from '../math.js';
* *
* @constructor * @constructor
* @extends {module:ol/geom/SimpleGeometry} * @extends {module:ol/geom/SimpleGeometry}
* @param {Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates. * @param {Array.<module:ol/coordinate~Coordinate>|Array.<number>} coordinates
* Coordinates. (For internal use, flat coordinates in combination with
* `opt_layout` are also accepted)
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
* @api * @api
*/ */
const MultiPoint = function(coordinates, opt_layout) { const MultiPoint = function(coordinates, opt_layout) {
SimpleGeometry.call(this); SimpleGeometry.call(this);
this.setCoordinates(coordinates, opt_layout); if (opt_layout && !Array.isArray(coordinates[0])) {
this.setFlatCoordinates(opt_layout, coordinates);
} else {
this.setCoordinates(coordinates, opt_layout);
}
}; };
inherits(MultiPoint, SimpleGeometry); inherits(MultiPoint, SimpleGeometry);
@@ -52,8 +57,7 @@ MultiPoint.prototype.appendPoint = function(point) {
* @api * @api
*/ */
MultiPoint.prototype.clone = function() { MultiPoint.prototype.clone = function() {
const multiPoint = new MultiPoint(null); const multiPoint = new MultiPoint(this.flatCoordinates.slice(), this.layout);
multiPoint.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
return multiPoint; return multiPoint;
}; };
@@ -105,10 +109,8 @@ MultiPoint.prototype.getPoint = function(index) {
if (index < 0 || n <= index) { if (index < 0 || n <= index) {
return null; return null;
} }
const point = new Point(null); return new Point(this.flatCoordinates.slice(
point.setFlatCoordinates(this.layout, this.flatCoordinates.slice( index * this.stride, (index + 1) * this.stride), this.layout);
index * this.stride, (index + 1) * this.stride));
return point;
}; };
@@ -124,8 +126,7 @@ MultiPoint.prototype.getPoints = function() {
/** @type {Array.<module:ol/geom/Point>} */ /** @type {Array.<module:ol/geom/Point>} */
const points = []; const points = [];
for (let i = 0, ii = flatCoordinates.length; i < ii; i += stride) { for (let i = 0, ii = flatCoordinates.length; i < ii; i += stride) {
const point = new Point(null); const point = new Point(flatCoordinates.slice(i, i + stride), layout);
point.setFlatCoordinates(layout, flatCoordinates.slice(i, i + stride));
points.push(point); points.push(point);
} }
return points; return points;
@@ -161,32 +162,18 @@ MultiPoint.prototype.intersectsExtent = function(extent) {
/** /**
* Set the coordinates of the multipoint. * Set the coordinates of the multipoint.
* @param {Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates. * @param {!Array.<module:ol/coordinate~Coordinate>} coordinates Coordinates.
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
* @override * @override
* @api * @api
*/ */
MultiPoint.prototype.setCoordinates = function(coordinates, opt_layout) { MultiPoint.prototype.setCoordinates = function(coordinates, opt_layout) {
if (!coordinates) { this.setLayout(opt_layout, coordinates, 1);
this.setFlatCoordinates(GeometryLayout.XY, null); if (!this.flatCoordinates) {
} else { this.flatCoordinates = [];
this.setLayout(opt_layout, coordinates, 1);
if (!this.flatCoordinates) {
this.flatCoordinates = [];
}
this.flatCoordinates.length = deflateCoordinates(
this.flatCoordinates, 0, coordinates, this.stride);
this.changed();
} }
}; this.flatCoordinates.length = deflateCoordinates(
this.flatCoordinates, 0, coordinates, this.stride);
/**
* @param {module:ol/geom/GeometryLayout} layout Layout.
* @param {Array.<number>} flatCoordinates Flat coordinates.
*/
MultiPoint.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
this.setFlatCoordinatesInternal(layout, flatCoordinates);
this.changed(); this.changed();
}; };
export default MultiPoint; export default MultiPoint;
+52 -75
View File
@@ -26,11 +26,15 @@ import {quantizeMultiArray} from '../geom/flat/simplify.js';
* *
* @constructor * @constructor
* @extends {module:ol/geom/SimpleGeometry} * @extends {module:ol/geom/SimpleGeometry}
* @param {Array.<Array.<Array.<module:ol/coordinate~Coordinate>>>} coordinates Coordinates. * @param {Array.<Array.<Array.<module:ol/coordinate~Coordinate>>>|Array.<number>} coordinates
* Coordinates. (For internal use, flat coordinats in combination with
* `opt_layout` and `opt_endss` are also accepted).
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
* @param {Array.<number>} opt_endss Array of ends for internal use with flat
* coordinates.
* @api * @api
*/ */
const MultiPolygon = function(coordinates, opt_layout) { const MultiPolygon = function(coordinates, opt_layout, opt_endss) {
SimpleGeometry.call(this); SimpleGeometry.call(this);
@@ -76,7 +80,33 @@ const MultiPolygon = function(coordinates, opt_layout) {
*/ */
this.orientedFlatCoordinates_ = null; this.orientedFlatCoordinates_ = null;
this.setCoordinates(coordinates, opt_layout); if (!opt_endss && !Array.isArray(coordinates[0])) {
let layout = this.getLayout();
const flatCoordinates = [];
const endss = [];
for (let i = 0, ii = coordinates.length; i < ii; ++i) {
const polygon = coordinates[i];
if (i === 0) {
layout = polygon.getLayout();
}
const offset = flatCoordinates.length;
const ends = polygon.getEnds();
for (let j = 0, jj = ends.length; j < jj; ++j) {
ends[j] += offset;
}
extend(flatCoordinates, polygon.getFlatCoordinates());
endss.push(ends);
}
opt_layout = layout;
coordinates = flatCoordinates;
opt_endss = endss;
}
if (opt_layout !== undefined && opt_endss) {
this.setFlatCoordinates(opt_layout, coordinates);
this.endss_ = opt_endss;
} else {
this.setCoordinates(coordinates, opt_layout);
}
}; };
@@ -115,17 +145,14 @@ MultiPolygon.prototype.appendPolygon = function(polygon) {
* @api * @api
*/ */
MultiPolygon.prototype.clone = function() { MultiPolygon.prototype.clone = function() {
const multiPolygon = new MultiPolygon(null);
const len = this.endss_.length; const len = this.endss_.length;
const newEndss = new Array(len); const newEndss = new Array(len);
for (let i = 0; i < len; ++i) { for (let i = 0; i < len; ++i) {
newEndss[i] = this.endss_[i].slice(); newEndss[i] = this.endss_[i].slice();
} }
multiPolygon.setFlatCoordinates( return new MultiPolygon(
this.layout, this.flatCoordinates.slice(), newEndss); this.flatCoordinates.slice(), this.layout, newEndss);
return multiPolygon;
}; };
@@ -225,10 +252,7 @@ MultiPolygon.prototype.getFlatInteriorPoints = function() {
* @api * @api
*/ */
MultiPolygon.prototype.getInteriorPoints = function() { MultiPolygon.prototype.getInteriorPoints = function() {
const interiorPoints = new MultiPoint(null); return new MultiPoint(this.getFlatInteriorPoints().slice(), GeometryLayout.XYM);
interiorPoints.setFlatCoordinates(GeometryLayout.XYM,
this.getFlatInteriorPoints().slice());
return interiorPoints;
}; };
@@ -263,10 +287,7 @@ MultiPolygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance
this.flatCoordinates, 0, this.endss_, this.stride, this.flatCoordinates, 0, this.endss_, this.stride,
Math.sqrt(squaredTolerance), Math.sqrt(squaredTolerance),
simplifiedFlatCoordinates, 0, simplifiedEndss); simplifiedFlatCoordinates, 0, simplifiedEndss);
const simplifiedMultiPolygon = new MultiPolygon(null); return new MultiPolygon(simplifiedFlatCoordinates, GeometryLayout.XY, simplifiedEndss);
simplifiedMultiPolygon.setFlatCoordinates(
GeometryLayout.XY, simplifiedFlatCoordinates, simplifiedEndss);
return simplifiedMultiPolygon;
}; };
@@ -294,10 +315,7 @@ MultiPolygon.prototype.getPolygon = function(index) {
ends[i] -= offset; ends[i] -= offset;
} }
} }
const polygon = new Polygon(null); return new Polygon(this.flatCoordinates.slice(offset, end), this.layout, ends);
polygon.setFlatCoordinates(
this.layout, this.flatCoordinates.slice(offset, end), ends);
return polygon;
}; };
@@ -320,9 +338,7 @@ MultiPolygon.prototype.getPolygons = function() {
ends[j] -= offset; ends[j] -= offset;
} }
} }
const polygon = new Polygon(null); const polygon = new Polygon(flatCoordinates.slice(offset, end), layout, ends);
polygon.setFlatCoordinates(
layout, flatCoordinates.slice(offset, end), ends);
polygons.push(polygon); polygons.push(polygon);
offset = end; offset = end;
} }
@@ -351,66 +367,27 @@ MultiPolygon.prototype.intersectsExtent = function(extent) {
/** /**
* Set the coordinates of the multipolygon. * Set the coordinates of the multipolygon.
* @param {Array.<Array.<Array.<module:ol/coordinate~Coordinate>>>} coordinates Coordinates. * @param {!Array.<Array.<Array.<module:ol/coordinate~Coordinate>>>} coordinates Coordinates.
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
* @override * @override
* @api * @api
*/ */
MultiPolygon.prototype.setCoordinates = function(coordinates, opt_layout) { MultiPolygon.prototype.setCoordinates = function(coordinates, opt_layout) {
if (!coordinates) { this.setLayout(opt_layout, coordinates, 3);
this.setFlatCoordinates(GeometryLayout.XY, null, this.endss_); if (!this.flatCoordinates) {
} else { this.flatCoordinates = [];
this.setLayout(opt_layout, coordinates, 3); }
if (!this.flatCoordinates) { const endss = deflateMultiCoordinatesArray(
this.flatCoordinates = []; this.flatCoordinates, 0, coordinates, this.stride, this.endss_);
} if (endss.length === 0) {
const endss = deflateMultiCoordinatesArray( this.flatCoordinates.length = 0;
this.flatCoordinates, 0, coordinates, this.stride, this.endss_); } else {
if (endss.length === 0) { const lastEnds = endss[endss.length - 1];
this.flatCoordinates.length = 0; this.flatCoordinates.length = lastEnds.length === 0 ?
} else { 0 : lastEnds[lastEnds.length - 1];
const lastEnds = endss[endss.length - 1];
this.flatCoordinates.length = lastEnds.length === 0 ?
0 : lastEnds[lastEnds.length - 1];
}
this.changed();
} }
};
/**
* @param {module:ol/geom/GeometryLayout} layout Layout.
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {Array.<Array.<number>>} endss Endss.
*/
MultiPolygon.prototype.setFlatCoordinates = function(layout, flatCoordinates, endss) {
this.setFlatCoordinatesInternal(layout, flatCoordinates);
this.endss_ = endss;
this.changed(); this.changed();
}; };
/**
* @param {Array.<module:ol/geom/Polygon>} polygons Polygons.
*/
MultiPolygon.prototype.setPolygons = function(polygons) {
let layout = this.getLayout();
const flatCoordinates = [];
const endss = [];
for (let i = 0, ii = polygons.length; i < ii; ++i) {
const polygon = polygons[i];
if (i === 0) {
layout = polygon.getLayout();
}
const offset = flatCoordinates.length;
const ends = polygon.getEnds();
for (let j = 0, jj = ends.length; j < jj; ++j) {
ends[j] += offset;
}
extend(flatCoordinates, polygon.getFlatCoordinates());
endss.push(ends);
}
this.setFlatCoordinates(layout, flatCoordinates, endss);
};
export default MultiPolygon; export default MultiPolygon;
+7 -22
View File
@@ -3,7 +3,6 @@
*/ */
import {inherits} from '../util.js'; import {inherits} from '../util.js';
import {createOrUpdateFromCoordinate, containsXY} from '../extent.js'; import {createOrUpdateFromCoordinate, containsXY} from '../extent.js';
import GeometryLayout from '../geom/GeometryLayout.js';
import GeometryType from '../geom/GeometryType.js'; import GeometryType from '../geom/GeometryType.js';
import SimpleGeometry from '../geom/SimpleGeometry.js'; import SimpleGeometry from '../geom/SimpleGeometry.js';
import {deflateCoordinate} from '../geom/flat/deflate.js'; import {deflateCoordinate} from '../geom/flat/deflate.js';
@@ -34,8 +33,7 @@ inherits(Point, SimpleGeometry);
* @api * @api
*/ */
Point.prototype.clone = function() { Point.prototype.clone = function() {
const point = new Point(null); const point = new Point(this.flatCoordinates.slice(), this.layout);
point.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
return point; return point;
}; };
@@ -101,26 +99,13 @@ Point.prototype.intersectsExtent = function(extent) {
* @api * @api
*/ */
Point.prototype.setCoordinates = function(coordinates, opt_layout) { Point.prototype.setCoordinates = function(coordinates, opt_layout) {
if (!coordinates) { this.setLayout(opt_layout, coordinates, 0);
this.setFlatCoordinates(GeometryLayout.XY, null); if (!this.flatCoordinates) {
} else { this.flatCoordinates = [];
this.setLayout(opt_layout, coordinates, 0);
if (!this.flatCoordinates) {
this.flatCoordinates = [];
}
this.flatCoordinates.length = deflateCoordinate(
this.flatCoordinates, 0, coordinates, this.stride);
this.changed();
} }
}; this.flatCoordinates.length = deflateCoordinate(
this.flatCoordinates, 0, coordinates, this.stride);
/**
* @param {module:ol/geom/GeometryLayout} layout Layout.
* @param {Array.<number>} flatCoordinates Flat coordinates.
*/
Point.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
this.setFlatCoordinatesInternal(layout, flatCoordinates);
this.changed(); this.changed();
}; };
export default Point; export default Point;
+32 -57
View File
@@ -27,16 +27,19 @@ import {modulo} from '../math.js';
* *
* @constructor * @constructor
* @extends {module:ol/geom/SimpleGeometry} * @extends {module:ol/geom/SimpleGeometry}
* @param {Array.<Array.<module:ol/coordinate~Coordinate>>} coordinates Array of linear * @param {!Array.<Array.<module:ol/coordinate~Coordinate>>|!Array.<number>} coordinates
* rings that define the polygon. The first linear ring of the array * Array of linear rings that define the polygon. The first linear ring of the
* defines the outer-boundary or surface of the polygon. Each subsequent * array defines the outer-boundary or surface of the polygon. Each subsequent
* linear ring defines a hole in the surface of the polygon. A linear ring * linear ring defines a hole in the surface of the polygon. A linear ring is
* is an array of vertices' coordinates where the first coordinate and the * an array of vertices' coordinates where the first coordinate and the last are
* last are equivalent. * equivalent. (For internal use, flat coordinates in combination with
* `opt_layout` and `opt_ends` are also accepted.)
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
* @param {Array.<number>=} opt_ends Ends (for internal use with flat
* coordinates).
* @api * @api
*/ */
const Polygon = function(coordinates, opt_layout) { const Polygon = function(coordinates, opt_layout, opt_ends) {
SimpleGeometry.call(this); SimpleGeometry.call(this);
@@ -82,7 +85,12 @@ const Polygon = function(coordinates, opt_layout) {
*/ */
this.orientedFlatCoordinates_ = null; this.orientedFlatCoordinates_ = null;
this.setCoordinates(coordinates, opt_layout); if (opt_layout !== undefined && opt_ends) {
this.setFlatCoordinates(opt_layout, coordinates);
this.ends_ = opt_ends;
} else {
this.setCoordinates(coordinates, opt_layout);
}
}; };
@@ -112,10 +120,7 @@ Polygon.prototype.appendLinearRing = function(linearRing) {
* @api * @api
*/ */
Polygon.prototype.clone = function() { Polygon.prototype.clone = function() {
const polygon = new Polygon(null); return new Polygon(this.flatCoordinates.slice(), this.layout, this.ends_.slice());
polygon.setFlatCoordinates(
this.layout, this.flatCoordinates.slice(), this.ends_.slice());
return polygon;
}; };
@@ -244,10 +249,8 @@ Polygon.prototype.getLinearRing = function(index) {
if (index < 0 || this.ends_.length <= index) { if (index < 0 || this.ends_.length <= index) {
return null; return null;
} }
const linearRing = new LinearRing(null); return new LinearRing(this.flatCoordinates.slice(
linearRing.setFlatCoordinates(this.layout, this.flatCoordinates.slice( index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]), this.layout);
index === 0 ? 0 : this.ends_[index - 1], this.ends_[index]));
return linearRing;
}; };
@@ -264,8 +267,7 @@ Polygon.prototype.getLinearRings = function() {
let offset = 0; let offset = 0;
for (let i = 0, ii = ends.length; i < ii; ++i) { for (let i = 0, ii = ends.length; i < ii; ++i) {
const end = ends[i]; const end = ends[i];
const linearRing = new LinearRing(null); const linearRing = new LinearRing(flatCoordinates.slice(offset, end), layout);
linearRing.setFlatCoordinates(layout, flatCoordinates.slice(offset, end));
linearRings.push(linearRing); linearRings.push(linearRing);
offset = end; offset = end;
} }
@@ -304,10 +306,7 @@ Polygon.prototype.getSimplifiedGeometryInternal = function(squaredTolerance) {
this.flatCoordinates, 0, this.ends_, this.stride, this.flatCoordinates, 0, this.ends_, this.stride,
Math.sqrt(squaredTolerance), Math.sqrt(squaredTolerance),
simplifiedFlatCoordinates, 0, simplifiedEnds); simplifiedFlatCoordinates, 0, simplifiedEnds);
const simplifiedPolygon = new Polygon(null); return new Polygon(simplifiedFlatCoordinates, GeometryLayout.XY, simplifiedEnds);
simplifiedPolygon.setFlatCoordinates(
GeometryLayout.XY, simplifiedFlatCoordinates, simplifiedEnds);
return simplifiedPolygon;
}; };
@@ -332,35 +331,19 @@ Polygon.prototype.intersectsExtent = function(extent) {
/** /**
* Set the coordinates of the polygon. * Set the coordinates of the polygon.
* @param {Array.<Array.<module:ol/coordinate~Coordinate>>} coordinates Coordinates. * @param {!Array.<Array.<module:ol/coordinate~Coordinate>>} coordinates Coordinates.
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
* @override * @override
* @api * @api
*/ */
Polygon.prototype.setCoordinates = function(coordinates, opt_layout) { Polygon.prototype.setCoordinates = function(coordinates, opt_layout) {
if (!coordinates) { this.setLayout(opt_layout, coordinates, 2);
this.setFlatCoordinates(GeometryLayout.XY, null, this.ends_); if (!this.flatCoordinates) {
} else { this.flatCoordinates = [];
this.setLayout(opt_layout, coordinates, 2);
if (!this.flatCoordinates) {
this.flatCoordinates = [];
}
const ends = deflateCoordinatesArray(
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
this.changed();
} }
}; const ends = deflateCoordinatesArray(
this.flatCoordinates, 0, coordinates, this.stride, this.ends_);
this.flatCoordinates.length = ends.length === 0 ? 0 : ends[ends.length - 1];
/**
* @param {module:ol/geom/GeometryLayout} layout Layout.
* @param {Array.<number>} flatCoordinates Flat coordinates.
* @param {Array.<number>} ends Ends.
*/
Polygon.prototype.setFlatCoordinates = function(layout, flatCoordinates, ends) {
this.setFlatCoordinatesInternal(layout, flatCoordinates);
this.ends_ = ends;
this.changed(); this.changed();
}; };
@@ -387,9 +370,7 @@ export function circular(center, radius, opt_n, opt_sphereRadius) {
extend(flatCoordinates, sphereOffset(center, radius, 2 * Math.PI * i / n, opt_sphereRadius)); extend(flatCoordinates, sphereOffset(center, radius, 2 * Math.PI * i / n, opt_sphereRadius));
} }
flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]); flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]);
const polygon = new Polygon(null); return new Polygon(flatCoordinates, GeometryLayout.XY, [flatCoordinates.length]);
polygon.setFlatCoordinates(GeometryLayout.XY, flatCoordinates, [flatCoordinates.length]);
return polygon;
} }
@@ -406,10 +387,7 @@ export function fromExtent(extent) {
const maxY = extent[3]; const maxY = extent[3];
const flatCoordinates = const flatCoordinates =
[minX, minY, minX, maxY, maxX, maxY, maxX, minY, minX, minY]; [minX, minY, minX, maxY, maxX, maxY, maxX, minY, minX, minY];
const polygon = new Polygon(null); return new Polygon(flatCoordinates, GeometryLayout.XY, [flatCoordinates.length]);
polygon.setFlatCoordinates(
GeometryLayout.XY, flatCoordinates, [flatCoordinates.length]);
return polygon;
} }
@@ -426,14 +404,13 @@ export function fromCircle(circle, opt_sides, opt_angle) {
const sides = opt_sides ? opt_sides : 32; const sides = opt_sides ? opt_sides : 32;
const stride = circle.getStride(); const stride = circle.getStride();
const layout = circle.getLayout(); const layout = circle.getLayout();
const polygon = new Polygon(null, layout);
const arrayLength = stride * (sides + 1); const arrayLength = stride * (sides + 1);
const flatCoordinates = new Array(arrayLength); const flatCoordinates = new Array(arrayLength);
for (let i = 0; i < arrayLength; i++) { for (let i = 0; i < arrayLength; i++) {
flatCoordinates[i] = 0; flatCoordinates[i] = 0;
} }
const ends = [flatCoordinates.length]; const ends = [flatCoordinates.length];
polygon.setFlatCoordinates(layout, flatCoordinates, ends); const polygon = new Polygon(flatCoordinates, layout, ends);
makeRegular(polygon, circle.getCenter(), circle.getRadius(), opt_angle); makeRegular(polygon, circle.getCenter(), circle.getRadius(), opt_angle);
return polygon; return polygon;
} }
@@ -449,9 +426,7 @@ export function fromCircle(circle, opt_sides, opt_angle) {
*/ */
export function makeRegular(polygon, center, radius, opt_angle) { export function makeRegular(polygon, center, radius, opt_angle) {
const flatCoordinates = polygon.getFlatCoordinates(); const flatCoordinates = polygon.getFlatCoordinates();
const layout = polygon.getLayout();
const stride = polygon.getStride(); const stride = polygon.getStride();
const ends = polygon.getEnds();
const sides = flatCoordinates.length / stride - 1; const sides = flatCoordinates.length / stride - 1;
const startAngle = opt_angle ? opt_angle : 0; const startAngle = opt_angle ? opt_angle : 0;
for (let i = 0; i <= sides; ++i) { for (let i = 0; i <= sides; ++i) {
@@ -460,5 +435,5 @@ export function makeRegular(polygon, center, radius, opt_angle) {
flatCoordinates[offset] = center[0] + (radius * Math.cos(angle)); flatCoordinates[offset] = center[0] + (radius * Math.cos(angle));
flatCoordinates[offset + 1] = center[1] + (radius * Math.sin(angle)); flatCoordinates[offset + 1] = center[1] + (radius * Math.sin(angle));
} }
polygon.setFlatCoordinates(layout, flatCoordinates, ends); polygon.changed();
} }
+3 -4
View File
@@ -203,9 +203,8 @@ SimpleGeometry.prototype.getStride = function() {
/** /**
* @param {module:ol/geom/GeometryLayout} layout Layout. * @param {module:ol/geom/GeometryLayout} layout Layout.
* @param {Array.<number>} flatCoordinates Flat coordinates. * @param {Array.<number>} flatCoordinates Flat coordinates.
* @protected */
*/ SimpleGeometry.prototype.setFlatCoordinates = function(layout, flatCoordinates) {
SimpleGeometry.prototype.setFlatCoordinatesInternal = function(layout, flatCoordinates) {
this.stride = getStrideForLayout(layout); this.stride = getStrideForLayout(layout);
this.layout = layout; this.layout = layout;
this.flatCoordinates = flatCoordinates; this.flatCoordinates = flatCoordinates;
@@ -214,7 +213,7 @@ SimpleGeometry.prototype.setFlatCoordinatesInternal = function(layout, flatCoord
/** /**
* @abstract * @abstract
* @param {Array} coordinates Coordinates. * @param {!Array} coordinates Coordinates.
* @param {module:ol/geom/GeometryLayout=} opt_layout Layout. * @param {module:ol/geom/GeometryLayout=} opt_layout Layout.
*/ */
SimpleGeometry.prototype.setCoordinates = function(coordinates, opt_layout) {}; SimpleGeometry.prototype.setCoordinates = function(coordinates, opt_layout) {};
+17 -6
View File
@@ -733,12 +733,18 @@ Draw.prototype.modifyDrawing_ = function(event) {
if (geometry instanceof Polygon && if (geometry instanceof Polygon &&
this.mode_ !== Mode.POLYGON) { this.mode_ !== Mode.POLYGON) {
if (!this.sketchLine_) { if (!this.sketchLine_) {
this.sketchLine_ = new Feature(new LineString(null)); this.sketchLine_ = new Feature();
} }
const ring = geometry.getLinearRing(0); const ring = geometry.getLinearRing(0);
sketchLineGeom = /** @type {module:ol/geom/LineString} */ (this.sketchLine_.getGeometry()); sketchLineGeom = /** @type {module:ol/geom/LineString} */ (this.sketchLine_.getGeometry());
sketchLineGeom.setFlatCoordinates( if (!sketchLineGeom) {
ring.getLayout(), ring.getFlatCoordinates()); sketchLineGeom = new LineString(ring.getFlatCoordinates(), ring.getLayout());
this.sketchLine_.setGeometry(sketchLineGeom);
} else {
sketchLineGeom.setFlatCoordinates(
ring.getLayout(), ring.getFlatCoordinates());
sketchLineGeom.changed();
}
} else if (this.sketchLineCoords_) { } else if (this.sketchLineCoords_) {
sketchLineGeom = /** @type {module:ol/geom/LineString} */ (this.sketchLine_.getGeometry()); sketchLineGeom = /** @type {module:ol/geom/LineString} */ (this.sketchLine_.getGeometry());
sketchLineGeom.setCoordinates(this.sketchLineCoords_); sketchLineGeom.setCoordinates(this.sketchLineCoords_);
@@ -988,14 +994,19 @@ export function createBox() {
return ( return (
function(coordinates, opt_geometry) { function(coordinates, opt_geometry) {
const extent = boundingExtent(coordinates); const extent = boundingExtent(coordinates);
const geometry = opt_geometry || new Polygon(null); const boxCoordinates = [[
geometry.setCoordinates([[
getBottomLeft(extent), getBottomLeft(extent),
getBottomRight(extent), getBottomRight(extent),
getTopRight(extent), getTopRight(extent),
getTopLeft(extent), getTopLeft(extent),
getBottomLeft(extent) getBottomLeft(extent)
]]); ]];
let geometry = opt_geometry;
if (geometry) {
geometry.setCoordinates(boxCoordinates);
} else {
geometry = new Polygon(boxCoordinates);
}
return geometry; return geometry;
} }
); );
+6 -12
View File
@@ -105,8 +105,7 @@ describe('ol.rendering.style.Text', function() {
const polygon = [151, 17, 163, 22, 159, 30, 150, 30, 143, 24, 151, 17]; const polygon = [151, 17, 163, 22, 159, 30, 150, 30, 143, 24, 151, 17];
function createLineString(coords, textAlign, maxAngle, strokeColor, strokeWidth, scale) { function createLineString(coords, textAlign, maxAngle, strokeColor, strokeWidth, scale) {
let geom = new LineString(); let geom = new LineString(coords, 'XY');
geom.setFlatCoordinates('XY', coords);
let style = new Style({ let style = new Style({
stroke: new Stroke({ stroke: new Stroke({
color: 'red' color: 'red'
@@ -262,10 +261,8 @@ describe('ol.rendering.style.Text', function() {
it('renders text along a MultiLineString', function(done) { it('renders text along a MultiLineString', function(done) {
createMap('canvas'); createMap('canvas');
let line = new LineString(); let line = new LineString(nicePath, 'XY');
line.setFlatCoordinates('XY', nicePath); const geom = new MultiLineString([line]);
const geom = new MultiLineString(null);
geom.appendLineString(line);
line = line.clone(); line = line.clone();
line.translate(0, 50); line.translate(0, 50);
geom.appendLineString(line); geom.appendLineString(line);
@@ -287,8 +284,7 @@ describe('ol.rendering.style.Text', function() {
it('renders text along a Polygon', function(done) { it('renders text along a Polygon', function(done) {
createMap('canvas'); createMap('canvas');
const geom = new Polygon(null); const geom = new Polygon(polygon, 'XY', [polygon.length]);
geom.setFlatCoordinates('XY', polygon, [polygon.length]);
const feature = new Feature(geom); const feature = new Feature(geom);
feature.setStyle(new Style({ feature.setStyle(new Style({
text: new Text({ text: new Text({
@@ -305,10 +301,8 @@ describe('ol.rendering.style.Text', function() {
it('renders text along a MultiPolygon', function(done) { it('renders text along a MultiPolygon', function(done) {
createMap('canvas'); createMap('canvas');
let geom = new Polygon(null); let geom = new Polygon(polygon, 'XY', [polygon.length]);
geom.setFlatCoordinates('XY', polygon, [polygon.length]); const multiPolygon = new MultiPolygon([geom]);
const multiPolygon = new MultiPolygon(null);
multiPolygon.appendPolygon(geom);
geom = geom.clone(); geom = geom.clone();
geom.translate(0, 30); geom.translate(0, 30);
multiPolygon.appendPolygon(geom); multiPolygon.appendPolygon(geom);
-7
View File
@@ -178,13 +178,6 @@ describe('ol.geom.Circle', function() {
expect(circle.getRadius()).to.be(3); expect(circle.getRadius()).to.be(3);
}); });
it('fires a single change event', function() {
const spy = sinon.spy();
circle.on('change', spy);
circle.setFlatCoordinates('XY', [1, 2, 4, 2]);
expect(spy.calledOnce).to.be(true);
});
}); });
describe('#setRadius', function() { describe('#setRadius', function() {
+2 -2
View File
@@ -4,10 +4,10 @@ import LineString from '../../../../src/ol/geom/LineString.js';
describe('ol.geom.LineString', function() { describe('ol.geom.LineString', function() {
it('can be constructed with a null geometry', function() { it('cannot be constructed with a null geometry', function() {
expect(function() { expect(function() {
return new LineString(null); return new LineString(null);
}).not.to.throwException(); }).to.throwException();
}); });
describe('construct empty', function() { describe('construct empty', function() {
+3 -4
View File
@@ -5,10 +5,10 @@ import MultiLineString from '../../../../src/ol/geom/MultiLineString.js';
describe('ol.geom.MultiLineString', function() { describe('ol.geom.MultiLineString', function() {
it('can be constructed with a null geometry', function() { it('cannot be constructed with a null geometry', function() {
expect(function() { expect(function() {
return new MultiLineString(null); return new MultiLineString(null);
}).not.to.throwException(); }).to.throwException();
}); });
describe('construct empty', function() { describe('construct empty', function() {
@@ -343,10 +343,9 @@ describe('ol.geom.MultiLineString', function() {
describe('#setLineStrings', function() { describe('#setLineStrings', function() {
it('sets the line strings', function() { it('sets the line strings', function() {
const multiLineString = new MultiLineString(null);
const lineString1 = new LineString([[1, 2], [3, 4]]); const lineString1 = new LineString([[1, 2], [3, 4]]);
const lineString2 = new LineString([[5, 6], [7, 8]]); const lineString2 = new LineString([[5, 6], [7, 8]]);
multiLineString.setLineStrings([lineString1, lineString2]); const multiLineString = new MultiLineString([lineString1, lineString2]);
expect(multiLineString.getFlatCoordinates()).to.eql( expect(multiLineString.getFlatCoordinates()).to.eql(
[1, 2, 3, 4, 5, 6, 7, 8]); [1, 2, 3, 4, 5, 6, 7, 8]);
expect(multiLineString.getEnds()).to.eql([4, 8]); expect(multiLineString.getEnds()).to.eql([4, 8]);
+2 -2
View File
@@ -5,10 +5,10 @@ import Point from '../../../../src/ol/geom/Point.js';
describe('ol.geom.MultiPoint', function() { describe('ol.geom.MultiPoint', function() {
it('can be constructed with a null geometry', function() { it('cannot be constructed with a null geometry', function() {
expect(function() { expect(function() {
return new MultiPoint(null); return new MultiPoint(null);
}).not.to.throwException(); }).to.throwException();
}); });
describe('construct empty', function() { describe('construct empty', function() {
+4 -9
View File
@@ -4,22 +4,17 @@ import Polygon from '../../../../src/ol/geom/Polygon.js';
describe('ol.geom.MultiPolygon', function() { describe('ol.geom.MultiPolygon', function() {
it('can be constructed with a null geometry', function() { it('cannot be constructed with a null geometry', function() {
expect(function() { expect(function() {
return new MultiPolygon(null); return new MultiPolygon(null);
}).not.to.throwException(); }).to.throwException();
}); });
describe('with a null MultiPolygon', function() { describe('with a null MultiPolygon', function() {
let multiPolygon;
beforeEach(function() {
multiPolygon = new MultiPolygon(null);
});
it('can append polygons', function() { it('can append polygons', function() {
multiPolygon.appendPolygon( const multiPolygon = new MultiPolygon([
new Polygon([[[0, 0], [0, 2], [1, 1], [2, 0]]])); new Polygon([[[0, 0], [0, 2], [1, 1], [2, 0]]])]);
expect(multiPolygon.getCoordinates()).to.eql( expect(multiPolygon.getCoordinates()).to.eql(
[[[[0, 0], [0, 2], [1, 1], [2, 0]]]]); [[[[0, 0], [0, 2], [1, 1], [2, 0]]]]);
multiPolygon.appendPolygon( multiPolygon.appendPolygon(
+2 -2
View File
@@ -3,10 +3,10 @@ import Point from '../../../../src/ol/geom/Point.js';
describe('ol.geom.Point', function() { describe('ol.geom.Point', function() {
it('can be constructed with a null geometry', function() { it('cannot be constructed with a null geometry', function() {
expect(function() { expect(function() {
return new Point(null); return new Point(null);
}).not.to.throwException(); }).to.throwException();
}); });
describe('construct with 2D coordinates', function() { describe('construct with 2D coordinates', function() {
+2 -2
View File
@@ -6,10 +6,10 @@ import Polygon, {fromCircle, fromExtent} from '../../../../src/ol/geom/Polygon.j
describe('ol/geom/Polygon', function() { describe('ol/geom/Polygon', function() {
it('can be constructed with a null geometry', function() { it('cannot be constructed with a null geometry', function() {
expect(function() { expect(function() {
return new Polygon(null); return new Polygon(null);
}).not.to.throwException(); }).to.throwException();
}); });
describe('construct empty', function() { describe('construct empty', function() {