Automated class transform
npx lebab --replace src --transform class
This commit is contained in:
+136
-140
@@ -63,20 +63,148 @@ GEOMETRY_WRITERS[GeometryType.MULTI_POLYGON] = writeMultiPolygonGeometry;
|
||||
* @param {module:ol/format/EsriJSON~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const EsriJSON = function(opt_options) {
|
||||
class EsriJSON {
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
JSONFeature.call(this);
|
||||
JSONFeature.call(this);
|
||||
|
||||
/**
|
||||
* Name of the geometry attribute for features.
|
||||
* @type {string|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.geometryName_ = options.geometryName;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the geometry attribute for features.
|
||||
* @type {string|undefined}
|
||||
* @private
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.geometryName_ = options.geometryName;
|
||||
readFeatureFromObject(object, opt_options) {
|
||||
const esriJSONFeature = /** @type {EsriJSONFeature} */ (object);
|
||||
const geometry = readGeometry(esriJSONFeature.geometry, opt_options);
|
||||
const feature = new Feature();
|
||||
if (this.geometryName_) {
|
||||
feature.setGeometryName(this.geometryName_);
|
||||
}
|
||||
feature.setGeometry(geometry);
|
||||
if (opt_options && opt_options.idField &&
|
||||
esriJSONFeature.attributes[opt_options.idField]) {
|
||||
feature.setId(/** @type {number} */(esriJSONFeature.attributes[opt_options.idField]));
|
||||
}
|
||||
if (esriJSONFeature.attributes) {
|
||||
feature.setProperties(esriJSONFeature.attributes);
|
||||
}
|
||||
return feature;
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readFeaturesFromObject(object, opt_options) {
|
||||
const esriJSONObject = /** @type {EsriJSONObject} */ (object);
|
||||
const options = opt_options ? opt_options : {};
|
||||
if (esriJSONObject.features) {
|
||||
const esriJSONFeatureCollection = /** @type {EsriJSONFeatureCollection} */ (object);
|
||||
/** @type {Array.<module:ol/Feature>} */
|
||||
const features = [];
|
||||
const esriJSONFeatures = esriJSONFeatureCollection.features;
|
||||
options.idField = object.objectIdFieldName;
|
||||
for (let i = 0, ii = esriJSONFeatures.length; i < ii; ++i) {
|
||||
features.push(this.readFeatureFromObject(esriJSONFeatures[i], options));
|
||||
}
|
||||
return features;
|
||||
} else {
|
||||
return [this.readFeatureFromObject(object, options)];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readGeometryFromObject(object, opt_options) {
|
||||
return readGeometry(/** @type {EsriJSONGeometry} */(object), opt_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readProjectionFromObject(object) {
|
||||
const esriJSONObject = /** @type {EsriJSONObject} */ (object);
|
||||
if (esriJSONObject.spatialReference && esriJSONObject.spatialReference.wkid) {
|
||||
const crs = esriJSONObject.spatialReference.wkid;
|
||||
return getProjection('EPSG:' + crs);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a geometry as a EsriJSON object.
|
||||
*
|
||||
* @param {module:ol/geom/Geometry} geometry Geometry.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {EsriJSONGeometry} Object.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
writeGeometryObject(geometry, opt_options) {
|
||||
return writeGeometry(geometry, this.adaptOptions(opt_options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a feature as a esriJSON Feature object.
|
||||
*
|
||||
* @param {module:ol/Feature} feature Feature.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {Object} Object.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
writeFeatureObject(feature, opt_options) {
|
||||
opt_options = this.adaptOptions(opt_options);
|
||||
const object = {};
|
||||
const geometry = feature.getGeometry();
|
||||
if (geometry) {
|
||||
object['geometry'] = writeGeometry(geometry, opt_options);
|
||||
if (opt_options && opt_options.featureProjection) {
|
||||
object['geometry']['spatialReference'] = /** @type {EsriJSONCRS} */({
|
||||
wkid: getProjection(opt_options.featureProjection).getCode().split(':').pop()
|
||||
});
|
||||
}
|
||||
}
|
||||
const properties = feature.getProperties();
|
||||
delete properties[feature.getGeometryName()];
|
||||
if (!isEmpty(properties)) {
|
||||
object['attributes'] = properties;
|
||||
} else {
|
||||
object['attributes'] = {};
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode an array of features as a EsriJSON object.
|
||||
*
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {Object} EsriJSON Object.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
writeFeaturesObject(features, opt_options) {
|
||||
opt_options = this.adaptOptions(opt_options);
|
||||
const objects = [];
|
||||
for (let i = 0, ii = features.length; i < ii; ++i) {
|
||||
objects.push(this.writeFeatureObject(features[i], opt_options));
|
||||
}
|
||||
return /** @type {EsriJSONFeatureCollection} */ ({
|
||||
'features': objects
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
inherits(EsriJSON, JSONFeature);
|
||||
|
||||
@@ -439,50 +567,6 @@ EsriJSON.prototype.readFeature;
|
||||
EsriJSON.prototype.readFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
EsriJSON.prototype.readFeatureFromObject = function(object, opt_options) {
|
||||
const esriJSONFeature = /** @type {EsriJSONFeature} */ (object);
|
||||
const geometry = readGeometry(esriJSONFeature.geometry, opt_options);
|
||||
const feature = new Feature();
|
||||
if (this.geometryName_) {
|
||||
feature.setGeometryName(this.geometryName_);
|
||||
}
|
||||
feature.setGeometry(geometry);
|
||||
if (opt_options && opt_options.idField &&
|
||||
esriJSONFeature.attributes[opt_options.idField]) {
|
||||
feature.setId(/** @type {number} */(esriJSONFeature.attributes[opt_options.idField]));
|
||||
}
|
||||
if (esriJSONFeature.attributes) {
|
||||
feature.setProperties(esriJSONFeature.attributes);
|
||||
}
|
||||
return feature;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
EsriJSON.prototype.readFeaturesFromObject = function(object, opt_options) {
|
||||
const esriJSONObject = /** @type {EsriJSONObject} */ (object);
|
||||
const options = opt_options ? opt_options : {};
|
||||
if (esriJSONObject.features) {
|
||||
const esriJSONFeatureCollection = /** @type {EsriJSONFeatureCollection} */ (object);
|
||||
/** @type {Array.<module:ol/Feature>} */
|
||||
const features = [];
|
||||
const esriJSONFeatures = esriJSONFeatureCollection.features;
|
||||
options.idField = object.objectIdFieldName;
|
||||
for (let i = 0, ii = esriJSONFeatures.length; i < ii; ++i) {
|
||||
features.push(this.readFeatureFromObject(esriJSONFeatures[i], options));
|
||||
}
|
||||
return features;
|
||||
} else {
|
||||
return [this.readFeatureFromObject(object, options)];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read a geometry from a EsriJSON source.
|
||||
*
|
||||
@@ -495,14 +579,6 @@ EsriJSON.prototype.readFeaturesFromObject = function(object, opt_options) {
|
||||
EsriJSON.prototype.readGeometry;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
EsriJSON.prototype.readGeometryFromObject = function(object, opt_options) {
|
||||
return readGeometry(/** @type {EsriJSONGeometry} */(object), opt_options);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the projection from a EsriJSON source.
|
||||
*
|
||||
@@ -514,20 +590,6 @@ EsriJSON.prototype.readGeometryFromObject = function(object, opt_options) {
|
||||
EsriJSON.prototype.readProjection;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
EsriJSON.prototype.readProjectionFromObject = function(object) {
|
||||
const esriJSONObject = /** @type {EsriJSONObject} */ (object);
|
||||
if (esriJSONObject.spatialReference && esriJSONObject.spatialReference.wkid) {
|
||||
const crs = esriJSONObject.spatialReference.wkid;
|
||||
return getProjection('EPSG:' + crs);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/geom/Geometry} geometry Geometry.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
@@ -552,20 +614,6 @@ function writeGeometry(geometry, opt_options) {
|
||||
EsriJSON.prototype.writeGeometry;
|
||||
|
||||
|
||||
/**
|
||||
* Encode a geometry as a EsriJSON object.
|
||||
*
|
||||
* @param {module:ol/geom/Geometry} geometry Geometry.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {EsriJSONGeometry} Object.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
EsriJSON.prototype.writeGeometryObject = function(geometry, opt_options) {
|
||||
return writeGeometry(geometry, this.adaptOptions(opt_options));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode a feature as a EsriJSON Feature string.
|
||||
*
|
||||
@@ -578,38 +626,6 @@ EsriJSON.prototype.writeGeometryObject = function(geometry, opt_options) {
|
||||
EsriJSON.prototype.writeFeature;
|
||||
|
||||
|
||||
/**
|
||||
* Encode a feature as a esriJSON Feature object.
|
||||
*
|
||||
* @param {module:ol/Feature} feature Feature.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {Object} Object.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
EsriJSON.prototype.writeFeatureObject = function(feature, opt_options) {
|
||||
opt_options = this.adaptOptions(opt_options);
|
||||
const object = {};
|
||||
const geometry = feature.getGeometry();
|
||||
if (geometry) {
|
||||
object['geometry'] = writeGeometry(geometry, opt_options);
|
||||
if (opt_options && opt_options.featureProjection) {
|
||||
object['geometry']['spatialReference'] = /** @type {EsriJSONCRS} */({
|
||||
wkid: getProjection(opt_options.featureProjection).getCode().split(':').pop()
|
||||
});
|
||||
}
|
||||
}
|
||||
const properties = feature.getProperties();
|
||||
delete properties[feature.getGeometryName()];
|
||||
if (!isEmpty(properties)) {
|
||||
object['attributes'] = properties;
|
||||
} else {
|
||||
object['attributes'] = {};
|
||||
}
|
||||
return object;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode an array of features as EsriJSON.
|
||||
*
|
||||
@@ -622,24 +638,4 @@ EsriJSON.prototype.writeFeatureObject = function(feature, opt_options) {
|
||||
EsriJSON.prototype.writeFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* Encode an array of features as a EsriJSON object.
|
||||
*
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {Object} EsriJSON Object.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
EsriJSON.prototype.writeFeaturesObject = function(features, opt_options) {
|
||||
opt_options = this.adaptOptions(opt_options);
|
||||
const objects = [];
|
||||
for (let i = 0, ii = features.length; i < ii; ++i) {
|
||||
objects.push(this.writeFeatureObject(features[i], opt_options));
|
||||
}
|
||||
return /** @type {EsriJSONFeatureCollection} */ ({
|
||||
'features': objects
|
||||
});
|
||||
};
|
||||
|
||||
export default EsriJSON;
|
||||
|
||||
+121
-130
@@ -60,150 +60,141 @@ import {get as getProjection, equivalent as equivalentProjection, transformExten
|
||||
* @abstract
|
||||
* @api
|
||||
*/
|
||||
const FeatureFormat = function() {
|
||||
class FeatureFormat {
|
||||
constructor() {
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {module:ol/proj/Projection}
|
||||
*/
|
||||
this.dataProjection = null;
|
||||
/**
|
||||
* @protected
|
||||
* @type {module:ol/proj/Projection}
|
||||
*/
|
||||
this.dataProjection = null;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {module:ol/proj/Projection}
|
||||
*/
|
||||
this.defaultFeatureProjection = null;
|
||||
/**
|
||||
* @protected
|
||||
* @type {module:ol/proj/Projection}
|
||||
*/
|
||||
this.defaultFeatureProjection = null;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the data projection to the read options.
|
||||
* @param {Document|Node|Object|string} source Source.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
|
||||
* @return {module:ol/format/Feature~ReadOptions|undefined} Options.
|
||||
* @protected
|
||||
*/
|
||||
getReadOptions(source, opt_options) {
|
||||
let options;
|
||||
if (opt_options) {
|
||||
options = {
|
||||
dataProjection: opt_options.dataProjection ?
|
||||
opt_options.dataProjection : this.readProjection(source),
|
||||
featureProjection: opt_options.featureProjection
|
||||
};
|
||||
}
|
||||
return this.adaptOptions(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the data projection to the read options.
|
||||
* @param {Document|Node|Object|string} source Source.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
|
||||
* @return {module:ol/format/Feature~ReadOptions|undefined} Options.
|
||||
* @protected
|
||||
*/
|
||||
FeatureFormat.prototype.getReadOptions = function(source, opt_options) {
|
||||
let options;
|
||||
if (opt_options) {
|
||||
options = {
|
||||
dataProjection: opt_options.dataProjection ?
|
||||
opt_options.dataProjection : this.readProjection(source),
|
||||
featureProjection: opt_options.featureProjection
|
||||
};
|
||||
}
|
||||
return this.adaptOptions(options);
|
||||
};
|
||||
/**
|
||||
* Sets the `dataProjection` on the options, if no `dataProjection`
|
||||
* is set.
|
||||
* @param {module:ol/format/Feature~WriteOptions|module:ol/format/Feature~ReadOptions|undefined} options
|
||||
* Options.
|
||||
* @protected
|
||||
* @return {module:ol/format/Feature~WriteOptions|module:ol/format/Feature~ReadOptions|undefined}
|
||||
* Updated options.
|
||||
*/
|
||||
adaptOptions(options) {
|
||||
return assign({
|
||||
dataProjection: this.dataProjection,
|
||||
featureProjection: this.defaultFeatureProjection
|
||||
}, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extent from the source of the last {@link readFeatures} call.
|
||||
* @return {module:ol/extent~Extent} Tile extent.
|
||||
*/
|
||||
getLastExtent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the `dataProjection` on the options, if no `dataProjection`
|
||||
* is set.
|
||||
* @param {module:ol/format/Feature~WriteOptions|module:ol/format/Feature~ReadOptions|undefined} options
|
||||
* Options.
|
||||
* @protected
|
||||
* @return {module:ol/format/Feature~WriteOptions|module:ol/format/Feature~ReadOptions|undefined}
|
||||
* Updated options.
|
||||
*/
|
||||
FeatureFormat.prototype.adaptOptions = function(options) {
|
||||
return assign({
|
||||
dataProjection: this.dataProjection,
|
||||
featureProjection: this.defaultFeatureProjection
|
||||
}, options);
|
||||
};
|
||||
/**
|
||||
* @abstract
|
||||
* @return {module:ol/format/FormatType} Format.
|
||||
*/
|
||||
getType() {}
|
||||
|
||||
/**
|
||||
* Read a single feature from a source.
|
||||
*
|
||||
* @abstract
|
||||
* @param {Document|Node|Object|string} source Source.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @return {module:ol/Feature} Feature.
|
||||
*/
|
||||
readFeature(source, opt_options) {}
|
||||
|
||||
/**
|
||||
* Get the extent from the source of the last {@link readFeatures} call.
|
||||
* @return {module:ol/extent~Extent} Tile extent.
|
||||
*/
|
||||
FeatureFormat.prototype.getLastExtent = function() {
|
||||
return null;
|
||||
};
|
||||
/**
|
||||
* Read all features from a source.
|
||||
*
|
||||
* @abstract
|
||||
* @param {Document|Node|ArrayBuffer|Object|string} source Source.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @return {Array.<module:ol/Feature>} Features.
|
||||
*/
|
||||
readFeatures(source, opt_options) {}
|
||||
|
||||
/**
|
||||
* Read a single geometry from a source.
|
||||
*
|
||||
* @abstract
|
||||
* @param {Document|Node|Object|string} source Source.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @return {module:ol/geom/Geometry} Geometry.
|
||||
*/
|
||||
readGeometry(source, opt_options) {}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @return {module:ol/format/FormatType} Format.
|
||||
*/
|
||||
FeatureFormat.prototype.getType = function() {};
|
||||
/**
|
||||
* Read the projection from a source.
|
||||
*
|
||||
* @abstract
|
||||
* @param {Document|Node|Object|string} source Source.
|
||||
* @return {module:ol/proj/Projection} Projection.
|
||||
*/
|
||||
readProjection(source) {}
|
||||
|
||||
/**
|
||||
* Encode a feature in this format.
|
||||
*
|
||||
* @abstract
|
||||
* @param {module:ol/Feature} feature Feature.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {string} Result.
|
||||
*/
|
||||
writeFeature(feature, opt_options) {}
|
||||
|
||||
/**
|
||||
* Read a single feature from a source.
|
||||
*
|
||||
* @abstract
|
||||
* @param {Document|Node|Object|string} source Source.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @return {module:ol/Feature} Feature.
|
||||
*/
|
||||
FeatureFormat.prototype.readFeature = function(source, opt_options) {};
|
||||
/**
|
||||
* Encode an array of features in this format.
|
||||
*
|
||||
* @abstract
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {string} Result.
|
||||
*/
|
||||
writeFeatures(features, opt_options) {}
|
||||
|
||||
|
||||
/**
|
||||
* Read all features from a source.
|
||||
*
|
||||
* @abstract
|
||||
* @param {Document|Node|ArrayBuffer|Object|string} source Source.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @return {Array.<module:ol/Feature>} Features.
|
||||
*/
|
||||
FeatureFormat.prototype.readFeatures = function(source, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* Read a single geometry from a source.
|
||||
*
|
||||
* @abstract
|
||||
* @param {Document|Node|Object|string} source Source.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @return {module:ol/geom/Geometry} Geometry.
|
||||
*/
|
||||
FeatureFormat.prototype.readGeometry = function(source, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* Read the projection from a source.
|
||||
*
|
||||
* @abstract
|
||||
* @param {Document|Node|Object|string} source Source.
|
||||
* @return {module:ol/proj/Projection} Projection.
|
||||
*/
|
||||
FeatureFormat.prototype.readProjection = function(source) {};
|
||||
|
||||
|
||||
/**
|
||||
* Encode a feature in this format.
|
||||
*
|
||||
* @abstract
|
||||
* @param {module:ol/Feature} feature Feature.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {string} Result.
|
||||
*/
|
||||
FeatureFormat.prototype.writeFeature = function(feature, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* Encode an array of features in this format.
|
||||
*
|
||||
* @abstract
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {string} Result.
|
||||
*/
|
||||
FeatureFormat.prototype.writeFeatures = function(features, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* Write a single geometry in this format.
|
||||
*
|
||||
* @abstract
|
||||
* @param {module:ol/geom/Geometry} geometry Geometry.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {string} Result.
|
||||
*/
|
||||
FeatureFormat.prototype.writeGeometry = function(geometry, opt_options) {};
|
||||
/**
|
||||
* Write a single geometry in this format.
|
||||
*
|
||||
* @abstract
|
||||
* @param {module:ol/geom/Geometry} geometry Geometry.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {string} Result.
|
||||
*/
|
||||
writeGeometry(geometry, opt_options) {}
|
||||
}
|
||||
|
||||
export default FeatureFormat;
|
||||
|
||||
|
||||
+514
-538
File diff suppressed because it is too large
Load Diff
+842
-880
File diff suppressed because it is too large
Load Diff
+363
-377
@@ -75,44 +75,385 @@ export const GMLNS = 'http://www.opengis.net/gml';
|
||||
* Optional configuration object.
|
||||
* @extends {module:ol/format/XMLFeature}
|
||||
*/
|
||||
const GMLBase = function(opt_options) {
|
||||
const options = /** @type {module:ol/format/GMLBase~Options} */ (opt_options ? opt_options : {});
|
||||
class GMLBase {
|
||||
constructor(opt_options) {
|
||||
const options = /** @type {module:ol/format/GMLBase~Options} */ (opt_options ? opt_options : {});
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {Array.<string>|string|undefined}
|
||||
*/
|
||||
this.featureType = options.featureType;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {Object.<string, string>|string|undefined}
|
||||
*/
|
||||
this.featureNS = options.featureNS;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {string}
|
||||
*/
|
||||
this.srsName = options.srsName;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {string}
|
||||
*/
|
||||
this.schemaLocation = '';
|
||||
|
||||
/**
|
||||
* @type {Object.<string, Object.<string, Object>>}
|
||||
*/
|
||||
this.FEATURE_COLLECTION_PARSERS = {};
|
||||
this.FEATURE_COLLECTION_PARSERS[GMLNS] = {
|
||||
'featureMember': makeReplacer(GMLBase.prototype.readFeaturesInternal),
|
||||
'featureMembers': makeReplacer(GMLBase.prototype.readFeaturesInternal)
|
||||
};
|
||||
|
||||
XMLFeature.call(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {Array.<string>|string|undefined}
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {Array.<module:ol/Feature> | undefined} Features.
|
||||
*/
|
||||
this.featureType = options.featureType;
|
||||
readFeaturesInternal(node, objectStack) {
|
||||
const localName = node.localName;
|
||||
let features = null;
|
||||
if (localName == 'FeatureCollection') {
|
||||
if (node.namespaceURI === 'http://www.opengis.net/wfs') {
|
||||
features = pushParseAndPop([],
|
||||
this.FEATURE_COLLECTION_PARSERS, node,
|
||||
objectStack, this);
|
||||
} else {
|
||||
features = pushParseAndPop(null,
|
||||
this.FEATURE_COLLECTION_PARSERS, node,
|
||||
objectStack, this);
|
||||
}
|
||||
} else if (localName == 'featureMembers' || localName == 'featureMember') {
|
||||
const context = objectStack[0];
|
||||
let featureType = context['featureType'];
|
||||
let featureNS = context['featureNS'];
|
||||
const prefix = 'p';
|
||||
const defaultPrefix = 'p0';
|
||||
if (!featureType && node.childNodes) {
|
||||
featureType = [], featureNS = {};
|
||||
for (let i = 0, ii = node.childNodes.length; i < ii; ++i) {
|
||||
const child = node.childNodes[i];
|
||||
if (child.nodeType === 1) {
|
||||
const ft = child.nodeName.split(':').pop();
|
||||
if (featureType.indexOf(ft) === -1) {
|
||||
let key = '';
|
||||
let count = 0;
|
||||
const uri = child.namespaceURI;
|
||||
for (const candidate in featureNS) {
|
||||
if (featureNS[candidate] === uri) {
|
||||
key = candidate;
|
||||
break;
|
||||
}
|
||||
++count;
|
||||
}
|
||||
if (!key) {
|
||||
key = prefix + count;
|
||||
featureNS[key] = uri;
|
||||
}
|
||||
featureType.push(key + ':' + ft);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (localName != 'featureMember') {
|
||||
// recheck featureType for each featureMember
|
||||
context['featureType'] = featureType;
|
||||
context['featureNS'] = featureNS;
|
||||
}
|
||||
}
|
||||
if (typeof featureNS === 'string') {
|
||||
const ns = featureNS;
|
||||
featureNS = {};
|
||||
featureNS[defaultPrefix] = ns;
|
||||
}
|
||||
const parsersNS = {};
|
||||
const featureTypes = Array.isArray(featureType) ? featureType : [featureType];
|
||||
for (const p in featureNS) {
|
||||
const parsers = {};
|
||||
for (let i = 0, ii = featureTypes.length; i < ii; ++i) {
|
||||
const featurePrefix = featureTypes[i].indexOf(':') === -1 ?
|
||||
defaultPrefix : featureTypes[i].split(':')[0];
|
||||
if (featurePrefix === p) {
|
||||
parsers[featureTypes[i].split(':').pop()] =
|
||||
(localName == 'featureMembers') ?
|
||||
makeArrayPusher(this.readFeatureElement, this) :
|
||||
makeReplacer(this.readFeatureElement, this);
|
||||
}
|
||||
}
|
||||
parsersNS[featureNS[p]] = parsers;
|
||||
}
|
||||
if (localName == 'featureMember') {
|
||||
features = pushParseAndPop(undefined, parsersNS, node, objectStack);
|
||||
} else {
|
||||
features = pushParseAndPop([], parsersNS, node, objectStack);
|
||||
}
|
||||
}
|
||||
if (features === null) {
|
||||
features = [];
|
||||
}
|
||||
return features;
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {Object.<string, string>|string|undefined}
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/Geometry|undefined} Geometry.
|
||||
*/
|
||||
this.featureNS = options.featureNS;
|
||||
readGeometryElement(node, objectStack) {
|
||||
const context = /** @type {Object} */ (objectStack[0]);
|
||||
context['srsName'] = node.firstElementChild.getAttribute('srsName');
|
||||
context['srsDimension'] = node.firstElementChild.getAttribute('srsDimension');
|
||||
/** @type {module:ol/geom/Geometry} */
|
||||
const geometry = pushParseAndPop(null, this.GEOMETRY_PARSERS_, node, objectStack, this);
|
||||
if (geometry) {
|
||||
return (
|
||||
/** @type {module:ol/geom/Geometry} */ (transformWithOptions(geometry, false, context))
|
||||
);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {string}
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/Feature} Feature.
|
||||
*/
|
||||
this.srsName = options.srsName;
|
||||
readFeatureElement(node, objectStack) {
|
||||
let n;
|
||||
const fid = node.getAttribute('fid') || getAttributeNS(node, GMLNS, 'id');
|
||||
const values = {};
|
||||
let geometryName;
|
||||
for (n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
const localName = n.localName;
|
||||
// Assume attribute elements have one child node and that the child
|
||||
// is a text or CDATA node (to be treated as text).
|
||||
// Otherwise assume it is a geometry node.
|
||||
if (n.childNodes.length === 0 ||
|
||||
(n.childNodes.length === 1 &&
|
||||
(n.firstChild.nodeType === 3 || n.firstChild.nodeType === 4))) {
|
||||
let value = getAllTextContent(n, false);
|
||||
if (ONLY_WHITESPACE_RE.test(value)) {
|
||||
value = undefined;
|
||||
}
|
||||
values[localName] = value;
|
||||
} else {
|
||||
// boundedBy is an extent and must not be considered as a geometry
|
||||
if (localName !== 'boundedBy') {
|
||||
geometryName = localName;
|
||||
}
|
||||
values[localName] = this.readGeometryElement(n, objectStack);
|
||||
}
|
||||
}
|
||||
const feature = new Feature(values);
|
||||
if (geometryName) {
|
||||
feature.setGeometryName(geometryName);
|
||||
}
|
||||
if (fid) {
|
||||
feature.setId(fid);
|
||||
}
|
||||
return feature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {string}
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/Point|undefined} Point.
|
||||
*/
|
||||
this.schemaLocation = '';
|
||||
readPoint(node, objectStack) {
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
|
||||
if (flatCoordinates) {
|
||||
return new Point(flatCoordinates, GeometryLayout.XYZ);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Object.<string, Object.<string, Object>>}
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/MultiPoint|undefined} MultiPoint.
|
||||
*/
|
||||
this.FEATURE_COLLECTION_PARSERS = {};
|
||||
this.FEATURE_COLLECTION_PARSERS[GMLNS] = {
|
||||
'featureMember': makeReplacer(GMLBase.prototype.readFeaturesInternal),
|
||||
'featureMembers': makeReplacer(GMLBase.prototype.readFeaturesInternal)
|
||||
};
|
||||
readMultiPoint(node, objectStack) {
|
||||
/** @type {Array.<Array.<number>>} */
|
||||
const coordinates = pushParseAndPop([],
|
||||
this.MULTIPOINT_PARSERS_, node, objectStack, this);
|
||||
if (coordinates) {
|
||||
return new MultiPoint(coordinates);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
XMLFeature.call(this);
|
||||
};
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/MultiLineString|undefined} MultiLineString.
|
||||
*/
|
||||
readMultiLineString(node, objectStack) {
|
||||
/** @type {Array.<module:ol/geom/LineString>} */
|
||||
const lineStrings = pushParseAndPop([],
|
||||
this.MULTILINESTRING_PARSERS_, node, objectStack, this);
|
||||
if (lineStrings) {
|
||||
return new MultiLineString(lineStrings);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/MultiPolygon|undefined} MultiPolygon.
|
||||
*/
|
||||
readMultiPolygon(node, objectStack) {
|
||||
/** @type {Array.<module:ol/geom/Polygon>} */
|
||||
const polygons = pushParseAndPop([], this.MULTIPOLYGON_PARSERS_, node, objectStack, this);
|
||||
if (polygons) {
|
||||
return new MultiPolygon(polygons);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
*/
|
||||
pointMemberParser_(node, objectStack) {
|
||||
parseNode(this.POINTMEMBER_PARSERS_, node, objectStack, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
*/
|
||||
lineStringMemberParser_(node, objectStack) {
|
||||
parseNode(this.LINESTRINGMEMBER_PARSERS_, node, objectStack, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
*/
|
||||
polygonMemberParser_(node, objectStack) {
|
||||
parseNode(this.POLYGONMEMBER_PARSERS_, node, objectStack, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/LineString|undefined} LineString.
|
||||
*/
|
||||
readLineString(node, objectStack) {
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
|
||||
if (flatCoordinates) {
|
||||
const lineString = new LineString(flatCoordinates, GeometryLayout.XYZ);
|
||||
return lineString;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
* @return {Array.<number>|undefined} LinearRing flat coordinates.
|
||||
*/
|
||||
readFlatLinearRing_(node, objectStack) {
|
||||
const ring = pushParseAndPop(null,
|
||||
this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node,
|
||||
objectStack, this);
|
||||
if (ring) {
|
||||
return ring;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/LinearRing|undefined} LinearRing.
|
||||
*/
|
||||
readLinearRing(node, objectStack) {
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
|
||||
if (flatCoordinates) {
|
||||
return new LinearRing(flatCoordinates, GeometryLayout.XYZ);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/Polygon|undefined} Polygon.
|
||||
*/
|
||||
readPolygon(node, objectStack) {
|
||||
/** @type {Array.<Array.<number>>} */
|
||||
const flatLinearRings = pushParseAndPop([null],
|
||||
this.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this);
|
||||
if (flatLinearRings && flatLinearRings[0]) {
|
||||
const flatCoordinates = flatLinearRings[0];
|
||||
const ends = [flatCoordinates.length];
|
||||
let i, ii;
|
||||
for (i = 1, ii = flatLinearRings.length; i < ii; ++i) {
|
||||
extend(flatCoordinates, flatLinearRings[i]);
|
||||
ends.push(flatCoordinates.length);
|
||||
}
|
||||
return new Polygon(flatCoordinates, GeometryLayout.XYZ, ends);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
* @return {Array.<number>} Flat coordinates.
|
||||
*/
|
||||
readFlatCoordinatesFromNode_(node, objectStack) {
|
||||
return pushParseAndPop(null, this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, objectStack, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readGeometryFromNode(node, opt_options) {
|
||||
const geometry = this.readGeometryElement(node,
|
||||
[this.getReadOptions(node, opt_options ? opt_options : {})]);
|
||||
return geometry ? geometry : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
const options = {
|
||||
featureType: this.featureType,
|
||||
featureNS: this.featureNS
|
||||
};
|
||||
if (opt_options) {
|
||||
assign(options, this.getReadOptions(node, opt_options));
|
||||
}
|
||||
const features = this.readFeaturesInternal(node, [options]);
|
||||
return features || [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readProjectionFromNode(node) {
|
||||
return getProjection(this.srsName ? this.srsName : node.firstElementChild.getAttribute('srsName'));
|
||||
}
|
||||
}
|
||||
|
||||
inherits(GMLBase, XMLFeature);
|
||||
|
||||
@@ -131,329 +472,6 @@ inherits(GMLBase, XMLFeature);
|
||||
const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {Array.<module:ol/Feature> | undefined} Features.
|
||||
*/
|
||||
GMLBase.prototype.readFeaturesInternal = function(node, objectStack) {
|
||||
const localName = node.localName;
|
||||
let features = null;
|
||||
if (localName == 'FeatureCollection') {
|
||||
if (node.namespaceURI === 'http://www.opengis.net/wfs') {
|
||||
features = pushParseAndPop([],
|
||||
this.FEATURE_COLLECTION_PARSERS, node,
|
||||
objectStack, this);
|
||||
} else {
|
||||
features = pushParseAndPop(null,
|
||||
this.FEATURE_COLLECTION_PARSERS, node,
|
||||
objectStack, this);
|
||||
}
|
||||
} else if (localName == 'featureMembers' || localName == 'featureMember') {
|
||||
const context = objectStack[0];
|
||||
let featureType = context['featureType'];
|
||||
let featureNS = context['featureNS'];
|
||||
const prefix = 'p';
|
||||
const defaultPrefix = 'p0';
|
||||
if (!featureType && node.childNodes) {
|
||||
featureType = [], featureNS = {};
|
||||
for (let i = 0, ii = node.childNodes.length; i < ii; ++i) {
|
||||
const child = node.childNodes[i];
|
||||
if (child.nodeType === 1) {
|
||||
const ft = child.nodeName.split(':').pop();
|
||||
if (featureType.indexOf(ft) === -1) {
|
||||
let key = '';
|
||||
let count = 0;
|
||||
const uri = child.namespaceURI;
|
||||
for (const candidate in featureNS) {
|
||||
if (featureNS[candidate] === uri) {
|
||||
key = candidate;
|
||||
break;
|
||||
}
|
||||
++count;
|
||||
}
|
||||
if (!key) {
|
||||
key = prefix + count;
|
||||
featureNS[key] = uri;
|
||||
}
|
||||
featureType.push(key + ':' + ft);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (localName != 'featureMember') {
|
||||
// recheck featureType for each featureMember
|
||||
context['featureType'] = featureType;
|
||||
context['featureNS'] = featureNS;
|
||||
}
|
||||
}
|
||||
if (typeof featureNS === 'string') {
|
||||
const ns = featureNS;
|
||||
featureNS = {};
|
||||
featureNS[defaultPrefix] = ns;
|
||||
}
|
||||
const parsersNS = {};
|
||||
const featureTypes = Array.isArray(featureType) ? featureType : [featureType];
|
||||
for (const p in featureNS) {
|
||||
const parsers = {};
|
||||
for (let i = 0, ii = featureTypes.length; i < ii; ++i) {
|
||||
const featurePrefix = featureTypes[i].indexOf(':') === -1 ?
|
||||
defaultPrefix : featureTypes[i].split(':')[0];
|
||||
if (featurePrefix === p) {
|
||||
parsers[featureTypes[i].split(':').pop()] =
|
||||
(localName == 'featureMembers') ?
|
||||
makeArrayPusher(this.readFeatureElement, this) :
|
||||
makeReplacer(this.readFeatureElement, this);
|
||||
}
|
||||
}
|
||||
parsersNS[featureNS[p]] = parsers;
|
||||
}
|
||||
if (localName == 'featureMember') {
|
||||
features = pushParseAndPop(undefined, parsersNS, node, objectStack);
|
||||
} else {
|
||||
features = pushParseAndPop([], parsersNS, node, objectStack);
|
||||
}
|
||||
}
|
||||
if (features === null) {
|
||||
features = [];
|
||||
}
|
||||
return features;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/Geometry|undefined} Geometry.
|
||||
*/
|
||||
GMLBase.prototype.readGeometryElement = function(node, objectStack) {
|
||||
const context = /** @type {Object} */ (objectStack[0]);
|
||||
context['srsName'] = node.firstElementChild.getAttribute('srsName');
|
||||
context['srsDimension'] = node.firstElementChild.getAttribute('srsDimension');
|
||||
/** @type {module:ol/geom/Geometry} */
|
||||
const geometry = pushParseAndPop(null, this.GEOMETRY_PARSERS_, node, objectStack, this);
|
||||
if (geometry) {
|
||||
return (
|
||||
/** @type {module:ol/geom/Geometry} */ (transformWithOptions(geometry, false, context))
|
||||
);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/Feature} Feature.
|
||||
*/
|
||||
GMLBase.prototype.readFeatureElement = function(node, objectStack) {
|
||||
let n;
|
||||
const fid = node.getAttribute('fid') || getAttributeNS(node, GMLNS, 'id');
|
||||
const values = {};
|
||||
let geometryName;
|
||||
for (n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
const localName = n.localName;
|
||||
// Assume attribute elements have one child node and that the child
|
||||
// is a text or CDATA node (to be treated as text).
|
||||
// Otherwise assume it is a geometry node.
|
||||
if (n.childNodes.length === 0 ||
|
||||
(n.childNodes.length === 1 &&
|
||||
(n.firstChild.nodeType === 3 || n.firstChild.nodeType === 4))) {
|
||||
let value = getAllTextContent(n, false);
|
||||
if (ONLY_WHITESPACE_RE.test(value)) {
|
||||
value = undefined;
|
||||
}
|
||||
values[localName] = value;
|
||||
} else {
|
||||
// boundedBy is an extent and must not be considered as a geometry
|
||||
if (localName !== 'boundedBy') {
|
||||
geometryName = localName;
|
||||
}
|
||||
values[localName] = this.readGeometryElement(n, objectStack);
|
||||
}
|
||||
}
|
||||
const feature = new Feature(values);
|
||||
if (geometryName) {
|
||||
feature.setGeometryName(geometryName);
|
||||
}
|
||||
if (fid) {
|
||||
feature.setId(fid);
|
||||
}
|
||||
return feature;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/Point|undefined} Point.
|
||||
*/
|
||||
GMLBase.prototype.readPoint = function(node, objectStack) {
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
|
||||
if (flatCoordinates) {
|
||||
return new Point(flatCoordinates, GeometryLayout.XYZ);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/MultiPoint|undefined} MultiPoint.
|
||||
*/
|
||||
GMLBase.prototype.readMultiPoint = function(node, objectStack) {
|
||||
/** @type {Array.<Array.<number>>} */
|
||||
const coordinates = pushParseAndPop([],
|
||||
this.MULTIPOINT_PARSERS_, node, objectStack, this);
|
||||
if (coordinates) {
|
||||
return new MultiPoint(coordinates);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/MultiLineString|undefined} MultiLineString.
|
||||
*/
|
||||
GMLBase.prototype.readMultiLineString = function(node, objectStack) {
|
||||
/** @type {Array.<module:ol/geom/LineString>} */
|
||||
const lineStrings = pushParseAndPop([],
|
||||
this.MULTILINESTRING_PARSERS_, node, objectStack, this);
|
||||
if (lineStrings) {
|
||||
return new MultiLineString(lineStrings);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/MultiPolygon|undefined} MultiPolygon.
|
||||
*/
|
||||
GMLBase.prototype.readMultiPolygon = function(node, objectStack) {
|
||||
/** @type {Array.<module:ol/geom/Polygon>} */
|
||||
const polygons = pushParseAndPop([], this.MULTIPOLYGON_PARSERS_, node, objectStack, this);
|
||||
if (polygons) {
|
||||
return new MultiPolygon(polygons);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
*/
|
||||
GMLBase.prototype.pointMemberParser_ = function(node, objectStack) {
|
||||
parseNode(this.POINTMEMBER_PARSERS_, node, objectStack, this);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
*/
|
||||
GMLBase.prototype.lineStringMemberParser_ = function(node, objectStack) {
|
||||
parseNode(this.LINESTRINGMEMBER_PARSERS_, node, objectStack, this);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
*/
|
||||
GMLBase.prototype.polygonMemberParser_ = function(node, objectStack) {
|
||||
parseNode(this.POLYGONMEMBER_PARSERS_, node, objectStack, this);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/LineString|undefined} LineString.
|
||||
*/
|
||||
GMLBase.prototype.readLineString = function(node, objectStack) {
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
|
||||
if (flatCoordinates) {
|
||||
const lineString = new LineString(flatCoordinates, GeometryLayout.XYZ);
|
||||
return lineString;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
* @return {Array.<number>|undefined} LinearRing flat coordinates.
|
||||
*/
|
||||
GMLBase.prototype.readFlatLinearRing_ = function(node, objectStack) {
|
||||
const ring = pushParseAndPop(null,
|
||||
this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node,
|
||||
objectStack, this);
|
||||
if (ring) {
|
||||
return ring;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/LinearRing|undefined} LinearRing.
|
||||
*/
|
||||
GMLBase.prototype.readLinearRing = function(node, objectStack) {
|
||||
const flatCoordinates = this.readFlatCoordinatesFromNode_(node, objectStack);
|
||||
if (flatCoordinates) {
|
||||
return new LinearRing(flatCoordinates, GeometryLayout.XYZ);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {module:ol/geom/Polygon|undefined} Polygon.
|
||||
*/
|
||||
GMLBase.prototype.readPolygon = function(node, objectStack) {
|
||||
/** @type {Array.<Array.<number>>} */
|
||||
const flatLinearRings = pushParseAndPop([null],
|
||||
this.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this);
|
||||
if (flatLinearRings && flatLinearRings[0]) {
|
||||
const flatCoordinates = flatLinearRings[0];
|
||||
const ends = [flatCoordinates.length];
|
||||
let i, ii;
|
||||
for (i = 1, ii = flatLinearRings.length; i < ii; ++i) {
|
||||
extend(flatCoordinates, flatLinearRings[i]);
|
||||
ends.push(flatCoordinates.length);
|
||||
}
|
||||
return new Polygon(flatCoordinates, GeometryLayout.XYZ, ends);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
* @return {Array.<number>} Flat coordinates.
|
||||
*/
|
||||
GMLBase.prototype.readFlatCoordinatesFromNode_ = function(node, objectStack) {
|
||||
return pushParseAndPop(null, this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node, objectStack, this);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
|
||||
@@ -541,16 +559,6 @@ GMLBase.prototype.RING_PARSERS = {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
GMLBase.prototype.readGeometryFromNode = function(node, opt_options) {
|
||||
const geometry = this.readGeometryElement(node,
|
||||
[this.getReadOptions(node, opt_options ? opt_options : {})]);
|
||||
return geometry ? geometry : null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read all features from a GML FeatureCollection.
|
||||
*
|
||||
@@ -563,26 +571,4 @@ GMLBase.prototype.readGeometryFromNode = function(node, opt_options) {
|
||||
GMLBase.prototype.readFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
GMLBase.prototype.readFeaturesFromNode = function(node, opt_options) {
|
||||
const options = {
|
||||
featureType: this.featureType,
|
||||
featureNS: this.featureNS
|
||||
};
|
||||
if (opt_options) {
|
||||
assign(options, this.getReadOptions(node, opt_options));
|
||||
}
|
||||
const features = this.readFeaturesInternal(node, [options]);
|
||||
return features || [];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
GMLBase.prototype.readProjectionFromNode = function(node) {
|
||||
return getProjection(this.srsName ? this.srsName : node.firstElementChild.getAttribute('srsName'));
|
||||
};
|
||||
export default GMLBase;
|
||||
|
||||
+94
-94
@@ -43,23 +43,109 @@ import {createElementNS, makeArrayPusher, makeArraySerializer, makeChildAppender
|
||||
* @param {module:ol/format/GPX~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const GPX = function(opt_options) {
|
||||
class GPX {
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
XMLFeature.call(this);
|
||||
XMLFeature.call(this);
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.dataProjection = getProjection('EPSG:4326');
|
||||
|
||||
/**
|
||||
* @type {function(module:ol/Feature, Node)|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.readExtensions_ = options.readExtensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array.<module:ol/Feature>} features List of features.
|
||||
* @private
|
||||
*/
|
||||
handleReadExtensions_(features) {
|
||||
if (!features) {
|
||||
features = [];
|
||||
}
|
||||
for (let i = 0, ii = features.length; i < ii; ++i) {
|
||||
const feature = features[i];
|
||||
if (this.readExtensions_) {
|
||||
const extensionsNode = feature.get('extensionsNode_') || null;
|
||||
this.readExtensions_(feature, extensionsNode);
|
||||
}
|
||||
feature.set('extensionsNode_', undefined);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.dataProjection = getProjection('EPSG:4326');
|
||||
readFeatureFromNode(node, opt_options) {
|
||||
if (!includes(NAMESPACE_URIS, node.namespaceURI)) {
|
||||
return null;
|
||||
}
|
||||
const featureReader = FEATURE_READER[node.localName];
|
||||
if (!featureReader) {
|
||||
return null;
|
||||
}
|
||||
const feature = featureReader(node, [this.getReadOptions(node, opt_options)]);
|
||||
if (!feature) {
|
||||
return null;
|
||||
}
|
||||
this.handleReadExtensions_([feature]);
|
||||
return feature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {function(module:ol/Feature, Node)|undefined}
|
||||
* @private
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.readExtensions_ = options.readExtensions;
|
||||
};
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
if (!includes(NAMESPACE_URIS, node.namespaceURI)) {
|
||||
return [];
|
||||
}
|
||||
if (node.localName == 'gpx') {
|
||||
/** @type {Array.<module:ol/Feature>} */
|
||||
const features = pushParseAndPop([], GPX_PARSERS,
|
||||
node, [this.getReadOptions(node, opt_options)]);
|
||||
if (features) {
|
||||
this.handleReadExtensions_(features);
|
||||
return features;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode an array of features in the GPX format as an XML node.
|
||||
* LineString geometries are output as routes (`<rte>`), and MultiLineString
|
||||
* as tracks (`<trk>`).
|
||||
*
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Options.
|
||||
* @return {Node} Node.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
writeFeaturesNode(features, opt_options) {
|
||||
opt_options = this.adaptOptions(opt_options);
|
||||
//FIXME Serialize metadata
|
||||
const gpx = createElementNS('http://www.topografix.com/GPX/1/1', 'gpx');
|
||||
const xmlnsUri = 'http://www.w3.org/2000/xmlns/';
|
||||
gpx.setAttributeNS(xmlnsUri, 'xmlns:xsi', XML_SCHEMA_INSTANCE_URI);
|
||||
gpx.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', SCHEMA_LOCATION);
|
||||
gpx.setAttribute('version', '1.1');
|
||||
gpx.setAttribute('creator', 'OpenLayers');
|
||||
|
||||
pushSerializeAndPop(/** @type {module:ol/xml~NodeStackItem} */
|
||||
({node: gpx}), GPX_SERIALIZERS, GPX_NODE_FACTORY, features, [opt_options]);
|
||||
return gpx;
|
||||
}
|
||||
}
|
||||
|
||||
inherits(GPX, XMLFeature);
|
||||
|
||||
@@ -614,25 +700,6 @@ function readWpt(node, objectStack) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<module:ol/Feature>} features List of features.
|
||||
* @private
|
||||
*/
|
||||
GPX.prototype.handleReadExtensions_ = function(features) {
|
||||
if (!features) {
|
||||
features = [];
|
||||
}
|
||||
for (let i = 0, ii = features.length; i < ii; ++i) {
|
||||
const feature = features[i];
|
||||
if (this.readExtensions_) {
|
||||
const extensionsNode = feature.get('extensionsNode_') || null;
|
||||
this.readExtensions_(feature, extensionsNode);
|
||||
}
|
||||
feature.set('extensionsNode_', undefined);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the first feature from a GPX source.
|
||||
* Routes (`<rte>`) are converted into LineString geometries, and tracks (`<trk>`)
|
||||
@@ -647,26 +714,6 @@ GPX.prototype.handleReadExtensions_ = function(features) {
|
||||
GPX.prototype.readFeature;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
GPX.prototype.readFeatureFromNode = function(node, opt_options) {
|
||||
if (!includes(NAMESPACE_URIS, node.namespaceURI)) {
|
||||
return null;
|
||||
}
|
||||
const featureReader = FEATURE_READER[node.localName];
|
||||
if (!featureReader) {
|
||||
return null;
|
||||
}
|
||||
const feature = featureReader(node, [this.getReadOptions(node, opt_options)]);
|
||||
if (!feature) {
|
||||
return null;
|
||||
}
|
||||
this.handleReadExtensions_([feature]);
|
||||
return feature;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read all features from a GPX source.
|
||||
* Routes (`<rte>`) are converted into LineString geometries, and tracks (`<trk>`)
|
||||
@@ -681,28 +728,6 @@ GPX.prototype.readFeatureFromNode = function(node, opt_options) {
|
||||
GPX.prototype.readFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
GPX.prototype.readFeaturesFromNode = function(node, opt_options) {
|
||||
if (!includes(NAMESPACE_URIS, node.namespaceURI)) {
|
||||
return [];
|
||||
}
|
||||
if (node.localName == 'gpx') {
|
||||
/** @type {Array.<module:ol/Feature>} */
|
||||
const features = pushParseAndPop([], GPX_PARSERS,
|
||||
node, [this.getReadOptions(node, opt_options)]);
|
||||
if (features) {
|
||||
this.handleReadExtensions_(features);
|
||||
return features;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the projection from a GPX source.
|
||||
*
|
||||
@@ -874,29 +899,4 @@ function writeWpt(node, feature, objectStack) {
|
||||
GPX.prototype.writeFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* Encode an array of features in the GPX format as an XML node.
|
||||
* LineString geometries are output as routes (`<rte>`), and MultiLineString
|
||||
* as tracks (`<trk>`).
|
||||
*
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Options.
|
||||
* @return {Node} Node.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
GPX.prototype.writeFeaturesNode = function(features, opt_options) {
|
||||
opt_options = this.adaptOptions(opt_options);
|
||||
//FIXME Serialize metadata
|
||||
const gpx = createElementNS('http://www.topografix.com/GPX/1/1', 'gpx');
|
||||
const xmlnsUri = 'http://www.w3.org/2000/xmlns/';
|
||||
gpx.setAttributeNS(xmlnsUri, 'xmlns:xsi', XML_SCHEMA_INSTANCE_URI);
|
||||
gpx.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', SCHEMA_LOCATION);
|
||||
gpx.setAttribute('version', '1.1');
|
||||
gpx.setAttribute('creator', 'OpenLayers');
|
||||
|
||||
pushSerializeAndPop(/** @type {module:ol/xml~NodeStackItem} */
|
||||
({node: gpx}), GPX_SERIALIZERS, GPX_NODE_FACTORY, features, [opt_options]);
|
||||
return gpx;
|
||||
};
|
||||
export default GPX;
|
||||
|
||||
+170
-173
@@ -42,38 +42,191 @@ import {get as getProjection} from '../proj.js';
|
||||
* @param {module:ol/format/GeoJSON~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const GeoJSON = function(opt_options) {
|
||||
class GeoJSON {
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
JSONFeature.call(this);
|
||||
JSONFeature.call(this);
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.dataProjection = getProjection(
|
||||
options.dataProjection ?
|
||||
options.dataProjection : 'EPSG:4326');
|
||||
|
||||
if (options.featureProjection) {
|
||||
this.defaultFeatureProjection = getProjection(options.featureProjection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the geometry attribute for features.
|
||||
* @type {string|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.geometryName_ = options.geometryName;
|
||||
|
||||
/**
|
||||
* Look for the geometry name in the feature GeoJSON
|
||||
* @type {boolean|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.extractGeometryName_ = options.extractGeometryName;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.dataProjection = getProjection(
|
||||
options.dataProjection ?
|
||||
options.dataProjection : 'EPSG:4326');
|
||||
readFeatureFromObject(object, opt_options) {
|
||||
/**
|
||||
* @type {GeoJSONFeature}
|
||||
*/
|
||||
let geoJSONFeature = null;
|
||||
if (object.type === 'Feature') {
|
||||
geoJSONFeature = /** @type {GeoJSONFeature} */ (object);
|
||||
} else {
|
||||
geoJSONFeature = /** @type {GeoJSONFeature} */ ({
|
||||
type: 'Feature',
|
||||
geometry: /** @type {GeoJSONGeometry|GeoJSONGeometryCollection} */ (object)
|
||||
});
|
||||
}
|
||||
|
||||
if (options.featureProjection) {
|
||||
this.defaultFeatureProjection = getProjection(options.featureProjection);
|
||||
const geometry = readGeometry(geoJSONFeature.geometry, opt_options);
|
||||
const feature = new Feature();
|
||||
if (this.geometryName_) {
|
||||
feature.setGeometryName(this.geometryName_);
|
||||
} else if (this.extractGeometryName_ && geoJSONFeature.geometry_name !== undefined) {
|
||||
feature.setGeometryName(geoJSONFeature.geometry_name);
|
||||
}
|
||||
feature.setGeometry(geometry);
|
||||
if (geoJSONFeature.id !== undefined) {
|
||||
feature.setId(geoJSONFeature.id);
|
||||
}
|
||||
if (geoJSONFeature.properties) {
|
||||
feature.setProperties(geoJSONFeature.properties);
|
||||
}
|
||||
return feature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the geometry attribute for features.
|
||||
* @type {string|undefined}
|
||||
* @private
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.geometryName_ = options.geometryName;
|
||||
readFeaturesFromObject(object, opt_options) {
|
||||
const geoJSONObject = /** @type {GeoJSONObject} */ (object);
|
||||
/** @type {Array.<module:ol/Feature>} */
|
||||
let features = null;
|
||||
if (geoJSONObject.type === 'FeatureCollection') {
|
||||
const geoJSONFeatureCollection = /** @type {GeoJSONFeatureCollection} */ (object);
|
||||
features = [];
|
||||
const geoJSONFeatures = geoJSONFeatureCollection.features;
|
||||
for (let i = 0, ii = geoJSONFeatures.length; i < ii; ++i) {
|
||||
features.push(this.readFeatureFromObject(geoJSONFeatures[i], opt_options));
|
||||
}
|
||||
} else {
|
||||
features = [this.readFeatureFromObject(object, opt_options)];
|
||||
}
|
||||
return features;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look for the geometry name in the feature GeoJSON
|
||||
* @type {boolean|undefined}
|
||||
* @private
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.extractGeometryName_ = options.extractGeometryName;
|
||||
readGeometryFromObject(object, opt_options) {
|
||||
return readGeometry(/** @type {GeoJSONGeometry} */ (object), opt_options);
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readProjectionFromObject(object) {
|
||||
const geoJSONObject = /** @type {GeoJSONObject} */ (object);
|
||||
const crs = geoJSONObject.crs;
|
||||
let projection;
|
||||
if (crs) {
|
||||
if (crs.type == 'name') {
|
||||
projection = getProjection(crs.properties.name);
|
||||
} else {
|
||||
assert(false, 36); // Unknown SRS type
|
||||
}
|
||||
} else {
|
||||
projection = this.dataProjection;
|
||||
}
|
||||
return (
|
||||
/** @type {module:ol/proj/Projection} */ (projection)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a feature as a GeoJSON Feature object.
|
||||
*
|
||||
* @param {module:ol/Feature} feature Feature.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {GeoJSONFeature} Object.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
writeFeatureObject(feature, opt_options) {
|
||||
opt_options = this.adaptOptions(opt_options);
|
||||
|
||||
const object = /** @type {GeoJSONFeature} */ ({
|
||||
'type': 'Feature'
|
||||
});
|
||||
const id = feature.getId();
|
||||
if (id !== undefined) {
|
||||
object.id = id;
|
||||
}
|
||||
const geometry = feature.getGeometry();
|
||||
if (geometry) {
|
||||
object.geometry = writeGeometry(geometry, opt_options);
|
||||
} else {
|
||||
object.geometry = null;
|
||||
}
|
||||
const properties = feature.getProperties();
|
||||
delete properties[feature.getGeometryName()];
|
||||
if (!isEmpty(properties)) {
|
||||
object.properties = properties;
|
||||
} else {
|
||||
object.properties = null;
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode an array of features as a GeoJSON object.
|
||||
*
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {GeoJSONFeatureCollection} GeoJSON Object.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
writeFeaturesObject(features, opt_options) {
|
||||
opt_options = this.adaptOptions(opt_options);
|
||||
const objects = [];
|
||||
for (let i = 0, ii = features.length; i < ii; ++i) {
|
||||
objects.push(this.writeFeatureObject(features[i], opt_options));
|
||||
}
|
||||
return /** @type {GeoJSONFeatureCollection} */ ({
|
||||
type: 'FeatureCollection',
|
||||
features: objects
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a geometry as a GeoJSON object.
|
||||
*
|
||||
* @param {module:ol/geom/Geometry} geometry Geometry.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {GeoJSONGeometry|GeoJSONGeometryCollection} Object.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
writeGeometryObject(geometry, opt_options) {
|
||||
return writeGeometry(geometry, this.adaptOptions(opt_options));
|
||||
}
|
||||
}
|
||||
|
||||
inherits(GeoJSON, JSONFeature);
|
||||
|
||||
@@ -354,62 +507,6 @@ GeoJSON.prototype.readFeature;
|
||||
GeoJSON.prototype.readFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
GeoJSON.prototype.readFeatureFromObject = function(object, opt_options) {
|
||||
/**
|
||||
* @type {GeoJSONFeature}
|
||||
*/
|
||||
let geoJSONFeature = null;
|
||||
if (object.type === 'Feature') {
|
||||
geoJSONFeature = /** @type {GeoJSONFeature} */ (object);
|
||||
} else {
|
||||
geoJSONFeature = /** @type {GeoJSONFeature} */ ({
|
||||
type: 'Feature',
|
||||
geometry: /** @type {GeoJSONGeometry|GeoJSONGeometryCollection} */ (object)
|
||||
});
|
||||
}
|
||||
|
||||
const geometry = readGeometry(geoJSONFeature.geometry, opt_options);
|
||||
const feature = new Feature();
|
||||
if (this.geometryName_) {
|
||||
feature.setGeometryName(this.geometryName_);
|
||||
} else if (this.extractGeometryName_ && geoJSONFeature.geometry_name !== undefined) {
|
||||
feature.setGeometryName(geoJSONFeature.geometry_name);
|
||||
}
|
||||
feature.setGeometry(geometry);
|
||||
if (geoJSONFeature.id !== undefined) {
|
||||
feature.setId(geoJSONFeature.id);
|
||||
}
|
||||
if (geoJSONFeature.properties) {
|
||||
feature.setProperties(geoJSONFeature.properties);
|
||||
}
|
||||
return feature;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
GeoJSON.prototype.readFeaturesFromObject = function(object, opt_options) {
|
||||
const geoJSONObject = /** @type {GeoJSONObject} */ (object);
|
||||
/** @type {Array.<module:ol/Feature>} */
|
||||
let features = null;
|
||||
if (geoJSONObject.type === 'FeatureCollection') {
|
||||
const geoJSONFeatureCollection = /** @type {GeoJSONFeatureCollection} */ (object);
|
||||
features = [];
|
||||
const geoJSONFeatures = geoJSONFeatureCollection.features;
|
||||
for (let i = 0, ii = geoJSONFeatures.length; i < ii; ++i) {
|
||||
features.push(this.readFeatureFromObject(geoJSONFeatures[i], opt_options));
|
||||
}
|
||||
} else {
|
||||
features = [this.readFeatureFromObject(object, opt_options)];
|
||||
}
|
||||
return features;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read a geometry from a GeoJSON source.
|
||||
*
|
||||
@@ -422,14 +519,6 @@ GeoJSON.prototype.readFeaturesFromObject = function(object, opt_options) {
|
||||
GeoJSON.prototype.readGeometry;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
GeoJSON.prototype.readGeometryFromObject = function(object, opt_options) {
|
||||
return readGeometry(/** @type {GeoJSONGeometry} */ (object), opt_options);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the projection from a GeoJSON source.
|
||||
*
|
||||
@@ -441,28 +530,6 @@ GeoJSON.prototype.readGeometryFromObject = function(object, opt_options) {
|
||||
GeoJSON.prototype.readProjection;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
GeoJSON.prototype.readProjectionFromObject = function(object) {
|
||||
const geoJSONObject = /** @type {GeoJSONObject} */ (object);
|
||||
const crs = geoJSONObject.crs;
|
||||
let projection;
|
||||
if (crs) {
|
||||
if (crs.type == 'name') {
|
||||
projection = getProjection(crs.properties.name);
|
||||
} else {
|
||||
assert(false, 36); // Unknown SRS type
|
||||
}
|
||||
} else {
|
||||
projection = this.dataProjection;
|
||||
}
|
||||
return (
|
||||
/** @type {module:ol/proj/Projection} */ (projection)
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode a feature as a GeoJSON Feature string.
|
||||
*
|
||||
@@ -476,42 +543,6 @@ GeoJSON.prototype.readProjectionFromObject = function(object) {
|
||||
GeoJSON.prototype.writeFeature;
|
||||
|
||||
|
||||
/**
|
||||
* Encode a feature as a GeoJSON Feature object.
|
||||
*
|
||||
* @param {module:ol/Feature} feature Feature.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {GeoJSONFeature} Object.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
GeoJSON.prototype.writeFeatureObject = function(feature, opt_options) {
|
||||
opt_options = this.adaptOptions(opt_options);
|
||||
|
||||
const object = /** @type {GeoJSONFeature} */ ({
|
||||
'type': 'Feature'
|
||||
});
|
||||
const id = feature.getId();
|
||||
if (id !== undefined) {
|
||||
object.id = id;
|
||||
}
|
||||
const geometry = feature.getGeometry();
|
||||
if (geometry) {
|
||||
object.geometry = writeGeometry(geometry, opt_options);
|
||||
} else {
|
||||
object.geometry = null;
|
||||
}
|
||||
const properties = feature.getProperties();
|
||||
delete properties[feature.getGeometryName()];
|
||||
if (!isEmpty(properties)) {
|
||||
object.properties = properties;
|
||||
} else {
|
||||
object.properties = null;
|
||||
}
|
||||
return object;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode an array of features as GeoJSON.
|
||||
*
|
||||
@@ -524,28 +555,6 @@ GeoJSON.prototype.writeFeatureObject = function(feature, opt_options) {
|
||||
GeoJSON.prototype.writeFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* Encode an array of features as a GeoJSON object.
|
||||
*
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {GeoJSONFeatureCollection} GeoJSON Object.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
GeoJSON.prototype.writeFeaturesObject = function(features, opt_options) {
|
||||
opt_options = this.adaptOptions(opt_options);
|
||||
const objects = [];
|
||||
for (let i = 0, ii = features.length; i < ii; ++i) {
|
||||
objects.push(this.writeFeatureObject(features[i], opt_options));
|
||||
}
|
||||
return /** @type {GeoJSONFeatureCollection} */ ({
|
||||
type: 'FeatureCollection',
|
||||
features: objects
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode a geometry as a GeoJSON string.
|
||||
*
|
||||
@@ -558,16 +567,4 @@ GeoJSON.prototype.writeFeaturesObject = function(features, opt_options) {
|
||||
GeoJSON.prototype.writeGeometry;
|
||||
|
||||
|
||||
/**
|
||||
* Encode a geometry as a GeoJSON object.
|
||||
*
|
||||
* @param {module:ol/geom/Geometry} geometry Geometry.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {GeoJSONGeometry|GeoJSONGeometryCollection} Object.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
GeoJSON.prototype.writeGeometryObject = function(geometry, opt_options) {
|
||||
return writeGeometry(geometry, this.adaptOptions(opt_options));
|
||||
};
|
||||
export default GeoJSON;
|
||||
|
||||
+121
-123
@@ -36,23 +36,136 @@ const IGCZ = {
|
||||
* @param {module:ol/format/IGC~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const IGC = function(opt_options) {
|
||||
class IGC {
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
TextFeature.call(this);
|
||||
TextFeature.call(this);
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.dataProjection = getProjection('EPSG:4326');
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {IGCZ}
|
||||
*/
|
||||
this.altitudeMode_ = options.altitudeMode ? options.altitudeMode : IGCZ.NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.dataProjection = getProjection('EPSG:4326');
|
||||
readFeatureFromText(text, opt_options) {
|
||||
const altitudeMode = this.altitudeMode_;
|
||||
const lines = text.split(NEWLINE_RE);
|
||||
/** @type {Object.<string, string>} */
|
||||
const properties = {};
|
||||
const flatCoordinates = [];
|
||||
let year = 2000;
|
||||
let month = 0;
|
||||
let day = 1;
|
||||
let lastDateTime = -1;
|
||||
let i, ii;
|
||||
for (i = 0, ii = lines.length; i < ii; ++i) {
|
||||
const line = lines[i];
|
||||
let m;
|
||||
if (line.charAt(0) == 'B') {
|
||||
m = B_RECORD_RE.exec(line);
|
||||
if (m) {
|
||||
const hour = parseInt(m[1], 10);
|
||||
const minute = parseInt(m[2], 10);
|
||||
const second = parseInt(m[3], 10);
|
||||
let y = parseInt(m[4], 10) + parseInt(m[5], 10) / 60000;
|
||||
if (m[6] == 'S') {
|
||||
y = -y;
|
||||
}
|
||||
let x = parseInt(m[7], 10) + parseInt(m[8], 10) / 60000;
|
||||
if (m[9] == 'W') {
|
||||
x = -x;
|
||||
}
|
||||
flatCoordinates.push(x, y);
|
||||
if (altitudeMode != IGCZ.NONE) {
|
||||
let z;
|
||||
if (altitudeMode == IGCZ.GPS) {
|
||||
z = parseInt(m[11], 10);
|
||||
} else if (altitudeMode == IGCZ.BAROMETRIC) {
|
||||
z = parseInt(m[12], 10);
|
||||
} else {
|
||||
z = 0;
|
||||
}
|
||||
flatCoordinates.push(z);
|
||||
}
|
||||
let dateTime = Date.UTC(year, month, day, hour, minute, second);
|
||||
// Detect UTC midnight wrap around.
|
||||
if (dateTime < lastDateTime) {
|
||||
dateTime = Date.UTC(year, month, day + 1, hour, minute, second);
|
||||
}
|
||||
flatCoordinates.push(dateTime / 1000);
|
||||
lastDateTime = dateTime;
|
||||
}
|
||||
} else if (line.charAt(0) == 'H') {
|
||||
m = HFDTE_RECORD_RE.exec(line);
|
||||
if (m) {
|
||||
day = parseInt(m[1], 10);
|
||||
month = parseInt(m[2], 10) - 1;
|
||||
year = 2000 + parseInt(m[3], 10);
|
||||
} else {
|
||||
m = H_RECORD_RE.exec(line);
|
||||
if (m) {
|
||||
properties[m[1]] = m[2].trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flatCoordinates.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const layout = altitudeMode == IGCZ.NONE ? GeometryLayout.XYM : GeometryLayout.XYZM;
|
||||
const lineString = new LineString(flatCoordinates, layout);
|
||||
const feature = new Feature(transformWithOptions(lineString, false, opt_options));
|
||||
feature.setProperties(properties);
|
||||
return feature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {IGCZ}
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.altitudeMode_ = options.altitudeMode ? options.altitudeMode : IGCZ.NONE;
|
||||
};
|
||||
readFeaturesFromText(text, opt_options) {
|
||||
const feature = this.readFeatureFromText(text, opt_options);
|
||||
if (feature) {
|
||||
return [feature];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeatureText(feature, opt_options) {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeaturesText(features, opt_options) {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeGeometryText(geometry, opt_options) {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
readGeometryFromText(text, opt_options) {}
|
||||
}
|
||||
|
||||
inherits(IGC, TextFeature);
|
||||
|
||||
@@ -100,82 +213,6 @@ const NEWLINE_RE = /\r\n|\r|\n/;
|
||||
IGC.prototype.readFeature;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
IGC.prototype.readFeatureFromText = function(text, opt_options) {
|
||||
const altitudeMode = this.altitudeMode_;
|
||||
const lines = text.split(NEWLINE_RE);
|
||||
/** @type {Object.<string, string>} */
|
||||
const properties = {};
|
||||
const flatCoordinates = [];
|
||||
let year = 2000;
|
||||
let month = 0;
|
||||
let day = 1;
|
||||
let lastDateTime = -1;
|
||||
let i, ii;
|
||||
for (i = 0, ii = lines.length; i < ii; ++i) {
|
||||
const line = lines[i];
|
||||
let m;
|
||||
if (line.charAt(0) == 'B') {
|
||||
m = B_RECORD_RE.exec(line);
|
||||
if (m) {
|
||||
const hour = parseInt(m[1], 10);
|
||||
const minute = parseInt(m[2], 10);
|
||||
const second = parseInt(m[3], 10);
|
||||
let y = parseInt(m[4], 10) + parseInt(m[5], 10) / 60000;
|
||||
if (m[6] == 'S') {
|
||||
y = -y;
|
||||
}
|
||||
let x = parseInt(m[7], 10) + parseInt(m[8], 10) / 60000;
|
||||
if (m[9] == 'W') {
|
||||
x = -x;
|
||||
}
|
||||
flatCoordinates.push(x, y);
|
||||
if (altitudeMode != IGCZ.NONE) {
|
||||
let z;
|
||||
if (altitudeMode == IGCZ.GPS) {
|
||||
z = parseInt(m[11], 10);
|
||||
} else if (altitudeMode == IGCZ.BAROMETRIC) {
|
||||
z = parseInt(m[12], 10);
|
||||
} else {
|
||||
z = 0;
|
||||
}
|
||||
flatCoordinates.push(z);
|
||||
}
|
||||
let dateTime = Date.UTC(year, month, day, hour, minute, second);
|
||||
// Detect UTC midnight wrap around.
|
||||
if (dateTime < lastDateTime) {
|
||||
dateTime = Date.UTC(year, month, day + 1, hour, minute, second);
|
||||
}
|
||||
flatCoordinates.push(dateTime / 1000);
|
||||
lastDateTime = dateTime;
|
||||
}
|
||||
} else if (line.charAt(0) == 'H') {
|
||||
m = HFDTE_RECORD_RE.exec(line);
|
||||
if (m) {
|
||||
day = parseInt(m[1], 10);
|
||||
month = parseInt(m[2], 10) - 1;
|
||||
year = 2000 + parseInt(m[3], 10);
|
||||
} else {
|
||||
m = H_RECORD_RE.exec(line);
|
||||
if (m) {
|
||||
properties[m[1]] = m[2].trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (flatCoordinates.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const layout = altitudeMode == IGCZ.NONE ? GeometryLayout.XYM : GeometryLayout.XYZM;
|
||||
const lineString = new LineString(flatCoordinates, layout);
|
||||
const feature = new Feature(transformWithOptions(lineString, false, opt_options));
|
||||
feature.setProperties(properties);
|
||||
return feature;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the feature from the source. As IGC sources contain a single
|
||||
* feature, this will return the feature in an array.
|
||||
@@ -189,19 +226,6 @@ IGC.prototype.readFeatureFromText = function(text, opt_options) {
|
||||
IGC.prototype.readFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
IGC.prototype.readFeaturesFromText = function(text, opt_options) {
|
||||
const feature = this.readFeatureFromText(text, opt_options);
|
||||
if (feature) {
|
||||
return [feature];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the projection from the IGC source.
|
||||
*
|
||||
@@ -213,30 +237,4 @@ IGC.prototype.readFeaturesFromText = function(text, opt_options) {
|
||||
IGC.prototype.readProjection;
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
IGC.prototype.writeFeatureText = function(feature, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
IGC.prototype.writeFeaturesText = function(features, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
IGC.prototype.writeGeometryText = function(geometry, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
IGC.prototype.readGeometryFromText = function(text, opt_options) {};
|
||||
export default IGC;
|
||||
|
||||
+123
-134
@@ -15,9 +15,129 @@ import FormatType from '../format/FormatType.js';
|
||||
* @abstract
|
||||
* @extends {module:ol/format/Feature}
|
||||
*/
|
||||
const JSONFeature = function() {
|
||||
FeatureFormat.call(this);
|
||||
};
|
||||
class JSONFeature {
|
||||
constructor() {
|
||||
FeatureFormat.call(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getType() {
|
||||
return FormatType.JSON;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readFeature(source, opt_options) {
|
||||
return this.readFeatureFromObject(
|
||||
getObject(source), this.getReadOptions(source, opt_options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readFeatures(source, opt_options) {
|
||||
return this.readFeaturesFromObject(
|
||||
getObject(source), this.getReadOptions(source, opt_options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Object} object Object.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @protected
|
||||
* @return {module:ol/Feature} Feature.
|
||||
*/
|
||||
readFeatureFromObject(object, opt_options) {}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Object} object Object.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @protected
|
||||
* @return {Array.<module:ol/Feature>} Features.
|
||||
*/
|
||||
readFeaturesFromObject(object, opt_options) {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readGeometry(source, opt_options) {
|
||||
return this.readGeometryFromObject(
|
||||
getObject(source), this.getReadOptions(source, opt_options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Object} object Object.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @protected
|
||||
* @return {module:ol/geom/Geometry} Geometry.
|
||||
*/
|
||||
readGeometryFromObject(object, opt_options) {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readProjection(source) {
|
||||
return this.readProjectionFromObject(getObject(source));
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Object} object Object.
|
||||
* @protected
|
||||
* @return {module:ol/proj/Projection} Projection.
|
||||
*/
|
||||
readProjectionFromObject(object) {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeature(feature, opt_options) {
|
||||
return JSON.stringify(this.writeFeatureObject(feature, opt_options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {module:ol/Feature} feature Feature.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {Object} Object.
|
||||
*/
|
||||
writeFeatureObject(feature, opt_options) {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeatures(features, opt_options) {
|
||||
return JSON.stringify(this.writeFeaturesObject(features, opt_options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {Object} Object.
|
||||
*/
|
||||
writeFeaturesObject(features, opt_options) {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeGeometry(geometry, opt_options) {
|
||||
return JSON.stringify(this.writeGeometryObject(geometry, opt_options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {module:ol/geom/Geometry} geometry Geometry.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {Object} Object.
|
||||
*/
|
||||
writeGeometryObject(geometry, opt_options) {}
|
||||
}
|
||||
|
||||
inherits(JSONFeature, FeatureFormat);
|
||||
|
||||
@@ -38,135 +158,4 @@ function getObject(source) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
JSONFeature.prototype.getType = function() {
|
||||
return FormatType.JSON;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
JSONFeature.prototype.readFeature = function(source, opt_options) {
|
||||
return this.readFeatureFromObject(
|
||||
getObject(source), this.getReadOptions(source, opt_options));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
JSONFeature.prototype.readFeatures = function(source, opt_options) {
|
||||
return this.readFeaturesFromObject(
|
||||
getObject(source), this.getReadOptions(source, opt_options));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Object} object Object.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @protected
|
||||
* @return {module:ol/Feature} Feature.
|
||||
*/
|
||||
JSONFeature.prototype.readFeatureFromObject = function(object, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Object} object Object.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @protected
|
||||
* @return {Array.<module:ol/Feature>} Features.
|
||||
*/
|
||||
JSONFeature.prototype.readFeaturesFromObject = function(object, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
JSONFeature.prototype.readGeometry = function(source, opt_options) {
|
||||
return this.readGeometryFromObject(
|
||||
getObject(source), this.getReadOptions(source, opt_options));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Object} object Object.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @protected
|
||||
* @return {module:ol/geom/Geometry} Geometry.
|
||||
*/
|
||||
JSONFeature.prototype.readGeometryFromObject = function(object, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
JSONFeature.prototype.readProjection = function(source) {
|
||||
return this.readProjectionFromObject(getObject(source));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Object} object Object.
|
||||
* @protected
|
||||
* @return {module:ol/proj/Projection} Projection.
|
||||
*/
|
||||
JSONFeature.prototype.readProjectionFromObject = function(object) {};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
JSONFeature.prototype.writeFeature = function(feature, opt_options) {
|
||||
return JSON.stringify(this.writeFeatureObject(feature, opt_options));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {module:ol/Feature} feature Feature.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {Object} Object.
|
||||
*/
|
||||
JSONFeature.prototype.writeFeatureObject = function(feature, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
JSONFeature.prototype.writeFeatures = function(features, opt_options) {
|
||||
return JSON.stringify(this.writeFeaturesObject(features, opt_options));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {Object} Object.
|
||||
*/
|
||||
JSONFeature.prototype.writeFeaturesObject = function(features, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
JSONFeature.prototype.writeGeometry = function(geometry, opt_options) {
|
||||
return JSON.stringify(this.writeGeometryObject(geometry, opt_options));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {module:ol/geom/Geometry} geometry Geometry.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @return {Object} Object.
|
||||
*/
|
||||
JSONFeature.prototype.writeGeometryObject = function(geometry, opt_options) {};
|
||||
export default JSONFeature;
|
||||
|
||||
+426
-439
@@ -259,56 +259,456 @@ function createStyleDefaults() {
|
||||
* @param {module:ol/format/KML~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const KML = function(opt_options) {
|
||||
class KML {
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
XMLFeature.call(this);
|
||||
XMLFeature.call(this);
|
||||
|
||||
if (!DEFAULT_STYLE_ARRAY) {
|
||||
createStyleDefaults();
|
||||
if (!DEFAULT_STYLE_ARRAY) {
|
||||
createStyleDefaults();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.dataProjection = getProjection('EPSG:4326');
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<module:ol/style/Style>}
|
||||
*/
|
||||
this.defaultStyle_ = options.defaultStyle ?
|
||||
options.defaultStyle : DEFAULT_STYLE_ARRAY;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.extractStyles_ = options.extractStyles !== undefined ?
|
||||
options.extractStyles : true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.writeStyles_ = options.writeStyles !== undefined ?
|
||||
options.writeStyles : true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Object.<string, (Array.<module:ol/style/Style>|string)>}
|
||||
*/
|
||||
this.sharedStyles_ = {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.showPointNames_ = options.showPointNames !== undefined ?
|
||||
options.showPointNames : true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
* @return {Array.<module:ol/Feature>|undefined} Features.
|
||||
*/
|
||||
readDocumentOrFolder_(node, objectStack) {
|
||||
// FIXME use scope somehow
|
||||
const parsersNS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Document': makeArrayExtender(this.readDocumentOrFolder_, this),
|
||||
'Folder': makeArrayExtender(this.readDocumentOrFolder_, this),
|
||||
'Placemark': makeArrayPusher(this.readPlacemark_, this),
|
||||
'Style': this.readSharedStyle_.bind(this),
|
||||
'StyleMap': this.readSharedStyleMap_.bind(this)
|
||||
});
|
||||
/** @type {Array.<module:ol/Feature>} */
|
||||
const features = pushParseAndPop([], parsersNS, node, objectStack, this);
|
||||
if (features) {
|
||||
return features;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
* @return {module:ol/Feature|undefined} Feature.
|
||||
*/
|
||||
readPlacemark_(node, objectStack) {
|
||||
const object = pushParseAndPop({'geometry': null},
|
||||
PLACEMARK_PARSERS, node, objectStack);
|
||||
if (!object) {
|
||||
return undefined;
|
||||
}
|
||||
const feature = new Feature();
|
||||
const id = node.getAttribute('id');
|
||||
if (id !== null) {
|
||||
feature.setId(id);
|
||||
}
|
||||
const options = /** @type {module:ol/format/Feature~ReadOptions} */ (objectStack[0]);
|
||||
|
||||
const geometry = object['geometry'];
|
||||
if (geometry) {
|
||||
transformWithOptions(geometry, false, options);
|
||||
}
|
||||
feature.setGeometry(geometry);
|
||||
delete object['geometry'];
|
||||
|
||||
if (this.extractStyles_) {
|
||||
const style = object['Style'];
|
||||
const styleUrl = object['styleUrl'];
|
||||
const styleFunction = createFeatureStyleFunction(
|
||||
style, styleUrl, this.defaultStyle_, this.sharedStyles_,
|
||||
this.showPointNames_);
|
||||
feature.setStyle(styleFunction);
|
||||
}
|
||||
delete object['Style'];
|
||||
// we do not remove the styleUrl property from the object, so it
|
||||
// gets stored on feature when setProperties is called
|
||||
|
||||
feature.setProperties(object);
|
||||
|
||||
return feature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
*/
|
||||
readSharedStyle_(node, objectStack) {
|
||||
const id = node.getAttribute('id');
|
||||
if (id !== null) {
|
||||
const style = readStyle(node, objectStack);
|
||||
if (style) {
|
||||
let styleUri;
|
||||
let baseURI = node.baseURI;
|
||||
if (!baseURI || baseURI == 'about:blank') {
|
||||
baseURI = window.location.href;
|
||||
}
|
||||
if (baseURI) {
|
||||
const url = new URL('#' + id, baseURI);
|
||||
styleUri = url.href;
|
||||
} else {
|
||||
styleUri = '#' + id;
|
||||
}
|
||||
this.sharedStyles_[styleUri] = style;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
*/
|
||||
readSharedStyleMap_(node, objectStack) {
|
||||
const id = node.getAttribute('id');
|
||||
if (id === null) {
|
||||
return;
|
||||
}
|
||||
const styleMapValue = readStyleMapValue(node, objectStack);
|
||||
if (!styleMapValue) {
|
||||
return;
|
||||
}
|
||||
let styleUri;
|
||||
let baseURI = node.baseURI;
|
||||
if (!baseURI || baseURI == 'about:blank') {
|
||||
baseURI = window.location.href;
|
||||
}
|
||||
if (baseURI) {
|
||||
const url = new URL('#' + id, baseURI);
|
||||
styleUri = url.href;
|
||||
} else {
|
||||
styleUri = '#' + id;
|
||||
}
|
||||
this.sharedStyles_[styleUri] = styleMapValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.dataProjection = getProjection('EPSG:4326');
|
||||
readFeatureFromNode(node, opt_options) {
|
||||
if (!includes(NAMESPACE_URIS, node.namespaceURI)) {
|
||||
return null;
|
||||
}
|
||||
const feature = this.readPlacemark_(
|
||||
node, [this.getReadOptions(node, opt_options)]);
|
||||
if (feature) {
|
||||
return feature;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<module:ol/style/Style>}
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.defaultStyle_ = options.defaultStyle ?
|
||||
options.defaultStyle : DEFAULT_STYLE_ARRAY;
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
if (!includes(NAMESPACE_URIS, node.namespaceURI)) {
|
||||
return [];
|
||||
}
|
||||
let features;
|
||||
const localName = node.localName;
|
||||
if (localName == 'Document' || localName == 'Folder') {
|
||||
features = this.readDocumentOrFolder_(
|
||||
node, [this.getReadOptions(node, opt_options)]);
|
||||
if (features) {
|
||||
return features;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
} else if (localName == 'Placemark') {
|
||||
const feature = this.readPlacemark_(
|
||||
node, [this.getReadOptions(node, opt_options)]);
|
||||
if (feature) {
|
||||
return [feature];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
} else if (localName == 'kml') {
|
||||
features = [];
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
const fs = this.readFeaturesFromNode(n, opt_options);
|
||||
if (fs) {
|
||||
extend(features, fs);
|
||||
}
|
||||
}
|
||||
return features;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
* Read the name of the KML.
|
||||
*
|
||||
* @param {Document|Node|string} source Source.
|
||||
* @return {string|undefined} Name.
|
||||
* @api
|
||||
*/
|
||||
this.extractStyles_ = options.extractStyles !== undefined ?
|
||||
options.extractStyles : true;
|
||||
readName(source) {
|
||||
if (isDocument(source)) {
|
||||
return this.readNameFromDocument(/** @type {Document} */ (source));
|
||||
} else if (isNode(source)) {
|
||||
return this.readNameFromNode(/** @type {Node} */ (source));
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readNameFromDocument(doc);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
* @param {Document} doc Document.
|
||||
* @return {string|undefined} Name.
|
||||
*/
|
||||
this.writeStyles_ = options.writeStyles !== undefined ?
|
||||
options.writeStyles : true;
|
||||
readNameFromDocument(doc) {
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
const name = this.readNameFromNode(n);
|
||||
if (name) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Object.<string, (Array.<module:ol/style/Style>|string)>}
|
||||
* @param {Node} node Node.
|
||||
* @return {string|undefined} Name.
|
||||
*/
|
||||
this.sharedStyles_ = {};
|
||||
readNameFromNode(node) {
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
if (includes(NAMESPACE_URIS, n.namespaceURI) &&
|
||||
n.localName == 'name') {
|
||||
return readString(n);
|
||||
}
|
||||
}
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
const localName = n.localName;
|
||||
if (includes(NAMESPACE_URIS, n.namespaceURI) &&
|
||||
(localName == 'Document' ||
|
||||
localName == 'Folder' ||
|
||||
localName == 'Placemark' ||
|
||||
localName == 'kml')) {
|
||||
const name = this.readNameFromNode(n);
|
||||
if (name) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
* Read the network links of the KML.
|
||||
*
|
||||
* @param {Document|Node|string} source Source.
|
||||
* @return {Array.<Object>} Network links.
|
||||
* @api
|
||||
*/
|
||||
this.showPointNames_ = options.showPointNames !== undefined ?
|
||||
options.showPointNames : true;
|
||||
readNetworkLinks(source) {
|
||||
const networkLinks = [];
|
||||
if (isDocument(source)) {
|
||||
extend(networkLinks, this.readNetworkLinksFromDocument(
|
||||
/** @type {Document} */ (source)));
|
||||
} else if (isNode(source)) {
|
||||
extend(networkLinks, this.readNetworkLinksFromNode(
|
||||
/** @type {Node} */ (source)));
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
extend(networkLinks, this.readNetworkLinksFromDocument(doc));
|
||||
}
|
||||
return networkLinks;
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @return {Array.<Object>} Network links.
|
||||
*/
|
||||
readNetworkLinksFromDocument(doc) {
|
||||
const networkLinks = [];
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
extend(networkLinks, this.readNetworkLinksFromNode(n));
|
||||
}
|
||||
}
|
||||
return networkLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @return {Array.<Object>} Network links.
|
||||
*/
|
||||
readNetworkLinksFromNode(node) {
|
||||
const networkLinks = [];
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
if (includes(NAMESPACE_URIS, n.namespaceURI) &&
|
||||
n.localName == 'NetworkLink') {
|
||||
const obj = pushParseAndPop({}, NETWORK_LINK_PARSERS,
|
||||
n, []);
|
||||
networkLinks.push(obj);
|
||||
}
|
||||
}
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
const localName = n.localName;
|
||||
if (includes(NAMESPACE_URIS, n.namespaceURI) &&
|
||||
(localName == 'Document' ||
|
||||
localName == 'Folder' ||
|
||||
localName == 'kml')) {
|
||||
extend(networkLinks, this.readNetworkLinksFromNode(n));
|
||||
}
|
||||
}
|
||||
return networkLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the regions of the KML.
|
||||
*
|
||||
* @param {Document|Node|string} source Source.
|
||||
* @return {Array.<Object>} Regions.
|
||||
* @api
|
||||
*/
|
||||
readRegion(source) {
|
||||
const regions = [];
|
||||
if (isDocument(source)) {
|
||||
extend(regions, this.readRegionFromDocument(
|
||||
/** @type {Document} */ (source)));
|
||||
} else if (isNode(source)) {
|
||||
extend(regions, this.readRegionFromNode(
|
||||
/** @type {Node} */ (source)));
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
extend(regions, this.readRegionFromDocument(doc));
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @return {Array.<Object>} Region.
|
||||
*/
|
||||
readRegionFromDocument(doc) {
|
||||
const regions = [];
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
extend(regions, this.readRegionFromNode(n));
|
||||
}
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @return {Array.<Object>} Region.
|
||||
* @api
|
||||
*/
|
||||
readRegionFromNode(node) {
|
||||
const regions = [];
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
if (includes(NAMESPACE_URIS, n.namespaceURI) &&
|
||||
n.localName == 'Region') {
|
||||
const obj = pushParseAndPop({}, REGION_PARSERS,
|
||||
n, []);
|
||||
regions.push(obj);
|
||||
}
|
||||
}
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
const localName = n.localName;
|
||||
if (includes(NAMESPACE_URIS, n.namespaceURI) &&
|
||||
(localName == 'Document' ||
|
||||
localName == 'Folder' ||
|
||||
localName == 'kml')) {
|
||||
extend(regions, this.readRegionFromNode(n));
|
||||
}
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode an array of features in the KML format as an XML node. GeometryCollections,
|
||||
* MultiPoints, MultiLineStrings, and MultiPolygons are output as MultiGeometries.
|
||||
*
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Options.
|
||||
* @return {Node} Node.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
writeFeaturesNode(features, opt_options) {
|
||||
opt_options = this.adaptOptions(opt_options);
|
||||
const kml = createElementNS(NAMESPACE_URIS[4], 'kml');
|
||||
const xmlnsUri = 'http://www.w3.org/2000/xmlns/';
|
||||
kml.setAttributeNS(xmlnsUri, 'xmlns:gx', GX_NAMESPACE_URIS[0]);
|
||||
kml.setAttributeNS(xmlnsUri, 'xmlns:xsi', XML_SCHEMA_INSTANCE_URI);
|
||||
kml.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', SCHEMA_LOCATION);
|
||||
|
||||
const /** @type {module:ol/xml~NodeStackItem} */ context = {node: kml};
|
||||
const properties = {};
|
||||
if (features.length > 1) {
|
||||
properties['Document'] = features;
|
||||
} else if (features.length == 1) {
|
||||
properties['Placemark'] = features[0];
|
||||
}
|
||||
const orderedKeys = KML_SEQUENCE[kml.namespaceURI];
|
||||
const values = makeSequence(properties, orderedKeys);
|
||||
pushSerializeAndPop(context, KML_SERIALIZERS,
|
||||
OBJECT_PROPERTY_NODE_FACTORY, values, [opt_options], orderedKeys,
|
||||
this);
|
||||
return kml;
|
||||
}
|
||||
}
|
||||
|
||||
inherits(KML, XMLFeature);
|
||||
|
||||
@@ -1643,132 +2043,6 @@ const PLACEMARK_PARSERS = makeStructureNS(
|
||||
));
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
* @return {Array.<module:ol/Feature>|undefined} Features.
|
||||
*/
|
||||
KML.prototype.readDocumentOrFolder_ = function(node, objectStack) {
|
||||
// FIXME use scope somehow
|
||||
const parsersNS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Document': makeArrayExtender(this.readDocumentOrFolder_, this),
|
||||
'Folder': makeArrayExtender(this.readDocumentOrFolder_, this),
|
||||
'Placemark': makeArrayPusher(this.readPlacemark_, this),
|
||||
'Style': this.readSharedStyle_.bind(this),
|
||||
'StyleMap': this.readSharedStyleMap_.bind(this)
|
||||
});
|
||||
/** @type {Array.<module:ol/Feature>} */
|
||||
const features = pushParseAndPop([], parsersNS, node, objectStack, this);
|
||||
if (features) {
|
||||
return features;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
* @return {module:ol/Feature|undefined} Feature.
|
||||
*/
|
||||
KML.prototype.readPlacemark_ = function(node, objectStack) {
|
||||
const object = pushParseAndPop({'geometry': null},
|
||||
PLACEMARK_PARSERS, node, objectStack);
|
||||
if (!object) {
|
||||
return undefined;
|
||||
}
|
||||
const feature = new Feature();
|
||||
const id = node.getAttribute('id');
|
||||
if (id !== null) {
|
||||
feature.setId(id);
|
||||
}
|
||||
const options = /** @type {module:ol/format/Feature~ReadOptions} */ (objectStack[0]);
|
||||
|
||||
const geometry = object['geometry'];
|
||||
if (geometry) {
|
||||
transformWithOptions(geometry, false, options);
|
||||
}
|
||||
feature.setGeometry(geometry);
|
||||
delete object['geometry'];
|
||||
|
||||
if (this.extractStyles_) {
|
||||
const style = object['Style'];
|
||||
const styleUrl = object['styleUrl'];
|
||||
const styleFunction = createFeatureStyleFunction(
|
||||
style, styleUrl, this.defaultStyle_, this.sharedStyles_,
|
||||
this.showPointNames_);
|
||||
feature.setStyle(styleFunction);
|
||||
}
|
||||
delete object['Style'];
|
||||
// we do not remove the styleUrl property from the object, so it
|
||||
// gets stored on feature when setProperties is called
|
||||
|
||||
feature.setProperties(object);
|
||||
|
||||
return feature;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
*/
|
||||
KML.prototype.readSharedStyle_ = function(node, objectStack) {
|
||||
const id = node.getAttribute('id');
|
||||
if (id !== null) {
|
||||
const style = readStyle(node, objectStack);
|
||||
if (style) {
|
||||
let styleUri;
|
||||
let baseURI = node.baseURI;
|
||||
if (!baseURI || baseURI == 'about:blank') {
|
||||
baseURI = window.location.href;
|
||||
}
|
||||
if (baseURI) {
|
||||
const url = new URL('#' + id, baseURI);
|
||||
styleUri = url.href;
|
||||
} else {
|
||||
styleUri = '#' + id;
|
||||
}
|
||||
this.sharedStyles_[styleUri] = style;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @private
|
||||
*/
|
||||
KML.prototype.readSharedStyleMap_ = function(node, objectStack) {
|
||||
const id = node.getAttribute('id');
|
||||
if (id === null) {
|
||||
return;
|
||||
}
|
||||
const styleMapValue = readStyleMapValue(node, objectStack);
|
||||
if (!styleMapValue) {
|
||||
return;
|
||||
}
|
||||
let styleUri;
|
||||
let baseURI = node.baseURI;
|
||||
if (!baseURI || baseURI == 'about:blank') {
|
||||
baseURI = window.location.href;
|
||||
}
|
||||
if (baseURI) {
|
||||
const url = new URL('#' + id, baseURI);
|
||||
styleUri = url.href;
|
||||
} else {
|
||||
styleUri = '#' + id;
|
||||
}
|
||||
this.sharedStyles_[styleUri] = styleMapValue;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the first feature from a KML source. MultiGeometries are converted into
|
||||
* GeometryCollections if they are a mix of geometry types, and into MultiPoint/
|
||||
@@ -1783,23 +2057,6 @@ KML.prototype.readSharedStyleMap_ = function(node, objectStack) {
|
||||
KML.prototype.readFeature;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
KML.prototype.readFeatureFromNode = function(node, opt_options) {
|
||||
if (!includes(NAMESPACE_URIS, node.namespaceURI)) {
|
||||
return null;
|
||||
}
|
||||
const feature = this.readPlacemark_(
|
||||
node, [this.getReadOptions(node, opt_options)]);
|
||||
if (feature) {
|
||||
return feature;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read all features from a KML source. MultiGeometries are converted into
|
||||
* GeometryCollections if they are a mix of geometry types, and into MultiPoint/
|
||||
@@ -1814,243 +2071,6 @@ KML.prototype.readFeatureFromNode = function(node, opt_options) {
|
||||
KML.prototype.readFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
KML.prototype.readFeaturesFromNode = function(node, opt_options) {
|
||||
if (!includes(NAMESPACE_URIS, node.namespaceURI)) {
|
||||
return [];
|
||||
}
|
||||
let features;
|
||||
const localName = node.localName;
|
||||
if (localName == 'Document' || localName == 'Folder') {
|
||||
features = this.readDocumentOrFolder_(
|
||||
node, [this.getReadOptions(node, opt_options)]);
|
||||
if (features) {
|
||||
return features;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
} else if (localName == 'Placemark') {
|
||||
const feature = this.readPlacemark_(
|
||||
node, [this.getReadOptions(node, opt_options)]);
|
||||
if (feature) {
|
||||
return [feature];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
} else if (localName == 'kml') {
|
||||
features = [];
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
const fs = this.readFeaturesFromNode(n, opt_options);
|
||||
if (fs) {
|
||||
extend(features, fs);
|
||||
}
|
||||
}
|
||||
return features;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the name of the KML.
|
||||
*
|
||||
* @param {Document|Node|string} source Source.
|
||||
* @return {string|undefined} Name.
|
||||
* @api
|
||||
*/
|
||||
KML.prototype.readName = function(source) {
|
||||
if (isDocument(source)) {
|
||||
return this.readNameFromDocument(/** @type {Document} */ (source));
|
||||
} else if (isNode(source)) {
|
||||
return this.readNameFromNode(/** @type {Node} */ (source));
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readNameFromDocument(doc);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @return {string|undefined} Name.
|
||||
*/
|
||||
KML.prototype.readNameFromDocument = function(doc) {
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
const name = this.readNameFromNode(n);
|
||||
if (name) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @return {string|undefined} Name.
|
||||
*/
|
||||
KML.prototype.readNameFromNode = function(node) {
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
if (includes(NAMESPACE_URIS, n.namespaceURI) &&
|
||||
n.localName == 'name') {
|
||||
return readString(n);
|
||||
}
|
||||
}
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
const localName = n.localName;
|
||||
if (includes(NAMESPACE_URIS, n.namespaceURI) &&
|
||||
(localName == 'Document' ||
|
||||
localName == 'Folder' ||
|
||||
localName == 'Placemark' ||
|
||||
localName == 'kml')) {
|
||||
const name = this.readNameFromNode(n);
|
||||
if (name) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the network links of the KML.
|
||||
*
|
||||
* @param {Document|Node|string} source Source.
|
||||
* @return {Array.<Object>} Network links.
|
||||
* @api
|
||||
*/
|
||||
KML.prototype.readNetworkLinks = function(source) {
|
||||
const networkLinks = [];
|
||||
if (isDocument(source)) {
|
||||
extend(networkLinks, this.readNetworkLinksFromDocument(
|
||||
/** @type {Document} */ (source)));
|
||||
} else if (isNode(source)) {
|
||||
extend(networkLinks, this.readNetworkLinksFromNode(
|
||||
/** @type {Node} */ (source)));
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
extend(networkLinks, this.readNetworkLinksFromDocument(doc));
|
||||
}
|
||||
return networkLinks;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @return {Array.<Object>} Network links.
|
||||
*/
|
||||
KML.prototype.readNetworkLinksFromDocument = function(doc) {
|
||||
const networkLinks = [];
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
extend(networkLinks, this.readNetworkLinksFromNode(n));
|
||||
}
|
||||
}
|
||||
return networkLinks;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @return {Array.<Object>} Network links.
|
||||
*/
|
||||
KML.prototype.readNetworkLinksFromNode = function(node) {
|
||||
const networkLinks = [];
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
if (includes(NAMESPACE_URIS, n.namespaceURI) &&
|
||||
n.localName == 'NetworkLink') {
|
||||
const obj = pushParseAndPop({}, NETWORK_LINK_PARSERS,
|
||||
n, []);
|
||||
networkLinks.push(obj);
|
||||
}
|
||||
}
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
const localName = n.localName;
|
||||
if (includes(NAMESPACE_URIS, n.namespaceURI) &&
|
||||
(localName == 'Document' ||
|
||||
localName == 'Folder' ||
|
||||
localName == 'kml')) {
|
||||
extend(networkLinks, this.readNetworkLinksFromNode(n));
|
||||
}
|
||||
}
|
||||
return networkLinks;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the regions of the KML.
|
||||
*
|
||||
* @param {Document|Node|string} source Source.
|
||||
* @return {Array.<Object>} Regions.
|
||||
* @api
|
||||
*/
|
||||
KML.prototype.readRegion = function(source) {
|
||||
const regions = [];
|
||||
if (isDocument(source)) {
|
||||
extend(regions, this.readRegionFromDocument(
|
||||
/** @type {Document} */ (source)));
|
||||
} else if (isNode(source)) {
|
||||
extend(regions, this.readRegionFromNode(
|
||||
/** @type {Node} */ (source)));
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
extend(regions, this.readRegionFromDocument(doc));
|
||||
}
|
||||
return regions;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @return {Array.<Object>} Region.
|
||||
*/
|
||||
KML.prototype.readRegionFromDocument = function(doc) {
|
||||
const regions = [];
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
extend(regions, this.readRegionFromNode(n));
|
||||
}
|
||||
}
|
||||
return regions;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @return {Array.<Object>} Region.
|
||||
* @api
|
||||
*/
|
||||
KML.prototype.readRegionFromNode = function(node) {
|
||||
const regions = [];
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
if (includes(NAMESPACE_URIS, n.namespaceURI) &&
|
||||
n.localName == 'Region') {
|
||||
const obj = pushParseAndPop({}, REGION_PARSERS,
|
||||
n, []);
|
||||
regions.push(obj);
|
||||
}
|
||||
}
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
const localName = n.localName;
|
||||
if (includes(NAMESPACE_URIS, n.namespaceURI) &&
|
||||
(localName == 'Document' ||
|
||||
localName == 'Folder' ||
|
||||
localName == 'kml')) {
|
||||
extend(regions, this.readRegionFromNode(n));
|
||||
}
|
||||
}
|
||||
return regions;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the projection from a KML source.
|
||||
*
|
||||
@@ -2955,37 +2975,4 @@ const KML_SERIALIZERS = makeStructureNS(
|
||||
KML.prototype.writeFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* Encode an array of features in the KML format as an XML node. GeometryCollections,
|
||||
* MultiPoints, MultiLineStrings, and MultiPolygons are output as MultiGeometries.
|
||||
*
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Options.
|
||||
* @return {Node} Node.
|
||||
* @override
|
||||
* @api
|
||||
*/
|
||||
KML.prototype.writeFeaturesNode = function(features, opt_options) {
|
||||
opt_options = this.adaptOptions(opt_options);
|
||||
const kml = createElementNS(NAMESPACE_URIS[4], 'kml');
|
||||
const xmlnsUri = 'http://www.w3.org/2000/xmlns/';
|
||||
kml.setAttributeNS(xmlnsUri, 'xmlns:gx', GX_NAMESPACE_URIS[0]);
|
||||
kml.setAttributeNS(xmlnsUri, 'xmlns:xsi', XML_SCHEMA_INSTANCE_URI);
|
||||
kml.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', SCHEMA_LOCATION);
|
||||
|
||||
const /** @type {module:ol/xml~NodeStackItem} */ context = {node: kml};
|
||||
const properties = {};
|
||||
if (features.length > 1) {
|
||||
properties['Document'] = features;
|
||||
} else if (features.length == 1) {
|
||||
properties['Placemark'] = features[0];
|
||||
}
|
||||
const orderedKeys = KML_SEQUENCE[kml.namespaceURI];
|
||||
const values = makeSequence(properties, orderedKeys);
|
||||
pushSerializeAndPop(context, KML_SERIALIZERS,
|
||||
OBJECT_PROPERTY_NODE_FACTORY, values, [opt_options], orderedKeys,
|
||||
this);
|
||||
return kml;
|
||||
};
|
||||
|
||||
export default KML;
|
||||
|
||||
+248
-256
@@ -47,54 +47,276 @@ import RenderFeature from '../render/Feature.js';
|
||||
* @param {module:ol/format/MVT~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const MVT = function(opt_options) {
|
||||
class MVT {
|
||||
constructor(opt_options) {
|
||||
|
||||
FeatureFormat.call(this);
|
||||
FeatureFormat.call(this);
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
/**
|
||||
* @type {module:ol/proj/Projection}
|
||||
*/
|
||||
this.dataProjection = new Projection({
|
||||
code: '',
|
||||
units: Units.TILE_PIXELS
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {function((module:ol/geom/Geometry|Object.<string,*>)=)|
|
||||
* function(module:ol/geom/GeometryType,Array.<number>,
|
||||
* (Array.<number>|Array.<Array.<number>>),Object.<string,*>,number)}
|
||||
*/
|
||||
this.featureClass_ = options.featureClass ?
|
||||
options.featureClass : RenderFeature;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.geometryName_ = options.geometryName;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.layerName_ = options.layerName ? options.layerName : 'layer';
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
this.layers_ = options.layers ? options.layers : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/extent~Extent}
|
||||
*/
|
||||
this.extent_ = null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {module:ol/proj/Projection}
|
||||
* Read the raw geometry from the pbf offset stored in a raw feature's geometry
|
||||
* property.
|
||||
* @suppress {missingProperties}
|
||||
* @param {Object} pbf PBF.
|
||||
* @param {Object} feature Raw feature.
|
||||
* @param {Array.<number>} flatCoordinates Array to store flat coordinates in.
|
||||
* @param {Array.<number>} ends Array to store ends in.
|
||||
* @private
|
||||
*/
|
||||
this.dataProjection = new Projection({
|
||||
code: '',
|
||||
units: Units.TILE_PIXELS
|
||||
});
|
||||
readRawGeometry_(pbf, feature, flatCoordinates, ends) {
|
||||
pbf.pos = feature.geometry;
|
||||
|
||||
const end = pbf.readVarint() + pbf.pos;
|
||||
let cmd = 1;
|
||||
let length = 0;
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
let coordsLen = 0;
|
||||
let currentEnd = 0;
|
||||
|
||||
while (pbf.pos < end) {
|
||||
if (!length) {
|
||||
const cmdLen = pbf.readVarint();
|
||||
cmd = cmdLen & 0x7;
|
||||
length = cmdLen >> 3;
|
||||
}
|
||||
|
||||
length--;
|
||||
|
||||
if (cmd === 1 || cmd === 2) {
|
||||
x += pbf.readSVarint();
|
||||
y += pbf.readSVarint();
|
||||
|
||||
if (cmd === 1) { // moveTo
|
||||
if (coordsLen > currentEnd) {
|
||||
ends.push(coordsLen);
|
||||
currentEnd = coordsLen;
|
||||
}
|
||||
}
|
||||
|
||||
flatCoordinates.push(x, y);
|
||||
coordsLen += 2;
|
||||
|
||||
} else if (cmd === 7) {
|
||||
|
||||
if (coordsLen > currentEnd) {
|
||||
// close polygon
|
||||
flatCoordinates.push(
|
||||
flatCoordinates[currentEnd], flatCoordinates[currentEnd + 1]);
|
||||
coordsLen += 2;
|
||||
}
|
||||
|
||||
} else {
|
||||
assert(false, 59); // Invalid command found in the PBF
|
||||
}
|
||||
}
|
||||
|
||||
if (coordsLen > currentEnd) {
|
||||
ends.push(coordsLen);
|
||||
currentEnd = coordsLen;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {function((module:ol/geom/Geometry|Object.<string,*>)=)|
|
||||
* function(module:ol/geom/GeometryType,Array.<number>,
|
||||
* (Array.<number>|Array.<Array.<number>>),Object.<string,*>,number)}
|
||||
* @param {Object} pbf PBF
|
||||
* @param {Object} rawFeature Raw Mapbox feature.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @return {module:ol/Feature|module:ol/render/Feature} Feature.
|
||||
*/
|
||||
this.featureClass_ = options.featureClass ?
|
||||
options.featureClass : RenderFeature;
|
||||
createFeature_(pbf, rawFeature, opt_options) {
|
||||
const type = rawFeature.type;
|
||||
if (type === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let feature;
|
||||
const id = rawFeature.id;
|
||||
const values = rawFeature.properties;
|
||||
values[this.layerName_] = rawFeature.layer.name;
|
||||
|
||||
const flatCoordinates = [];
|
||||
const ends = [];
|
||||
this.readRawGeometry_(pbf, rawFeature, flatCoordinates, ends);
|
||||
|
||||
const geometryType = getGeometryType(type, ends.length);
|
||||
|
||||
if (this.featureClass_ === RenderFeature) {
|
||||
feature = new this.featureClass_(geometryType, flatCoordinates, ends, values, id);
|
||||
} else {
|
||||
let geom;
|
||||
if (geometryType == GeometryType.POLYGON) {
|
||||
const endss = [];
|
||||
let offset = 0;
|
||||
let prevEndIndex = 0;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
if (!linearRingIsClockwise(flatCoordinates, offset, end, 2)) {
|
||||
endss.push(ends.slice(prevEndIndex, i));
|
||||
prevEndIndex = i;
|
||||
}
|
||||
offset = end;
|
||||
}
|
||||
if (endss.length > 1) {
|
||||
geom = new MultiPolygon(flatCoordinates, GeometryLayout.XY, endss);
|
||||
} else {
|
||||
geom = new Polygon(flatCoordinates, GeometryLayout.XY, ends);
|
||||
}
|
||||
} else {
|
||||
geom = geometryType === GeometryType.POINT ? new Point(flatCoordinates, GeometryLayout.XY) :
|
||||
geometryType === GeometryType.LINE_STRING ? new LineString(flatCoordinates, GeometryLayout.XY) :
|
||||
geometryType === GeometryType.POLYGON ? new Polygon(flatCoordinates, GeometryLayout.XY, ends) :
|
||||
geometryType === GeometryType.MULTI_POINT ? new MultiPoint(flatCoordinates, GeometryLayout.XY) :
|
||||
geometryType === GeometryType.MULTI_LINE_STRING ? new MultiLineString(flatCoordinates, GeometryLayout.XY, ends) :
|
||||
null;
|
||||
}
|
||||
feature = new this.featureClass_();
|
||||
if (this.geometryName_) {
|
||||
feature.setGeometryName(this.geometryName_);
|
||||
}
|
||||
const geometry = transformWithOptions(geom, false, this.adaptOptions(opt_options));
|
||||
feature.setGeometry(geometry);
|
||||
feature.setId(id);
|
||||
feature.setProperties(values);
|
||||
}
|
||||
|
||||
return feature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
this.geometryName_ = options.geometryName;
|
||||
getLastExtent() {
|
||||
return this.extent_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.layerName_ = options.layerName ? options.layerName : 'layer';
|
||||
getType() {
|
||||
return FormatType.ARRAY_BUFFER;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<string>}
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
this.layers_ = options.layers ? options.layers : null;
|
||||
readFeatures(source, opt_options) {
|
||||
const layers = this.layers_;
|
||||
|
||||
const pbf = new PBF(/** @type {ArrayBuffer} */ (source));
|
||||
const pbfLayers = pbf.readFields(layersPBFReader, {});
|
||||
/** @type {Array.<module:ol/Feature|module:ol/render/Feature>} */
|
||||
const features = [];
|
||||
for (const name in pbfLayers) {
|
||||
if (layers && layers.indexOf(name) == -1) {
|
||||
continue;
|
||||
}
|
||||
const pbfLayer = pbfLayers[name];
|
||||
|
||||
for (let i = 0, ii = pbfLayer.length; i < ii; ++i) {
|
||||
const rawFeature = readRawFeature(pbf, pbfLayer, i);
|
||||
features.push(this.createFeature_(pbf, rawFeature));
|
||||
}
|
||||
this.extent_ = pbfLayer ? [0, 0, pbfLayer.extent, pbfLayer.extent] : null;
|
||||
}
|
||||
|
||||
return features;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/extent~Extent}
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
this.extent_ = null;
|
||||
readProjection(source) {
|
||||
return this.dataProjection;
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* Sets the layers that features will be read from.
|
||||
* @param {Array.<string>} layers Layers.
|
||||
* @api
|
||||
*/
|
||||
setLayers(layers) {
|
||||
this.layers_ = layers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @override
|
||||
*/
|
||||
readFeature() {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @override
|
||||
*/
|
||||
readGeometry() {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @override
|
||||
*/
|
||||
writeFeature() {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @override
|
||||
*/
|
||||
writeGeometry() {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @override
|
||||
*/
|
||||
writeFeatures() {}
|
||||
}
|
||||
|
||||
inherits(MVT, FeatureFormat);
|
||||
|
||||
@@ -201,72 +423,6 @@ function readRawFeature(pbf, layer, i) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read the raw geometry from the pbf offset stored in a raw feature's geometry
|
||||
* property.
|
||||
* @suppress {missingProperties}
|
||||
* @param {Object} pbf PBF.
|
||||
* @param {Object} feature Raw feature.
|
||||
* @param {Array.<number>} flatCoordinates Array to store flat coordinates in.
|
||||
* @param {Array.<number>} ends Array to store ends in.
|
||||
* @private
|
||||
*/
|
||||
MVT.prototype.readRawGeometry_ = function(pbf, feature, flatCoordinates, ends) {
|
||||
pbf.pos = feature.geometry;
|
||||
|
||||
const end = pbf.readVarint() + pbf.pos;
|
||||
let cmd = 1;
|
||||
let length = 0;
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
let coordsLen = 0;
|
||||
let currentEnd = 0;
|
||||
|
||||
while (pbf.pos < end) {
|
||||
if (!length) {
|
||||
const cmdLen = pbf.readVarint();
|
||||
cmd = cmdLen & 0x7;
|
||||
length = cmdLen >> 3;
|
||||
}
|
||||
|
||||
length--;
|
||||
|
||||
if (cmd === 1 || cmd === 2) {
|
||||
x += pbf.readSVarint();
|
||||
y += pbf.readSVarint();
|
||||
|
||||
if (cmd === 1) { // moveTo
|
||||
if (coordsLen > currentEnd) {
|
||||
ends.push(coordsLen);
|
||||
currentEnd = coordsLen;
|
||||
}
|
||||
}
|
||||
|
||||
flatCoordinates.push(x, y);
|
||||
coordsLen += 2;
|
||||
|
||||
} else if (cmd === 7) {
|
||||
|
||||
if (coordsLen > currentEnd) {
|
||||
// close polygon
|
||||
flatCoordinates.push(
|
||||
flatCoordinates[currentEnd], flatCoordinates[currentEnd + 1]);
|
||||
coordsLen += 2;
|
||||
}
|
||||
|
||||
} else {
|
||||
assert(false, 59); // Invalid command found in the PBF
|
||||
}
|
||||
}
|
||||
|
||||
if (coordsLen > currentEnd) {
|
||||
ends.push(coordsLen);
|
||||
currentEnd = coordsLen;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @suppress {missingProperties}
|
||||
* @param {number} type The raw feature's geometry type
|
||||
@@ -292,168 +448,4 @@ function getGeometryType(type, numEnds) {
|
||||
return geometryType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Object} pbf PBF
|
||||
* @param {Object} rawFeature Raw Mapbox feature.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @return {module:ol/Feature|module:ol/render/Feature} Feature.
|
||||
*/
|
||||
MVT.prototype.createFeature_ = function(pbf, rawFeature, opt_options) {
|
||||
const type = rawFeature.type;
|
||||
if (type === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let feature;
|
||||
const id = rawFeature.id;
|
||||
const values = rawFeature.properties;
|
||||
values[this.layerName_] = rawFeature.layer.name;
|
||||
|
||||
const flatCoordinates = [];
|
||||
const ends = [];
|
||||
this.readRawGeometry_(pbf, rawFeature, flatCoordinates, ends);
|
||||
|
||||
const geometryType = getGeometryType(type, ends.length);
|
||||
|
||||
if (this.featureClass_ === RenderFeature) {
|
||||
feature = new this.featureClass_(geometryType, flatCoordinates, ends, values, id);
|
||||
} else {
|
||||
let geom;
|
||||
if (geometryType == GeometryType.POLYGON) {
|
||||
const endss = [];
|
||||
let offset = 0;
|
||||
let prevEndIndex = 0;
|
||||
for (let i = 0, ii = ends.length; i < ii; ++i) {
|
||||
const end = ends[i];
|
||||
if (!linearRingIsClockwise(flatCoordinates, offset, end, 2)) {
|
||||
endss.push(ends.slice(prevEndIndex, i));
|
||||
prevEndIndex = i;
|
||||
}
|
||||
offset = end;
|
||||
}
|
||||
if (endss.length > 1) {
|
||||
geom = new MultiPolygon(flatCoordinates, GeometryLayout.XY, endss);
|
||||
} else {
|
||||
geom = new Polygon(flatCoordinates, GeometryLayout.XY, ends);
|
||||
}
|
||||
} else {
|
||||
geom = geometryType === GeometryType.POINT ? new Point(flatCoordinates, GeometryLayout.XY) :
|
||||
geometryType === GeometryType.LINE_STRING ? new LineString(flatCoordinates, GeometryLayout.XY) :
|
||||
geometryType === GeometryType.POLYGON ? new Polygon(flatCoordinates, GeometryLayout.XY, ends) :
|
||||
geometryType === GeometryType.MULTI_POINT ? new MultiPoint(flatCoordinates, GeometryLayout.XY) :
|
||||
geometryType === GeometryType.MULTI_LINE_STRING ? new MultiLineString(flatCoordinates, GeometryLayout.XY, ends) :
|
||||
null;
|
||||
}
|
||||
feature = new this.featureClass_();
|
||||
if (this.geometryName_) {
|
||||
feature.setGeometryName(this.geometryName_);
|
||||
}
|
||||
const geometry = transformWithOptions(geom, false, this.adaptOptions(opt_options));
|
||||
feature.setGeometry(geometry);
|
||||
feature.setId(id);
|
||||
feature.setProperties(values);
|
||||
}
|
||||
|
||||
return feature;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
MVT.prototype.getLastExtent = function() {
|
||||
return this.extent_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
MVT.prototype.getType = function() {
|
||||
return FormatType.ARRAY_BUFFER;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
MVT.prototype.readFeatures = function(source, opt_options) {
|
||||
const layers = this.layers_;
|
||||
|
||||
const pbf = new PBF(/** @type {ArrayBuffer} */ (source));
|
||||
const pbfLayers = pbf.readFields(layersPBFReader, {});
|
||||
/** @type {Array.<module:ol/Feature|module:ol/render/Feature>} */
|
||||
const features = [];
|
||||
for (const name in pbfLayers) {
|
||||
if (layers && layers.indexOf(name) == -1) {
|
||||
continue;
|
||||
}
|
||||
const pbfLayer = pbfLayers[name];
|
||||
|
||||
for (let i = 0, ii = pbfLayer.length; i < ii; ++i) {
|
||||
const rawFeature = readRawFeature(pbf, pbfLayer, i);
|
||||
features.push(this.createFeature_(pbf, rawFeature));
|
||||
}
|
||||
this.extent_ = pbfLayer ? [0, 0, pbfLayer.extent, pbfLayer.extent] : null;
|
||||
}
|
||||
|
||||
return features;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
MVT.prototype.readProjection = function(source) {
|
||||
return this.dataProjection;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Sets the layers that features will be read from.
|
||||
* @param {Array.<string>} layers Layers.
|
||||
* @api
|
||||
*/
|
||||
MVT.prototype.setLayers = function(layers) {
|
||||
this.layers_ = layers;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @override
|
||||
*/
|
||||
MVT.prototype.readFeature = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @override
|
||||
*/
|
||||
MVT.prototype.readGeometry = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @override
|
||||
*/
|
||||
MVT.prototype.writeFeature = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @override
|
||||
*/
|
||||
MVT.prototype.writeGeometry = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @override
|
||||
*/
|
||||
MVT.prototype.writeFeatures = function() {};
|
||||
export default MVT;
|
||||
|
||||
+64
-64
@@ -24,14 +24,74 @@ import {pushParseAndPop, makeStructureNS} from '../xml.js';
|
||||
* @extends {module:ol/format/XMLFeature}
|
||||
* @api
|
||||
*/
|
||||
const OSMXML = function() {
|
||||
XMLFeature.call(this);
|
||||
class OSMXML {
|
||||
constructor() {
|
||||
XMLFeature.call(this);
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.dataProjection = getProjection('EPSG:4326');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.dataProjection = getProjection('EPSG:4326');
|
||||
};
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
const options = this.getReadOptions(node, opt_options);
|
||||
if (node.localName == 'osm') {
|
||||
const state = pushParseAndPop({
|
||||
nodes: {},
|
||||
ways: [],
|
||||
features: []
|
||||
}, PARSERS, node, [options]);
|
||||
// parse nodes in ways
|
||||
for (let j = 0; j < state.ways.length; j++) {
|
||||
const values = /** @type {Object} */ (state.ways[j]);
|
||||
/** @type {Array.<number>} */
|
||||
const flatCoordinates = [];
|
||||
for (let i = 0, ii = values.ndrefs.length; i < ii; i++) {
|
||||
const point = state.nodes[values.ndrefs[i]];
|
||||
extend(flatCoordinates, point);
|
||||
}
|
||||
let geometry;
|
||||
if (values.ndrefs[0] == values.ndrefs[values.ndrefs.length - 1]) {
|
||||
// closed way
|
||||
geometry = new Polygon(flatCoordinates, GeometryLayout.XY, [flatCoordinates.length]);
|
||||
} else {
|
||||
geometry = new LineString(flatCoordinates, GeometryLayout.XY);
|
||||
}
|
||||
transformWithOptions(geometry, false, options);
|
||||
const feature = new Feature(geometry);
|
||||
feature.setId(values.id);
|
||||
feature.setProperties(values.tags);
|
||||
state.features.push(feature);
|
||||
}
|
||||
if (state.features) {
|
||||
return state.features;
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeatureNode(feature, opt_options) {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeaturesNode(features, opt_options) {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeGeometryNode(geometry, opt_options) {}
|
||||
}
|
||||
|
||||
inherits(OSMXML, XMLFeature);
|
||||
|
||||
@@ -152,47 +212,6 @@ function readTag(node, objectStack) {
|
||||
OSMXML.prototype.readFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
OSMXML.prototype.readFeaturesFromNode = function(node, opt_options) {
|
||||
const options = this.getReadOptions(node, opt_options);
|
||||
if (node.localName == 'osm') {
|
||||
const state = pushParseAndPop({
|
||||
nodes: {},
|
||||
ways: [],
|
||||
features: []
|
||||
}, PARSERS, node, [options]);
|
||||
// parse nodes in ways
|
||||
for (let j = 0; j < state.ways.length; j++) {
|
||||
const values = /** @type {Object} */ (state.ways[j]);
|
||||
/** @type {Array.<number>} */
|
||||
const flatCoordinates = [];
|
||||
for (let i = 0, ii = values.ndrefs.length; i < ii; i++) {
|
||||
const point = state.nodes[values.ndrefs[i]];
|
||||
extend(flatCoordinates, point);
|
||||
}
|
||||
let geometry;
|
||||
if (values.ndrefs[0] == values.ndrefs[values.ndrefs.length - 1]) {
|
||||
// closed way
|
||||
geometry = new Polygon(flatCoordinates, GeometryLayout.XY, [flatCoordinates.length]);
|
||||
} else {
|
||||
geometry = new LineString(flatCoordinates, GeometryLayout.XY);
|
||||
}
|
||||
transformWithOptions(geometry, false, options);
|
||||
const feature = new Feature(geometry);
|
||||
feature.setId(values.id);
|
||||
feature.setProperties(values.tags);
|
||||
state.features.push(feature);
|
||||
}
|
||||
if (state.features) {
|
||||
return state.features;
|
||||
}
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the projection from an OSM source.
|
||||
*
|
||||
@@ -204,23 +223,4 @@ OSMXML.prototype.readFeaturesFromNode = function(node, opt_options) {
|
||||
OSMXML.prototype.readProjection;
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
OSMXML.prototype.writeFeatureNode = function(feature, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
OSMXML.prototype.writeFeaturesNode = function(features, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
OSMXML.prototype.writeGeometryNode = function(geometry, opt_options) {};
|
||||
export default OSMXML;
|
||||
|
||||
+26
-26
@@ -11,9 +11,32 @@ import {makeObjectPropertyPusher, makeObjectPropertySetter, makeStructureNS, pus
|
||||
* @constructor
|
||||
* @extends {module:ol/format/XML}
|
||||
*/
|
||||
const OWS = function() {
|
||||
XML.call(this);
|
||||
};
|
||||
class OWS {
|
||||
constructor() {
|
||||
XML.call(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readFromDocument(doc) {
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
return this.readFromNode(n);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readFromNode(node) {
|
||||
const owsObject = pushParseAndPop({},
|
||||
PARSERS, node, []);
|
||||
return owsObject ? owsObject : null;
|
||||
}
|
||||
}
|
||||
|
||||
inherits(OWS, XML);
|
||||
|
||||
@@ -187,29 +210,6 @@ const SERVICE_PROVIDER_PARSERS =
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
OWS.prototype.readFromDocument = function(doc) {
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
return this.readFromNode(n);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
OWS.prototype.readFromNode = function(node) {
|
||||
const owsObject = pushParseAndPop({},
|
||||
PARSERS, node, []);
|
||||
return owsObject ? owsObject : null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
|
||||
+80
-82
@@ -32,30 +32,98 @@ import {get as getProjection} from '../proj.js';
|
||||
* @param {module:ol/format/Polyline~Options=} opt_options Optional configuration object.
|
||||
* @api
|
||||
*/
|
||||
const Polyline = function(opt_options) {
|
||||
class Polyline {
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
TextFeature.call(this);
|
||||
TextFeature.call(this);
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.dataProjection = getProjection('EPSG:4326');
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.factor_ = options.factor ? options.factor : 1e5;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/geom/GeometryLayout}
|
||||
*/
|
||||
this.geometryLayout_ = options.geometryLayout ?
|
||||
options.geometryLayout : GeometryLayout.XY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.dataProjection = getProjection('EPSG:4326');
|
||||
readFeatureFromText(text, opt_options) {
|
||||
const geometry = this.readGeometryFromText(text, opt_options);
|
||||
return new Feature(geometry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.factor_ = options.factor ? options.factor : 1e5;
|
||||
readFeaturesFromText(text, opt_options) {
|
||||
const feature = this.readFeatureFromText(text, opt_options);
|
||||
return [feature];
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/geom/GeometryLayout}
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.geometryLayout_ = options.geometryLayout ?
|
||||
options.geometryLayout : GeometryLayout.XY;
|
||||
};
|
||||
readGeometryFromText(text, opt_options) {
|
||||
const stride = getStrideForLayout(this.geometryLayout_);
|
||||
const flatCoordinates = decodeDeltas(text, stride, this.factor_);
|
||||
flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
|
||||
const coordinates = inflateCoordinates(flatCoordinates, 0, flatCoordinates.length, stride);
|
||||
|
||||
return (
|
||||
/** @type {module:ol/geom/Geometry} */ (transformWithOptions(
|
||||
new LineString(coordinates, this.geometryLayout_),
|
||||
false,
|
||||
this.adaptOptions(opt_options)
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeatureText(feature, opt_options) {
|
||||
const geometry = feature.getGeometry();
|
||||
if (geometry) {
|
||||
return this.writeGeometryText(geometry, opt_options);
|
||||
} else {
|
||||
assert(false, 40); // Expected `feature` to have a geometry
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeaturesText(features, opt_options) {
|
||||
return this.writeFeatureText(features[0], opt_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeGeometryText(geometry, opt_options) {
|
||||
geometry = /** @type {module:ol/geom/LineString} */
|
||||
(transformWithOptions(geometry, true, this.adaptOptions(opt_options)));
|
||||
const flatCoordinates = geometry.getFlatCoordinates();
|
||||
const stride = geometry.getStride();
|
||||
flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
|
||||
return encodeDeltas(flatCoordinates, stride, this.factor_);
|
||||
}
|
||||
}
|
||||
|
||||
inherits(Polyline, TextFeature);
|
||||
|
||||
@@ -277,15 +345,6 @@ export function encodeUnsignedInteger(num) {
|
||||
Polyline.prototype.readFeature;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Polyline.prototype.readFeatureFromText = function(text, opt_options) {
|
||||
const geometry = this.readGeometryFromText(text, opt_options);
|
||||
return new Feature(geometry);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the feature from the source. As Polyline sources contain a single
|
||||
* feature, this will return the feature in an array.
|
||||
@@ -299,15 +358,6 @@ Polyline.prototype.readFeatureFromText = function(text, opt_options) {
|
||||
Polyline.prototype.readFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Polyline.prototype.readFeaturesFromText = function(text, opt_options) {
|
||||
const feature = this.readFeatureFromText(text, opt_options);
|
||||
return [feature];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the geometry from the source.
|
||||
*
|
||||
@@ -320,25 +370,6 @@ Polyline.prototype.readFeaturesFromText = function(text, opt_options) {
|
||||
Polyline.prototype.readGeometry;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Polyline.prototype.readGeometryFromText = function(text, opt_options) {
|
||||
const stride = getStrideForLayout(this.geometryLayout_);
|
||||
const flatCoordinates = decodeDeltas(text, stride, this.factor_);
|
||||
flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
|
||||
const coordinates = inflateCoordinates(flatCoordinates, 0, flatCoordinates.length, stride);
|
||||
|
||||
return (
|
||||
/** @type {module:ol/geom/Geometry} */ (transformWithOptions(
|
||||
new LineString(coordinates, this.geometryLayout_),
|
||||
false,
|
||||
this.adaptOptions(opt_options)
|
||||
))
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the projection from a Polyline source.
|
||||
*
|
||||
@@ -350,28 +381,6 @@ Polyline.prototype.readGeometryFromText = function(text, opt_options) {
|
||||
Polyline.prototype.readProjection;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Polyline.prototype.writeFeatureText = function(feature, opt_options) {
|
||||
const geometry = feature.getGeometry();
|
||||
if (geometry) {
|
||||
return this.writeGeometryText(geometry, opt_options);
|
||||
} else {
|
||||
assert(false, 40); // Expected `feature` to have a geometry
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Polyline.prototype.writeFeaturesText = function(features, opt_options) {
|
||||
return this.writeFeatureText(features[0], opt_options);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Write a single geometry in Polyline format.
|
||||
*
|
||||
@@ -384,15 +393,4 @@ Polyline.prototype.writeFeaturesText = function(features, opt_options) {
|
||||
Polyline.prototype.writeGeometry;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
Polyline.prototype.writeGeometryText = function(geometry, opt_options) {
|
||||
geometry = /** @type {module:ol/geom/LineString} */
|
||||
(transformWithOptions(geometry, true, this.adaptOptions(opt_options)));
|
||||
const flatCoordinates = geometry.getFlatCoordinates();
|
||||
const stride = geometry.getStride();
|
||||
flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
|
||||
return encodeDeltas(flatCoordinates, stride, this.factor_);
|
||||
};
|
||||
export default Polyline;
|
||||
|
||||
+124
-135
@@ -15,9 +15,130 @@ import FormatType from '../format/FormatType.js';
|
||||
* @abstract
|
||||
* @extends {module:ol/format/Feature}
|
||||
*/
|
||||
const TextFeature = function() {
|
||||
FeatureFormat.call(this);
|
||||
};
|
||||
class TextFeature {
|
||||
constructor() {
|
||||
FeatureFormat.call(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
getType() {
|
||||
return FormatType.TEXT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readFeature(source, opt_options) {
|
||||
return this.readFeatureFromText(getText(source), this.adaptOptions(opt_options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {string} text Text.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @protected
|
||||
* @return {module:ol/Feature} Feature.
|
||||
*/
|
||||
readFeatureFromText(text, opt_options) {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readFeatures(source, opt_options) {
|
||||
return this.readFeaturesFromText(getText(source), this.adaptOptions(opt_options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {string} text Text.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @protected
|
||||
* @return {Array.<module:ol/Feature>} Features.
|
||||
*/
|
||||
readFeaturesFromText(text, opt_options) {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readGeometry(source, opt_options) {
|
||||
return this.readGeometryFromText(getText(source), this.adaptOptions(opt_options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {string} text Text.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @protected
|
||||
* @return {module:ol/geom/Geometry} Geometry.
|
||||
*/
|
||||
readGeometryFromText(text, opt_options) {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readProjection(source) {
|
||||
return this.readProjectionFromText(getText(source));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} text Text.
|
||||
* @protected
|
||||
* @return {module:ol/proj/Projection} Projection.
|
||||
*/
|
||||
readProjectionFromText(text) {
|
||||
return this.dataProjection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeature(feature, opt_options) {
|
||||
return this.writeFeatureText(feature, this.adaptOptions(opt_options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {module:ol/Feature} feature Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
writeFeatureText(feature, opt_options) {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeatures(features, opt_options) {
|
||||
return this.writeFeaturesText(features, this.adaptOptions(opt_options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
writeFeaturesText(features, opt_options) {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeGeometry(geometry, opt_options) {
|
||||
return this.writeGeometryText(geometry, this.adaptOptions(opt_options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {module:ol/geom/Geometry} geometry Geometry.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
writeGeometryText(geometry, opt_options) {}
|
||||
}
|
||||
|
||||
inherits(TextFeature, FeatureFormat);
|
||||
|
||||
@@ -35,136 +156,4 @@ function getText(source) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
TextFeature.prototype.getType = function() {
|
||||
return FormatType.TEXT;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
TextFeature.prototype.readFeature = function(source, opt_options) {
|
||||
return this.readFeatureFromText(getText(source), this.adaptOptions(opt_options));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {string} text Text.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @protected
|
||||
* @return {module:ol/Feature} Feature.
|
||||
*/
|
||||
TextFeature.prototype.readFeatureFromText = function(text, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
TextFeature.prototype.readFeatures = function(source, opt_options) {
|
||||
return this.readFeaturesFromText(getText(source), this.adaptOptions(opt_options));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {string} text Text.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @protected
|
||||
* @return {Array.<module:ol/Feature>} Features.
|
||||
*/
|
||||
TextFeature.prototype.readFeaturesFromText = function(text, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
TextFeature.prototype.readGeometry = function(source, opt_options) {
|
||||
return this.readGeometryFromText(getText(source), this.adaptOptions(opt_options));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {string} text Text.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Read options.
|
||||
* @protected
|
||||
* @return {module:ol/geom/Geometry} Geometry.
|
||||
*/
|
||||
TextFeature.prototype.readGeometryFromText = function(text, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
TextFeature.prototype.readProjection = function(source) {
|
||||
return this.readProjectionFromText(getText(source));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} text Text.
|
||||
* @protected
|
||||
* @return {module:ol/proj/Projection} Projection.
|
||||
*/
|
||||
TextFeature.prototype.readProjectionFromText = function(text) {
|
||||
return this.dataProjection;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
TextFeature.prototype.writeFeature = function(feature, opt_options) {
|
||||
return this.writeFeatureText(feature, this.adaptOptions(opt_options));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {module:ol/Feature} feature Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
TextFeature.prototype.writeFeatureText = function(feature, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
TextFeature.prototype.writeFeatures = function(features, opt_options) {
|
||||
return this.writeFeaturesText(features, this.adaptOptions(opt_options));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
TextFeature.prototype.writeFeaturesText = function(features, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
TextFeature.prototype.writeGeometry = function(geometry, opt_options) {
|
||||
return this.writeGeometryText(geometry, this.adaptOptions(opt_options));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {module:ol/geom/Geometry} geometry Geometry.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
TextFeature.prototype.writeGeometryText = function(geometry, opt_options) {};
|
||||
export default TextFeature;
|
||||
|
||||
+97
-100
@@ -48,32 +48,112 @@ import {get as getProjection} from '../proj.js';
|
||||
* @param {module:ol/format/TopoJSON~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const TopoJSON = function(opt_options) {
|
||||
class TopoJSON {
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
JSONFeature.call(this);
|
||||
JSONFeature.call(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.layerName_ = options.layerName;
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.layerName_ = options.layerName;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
this.layers_ = options.layers ? options.layers : null;
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
this.layers_ = options.layers ? options.layers : null;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.dataProjection = getProjection(
|
||||
options.dataProjection ?
|
||||
options.dataProjection : 'EPSG:4326');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.dataProjection = getProjection(
|
||||
options.dataProjection ?
|
||||
options.dataProjection : 'EPSG:4326');
|
||||
readFeaturesFromObject(object, opt_options) {
|
||||
if (object.type == 'Topology') {
|
||||
const topoJSONTopology = /** @type {TopoJSONTopology} */ (object);
|
||||
let transform, scale = null, translate = null;
|
||||
if (topoJSONTopology.transform) {
|
||||
transform = topoJSONTopology.transform;
|
||||
scale = transform.scale;
|
||||
translate = transform.translate;
|
||||
}
|
||||
const arcs = topoJSONTopology.arcs;
|
||||
if (transform) {
|
||||
transformArcs(arcs, scale, translate);
|
||||
}
|
||||
/** @type {Array.<module:ol/Feature>} */
|
||||
const features = [];
|
||||
const topoJSONFeatures = topoJSONTopology.objects;
|
||||
const property = this.layerName_;
|
||||
let feature;
|
||||
for (const objectName in topoJSONFeatures) {
|
||||
if (this.layers_ && this.layers_.indexOf(objectName) == -1) {
|
||||
continue;
|
||||
}
|
||||
if (topoJSONFeatures[objectName].type === 'GeometryCollection') {
|
||||
feature = /** @type {TopoJSONGeometryCollection} */ (topoJSONFeatures[objectName]);
|
||||
features.push.apply(features, readFeaturesFromGeometryCollection(
|
||||
feature, arcs, scale, translate, property, objectName, opt_options));
|
||||
} else {
|
||||
feature = /** @type {TopoJSONGeometry} */ (topoJSONFeatures[objectName]);
|
||||
features.push(readFeatureFromGeometry(
|
||||
feature, arcs, scale, translate, property, objectName, opt_options));
|
||||
}
|
||||
}
|
||||
return features;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readProjectionFromObject(object) {
|
||||
return this.dataProjection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeatureObject(feature, opt_options) {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeaturesObject(features, opt_options) {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeGeometryObject(geometry, opt_options) {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @override
|
||||
*/
|
||||
readGeometryFromObject() {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @override
|
||||
*/
|
||||
readFeatureFromObject() {}
|
||||
}
|
||||
|
||||
inherits(TopoJSON, JSONFeature);
|
||||
|
||||
@@ -309,48 +389,6 @@ function readFeatureFromGeometry(object, arcs, scale, translate, property, name,
|
||||
TopoJSON.prototype.readFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
TopoJSON.prototype.readFeaturesFromObject = function(object, opt_options) {
|
||||
if (object.type == 'Topology') {
|
||||
const topoJSONTopology = /** @type {TopoJSONTopology} */ (object);
|
||||
let transform, scale = null, translate = null;
|
||||
if (topoJSONTopology.transform) {
|
||||
transform = topoJSONTopology.transform;
|
||||
scale = transform.scale;
|
||||
translate = transform.translate;
|
||||
}
|
||||
const arcs = topoJSONTopology.arcs;
|
||||
if (transform) {
|
||||
transformArcs(arcs, scale, translate);
|
||||
}
|
||||
/** @type {Array.<module:ol/Feature>} */
|
||||
const features = [];
|
||||
const topoJSONFeatures = topoJSONTopology.objects;
|
||||
const property = this.layerName_;
|
||||
let feature;
|
||||
for (const objectName in topoJSONFeatures) {
|
||||
if (this.layers_ && this.layers_.indexOf(objectName) == -1) {
|
||||
continue;
|
||||
}
|
||||
if (topoJSONFeatures[objectName].type === 'GeometryCollection') {
|
||||
feature = /** @type {TopoJSONGeometryCollection} */ (topoJSONFeatures[objectName]);
|
||||
features.push.apply(features, readFeaturesFromGeometryCollection(
|
||||
feature, arcs, scale, translate, property, objectName, opt_options));
|
||||
} else {
|
||||
feature = /** @type {TopoJSONGeometry} */ (topoJSONFeatures[objectName]);
|
||||
features.push(readFeatureFromGeometry(
|
||||
feature, arcs, scale, translate, property, objectName, opt_options));
|
||||
}
|
||||
}
|
||||
return features;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Apply a linear transform to array of arcs. The provided array of arcs is
|
||||
* modified in place.
|
||||
@@ -412,45 +450,4 @@ function transformVertex(vertex, scale, translate) {
|
||||
TopoJSON.prototype.readProjection;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
TopoJSON.prototype.readProjectionFromObject = function(object) {
|
||||
return this.dataProjection;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
TopoJSON.prototype.writeFeatureObject = function(feature, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
TopoJSON.prototype.writeFeaturesObject = function(features, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
TopoJSON.prototype.writeGeometryObject = function(geometry, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @override
|
||||
*/
|
||||
TopoJSON.prototype.readGeometryFromObject = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @override
|
||||
*/
|
||||
TopoJSON.prototype.readFeatureFromObject = function() {};
|
||||
export default TopoJSON;
|
||||
|
||||
+315
-324
@@ -143,57 +143,338 @@ const DEFAULT_VERSION = '1.1.0';
|
||||
* @extends {module:ol/format/XMLFeature}
|
||||
* @api
|
||||
*/
|
||||
const WFS = function(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
class WFS {
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<string>|string|undefined}
|
||||
*/
|
||||
this.featureType_ = options.featureType;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string, string>|string|undefined}
|
||||
*/
|
||||
this.featureNS_ = options.featureNS;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/format/GMLBase}
|
||||
*/
|
||||
this.gmlFormat_ = options.gmlFormat ?
|
||||
options.gmlFormat : new GML3();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.schemaLocation_ = options.schemaLocation ?
|
||||
options.schemaLocation : SCHEMA_LOCATIONS[DEFAULT_VERSION];
|
||||
|
||||
XMLFeature.call(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<string>|string|undefined}
|
||||
* @return {Array.<string>|string|undefined} featureType
|
||||
*/
|
||||
this.featureType_ = options.featureType;
|
||||
getFeatureType() {
|
||||
return this.featureType_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string, string>|string|undefined}
|
||||
* @param {Array.<string>|string|undefined} featureType Feature type(s) to parse.
|
||||
*/
|
||||
this.featureNS_ = options.featureNS;
|
||||
setFeatureType(featureType) {
|
||||
this.featureType_ = featureType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/format/GMLBase}
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.gmlFormat_ = options.gmlFormat ?
|
||||
options.gmlFormat : new GML3();
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
const context = /** @type {module:ol/xml~NodeStackItem} */ ({
|
||||
'featureType': this.featureType_,
|
||||
'featureNS': this.featureNS_
|
||||
});
|
||||
assign(context, this.getReadOptions(node, opt_options ? opt_options : {}));
|
||||
const objectStack = [context];
|
||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS[GMLNS][
|
||||
'featureMember'] =
|
||||
makeArrayPusher(GMLBase.prototype.readFeaturesInternal);
|
||||
let features = pushParseAndPop([],
|
||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
|
||||
objectStack, this.gmlFormat_);
|
||||
if (!features) {
|
||||
features = [];
|
||||
}
|
||||
return features;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
* Read transaction response of the source.
|
||||
*
|
||||
* @param {Document|Node|Object|string} source Source.
|
||||
* @return {module:ol/format/WFS~TransactionResponse|undefined} Transaction response.
|
||||
* @api
|
||||
*/
|
||||
this.schemaLocation_ = options.schemaLocation ?
|
||||
options.schemaLocation : SCHEMA_LOCATIONS[DEFAULT_VERSION];
|
||||
readTransactionResponse(source) {
|
||||
if (isDocument(source)) {
|
||||
return this.readTransactionResponseFromDocument(
|
||||
/** @type {Document} */ (source));
|
||||
} else if (isNode(source)) {
|
||||
return this.readTransactionResponseFromNode(/** @type {Node} */ (source));
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readTransactionResponseFromDocument(doc);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
XMLFeature.call(this);
|
||||
};
|
||||
/**
|
||||
* Read feature collection metadata of the source.
|
||||
*
|
||||
* @param {Document|Node|Object|string} source Source.
|
||||
* @return {module:ol/format/WFS~FeatureCollectionMetadata|undefined}
|
||||
* FeatureCollection metadata.
|
||||
* @api
|
||||
*/
|
||||
readFeatureCollectionMetadata(source) {
|
||||
if (isDocument(source)) {
|
||||
return this.readFeatureCollectionMetadataFromDocument(
|
||||
/** @type {Document} */ (source));
|
||||
} else if (isNode(source)) {
|
||||
return this.readFeatureCollectionMetadataFromNode(
|
||||
/** @type {Node} */ (source));
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readFeatureCollectionMetadataFromDocument(doc);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @return {module:ol/format/WFS~FeatureCollectionMetadata|undefined}
|
||||
* FeatureCollection metadata.
|
||||
*/
|
||||
readFeatureCollectionMetadataFromDocument(doc) {
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
return this.readFeatureCollectionMetadataFromNode(n);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @return {module:ol/format/WFS~FeatureCollectionMetadata|undefined}
|
||||
* FeatureCollection metadata.
|
||||
*/
|
||||
readFeatureCollectionMetadataFromNode(node) {
|
||||
const result = {};
|
||||
const value = readNonNegativeIntegerString(
|
||||
node.getAttribute('numberOfFeatures'));
|
||||
result['numberOfFeatures'] = value;
|
||||
return pushParseAndPop(
|
||||
/** @type {module:ol/format/WFS~FeatureCollectionMetadata} */ (result),
|
||||
FEATURE_COLLECTION_PARSERS, node, [], this.gmlFormat_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @return {module:ol/format/WFS~TransactionResponse|undefined} Transaction response.
|
||||
*/
|
||||
readTransactionResponseFromDocument(doc) {
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
return this.readTransactionResponseFromNode(n);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @return {module:ol/format/WFS~TransactionResponse|undefined} Transaction response.
|
||||
*/
|
||||
readTransactionResponseFromNode(node) {
|
||||
return pushParseAndPop(
|
||||
/** @type {module:ol/format/WFS~TransactionResponse} */({}),
|
||||
TRANSACTION_RESPONSE_PARSERS, node, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode format as WFS `GetFeature` and return the Node.
|
||||
*
|
||||
* @param {module:ol/format/WFS~WriteGetFeatureOptions} options Options.
|
||||
* @return {Node} Result.
|
||||
* @api
|
||||
*/
|
||||
writeGetFeature(options) {
|
||||
const node = createElementNS(WFSNS, 'GetFeature');
|
||||
node.setAttribute('service', 'WFS');
|
||||
node.setAttribute('version', '1.1.0');
|
||||
let filter;
|
||||
if (options) {
|
||||
if (options.handle) {
|
||||
node.setAttribute('handle', options.handle);
|
||||
}
|
||||
if (options.outputFormat) {
|
||||
node.setAttribute('outputFormat', options.outputFormat);
|
||||
}
|
||||
if (options.maxFeatures !== undefined) {
|
||||
node.setAttribute('maxFeatures', options.maxFeatures);
|
||||
}
|
||||
if (options.resultType) {
|
||||
node.setAttribute('resultType', options.resultType);
|
||||
}
|
||||
if (options.startIndex !== undefined) {
|
||||
node.setAttribute('startIndex', options.startIndex);
|
||||
}
|
||||
if (options.count !== undefined) {
|
||||
node.setAttribute('count', options.count);
|
||||
}
|
||||
filter = options.filter;
|
||||
if (options.bbox) {
|
||||
assert(options.geometryName,
|
||||
12); // `options.geometryName` must also be provided when `options.bbox` is set
|
||||
const bbox = bboxFilter(
|
||||
/** @type {string} */ (options.geometryName), options.bbox, options.srsName);
|
||||
if (filter) {
|
||||
// if bbox and filter are both set, combine the two into a single filter
|
||||
filter = andFilter(filter, bbox);
|
||||
} else {
|
||||
filter = bbox;
|
||||
}
|
||||
}
|
||||
}
|
||||
node.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', this.schemaLocation_);
|
||||
/** @type {module:ol/xml~NodeStackItem} */
|
||||
const context = {
|
||||
node: node,
|
||||
'srsName': options.srsName,
|
||||
'featureNS': options.featureNS ? options.featureNS : this.featureNS_,
|
||||
'featurePrefix': options.featurePrefix,
|
||||
'geometryName': options.geometryName,
|
||||
'filter': filter,
|
||||
'propertyNames': options.propertyNames ? options.propertyNames : []
|
||||
};
|
||||
assert(Array.isArray(options.featureTypes),
|
||||
11); // `options.featureTypes` should be an Array
|
||||
writeGetFeature(node, /** @type {!Array.<string>} */ (options.featureTypes), [context]);
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode format as WFS `Transaction` and return the Node.
|
||||
*
|
||||
* @param {Array.<module:ol/Feature>} inserts The features to insert.
|
||||
* @param {Array.<module:ol/Feature>} updates The features to update.
|
||||
* @param {Array.<module:ol/Feature>} deletes The features to delete.
|
||||
* @param {module:ol/format/WFS~WriteTransactionOptions} options Write options.
|
||||
* @return {Node} Result.
|
||||
* @api
|
||||
*/
|
||||
writeTransaction(inserts, updates, deletes, options) {
|
||||
const objectStack = [];
|
||||
const node = createElementNS(WFSNS, 'Transaction');
|
||||
const version = options.version ? options.version : DEFAULT_VERSION;
|
||||
const gmlVersion = version === '1.0.0' ? 2 : 3;
|
||||
node.setAttribute('service', 'WFS');
|
||||
node.setAttribute('version', version);
|
||||
let baseObj;
|
||||
/** @type {module:ol/xml~NodeStackItem} */
|
||||
let obj;
|
||||
if (options) {
|
||||
baseObj = options.gmlOptions ? options.gmlOptions : {};
|
||||
if (options.handle) {
|
||||
node.setAttribute('handle', options.handle);
|
||||
}
|
||||
}
|
||||
const schemaLocation = SCHEMA_LOCATIONS[version];
|
||||
node.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', schemaLocation);
|
||||
const featurePrefix = options.featurePrefix ? options.featurePrefix : FEATURE_PREFIX;
|
||||
if (inserts) {
|
||||
obj = {node: node, 'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName};
|
||||
assign(obj, baseObj);
|
||||
pushSerializeAndPop(obj,
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Insert'), inserts,
|
||||
objectStack);
|
||||
}
|
||||
if (updates) {
|
||||
obj = {node: node, 'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName};
|
||||
assign(obj, baseObj);
|
||||
pushSerializeAndPop(obj,
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Update'), updates,
|
||||
objectStack);
|
||||
}
|
||||
if (deletes) {
|
||||
pushSerializeAndPop({node: node, 'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'srsName': options.srsName},
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Delete'), deletes,
|
||||
objectStack);
|
||||
}
|
||||
if (options.nativeElements) {
|
||||
pushSerializeAndPop({node: node, 'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'srsName': options.srsName},
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Native'), options.nativeElements,
|
||||
objectStack);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readProjectionFromDocument(doc) {
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
return this.readProjectionFromNode(n);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readProjectionFromNode(node) {
|
||||
if (node.firstElementChild &&
|
||||
node.firstElementChild.firstElementChild) {
|
||||
node = node.firstElementChild.firstElementChild;
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
if (!(n.childNodes.length === 0 ||
|
||||
(n.childNodes.length === 1 &&
|
||||
n.firstChild.nodeType === 3))) {
|
||||
const objectStack = [{}];
|
||||
this.gmlFormat_.readGeometryElement(n, objectStack);
|
||||
return getProjection(objectStack.pop().srsName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
inherits(WFS, XMLFeature);
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<string>|string|undefined} featureType
|
||||
*/
|
||||
WFS.prototype.getFeatureType = function() {
|
||||
return this.featureType_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<string>|string|undefined} featureType Feature type(s) to parse.
|
||||
*/
|
||||
WFS.prototype.setFeatureType = function(featureType) {
|
||||
this.featureType_ = featureType;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read all features from a WFS FeatureCollection.
|
||||
*
|
||||
@@ -206,90 +487,6 @@ WFS.prototype.setFeatureType = function(featureType) {
|
||||
WFS.prototype.readFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
WFS.prototype.readFeaturesFromNode = function(node, opt_options) {
|
||||
const context = /** @type {module:ol/xml~NodeStackItem} */ ({
|
||||
'featureType': this.featureType_,
|
||||
'featureNS': this.featureNS_
|
||||
});
|
||||
assign(context, this.getReadOptions(node, opt_options ? opt_options : {}));
|
||||
const objectStack = [context];
|
||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS[GMLNS][
|
||||
'featureMember'] =
|
||||
makeArrayPusher(GMLBase.prototype.readFeaturesInternal);
|
||||
let features = pushParseAndPop([],
|
||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
|
||||
objectStack, this.gmlFormat_);
|
||||
if (!features) {
|
||||
features = [];
|
||||
}
|
||||
return features;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read transaction response of the source.
|
||||
*
|
||||
* @param {Document|Node|Object|string} source Source.
|
||||
* @return {module:ol/format/WFS~TransactionResponse|undefined} Transaction response.
|
||||
* @api
|
||||
*/
|
||||
WFS.prototype.readTransactionResponse = function(source) {
|
||||
if (isDocument(source)) {
|
||||
return this.readTransactionResponseFromDocument(
|
||||
/** @type {Document} */ (source));
|
||||
} else if (isNode(source)) {
|
||||
return this.readTransactionResponseFromNode(/** @type {Node} */ (source));
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readTransactionResponseFromDocument(doc);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read feature collection metadata of the source.
|
||||
*
|
||||
* @param {Document|Node|Object|string} source Source.
|
||||
* @return {module:ol/format/WFS~FeatureCollectionMetadata|undefined}
|
||||
* FeatureCollection metadata.
|
||||
* @api
|
||||
*/
|
||||
WFS.prototype.readFeatureCollectionMetadata = function(source) {
|
||||
if (isDocument(source)) {
|
||||
return this.readFeatureCollectionMetadataFromDocument(
|
||||
/** @type {Document} */ (source));
|
||||
} else if (isNode(source)) {
|
||||
return this.readFeatureCollectionMetadataFromNode(
|
||||
/** @type {Node} */ (source));
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readFeatureCollectionMetadataFromDocument(doc);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @return {module:ol/format/WFS~FeatureCollectionMetadata|undefined}
|
||||
* FeatureCollection metadata.
|
||||
*/
|
||||
WFS.prototype.readFeatureCollectionMetadataFromDocument = function(doc) {
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
return this.readFeatureCollectionMetadataFromNode(n);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
|
||||
@@ -302,22 +499,6 @@ const FEATURE_COLLECTION_PARSERS = {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @return {module:ol/format/WFS~FeatureCollectionMetadata|undefined}
|
||||
* FeatureCollection metadata.
|
||||
*/
|
||||
WFS.prototype.readFeatureCollectionMetadataFromNode = function(node) {
|
||||
const result = {};
|
||||
const value = readNonNegativeIntegerString(
|
||||
node.getAttribute('numberOfFeatures'));
|
||||
result['numberOfFeatures'] = value;
|
||||
return pushParseAndPop(
|
||||
/** @type {module:ol/format/WFS~FeatureCollectionMetadata} */ (result),
|
||||
FEATURE_COLLECTION_PARSERS, node, [], this.gmlFormat_);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, Object.<string, module:ol/xml~Parser>>}
|
||||
@@ -400,31 +581,6 @@ const TRANSACTION_RESPONSE_PARSERS = {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @return {module:ol/format/WFS~TransactionResponse|undefined} Transaction response.
|
||||
*/
|
||||
WFS.prototype.readTransactionResponseFromDocument = function(doc) {
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
return this.readTransactionResponseFromNode(n);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @return {module:ol/format/WFS~TransactionResponse|undefined} Transaction response.
|
||||
*/
|
||||
WFS.prototype.readTransactionResponseFromNode = function(node) {
|
||||
return pushParseAndPop(
|
||||
/** @type {module:ol/format/WFS~TransactionResponse} */({}),
|
||||
TRANSACTION_RESPONSE_PARSERS, node, []);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object.<string, Object.<string, module:ol/xml~Serializer>>}
|
||||
*/
|
||||
@@ -942,138 +1098,6 @@ function writeGetFeature(node, featureTypes, objectStack) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encode format as WFS `GetFeature` and return the Node.
|
||||
*
|
||||
* @param {module:ol/format/WFS~WriteGetFeatureOptions} options Options.
|
||||
* @return {Node} Result.
|
||||
* @api
|
||||
*/
|
||||
WFS.prototype.writeGetFeature = function(options) {
|
||||
const node = createElementNS(WFSNS, 'GetFeature');
|
||||
node.setAttribute('service', 'WFS');
|
||||
node.setAttribute('version', '1.1.0');
|
||||
let filter;
|
||||
if (options) {
|
||||
if (options.handle) {
|
||||
node.setAttribute('handle', options.handle);
|
||||
}
|
||||
if (options.outputFormat) {
|
||||
node.setAttribute('outputFormat', options.outputFormat);
|
||||
}
|
||||
if (options.maxFeatures !== undefined) {
|
||||
node.setAttribute('maxFeatures', options.maxFeatures);
|
||||
}
|
||||
if (options.resultType) {
|
||||
node.setAttribute('resultType', options.resultType);
|
||||
}
|
||||
if (options.startIndex !== undefined) {
|
||||
node.setAttribute('startIndex', options.startIndex);
|
||||
}
|
||||
if (options.count !== undefined) {
|
||||
node.setAttribute('count', options.count);
|
||||
}
|
||||
filter = options.filter;
|
||||
if (options.bbox) {
|
||||
assert(options.geometryName,
|
||||
12); // `options.geometryName` must also be provided when `options.bbox` is set
|
||||
const bbox = bboxFilter(
|
||||
/** @type {string} */ (options.geometryName), options.bbox, options.srsName);
|
||||
if (filter) {
|
||||
// if bbox and filter are both set, combine the two into a single filter
|
||||
filter = andFilter(filter, bbox);
|
||||
} else {
|
||||
filter = bbox;
|
||||
}
|
||||
}
|
||||
}
|
||||
node.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', this.schemaLocation_);
|
||||
/** @type {module:ol/xml~NodeStackItem} */
|
||||
const context = {
|
||||
node: node,
|
||||
'srsName': options.srsName,
|
||||
'featureNS': options.featureNS ? options.featureNS : this.featureNS_,
|
||||
'featurePrefix': options.featurePrefix,
|
||||
'geometryName': options.geometryName,
|
||||
'filter': filter,
|
||||
'propertyNames': options.propertyNames ? options.propertyNames : []
|
||||
};
|
||||
assert(Array.isArray(options.featureTypes),
|
||||
11); // `options.featureTypes` should be an Array
|
||||
writeGetFeature(node, /** @type {!Array.<string>} */ (options.featureTypes), [context]);
|
||||
return node;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode format as WFS `Transaction` and return the Node.
|
||||
*
|
||||
* @param {Array.<module:ol/Feature>} inserts The features to insert.
|
||||
* @param {Array.<module:ol/Feature>} updates The features to update.
|
||||
* @param {Array.<module:ol/Feature>} deletes The features to delete.
|
||||
* @param {module:ol/format/WFS~WriteTransactionOptions} options Write options.
|
||||
* @return {Node} Result.
|
||||
* @api
|
||||
*/
|
||||
WFS.prototype.writeTransaction = function(inserts, updates, deletes, options) {
|
||||
const objectStack = [];
|
||||
const node = createElementNS(WFSNS, 'Transaction');
|
||||
const version = options.version ? options.version : DEFAULT_VERSION;
|
||||
const gmlVersion = version === '1.0.0' ? 2 : 3;
|
||||
node.setAttribute('service', 'WFS');
|
||||
node.setAttribute('version', version);
|
||||
let baseObj;
|
||||
/** @type {module:ol/xml~NodeStackItem} */
|
||||
let obj;
|
||||
if (options) {
|
||||
baseObj = options.gmlOptions ? options.gmlOptions : {};
|
||||
if (options.handle) {
|
||||
node.setAttribute('handle', options.handle);
|
||||
}
|
||||
}
|
||||
const schemaLocation = SCHEMA_LOCATIONS[version];
|
||||
node.setAttributeNS(XML_SCHEMA_INSTANCE_URI, 'xsi:schemaLocation', schemaLocation);
|
||||
const featurePrefix = options.featurePrefix ? options.featurePrefix : FEATURE_PREFIX;
|
||||
if (inserts) {
|
||||
obj = {node: node, 'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName};
|
||||
assign(obj, baseObj);
|
||||
pushSerializeAndPop(obj,
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Insert'), inserts,
|
||||
objectStack);
|
||||
}
|
||||
if (updates) {
|
||||
obj = {node: node, 'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'hasZ': options.hasZ, 'srsName': options.srsName};
|
||||
assign(obj, baseObj);
|
||||
pushSerializeAndPop(obj,
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Update'), updates,
|
||||
objectStack);
|
||||
}
|
||||
if (deletes) {
|
||||
pushSerializeAndPop({node: node, 'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'srsName': options.srsName},
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Delete'), deletes,
|
||||
objectStack);
|
||||
}
|
||||
if (options.nativeElements) {
|
||||
pushSerializeAndPop({node: node, 'featureNS': options.featureNS,
|
||||
'featureType': options.featureType, 'featurePrefix': featurePrefix,
|
||||
'gmlVersion': gmlVersion, 'srsName': options.srsName},
|
||||
TRANSACTION_SERIALIZERS,
|
||||
makeSimpleNodeFactory('Native'), options.nativeElements,
|
||||
objectStack);
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the projection from a WFS source.
|
||||
*
|
||||
@@ -1085,37 +1109,4 @@ WFS.prototype.writeTransaction = function(inserts, updates, deletes, options) {
|
||||
WFS.prototype.readProjection;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
WFS.prototype.readProjectionFromDocument = function(doc) {
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
return this.readProjectionFromNode(n);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
WFS.prototype.readProjectionFromNode = function(node) {
|
||||
if (node.firstElementChild &&
|
||||
node.firstElementChild.firstElementChild) {
|
||||
node = node.firstElementChild.firstElementChild;
|
||||
for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
|
||||
if (!(n.childNodes.length === 0 ||
|
||||
(n.childNodes.length === 1 &&
|
||||
n.firstChild.nodeType === 3))) {
|
||||
const objectStack = [{}];
|
||||
this.gmlFormat_.readGeometryElement(n, objectStack);
|
||||
return getProjection(objectStack.pop().srsName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
export default WFS;
|
||||
|
||||
+519
-548
File diff suppressed because it is too large
Load Diff
@@ -17,15 +17,40 @@ import {makeArrayPusher, makeObjectPropertyPusher, makeObjectPropertySetter,
|
||||
* @extends {module:ol/format/XML}
|
||||
* @api
|
||||
*/
|
||||
const WMSCapabilities = function() {
|
||||
class WMSCapabilities {
|
||||
constructor() {
|
||||
|
||||
XML.call(this);
|
||||
XML.call(this);
|
||||
|
||||
/**
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.version = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {string|undefined}
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.version = undefined;
|
||||
};
|
||||
readFromDocument(doc) {
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
return this.readFromNode(n);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readFromNode(node) {
|
||||
this.version = node.getAttribute('version').trim();
|
||||
const wmsCapabilityObject = pushParseAndPop({
|
||||
'version': this.version
|
||||
}, PARSERS, node, []);
|
||||
return wmsCapabilityObject ? wmsCapabilityObject : null;
|
||||
}
|
||||
}
|
||||
|
||||
inherits(WMSCapabilities, XML);
|
||||
|
||||
@@ -277,31 +302,6 @@ const KEYWORDLIST_PARSERS = makeStructureNS(
|
||||
WMSCapabilities.prototype.read;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
WMSCapabilities.prototype.readFromDocument = function(doc) {
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
return this.readFromNode(n);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
WMSCapabilities.prototype.readFromNode = function(node) {
|
||||
this.version = node.getAttribute('version').trim();
|
||||
const wmsCapabilityObject = pushParseAndPop({
|
||||
'version': this.version
|
||||
}, PARSERS, node, []);
|
||||
return wmsCapabilityObject ? wmsCapabilityObject : null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
|
||||
+118
-121
@@ -25,32 +25,136 @@ import {makeArrayPusher, makeStructureNS, pushParseAndPop} from '../xml.js';
|
||||
* @param {module:ol/format/WMSGetFeatureInfo~Options=} opt_options Options.
|
||||
* @api
|
||||
*/
|
||||
const WMSGetFeatureInfo = function(opt_options) {
|
||||
class WMSGetFeatureInfo {
|
||||
constructor(opt_options) {
|
||||
|
||||
const options = opt_options ? opt_options : {};
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.featureNS_ = 'http://mapserver.gis.umn.edu/mapserver';
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/format/GML2}
|
||||
*/
|
||||
this.gmlFormat_ = new GML2();
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
this.layers_ = options.layers ? options.layers : null;
|
||||
|
||||
XMLFeature.call(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
* @return {Array.<string>} layers
|
||||
*/
|
||||
this.featureNS_ = 'http://mapserver.gis.umn.edu/mapserver';
|
||||
|
||||
getLayers() {
|
||||
return this.layers_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:ol/format/GML2}
|
||||
* @param {Array.<string>} layers Layers to parse.
|
||||
*/
|
||||
this.gmlFormat_ = new GML2();
|
||||
|
||||
setLayers(layers) {
|
||||
this.layers_ = layers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {Array.<module:ol/Feature>} Features.
|
||||
* @private
|
||||
* @type {Array.<string>}
|
||||
*/
|
||||
this.layers_ = options.layers ? options.layers : null;
|
||||
readFeatures_(node, objectStack) {
|
||||
node.setAttribute('namespaceURI', this.featureNS_);
|
||||
const localName = node.localName;
|
||||
/** @type {Array.<module:ol/Feature>} */
|
||||
let features = [];
|
||||
if (node.childNodes.length === 0) {
|
||||
return features;
|
||||
}
|
||||
if (localName == 'msGMLOutput') {
|
||||
for (let i = 0, ii = node.childNodes.length; i < ii; i++) {
|
||||
const layer = node.childNodes[i];
|
||||
if (layer.nodeType !== Node.ELEMENT_NODE) {
|
||||
continue;
|
||||
}
|
||||
const context = objectStack[0];
|
||||
|
||||
XMLFeature.call(this);
|
||||
};
|
||||
const toRemove = layerIdentifier;
|
||||
const layerName = layer.localName.replace(toRemove, '');
|
||||
|
||||
if (this.layers_ && !includes(this.layers_, layerName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const featureType = layerName +
|
||||
featureIdentifier;
|
||||
|
||||
context['featureType'] = featureType;
|
||||
context['featureNS'] = this.featureNS_;
|
||||
|
||||
const parsers = {};
|
||||
parsers[featureType] = makeArrayPusher(
|
||||
this.gmlFormat_.readFeatureElement, this.gmlFormat_);
|
||||
const parsersNS = makeStructureNS(
|
||||
[context['featureNS'], null], parsers);
|
||||
layer.setAttribute('namespaceURI', this.featureNS_);
|
||||
const layerFeatures = pushParseAndPop(
|
||||
[], parsersNS, layer, objectStack, this.gmlFormat_);
|
||||
if (layerFeatures) {
|
||||
extend(features, layerFeatures);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (localName == 'FeatureCollection') {
|
||||
const gmlFeatures = pushParseAndPop([],
|
||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
|
||||
[{}], this.gmlFormat_);
|
||||
if (gmlFeatures) {
|
||||
features = gmlFeatures;
|
||||
}
|
||||
}
|
||||
return features;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
const options = {};
|
||||
if (opt_options) {
|
||||
assign(options, this.getReadOptions(node, opt_options));
|
||||
}
|
||||
return this.readFeatures_(node, [options]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeatureNode(feature, opt_options) {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeaturesNode(features, opt_options) {}
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeGeometryNode(geometry, opt_options) {}
|
||||
}
|
||||
|
||||
inherits(WMSGetFeatureInfo, XMLFeature);
|
||||
|
||||
@@ -69,82 +173,6 @@ const featureIdentifier = '_feature';
|
||||
const layerIdentifier = '_layer';
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<string>} layers
|
||||
*/
|
||||
WMSGetFeatureInfo.prototype.getLayers = function() {
|
||||
return this.layers_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<string>} layers Layers to parse.
|
||||
*/
|
||||
WMSGetFeatureInfo.prototype.setLayers = function(layers) {
|
||||
this.layers_ = layers;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
* @return {Array.<module:ol/Feature>} Features.
|
||||
* @private
|
||||
*/
|
||||
WMSGetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) {
|
||||
node.setAttribute('namespaceURI', this.featureNS_);
|
||||
const localName = node.localName;
|
||||
/** @type {Array.<module:ol/Feature>} */
|
||||
let features = [];
|
||||
if (node.childNodes.length === 0) {
|
||||
return features;
|
||||
}
|
||||
if (localName == 'msGMLOutput') {
|
||||
for (let i = 0, ii = node.childNodes.length; i < ii; i++) {
|
||||
const layer = node.childNodes[i];
|
||||
if (layer.nodeType !== Node.ELEMENT_NODE) {
|
||||
continue;
|
||||
}
|
||||
const context = objectStack[0];
|
||||
|
||||
const toRemove = layerIdentifier;
|
||||
const layerName = layer.localName.replace(toRemove, '');
|
||||
|
||||
if (this.layers_ && !includes(this.layers_, layerName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const featureType = layerName +
|
||||
featureIdentifier;
|
||||
|
||||
context['featureType'] = featureType;
|
||||
context['featureNS'] = this.featureNS_;
|
||||
|
||||
const parsers = {};
|
||||
parsers[featureType] = makeArrayPusher(
|
||||
this.gmlFormat_.readFeatureElement, this.gmlFormat_);
|
||||
const parsersNS = makeStructureNS(
|
||||
[context['featureNS'], null], parsers);
|
||||
layer.setAttribute('namespaceURI', this.featureNS_);
|
||||
const layerFeatures = pushParseAndPop(
|
||||
[], parsersNS, layer, objectStack, this.gmlFormat_);
|
||||
if (layerFeatures) {
|
||||
extend(features, layerFeatures);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (localName == 'FeatureCollection') {
|
||||
const gmlFeatures = pushParseAndPop([],
|
||||
this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
|
||||
[{}], this.gmlFormat_);
|
||||
if (gmlFeatures) {
|
||||
features = gmlFeatures;
|
||||
}
|
||||
}
|
||||
return features;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read all features from a WMSGetFeatureInfo response.
|
||||
*
|
||||
@@ -157,35 +185,4 @@ WMSGetFeatureInfo.prototype.readFeatures_ = function(node, objectStack) {
|
||||
WMSGetFeatureInfo.prototype.readFeatures;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
WMSGetFeatureInfo.prototype.readFeaturesFromNode = function(node, opt_options) {
|
||||
const options = {};
|
||||
if (opt_options) {
|
||||
assign(options, this.getReadOptions(node, opt_options));
|
||||
}
|
||||
return this.readFeatures_(node, [options]);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
WMSGetFeatureInfo.prototype.writeFeatureNode = function(feature, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
WMSGetFeatureInfo.prototype.writeFeaturesNode = function(features, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* Not implemented.
|
||||
* @inheritDoc
|
||||
*/
|
||||
WMSGetFeatureInfo.prototype.writeGeometryNode = function(geometry, opt_options) {};
|
||||
export default WMSGetFeatureInfo;
|
||||
|
||||
@@ -18,15 +18,43 @@ import {pushParseAndPop, makeStructureNS,
|
||||
* @extends {module:ol/format/XML}
|
||||
* @api
|
||||
*/
|
||||
const WMTSCapabilities = function() {
|
||||
XML.call(this);
|
||||
class WMTSCapabilities {
|
||||
constructor() {
|
||||
XML.call(this);
|
||||
|
||||
/**
|
||||
* @type {module:ol/format/OWS}
|
||||
* @private
|
||||
*/
|
||||
this.owsParser_ = new OWS();
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {module:ol/format/OWS}
|
||||
* @private
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.owsParser_ = new OWS();
|
||||
};
|
||||
readFromDocument(doc) {
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
return this.readFromNode(n);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readFromNode(node) {
|
||||
const version = node.getAttribute('version').trim();
|
||||
let WMTSCapabilityObject = this.owsParser_.readFromNode(node);
|
||||
if (!WMTSCapabilityObject) {
|
||||
return null;
|
||||
}
|
||||
WMTSCapabilityObject['version'] = version;
|
||||
WMTSCapabilityObject = pushParseAndPop(WMTSCapabilityObject, PARSERS, node, []);
|
||||
return WMTSCapabilityObject ? WMTSCapabilityObject : null;
|
||||
}
|
||||
}
|
||||
|
||||
inherits(WMTSCapabilities, XML);
|
||||
|
||||
@@ -204,34 +232,6 @@ const TM_PARSERS = makeStructureNS(
|
||||
WMTSCapabilities.prototype.read;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
WMTSCapabilities.prototype.readFromDocument = function(doc) {
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
return this.readFromNode(n);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
WMTSCapabilities.prototype.readFromNode = function(node) {
|
||||
const version = node.getAttribute('version').trim();
|
||||
let WMTSCapabilityObject = this.owsParser_.readFromNode(node);
|
||||
if (!WMTSCapabilityObject) {
|
||||
return null;
|
||||
}
|
||||
WMTSCapabilityObject['version'] = version;
|
||||
WMTSCapabilityObject = pushParseAndPop(WMTSCapabilityObject, PARSERS, node, []);
|
||||
return WMTSCapabilityObject ? WMTSCapabilityObject : null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array.<*>} objectStack Object stack.
|
||||
|
||||
+30
-33
@@ -11,40 +11,37 @@ import {isDocument, isNode, parse} from '../xml.js';
|
||||
* @abstract
|
||||
* @struct
|
||||
*/
|
||||
const XML = function() {
|
||||
};
|
||||
class XML {
|
||||
/**
|
||||
* @param {Document|Node|string} source Source.
|
||||
* @return {Object} The parsed result.
|
||||
*/
|
||||
read(source) {
|
||||
if (isDocument(source)) {
|
||||
return this.readFromDocument(/** @type {Document} */ (source));
|
||||
} else if (isNode(source)) {
|
||||
return this.readFromNode(/** @type {Node} */ (source));
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readFromDocument(doc);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Document} doc Document.
|
||||
* @return {Object} Object
|
||||
*/
|
||||
readFromDocument(doc) {}
|
||||
|
||||
/**
|
||||
* @param {Document|Node|string} source Source.
|
||||
* @return {Object} The parsed result.
|
||||
*/
|
||||
XML.prototype.read = function(source) {
|
||||
if (isDocument(source)) {
|
||||
return this.readFromDocument(/** @type {Document} */ (source));
|
||||
} else if (isNode(source)) {
|
||||
return this.readFromNode(/** @type {Node} */ (source));
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readFromDocument(doc);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Node} node Node.
|
||||
* @return {Object} Object
|
||||
*/
|
||||
readFromNode(node) {}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Document} doc Document.
|
||||
* @return {Object} Object
|
||||
*/
|
||||
XML.prototype.readFromDocument = function(doc) {};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Node} node Node.
|
||||
* @return {Object} Object
|
||||
*/
|
||||
XML.prototype.readFromNode = function(node) {};
|
||||
export default XML;
|
||||
|
||||
+220
-235
@@ -17,247 +17,232 @@ import {isDocument, isNode, parse} from '../xml.js';
|
||||
* @abstract
|
||||
* @extends {module:ol/format/Feature}
|
||||
*/
|
||||
const XMLFeature = function() {
|
||||
class XMLFeature {
|
||||
constructor() {
|
||||
|
||||
/**
|
||||
* @type {XMLSerializer}
|
||||
* @private
|
||||
*/
|
||||
this.xmlSerializer_ = new XMLSerializer();
|
||||
|
||||
FeatureFormat.call(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {XMLSerializer}
|
||||
* @private
|
||||
* @inheritDoc
|
||||
*/
|
||||
this.xmlSerializer_ = new XMLSerializer();
|
||||
getType() {
|
||||
return FormatType.XML;
|
||||
}
|
||||
|
||||
FeatureFormat.call(this);
|
||||
};
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readFeature(source, opt_options) {
|
||||
if (isDocument(source)) {
|
||||
return this.readFeatureFromDocument(/** @type {Document} */ (source), opt_options);
|
||||
} else if (isNode(source)) {
|
||||
return this.readFeatureFromNode(/** @type {Node} */ (source), opt_options);
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readFeatureFromDocument(doc, opt_options);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
|
||||
* @return {module:ol/Feature} Feature.
|
||||
*/
|
||||
readFeatureFromDocument(doc, opt_options) {
|
||||
const features = this.readFeaturesFromDocument(doc, opt_options);
|
||||
if (features.length > 0) {
|
||||
return features[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
|
||||
* @return {module:ol/Feature} Feature.
|
||||
*/
|
||||
readFeatureFromNode(node, opt_options) {
|
||||
return null; // not implemented
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readFeatures(source, opt_options) {
|
||||
if (isDocument(source)) {
|
||||
return this.readFeaturesFromDocument(
|
||||
/** @type {Document} */ (source), opt_options);
|
||||
} else if (isNode(source)) {
|
||||
return this.readFeaturesFromNode(/** @type {Node} */ (source), opt_options);
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readFeaturesFromDocument(doc, opt_options);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
|
||||
* @protected
|
||||
* @return {Array.<module:ol/Feature>} Features.
|
||||
*/
|
||||
readFeaturesFromDocument(doc, opt_options) {
|
||||
/** @type {Array.<module:ol/Feature>} */
|
||||
const features = [];
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
extend(features, this.readFeaturesFromNode(n, opt_options));
|
||||
}
|
||||
}
|
||||
return features;
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Node} node Node.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
|
||||
* @protected
|
||||
* @return {Array.<module:ol/Feature>} Features.
|
||||
*/
|
||||
readFeaturesFromNode(node, opt_options) {}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readGeometry(source, opt_options) {
|
||||
if (isDocument(source)) {
|
||||
return this.readGeometryFromDocument(
|
||||
/** @type {Document} */ (source), opt_options);
|
||||
} else if (isNode(source)) {
|
||||
return this.readGeometryFromNode(/** @type {Node} */ (source), opt_options);
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readGeometryFromDocument(doc, opt_options);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
|
||||
* @protected
|
||||
* @return {module:ol/geom/Geometry} Geometry.
|
||||
*/
|
||||
readGeometryFromDocument(doc, opt_options) {
|
||||
return null; // not implemented
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
|
||||
* @protected
|
||||
* @return {module:ol/geom/Geometry} Geometry.
|
||||
*/
|
||||
readGeometryFromNode(node, opt_options) {
|
||||
return null; // not implemented
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
readProjection(source) {
|
||||
if (isDocument(source)) {
|
||||
return this.readProjectionFromDocument(/** @type {Document} */ (source));
|
||||
} else if (isNode(source)) {
|
||||
return this.readProjectionFromNode(/** @type {Node} */ (source));
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readProjectionFromDocument(doc);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @protected
|
||||
* @return {module:ol/proj/Projection} Projection.
|
||||
*/
|
||||
readProjectionFromDocument(doc) {
|
||||
return this.dataProjection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @protected
|
||||
* @return {module:ol/proj/Projection} Projection.
|
||||
*/
|
||||
readProjectionFromNode(node) {
|
||||
return this.dataProjection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeature(feature, opt_options) {
|
||||
const node = this.writeFeatureNode(feature, opt_options);
|
||||
return this.xmlSerializer_.serializeToString(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/Feature} feature Feature.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Options.
|
||||
* @protected
|
||||
* @return {Node} Node.
|
||||
*/
|
||||
writeFeatureNode(feature, opt_options) {
|
||||
return null; // not implemented
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeFeatures(features, opt_options) {
|
||||
const node = this.writeFeaturesNode(features, opt_options);
|
||||
return this.xmlSerializer_.serializeToString(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Options.
|
||||
* @return {Node} Node.
|
||||
*/
|
||||
writeFeaturesNode(features, opt_options) {
|
||||
return null; // not implemented
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
writeGeometry(geometry, opt_options) {
|
||||
const node = this.writeGeometryNode(geometry, opt_options);
|
||||
return this.xmlSerializer_.serializeToString(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {module:ol/geom/Geometry} geometry Geometry.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Options.
|
||||
* @return {Node} Node.
|
||||
*/
|
||||
writeGeometryNode(geometry, opt_options) {
|
||||
return null; // not implemented
|
||||
}
|
||||
}
|
||||
|
||||
inherits(XMLFeature, FeatureFormat);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
XMLFeature.prototype.getType = function() {
|
||||
return FormatType.XML;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
XMLFeature.prototype.readFeature = function(source, opt_options) {
|
||||
if (isDocument(source)) {
|
||||
return this.readFeatureFromDocument(/** @type {Document} */ (source), opt_options);
|
||||
} else if (isNode(source)) {
|
||||
return this.readFeatureFromNode(/** @type {Node} */ (source), opt_options);
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readFeatureFromDocument(doc, opt_options);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
|
||||
* @return {module:ol/Feature} Feature.
|
||||
*/
|
||||
XMLFeature.prototype.readFeatureFromDocument = function(doc, opt_options) {
|
||||
const features = this.readFeaturesFromDocument(doc, opt_options);
|
||||
if (features.length > 0) {
|
||||
return features[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
|
||||
* @return {module:ol/Feature} Feature.
|
||||
*/
|
||||
XMLFeature.prototype.readFeatureFromNode = function(node, opt_options) {
|
||||
return null; // not implemented
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
XMLFeature.prototype.readFeatures = function(source, opt_options) {
|
||||
if (isDocument(source)) {
|
||||
return this.readFeaturesFromDocument(
|
||||
/** @type {Document} */ (source), opt_options);
|
||||
} else if (isNode(source)) {
|
||||
return this.readFeaturesFromNode(/** @type {Node} */ (source), opt_options);
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readFeaturesFromDocument(doc, opt_options);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
|
||||
* @protected
|
||||
* @return {Array.<module:ol/Feature>} Features.
|
||||
*/
|
||||
XMLFeature.prototype.readFeaturesFromDocument = function(doc, opt_options) {
|
||||
/** @type {Array.<module:ol/Feature>} */
|
||||
const features = [];
|
||||
for (let n = doc.firstChild; n; n = n.nextSibling) {
|
||||
if (n.nodeType == Node.ELEMENT_NODE) {
|
||||
extend(features, this.readFeaturesFromNode(n, opt_options));
|
||||
}
|
||||
}
|
||||
return features;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Node} node Node.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
|
||||
* @protected
|
||||
* @return {Array.<module:ol/Feature>} Features.
|
||||
*/
|
||||
XMLFeature.prototype.readFeaturesFromNode = function(node, opt_options) {};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
XMLFeature.prototype.readGeometry = function(source, opt_options) {
|
||||
if (isDocument(source)) {
|
||||
return this.readGeometryFromDocument(
|
||||
/** @type {Document} */ (source), opt_options);
|
||||
} else if (isNode(source)) {
|
||||
return this.readGeometryFromNode(/** @type {Node} */ (source), opt_options);
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readGeometryFromDocument(doc, opt_options);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
|
||||
* @protected
|
||||
* @return {module:ol/geom/Geometry} Geometry.
|
||||
*/
|
||||
XMLFeature.prototype.readGeometryFromDocument = function(doc, opt_options) {
|
||||
return null; // not implemented
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {module:ol/format/Feature~ReadOptions=} opt_options Options.
|
||||
* @protected
|
||||
* @return {module:ol/geom/Geometry} Geometry.
|
||||
*/
|
||||
XMLFeature.prototype.readGeometryFromNode = function(node, opt_options) {
|
||||
return null; // not implemented
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
XMLFeature.prototype.readProjection = function(source) {
|
||||
if (isDocument(source)) {
|
||||
return this.readProjectionFromDocument(/** @type {Document} */ (source));
|
||||
} else if (isNode(source)) {
|
||||
return this.readProjectionFromNode(/** @type {Node} */ (source));
|
||||
} else if (typeof source === 'string') {
|
||||
const doc = parse(source);
|
||||
return this.readProjectionFromDocument(doc);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @protected
|
||||
* @return {module:ol/proj/Projection} Projection.
|
||||
*/
|
||||
XMLFeature.prototype.readProjectionFromDocument = function(doc) {
|
||||
return this.dataProjection;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @protected
|
||||
* @return {module:ol/proj/Projection} Projection.
|
||||
*/
|
||||
XMLFeature.prototype.readProjectionFromNode = function(node) {
|
||||
return this.dataProjection;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
XMLFeature.prototype.writeFeature = function(feature, opt_options) {
|
||||
const node = this.writeFeatureNode(feature, opt_options);
|
||||
return this.xmlSerializer_.serializeToString(node);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/Feature} feature Feature.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Options.
|
||||
* @protected
|
||||
* @return {Node} Node.
|
||||
*/
|
||||
XMLFeature.prototype.writeFeatureNode = function(feature, opt_options) {
|
||||
return null; // not implemented
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
XMLFeature.prototype.writeFeatures = function(features, opt_options) {
|
||||
const node = this.writeFeaturesNode(features, opt_options);
|
||||
return this.xmlSerializer_.serializeToString(node);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<module:ol/Feature>} features Features.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Options.
|
||||
* @return {Node} Node.
|
||||
*/
|
||||
XMLFeature.prototype.writeFeaturesNode = function(features, opt_options) {
|
||||
return null; // not implemented
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
XMLFeature.prototype.writeGeometry = function(geometry, opt_options) {
|
||||
const node = this.writeGeometryNode(geometry, opt_options);
|
||||
return this.xmlSerializer_.serializeToString(node);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {module:ol/geom/Geometry} geometry Geometry.
|
||||
* @param {module:ol/format/Feature~WriteOptions=} opt_options Options.
|
||||
* @return {Node} Node.
|
||||
*/
|
||||
XMLFeature.prototype.writeGeometryNode = function(geometry, opt_options) {
|
||||
return null; // not implemented
|
||||
};
|
||||
export default XMLFeature;
|
||||
|
||||
@@ -13,21 +13,23 @@
|
||||
* @param {!string} tagName The XML tag name for this filter.
|
||||
* @struct
|
||||
*/
|
||||
const Filter = function(tagName) {
|
||||
class Filter {
|
||||
constructor(tagName) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!string}
|
||||
*/
|
||||
this.tagName_ = tagName;
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
* @type {!string}
|
||||
*/
|
||||
this.tagName_ = tagName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The XML tag name for a filter.
|
||||
* @returns {!string} Name.
|
||||
*/
|
||||
Filter.prototype.getTagName = function() {
|
||||
return this.tagName_;
|
||||
};
|
||||
/**
|
||||
* The XML tag name for a filter.
|
||||
* @returns {!string} Name.
|
||||
*/
|
||||
getTagName() {
|
||||
return this.tagName_;
|
||||
}
|
||||
}
|
||||
|
||||
export default Filter;
|
||||
|
||||
Reference in New Issue
Block a user