Merge pull request #1358 from twpayne/vector-api-geometry-collection
[vector-api] Add ol.geom.GeometryCollection
This commit is contained in:
+32
-25
@@ -2,8 +2,6 @@ goog.require('ol.Feature');
|
|||||||
goog.require('ol.Map');
|
goog.require('ol.Map');
|
||||||
goog.require('ol.RendererHint');
|
goog.require('ol.RendererHint');
|
||||||
goog.require('ol.View2D');
|
goog.require('ol.View2D');
|
||||||
goog.require('ol.geom.LineString');
|
|
||||||
goog.require('ol.geom.Point');
|
|
||||||
goog.require('ol.layer.Tile');
|
goog.require('ol.layer.Tile');
|
||||||
goog.require('ol.layer.Vector');
|
goog.require('ol.layer.Vector');
|
||||||
goog.require('ol.shape');
|
goog.require('ol.shape');
|
||||||
@@ -54,6 +52,18 @@ var styles = {
|
|||||||
fill: new ol.style.Fill({
|
fill: new ol.style.Fill({
|
||||||
color: 'rgba(0, 0, 255, 0.1)'
|
color: 'rgba(0, 0, 255, 0.1)'
|
||||||
})
|
})
|
||||||
|
})],
|
||||||
|
'GeometryCollection': [new ol.style.Style({
|
||||||
|
stroke: new ol.style.Stroke({
|
||||||
|
color: 'magenta',
|
||||||
|
width: 2
|
||||||
|
}),
|
||||||
|
fill: new ol.style.Fill({
|
||||||
|
color: 'magenta'
|
||||||
|
}),
|
||||||
|
image: ol.shape.renderCircle(10, null, new ol.style.Stroke({
|
||||||
|
color: 'magenta'
|
||||||
|
}))
|
||||||
})]
|
})]
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -122,6 +132,26 @@ var vectorSource = new ol.source.GeoJSON(
|
|||||||
[[[1e6, 6e6], [1e6, 8e6], [3e6, 8e6], [3e6, 6e6]]]
|
[[[1e6, 6e6], [1e6, 8e6], [3e6, 8e6], [3e6, 6e6]]]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'type': 'Feature',
|
||||||
|
'geometry': {
|
||||||
|
'type': 'GeometryCollection',
|
||||||
|
'geometries': [
|
||||||
|
{
|
||||||
|
'type': 'LineString',
|
||||||
|
'coordinates': [[-5e6, -5e6], [0e6, -5e6]]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'type': 'Point',
|
||||||
|
'coordinates': [4e6, -5e6]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'type': 'Polygon',
|
||||||
|
'coordinates': [[[1e6, -6e6], [2e6, -4e6], [3e6, -6e6]]]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -131,29 +161,6 @@ var vectorLayer = new ol.layer.Vector({
|
|||||||
source: vectorSource,
|
source: vectorSource,
|
||||||
styleFunction: styleFunction
|
styleFunction: styleFunction
|
||||||
});
|
});
|
||||||
var tmpLineFeature = new ol.Feature(
|
|
||||||
new ol.geom.LineString([[-5e6, -5e6], [5e6, -5e6]]));
|
|
||||||
var tmpPointFeature = new ol.Feature(
|
|
||||||
new ol.geom.Point([0, 3e6]));
|
|
||||||
var tmpStyle = new ol.style.Style({
|
|
||||||
stroke: new ol.style.Stroke({
|
|
||||||
color: 'magenta',
|
|
||||||
lineCap: 'round',
|
|
||||||
width: 5
|
|
||||||
}),
|
|
||||||
image: ol.shape.renderCircle(5,
|
|
||||||
new ol.style.Fill({
|
|
||||||
color: 'green'
|
|
||||||
}),
|
|
||||||
new ol.style.Stroke({
|
|
||||||
color: 'blue'
|
|
||||||
}))
|
|
||||||
});
|
|
||||||
vectorLayer.on('postcompose', function(event) {
|
|
||||||
var render = event.getRender();
|
|
||||||
render.drawFeature(tmpLineFeature, tmpStyle);
|
|
||||||
render.drawFeature(tmpPointFeature, tmpStyle);
|
|
||||||
});
|
|
||||||
|
|
||||||
var map = new ol.Map({
|
var map = new ol.Map({
|
||||||
layers: [
|
layers: [
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
// FIXME coordinate order
|
// FIXME coordinate order
|
||||||
// FIXME reprojection
|
// FIXME reprojection
|
||||||
// FIXME GeometryCollection
|
|
||||||
|
|
||||||
goog.provide('ol.format.GeoJSON');
|
goog.provide('ol.format.GeoJSON');
|
||||||
|
|
||||||
|
goog.require('goog.array');
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
goog.require('ol.format.JSON');
|
goog.require('ol.format.JSON');
|
||||||
|
goog.require('ol.geom.GeometryCollection');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.geom.MultiLineString');
|
goog.require('ol.geom.MultiLineString');
|
||||||
goog.require('ol.geom.MultiPoint');
|
goog.require('ol.geom.MultiPoint');
|
||||||
@@ -41,7 +42,7 @@ goog.inherits(ol.format.GeoJSON, ol.format.JSON);
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {GeoJSONGeometry} object Object.
|
* @param {GeoJSONObject} object Object.
|
||||||
* @private
|
* @private
|
||||||
* @return {ol.geom.Geometry} Geometry.
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
*/
|
*/
|
||||||
@@ -52,6 +53,19 @@ ol.format.GeoJSON.readGeometry_ = function(object) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {GeoJSONGeometryCollection} object Object.
|
||||||
|
* @private
|
||||||
|
* @return {ol.geom.GeometryCollection} Geometry collection.
|
||||||
|
*/
|
||||||
|
ol.format.GeoJSON.readGeometryCollectionGeometry_ = function(object) {
|
||||||
|
goog.asserts.assert(object.type == 'GeometryCollection');
|
||||||
|
var geometries = goog.array.map(
|
||||||
|
object.geometries, ol.format.GeoJSON.readGeometry_);
|
||||||
|
return new ol.geom.GeometryCollection(geometries);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {GeoJSONGeometry} object Object.
|
* @param {GeoJSONGeometry} object Object.
|
||||||
* @private
|
* @private
|
||||||
@@ -121,7 +135,7 @@ ol.format.GeoJSON.readPolygonGeometry_ = function(object) {
|
|||||||
/**
|
/**
|
||||||
* @param {ol.geom.Geometry} geometry Geometry.
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
* @private
|
* @private
|
||||||
* @return {GeoJSONGeometry} GeoJSON geometry.
|
* @return {GeoJSONObject} GeoJSON geometry.
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.writeGeometry_ = function(geometry) {
|
ol.format.GeoJSON.writeGeometry_ = function(geometry) {
|
||||||
var geometryWriter = ol.format.GeoJSON.GEOMETRY_WRITERS_[geometry.getType()];
|
var geometryWriter = ol.format.GeoJSON.GEOMETRY_WRITERS_[geometry.getType()];
|
||||||
@@ -130,6 +144,22 @@ ol.format.GeoJSON.writeGeometry_ = function(geometry) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @private
|
||||||
|
* @return {GeoJSONGeometryCollection} GeoJSON geometry collection.
|
||||||
|
*/
|
||||||
|
ol.format.GeoJSON.writeGeometryCollectionGeometry_ = function(geometry) {
|
||||||
|
goog.asserts.assertInstanceof(geometry, ol.geom.GeometryCollection);
|
||||||
|
var geometries = goog.array.map(
|
||||||
|
geometry.getGeometriesArray(), ol.format.GeoJSON.writeGeometry_);
|
||||||
|
return /** @type {GeoJSONGeometryCollection} */ ({
|
||||||
|
'type': 'GeometryCollection',
|
||||||
|
'geometries': geometries
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.geom.Geometry} geometry Geometry.
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
* @private
|
* @private
|
||||||
@@ -219,7 +249,7 @@ ol.format.GeoJSON.writePolygonGeometry_ = function(geometry) {
|
|||||||
/**
|
/**
|
||||||
* @const
|
* @const
|
||||||
* @private
|
* @private
|
||||||
* @type {Object.<string, function(GeoJSONGeometry): ol.geom.Geometry>}
|
* @type {Object.<string, function(GeoJSONObject): ol.geom.Geometry>}
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.GEOMETRY_READERS_ = {
|
ol.format.GeoJSON.GEOMETRY_READERS_ = {
|
||||||
'Point': ol.format.GeoJSON.readPointGeometry_,
|
'Point': ol.format.GeoJSON.readPointGeometry_,
|
||||||
@@ -227,14 +257,15 @@ ol.format.GeoJSON.GEOMETRY_READERS_ = {
|
|||||||
'Polygon': ol.format.GeoJSON.readPolygonGeometry_,
|
'Polygon': ol.format.GeoJSON.readPolygonGeometry_,
|
||||||
'MultiPoint': ol.format.GeoJSON.readMultiPointGeometry_,
|
'MultiPoint': ol.format.GeoJSON.readMultiPointGeometry_,
|
||||||
'MultiLineString': ol.format.GeoJSON.readMultiLineStringGeometry_,
|
'MultiLineString': ol.format.GeoJSON.readMultiLineStringGeometry_,
|
||||||
'MultiPolygon': ol.format.GeoJSON.readMultiPolygonGeometry_
|
'MultiPolygon': ol.format.GeoJSON.readMultiPolygonGeometry_,
|
||||||
|
'GeometryCollection': ol.format.GeoJSON.readGeometryCollectionGeometry_
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @const
|
* @const
|
||||||
* @private
|
* @private
|
||||||
* @type {Object.<string, function(ol.geom.Geometry): GeoJSONGeometry>}
|
* @type {Object.<string, function(ol.geom.Geometry): GeoJSONObject>}
|
||||||
*/
|
*/
|
||||||
ol.format.GeoJSON.GEOMETRY_WRITERS_ = {
|
ol.format.GeoJSON.GEOMETRY_WRITERS_ = {
|
||||||
'Point': ol.format.GeoJSON.writePointGeometry_,
|
'Point': ol.format.GeoJSON.writePointGeometry_,
|
||||||
@@ -242,7 +273,8 @@ ol.format.GeoJSON.GEOMETRY_WRITERS_ = {
|
|||||||
'Polygon': ol.format.GeoJSON.writePolygonGeometry_,
|
'Polygon': ol.format.GeoJSON.writePolygonGeometry_,
|
||||||
'MultiPoint': ol.format.GeoJSON.writeMultiPointGeometry_,
|
'MultiPoint': ol.format.GeoJSON.writeMultiPointGeometry_,
|
||||||
'MultiLineString': ol.format.GeoJSON.writeMultiLineStringGeometry_,
|
'MultiLineString': ol.format.GeoJSON.writeMultiLineStringGeometry_,
|
||||||
'MultiPolygon': ol.format.GeoJSON.writeMultiPolygonGeometry_
|
'MultiPolygon': ol.format.GeoJSON.writeMultiPolygonGeometry_,
|
||||||
|
'GeometryCollection': ol.format.GeoJSON.writeGeometryCollectionGeometry_
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
@exportSymbol ol.geom.Geometry
|
@exportSymbol ol.geom.Geometry
|
||||||
@exportProperty ol.geom.Geometry.prototype.getClosestPoint
|
@exportProperty ol.geom.Geometry.prototype.getClosestPoint
|
||||||
@exportProperty ol.geom.Geometry.prototype.getExtent
|
@exportProperty ol.geom.Geometry.prototype.getType
|
||||||
@exportProperty ol.geom.Geometry.prototype.getLayout
|
|
||||||
@exportProperty ol.geom.Geometry.prototype.getSimplifiedGeometry
|
|
||||||
@exportProperty ol.geom.Geometry.prototype.transform
|
|
||||||
|
|||||||
+17
-215
@@ -1,14 +1,9 @@
|
|||||||
// FIXME add GeometryCollection
|
|
||||||
|
|
||||||
goog.provide('ol.geom.Geometry');
|
goog.provide('ol.geom.Geometry');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('goog.events.EventType');
|
goog.require('goog.events.EventType');
|
||||||
goog.require('goog.functions');
|
goog.require('goog.functions');
|
||||||
goog.require('goog.object');
|
|
||||||
goog.require('ol.Observable');
|
goog.require('ol.Observable');
|
||||||
goog.require('ol.extent');
|
|
||||||
goog.require('ol.geom.flat');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,7 +16,8 @@ ol.geom.GeometryType = {
|
|||||||
POLYGON: 'Polygon',
|
POLYGON: 'Polygon',
|
||||||
MULTI_POINT: 'MultiPoint',
|
MULTI_POINT: 'MultiPoint',
|
||||||
MULTI_LINE_STRING: 'MultiLineString',
|
MULTI_LINE_STRING: 'MultiLineString',
|
||||||
MULTI_POLYGON: 'MultiPolygon'
|
MULTI_POLYGON: 'MultiPolygon',
|
||||||
|
GEOMETRY_COLLECTION: 'GeometryCollection'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -45,24 +41,6 @@ ol.geom.Geometry = function() {
|
|||||||
|
|
||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
/**
|
|
||||||
* @protected
|
|
||||||
* @type {ol.geom.GeometryLayout}
|
|
||||||
*/
|
|
||||||
this.layout = ol.geom.GeometryLayout.XY;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @protected
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
this.stride = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @protected
|
|
||||||
* @type {Array.<number>}
|
|
||||||
*/
|
|
||||||
this.flatCoordinates = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@@ -82,27 +60,33 @@ ol.geom.Geometry = function() {
|
|||||||
this.extentRevision = -1;
|
this.extentRevision = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @protected
|
||||||
* @type {Object.<string, ol.geom.Geometry>}
|
* @type {Object.<string, ol.geom.Geometry>}
|
||||||
*/
|
*/
|
||||||
this.simplifiedGeometryCache_ = {};
|
this.simplifiedGeometryCache = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @protected
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.simplifiedGeometryMaxMinSquaredTolerance_ = 0;
|
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @protected
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.simplifiedGeometryRevision_ = 0;
|
this.simplifiedGeometryRevision = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.geom.Geometry, ol.Observable);
|
goog.inherits(ol.geom.Geometry, ol.Observable);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {ol.geom.Geometry} Clone.
|
||||||
|
*/
|
||||||
|
ol.geom.Geometry.prototype.clone = goog.abstractMethod;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} x X.
|
* @param {number} x X.
|
||||||
* @param {number} y Y.
|
* @param {number} y Y.
|
||||||
@@ -126,44 +110,6 @@ ol.geom.Geometry.prototype.getClosestPoint = function(point, opt_closestPoint) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {number} stride Stride.
|
|
||||||
* @private
|
|
||||||
* @return {ol.geom.GeometryLayout} layout Layout.
|
|
||||||
*/
|
|
||||||
ol.geom.Geometry.getLayoutForStride_ = function(stride) {
|
|
||||||
if (stride == 2) {
|
|
||||||
return ol.geom.GeometryLayout.XY;
|
|
||||||
} else if (stride == 3) {
|
|
||||||
return ol.geom.GeometryLayout.XYZ;
|
|
||||||
} else if (stride == 4) {
|
|
||||||
return ol.geom.GeometryLayout.XYZM;
|
|
||||||
} else {
|
|
||||||
throw new Error('unsupported stride: ' + stride);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.geom.GeometryLayout} layout Layout.
|
|
||||||
* @private
|
|
||||||
* @return {number} Stride.
|
|
||||||
*/
|
|
||||||
ol.geom.Geometry.getStrideForLayout_ = function(layout) {
|
|
||||||
if (layout == ol.geom.GeometryLayout.XY) {
|
|
||||||
return 2;
|
|
||||||
} else if (layout == ol.geom.GeometryLayout.XYZ) {
|
|
||||||
return 3;
|
|
||||||
} else if (layout == ol.geom.GeometryLayout.XYM) {
|
|
||||||
return 3;
|
|
||||||
} else if (layout == ol.geom.GeometryLayout.XYZM) {
|
|
||||||
return 4;
|
|
||||||
} else {
|
|
||||||
throw new Error('unsupported layout: ' + layout);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.Coordinate} coordinate Coordinate.
|
* @param {ol.Coordinate} coordinate Coordinate.
|
||||||
* @return {boolean} Contains coordinate.
|
* @return {boolean} Contains coordinate.
|
||||||
@@ -194,31 +140,7 @@ ol.geom.Geometry.prototype.dispatchChangeEvent = function() {
|
|||||||
* @param {ol.Extent=} opt_extent Extent.
|
* @param {ol.Extent=} opt_extent Extent.
|
||||||
* @return {ol.Extent} extent Extent.
|
* @return {ol.Extent} extent Extent.
|
||||||
*/
|
*/
|
||||||
ol.geom.Geometry.prototype.getExtent = function(opt_extent) {
|
ol.geom.Geometry.prototype.getExtent = goog.abstractMethod;
|
||||||
if (this.extentRevision != this.revision) {
|
|
||||||
this.extent = ol.extent.createOrUpdateFromFlatCoordinates(
|
|
||||||
this.flatCoordinates, this.stride, this.extent);
|
|
||||||
this.extentRevision = this.revision;
|
|
||||||
}
|
|
||||||
goog.asserts.assert(goog.isDef(this.extent));
|
|
||||||
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {Array.<number>} Flat coordinates.
|
|
||||||
*/
|
|
||||||
ol.geom.Geometry.prototype.getFlatCoordinates = function() {
|
|
||||||
return this.flatCoordinates;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {ol.geom.GeometryLayout} Layout.
|
|
||||||
*/
|
|
||||||
ol.geom.Geometry.prototype.getLayout = function() {
|
|
||||||
return this.layout;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -233,60 +155,7 @@ ol.geom.Geometry.prototype.getRevision = function() {
|
|||||||
* @param {number} squaredTolerance Squared tolerance.
|
* @param {number} squaredTolerance Squared tolerance.
|
||||||
* @return {ol.geom.Geometry} Simplified geometry.
|
* @return {ol.geom.Geometry} Simplified geometry.
|
||||||
*/
|
*/
|
||||||
ol.geom.Geometry.prototype.getSimplifiedGeometry = function(squaredTolerance) {
|
ol.geom.Geometry.prototype.getSimplifiedGeometry = goog.abstractMethod;
|
||||||
if (this.simplifiedGeometryRevision_ != this.revision) {
|
|
||||||
goog.object.clear(this.simplifiedGeometryCache_);
|
|
||||||
this.simplifiedGeometryMaxMinSquaredTolerance_ = 0;
|
|
||||||
this.simplifiedGeometryRevision_ = this.revision;
|
|
||||||
}
|
|
||||||
// If squaredTolerance is negative or if we know that simplification will not
|
|
||||||
// have any effect then just return this.
|
|
||||||
if (squaredTolerance < 0 ||
|
|
||||||
(this.simplifiedGeometryMaxMinSquaredTolerance_ !== 0 &&
|
|
||||||
squaredTolerance <= this.simplifiedGeometryMaxMinSquaredTolerance_)) {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
var key = squaredTolerance.toString();
|
|
||||||
if (this.simplifiedGeometryCache_.hasOwnProperty(key)) {
|
|
||||||
return this.simplifiedGeometryCache_[key];
|
|
||||||
} else {
|
|
||||||
var simplifiedGeometry =
|
|
||||||
this.getSimplifiedGeometryInternal(squaredTolerance);
|
|
||||||
var simplifiedFlatCoordinates = simplifiedGeometry.getFlatCoordinates();
|
|
||||||
if (simplifiedFlatCoordinates.length < this.flatCoordinates.length) {
|
|
||||||
this.simplifiedGeometryCache_[key] = simplifiedGeometry;
|
|
||||||
return simplifiedGeometry;
|
|
||||||
} else {
|
|
||||||
// Simplification did not actually remove any coordinates. We now know
|
|
||||||
// that any calls to getSimplifiedGeometry with a squaredTolerance less
|
|
||||||
// than or equal to the current squaredTolerance will also not have any
|
|
||||||
// effect. This allows us to short circuit simplification (saving CPU
|
|
||||||
// cycles) and prevents the cache of simplified geometries from filling
|
|
||||||
// up with useless identical copies of this geometry (saving memory).
|
|
||||||
this.simplifiedGeometryMaxMinSquaredTolerance_ = squaredTolerance;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {number} squaredTolerance Squared tolerance.
|
|
||||||
* @return {ol.geom.Geometry} Simplified geometry.
|
|
||||||
* @protected
|
|
||||||
*/
|
|
||||||
ol.geom.Geometry.prototype.getSimplifiedGeometryInternal =
|
|
||||||
function(squaredTolerance) {
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {number} Stride.
|
|
||||||
*/
|
|
||||||
ol.geom.Geometry.prototype.getStride = function() {
|
|
||||||
return this.stride;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -295,59 +164,10 @@ ol.geom.Geometry.prototype.getStride = function() {
|
|||||||
ol.geom.Geometry.prototype.getType = goog.abstractMethod;
|
ol.geom.Geometry.prototype.getType = goog.abstractMethod;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.geom.GeometryLayout} layout Layout.
|
|
||||||
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
|
||||||
* @protected
|
|
||||||
*/
|
|
||||||
ol.geom.Geometry.prototype.setFlatCoordinatesInternal =
|
|
||||||
function(layout, flatCoordinates) {
|
|
||||||
this.stride = ol.geom.Geometry.getStrideForLayout_(layout);
|
|
||||||
this.layout = layout;
|
|
||||||
this.flatCoordinates = flatCoordinates;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.geom.GeometryLayout|undefined} layout Layout.
|
|
||||||
* @param {Array} coordinates Coordinates.
|
|
||||||
* @param {number} nesting Nesting.
|
|
||||||
* @protected
|
|
||||||
*/
|
|
||||||
ol.geom.Geometry.prototype.setLayout =
|
|
||||||
function(layout, coordinates, nesting) {
|
|
||||||
/** @type {number} */
|
|
||||||
var stride;
|
|
||||||
if (goog.isDef(layout)) {
|
|
||||||
stride = ol.geom.Geometry.getStrideForLayout_(layout);
|
|
||||||
} else {
|
|
||||||
var i;
|
|
||||||
for (i = 0; i < nesting; ++i) {
|
|
||||||
if (coordinates.length === 0) {
|
|
||||||
this.layout = ol.geom.GeometryLayout.XY;
|
|
||||||
this.stride = 2;
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
coordinates = /** @type {Array} */ (coordinates[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stride = (/** @type {Array} */ (coordinates)).length;
|
|
||||||
layout = ol.geom.Geometry.getLayoutForStride_(stride);
|
|
||||||
}
|
|
||||||
this.layout = layout;
|
|
||||||
this.stride = stride;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.TransformFunction} transformFn Transform.
|
* @param {ol.TransformFunction} transformFn Transform.
|
||||||
*/
|
*/
|
||||||
ol.geom.Geometry.prototype.transform = function(transformFn) {
|
ol.geom.Geometry.prototype.transform = goog.abstractMethod;
|
||||||
if (!goog.isNull(this.flatCoordinates)) {
|
|
||||||
transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
|
|
||||||
this.dispatchChangeEvent();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -391,21 +211,3 @@ ol.geom.RawMultiLineString;
|
|||||||
* @typedef {Array.<ol.geom.RawPolygon>}
|
* @typedef {Array.<ol.geom.RawPolygon>}
|
||||||
*/
|
*/
|
||||||
ol.geom.RawMultiPolygon;
|
ol.geom.RawMultiPolygon;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.geom.Geometry} geometry Geometry.
|
|
||||||
* @param {goog.vec.Mat4.AnyType} transform Transform.
|
|
||||||
* @param {Array.<number>=} opt_dest Destination.
|
|
||||||
* @return {Array.<number>} Transformed flat coordinates.
|
|
||||||
*/
|
|
||||||
ol.geom.transformGeometry2D = function(geometry, transform, opt_dest) {
|
|
||||||
var flatCoordinates = geometry.getFlatCoordinates();
|
|
||||||
if (goog.isNull(flatCoordinates)) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
var stride = geometry.getStride();
|
|
||||||
return ol.geom.flat.transform2D(
|
|
||||||
flatCoordinates, stride, transform, opt_dest);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
@exportSymbol ol.geom.GeometryCollection
|
||||||
|
@exportProperty ol.geom.GeometryCollection.prototype.clone
|
||||||
|
@exportProperty ol.geom.GeometryCollection.prototype.getExtent
|
||||||
|
@exportProperty ol.geom.GeometryCollection.prototype.getGeometries
|
||||||
|
@exportProperty ol.geom.GeometryCollection.prototype.getSimplifiedGeometry
|
||||||
|
@exportProperty ol.geom.GeometryCollection.prototype.getType
|
||||||
|
@exportProperty ol.geom.GeometryCollection.prototype.setGeometries
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
goog.provide('ol.geom.GeometryCollection');
|
||||||
|
|
||||||
|
goog.require('goog.array');
|
||||||
|
goog.require('goog.asserts');
|
||||||
|
goog.require('goog.object');
|
||||||
|
goog.require('ol.extent');
|
||||||
|
goog.require('ol.geom.Geometry');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @extends {ol.geom.Geometry}
|
||||||
|
* @param {Array.<ol.geom.Geometry>=} opt_geometries Geometries.
|
||||||
|
*/
|
||||||
|
ol.geom.GeometryCollection = function(opt_geometries) {
|
||||||
|
|
||||||
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {Array.<ol.geom.Geometry>}
|
||||||
|
*/
|
||||||
|
this.geometries_ = goog.isDef(opt_geometries) ? opt_geometries : null;
|
||||||
|
|
||||||
|
};
|
||||||
|
goog.inherits(ol.geom.GeometryCollection, ol.geom.Geometry);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Array.<ol.geom.Geometry>} geometries Geometries.
|
||||||
|
* @private
|
||||||
|
* @return {Array.<ol.geom.Geometry>} Cloned geometries.
|
||||||
|
*/
|
||||||
|
ol.geom.GeometryCollection.cloneGeometries_ = function(geometries) {
|
||||||
|
var clonedGeometries = [];
|
||||||
|
var i, ii;
|
||||||
|
for (i = 0, ii = geometries.length; i < ii; ++i) {
|
||||||
|
clonedGeometries.push(geometries[i].clone());
|
||||||
|
}
|
||||||
|
return clonedGeometries;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.GeometryCollection.prototype.clone = function() {
|
||||||
|
var geometryCollection = new ol.geom.GeometryCollection(null);
|
||||||
|
geometryCollection.setGeometries(this.geometries_);
|
||||||
|
return geometryCollection;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.GeometryCollection.prototype.closestPointXY =
|
||||||
|
function(x, y, closestPoint, minSquaredDistance) {
|
||||||
|
if (minSquaredDistance <
|
||||||
|
ol.extent.closestSquaredDistanceXY(this.getExtent(), x, y)) {
|
||||||
|
return minSquaredDistance;
|
||||||
|
}
|
||||||
|
var geometries = this.geometries_;
|
||||||
|
var i, ii;
|
||||||
|
for (i = 0, ii = geometries.length; i < ii; ++i) {
|
||||||
|
minSquaredDistance = geometries[i].closestPointXY(
|
||||||
|
x, y, closestPoint, minSquaredDistance);
|
||||||
|
}
|
||||||
|
return minSquaredDistance;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.GeometryCollection.prototype.containsXY = function(x, y) {
|
||||||
|
var geometries = this.geometries_;
|
||||||
|
var i, ii;
|
||||||
|
for (i = 0, ii = geometries.length; i < ii; ++i) {
|
||||||
|
if (geometries[i].containsXY(x, y)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.GeometryCollection.prototype.getExtent = function(opt_extent) {
|
||||||
|
if (this.extentRevision != this.revision) {
|
||||||
|
var extent = ol.extent.createOrUpdateEmpty(this.extent);
|
||||||
|
var geometries = this.geometries_;
|
||||||
|
var i, ii;
|
||||||
|
for (i = 0, ii = geometries.length; i < ii; ++i) {
|
||||||
|
ol.extent.extend(extent, geometries[i].getExtent());
|
||||||
|
}
|
||||||
|
this.extent = extent;
|
||||||
|
this.extentRevision = this.revision;
|
||||||
|
}
|
||||||
|
goog.asserts.assert(goog.isDef(this.extent));
|
||||||
|
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Array.<ol.geom.Geometry>} Geometries.
|
||||||
|
*/
|
||||||
|
ol.geom.GeometryCollection.prototype.getGeometries = function() {
|
||||||
|
return ol.geom.GeometryCollection.cloneGeometries_(this.geometries_);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Array.<ol.geom.Geometry>} Geometries.
|
||||||
|
*/
|
||||||
|
ol.geom.GeometryCollection.prototype.getGeometriesArray = function() {
|
||||||
|
return this.geometries_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.GeometryCollection.prototype.getSimplifiedGeometry =
|
||||||
|
function(squaredTolerance) {
|
||||||
|
if (this.simplifiedGeometryRevision != this.revision) {
|
||||||
|
goog.object.clear(this.simplifiedGeometryCache);
|
||||||
|
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||||
|
this.simplifiedGeometryRevision = this.revision;
|
||||||
|
}
|
||||||
|
if (squaredTolerance < 0 ||
|
||||||
|
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
|
||||||
|
squaredTolerance < this.simplifiedGeometryMaxMinSquaredTolerance)) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
var key = squaredTolerance.toString();
|
||||||
|
if (this.simplifiedGeometryCache.hasOwnProperty(key)) {
|
||||||
|
return this.simplifiedGeometryCache[key];
|
||||||
|
} else {
|
||||||
|
var simplifiedGeometries = [];
|
||||||
|
var geometries = this.geometries_;
|
||||||
|
var simplified = false;
|
||||||
|
var i, ii;
|
||||||
|
for (i = 0, ii = geometries.length; i < ii; ++i) {
|
||||||
|
var geometry = geometries[i];
|
||||||
|
var simplifiedGeometry = geometry.getSimplifiedGeometry(squaredTolerance);
|
||||||
|
simplifiedGeometries.push(simplifiedGeometry);
|
||||||
|
if (simplifiedGeometry !== geometry) {
|
||||||
|
simplified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (simplified) {
|
||||||
|
var simplifiedGeometryCollection = new ol.geom.GeometryCollection(null);
|
||||||
|
simplifiedGeometryCollection.setGeometriesArray(simplifiedGeometries);
|
||||||
|
this.simplifiedGeometryCache[key] = simplifiedGeometryCollection;
|
||||||
|
return simplifiedGeometryCollection;
|
||||||
|
} else {
|
||||||
|
this.simplifiedGeometryMaxMinSquaredTolerance = squaredTolerance;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.GeometryCollection.prototype.getType = function() {
|
||||||
|
return ol.geom.GeometryType.GEOMETRY_COLLECTION;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Array.<ol.geom.Geometry>} geometries Geometries.
|
||||||
|
*/
|
||||||
|
ol.geom.GeometryCollection.prototype.setGeometries = function(geometries) {
|
||||||
|
this.setGeometriesArray(
|
||||||
|
ol.geom.GeometryCollection.cloneGeometries_(geometries));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Array.<ol.geom.Geometry>} geometries Geometries.
|
||||||
|
*/
|
||||||
|
ol.geom.GeometryCollection.prototype.setGeometriesArray = function(geometries) {
|
||||||
|
this.geometries_ = geometries;
|
||||||
|
this.dispatchChangeEvent();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.GeometryCollection.prototype.transform = function(transformFn) {
|
||||||
|
var geometries = this.geometries_;
|
||||||
|
var i, ii;
|
||||||
|
for (i = 0, ii = geometries.length; i < ii; ++i) {
|
||||||
|
geometries[i].transform(transformFn);
|
||||||
|
}
|
||||||
|
this.dispatchChangeEvent();
|
||||||
|
};
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
@exportSymbol ol.geom.LinearRing
|
@exportSymbol ol.geom.LinearRing
|
||||||
|
@exportProperty ol.geom.LinearRing.prototype.clone
|
||||||
@exportProperty ol.geom.LinearRing.prototype.getArea
|
@exportProperty ol.geom.LinearRing.prototype.getArea
|
||||||
@exportProperty ol.geom.LinearRing.prototype.getCoordinates
|
@exportProperty ol.geom.LinearRing.prototype.getCoordinates
|
||||||
@exportProperty ol.geom.LinearRing.prototype.getType
|
@exportProperty ol.geom.LinearRing.prototype.getType
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
goog.provide('ol.geom.LinearRing');
|
goog.provide('ol.geom.LinearRing');
|
||||||
|
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.geom.Geometry');
|
goog.require('ol.geom.SimpleGeometry');
|
||||||
goog.require('ol.geom.closest');
|
goog.require('ol.geom.closest');
|
||||||
goog.require('ol.geom.flat');
|
goog.require('ol.geom.flat');
|
||||||
goog.require('ol.geom.simplify');
|
goog.require('ol.geom.simplify');
|
||||||
@@ -10,7 +10,7 @@ goog.require('ol.geom.simplify');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.geom.Geometry}
|
* @extends {ol.geom.SimpleGeometry}
|
||||||
* @param {ol.geom.RawLinearRing} coordinates Coordinates.
|
* @param {ol.geom.RawLinearRing} coordinates Coordinates.
|
||||||
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
||||||
*/
|
*/
|
||||||
@@ -33,7 +33,17 @@ ol.geom.LinearRing = function(coordinates, opt_layout) {
|
|||||||
this.setCoordinates(coordinates, opt_layout);
|
this.setCoordinates(coordinates, opt_layout);
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.geom.LinearRing, ol.geom.Geometry);
|
goog.inherits(ol.geom.LinearRing, ol.geom.SimpleGeometry);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.LinearRing.prototype.clone = function() {
|
||||||
|
var linearRing = new ol.geom.LinearRing(null);
|
||||||
|
linearRing.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
|
||||||
|
return linearRing;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@exportSymbol ol.geom.LineString
|
@exportSymbol ol.geom.LineString
|
||||||
|
@exportProperty ol.geom.LineString.prototype.clone
|
||||||
@exportProperty ol.geom.LineString.prototype.getCoordinates
|
@exportProperty ol.geom.LineString.prototype.getCoordinates
|
||||||
@exportProperty ol.geom.LineString.prototype.getType
|
@exportProperty ol.geom.LineString.prototype.getType
|
||||||
@exportProperty ol.geom.LineString.prototype.setCoordinates
|
@exportProperty ol.geom.LineString.prototype.setCoordinates
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
goog.provide('ol.geom.LineString');
|
goog.provide('ol.geom.LineString');
|
||||||
|
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.geom.Geometry');
|
goog.require('ol.geom.SimpleGeometry');
|
||||||
goog.require('ol.geom.closest');
|
goog.require('ol.geom.closest');
|
||||||
goog.require('ol.geom.flat');
|
goog.require('ol.geom.flat');
|
||||||
goog.require('ol.geom.simplify');
|
goog.require('ol.geom.simplify');
|
||||||
@@ -10,7 +10,7 @@ goog.require('ol.geom.simplify');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.geom.Geometry}
|
* @extends {ol.geom.SimpleGeometry}
|
||||||
* @param {ol.geom.RawLineString} coordinates Coordinates.
|
* @param {ol.geom.RawLineString} coordinates Coordinates.
|
||||||
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
||||||
*/
|
*/
|
||||||
@@ -33,7 +33,17 @@ ol.geom.LineString = function(coordinates, opt_layout) {
|
|||||||
this.setCoordinates(coordinates, opt_layout);
|
this.setCoordinates(coordinates, opt_layout);
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.geom.LineString, ol.geom.Geometry);
|
goog.inherits(ol.geom.LineString, ol.geom.SimpleGeometry);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.LineString.prototype.clone = function() {
|
||||||
|
var lineString = new ol.geom.LineString(null);
|
||||||
|
lineString.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
|
||||||
|
return lineString;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@exportSymbol ol.geom.MultiLineString
|
@exportSymbol ol.geom.MultiLineString
|
||||||
|
@exportProperty ol.geom.MultiLineString.prototype.clone
|
||||||
@exportProperty ol.geom.MultiLineString.prototype.getCoordinates
|
@exportProperty ol.geom.MultiLineString.prototype.getCoordinates
|
||||||
@exportProperty ol.geom.MultiLineString.prototype.getLineStrings
|
@exportProperty ol.geom.MultiLineString.prototype.getLineStrings
|
||||||
@exportProperty ol.geom.MultiLineString.prototype.getType
|
@exportProperty ol.geom.MultiLineString.prototype.getType
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
goog.provide('ol.geom.MultiLineString');
|
goog.provide('ol.geom.MultiLineString');
|
||||||
|
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.geom.Geometry');
|
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
|
goog.require('ol.geom.SimpleGeometry');
|
||||||
goog.require('ol.geom.closest');
|
goog.require('ol.geom.closest');
|
||||||
goog.require('ol.geom.flat');
|
goog.require('ol.geom.flat');
|
||||||
goog.require('ol.geom.simplify');
|
goog.require('ol.geom.simplify');
|
||||||
@@ -11,7 +11,7 @@ goog.require('ol.geom.simplify');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.geom.Geometry}
|
* @extends {ol.geom.SimpleGeometry}
|
||||||
* @param {ol.geom.RawMultiLineString} coordinates Coordinates.
|
* @param {ol.geom.RawMultiLineString} coordinates Coordinates.
|
||||||
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
||||||
*/
|
*/
|
||||||
@@ -40,7 +40,18 @@ ol.geom.MultiLineString = function(coordinates, opt_layout) {
|
|||||||
this.setCoordinates(coordinates, opt_layout);
|
this.setCoordinates(coordinates, opt_layout);
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.geom.MultiLineString, ol.geom.Geometry);
|
goog.inherits(ol.geom.MultiLineString, ol.geom.SimpleGeometry);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@exportSymbol ol.geom.MultiPoint
|
@exportSymbol ol.geom.MultiPoint
|
||||||
|
@exportProperty ol.geom.MultiPoint.prototype.clone
|
||||||
@exportProperty ol.geom.MultiPoint.prototype.getCoordinates
|
@exportProperty ol.geom.MultiPoint.prototype.getCoordinates
|
||||||
@exportProperty ol.geom.MultiPoint.prototype.getPoints
|
@exportProperty ol.geom.MultiPoint.prototype.getPoints
|
||||||
@exportProperty ol.geom.MultiPoint.prototype.getType
|
@exportProperty ol.geom.MultiPoint.prototype.getType
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
goog.provide('ol.geom.MultiPoint');
|
goog.provide('ol.geom.MultiPoint');
|
||||||
|
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.geom.Geometry');
|
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
|
goog.require('ol.geom.SimpleGeometry');
|
||||||
goog.require('ol.geom.flat');
|
goog.require('ol.geom.flat');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.geom.Geometry}
|
* @extends {ol.geom.SimpleGeometry}
|
||||||
* @param {ol.geom.RawMultiPoint} coordinates Coordinates.
|
* @param {ol.geom.RawMultiPoint} coordinates Coordinates.
|
||||||
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
||||||
*/
|
*/
|
||||||
@@ -17,7 +17,17 @@ ol.geom.MultiPoint = function(coordinates, opt_layout) {
|
|||||||
goog.base(this);
|
goog.base(this);
|
||||||
this.setCoordinates(coordinates, opt_layout);
|
this.setCoordinates(coordinates, opt_layout);
|
||||||
};
|
};
|
||||||
goog.inherits(ol.geom.MultiPoint, ol.geom.Geometry);
|
goog.inherits(ol.geom.MultiPoint, ol.geom.SimpleGeometry);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.MultiPoint.prototype.clone = function() {
|
||||||
|
var multiPoint = new ol.geom.MultiPoint(null);
|
||||||
|
multiPoint.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
|
||||||
|
return multiPoint;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@exportSymbol ol.geom.MultiPolygon
|
@exportSymbol ol.geom.MultiPolygon
|
||||||
|
@exportProperty ol.geom.MultiPolygon.prototype.clone
|
||||||
@exportProperty ol.geom.MultiPolygon.prototype.getArea
|
@exportProperty ol.geom.MultiPolygon.prototype.getArea
|
||||||
@exportProperty ol.geom.MultiPolygon.prototype.getCoordinates
|
@exportProperty ol.geom.MultiPolygon.prototype.getCoordinates
|
||||||
@exportProperty ol.geom.MultiPolygon.prototype.getPolygons
|
@exportProperty ol.geom.MultiPolygon.prototype.getPolygons
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
goog.provide('ol.geom.MultiPolygon');
|
goog.provide('ol.geom.MultiPolygon');
|
||||||
|
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.geom.Geometry');
|
|
||||||
goog.require('ol.geom.Polygon');
|
goog.require('ol.geom.Polygon');
|
||||||
|
goog.require('ol.geom.SimpleGeometry');
|
||||||
goog.require('ol.geom.closest');
|
goog.require('ol.geom.closest');
|
||||||
goog.require('ol.geom.flat');
|
goog.require('ol.geom.flat');
|
||||||
goog.require('ol.geom.simplify');
|
goog.require('ol.geom.simplify');
|
||||||
@@ -11,7 +11,7 @@ goog.require('ol.geom.simplify');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.geom.Geometry}
|
* @extends {ol.geom.SimpleGeometry}
|
||||||
* @param {ol.geom.RawMultiPolygon} coordinates Coordinates.
|
* @param {ol.geom.RawMultiPolygon} coordinates Coordinates.
|
||||||
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
||||||
*/
|
*/
|
||||||
@@ -52,7 +52,18 @@ ol.geom.MultiPolygon = function(coordinates, opt_layout) {
|
|||||||
this.setCoordinates(coordinates, opt_layout);
|
this.setCoordinates(coordinates, opt_layout);
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.geom.MultiPolygon, ol.geom.Geometry);
|
goog.inherits(ol.geom.MultiPolygon, ol.geom.SimpleGeometry);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.MultiPolygon.prototype.clone = function() {
|
||||||
|
var multiPolygon = new ol.geom.MultiPolygon(null);
|
||||||
|
multiPolygon.setFlatCoordinates(
|
||||||
|
this.layout, this.flatCoordinates.slice(), this.endss_.slice());
|
||||||
|
return multiPolygon;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@exportSymbol ol.geom.Point
|
@exportSymbol ol.geom.Point
|
||||||
|
@exportProperty ol.geom.Point.prototype.clone
|
||||||
@exportProperty ol.geom.Point.prototype.getCoordinates
|
@exportProperty ol.geom.Point.prototype.getCoordinates
|
||||||
@exportProperty ol.geom.Point.prototype.getType
|
@exportProperty ol.geom.Point.prototype.getType
|
||||||
@exportProperty ol.geom.Point.prototype.setCoordinates
|
@exportProperty ol.geom.Point.prototype.setCoordinates
|
||||||
|
|||||||
+13
-3
@@ -2,14 +2,14 @@ goog.provide('ol.geom.Point');
|
|||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.geom.Geometry');
|
goog.require('ol.geom.SimpleGeometry');
|
||||||
goog.require('ol.geom.flat');
|
goog.require('ol.geom.flat');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.geom.Geometry}
|
* @extends {ol.geom.SimpleGeometry}
|
||||||
* @param {ol.geom.RawPoint} coordinates Coordinates.
|
* @param {ol.geom.RawPoint} coordinates Coordinates.
|
||||||
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
||||||
*/
|
*/
|
||||||
@@ -17,7 +17,17 @@ ol.geom.Point = function(coordinates, opt_layout) {
|
|||||||
goog.base(this);
|
goog.base(this);
|
||||||
this.setCoordinates(coordinates, opt_layout);
|
this.setCoordinates(coordinates, opt_layout);
|
||||||
};
|
};
|
||||||
goog.inherits(ol.geom.Point, ol.geom.Geometry);
|
goog.inherits(ol.geom.Point, ol.geom.SimpleGeometry);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.Point.prototype.clone = function() {
|
||||||
|
var point = new ol.geom.Point(null);
|
||||||
|
point.setFlatCoordinates(this.layout, this.flatCoordinates.slice());
|
||||||
|
return point;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
@exportSymbol ol.geom.Polygon
|
@exportSymbol ol.geom.Polygon
|
||||||
|
@exportProperty ol.geom.Polygon.prototype.clone
|
||||||
@exportProperty ol.geom.Polygon.prototype.getArea
|
@exportProperty ol.geom.Polygon.prototype.getArea
|
||||||
@exportProperty ol.geom.Polygon.prototype.getCoordinates
|
@exportProperty ol.geom.Polygon.prototype.getCoordinates
|
||||||
@exportProperty ol.geom.Polygon.prototype.getLinearRings
|
@exportProperty ol.geom.Polygon.prototype.getLinearRings
|
||||||
|
|||||||
+14
-3
@@ -1,8 +1,8 @@
|
|||||||
goog.provide('ol.geom.Polygon');
|
goog.provide('ol.geom.Polygon');
|
||||||
|
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.geom.Geometry');
|
|
||||||
goog.require('ol.geom.LinearRing');
|
goog.require('ol.geom.LinearRing');
|
||||||
|
goog.require('ol.geom.SimpleGeometry');
|
||||||
goog.require('ol.geom.closest');
|
goog.require('ol.geom.closest');
|
||||||
goog.require('ol.geom.flat');
|
goog.require('ol.geom.flat');
|
||||||
goog.require('ol.geom.simplify');
|
goog.require('ol.geom.simplify');
|
||||||
@@ -11,7 +11,7 @@ goog.require('ol.geom.simplify');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.geom.Geometry}
|
* @extends {ol.geom.SimpleGeometry}
|
||||||
* @param {ol.geom.RawPolygon} coordinates Coordinates.
|
* @param {ol.geom.RawPolygon} coordinates Coordinates.
|
||||||
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
* @param {ol.geom.GeometryLayout=} opt_layout Layout.
|
||||||
*/
|
*/
|
||||||
@@ -52,7 +52,18 @@ ol.geom.Polygon = function(coordinates, opt_layout) {
|
|||||||
this.setCoordinates(coordinates, opt_layout);
|
this.setCoordinates(coordinates, opt_layout);
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.geom.Polygon, ol.geom.Geometry);
|
goog.inherits(ol.geom.Polygon, ol.geom.SimpleGeometry);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.Polygon.prototype.clone = function() {
|
||||||
|
var polygon = new ol.geom.Polygon(null);
|
||||||
|
polygon.setFlatCoordinates(
|
||||||
|
this.layout, this.flatCoordinates.slice(), this.ends_.slice());
|
||||||
|
return polygon;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
@exportSymbol ol.geom.SimpleGeometry
|
||||||
|
@exportProperty ol.geom.SimpleGeometry.prototype.getExtent
|
||||||
|
@exportProperty ol.geom.SimpleGeometry.prototype.getLayout
|
||||||
|
@exportProperty ol.geom.SimpleGeometry.prototype.getSimplifiedGeometry
|
||||||
|
@exportProperty ol.geom.SimpleGeometry.prototype.transform
|
||||||
@@ -0,0 +1,247 @@
|
|||||||
|
goog.provide('ol.geom.SimpleGeometry');
|
||||||
|
|
||||||
|
goog.require('goog.asserts');
|
||||||
|
goog.require('goog.functions');
|
||||||
|
goog.require('goog.object');
|
||||||
|
goog.require('ol.extent');
|
||||||
|
goog.require('ol.geom.Geometry');
|
||||||
|
goog.require('ol.geom.flat');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @extends {ol.geom.Geometry}
|
||||||
|
*/
|
||||||
|
ol.geom.SimpleGeometry = function() {
|
||||||
|
|
||||||
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @protected
|
||||||
|
* @type {ol.geom.GeometryLayout}
|
||||||
|
*/
|
||||||
|
this.layout = ol.geom.GeometryLayout.XY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @protected
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.stride = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @protected
|
||||||
|
* @type {Array.<number>}
|
||||||
|
*/
|
||||||
|
this.flatCoordinates = null;
|
||||||
|
|
||||||
|
};
|
||||||
|
goog.inherits(ol.geom.SimpleGeometry, ol.geom.Geometry);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} stride Stride.
|
||||||
|
* @private
|
||||||
|
* @return {ol.geom.GeometryLayout} layout Layout.
|
||||||
|
*/
|
||||||
|
ol.geom.SimpleGeometry.getLayoutForStride_ = function(stride) {
|
||||||
|
if (stride == 2) {
|
||||||
|
return ol.geom.GeometryLayout.XY;
|
||||||
|
} else if (stride == 3) {
|
||||||
|
return ol.geom.GeometryLayout.XYZ;
|
||||||
|
} else if (stride == 4) {
|
||||||
|
return ol.geom.GeometryLayout.XYZM;
|
||||||
|
} else {
|
||||||
|
throw new Error('unsupported stride: ' + stride);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.GeometryLayout} layout Layout.
|
||||||
|
* @private
|
||||||
|
* @return {number} Stride.
|
||||||
|
*/
|
||||||
|
ol.geom.SimpleGeometry.getStrideForLayout_ = function(layout) {
|
||||||
|
if (layout == ol.geom.GeometryLayout.XY) {
|
||||||
|
return 2;
|
||||||
|
} else if (layout == ol.geom.GeometryLayout.XYZ) {
|
||||||
|
return 3;
|
||||||
|
} else if (layout == ol.geom.GeometryLayout.XYM) {
|
||||||
|
return 3;
|
||||||
|
} else if (layout == ol.geom.GeometryLayout.XYZM) {
|
||||||
|
return 4;
|
||||||
|
} else {
|
||||||
|
throw new Error('unsupported layout: ' + layout);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.SimpleGeometry.prototype.containsXY = goog.functions.FALSE;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.SimpleGeometry.prototype.getExtent = function(opt_extent) {
|
||||||
|
if (this.extentRevision != this.revision) {
|
||||||
|
this.extent = ol.extent.createOrUpdateFromFlatCoordinates(
|
||||||
|
this.flatCoordinates, this.stride, this.extent);
|
||||||
|
this.extentRevision = this.revision;
|
||||||
|
}
|
||||||
|
goog.asserts.assert(goog.isDef(this.extent));
|
||||||
|
return ol.extent.returnOrUpdate(this.extent, opt_extent);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Array.<number>} Flat coordinates.
|
||||||
|
*/
|
||||||
|
ol.geom.SimpleGeometry.prototype.getFlatCoordinates = function() {
|
||||||
|
return this.flatCoordinates;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {ol.geom.GeometryLayout} Layout.
|
||||||
|
*/
|
||||||
|
ol.geom.SimpleGeometry.prototype.getLayout = function() {
|
||||||
|
return this.layout;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.SimpleGeometry.prototype.getSimplifiedGeometry =
|
||||||
|
function(squaredTolerance) {
|
||||||
|
if (this.simplifiedGeometryRevision != this.revision) {
|
||||||
|
goog.object.clear(this.simplifiedGeometryCache);
|
||||||
|
this.simplifiedGeometryMaxMinSquaredTolerance = 0;
|
||||||
|
this.simplifiedGeometryRevision = this.revision;
|
||||||
|
}
|
||||||
|
// If squaredTolerance is negative or if we know that simplification will not
|
||||||
|
// have any effect then just return this.
|
||||||
|
if (squaredTolerance < 0 ||
|
||||||
|
(this.simplifiedGeometryMaxMinSquaredTolerance !== 0 &&
|
||||||
|
squaredTolerance <= this.simplifiedGeometryMaxMinSquaredTolerance)) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
var key = squaredTolerance.toString();
|
||||||
|
if (this.simplifiedGeometryCache.hasOwnProperty(key)) {
|
||||||
|
return this.simplifiedGeometryCache[key];
|
||||||
|
} else {
|
||||||
|
var simplifiedGeometry =
|
||||||
|
this.getSimplifiedGeometryInternal(squaredTolerance);
|
||||||
|
var simplifiedFlatCoordinates = simplifiedGeometry.getFlatCoordinates();
|
||||||
|
if (simplifiedFlatCoordinates.length < this.flatCoordinates.length) {
|
||||||
|
this.simplifiedGeometryCache[key] = simplifiedGeometry;
|
||||||
|
return simplifiedGeometry;
|
||||||
|
} else {
|
||||||
|
// Simplification did not actually remove any coordinates. We now know
|
||||||
|
// that any calls to getSimplifiedGeometry with a squaredTolerance less
|
||||||
|
// than or equal to the current squaredTolerance will also not have any
|
||||||
|
// effect. This allows us to short circuit simplification (saving CPU
|
||||||
|
// cycles) and prevents the cache of simplified geometries from filling
|
||||||
|
// up with useless identical copies of this geometry (saving memory).
|
||||||
|
this.simplifiedGeometryMaxMinSquaredTolerance = squaredTolerance;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} squaredTolerance Squared tolerance.
|
||||||
|
* @return {ol.geom.SimpleGeometry} Simplified geometry.
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
ol.geom.SimpleGeometry.prototype.getSimplifiedGeometryInternal =
|
||||||
|
function(squaredTolerance) {
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {number} Stride.
|
||||||
|
*/
|
||||||
|
ol.geom.SimpleGeometry.prototype.getStride = function() {
|
||||||
|
return this.stride;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.GeometryLayout} layout Layout.
|
||||||
|
* @param {Array.<number>} flatCoordinates Flat coordinates.
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
ol.geom.SimpleGeometry.prototype.setFlatCoordinatesInternal =
|
||||||
|
function(layout, flatCoordinates) {
|
||||||
|
this.stride = ol.geom.SimpleGeometry.getStrideForLayout_(layout);
|
||||||
|
this.layout = layout;
|
||||||
|
this.flatCoordinates = flatCoordinates;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.GeometryLayout|undefined} layout Layout.
|
||||||
|
* @param {Array} coordinates Coordinates.
|
||||||
|
* @param {number} nesting Nesting.
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
ol.geom.SimpleGeometry.prototype.setLayout =
|
||||||
|
function(layout, coordinates, nesting) {
|
||||||
|
/** @type {number} */
|
||||||
|
var stride;
|
||||||
|
if (goog.isDef(layout)) {
|
||||||
|
stride = ol.geom.SimpleGeometry.getStrideForLayout_(layout);
|
||||||
|
} else {
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < nesting; ++i) {
|
||||||
|
if (coordinates.length === 0) {
|
||||||
|
this.layout = ol.geom.GeometryLayout.XY;
|
||||||
|
this.stride = 2;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
coordinates = /** @type {Array} */ (coordinates[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stride = (/** @type {Array} */ (coordinates)).length;
|
||||||
|
layout = ol.geom.SimpleGeometry.getLayoutForStride_(stride);
|
||||||
|
}
|
||||||
|
this.layout = layout;
|
||||||
|
this.stride = stride;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.geom.SimpleGeometry.prototype.transform = function(transformFn) {
|
||||||
|
if (!goog.isNull(this.flatCoordinates)) {
|
||||||
|
transformFn(this.flatCoordinates, this.flatCoordinates, this.stride);
|
||||||
|
this.dispatchChangeEvent();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.SimpleGeometry} simpleGeometry Simple geometry.
|
||||||
|
* @param {goog.vec.Mat4.AnyType} transform Transform.
|
||||||
|
* @param {Array.<number>=} opt_dest Destination.
|
||||||
|
* @return {Array.<number>} Transformed flat coordinates.
|
||||||
|
*/
|
||||||
|
ol.geom.transformSimpleGeometry2D =
|
||||||
|
function(simpleGeometry, transform, opt_dest) {
|
||||||
|
var flatCoordinates = simpleGeometry.getFlatCoordinates();
|
||||||
|
if (goog.isNull(flatCoordinates)) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
var stride = simpleGeometry.getStride();
|
||||||
|
return ol.geom.flat.transform2D(
|
||||||
|
flatCoordinates, stride, transform, opt_dest);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -113,7 +113,7 @@ ol.render.canvas.Immediate.prototype.drawImages_ = function(geometry) {
|
|||||||
goog.asserts.assert(goog.isDef(state.anchorY));
|
goog.asserts.assert(goog.isDef(state.anchorY));
|
||||||
goog.asserts.assert(goog.isDef(state.height));
|
goog.asserts.assert(goog.isDef(state.height));
|
||||||
goog.asserts.assert(goog.isDef(state.width));
|
goog.asserts.assert(goog.isDef(state.width));
|
||||||
var pixelCoordinates = ol.geom.transformGeometry2D(
|
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
|
||||||
geometry, this.transform_, this.pixelCoordinates_);
|
geometry, this.transform_, this.pixelCoordinates_);
|
||||||
var i, ii;
|
var i, ii;
|
||||||
for (i = 0, ii = pixelCoordinates.length; i < ii; i += 2) {
|
for (i = 0, ii = pixelCoordinates.length; i < ii; i += 2) {
|
||||||
@@ -144,7 +144,7 @@ ol.render.canvas.Immediate.prototype.drawText_ = function(geometry) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.setFillStrokeStyles_();
|
this.setFillStrokeStyles_();
|
||||||
var pixelCoordinates = ol.geom.transformGeometry2D(
|
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
|
||||||
geometry, this.transform_, this.pixelCoordinates_);
|
geometry, this.transform_, this.pixelCoordinates_);
|
||||||
var i, ii;
|
var i, ii;
|
||||||
for (i = 0, ii = pixelCoordinates.length; i < ii; i += 2) {
|
for (i = 0, ii = pixelCoordinates.length; i < ii; i += 2) {
|
||||||
@@ -220,6 +220,23 @@ ol.render.canvas.Immediate.prototype.drawFeature = function(feature, style) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.render.canvas.Immediate.prototype.drawGeometryCollectionGeometry =
|
||||||
|
function(geometryCollectionGeometry, data) {
|
||||||
|
var geometries = geometryCollectionGeometry.getGeometriesArray();
|
||||||
|
var i, ii;
|
||||||
|
for (i = 0, ii = geometries.length; i < ii; ++i) {
|
||||||
|
var geometry = geometries[i];
|
||||||
|
var geometryRenderer =
|
||||||
|
ol.render.canvas.Immediate.GEOMETRY_RENDERES_[geometry.getType()];
|
||||||
|
goog.asserts.assert(goog.isDef(geometryRenderer));
|
||||||
|
geometryRenderer.call(this, geometry, data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
@@ -251,7 +268,7 @@ ol.render.canvas.Immediate.prototype.drawLineStringGeometry =
|
|||||||
}
|
}
|
||||||
this.setFillStrokeStyles_();
|
this.setFillStrokeStyles_();
|
||||||
var context = this.context_;
|
var context = this.context_;
|
||||||
var pixelCoordinates = ol.geom.transformGeometry2D(
|
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
|
||||||
lineStringGeometry, this.transform_, this.pixelCoordinates_);
|
lineStringGeometry, this.transform_, this.pixelCoordinates_);
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
this.moveToLineTo_(pixelCoordinates, 0, pixelCoordinates.length, false);
|
this.moveToLineTo_(pixelCoordinates, 0, pixelCoordinates.length, false);
|
||||||
@@ -271,7 +288,7 @@ ol.render.canvas.Immediate.prototype.drawMultiLineStringGeometry =
|
|||||||
}
|
}
|
||||||
this.setFillStrokeStyles_();
|
this.setFillStrokeStyles_();
|
||||||
var context = this.context_;
|
var context = this.context_;
|
||||||
var pixelCoordinates = ol.geom.transformGeometry2D(
|
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
|
||||||
multiLineStringGeometry, this.transform_, this.pixelCoordinates_);
|
multiLineStringGeometry, this.transform_, this.pixelCoordinates_);
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
var ends = multiLineStringGeometry.getEnds();
|
var ends = multiLineStringGeometry.getEnds();
|
||||||
@@ -298,7 +315,7 @@ ol.render.canvas.Immediate.prototype.drawPolygonGeometry =
|
|||||||
}
|
}
|
||||||
this.setFillStrokeStyles_();
|
this.setFillStrokeStyles_();
|
||||||
var context = this.context_;
|
var context = this.context_;
|
||||||
var pixelCoordinates = ol.geom.transformGeometry2D(
|
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
|
||||||
polygonGeometry, this.transform_, this.pixelCoordinates_);
|
polygonGeometry, this.transform_, this.pixelCoordinates_);
|
||||||
var ends = polygonGeometry.getEnds();
|
var ends = polygonGeometry.getEnds();
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
@@ -327,7 +344,7 @@ ol.render.canvas.Immediate.prototype.drawMultiPolygonGeometry =
|
|||||||
}
|
}
|
||||||
this.setFillStrokeStyles_();
|
this.setFillStrokeStyles_();
|
||||||
var context = this.context_;
|
var context = this.context_;
|
||||||
var pixelCoordinates = ol.geom.transformGeometry2D(
|
var pixelCoordinates = ol.geom.transformSimpleGeometry2D(
|
||||||
multiPolygonGeometry, this.transform_, this.pixelCoordinates_);
|
multiPolygonGeometry, this.transform_, this.pixelCoordinates_);
|
||||||
var endss = multiPolygonGeometry.getEndss();
|
var endss = multiPolygonGeometry.getEndss();
|
||||||
var offset = 0;
|
var offset = 0;
|
||||||
@@ -478,5 +495,7 @@ ol.render.canvas.Immediate.GEOMETRY_RENDERES_ = {
|
|||||||
'MultiPoint': ol.render.canvas.Immediate.prototype.drawMultiPointGeometry,
|
'MultiPoint': ol.render.canvas.Immediate.prototype.drawMultiPointGeometry,
|
||||||
'MultiLineString':
|
'MultiLineString':
|
||||||
ol.render.canvas.Immediate.prototype.drawMultiLineStringGeometry,
|
ol.render.canvas.Immediate.prototype.drawMultiLineStringGeometry,
|
||||||
'MultiPolygon': ol.render.canvas.Immediate.prototype.drawMultiPolygonGeometry
|
'MultiPolygon': ol.render.canvas.Immediate.prototype.drawMultiPolygonGeometry,
|
||||||
|
'GeometryCollection':
|
||||||
|
ol.render.canvas.Immediate.prototype.drawGeometryCollectionGeometry
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -330,6 +330,13 @@ ol.render.canvas.Replay.prototype.reverseHitDetectionInstructions_ =
|
|||||||
ol.render.canvas.Replay.prototype.drawFeature = goog.abstractMethod;
|
ol.render.canvas.Replay.prototype.drawFeature = goog.abstractMethod;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.render.canvas.Replay.prototype.drawGeometryCollectionGeometry =
|
||||||
|
goog.abstractMethod;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// FIXME remove trailing "Geometry" in method names
|
||||||
|
|
||||||
goog.provide('ol.render.IRender');
|
goog.provide('ol.render.IRender');
|
||||||
|
|
||||||
|
|
||||||
@@ -17,6 +19,16 @@ ol.render.IRender.prototype.drawFeature = function(feature, style) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.GeometryCollection} geometryCollectionGeometry Geometry
|
||||||
|
* collection.
|
||||||
|
* @param {Object} data Opaque data object.
|
||||||
|
*/
|
||||||
|
ol.render.IRender.prototype.drawGeometryCollectionGeometry =
|
||||||
|
function(geometryCollectionGeometry, data) {
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.geom.Point} pointGeometry Point geometry.
|
* @param {ol.geom.Point} pointGeometry Point geometry.
|
||||||
* @param {Object} data Opaque data object.
|
* @param {Object} data Opaque data object.
|
||||||
|
|||||||
+26
-1
@@ -1,6 +1,7 @@
|
|||||||
goog.provide('ol.renderer.vector');
|
goog.provide('ol.renderer.vector');
|
||||||
|
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
|
goog.require('ol.geom.GeometryCollection');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.geom.MultiLineString');
|
goog.require('ol.geom.MultiLineString');
|
||||||
goog.require('ol.geom.MultiPoint');
|
goog.require('ol.geom.MultiPoint');
|
||||||
@@ -28,6 +29,29 @@ ol.renderer.vector.renderFeature = function(
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.render.IReplayGroup} replayGroup Replay group.
|
||||||
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {ol.style.Style} style Style.
|
||||||
|
* @param {Object} data Opaque data object.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.renderer.vector.renderGeometryCollectionGeometry_ =
|
||||||
|
function(replayGroup, geometry, style, data) {
|
||||||
|
goog.asserts.assertInstanceof(geometry, ol.geom.GeometryCollection);
|
||||||
|
var geometryCollectionGeometry = /** @type {ol.geom.GeometryCollection} */ (
|
||||||
|
geometry);
|
||||||
|
var geometries = geometryCollectionGeometry.getGeometriesArray();
|
||||||
|
var i, ii;
|
||||||
|
for (i = 0, ii = geometries.length; i < ii; ++i) {
|
||||||
|
var geometryRenderer =
|
||||||
|
ol.renderer.vector.GEOMETRY_RENDERERS_[geometries[i].getType()];
|
||||||
|
goog.asserts.assert(goog.isDef(geometryRenderer));
|
||||||
|
geometryRenderer(replayGroup, geometries[i], style, data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ol.render.IReplayGroup} replayGroup Replay group.
|
* @param {ol.render.IReplayGroup} replayGroup Replay group.
|
||||||
* @param {ol.geom.Geometry} geometry Geometry.
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
@@ -167,5 +191,6 @@ ol.renderer.vector.GEOMETRY_RENDERERS_ = {
|
|||||||
'Polygon': ol.renderer.vector.renderPolygonGeometry_,
|
'Polygon': ol.renderer.vector.renderPolygonGeometry_,
|
||||||
'MultiPoint': ol.renderer.vector.renderMultiPointGeometry_,
|
'MultiPoint': ol.renderer.vector.renderMultiPointGeometry_,
|
||||||
'MultiLineString': ol.renderer.vector.renderMultiLineStringGeometry_,
|
'MultiLineString': ol.renderer.vector.renderMultiLineStringGeometry_,
|
||||||
'MultiPolygon': ol.renderer.vector.renderMultiPolygonGeometry_
|
'MultiPolygon': ol.renderer.vector.renderMultiPolygonGeometry_,
|
||||||
|
'GeometryCollection': ol.renderer.vector.renderGeometryCollectionGeometry_
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ describe('ol.format.GeoJSON', function() {
|
|||||||
expect(rings[2]).to.be.a(ol.geom.LinearRing);
|
expect(rings[2]).to.be.a(ol.geom.LinearRing);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.skip('parses geometry collection', function() {
|
it('parses geometry collection', function() {
|
||||||
var str = JSON.stringify({
|
var str = JSON.stringify({
|
||||||
type: 'GeometryCollection',
|
type: 'GeometryCollection',
|
||||||
geometries: [
|
geometries: [
|
||||||
@@ -288,7 +288,9 @@ describe('ol.format.GeoJSON', function() {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
var array = format.readGeometry(str);
|
var geometryCollection = format.readGeometry(str);
|
||||||
|
expect(geometryCollection).to.be.an(ol.geom.GeometryCollection);
|
||||||
|
var array = geometryCollection.getGeometries();
|
||||||
expect(array.length).to.be(2);
|
expect(array.length).to.be(2);
|
||||||
expect(array[0]).to.be.a(ol.geom.Point);
|
expect(array[0]).to.be.a(ol.geom.Point);
|
||||||
expect(array[1]).to.be.a(ol.geom.LineString);
|
expect(array[1]).to.be.a(ol.geom.LineString);
|
||||||
@@ -441,17 +443,20 @@ describe('ol.format.GeoJSON', function() {
|
|||||||
format.readGeometry(geojson).getCoordinates());
|
format.readGeometry(geojson).getCoordinates());
|
||||||
});
|
});
|
||||||
|
|
||||||
it.skip('encodes geometry collection', function() {
|
it('encodes geometry collection', function() {
|
||||||
var collection = new ol.geom.GeometryCollection([
|
var collection = new ol.geom.GeometryCollection([
|
||||||
new ol.geom.Point([10, 20]),
|
new ol.geom.Point([10, 20]),
|
||||||
new ol.geom.LineString([[30, 40], [50, 60]])
|
new ol.geom.LineString([[30, 40], [50, 60]])
|
||||||
]);
|
]);
|
||||||
var geojson = format.writeGeometry(collection);
|
var geojson = format.writeGeometry(collection);
|
||||||
var got = format.readGeometry(geojson);
|
var got = format.readGeometry(geojson);
|
||||||
var components = collection.getComponents();
|
expect(got).to.be.an(ol.geom.GeometryCollection);
|
||||||
expect(components.length).to.equal(got.length);
|
var gotGeometries = got.getGeometries();
|
||||||
for (var i = 0, ii = components.length; i < ii; ++i) {
|
var geometries = collection.getGeometries();
|
||||||
expect(components[i].getCoordinates()).to.eql(got[i].getCoordinates());
|
expect(geometries.length).to.equal(gotGeometries.length);
|
||||||
|
for (var i = 0, ii = geometries.length; i < ii; ++i) {
|
||||||
|
expect(geometries[i].getCoordinates()).
|
||||||
|
to.eql(gotGeometries[i].getCoordinates());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -463,6 +468,7 @@ describe('ol.format.GeoJSON', function() {
|
|||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.format.GeoJSON');
|
goog.require('ol.format.GeoJSON');
|
||||||
|
goog.require('ol.geom.GeometryCollection');
|
||||||
goog.require('ol.geom.LineString');
|
goog.require('ol.geom.LineString');
|
||||||
goog.require('ol.geom.LinearRing');
|
goog.require('ol.geom.LinearRing');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
goog.provide('ol.test.geom.GeometryCollection');
|
||||||
|
|
||||||
|
|
||||||
|
describe('ol.geom.GeometryCollection', function() {
|
||||||
|
|
||||||
|
var outer = [[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]],
|
||||||
|
inner1 = [[1, 1], [2, 1], [2, 2], [1, 2], [1, 1]],
|
||||||
|
inner2 = [[8, 8], [9, 8], [9, 9], [8, 9], [8, 8]];
|
||||||
|
|
||||||
|
describe('constructor', function() {
|
||||||
|
|
||||||
|
it('creates a geometry collection from an array of geometries', function() {
|
||||||
|
var point = new ol.geom.Point([10, 20]);
|
||||||
|
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||||
|
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||||
|
var multi = new ol.geom.GeometryCollection([point, line, poly]);
|
||||||
|
expect(multi).to.be.a(ol.geom.GeometryCollection);
|
||||||
|
expect(multi).to.be.a(ol.geom.Geometry);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#getGeometries', function() {
|
||||||
|
|
||||||
|
it('returns a collection of geometries', function() {
|
||||||
|
var point = new ol.geom.Point([10, 20]);
|
||||||
|
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||||
|
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||||
|
var multi = new ol.geom.GeometryCollection([point, line, poly]);
|
||||||
|
|
||||||
|
var geometries = multi.getGeometries();
|
||||||
|
expect(geometries).to.be.an(Array);
|
||||||
|
expect(geometries).to.have.length(3);
|
||||||
|
expect(geometries[0]).to.be.a(ol.geom.Point);
|
||||||
|
expect(geometries[1]).to.be.a(ol.geom.LineString);
|
||||||
|
expect(geometries[2]).to.be.a(ol.geom.Polygon);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#clone()', function() {
|
||||||
|
|
||||||
|
it('has a working clone method', function() {
|
||||||
|
var point = new ol.geom.Point([10, 20]);
|
||||||
|
var line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||||
|
var poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||||
|
var multi = new ol.geom.GeometryCollection([point, line, poly]);
|
||||||
|
var clone = multi.clone();
|
||||||
|
expect(clone).to.not.be(multi);
|
||||||
|
var geometries = clone.getGeometries();
|
||||||
|
expect(geometries[0].getCoordinates()).to.eql([10, 20]);
|
||||||
|
expect(geometries[1].getCoordinates()).to.eql([[10, 20], [30, 40]]);
|
||||||
|
expect(geometries[2].getCoordinates()).to.eql([outer, inner1, inner2]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does a deep clone', function() {
|
||||||
|
var point = new ol.geom.Point([30, 40]);
|
||||||
|
var originalGeometries = [point];
|
||||||
|
var multi = new ol.geom.GeometryCollection(originalGeometries);
|
||||||
|
var clone = multi.clone();
|
||||||
|
var clonedGeometries = multi.getGeometries();
|
||||||
|
expect(clonedGeometries).not.to.be(originalGeometries);
|
||||||
|
expect(clonedGeometries).to.have.length(originalGeometries.length);
|
||||||
|
expect(clonedGeometries).to.have.length(1);
|
||||||
|
expect(clonedGeometries[0]).not.to.be(originalGeometries[0]);
|
||||||
|
expect(clonedGeometries[0].getCoordinates()).
|
||||||
|
to.eql(originalGeometries[0].getCoordinates());
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#getExtent()', function() {
|
||||||
|
|
||||||
|
it('returns the bounding extent', function() {
|
||||||
|
var point = new ol.geom.Point([10, 2]);
|
||||||
|
var line = new ol.geom.LineString([[1, 20], [30, 40]]);
|
||||||
|
var multi = new ol.geom.GeometryCollection([point, line]);
|
||||||
|
var extent = multi.getExtent();
|
||||||
|
expect(extent[0]).to.be(1);
|
||||||
|
expect(extent[2]).to.be(30);
|
||||||
|
expect(extent[1]).to.be(2);
|
||||||
|
expect(extent[3]).to.be(40);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#setGeometries', function() {
|
||||||
|
|
||||||
|
var line, multi, point, poly;
|
||||||
|
beforeEach(function() {
|
||||||
|
point = new ol.geom.Point([10, 20]);
|
||||||
|
line = new ol.geom.LineString([[10, 20], [30, 40]]);
|
||||||
|
poly = new ol.geom.Polygon([outer, inner1, inner2]);
|
||||||
|
multi = new ol.geom.GeometryCollection([point, line, poly]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fires a change event', function() {
|
||||||
|
var listener = sinon.spy();
|
||||||
|
multi.on('change', listener);
|
||||||
|
point.setCoordinates([15, 25]);
|
||||||
|
expect(listener.calledOnce).to.be(false);
|
||||||
|
multi.setGeometries([point, line, poly]);
|
||||||
|
expect(listener.calledOnce).to.be(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('updates the extent', function() {
|
||||||
|
expect(multi.getExtent()).to.eql([0, 0, 30, 40]);
|
||||||
|
line.setCoordinates([[10, 20], [300, 400]]);
|
||||||
|
expect(multi.getExtent()).to.eql([0, 0, 30, 40]);
|
||||||
|
multi.setGeometries([point, line, poly]);
|
||||||
|
expect(multi.getExtent()).to.eql([0, 0, 300, 400]);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
goog.require('ol.Collection');
|
||||||
|
goog.require('ol.geom.Geometry');
|
||||||
|
goog.require('ol.geom.GeometryCollection');
|
||||||
|
goog.require('ol.geom.LineString');
|
||||||
|
goog.require('ol.geom.Point');
|
||||||
|
goog.require('ol.geom.Polygon');
|
||||||
Reference in New Issue
Block a user