Move vector code out of the way
This commit is contained in:
@@ -1,98 +0,0 @@
|
||||
goog.provide('ol.parser.AsyncObjectFeatureParser');
|
||||
goog.provide('ol.parser.AsyncStringFeatureParser');
|
||||
goog.provide('ol.parser.DomFeatureParser');
|
||||
goog.provide('ol.parser.ObjectFeatureParser');
|
||||
goog.provide('ol.parser.ReadFeaturesResult');
|
||||
goog.provide('ol.parser.StringFeatureParser');
|
||||
|
||||
goog.require('ol.Feature');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
ol.parser.DomFeatureParser = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element|Document} node Document or element node.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.DomFeatureParser.prototype.readFeaturesFromNode =
|
||||
goog.abstractMethod;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
ol.parser.ObjectFeatureParser = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} obj Object representing features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.ObjectFeatureParser.prototype.readFeaturesFromObject =
|
||||
goog.abstractMethod;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
ol.parser.StringFeatureParser = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} data String data.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.StringFeatureParser.prototype.readFeaturesFromString =
|
||||
goog.abstractMethod;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
ol.parser.AsyncStringFeatureParser = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} data String data.
|
||||
* @param {function(ol.parser.ReadFeaturesResult)} callback Callback which is
|
||||
* called after parsing.
|
||||
*/
|
||||
ol.parser.AsyncStringFeatureParser.prototype.readFeaturesFromStringAsync =
|
||||
goog.abstractMethod;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
ol.parser.AsyncObjectFeatureParser = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} obj Object representing features.
|
||||
* @param {function(ol.parser.ReadFeaturesResult)} callback Callback which is
|
||||
* called after parsing.
|
||||
*/
|
||||
ol.parser.AsyncObjectFeatureParser.prototype.readFeaturesFromObjectAsync =
|
||||
goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{projection: ol.proj.ProjectionLike}}
|
||||
*/
|
||||
ol.parser.ReadFeaturesMetadata;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{features: Array.<ol.Feature>,
|
||||
* metadata: ol.parser.ReadFeaturesMetadata}}
|
||||
*/
|
||||
ol.parser.ReadFeaturesResult;
|
||||
@@ -1 +0,0 @@
|
||||
@exportSymbol ol.parser.GeoJSON
|
||||
@@ -1,419 +0,0 @@
|
||||
goog.provide('ol.parser.GeoJSON');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryCollection');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.Parser');
|
||||
goog.require('ol.parser.ReadFeaturesResult');
|
||||
goog.require('ol.parser.StringFeatureParser');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read and write [GeoJSON](http://geojson.org/)
|
||||
*
|
||||
* @constructor
|
||||
* @implements {ol.parser.StringFeatureParser}
|
||||
* @extends {ol.parser.Parser}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.GeoJSON = function() {};
|
||||
goog.inherits(ol.parser.GeoJSON, ol.parser.Parser);
|
||||
goog.addSingletonGetter(ol.parser.GeoJSON);
|
||||
|
||||
|
||||
/**
|
||||
* Parse a GeoJSON string.
|
||||
* @param {string} str GeoJSON string.
|
||||
* @return {ol.Feature|Array.<ol.Feature>|
|
||||
* ol.geom.Geometry|Array.<ol.geom.Geometry>} Parsed geometry or array
|
||||
* of geometries.
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.read = function(str) {
|
||||
var json = /** @type {GeoJSONObject} */ (JSON.parse(str));
|
||||
return this.parse_(json);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a GeoJSON string.
|
||||
* @param {string} str GeoJSON string.
|
||||
* @return {ol.Feature|Array.<ol.Feature>|
|
||||
* ol.geom.Geometry|Array.<ol.geom.Geometry>} Parsed geometry or array
|
||||
* of geometries.
|
||||
*/
|
||||
ol.parser.GeoJSON.read = function(str) {
|
||||
return ol.parser.GeoJSON.getInstance().read(str);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a GeoJSON feature collection.
|
||||
* @param {string} str GeoJSON feature collection.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.readFeaturesFromString = function(str) {
|
||||
var json = /** @type {GeoJSONFeatureCollection} */ (JSON.parse(str));
|
||||
return this.parseAsFeatureCollection_(json);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a GeoJSON feature collection from decoded JSON.
|
||||
* @param {GeoJSONFeatureCollection} object GeoJSON feature collection decoded
|
||||
* from JSON.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.readFeaturesFromObject = function(object) {
|
||||
return this.parseAsFeatureCollection_(object);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse any GeoJSON object.
|
||||
*
|
||||
* @param {GeoJSONObject} json GeoJSON object.
|
||||
* @return {ol.Feature|Array.<ol.Feature>|
|
||||
* ol.geom.Geometry|Array.<ol.geom.Geometry>} Parsed geometry or array
|
||||
* of geometries.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parse_ = function(json) {
|
||||
var result;
|
||||
if (json.type === 'FeatureCollection') {
|
||||
result = this.parseFeatureCollection_(
|
||||
/** @type {GeoJSONFeatureCollection} */ (json));
|
||||
} else if (json.type === 'Feature') {
|
||||
result = this.parseFeature_(
|
||||
/** @type {GeoJSONFeature} */ (json));
|
||||
} else if (json.type === 'GeometryCollection') {
|
||||
result = this.parseGeometryCollection_(
|
||||
/** @type {GeoJSONGeometryCollection} */ (json));
|
||||
} else {
|
||||
// we've been called with a geometry or an unknown object
|
||||
// create a feature to get shared vertices handling
|
||||
var feature = this.parseFeature_(
|
||||
/** @type {GeoJSONFeature} */ ({type: 'Feature', geometry: json}));
|
||||
result = feature.getGeometry();
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONObject} json GeoJSON object.
|
||||
* @return {ol.parser.ReadFeaturesResult} Parsed object coerced into array of
|
||||
* features.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseAsFeatureCollection_ = function(json) {
|
||||
var obj = this.parse_(json);
|
||||
var features = [];
|
||||
var feature;
|
||||
if (obj instanceof ol.Feature) {
|
||||
features = [obj];
|
||||
} else if (obj instanceof ol.geom.Geometry) {
|
||||
feature = new ol.Feature();
|
||||
feature.setGeometry(obj);
|
||||
features = [feature];
|
||||
} else if (goog.isArray(obj)) {
|
||||
var item, geomArray;
|
||||
for (var i = 0, ii = obj.length; i < ii; ++i) {
|
||||
item = obj[i];
|
||||
geomArray = geomArray || (item instanceof ol.geom.Geometry);
|
||||
if (!geomArray) {
|
||||
goog.asserts.assert(item instanceof ol.Feature, 'expected feature');
|
||||
features = obj;
|
||||
break;
|
||||
} else {
|
||||
feature = new ol.Feature();
|
||||
feature.setGeometry(item);
|
||||
features[i] = feature;
|
||||
}
|
||||
}
|
||||
}
|
||||
var projection = 'EPSG:4326';
|
||||
if (goog.isDefAndNotNull(json.crs)) {
|
||||
var crs = json.crs;
|
||||
if (crs.type === 'name') {
|
||||
projection = (/** GeoJSONCRSName */ (crs.properties)).name;
|
||||
}
|
||||
}
|
||||
return {features: features, metadata: {projection: projection}};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONFeature} json GeoJSON feature.
|
||||
* @return {ol.Feature} Parsed feature.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseFeature_ = function(json) {
|
||||
var geomJson = json.geometry,
|
||||
geometry = null;
|
||||
var feature = new ol.Feature(json.properties);
|
||||
if (goog.isDef(json.id)) {
|
||||
feature.setId(json.id);
|
||||
}
|
||||
if (geomJson) {
|
||||
var type = geomJson.type;
|
||||
switch (type) {
|
||||
case 'Point':
|
||||
geometry = this.parsePoint_(geomJson);
|
||||
break;
|
||||
case 'LineString':
|
||||
geometry = this.parseLineString_(geomJson);
|
||||
break;
|
||||
case 'Polygon':
|
||||
geometry = this.parsePolygon_(geomJson);
|
||||
break;
|
||||
case 'MultiPoint':
|
||||
geometry = this.parseMultiPoint_(geomJson);
|
||||
break;
|
||||
case 'MultiLineString':
|
||||
geometry = this.parseMultiLineString_(geomJson);
|
||||
break;
|
||||
case 'MultiPolygon':
|
||||
geometry = this.parseMultiPolygon_(geomJson);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Bad geometry type: ' + type);
|
||||
}
|
||||
feature.setGeometry(geometry);
|
||||
}
|
||||
return feature;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONFeatureCollection} json GeoJSON feature collection.
|
||||
* @return {Array.<ol.Feature>} Parsed array of features.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseFeatureCollection_ = function(json) {
|
||||
var features = json.features,
|
||||
len = features.length,
|
||||
result = new Array(len),
|
||||
i;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
result[i] = this.parseFeature_(/** @type {GeoJSONFeature} */ (features[i]));
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometryCollection} json GeoJSON geometry collection.
|
||||
* @return {Array.<ol.geom.Geometry>} Parsed array of geometries.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseGeometryCollection_ = function(json) {
|
||||
var geometries = json.geometries,
|
||||
len = geometries.length,
|
||||
result = new Array(len),
|
||||
i;
|
||||
|
||||
for (i = 0; i < len; ++i) {
|
||||
result[i] = this.parse_(/** @type {GeoJSONGeometry} */ (geometries[i]));
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} json GeoJSON linestring.
|
||||
* @return {ol.geom.LineString} Parsed linestring.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseLineString_ = function(json) {
|
||||
return new ol.geom.LineString(json.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} json GeoJSON multi-linestring.
|
||||
* @return {ol.geom.MultiLineString} Parsed multi-linestring.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseMultiLineString_ = function(json) {
|
||||
return new ol.geom.MultiLineString(json.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} json GeoJSON multi-point.
|
||||
* @return {ol.geom.MultiPoint} Parsed multi-point.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseMultiPoint_ = function(json) {
|
||||
return new ol.geom.MultiPoint(json.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} json GeoJSON multi-polygon.
|
||||
* @return {ol.geom.MultiPolygon} Parsed multi-polygon.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parseMultiPolygon_ = function(json) {
|
||||
return new ol.geom.MultiPolygon(json.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} json GeoJSON point.
|
||||
* @return {ol.geom.Point} Parsed point.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parsePoint_ = function(json) {
|
||||
return new ol.geom.Point(json.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} json GeoJSON polygon.
|
||||
* @return {ol.geom.Polygon} Parsed polygon.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.parsePolygon_ = function(json) {
|
||||
return new ol.geom.Polygon(json.coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Geometry} geometry Geometry to encode.
|
||||
* @return {GeoJSONGeometry} GeoJSON geometry.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.encodeGeometry_ = function(geometry) {
|
||||
var type = geometry.getType();
|
||||
return /** @type {GeoJSONGeometry} */({
|
||||
type: goog.object.findKey(ol.parser.GeoJSON.GeometryType,
|
||||
function(value, key) {
|
||||
return value === type;
|
||||
}
|
||||
),
|
||||
coordinates: geometry.getCoordinates()
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.GeometryCollection} collection Geometry collection to
|
||||
* encode.
|
||||
* @return {GeoJSONGeometryCollection} GeoJSON geometry collection.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.encodeGeometryCollection_ = function(collection) {
|
||||
var geometries = [];
|
||||
var components = collection.getComponents();
|
||||
for (var i = 0, ii = components.length; i < ii; ++i) {
|
||||
geometries.push(this.encodeGeometry_(components[i]));
|
||||
}
|
||||
return /** @type {GeoJSONGeometryCollection} */({
|
||||
type: 'GeometryCollection',
|
||||
geometries: geometries
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<ol.Feature>} collection Feature collection to encode.
|
||||
* @return {GeoJSONFeatureCollection} GeoJSON feature collection.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.encodeFeatureCollection_ = function(collection) {
|
||||
var features = [];
|
||||
for (var i = 0, ii = collection.length; i < ii; ++i) {
|
||||
features.push(this.encodeFeature_(collection[i]));
|
||||
}
|
||||
return /** @type {GeoJSONFeatureCollection} */({
|
||||
type: 'FeatureCollection',
|
||||
features: features
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature to encode.
|
||||
* @return {GeoJSONFeature} GeoJSON feature.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.encodeFeature_ = function(feature) {
|
||||
var geometry = feature.getGeometry(),
|
||||
properties = feature.getAttributes(true);
|
||||
return /** @type {GeoJSONFeature} */({
|
||||
type: 'Feature',
|
||||
properties: properties,
|
||||
geometry: this.encodeGeometry_(geometry)
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.GeometryCollection|ol.geom.Geometry|Array.<ol.Feature>|
|
||||
* ol.Feature} obj The object to encode.
|
||||
* @return {string} The GeoJSON as string.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.encode_ = function(obj) {
|
||||
var result;
|
||||
if (obj instanceof ol.geom.GeometryCollection) {
|
||||
result = this.encodeGeometryCollection_(obj);
|
||||
} else if (obj instanceof ol.geom.Geometry) {
|
||||
result = this.encodeGeometry_(obj);
|
||||
} else if (obj instanceof ol.Feature) {
|
||||
result = this.encodeFeature_(obj);
|
||||
} else if (goog.isArray(obj)) {
|
||||
result = this.encodeFeatureCollection_(obj);
|
||||
}
|
||||
return JSON.stringify(result);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Write out a geometry, geometry collection, feature or an array of features
|
||||
* as a GeoJSON string.
|
||||
* @param {ol.geom.Geometry|ol.geom.GeometryCollection|ol.Feature|
|
||||
* Array.<ol.Feature>} obj The object to encode.
|
||||
* @return {string} GeoJSON for the geometry.
|
||||
*/
|
||||
ol.parser.GeoJSON.write = function(obj) {
|
||||
return ol.parser.GeoJSON.getInstance().write(obj);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Write out a geometry, geometry collection, feature or an array of features
|
||||
* as a GeoJSON string.
|
||||
* @param {ol.geom.Geometry|ol.geom.GeometryCollection|ol.Feature|
|
||||
* Array.<ol.Feature>} obj The object to encode.
|
||||
* @return {string} GeoJSON for the geometry.
|
||||
*/
|
||||
ol.parser.GeoJSON.prototype.write = function(obj) {
|
||||
return this.encode_(obj);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @enum {ol.geom.GeometryType}
|
||||
*/
|
||||
ol.parser.GeoJSON.GeometryType = {
|
||||
'Point': ol.geom.GeometryType.POINT,
|
||||
'LineString': ol.geom.GeometryType.LINESTRING,
|
||||
'Polygon': ol.geom.GeometryType.POLYGON,
|
||||
'MultiPoint': ol.geom.GeometryType.MULTIPOINT,
|
||||
'MultiLineString': ol.geom.GeometryType.MULTILINESTRING,
|
||||
'MultiPolygon': ol.geom.GeometryType.MULTIPOLYGON,
|
||||
'GeometryCollection': ol.geom.GeometryType.GEOMETRYCOLLECTION
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
@exportSymbol ol.parser.GPX
|
||||
@@ -1,291 +0,0 @@
|
||||
goog.provide('ol.parser.GPX');
|
||||
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.DomFeatureParser');
|
||||
goog.require('ol.parser.ObjectFeatureParser');
|
||||
goog.require('ol.parser.StringFeatureParser');
|
||||
goog.require('ol.parser.XML');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read and write [GPX](http://www.topografix.com/gpx.asp) version 1.1
|
||||
*
|
||||
* @constructor
|
||||
* @implements {ol.parser.DomFeatureParser}
|
||||
* @implements {ol.parser.StringFeatureParser}
|
||||
* @implements {ol.parser.ObjectFeatureParser}
|
||||
* @param {ol.parser.GPXOptions=} opt_options Optional configuration object.
|
||||
* @extends {ol.parser.XML}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.GPX = function(opt_options) {
|
||||
var options = /** @type {ol.parser.GPXOptions} */
|
||||
(goog.isDef(opt_options) ? opt_options : {});
|
||||
this.extractAttributes = goog.isDef(options.extractAttributes) ?
|
||||
options.extractAttributes : true;
|
||||
this.extractWaypoints = goog.isDef(options.extractWaypoints) ?
|
||||
options.extractWaypoints : true;
|
||||
this.extractTracks = goog.isDef(options.extractTracks) ?
|
||||
options.extractTracks : true;
|
||||
this.extractRoutes = goog.isDef(options.extractRoutes) ?
|
||||
options.extractRoutes : true;
|
||||
this.creator = goog.isDef(options.creator) ?
|
||||
options.creator : 'OpenLayers';
|
||||
this.defaultDesc = goog.isDef(options.defaultDesc) ?
|
||||
options.defaultDesc : 'No description available';
|
||||
this.defaultNamespaceURI = 'http://www.topografix.com/GPX/1/1';
|
||||
this.schemaLocation = 'http://www.topografix.com/GPX/1/1 ' +
|
||||
'http://www.topografix.com/GPX/1/1/gpx.xsd';
|
||||
this.readers = {
|
||||
'http://www.topografix.com/GPX/1/1': {
|
||||
'gpx': function(node, obj) {
|
||||
if (!goog.isDef(obj.features)) {
|
||||
obj.features = [];
|
||||
}
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'wpt': function(node, obj) {
|
||||
if (this.extractWaypoints) {
|
||||
var properties = {};
|
||||
var coordinates = [parseFloat(node.getAttribute('lon')),
|
||||
parseFloat(node.getAttribute('lat'))];
|
||||
this.readChildNodes(node, properties);
|
||||
var feature = new ol.Feature(properties);
|
||||
var geometry = new ol.geom.Point(coordinates);
|
||||
feature.setGeometry(geometry);
|
||||
obj.features.push(feature);
|
||||
}
|
||||
},
|
||||
'rte': function(node, obj) {
|
||||
if (this.extractRoutes || obj.force) {
|
||||
var type = ol.geom.GeometryType.LINESTRING;
|
||||
var container = {
|
||||
properties: {},
|
||||
geometry: {
|
||||
type: type,
|
||||
coordinates: []
|
||||
}
|
||||
};
|
||||
this.readChildNodes(node, container);
|
||||
var feature = new ol.Feature(container.properties);
|
||||
var geometry = new ol.geom.LineString(container.geometry.coordinates);
|
||||
feature.setGeometry(geometry);
|
||||
obj.features.push(feature);
|
||||
}
|
||||
},
|
||||
'rtept': function(node, container) {
|
||||
var coordinate = [parseFloat(node.getAttribute('lon')),
|
||||
parseFloat(node.getAttribute('lat'))];
|
||||
container.geometry.coordinates.push(coordinate);
|
||||
},
|
||||
'trk': function(node, obj) {
|
||||
if (this.extractTracks) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
obj.force = true;
|
||||
readers['rte'].apply(this, arguments);
|
||||
}
|
||||
},
|
||||
'trkseg': function(node, container) {
|
||||
this.readChildNodes(node, container);
|
||||
},
|
||||
'trkpt': function(node, container) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
readers['rtept'].apply(this, arguments);
|
||||
},
|
||||
'*': function(node, obj) {
|
||||
if (this.extractAttributes === true) {
|
||||
var len = node.childNodes.length;
|
||||
if ((len === 1 || len === 2) && (node.firstChild.nodeType === 3 ||
|
||||
node.firstChild.nodeType === 4)) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
readers['_attribute'].apply(this, arguments);
|
||||
}
|
||||
}
|
||||
},
|
||||
'_attribute': function(node, obj) {
|
||||
var local = node.localName || node.nodeName.split(':').pop();
|
||||
var value = this.getChildValue(node);
|
||||
if (obj.properties) {
|
||||
obj.properties[local] = value.replace(this.regExes.trimSpace, '');
|
||||
} else {
|
||||
obj[local] = value.replace(this.regExes.trimSpace, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
// create an alias for GXP 1.0
|
||||
this.readers['http://www.topografix.com/GPX/1/0'] =
|
||||
this.readers[this.defaultNamespaceURI];
|
||||
this.writers = {
|
||||
'http://www.topografix.com/GPX/1/1': {
|
||||
'_feature': function(feature) {
|
||||
var geom = feature.getGeometry();
|
||||
if (geom instanceof ol.geom.Point) {
|
||||
return this.writeNode('wpt', feature);
|
||||
} else if ((geom instanceof ol.geom.LineString) ||
|
||||
(geom instanceof ol.geom.MultiLineString) ||
|
||||
(geom instanceof ol.geom.Polygon)) {
|
||||
return this.writeNode('trk', feature);
|
||||
}
|
||||
},
|
||||
'wpt': function(feature) {
|
||||
var node = this.createElementNS('wpt');
|
||||
var geom = feature.getGeometry();
|
||||
var coordinates = geom.getCoordinates();
|
||||
node.setAttribute('lon', coordinates[0]);
|
||||
node.setAttribute('lat', coordinates[1]);
|
||||
var attributes = feature.getAttributes();
|
||||
var name = attributes['name'] || goog.getUid(feature).toString();
|
||||
this.writeNode('name', name, undefined, node);
|
||||
var desc = attributes['description'] || this.defaultDesc;
|
||||
this.writeNode('desc', desc, undefined, node);
|
||||
return node;
|
||||
},
|
||||
'trk': function(feature) {
|
||||
var attributes = feature.getAttributes();
|
||||
var node = this.createElementNS('trk');
|
||||
var name = attributes['name'] || goog.getUid(feature).toString();
|
||||
this.writeNode('name', name, undefined, node);
|
||||
var desc = attributes['description'] || this.defaultDesc;
|
||||
this.writeNode('desc', desc, undefined, node);
|
||||
var geom = feature.getGeometry();
|
||||
var i, ii, rings;
|
||||
if (geom instanceof ol.geom.LineString) {
|
||||
this.writeNode('trkseg', feature.getGeometry(), undefined, node);
|
||||
} else if (geom instanceof ol.geom.MultiLineString) {
|
||||
var components = geom.getComponents();
|
||||
for (i = 0, ii = components.length; i < ii; ++i) {
|
||||
this.writeNode('trkseg', components[i], undefined, node);
|
||||
}
|
||||
} else if (geom instanceof ol.geom.Polygon) {
|
||||
rings = geom.getRings();
|
||||
for (i = 0, ii = rings.length; i < ii; ++i) {
|
||||
this.writeNode('trkseg', rings[i], undefined, node);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'trkseg': function(geometry) {
|
||||
var node = this.createElementNS('trkseg');
|
||||
var coordinates = geometry.getCoordinates();
|
||||
for (var i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
this.writeNode('trkpt', coordinates[i], undefined, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'trkpt': function(coord) {
|
||||
var node = this.createElementNS('trkpt');
|
||||
node.setAttribute('lon', coord[0]);
|
||||
node.setAttribute('lat', coord[1]);
|
||||
return node;
|
||||
},
|
||||
'metadata': function(metadata) {
|
||||
var node = this.createElementNS('metadata');
|
||||
if (goog.isDef(metadata['name'])) {
|
||||
this.writeNode('name', metadata['name'], undefined, node);
|
||||
}
|
||||
if (goog.isDef(metadata['desc'])) {
|
||||
this.writeNode('desc', metadata['desc'], undefined, node);
|
||||
}
|
||||
if (goog.isDef(metadata['author'])) {
|
||||
this.writeNode('author', metadata['author'], undefined, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'name': function(name) {
|
||||
var node = this.createElementNS('name');
|
||||
node.appendChild(this.createTextNode(name));
|
||||
return node;
|
||||
},
|
||||
'desc': function(desc) {
|
||||
var node = this.createElementNS('desc');
|
||||
node.appendChild(this.createTextNode(desc));
|
||||
return node;
|
||||
},
|
||||
'author': function(author) {
|
||||
var node = this.createElementNS('author');
|
||||
node.appendChild(this.createTextNode(author));
|
||||
return node;
|
||||
}
|
||||
}
|
||||
};
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.parser.GPX, ol.parser.XML);
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|Document|Element|Object} data Data to read.
|
||||
* @return {ol.parser.ReadFeaturesResult} An object representing the document.
|
||||
*/
|
||||
ol.parser.GPX.prototype.read = function(data) {
|
||||
if (goog.isString(data)) {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
if (data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var obj = /** @type {ol.parser.ReadFeaturesResult} */
|
||||
({metadata: {projection: 'EPSG:4326'}});
|
||||
this.readNode(data, obj);
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a GPX document provided as a string.
|
||||
* @param {string} str GPX document.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GPX.prototype.readFeaturesFromString = function(str) {
|
||||
return this.read(str);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a GPX document provided as a DOM structure.
|
||||
* @param {Element|Document} node Document or element node.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GPX.prototype.readFeaturesFromNode = function(node) {
|
||||
return this.read(node);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} obj Object representing features.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.GPX.prototype.readFeaturesFromObject = function(obj) {
|
||||
return this.read(obj);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.parser.GPXWriteOptions} obj Object structure to write out
|
||||
* as GPX.
|
||||
* @return {string} An string representing the GPX document.
|
||||
*/
|
||||
ol.parser.GPX.prototype.write = function(obj) {
|
||||
var features = goog.isArray(obj.features) ? obj.features : [obj.features];
|
||||
var root = this.createElementNS('gpx');
|
||||
root.setAttribute('version', '1.1');
|
||||
root.setAttribute('creator', this.creator);
|
||||
this.setAttributeNS(
|
||||
root, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation', this.schemaLocation);
|
||||
if (goog.isDef(obj.metadata)) {
|
||||
this.writeNode('metadata', obj.metadata, undefined, root);
|
||||
}
|
||||
for (var i = 0, ii = features.length; i < ii; i++) {
|
||||
this.writeNode('_feature', features[i], undefined, root);
|
||||
}
|
||||
return this.serialize(root);
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
@exportSymbol ol.parser.KML
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,96 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.ExceptionReport');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.parser.XML');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.XML}
|
||||
*/
|
||||
ol.parser.ogc.ExceptionReport = function() {
|
||||
var exceptionReader = function(node, exceptionReport) {
|
||||
var exception = {
|
||||
code: node.getAttribute('exceptionCode'),
|
||||
locator: node.getAttribute('locator'),
|
||||
texts: []
|
||||
};
|
||||
exceptionReport.exceptions.push(exception);
|
||||
this.readChildNodes(node, exception);
|
||||
};
|
||||
var exceptionTextReader = function(node, exception) {
|
||||
var text = this.getChildValue(node);
|
||||
exception.texts.push(text);
|
||||
};
|
||||
this.readers = {
|
||||
'http://www.opengis.net/ogc': {
|
||||
'ServiceExceptionReport': function(node, obj) {
|
||||
obj['exceptionReport'] = {};
|
||||
obj['exceptionReport']['exceptions'] = [];
|
||||
this.readChildNodes(node, obj['exceptionReport']);
|
||||
},
|
||||
'ServiceException': function(node, exceptionReport) {
|
||||
var exception = {};
|
||||
exception['code'] = node.getAttribute('code');
|
||||
exception['locator'] = node.getAttribute('locator');
|
||||
exception['text'] = this.getChildValue(node);
|
||||
exceptionReport['exceptions'].push(exception);
|
||||
}
|
||||
},
|
||||
'http://www.opengis.net/ows': {
|
||||
'ExceptionReport': function(node, obj) {
|
||||
obj.success = false;
|
||||
obj.exceptionReport = {
|
||||
version: node.getAttribute('version'),
|
||||
language: node.getAttribute('language'),
|
||||
exceptions: []
|
||||
};
|
||||
this.readChildNodes(node, obj.exceptionReport);
|
||||
},
|
||||
'Exception': function(node, exceptionReport) {
|
||||
exceptionReader.apply(this, arguments);
|
||||
},
|
||||
'ExceptionText': function(node, exception) {
|
||||
exceptionTextReader.apply(this, arguments);
|
||||
}
|
||||
},
|
||||
'http://www.opengis.net/ows/1.1': {
|
||||
'ExceptionReport': function(node, obj) {
|
||||
obj.exceptionReport = {
|
||||
version: node.getAttribute('version'),
|
||||
language: node.getAttribute('xml:lang'),
|
||||
exceptions: []
|
||||
};
|
||||
this.readChildNodes(node, obj.exceptionReport);
|
||||
},
|
||||
'Exception': function(node, exceptionReport) {
|
||||
exceptionReader.apply(this, arguments);
|
||||
},
|
||||
'ExceptionText': function(node, exception) {
|
||||
exceptionTextReader.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
};
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.ExceptionReport, ol.parser.XML);
|
||||
|
||||
|
||||
/**
|
||||
* Read OGC exception report data from a string, and return an object with
|
||||
* information about the exceptions.
|
||||
*
|
||||
* @param {string|Document} data to read/parse.
|
||||
* @return {Object} Information about the exceptions that occurred.
|
||||
*/
|
||||
ol.parser.ogc.ExceptionReport.prototype.read = function(data) {
|
||||
if (goog.isString(data)) {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
var exceptionInfo = {};
|
||||
exceptionInfo['exceptionReport'] = null;
|
||||
if (data) {
|
||||
this.readChildNodes(data, exceptionInfo);
|
||||
}
|
||||
return exceptionInfo;
|
||||
};
|
||||
@@ -1,37 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.Filter');
|
||||
goog.require('ol.parser.ogc.Filter_v1_0_0');
|
||||
goog.require('ol.parser.ogc.Filter_v1_1_0');
|
||||
goog.require('ol.parser.ogc.Versioned');
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable OGC Filter version 1.0.0.
|
||||
*/
|
||||
ol.ENABLE_OGCFILTER_1_0_0 = true;
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable OGC Filter version 1.1.0.
|
||||
*/
|
||||
ol.ENABLE_OGCFILTER_1_1_0 = true;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object=} opt_options Options which will be set on this object.
|
||||
* @extends {ol.parser.ogc.Versioned}
|
||||
*/
|
||||
ol.parser.ogc.Filter = function(opt_options) {
|
||||
opt_options = opt_options || {};
|
||||
opt_options['defaultVersion'] = '1.0.0';
|
||||
this.parsers = {};
|
||||
if (ol.ENABLE_OGCFILTER_1_0_0) {
|
||||
this.parsers['v1_0_0'] = ol.parser.ogc.Filter_v1_0_0;
|
||||
}
|
||||
if (ol.ENABLE_OGCFILTER_1_1_0) {
|
||||
this.parsers['v1_1_0'] = ol.parser.ogc.Filter_v1_1_0;
|
||||
}
|
||||
goog.base(this, opt_options);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.Filter, ol.parser.ogc.Versioned);
|
||||
@@ -1,601 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.Filter_v1');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('goog.object');
|
||||
goog.require('goog.string');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.Logical');
|
||||
goog.require('ol.expr.LogicalOp');
|
||||
goog.require('ol.expr.Not');
|
||||
goog.require('ol.expr.functions');
|
||||
goog.require('ol.parser.XML');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.XML}
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1 = function() {
|
||||
this.defaultNamespaceURI = 'http://www.opengis.net/ogc';
|
||||
this.errorProperty = 'filter';
|
||||
this.readers = {
|
||||
'http://www.opengis.net/ogc': {
|
||||
_expression: function(node) {
|
||||
var expressions = [];
|
||||
var obj, value, numValue, expr;
|
||||
for (var child = node.firstChild; child; child = child.nextSibling) {
|
||||
switch (child.nodeType) {
|
||||
case 1:
|
||||
obj = this.readNode(child);
|
||||
if (obj.property) {
|
||||
expressions.push(obj.property);
|
||||
} else if (goog.isDef(obj.value)) {
|
||||
expressions.push(obj.value);
|
||||
}
|
||||
break;
|
||||
case 3: // text node
|
||||
case 4: // cdata section
|
||||
value = goog.string.trim(child.nodeValue);
|
||||
// no need to concatenate empty strings
|
||||
if (value) {
|
||||
// check for numeric values
|
||||
numValue = goog.string.toNumber(value);
|
||||
if (!isNaN(numValue)) {
|
||||
value = numValue;
|
||||
}
|
||||
expressions.push(new ol.expr.Literal(value));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if we have more than one property or literal, we concatenate them
|
||||
var num = expressions.length;
|
||||
if (num === 1) {
|
||||
expr = expressions[0];
|
||||
} else {
|
||||
expr = new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.CONCAT),
|
||||
expressions);
|
||||
}
|
||||
return expr;
|
||||
},
|
||||
'Filter': function(node, obj) {
|
||||
var container = {
|
||||
filters: []
|
||||
};
|
||||
this.readChildNodes(node, container);
|
||||
if (goog.isDef(container.fids)) {
|
||||
obj.filter = new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.FID),
|
||||
goog.object.getValues(container.fids));
|
||||
} else if (container.filters.length > 0) {
|
||||
obj.filter = container.filters[0];
|
||||
}
|
||||
},
|
||||
'FeatureId': function(node, obj) {
|
||||
var fid = node.getAttribute('fid');
|
||||
if (fid) {
|
||||
if (!goog.isDef(obj.fids)) {
|
||||
obj.fids = {};
|
||||
}
|
||||
if (!obj.fids.hasOwnProperty(fid)) {
|
||||
obj.fids[fid] = new ol.expr.Literal(fid);
|
||||
}
|
||||
}
|
||||
},
|
||||
'And': function(node, obj) {
|
||||
var container = {filters: []};
|
||||
this.readChildNodes(node, container);
|
||||
var filter = this.aggregateLogical_(container.filters,
|
||||
ol.expr.LogicalOp.AND);
|
||||
obj.filters.push(filter);
|
||||
},
|
||||
'Or': function(node, obj) {
|
||||
var container = {filters: []};
|
||||
this.readChildNodes(node, container);
|
||||
var filter = this.aggregateLogical_(container.filters,
|
||||
ol.expr.LogicalOp.OR);
|
||||
obj.filters.push(filter);
|
||||
},
|
||||
'Not': function(node, obj) {
|
||||
var container = {filters: []};
|
||||
this.readChildNodes(node, container);
|
||||
// Not is unary so can only contain 1 child filter
|
||||
obj.filters.push(new ol.expr.Not(
|
||||
container.filters[0]));
|
||||
},
|
||||
'PropertyIsNull': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.EQ,
|
||||
container.property,
|
||||
new ol.expr.Literal(null)));
|
||||
},
|
||||
'PropertyIsLessThan': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.LT,
|
||||
container.property,
|
||||
container.value));
|
||||
},
|
||||
'PropertyIsGreaterThan': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.GT,
|
||||
container.property,
|
||||
container.value));
|
||||
},
|
||||
'PropertyIsLessThanOrEqualTo': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.LTE,
|
||||
container.property,
|
||||
container.value));
|
||||
},
|
||||
'PropertyIsGreaterThanOrEqualTo': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.GTE,
|
||||
container.property,
|
||||
container.value));
|
||||
},
|
||||
'PropertyIsBetween': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Logical(ol.expr.LogicalOp.AND,
|
||||
new ol.expr.Comparison(ol.expr.ComparisonOp.GTE,
|
||||
container.property, container.lowerBoundary),
|
||||
new ol.expr.Comparison(ol.expr.ComparisonOp.LTE,
|
||||
container.property, container.upperBoundary)));
|
||||
},
|
||||
'Literal': function(node, obj) {
|
||||
var nodeValue = this.getChildValue(node);
|
||||
var value = goog.string.toNumber(nodeValue);
|
||||
obj.value = new ol.expr.Literal(isNaN(value) ? nodeValue : value);
|
||||
},
|
||||
'PropertyName': function(node, obj) {
|
||||
obj.property = new ol.expr.Identifier(this.getChildValue(node));
|
||||
},
|
||||
'LowerBoundary': function(node, obj) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
obj.lowerBoundary = readers._expression.call(this, node);
|
||||
},
|
||||
'UpperBoundary': function(node, obj) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
obj.upperBoundary = readers._expression.call(this, node);
|
||||
},
|
||||
_spatial: function(node, obj, identifier) {
|
||||
var args = [], container = {};
|
||||
this.readChildNodes(node, container);
|
||||
if (goog.isDef(container.geometry)) {
|
||||
args.push(new ol.expr.Literal(this.gml_.createGeometry(container)));
|
||||
} else {
|
||||
args = [new ol.expr.Literal(container.bounds[0]),
|
||||
new ol.expr.Literal(container.bounds[1]),
|
||||
new ol.expr.Literal(container.bounds[2]),
|
||||
new ol.expr.Literal(container.bounds[3])];
|
||||
}
|
||||
if (goog.isDef(container.distance)) {
|
||||
args.push(container.distance);
|
||||
}
|
||||
if (goog.isDef(container.distanceUnits)) {
|
||||
args.push(container.distanceUnits);
|
||||
}
|
||||
args.push(new ol.expr.Literal(container.projection));
|
||||
if (goog.isDef(container.property)) {
|
||||
args.push(container.property);
|
||||
}
|
||||
obj.filters.push(new ol.expr.Call(new ol.expr.Identifier(
|
||||
identifier), args));
|
||||
},
|
||||
'BBOX': function(node, obj) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
readers._spatial.call(this, node, obj,
|
||||
ol.expr.functions.EXTENT);
|
||||
},
|
||||
'Intersects': function(node, obj) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
readers._spatial.call(this, node, obj,
|
||||
ol.expr.functions.INTERSECTS);
|
||||
},
|
||||
'Within': function(node, obj) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
readers._spatial.call(this, node, obj,
|
||||
ol.expr.functions.WITHIN);
|
||||
},
|
||||
'Contains': function(node, obj) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
readers._spatial.call(this, node, obj,
|
||||
ol.expr.functions.CONTAINS);
|
||||
},
|
||||
'DWithin': function(node, obj) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
readers._spatial.call(this, node, obj,
|
||||
ol.expr.functions.DWITHIN);
|
||||
},
|
||||
'Distance': function(node, obj) {
|
||||
var value = goog.string.toNumber(this.getChildValue(node));
|
||||
obj.distance = new ol.expr.Literal(value);
|
||||
obj.distanceUnits = new ol.expr.Literal(node.getAttribute('units'));
|
||||
}
|
||||
}
|
||||
};
|
||||
this.writers = {
|
||||
'http://www.opengis.net/ogc': {
|
||||
'Filter': function(filter) {
|
||||
var node = this.createElementNS('ogc:Filter');
|
||||
this.writeNode(this.getFilterType_(filter), filter, null, node);
|
||||
return node;
|
||||
},
|
||||
'_featureIds': function(filter) {
|
||||
var node = this.createDocumentFragment();
|
||||
var args = filter.getArgs();
|
||||
for (var i = 0, ii = args.length; i < ii; i++) {
|
||||
goog.asserts.assert(args[i] instanceof ol.expr.Literal);
|
||||
this.writeNode('FeatureId', args[i].getValue(), null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'FeatureId': function(fid) {
|
||||
var node = this.createElementNS('ogc:FeatureId');
|
||||
node.setAttribute('fid', fid);
|
||||
return node;
|
||||
},
|
||||
'And': function(filter) {
|
||||
var node = this.createElementNS('ogc:And');
|
||||
var subFilters = [];
|
||||
this.getSubfiltersForLogical_(filter, subFilters);
|
||||
for (var i = 0, ii = subFilters.length; i < ii; ++i) {
|
||||
var subFilter = subFilters[i];
|
||||
if (goog.isDefAndNotNull(subFilter)) {
|
||||
this.writeNode(this.getFilterType_(subFilter), subFilter,
|
||||
null, node);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'Or': function(filter) {
|
||||
var node = this.createElementNS('ogc:Or');
|
||||
var subFilters = [];
|
||||
this.getSubfiltersForLogical_(filter, subFilters);
|
||||
for (var i = 0, ii = subFilters.length; i < ii; ++i) {
|
||||
var subFilter = subFilters[i];
|
||||
if (goog.isDefAndNotNull(subFilter)) {
|
||||
this.writeNode(this.getFilterType_(subFilter), subFilter,
|
||||
null, node);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'Not': function(filter) {
|
||||
var node = this.createElementNS('ogc:Not');
|
||||
var childFilter = filter.getArgument();
|
||||
this.writeNode(this.getFilterType_(childFilter), childFilter, null,
|
||||
node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsLessThan': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsLessThan');
|
||||
this.writeNode('PropertyName', filter.getLeft(), null, node);
|
||||
this.writeOgcExpression(filter.getRight(), node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsGreaterThan': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsGreaterThan');
|
||||
this.writeNode('PropertyName', filter.getLeft(), null, node);
|
||||
this.writeOgcExpression(filter.getRight(), node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsLessThanOrEqualTo': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsLessThanOrEqualTo');
|
||||
this.writeNode('PropertyName', filter.getLeft(), null, node);
|
||||
this.writeOgcExpression(filter.getRight(), node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsGreaterThanOrEqualTo': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsGreaterThanOrEqualTo');
|
||||
this.writeNode('PropertyName', filter.getLeft(), null, node);
|
||||
this.writeOgcExpression(filter.getRight(), node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsBetween': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsBetween');
|
||||
var property = filter.getLeft().getLeft();
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
var lower, upper;
|
||||
var filters = new Array(2);
|
||||
filters[0] = filter.getLeft();
|
||||
filters[1] = filter.getRight();
|
||||
for (var i = 0; i < 2; ++i) {
|
||||
var expr = filters[i].getRight();
|
||||
if (filters[i].getOperator() === ol.expr.ComparisonOp.GTE) {
|
||||
lower = expr;
|
||||
} else if (filters[i].getOperator() === ol.expr.ComparisonOp.LTE) {
|
||||
upper = expr;
|
||||
}
|
||||
}
|
||||
this.writeNode('LowerBoundary', lower, null, node);
|
||||
this.writeNode('UpperBoundary', upper, null, node);
|
||||
return node;
|
||||
},
|
||||
'PropertyName': function(expr) {
|
||||
goog.asserts.assert(expr instanceof ol.expr.Identifier);
|
||||
var node = this.createElementNS('ogc:PropertyName');
|
||||
node.appendChild(this.createTextNode(expr.getName()));
|
||||
return node;
|
||||
},
|
||||
'Literal': function(expr) {
|
||||
goog.asserts.assert(expr instanceof ol.expr.Literal);
|
||||
var node = this.createElementNS('ogc:Literal');
|
||||
node.appendChild(this.createTextNode(expr.getValue()));
|
||||
return node;
|
||||
},
|
||||
'LowerBoundary': function(expr) {
|
||||
var node = this.createElementNS('ogc:LowerBoundary');
|
||||
this.writeOgcExpression(expr, node);
|
||||
return node;
|
||||
},
|
||||
'UpperBoundary': function(expr) {
|
||||
var node = this.createElementNS('ogc:UpperBoundary');
|
||||
this.writeOgcExpression(expr, node);
|
||||
return node;
|
||||
},
|
||||
'INTERSECTS': function(filter) {
|
||||
return this.writeSpatial_(filter, 'Intersects');
|
||||
},
|
||||
'WITHIN': function(filter) {
|
||||
return this.writeSpatial_(filter, 'Within');
|
||||
},
|
||||
'CONTAINS': function(filter) {
|
||||
return this.writeSpatial_(filter, 'Contains');
|
||||
},
|
||||
'DWITHIN': function(filter) {
|
||||
var node = this.writeSpatial_(filter, 'DWithin');
|
||||
this.writeNode('Distance', filter, null, node);
|
||||
return node;
|
||||
},
|
||||
'Distance': function(filter) {
|
||||
var node = this.createElementNS('ogc:Distance');
|
||||
var args = filter.getArgs();
|
||||
goog.asserts.assert(args[2] instanceof ol.expr.Literal);
|
||||
node.setAttribute('units', args[2].getValue());
|
||||
goog.asserts.assert(args[1] instanceof ol.expr.Literal);
|
||||
node.appendChild(this.createTextNode(args[1].getValue()));
|
||||
return node;
|
||||
},
|
||||
'Function': function(filter) {
|
||||
var node = this.createElementNS('ogc:Function');
|
||||
node.setAttribute('name', filter.getCallee().getName());
|
||||
var params = filter.getArgs();
|
||||
for (var i = 0, len = params.length; i < len; i++) {
|
||||
this.writeOgcExpression(params[i], node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'PropertyIsNull': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsNull');
|
||||
this.writeNode('PropertyName', filter.getLeft(), null, node);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
};
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.Filter_v1, ol.parser.XML);
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.filterMap_ = {
|
||||
'&&': 'And',
|
||||
'||': 'Or',
|
||||
'!': 'Not',
|
||||
'==': 'PropertyIsEqualTo',
|
||||
'!=': 'PropertyIsNotEqualTo',
|
||||
'<': 'PropertyIsLessThan',
|
||||
'>': 'PropertyIsGreaterThan',
|
||||
'<=': 'PropertyIsLessThanOrEqualTo',
|
||||
'>=': 'PropertyIsGreaterThanOrEqualTo',
|
||||
'..': 'PropertyIsBetween',
|
||||
'like': 'PropertyIsLike',
|
||||
'null': 'PropertyIsNull',
|
||||
'extent': 'BBOX',
|
||||
'dwithin': 'DWITHIN',
|
||||
'within': 'WITHIN',
|
||||
'contains': 'CONTAINS',
|
||||
'intersects': 'INTERSECTS',
|
||||
'fid': '_featureIds',
|
||||
'ieq': 'PropertyIsEqualTo',
|
||||
'ineq': 'PropertyIsNotEqualTo'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.expr.Expression} filter The filter to determine the type of.
|
||||
* @return {string} The type of filter.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.getFilterType_ = function(filter) {
|
||||
var type;
|
||||
if (filter instanceof ol.expr.Logical ||
|
||||
filter instanceof ol.expr.Comparison) {
|
||||
type = filter.getOperator();
|
||||
var left = filter.getLeft();
|
||||
var right = filter.getRight();
|
||||
var isNull = (type === ol.expr.ComparisonOp.EQ &&
|
||||
right instanceof ol.expr.Literal && right.getValue() === null);
|
||||
if (isNull) {
|
||||
type = 'null';
|
||||
}
|
||||
var isBetween = (type === ol.expr.LogicalOp.AND &&
|
||||
left instanceof ol.expr.Comparison &&
|
||||
right instanceof ol.expr.Comparison &&
|
||||
left.getLeft() instanceof ol.expr.Identifier &&
|
||||
right.getLeft() instanceof ol.expr.Identifier &&
|
||||
left.getLeft().getName() === right.getLeft().getName() &&
|
||||
(left.getOperator() === ol.expr.ComparisonOp.LTE ||
|
||||
left.getOperator() === ol.expr.ComparisonOp.GTE) &&
|
||||
(right.getOperator() === ol.expr.ComparisonOp.LTE ||
|
||||
right.getOperator() === ol.expr.ComparisonOp.GTE));
|
||||
if (isBetween) {
|
||||
type = '..';
|
||||
}
|
||||
} else if (filter instanceof ol.expr.Call) {
|
||||
var callee = filter.getCallee();
|
||||
goog.asserts.assert(callee instanceof ol.expr.Identifier);
|
||||
type = callee.getName();
|
||||
} else if (filter instanceof ol.expr.Not) {
|
||||
type = '!';
|
||||
}
|
||||
var filterType = ol.parser.ogc.Filter_v1.filterMap_[type];
|
||||
if (!filterType) {
|
||||
throw new Error('Filter writing not supported for rule type: ' + type);
|
||||
}
|
||||
return filterType;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|Document|Element} data Data to read.
|
||||
* @return {Object} An object representing the document.
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.read = function(data) {
|
||||
if (goog.isString(data)) {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
if (data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var obj = {};
|
||||
this.readNode(data, obj);
|
||||
return obj.filter;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.expr.Expression} filter The filter to write out.
|
||||
* @return {string} The serialized filter.
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.write = function(filter) {
|
||||
var root = this.writeNode('Filter', filter);
|
||||
this.setAttributeNS(
|
||||
root, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation', this.schemaLocation);
|
||||
return this.serialize(root);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.expr.Expression} expr The value write out.
|
||||
* @param {Element} node The node to append to.
|
||||
* @return {Element} The node to which was appended.
|
||||
* @protected
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.writeOgcExpression = function(expr, node) {
|
||||
if (expr instanceof ol.expr.Call) {
|
||||
this.writeNode('Function', expr, null, node);
|
||||
} else if (expr instanceof ol.expr.Literal) {
|
||||
this.writeNode('Literal', expr, null, node);
|
||||
} else if (expr instanceof ol.expr.Identifier) {
|
||||
this.writeNode('PropertyName', expr, null, node);
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.expr.Logical} filter The filter to retrieve the sub filters from.
|
||||
* @param {Array.<ol.expr.Expression>} subFilters The sub filters retrieved.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.getSubfiltersForLogical_ = function(filter,
|
||||
subFilters) {
|
||||
var operator = filter.getOperator();
|
||||
var filters = new Array(2);
|
||||
filters[0] = filter.getLeft();
|
||||
filters[1] = filter.getRight();
|
||||
for (var i = 0; i < 2; ++i) {
|
||||
if (filters[i] instanceof ol.expr.Logical && filters[i].getOperator() ===
|
||||
operator) {
|
||||
this.getSubfiltersForLogical_(filters[i], subFilters);
|
||||
} else {
|
||||
subFilters.push(filters[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Since ol.expr.Logical can only have a left and a right, we need to nest
|
||||
* sub filters coming from OGC Filter.
|
||||
* @param {Array.<ol.expr.Expression>} filters The filters to aggregate.
|
||||
* @param {ol.expr.LogicalOp} operator The logical operator to use.
|
||||
* @return {ol.expr.Logical} The logical filter created.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.aggregateLogical_ = function(filters,
|
||||
operator) {
|
||||
var subFilters = [];
|
||||
var newFilters = [];
|
||||
// we only need to do this if we have more than 2 items
|
||||
if (filters.length > 2) {
|
||||
while (filters.length) {
|
||||
subFilters.push(filters.pop());
|
||||
if (subFilters.length === 2) {
|
||||
newFilters.push(new ol.expr.Logical(operator,
|
||||
subFilters[0], subFilters[1]));
|
||||
subFilters.length = 0;
|
||||
}
|
||||
}
|
||||
// there could be a single item left now
|
||||
if (subFilters.length === 1) {
|
||||
newFilters.push(subFilters[0]);
|
||||
}
|
||||
return this.aggregateLogical_(newFilters, operator);
|
||||
} else {
|
||||
return new ol.expr.Logical(operator, filters[0], filters[1]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.parser.ogc.GML_v2|ol.parser.ogc.GML_v3} gml The GML parser to
|
||||
* use.
|
||||
* @protected
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.setGmlParser = function(gml) {
|
||||
this.gml_ = gml;
|
||||
for (var uri in this.gml_.readers) {
|
||||
for (var key in this.gml_.readers[uri]) {
|
||||
if (!goog.isDef(this.readers[uri])) {
|
||||
this.readers[uri] = {};
|
||||
}
|
||||
this.readers[uri][key] = goog.bind(this.gml_.readers[uri][key],
|
||||
this.gml_);
|
||||
}
|
||||
}
|
||||
for (uri in this.gml_.writers) {
|
||||
for (key in this.gml_.writers[uri]) {
|
||||
if (!goog.isDef(this.writers[uri])) {
|
||||
this.writers[uri] = {};
|
||||
}
|
||||
this.writers[uri][key] = goog.bind(this.gml_.writers[uri][key],
|
||||
this.gml_);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,184 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.Filter_v1_0_0');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.functions');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.parser.ogc.Filter_v1');
|
||||
goog.require('ol.parser.ogc.GML_v2');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.ogc.Filter_v1}
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1_0_0 = function() {
|
||||
goog.base(this);
|
||||
this.version = '1.0.0';
|
||||
this.schemaLocation = 'http://www.opengis.net/ogc ' +
|
||||
'http://schemas.opengis.net/filter/1.0.0/filter.xsd';
|
||||
goog.object.extend(this.readers['http://www.opengis.net/ogc'], {
|
||||
'PropertyIsEqualTo': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.EQ,
|
||||
container.property,
|
||||
container.value));
|
||||
},
|
||||
'PropertyIsNotEqualTo': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.NEQ,
|
||||
container.property,
|
||||
container.value));
|
||||
},
|
||||
'PropertyIsLike': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
var args = [];
|
||||
args.push(container.property, container.value,
|
||||
new ol.expr.Literal(node.getAttribute('wildCard')),
|
||||
new ol.expr.Literal(node.getAttribute('singleChar')),
|
||||
new ol.expr.Literal(node.getAttribute('escape')));
|
||||
obj.filters.push(new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.LIKE), args));
|
||||
}
|
||||
});
|
||||
goog.object.extend(this.writers['http://www.opengis.net/ogc'], {
|
||||
'PropertyIsEqualTo': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsEqualTo');
|
||||
var property = filter.getLeft();
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
this.writeOgcExpression(filter.getRight(), node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsNotEqualTo': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsNotEqualTo');
|
||||
var property = filter.getLeft();
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
this.writeOgcExpression(filter.getRight(), node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsLike': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsLike');
|
||||
var args = filter.getArgs();
|
||||
goog.asserts.assert(args[2] instanceof ol.expr.Literal);
|
||||
node.setAttribute('wildCard', args[2].getValue());
|
||||
goog.asserts.assert(args[3] instanceof ol.expr.Literal);
|
||||
node.setAttribute('singleChar', args[3].getValue());
|
||||
goog.asserts.assert(args[4] instanceof ol.expr.Literal);
|
||||
node.setAttribute('escape', args[4].getValue());
|
||||
var property = args[0];
|
||||
if (goog.isDef(property)) {
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
}
|
||||
this.writeNode('Literal', args[1], null, node);
|
||||
return node;
|
||||
},
|
||||
'BBOX': function(filter) {
|
||||
var node = this.createElementNS('ogc:BBOX');
|
||||
var args = filter.getArgs();
|
||||
goog.asserts.assert(args[0] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[1] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[2] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[3] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[4] instanceof ol.expr.Literal);
|
||||
var bbox = [
|
||||
args[0].getValue(), args[1].getValue(),
|
||||
args[2].getValue(), args[3].getValue()
|
||||
];
|
||||
var projection = args[4].getValue();
|
||||
var property = args[5];
|
||||
// PropertyName is mandatory in 1.0.0, but e.g. GeoServer also
|
||||
// accepts filters without it.
|
||||
if (goog.isDefAndNotNull(property)) {
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
}
|
||||
var box = this.writeNode('Box', bbox,
|
||||
'http://www.opengis.net/gml');
|
||||
if (goog.isDefAndNotNull(projection)) {
|
||||
box.setAttribute('srsName', projection);
|
||||
}
|
||||
node.appendChild(box);
|
||||
return node;
|
||||
}
|
||||
});
|
||||
this.setGmlParser(new ol.parser.ogc.GML_v2({featureNS: 'http://foo'}));
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.Filter_v1_0_0,
|
||||
ol.parser.ogc.Filter_v1);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.expr.Call} filter The filter to write out.
|
||||
* @param {string} name The name of the spatial operator.
|
||||
* @return {Element} The node created.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1_0_0.prototype.writeSpatial_ = function(filter, name) {
|
||||
var node = this.createElementNS('ogc:' + name);
|
||||
var args = filter.getArgs();
|
||||
var property, geom = null, bbox, call, projection;
|
||||
if (args[0] instanceof ol.expr.Literal && goog.isNumber(args[0].getValue())) {
|
||||
goog.asserts.assert(args[1] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[2] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[3] instanceof ol.expr.Literal);
|
||||
bbox = [
|
||||
args[0].getValue(), args[1].getValue(),
|
||||
args[2].getValue(), args[3].getValue()
|
||||
];
|
||||
projection = args[4];
|
||||
property = args[5];
|
||||
} else if (args[0] instanceof ol.expr.Literal &&
|
||||
args[0].getValue() instanceof ol.geom.Geometry) {
|
||||
geom = args[0].getValue();
|
||||
if (name === 'DWithin') {
|
||||
projection = args[3];
|
||||
property = args[4];
|
||||
} else {
|
||||
projection = args[1];
|
||||
property = args[2];
|
||||
}
|
||||
} else if (args[0] instanceof ol.expr.Call) {
|
||||
call = args[0];
|
||||
if (name === 'DWithin') {
|
||||
projection = args[3];
|
||||
property = args[4];
|
||||
} else {
|
||||
projection = args[1];
|
||||
property = args[2];
|
||||
}
|
||||
}
|
||||
if (goog.isDefAndNotNull(property)) {
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
}
|
||||
if (goog.isDef(call)) {
|
||||
this.writeNode('Function', call, null, node);
|
||||
} else {
|
||||
var child;
|
||||
if (geom !== null) {
|
||||
child = this.writeNode('_geometry', geom,
|
||||
this.gml_.featureNS).firstChild;
|
||||
} else if (bbox.length === 4) {
|
||||
child = this.writeNode('Box', bbox,
|
||||
'http://www.opengis.net/gml');
|
||||
}
|
||||
if (goog.isDef(child)) {
|
||||
goog.asserts.assert(projection instanceof ol.expr.Literal);
|
||||
if (goog.isDefAndNotNull(projection.getValue())) {
|
||||
child.setAttribute('srsName', projection.getValue());
|
||||
}
|
||||
node.appendChild(child);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
};
|
||||
@@ -1,242 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.Filter_v1_1_0');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.functions');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.parser.ogc.Filter_v1');
|
||||
goog.require('ol.parser.ogc.GML_v3');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.ogc.Filter_v1}
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1_1_0 = function() {
|
||||
goog.base(this);
|
||||
this.version = '1.1.0';
|
||||
this.schemaLocation = 'http://www.opengis.net/ogc ' +
|
||||
'http://schemas.opengis.net/filter/1.1.0/filter.xsd';
|
||||
goog.object.extend(this.readers['http://www.opengis.net/ogc'], {
|
||||
'PropertyIsEqualTo': function(node, obj) {
|
||||
var matchCase = node.getAttribute('matchCase');
|
||||
var container = {}, filter;
|
||||
this.readChildNodes(node, container);
|
||||
if (matchCase === 'false' || matchCase === '0') {
|
||||
filter = new ol.expr.Call(new ol.expr.Identifier(ol.expr.functions.IEQ),
|
||||
[container.property, container.value]);
|
||||
} else {
|
||||
filter = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.EQ,
|
||||
container.property,
|
||||
container.value);
|
||||
}
|
||||
obj.filters.push(filter);
|
||||
},
|
||||
'PropertyIsNotEqualTo': function(node, obj) {
|
||||
var matchCase = node.getAttribute('matchCase');
|
||||
var container = {}, filter;
|
||||
this.readChildNodes(node, container);
|
||||
if (matchCase === 'false' || matchCase === '0') {
|
||||
filter = new ol.expr.Call(new ol.expr.Identifier(
|
||||
ol.expr.functions.INEQ),
|
||||
[container.property, container.value]);
|
||||
} else {
|
||||
filter = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.NEQ,
|
||||
container.property,
|
||||
container.value);
|
||||
}
|
||||
obj.filters.push(filter);
|
||||
},
|
||||
'PropertyIsLike': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
var args = [];
|
||||
args.push(container.property, container.value,
|
||||
new ol.expr.Literal(node.getAttribute('wildCard')),
|
||||
new ol.expr.Literal(node.getAttribute('singleChar')),
|
||||
new ol.expr.Literal(node.getAttribute('escapeChar')),
|
||||
new ol.expr.Literal(node.getAttribute('matchCase')));
|
||||
obj.filters.push(new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.LIKE), args));
|
||||
}
|
||||
});
|
||||
goog.object.extend(this.writers['http://www.opengis.net/ogc'], {
|
||||
'PropertyIsEqualTo': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsEqualTo');
|
||||
var property, value;
|
||||
if (filter instanceof ol.expr.Call) {
|
||||
var args = filter.getArgs();
|
||||
property = args[0];
|
||||
value = args[1];
|
||||
node.setAttribute('matchCase', false);
|
||||
} else {
|
||||
property = filter.getLeft();
|
||||
value = filter.getRight();
|
||||
}
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
this.writeOgcExpression(value, node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsNotEqualTo': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsNotEqualTo');
|
||||
var property, value;
|
||||
if (filter instanceof ol.expr.Call) {
|
||||
var args = filter.getArgs();
|
||||
property = args[0];
|
||||
value = args[1];
|
||||
node.setAttribute('matchCase', false);
|
||||
} else {
|
||||
property = filter.getLeft();
|
||||
value = filter.getRight();
|
||||
}
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
this.writeOgcExpression(value, node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsLike': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsLike');
|
||||
var args = filter.getArgs();
|
||||
goog.asserts.assert(args[2] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[3] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[4] instanceof ol.expr.Literal);
|
||||
node.setAttribute('wildCard', args[2].getValue());
|
||||
node.setAttribute('singleChar', args[3].getValue());
|
||||
node.setAttribute('escapeChar', args[4].getValue());
|
||||
if (goog.isDefAndNotNull(args[5])) {
|
||||
goog.asserts.assert(args[5] instanceof ol.expr.Literal);
|
||||
node.setAttribute('matchCase', args[5].getValue());
|
||||
}
|
||||
var property = args[0];
|
||||
if (goog.isDef(property)) {
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
}
|
||||
this.writeNode('Literal', args[1], null, node);
|
||||
return node;
|
||||
},
|
||||
'BBOX': function(filter) {
|
||||
var node = this.createElementNS('ogc:BBOX');
|
||||
var args = filter.getArgs();
|
||||
goog.asserts.assert(args[0] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[1] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[2] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[3] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[4] instanceof ol.expr.Literal);
|
||||
var bbox = [
|
||||
args[0].getValue(), args[1].getValue(),
|
||||
args[2].getValue(), args[3].getValue()
|
||||
];
|
||||
var projection = args[4].getValue();
|
||||
var property = args[5];
|
||||
// PropertyName is optional in 1.1.0
|
||||
if (goog.isDefAndNotNull(property)) {
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
}
|
||||
var box = this.writeNode('Envelope', bbox,
|
||||
'http://www.opengis.net/gml');
|
||||
if (goog.isDefAndNotNull(projection)) {
|
||||
box.setAttribute('srsName', projection);
|
||||
}
|
||||
node.appendChild(box);
|
||||
return node;
|
||||
},
|
||||
'SortBy': function(sortProperties) {
|
||||
var node = this.createElementNS('ogc:SortBy');
|
||||
for (var i = 0, l = sortProperties.length; i < l; i++) {
|
||||
this.writeNode('SortProperty', sortProperties[i], null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'SortProperty': function(sortProperty) {
|
||||
var node = this.createElementNS('ogc:SortProperty');
|
||||
this.writeNode('PropertyName', sortProperty['property'], null, node);
|
||||
goog.asserts.assert(sortProperty['order'] instanceof ol.expr.Literal);
|
||||
this.writeNode('SortOrder',
|
||||
(sortProperty['order'].getValue() == 'DESC') ? 'DESC' : 'ASC', null,
|
||||
node);
|
||||
return node;
|
||||
},
|
||||
'SortOrder': function(value) {
|
||||
var node = this.createElementNS('ogc:SortOrder');
|
||||
node.appendChild(this.createTextNode(value));
|
||||
return node;
|
||||
}
|
||||
});
|
||||
this.setGmlParser(new ol.parser.ogc.GML_v3());
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.Filter_v1_1_0,
|
||||
ol.parser.ogc.Filter_v1);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.expr.Call} filter The filter to write out.
|
||||
* @param {string} name The name of the spatial operator.
|
||||
* @return {Element} The node created.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1_1_0.prototype.writeSpatial_ = function(filter, name) {
|
||||
var node = this.createElementNS('ogc:' + name);
|
||||
var args = filter.getArgs();
|
||||
var property, geom = null, bbox, call, projection;
|
||||
if (args[0] instanceof ol.expr.Literal && goog.isNumber(args[0].getValue())) {
|
||||
goog.asserts.assert(args[1] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[2] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[3] instanceof ol.expr.Literal);
|
||||
bbox = [
|
||||
args[0].getValue(), args[1].getValue(),
|
||||
args[2].getValue(), args[3].getValue()
|
||||
];
|
||||
projection = args[4];
|
||||
property = args[5];
|
||||
} else if (args[0] instanceof ol.expr.Literal &&
|
||||
args[0].getValue() instanceof ol.geom.Geometry) {
|
||||
geom = args[0].getValue();
|
||||
if (name === 'DWithin') {
|
||||
projection = args[3];
|
||||
property = args[4];
|
||||
} else {
|
||||
projection = args[1];
|
||||
property = args[2];
|
||||
}
|
||||
} else if (args[0] instanceof ol.expr.Call) {
|
||||
call = args[0];
|
||||
if (name === 'DWithin') {
|
||||
projection = args[3];
|
||||
property = args[4];
|
||||
} else {
|
||||
projection = args[1];
|
||||
property = args[2];
|
||||
}
|
||||
}
|
||||
if (goog.isDefAndNotNull(property)) {
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
}
|
||||
if (goog.isDef(call)) {
|
||||
this.writeNode('Function', call, null, node);
|
||||
} else {
|
||||
var child;
|
||||
if (geom !== null) {
|
||||
child = this.writeNode('_geometry', geom,
|
||||
this.gml_.featureNS).firstChild;
|
||||
} else if (bbox.length === 4) {
|
||||
child = this.writeNode('Envelope', bbox,
|
||||
'http://www.opengis.net/gml');
|
||||
}
|
||||
if (goog.isDef(child)) {
|
||||
goog.asserts.assert(projection instanceof ol.expr.Literal);
|
||||
if (goog.isDefAndNotNull(projection.getValue())) {
|
||||
child.setAttribute('srsName', projection.getValue());
|
||||
}
|
||||
node.appendChild(child);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
};
|
||||
@@ -1,6 +0,0 @@
|
||||
@exportSymbol ol.parser.ogc.GML_v2
|
||||
@exportProperty ol.parser.ogc.GML_v2.prototype.read
|
||||
@exportProperty ol.parser.ogc.GML_v2.prototype.write
|
||||
@exportSymbol ol.parser.ogc.GML_v3
|
||||
@exportProperty ol.parser.ogc.GML_v3.prototype.read
|
||||
@exportProperty ol.parser.ogc.GML_v3.prototype.write
|
||||
@@ -1,641 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.GML');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryCollection');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.LinearRing');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.StringFeatureParser');
|
||||
goog.require('ol.parser.XML');
|
||||
goog.require('ol.proj');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {ol.parser.StringFeatureParser}
|
||||
* @param {ol.parser.GMLOptions=} opt_options
|
||||
* Optional configuration object.
|
||||
* @extends {ol.parser.XML}
|
||||
*/
|
||||
ol.parser.ogc.GML = function(opt_options) {
|
||||
var options = /** @type {ol.parser.GMLOptions} */
|
||||
(goog.isDef(opt_options) ? opt_options : {});
|
||||
this.extractAttributes = goog.isDef(options.extractAttributes) ?
|
||||
options.extractAttributes : true;
|
||||
this.surface = goog.isDef(options.surface) ?
|
||||
options.surface : false;
|
||||
this.curve = goog.isDef(options.curve) ?
|
||||
options.curve : false;
|
||||
this.multiCurve = goog.isDef(options.multiCurve) ?
|
||||
options.multiCurve : true;
|
||||
this.multiSurface = goog.isDef(options.multiSurface) ?
|
||||
options.multiSurface : true;
|
||||
this.readOptions = options.readOptions;
|
||||
this.writeOptions = options.writeOptions;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.srsName;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.axisOrientation;
|
||||
|
||||
if (goog.isDef(options.schemaLocation)) {
|
||||
this.schemaLocation = options.schemaLocation;
|
||||
}
|
||||
if (goog.isDef(options.featureNS)) {
|
||||
this.featureNS = options.featureNS;
|
||||
}
|
||||
if (goog.isDef(options.featureType)) {
|
||||
this.featureType = options.featureType;
|
||||
}
|
||||
this.singleFeatureType = !goog.isDef(opt_options) ||
|
||||
goog.isString(opt_options.featureType);
|
||||
this.defaultNamespaceURI = 'http://www.opengis.net/gml';
|
||||
this.readers = {
|
||||
'http://www.opengis.net/wfs': {
|
||||
'FeatureCollection': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
}
|
||||
},
|
||||
'http://www.opengis.net/gml': {
|
||||
'_inherit': function(node, obj, container) {
|
||||
// Version specific parsers extend this with goog.functions.sequence
|
||||
var srsName;
|
||||
if (!goog.isDef(this.srsName)) {
|
||||
srsName = this.srsName = node.getAttribute('srsName');
|
||||
}
|
||||
if (!goog.isDef(this.axisOrientation)) {
|
||||
if (goog.isDefAndNotNull(srsName)) {
|
||||
this.axisOrientation = ol.proj.get(srsName).getAxisOrientation();
|
||||
} else {
|
||||
this.axisOrientation = 'enu';
|
||||
}
|
||||
}
|
||||
},
|
||||
'name': function(node, obj) {
|
||||
obj.name = this.getChildValue(node);
|
||||
},
|
||||
'featureMember': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'featureMembers': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'GeometryCollection': function(node, container) {
|
||||
var parts = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, parts, container]);
|
||||
this.readChildNodes(node, parts);
|
||||
container.geometry = {
|
||||
type: ol.geom.GeometryType.GEOMETRYCOLLECTION,
|
||||
parts: parts
|
||||
};
|
||||
},
|
||||
'geometryMember': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'MultiPoint': function(node, container) {
|
||||
var parts = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, parts, container]);
|
||||
this.readChildNodes(node, parts);
|
||||
container.geometry = {
|
||||
type: ol.geom.GeometryType.MULTIPOINT,
|
||||
parts: parts
|
||||
};
|
||||
},
|
||||
'pointMember': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'MultiLineString': function(node, container) {
|
||||
var parts = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, parts, container]);
|
||||
this.readChildNodes(node, parts);
|
||||
container.geometry = {
|
||||
type: ol.geom.GeometryType.MULTILINESTRING,
|
||||
parts: parts
|
||||
};
|
||||
},
|
||||
'lineStringMember': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'MultiPolygon': function(node, container) {
|
||||
var parts = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, parts, container]);
|
||||
this.readChildNodes(node, parts);
|
||||
container.geometry = {
|
||||
type: ol.geom.GeometryType.MULTIPOLYGON,
|
||||
parts: parts
|
||||
};
|
||||
},
|
||||
'polygonMember': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'Point': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, coordinates, container]);
|
||||
this.readChildNodes(node, coordinates);
|
||||
var point = {
|
||||
type: ol.geom.GeometryType.POINT,
|
||||
coordinates: coordinates[0][0]
|
||||
};
|
||||
// in the case of a multi geometry this is parts
|
||||
if (goog.isArray(container)) {
|
||||
container.push(point);
|
||||
} else {
|
||||
container.geometry = point;
|
||||
}
|
||||
},
|
||||
'LineString': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, coordinates, container]);
|
||||
this.readChildNodes(node, coordinates);
|
||||
var linestring = {
|
||||
type: ol.geom.GeometryType.LINESTRING,
|
||||
coordinates: coordinates[0]
|
||||
};
|
||||
// in the case of a multi geometry this is parts
|
||||
if (goog.isArray(container)) {
|
||||
container.push(linestring);
|
||||
} else {
|
||||
container.geometry = linestring;
|
||||
}
|
||||
},
|
||||
'Polygon': function(node, container) {
|
||||
var obj = {outer: null, inner: []};
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, obj, container]);
|
||||
this.readChildNodes(node, obj);
|
||||
obj.inner.unshift(obj.outer);
|
||||
var polygon = {
|
||||
type: ol.geom.GeometryType.POLYGON,
|
||||
coordinates: obj.inner
|
||||
};
|
||||
// in the case of a multi geometry this is parts
|
||||
if (goog.isArray(container)) {
|
||||
container.push(polygon);
|
||||
} else {
|
||||
container.geometry = polygon;
|
||||
}
|
||||
},
|
||||
'LinearRing': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, coordinates, container]);
|
||||
this.readChildNodes(node, coordinates);
|
||||
if (goog.isArray(container)) {
|
||||
container.push(coordinates);
|
||||
} else {
|
||||
container.geometry = {
|
||||
type: ol.geom.GeometryType.LINEARRING,
|
||||
coordinates: coordinates[0]
|
||||
};
|
||||
}
|
||||
},
|
||||
'coordinates': function(node, coordinates) {
|
||||
var str = this.getChildValue(node).replace(
|
||||
this.regExes.trimSpace, '');
|
||||
str = str.replace(this.regExes.trimComma, ',');
|
||||
var coords;
|
||||
var cs = node.getAttribute('cs') || ',';
|
||||
var ts = node.getAttribute('ts') || this.regExes.splitSpace;
|
||||
var pointList = str.split(ts);
|
||||
var numPoints = pointList.length;
|
||||
var points = new Array(numPoints);
|
||||
for (var i = 0; i < numPoints; ++i) {
|
||||
coords = goog.array.map(pointList[i].split(cs), parseFloat);
|
||||
if (this.axisOrientation.substr(0, 2) === 'en') {
|
||||
points[i] = coords;
|
||||
} else {
|
||||
if (coords.length === 2) {
|
||||
points[i] = coords.reverse();
|
||||
} else if (coords.length === 3) {
|
||||
points[i] = [coords[1], coords[0], coords[2]];
|
||||
}
|
||||
}
|
||||
}
|
||||
coordinates.push(points);
|
||||
},
|
||||
'coord': function(node, coordinates) {
|
||||
var coord = {};
|
||||
if (coordinates.length === 0) {
|
||||
coordinates.push([]);
|
||||
}
|
||||
this.readChildNodes(node, coord);
|
||||
if (goog.isDef(coord.z)) {
|
||||
coordinates.push([coord.x, coord.y, coord.z]);
|
||||
} else {
|
||||
coordinates[0].push([coord.x, coord.y]);
|
||||
}
|
||||
},
|
||||
'X': function(node, coord) {
|
||||
coord.x = parseFloat(this.getChildValue(node));
|
||||
},
|
||||
'Y': function(node, coord) {
|
||||
coord.y = parseFloat(this.getChildValue(node));
|
||||
},
|
||||
'Z': function(node, coord) {
|
||||
coord.z = parseFloat(this.getChildValue(node));
|
||||
}
|
||||
}
|
||||
};
|
||||
this.featureNSReaders_ = {
|
||||
'*': function(node, obj) {
|
||||
// The node can either be named like the featureType, or it
|
||||
// can be a child of the feature:featureType. Children can be
|
||||
// geometry or attributes.
|
||||
var name;
|
||||
var local = node.localName || node.nodeName.split(':').pop();
|
||||
// Since an attribute can have the same name as the feature type
|
||||
// we only want to read the node as a feature if the parent
|
||||
// node can have feature nodes as children. In this case, the
|
||||
// obj.features property is set.
|
||||
if (obj.features) {
|
||||
if (!this.singleFeatureType &&
|
||||
(goog.array.indexOf(this.featureType, local) !== -1)) {
|
||||
name = '_typeName';
|
||||
} else if (local === this.featureType) {
|
||||
name = '_typeName';
|
||||
}
|
||||
} else {
|
||||
// Assume attribute elements have one child node and that the child
|
||||
// is a text node. Otherwise assume it is a geometry node.
|
||||
if (node.childNodes.length === 0 ||
|
||||
(node.childNodes.length === 1 &&
|
||||
node.firstChild.nodeType === 3)) {
|
||||
if (this.extractAttributes) {
|
||||
name = '_attribute';
|
||||
}
|
||||
} else {
|
||||
name = '_geometry';
|
||||
}
|
||||
}
|
||||
if (name) {
|
||||
this.readers[this.featureNS][name].apply(this, [node, obj]);
|
||||
}
|
||||
},
|
||||
'_typeName': function(node, obj) {
|
||||
var container = {properties: {}};
|
||||
this.readChildNodes(node, container);
|
||||
// look for common gml namespaced elements
|
||||
if (container.name) {
|
||||
container.properties.name = container.name;
|
||||
}
|
||||
var feature = new ol.Feature(container.properties);
|
||||
var geom = container.geometry;
|
||||
if (geom) {
|
||||
var geometry = this.createGeometry({geometry: geom});
|
||||
if (goog.isDef(geometry)) {
|
||||
feature.setGeometry(geometry);
|
||||
}
|
||||
}
|
||||
// TODO set feature.type and feature.namespace
|
||||
var fid = node.getAttribute('fid') ||
|
||||
this.getAttributeNS(node, this.defaultNamespaceURI, 'id');
|
||||
if (!goog.isNull(fid)) {
|
||||
feature.setId(fid);
|
||||
}
|
||||
obj.features.push(feature);
|
||||
},
|
||||
'_geometry': function(node, obj) {
|
||||
if (!this.geometryName) {
|
||||
this.geometryName = node.nodeName.split(':').pop();
|
||||
}
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'_attribute': function(node, obj) {
|
||||
var local = node.localName || node.nodeName.split(':').pop();
|
||||
var value = this.getChildValue(node);
|
||||
obj.properties[local] = value;
|
||||
}
|
||||
};
|
||||
if (goog.isDef(this.featureNS)) {
|
||||
this.readers[this.featureNS] = this.featureNSReaders_;
|
||||
}
|
||||
this.writers = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'featureMember': function(obj) {
|
||||
var node = this.createElementNS('gml:featureMember');
|
||||
this.writeNode('_typeName', obj, this.featureNS, node);
|
||||
return node;
|
||||
},
|
||||
'MultiPoint': function(geometry) {
|
||||
var node = this.createElementNS('gml:MultiPoint');
|
||||
var components = geometry.getComponents();
|
||||
for (var i = 0, ii = components.length; i < ii; ++i) {
|
||||
this.writeNode('pointMember', components[i], null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'pointMember': function(geometry) {
|
||||
var node = this.createElementNS('gml:pointMember');
|
||||
this.writeNode('Point', geometry, null, node);
|
||||
return node;
|
||||
},
|
||||
'MultiLineString': function(geometry) {
|
||||
var node = this.createElementNS('gml:MultiLineString');
|
||||
var components = geometry.getComponents();
|
||||
for (var i = 0, ii = components.length; i < ii; ++i) {
|
||||
this.writeNode('lineStringMember', components[i], null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'lineStringMember': function(geometry) {
|
||||
var node = this.createElementNS('gml:lineStringMember');
|
||||
this.writeNode('LineString', geometry, null, node);
|
||||
return node;
|
||||
},
|
||||
'MultiPolygon': function(geometry) {
|
||||
var node = this.createElementNS('gml:MultiPolygon');
|
||||
var components = geometry.getComponents();
|
||||
for (var i = 0, ii = components.length; i < ii; ++i) {
|
||||
this.writeNode('polygonMember', components[i], null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'polygonMember': function(geometry) {
|
||||
var node = this.createElementNS('gml:polygonMember');
|
||||
this.writeNode('Polygon', geometry, null, node);
|
||||
return node;
|
||||
},
|
||||
'GeometryCollection': function(geometry) {
|
||||
var node = this.createElementNS('gml:GeometryCollection');
|
||||
var components = geometry.getComponents();
|
||||
for (var i = 0, ii = components.length; i < ii; ++i) {
|
||||
this.writeNode('geometryMember', components[i], null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'geometryMember': function(geometry) {
|
||||
var node = this.createElementNS('gml:geometryMember');
|
||||
var child = this.writeNode('_geometry', geometry, this.featureNS);
|
||||
node.appendChild(child.firstChild);
|
||||
return node;
|
||||
}
|
||||
},
|
||||
'http://www.opengis.net/wfs': {
|
||||
'FeatureCollection': function(features) {
|
||||
/**
|
||||
* This is only here because GML2 only describes abstract
|
||||
* feature collections. Typically, you would not be using
|
||||
* the GML format to write wfs elements. This just provides
|
||||
* some way to write out lists of features. GML3 defines the
|
||||
* featureMembers element, so that is used by default instead.
|
||||
*/
|
||||
var node = this.createElementNS('wfs:FeatureCollection',
|
||||
'http://www.opengis.net/wfs');
|
||||
for (var i = 0, ii = features.length; i < ii; ++i) {
|
||||
this.writeNode('featureMember', features[i], null, node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
};
|
||||
this.featureNSWiters_ = {
|
||||
'_typeName': function(feature) {
|
||||
var node = this.createElementNS('feature:' + this.featureType,
|
||||
this.featureNS);
|
||||
var fid = feature.getId();
|
||||
if (goog.isDef(fid)) {
|
||||
this.setAttributeNS(node, this.defaultNamespaceURI, 'fid', fid);
|
||||
}
|
||||
if (feature.getGeometry() !== null) {
|
||||
this.writeNode('_geometry', feature.getGeometry(), this.featureNS,
|
||||
node);
|
||||
}
|
||||
var attributes = feature.getAttributes(true);
|
||||
for (var name in attributes) {
|
||||
var value = attributes[name];
|
||||
if (goog.isDefAndNotNull(value)) {
|
||||
this.writeNode('_attribute', {name: name, value: value},
|
||||
this.featureNS, node);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'_geometry': function(geometry) {
|
||||
var node = this.createElementNS('feature:' + this.geometryName,
|
||||
this.featureNS);
|
||||
var type = geometry.getType(), child;
|
||||
if (type === ol.geom.GeometryType.POINT) {
|
||||
child = this.writeNode('Point', geometry, null, node);
|
||||
} else if (type === ol.geom.GeometryType.MULTIPOINT) {
|
||||
child = this.writeNode('MultiPoint', geometry, null, node);
|
||||
} else if (type === ol.geom.GeometryType.LINEARRING) {
|
||||
child = this.writeNode('LinearRing', geometry.getCoordinates(), null,
|
||||
node);
|
||||
} else if (type === ol.geom.GeometryType.LINESTRING) {
|
||||
child = this.writeNode('LineString', geometry, null, node);
|
||||
} else if (type === ol.geom.GeometryType.MULTILINESTRING) {
|
||||
child = this.writeNode('MultiLineString', geometry, null, node);
|
||||
} else if (type === ol.geom.GeometryType.POLYGON) {
|
||||
child = this.writeNode('Polygon', geometry, null, node);
|
||||
} else if (type === ol.geom.GeometryType.MULTIPOLYGON) {
|
||||
child = this.writeNode('MultiPolygon', geometry, null, node);
|
||||
} else if (type === ol.geom.GeometryType.GEOMETRYCOLLECTION) {
|
||||
child = this.writeNode('GeometryCollection', geometry, null, node);
|
||||
}
|
||||
if (goog.isDefAndNotNull(this.srsName)) {
|
||||
this.setAttributeNS(child, null, 'srsName', this.srsName);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'_attribute': function(obj) {
|
||||
var node = this.createElementNS('feature:' + obj.name, this.featureNS);
|
||||
node.appendChild(this.createTextNode(obj.value));
|
||||
return node;
|
||||
}
|
||||
};
|
||||
if (goog.isDef(this.featureNS)) {
|
||||
this.writers[this.featureNS] = this.featureNSWiters_;
|
||||
}
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.GML, ol.parser.XML);
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|Document|Element|Object} data Data to read.
|
||||
* @param {ol.parser.GMLReadOptions=} opt_options Read options.
|
||||
* @return {ol.parser.ReadFeaturesResult} An object representing the document.
|
||||
*/
|
||||
ol.parser.ogc.GML.prototype.read = function(data, opt_options) {
|
||||
var srsName;
|
||||
if (goog.isDef(opt_options) && goog.isDef(opt_options.srsName)) {
|
||||
srsName = opt_options.srsName;
|
||||
} else if (goog.isDef(this.readOptions) &&
|
||||
goog.isDef(this.readOptions.srsName)) {
|
||||
srsName = this.readOptions.srsName;
|
||||
}
|
||||
if (goog.isDef(srsName)) {
|
||||
this.srsName = goog.isString(srsName) ? srsName : srsName.getCode();
|
||||
}
|
||||
if (goog.isDef(opt_options) && goog.isDef(opt_options.axisOrientation)) {
|
||||
this.axisOrientation = opt_options.axisOrientation;
|
||||
} else if (goog.isDef(this.readOptions) &&
|
||||
goog.isDef(this.readOptions.axisOrientation)) {
|
||||
this.axisOrientation = this.readOptions.axisOrientation;
|
||||
}
|
||||
if (typeof data == 'string') {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
if (data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var obj = /** @type {ol.parser.ReadFeaturesResult} */
|
||||
({features: [], metadata: {}});
|
||||
this.readNode(data, obj, true);
|
||||
obj.metadata.projection = this.srsName;
|
||||
delete this.srsName;
|
||||
delete this.axisOrientation;
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element|Document} node The node to be read.
|
||||
* @param {Object} obj The object to be modified.
|
||||
* @param {boolean=} opt_first Should be set to true for the first node read.
|
||||
* This is usually the readNode call in the read method. Without this being
|
||||
* set, auto-configured properties will stick on subsequent reads.
|
||||
* @return {Object} The input object, modified (or a new one if none was
|
||||
* provided).
|
||||
*/
|
||||
ol.parser.ogc.GML.prototype.readNode = function(node, obj, opt_first) {
|
||||
// on subsequent calls of this.read(), we want to reset auto-
|
||||
// configured properties and auto-configure again.
|
||||
if (opt_first === true && this.autoConfig === true) {
|
||||
this.featureType = null;
|
||||
delete this.readers[this.featureNS];
|
||||
delete this.writers[this.featureNS];
|
||||
this.featureNS = null;
|
||||
}
|
||||
// featureType auto-configuration
|
||||
if (!this.featureNS && (!(node.namespaceURI in this.readers) &&
|
||||
node.parentNode.namespaceURI == this.defaultNamespaceURI &&
|
||||
(/^(.*:)?featureMembers?$/).test(node.parentNode.nodeName))) {
|
||||
this.featureType = node.nodeName.split(':').pop();
|
||||
this.readers[node.namespaceURI] = this.featureNSReaders_;
|
||||
this.writers[node.namespaceURI] = this.featureNSWiters_;
|
||||
this.featureNS = node.namespaceURI;
|
||||
this.autoConfig = true;
|
||||
}
|
||||
return ol.parser.XML.prototype.readNode.apply(this, [node, obj]);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} container Geometry container.
|
||||
* @return {ol.geom.Geometry} The geometry created.
|
||||
*/
|
||||
// TODO use a mixin since this is also used in the KML parser
|
||||
ol.parser.ogc.GML.prototype.createGeometry = function(container) {
|
||||
var geometry = null, coordinates, i, ii;
|
||||
switch (container.geometry.type) {
|
||||
case ol.geom.GeometryType.POINT:
|
||||
geometry = new ol.geom.Point(container.geometry.coordinates);
|
||||
break;
|
||||
case ol.geom.GeometryType.LINEARRING:
|
||||
geometry = new ol.geom.LinearRing(container.geometry.coordinates);
|
||||
break;
|
||||
case ol.geom.GeometryType.LINESTRING:
|
||||
geometry = new ol.geom.LineString(container.geometry.coordinates);
|
||||
break;
|
||||
case ol.geom.GeometryType.POLYGON:
|
||||
geometry = new ol.geom.Polygon(container.geometry.coordinates);
|
||||
break;
|
||||
case ol.geom.GeometryType.MULTIPOINT:
|
||||
coordinates = [];
|
||||
for (i = 0, ii = container.geometry.parts.length; i < ii; i++) {
|
||||
coordinates.push(container.geometry.parts[i].coordinates);
|
||||
}
|
||||
geometry = new ol.geom.MultiPoint(coordinates);
|
||||
break;
|
||||
case ol.geom.GeometryType.MULTILINESTRING:
|
||||
coordinates = [];
|
||||
for (i = 0, ii = container.geometry.parts.length; i < ii; i++) {
|
||||
coordinates.push(container.geometry.parts[i].coordinates);
|
||||
}
|
||||
geometry = new ol.geom.MultiLineString(coordinates);
|
||||
break;
|
||||
case ol.geom.GeometryType.MULTIPOLYGON:
|
||||
coordinates = [];
|
||||
for (i = 0, ii = container.geometry.parts.length; i < ii; i++) {
|
||||
coordinates.push(container.geometry.parts[i].coordinates);
|
||||
}
|
||||
geometry = new ol.geom.MultiPolygon(coordinates);
|
||||
break;
|
||||
case ol.geom.GeometryType.GEOMETRYCOLLECTION:
|
||||
var geometries = [];
|
||||
for (i = 0, ii = container.geometry.parts.length; i < ii; i++) {
|
||||
geometries.push(this.createGeometry({
|
||||
geometry: container.geometry.parts[i]
|
||||
}));
|
||||
}
|
||||
geometry = new ol.geom.GeometryCollection(geometries);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return geometry;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a GML document provided as a string.
|
||||
* @param {string} str GML document.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.ogc.GML.prototype.readFeaturesFromString = function(str) {
|
||||
return this.read(str);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Applies the writeOptions passed into the write function.
|
||||
* @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as
|
||||
* GML.
|
||||
* @param {ol.parser.GMLWriteOptions=} opt_options Write options.
|
||||
*/
|
||||
ol.parser.ogc.GML.prototype.applyWriteOptions = function(obj, opt_options) {
|
||||
// srsName handling: opt_options -> this.writeOptions -> obj.metadata
|
||||
var srsName;
|
||||
if (goog.isDef(opt_options) && goog.isDef(opt_options.srsName)) {
|
||||
srsName = opt_options.srsName;
|
||||
} else if (goog.isDef(this.writeOptions) &&
|
||||
goog.isDef(this.writeOptions.srsName)) {
|
||||
srsName = this.writeOptions.srsName;
|
||||
} else if (goog.isDef(obj.metadata)) {
|
||||
srsName = obj.metadata.projection;
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(srsName), 'srsName required for writing GML');
|
||||
this.srsName = goog.isString(srsName) ? srsName : srsName.getCode();
|
||||
// axisOrientation handling: opt_options -> this.writeOptions
|
||||
if (goog.isDef(opt_options) && goog.isDef(opt_options.axisOrientation)) {
|
||||
this.axisOrientation = opt_options.axisOrientation;
|
||||
} else if (goog.isDef(this.writeOptions) &&
|
||||
goog.isDef(this.writeOptions.axisOrientation)) {
|
||||
this.axisOrientation = this.writeOptions.axisOrientation;
|
||||
} else {
|
||||
this.axisOrientation = ol.proj.get(this.srsName).getAxisOrientation();
|
||||
}
|
||||
};
|
||||
@@ -1,144 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.GML_v2');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.parser.ogc.GML');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read and write [GML](http://www.opengeospatial.org/standards/gml)
|
||||
* version 2.1.2
|
||||
*
|
||||
* @constructor
|
||||
* @param {ol.parser.GMLOptions=} opt_options Optional configuration object.
|
||||
* @extends {ol.parser.ogc.GML}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.ogc.GML_v2 = function(opt_options) {
|
||||
this.schemaLocation = 'http://www.opengis.net/gml ' +
|
||||
'http://schemas.opengis.net/gml/2.1.2/feature.xsd';
|
||||
goog.base(this, opt_options);
|
||||
goog.object.extend(this.readers['http://www.opengis.net/gml'], {
|
||||
'outerBoundaryIs': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readChildNodes(node, coordinates);
|
||||
container['outer'] = coordinates[0][0];
|
||||
},
|
||||
'innerBoundaryIs': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readChildNodes(node, coordinates);
|
||||
container.inner.push(coordinates[0][0]);
|
||||
},
|
||||
'Box': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, coordinates, container]);
|
||||
this.readChildNodes(node, coordinates);
|
||||
container.projection = node.getAttribute('srsName');
|
||||
container.bounds = [
|
||||
coordinates[0][0][0], coordinates[0][0][1],
|
||||
coordinates[0][1][0], coordinates[0][1][1]
|
||||
];
|
||||
}
|
||||
});
|
||||
goog.object.extend(this.writers['http://www.opengis.net/gml'], {
|
||||
'Point': function(geometry) {
|
||||
var node = this.createElementNS('gml:Point');
|
||||
this.writeNode('coordinates', [geometry.getCoordinates()], null, node);
|
||||
return node;
|
||||
},
|
||||
'coordinates': function(coordinates) {
|
||||
var numCoordinates = coordinates.length;
|
||||
var parts = new Array(numCoordinates);
|
||||
for (var i = 0; i < numCoordinates; ++i) {
|
||||
var coord = coordinates[i];
|
||||
var part = goog.array.concat(coord);
|
||||
if (this.axisOrientation.substr(0, 2) !== 'en') {
|
||||
part[0] = coord[1];
|
||||
part[1] = coord[0];
|
||||
}
|
||||
parts[i] = part.join(',');
|
||||
}
|
||||
var value = parts.join(' ');
|
||||
var node = this.createElementNS('gml:coordinates');
|
||||
this.setAttributeNS(node, null, 'decimal', '.');
|
||||
this.setAttributeNS(node, null, 'cs', ',');
|
||||
this.setAttributeNS(node, null, 'ts', ' ');
|
||||
node.appendChild(this.createTextNode(value));
|
||||
return node;
|
||||
},
|
||||
'LineString': function(geometry) {
|
||||
var node = this.createElementNS('gml:LineString');
|
||||
this.writeNode('coordinates', geometry.getCoordinates(), null, node);
|
||||
return node;
|
||||
},
|
||||
'Polygon': function(geometry) {
|
||||
var node = this.createElementNS('gml:Polygon');
|
||||
var coordinates = geometry.getCoordinates();
|
||||
/**
|
||||
* Though there continues to be ambiguity around this, GML references
|
||||
* ISO 19107, which says polygons have counter-clockwise exterior rings
|
||||
* and clockwise interior rings. The ambiguity comes because the
|
||||
* the Simple Feature Access - SQL spec (ISO 19125-2) says that no
|
||||
* winding order is enforced. Anyway, we write out counter-clockwise
|
||||
* exterior and clockwise interior here but accept either when reading.
|
||||
*/
|
||||
this.writeNode('outerBoundaryIs', coordinates[0].reverse(), null, node);
|
||||
for (var i = 1; i < coordinates.length; ++i) {
|
||||
this.writeNode('innerBoundaryIs', coordinates[i].reverse(), null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'outerBoundaryIs': function(ring) {
|
||||
var node = this.createElementNS('gml:outerBoundaryIs');
|
||||
this.writeNode('LinearRing', ring, null, node);
|
||||
return node;
|
||||
},
|
||||
'innerBoundaryIs': function(ring) {
|
||||
var node = this.createElementNS('gml:innerBoundaryIs');
|
||||
this.writeNode('LinearRing', ring, null, node);
|
||||
return node;
|
||||
},
|
||||
'LinearRing': function(ring) {
|
||||
var node = this.createElementNS('gml:LinearRing');
|
||||
this.writeNode('coordinates', ring, null, node);
|
||||
return node;
|
||||
},
|
||||
'Box': function(extent) {
|
||||
var node = this.createElementNS('gml:Box');
|
||||
var coordinates = [
|
||||
[extent[0], extent[1]],
|
||||
[extent[2], extent[3]]
|
||||
];
|
||||
this.writeNode('coordinates', coordinates, null, node);
|
||||
// srsName attribute is optional for gml:Box
|
||||
if (goog.isDefAndNotNull(this.srsName)) {
|
||||
node.setAttribute('srsName', this.srsName);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
});
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.GML_v2, ol.parser.ogc.GML);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as
|
||||
* GML.
|
||||
* @param {ol.parser.GMLWriteOptions=} opt_options Write options.
|
||||
* @return {string} A string representing the GML document.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.ogc.GML_v2.prototype.write = function(obj, opt_options) {
|
||||
this.applyWriteOptions(obj, opt_options);
|
||||
var root = this.writeNode('FeatureCollection', obj.features,
|
||||
'http://www.opengis.net/wfs');
|
||||
this.setAttributeNS(
|
||||
root, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation', this.schemaLocation);
|
||||
var gml = this.serialize(root);
|
||||
delete this.srsName;
|
||||
delete this.axisOrientation;
|
||||
return gml;
|
||||
};
|
||||
@@ -1,441 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.GML_v3');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.functions');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.parser.ogc.GML');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read and write [GML](http://www.opengeospatial.org/standards/gml)
|
||||
* version 3.1.1
|
||||
*
|
||||
* @constructor
|
||||
* @param {ol.parser.GMLOptions=} opt_options Optional configuration object.
|
||||
* @extends {ol.parser.ogc.GML}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.ogc.GML_v3 = function(opt_options) {
|
||||
this.schemaLocation = 'http://www.opengis.net/gml ' +
|
||||
'http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/' +
|
||||
'1.0.0/gmlsf.xsd';
|
||||
goog.base(this, opt_options);
|
||||
this.featureNSWiters_['_geometry'] = function(geometry) {
|
||||
var node = this.createElementNS('feature:' + this.geometryName,
|
||||
this.featureNS);
|
||||
var type = geometry.getType(), child;
|
||||
if (type === ol.geom.GeometryType.POINT) {
|
||||
child = this.writeNode('Point', geometry, null, node);
|
||||
} else if (type === ol.geom.GeometryType.MULTIPOINT) {
|
||||
child = this.writeNode('MultiPoint', geometry, null, node);
|
||||
} else if (type === ol.geom.GeometryType.LINESTRING) {
|
||||
if (this.curve === true) {
|
||||
child = this.writeNode('Curve', geometry, null, node);
|
||||
} else {
|
||||
child = this.writeNode('LineString', geometry, null, node);
|
||||
}
|
||||
} else if (type === ol.geom.GeometryType.LINEARRING) {
|
||||
child = this.writeNode('LinearRing', geometry.getCoordinates(), null,
|
||||
node);
|
||||
} else if (type === ol.geom.GeometryType.MULTILINESTRING) {
|
||||
if (this.multiCurve === false) {
|
||||
child = this.writeNode('MultiLineString', geometry, null, node);
|
||||
} else {
|
||||
child = this.writeNode('MultiCurve', geometry, null, node);
|
||||
}
|
||||
} else if (type === ol.geom.GeometryType.POLYGON) {
|
||||
if (this.surface === true) {
|
||||
child = this.writeNode('Surface', geometry, null, node);
|
||||
} else {
|
||||
child = this.writeNode('Polygon', geometry, null, node);
|
||||
}
|
||||
} else if (type === ol.geom.GeometryType.MULTIPOLYGON) {
|
||||
if (this.multiSurface === false) {
|
||||
child = this.writeNode('MultiPolygon', geometry, null, node);
|
||||
} else {
|
||||
child = this.writeNode('MultiSurface', geometry, null, node);
|
||||
}
|
||||
} else if (type === ol.geom.GeometryType.GEOMETRYCOLLECTION) {
|
||||
child = this.writeNode('MultiGeometry', geometry, null, node);
|
||||
}
|
||||
if (goog.isDefAndNotNull(this.srsName)) {
|
||||
this.setAttributeNS(child, null, 'srsName', this.srsName);
|
||||
}
|
||||
return node;
|
||||
};
|
||||
goog.object.extend(this.readers['http://www.opengis.net/gml'], {
|
||||
'_inherit': goog.functions.sequence(
|
||||
this.readers['http://www.opengis.net/gml']['_inherit'],
|
||||
function(node, obj, container) {
|
||||
// SRSReferenceGroup attributes
|
||||
var dim = parseInt(node.getAttribute('srsDimension'), 10) ||
|
||||
(container && container.srsDimension);
|
||||
if (dim) {
|
||||
obj.srsDimension = dim;
|
||||
}
|
||||
}),
|
||||
'featureMembers': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'Curve': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, coordinates, container]);
|
||||
this.readChildNodes(node, coordinates);
|
||||
var linestring = {
|
||||
type: ol.geom.GeometryType.LINESTRING,
|
||||
coordinates: coordinates[0]
|
||||
};
|
||||
// in the case of a multi geometry this is parts
|
||||
if (goog.isArray(container)) {
|
||||
container.push(linestring);
|
||||
} else {
|
||||
container.geometry = linestring;
|
||||
}
|
||||
},
|
||||
'segments': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'LineStringSegment': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readChildNodes(node, coordinates);
|
||||
container.push(coordinates[0]);
|
||||
},
|
||||
'pos': function(node, obj) {
|
||||
var str = this.getChildValue(node).replace(
|
||||
this.regExes.trimSpace, '');
|
||||
var coords = goog.array.map(str.split(this.regExes.splitSpace),
|
||||
parseFloat);
|
||||
if (this.axisOrientation.substr(0, 2) === 'en') {
|
||||
obj.push([coords]);
|
||||
} else {
|
||||
if (coords.length === 2) {
|
||||
obj.push([coords.reverse()]);
|
||||
} else if (coords.length === 3) {
|
||||
obj.push([[coords[1], coords[0], coords[2]]]);
|
||||
}
|
||||
}
|
||||
},
|
||||
'posList': function(node, obj) {
|
||||
var str = this.getChildValue(node).replace(
|
||||
this.regExes.trimSpace, '');
|
||||
var coords = str.split(this.regExes.splitSpace);
|
||||
// The "dimension" attribute is from the GML 3.0.1 spec.
|
||||
var dim = obj.srsDimension ||
|
||||
parseInt(node.getAttribute('srsDimension') ||
|
||||
node.getAttribute('dimension'), 10) || 2;
|
||||
var x, y, z;
|
||||
var numPoints = coords.length / dim;
|
||||
var points = new Array(numPoints);
|
||||
for (var i = 0, ii = coords.length; i < ii; i += dim) {
|
||||
x = parseFloat(coords[i]);
|
||||
y = parseFloat(coords[i + 1]);
|
||||
var xy = this.axisOrientation.substr(0, 2) === 'en';
|
||||
if (dim === 3) {
|
||||
if (xy) {
|
||||
points[i / dim] = [x, y, parseFloat(coords[i + 2])];
|
||||
} else {
|
||||
points[i / dim] = [y, x, parseFloat(coords[i + 2])];
|
||||
}
|
||||
} else if (dim === 2) {
|
||||
if (xy) {
|
||||
points[i / dim] = [x, y];
|
||||
} else {
|
||||
points[i / dim] = [y, x];
|
||||
}
|
||||
}
|
||||
}
|
||||
obj.push(points);
|
||||
},
|
||||
'Surface': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'patches': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'PolygonPatch': function(node, obj) {
|
||||
this.readers[this.defaultNamespaceURI]['Polygon'].apply(this,
|
||||
[node, obj]);
|
||||
},
|
||||
'exterior': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readChildNodes(node, coordinates);
|
||||
container.outer = coordinates[0][0];
|
||||
},
|
||||
'interior': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readChildNodes(node, coordinates);
|
||||
container.inner.push(coordinates[0][0]);
|
||||
},
|
||||
'MultiCurve': function(node, container) {
|
||||
var parts = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, parts, container]);
|
||||
this.readChildNodes(node, parts);
|
||||
container.geometry = {
|
||||
type: ol.geom.GeometryType.MULTILINESTRING,
|
||||
parts: parts
|
||||
};
|
||||
},
|
||||
'curveMember': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'MultiSurface': function(node, container) {
|
||||
var parts = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, parts, container]);
|
||||
this.readChildNodes(node, parts);
|
||||
container.geometry = {
|
||||
type: ol.geom.GeometryType.MULTIPOLYGON,
|
||||
parts: parts
|
||||
};
|
||||
},
|
||||
'surfaceMember': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'surfaceMembers': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'pointMembers': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'lineStringMembers': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'polygonMembers': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'geometryMembers': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'Envelope': function(node, container) {
|
||||
var coordinates = [];
|
||||
this.readers[this.defaultNamespaceURI]['_inherit'].apply(this,
|
||||
[node, coordinates, container]);
|
||||
this.readChildNodes(node, coordinates);
|
||||
container.projection = node.getAttribute('srsName');
|
||||
container.bounds = [
|
||||
coordinates[0][0], coordinates[0][1],
|
||||
coordinates[1][0], coordinates[1][1]
|
||||
];
|
||||
},
|
||||
'lowerCorner': function(node, envelope) {
|
||||
var coordinates = [];
|
||||
this.readers[this.defaultNamespaceURI]['pos'].apply(this,
|
||||
[node, coordinates]);
|
||||
envelope.push(coordinates[0][0]);
|
||||
},
|
||||
'upperCorner': function(node, envelope) {
|
||||
var coordinates = [];
|
||||
this.readers[this.defaultNamespaceURI]['pos'].apply(this,
|
||||
[node, coordinates]);
|
||||
envelope.push(coordinates[0][0]);
|
||||
}
|
||||
});
|
||||
goog.object.extend(this.writers['http://www.opengis.net/gml'], {
|
||||
'featureMembers': function(features) {
|
||||
var node = this.createElementNS('gml:featureMembers');
|
||||
for (var i = 0, ii = features.length; i < ii; ++i) {
|
||||
this.writeNode('_typeName', features[i], this.featureNS, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'Point': function(geometry) {
|
||||
var node = this.createElementNS('gml:Point');
|
||||
this.writeNode('pos', geometry.getCoordinates(), null, node);
|
||||
return node;
|
||||
},
|
||||
'pos': function(point) {
|
||||
// only 2d for simple features profile
|
||||
var pos;
|
||||
if (this.axisOrientation.substr(0, 2) === 'en') {
|
||||
pos = (point[0] + ' ' + point[1]);
|
||||
} else {
|
||||
pos = (point[1] + ' ' + point[0]);
|
||||
}
|
||||
var node = this.createElementNS('gml:pos');
|
||||
node.appendChild(this.createTextNode(pos));
|
||||
return node;
|
||||
},
|
||||
'LineString': function(geometry) {
|
||||
var node = this.createElementNS('gml:LineString');
|
||||
this.writeNode('posList', geometry.getCoordinates(), null, node);
|
||||
return node;
|
||||
},
|
||||
'Curve': function(geometry) {
|
||||
var node = this.createElementNS('gml:Curve');
|
||||
this.writeNode('segments', geometry, null, node);
|
||||
return node;
|
||||
},
|
||||
'segments': function(geometry) {
|
||||
var node = this.createElementNS('gml:segments');
|
||||
this.writeNode('LineStringSegment', geometry, null, node);
|
||||
return node;
|
||||
},
|
||||
'LineStringSegment': function(geometry) {
|
||||
var node = this.createElementNS('gml:LineStringSegment');
|
||||
this.writeNode('posList', geometry.getCoordinates(), null, node);
|
||||
return node;
|
||||
},
|
||||
'posList': function(points) {
|
||||
// only 2d for simple features profile
|
||||
var len = points.length;
|
||||
var parts = new Array(len);
|
||||
var point;
|
||||
for (var i = 0; i < len; ++i) {
|
||||
point = points[i];
|
||||
if (this.axisOrientation.substr(0, 2) === 'en') {
|
||||
parts[i] = point[0] + ' ' + point[1];
|
||||
} else {
|
||||
parts[i] = point[1] + ' ' + point[0];
|
||||
}
|
||||
}
|
||||
var node = this.createElementNS('gml:posList');
|
||||
node.appendChild(this.createTextNode(parts.join(' ')));
|
||||
return node;
|
||||
},
|
||||
'Surface': function(geometry) {
|
||||
var node = this.createElementNS('gml:Surface');
|
||||
this.writeNode('patches', geometry, null, node);
|
||||
return node;
|
||||
},
|
||||
'patches': function(geometry) {
|
||||
var node = this.createElementNS('gml:patches');
|
||||
this.writeNode('PolygonPatch', geometry, null, node);
|
||||
return node;
|
||||
},
|
||||
'PolygonPatch': function(geometry) {
|
||||
var node = this.createElementNS('gml:PolygonPatch');
|
||||
node.setAttribute('interpolation', 'planar');
|
||||
var coordinates = geometry.getCoordinates();
|
||||
this.writeNode('exterior', coordinates[0].reverse(), null, node);
|
||||
for (var i = 1, len = coordinates.length; i < len; ++i) {
|
||||
this.writeNode('interior', coordinates[i].reverse(), null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'Polygon': function(geometry) {
|
||||
var node = this.createElementNS('gml:Polygon');
|
||||
var coordinates = geometry.getCoordinates();
|
||||
/**
|
||||
* Though there continues to be ambiguity around this, GML references
|
||||
* ISO 19107, which says polygons have counter-clockwise exterior rings
|
||||
* and clockwise interior rings. The ambiguity comes because the
|
||||
* the Simple Feature Access - SQL spec (ISO 19125-2) says that no
|
||||
* winding order is enforced. Anyway, we write out counter-clockwise
|
||||
* exterior and clockwise interior here but accept either when reading.
|
||||
*/
|
||||
this.writeNode('exterior', coordinates[0].reverse(), null, node);
|
||||
for (var i = 1, len = coordinates.length; i < len; ++i) {
|
||||
this.writeNode('interior', coordinates[i].reverse(), null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'exterior': function(ring) {
|
||||
var node = this.createElementNS('gml:exterior');
|
||||
this.writeNode('LinearRing', ring, null, node);
|
||||
return node;
|
||||
},
|
||||
'interior': function(ring) {
|
||||
var node = this.createElementNS('gml:interior');
|
||||
this.writeNode('LinearRing', ring, null, node);
|
||||
return node;
|
||||
},
|
||||
'LinearRing': function(ring) {
|
||||
var node = this.createElementNS('gml:LinearRing');
|
||||
this.writeNode('posList', ring, null, node);
|
||||
return node;
|
||||
},
|
||||
'MultiCurve': function(geometry) {
|
||||
var node = this.createElementNS('gml:MultiCurve');
|
||||
var components = geometry.getComponents();
|
||||
for (var i = 0, len = components.length; i < len; ++i) {
|
||||
this.writeNode('curveMember', components[i], null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'curveMember': function(geometry) {
|
||||
var node = this.createElementNS('gml:curveMember');
|
||||
if (this.curve) {
|
||||
this.writeNode('Curve', geometry, null, node);
|
||||
} else {
|
||||
this.writeNode('LineString', geometry, null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'MultiSurface': function(geometry) {
|
||||
var node = this.createElementNS('gml:MultiSurface');
|
||||
var components = geometry.getComponents();
|
||||
for (var i = 0, len = components.length; i < len; ++i) {
|
||||
this.writeNode('surfaceMember', components[i], null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'surfaceMember': function(polygon) {
|
||||
var node = this.createElementNS('gml:surfaceMember');
|
||||
if (this.surface) {
|
||||
this.writeNode('Surface', polygon, null, node);
|
||||
} else {
|
||||
this.writeNode('Polygon', polygon, null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'Envelope': function(bounds) {
|
||||
var node = this.createElementNS('gml:Envelope');
|
||||
this.writeNode('lowerCorner', bounds, null, node);
|
||||
this.writeNode('upperCorner', bounds, null, node);
|
||||
// srsName attribute is required for gml:Envelope
|
||||
if (goog.isDef(this.srsName)) {
|
||||
node.setAttribute('srsName', this.srsName);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'lowerCorner': function(bounds) {
|
||||
// only 2d for simple features profile
|
||||
var pos;
|
||||
if (this.axisOrientation.substr(0, 2) === 'en') {
|
||||
pos = (bounds[0] + ' ' + bounds[1]);
|
||||
} else {
|
||||
pos = (bounds[1] + ' ' + bounds[0]);
|
||||
}
|
||||
var node = this.createElementNS('gml:lowerCorner');
|
||||
node.appendChild(this.createTextNode(pos));
|
||||
return node;
|
||||
},
|
||||
'upperCorner': function(bounds) {
|
||||
// only 2d for simple features profile
|
||||
var pos;
|
||||
if (this.axisOrientation.substr(0, 2) === 'en') {
|
||||
pos = (bounds[2] + ' ' + bounds[3]);
|
||||
} else {
|
||||
pos = (bounds[3] + ' ' + bounds[2]);
|
||||
}
|
||||
var node = this.createElementNS('gml:upperCorner');
|
||||
node.appendChild(this.createTextNode(pos));
|
||||
return node;
|
||||
}
|
||||
});
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.GML_v3, ol.parser.ogc.GML);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.parser.ReadFeaturesResult} obj Object structure to write out as
|
||||
* XML.
|
||||
* @param {ol.parser.GMLWriteOptions=} opt_options Write options.
|
||||
* @return {string} An string representing the XML document.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.ogc.GML_v3.prototype.write = function(obj, opt_options) {
|
||||
this.applyWriteOptions(obj, opt_options);
|
||||
var root = this.writeNode('featureMembers', obj.features);
|
||||
this.setAttributeNS(
|
||||
root, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation', this.schemaLocation);
|
||||
var gml = this.serialize(root);
|
||||
delete this.srsName;
|
||||
delete this.axisOrientation;
|
||||
return gml;
|
||||
};
|
||||
@@ -1,214 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.OWSCommon_v1');
|
||||
goog.require('ol.parser.XML');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.XML}
|
||||
*/
|
||||
ol.parser.ogc.OWSCommon_v1 = function() {
|
||||
this.readers = {
|
||||
'http://www.opengis.net/ows': {
|
||||
'ServiceIdentification': function(node, obj) {
|
||||
obj['serviceIdentification'] = {};
|
||||
this.readChildNodes(node, obj['serviceIdentification']);
|
||||
},
|
||||
'Title': function(node, obj) {
|
||||
obj['title'] = this.getChildValue(node);
|
||||
},
|
||||
'Abstract': function(node, serviceIdentification) {
|
||||
serviceIdentification['abstract'] = this.getChildValue(node);
|
||||
},
|
||||
'Keywords': function(node, serviceIdentification) {
|
||||
serviceIdentification['keywords'] = {};
|
||||
this.readChildNodes(node, serviceIdentification['keywords']);
|
||||
},
|
||||
'Keyword': function(node, keywords) {
|
||||
keywords[this.getChildValue(node)] = true;
|
||||
},
|
||||
'ServiceType': function(node, serviceIdentification) {
|
||||
serviceIdentification['serviceType'] = {
|
||||
'codeSpace': node.getAttribute('codeSpace'),
|
||||
'value': this.getChildValue(node)};
|
||||
},
|
||||
'ServiceTypeVersion': function(node, serviceIdentification) {
|
||||
serviceIdentification['serviceTypeVersion'] = this.getChildValue(node);
|
||||
},
|
||||
'Fees': function(node, serviceIdentification) {
|
||||
serviceIdentification['fees'] = this.getChildValue(node);
|
||||
},
|
||||
'AccessConstraints': function(node, serviceIdentification) {
|
||||
serviceIdentification['accessConstraints'] =
|
||||
this.getChildValue(node);
|
||||
},
|
||||
'ServiceProvider': function(node, obj) {
|
||||
obj['serviceProvider'] = {};
|
||||
this.readChildNodes(node, obj['serviceProvider']);
|
||||
},
|
||||
'ProviderName': function(node, serviceProvider) {
|
||||
serviceProvider['providerName'] = this.getChildValue(node);
|
||||
},
|
||||
'ProviderSite': function(node, serviceProvider) {
|
||||
serviceProvider['providerSite'] = this.getAttributeNS(node,
|
||||
'http://www.w3.org/1999/xlink', 'href');
|
||||
},
|
||||
'ServiceContact': function(node, serviceProvider) {
|
||||
serviceProvider['serviceContact'] = {};
|
||||
this.readChildNodes(node, serviceProvider['serviceContact']);
|
||||
},
|
||||
'IndividualName': function(node, serviceContact) {
|
||||
serviceContact['individualName'] = this.getChildValue(node);
|
||||
},
|
||||
'PositionName': function(node, serviceContact) {
|
||||
serviceContact['positionName'] = this.getChildValue(node);
|
||||
},
|
||||
'ContactInfo': function(node, serviceContact) {
|
||||
serviceContact['contactInfo'] = {};
|
||||
this.readChildNodes(node, serviceContact['contactInfo']);
|
||||
},
|
||||
'Phone': function(node, contactInfo) {
|
||||
contactInfo['phone'] = {};
|
||||
this.readChildNodes(node, contactInfo['phone']);
|
||||
},
|
||||
'Voice': function(node, phone) {
|
||||
phone['voice'] = this.getChildValue(node);
|
||||
},
|
||||
'Address': function(node, contactInfo) {
|
||||
contactInfo['address'] = {};
|
||||
this.readChildNodes(node, contactInfo['address']);
|
||||
},
|
||||
'DeliveryPoint': function(node, address) {
|
||||
address['deliveryPoint'] = this.getChildValue(node);
|
||||
},
|
||||
'City': function(node, address) {
|
||||
address['city'] = this.getChildValue(node);
|
||||
},
|
||||
'AdministrativeArea': function(node, address) {
|
||||
address['administrativeArea'] = this.getChildValue(node);
|
||||
},
|
||||
'PostalCode': function(node, address) {
|
||||
address['postalCode'] = this.getChildValue(node);
|
||||
},
|
||||
'Country': function(node, address) {
|
||||
address['country'] = this.getChildValue(node);
|
||||
},
|
||||
'ElectronicMailAddress': function(node, address) {
|
||||
address['electronicMailAddress'] = this.getChildValue(node);
|
||||
},
|
||||
'Role': function(node, serviceContact) {
|
||||
serviceContact['role'] = this.getChildValue(node);
|
||||
},
|
||||
'OperationsMetadata': function(node, obj) {
|
||||
obj['operationsMetadata'] = {};
|
||||
this.readChildNodes(node, obj['operationsMetadata']);
|
||||
},
|
||||
'Operation': function(node, operationsMetadata) {
|
||||
var name = node.getAttribute('name');
|
||||
operationsMetadata[name] = {};
|
||||
this.readChildNodes(node, operationsMetadata[name]);
|
||||
},
|
||||
'DCP': function(node, operation) {
|
||||
operation['dcp'] = {};
|
||||
this.readChildNodes(node, operation['dcp']);
|
||||
},
|
||||
'HTTP': function(node, dcp) {
|
||||
dcp['http'] = {};
|
||||
this.readChildNodes(node, dcp['http']);
|
||||
},
|
||||
'Get': function(node, http) {
|
||||
if (!http['get']) {
|
||||
http['get'] = [];
|
||||
}
|
||||
var obj = {
|
||||
'url': this.getAttributeNS(node, 'http://www.w3.org/1999/xlink',
|
||||
'href')
|
||||
};
|
||||
this.readChildNodes(node, obj);
|
||||
http['get'].push(obj);
|
||||
},
|
||||
'Post': function(node, http) {
|
||||
if (!http['post']) {
|
||||
http['post'] = [];
|
||||
}
|
||||
var obj = {
|
||||
'url': this.getAttributeNS(node, 'http://www.w3.org/1999/xlink',
|
||||
'href')
|
||||
};
|
||||
this.readChildNodes(node, obj);
|
||||
http['post'].push(obj);
|
||||
},
|
||||
'Parameter': function(node, operation) {
|
||||
if (!operation['parameters']) {
|
||||
operation['parameters'] = {};
|
||||
}
|
||||
var name = node.getAttribute('name');
|
||||
operation['parameters'][name] = {};
|
||||
this.readChildNodes(node, operation['parameters'][name]);
|
||||
},
|
||||
'Constraint': function(node, obj) {
|
||||
if (!obj['constraints']) {
|
||||
obj['constraints'] = {};
|
||||
}
|
||||
var name = node.getAttribute('name');
|
||||
obj['constraints'][name] = {};
|
||||
this.readChildNodes(node, obj['constraints'][name]);
|
||||
},
|
||||
'Value': function(node, allowedValues) {
|
||||
allowedValues[this.getChildValue(node)] = true;
|
||||
},
|
||||
'OutputFormat': function(node, obj) {
|
||||
obj['formats'].push({'value': this.getChildValue(node)});
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'WGS84BoundingBox': function(node, obj) {
|
||||
var boundingBox = {};
|
||||
boundingBox['crs'] = node.getAttribute('crs');
|
||||
if (obj['BoundingBox']) {
|
||||
obj['BoundingBox'].push(boundingBox);
|
||||
} else {
|
||||
obj['projection'] = boundingBox['crs'];
|
||||
boundingBox = obj;
|
||||
}
|
||||
this.readChildNodes(node, boundingBox);
|
||||
},
|
||||
'BoundingBox': function(node, obj) {
|
||||
// FIXME: We consider that BoundingBox is the same as WGS84BoundingBox
|
||||
// LowerCorner = "min_x min_y"
|
||||
// UpperCorner = "max_x max_y"
|
||||
// It should normally depend on the projection
|
||||
var readers = this.readers[node.namespaceURI];
|
||||
readers['WGS84BoundingBox'].apply(this, [node, obj]);
|
||||
},
|
||||
'LowerCorner': function(node, obj) {
|
||||
var str = this.getChildValue(node).replace(
|
||||
this.regExes.trimSpace, '');
|
||||
str = str.replace(this.regExes.trimComma, ',');
|
||||
var pointList = str.split(this.regExes.splitSpace);
|
||||
obj['left'] = pointList[0];
|
||||
obj['bottom'] = pointList[1];
|
||||
},
|
||||
'UpperCorner': function(node, obj) {
|
||||
var str = this.getChildValue(node).replace(
|
||||
this.regExes.trimSpace, '');
|
||||
str = str.replace(this.regExes.trimComma, ',');
|
||||
var pointList = str.split(this.regExes.splitSpace);
|
||||
obj['right'] = pointList[0];
|
||||
obj['top'] = pointList[1];
|
||||
obj['bounds'] = [
|
||||
parseFloat(obj['left']), parseFloat(obj['right']),
|
||||
parseFloat(obj['bottom']), parseFloat(obj['top'])
|
||||
];
|
||||
delete obj['left'];
|
||||
delete obj['bottom'];
|
||||
delete obj['right'];
|
||||
delete obj['top'];
|
||||
},
|
||||
'Language': function(node, obj) {
|
||||
obj['language'] = this.getChildValue(node);
|
||||
}
|
||||
}
|
||||
};
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.OWSCommon_v1, ol.parser.XML);
|
||||
@@ -1,45 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.OWSCommon_v1_1_0');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.parser.ogc.OWSCommon_v1');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.ogc.OWSCommon_v1}
|
||||
*/
|
||||
ol.parser.ogc.OWSCommon_v1_1_0 = function() {
|
||||
goog.base(this);
|
||||
this.readers['http://www.opengis.net/ows/1.1'] =
|
||||
this.readers['http://www.opengis.net/ows'];
|
||||
goog.object.extend(this.readers['http://www.opengis.net/ows/1.1'], {
|
||||
'AllowedValues': function(node, parameter) {
|
||||
parameter['allowedValues'] = {};
|
||||
this.readChildNodes(node, parameter['allowedValues']);
|
||||
},
|
||||
'AnyValue': function(node, parameter) {
|
||||
parameter['anyValue'] = true;
|
||||
},
|
||||
'DataType': function(node, parameter) {
|
||||
parameter['dataType'] = this.getChildValue(node);
|
||||
},
|
||||
'Range': function(node, allowedValues) {
|
||||
allowedValues['range'] = {};
|
||||
this.readChildNodes(node, allowedValues['range']);
|
||||
},
|
||||
'MinimumValue': function(node, range) {
|
||||
range['minValue'] = this.getChildValue(node);
|
||||
},
|
||||
'MaximumValue': function(node, range) {
|
||||
range['maxValue'] = this.getChildValue(node);
|
||||
},
|
||||
'Identifier': function(node, obj) {
|
||||
obj['identifier'] = this.getChildValue(node);
|
||||
},
|
||||
'SupportedCRS': function(node, obj) {
|
||||
obj['supportedCRS'] = this.getChildValue(node);
|
||||
}
|
||||
});
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.OWSCommon_v1_1_0,
|
||||
ol.parser.ogc.OWSCommon_v1);
|
||||
@@ -1,121 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.Versioned');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.parser.ogc.ExceptionReport');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object=} opt_options Options which will be set on this object.
|
||||
*/
|
||||
ol.parser.ogc.Versioned = function(opt_options) {
|
||||
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||
this.options = options;
|
||||
this.defaultVersion = options.defaultVersion || null;
|
||||
this.version = options.version;
|
||||
this.profile = options.profile;
|
||||
if (goog.isDef(options.allowFallback)) {
|
||||
this.allowFallback = options.allowFallback;
|
||||
} else {
|
||||
this.allowFallback = false;
|
||||
}
|
||||
if (goog.isDef(options.stringifyOutput)) {
|
||||
this.stringifyOutput = options.stringifyOutput;
|
||||
} else {
|
||||
this.stringifyOutput = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} root root element.
|
||||
* @param {Object=} opt_options optional configuration object.
|
||||
* @return {string} the version to use.
|
||||
*/
|
||||
ol.parser.ogc.Versioned.prototype.getVersion = function(root, opt_options) {
|
||||
var version;
|
||||
// read
|
||||
if (root) {
|
||||
version = this.version;
|
||||
if (!version) {
|
||||
version = root.getAttribute('version');
|
||||
if (!version) {
|
||||
version = this.defaultVersion;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// write
|
||||
version = (opt_options && opt_options.version) ||
|
||||
this.version || this.defaultVersion;
|
||||
}
|
||||
return version;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} version the version to use.
|
||||
* @return {Object} the parser to use.
|
||||
*/
|
||||
ol.parser.ogc.Versioned.prototype.getParser = function(version) {
|
||||
version = version || this.defaultVersion;
|
||||
var profile = this.profile ? '_' + this.profile : '';
|
||||
if (!this.parser || this.parser.VERSION != version) {
|
||||
var format = this.parsers['v' + version.replace(/\./g, '_') + profile];
|
||||
if (!format) {
|
||||
if (profile !== '' && this.allowFallback) {
|
||||
// fallback to the non-profiled version of the parser
|
||||
profile = '';
|
||||
format = this.parsers['v' + version.replace(/\./g, '_') + profile];
|
||||
}
|
||||
if (!format) {
|
||||
throw 'Can\'t find a parser for version ' +
|
||||
version + profile;
|
||||
}
|
||||
}
|
||||
this.parser = new format(this.options);
|
||||
}
|
||||
return this.parser;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Write a document.
|
||||
*
|
||||
* @param {Object} obj An object representing the document.
|
||||
* @param {Object=} opt_options Optional configuration object.
|
||||
* @return {Element|string} the XML created.
|
||||
*/
|
||||
ol.parser.ogc.Versioned.prototype.write = function(obj, opt_options) {
|
||||
var version = this.getVersion(null, opt_options);
|
||||
this.parser = this.getParser(version);
|
||||
var root = this.parser.write(obj, opt_options);
|
||||
if (this.stringifyOutput === false) {
|
||||
return root;
|
||||
} else {
|
||||
return goog.dom.xml.serialize(root);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|Document} data Data to read.
|
||||
* @param {Object=} opt_options Options for the reader.
|
||||
* @return {Object} An object representing the document.
|
||||
*/
|
||||
ol.parser.ogc.Versioned.prototype.read = function(data, opt_options) {
|
||||
if (goog.isString(data)) {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
var root = data.documentElement;
|
||||
var version = this.getVersion(root);
|
||||
this.parser = this.getParser(version);
|
||||
var obj = this.parser.read(data, opt_options);
|
||||
var errorProperty = this.parser.errorProperty || null;
|
||||
if (errorProperty !== null && obj[errorProperty] === undefined) {
|
||||
// an error must have happened, so parse it and report back
|
||||
var format = new ol.parser.ogc.ExceptionReport();
|
||||
obj.error = format.read(data);
|
||||
}
|
||||
obj.version = version;
|
||||
return obj;
|
||||
};
|
||||
@@ -1,2 +0,0 @@
|
||||
@exportSymbol ol.parser.ogc.WMSCapabilities
|
||||
@exportProperty ol.parser.ogc.WMSCapabilities.prototype.read
|
||||
@@ -1,69 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.WMSCapabilities');
|
||||
goog.require('ol.parser.ogc.Versioned');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities_v1_0_0');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities_v1_1_0');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities_v1_1_1');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities_v1_1_1_WMSC');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities_v1_3_0');
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable WMS Capabilities version 1.0.0.
|
||||
*/
|
||||
ol.ENABLE_WMSCAPS_1_0_0 = false;
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable WMS Capabilities version 1.1.0.
|
||||
*/
|
||||
ol.ENABLE_WMSCAPS_1_1_0 = true;
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable WMS Capabilities version 1.1.1.
|
||||
*/
|
||||
ol.ENABLE_WMSCAPS_1_1_1 = true;
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable WMS Capabilities version 1.3.0.
|
||||
*/
|
||||
ol.ENABLE_WMSCAPS_1_3_0 = true;
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable WMS Capabilities version 1.1.1.
|
||||
* WMSC profile.
|
||||
*/
|
||||
ol.ENABLE_WMSCAPS_1_1_1_WMSC = true;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object=} opt_options Options which will be set on this object.
|
||||
* @extends {ol.parser.ogc.Versioned}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.ogc.WMSCapabilities = function(opt_options) {
|
||||
opt_options = opt_options || {};
|
||||
opt_options['defaultVersion'] = '1.1.1';
|
||||
this.parsers = {};
|
||||
if (ol.ENABLE_WMSCAPS_1_0_0) {
|
||||
this.parsers['v1_0_0'] = ol.parser.ogc.WMSCapabilities_v1_0_0;
|
||||
}
|
||||
if (ol.ENABLE_WMSCAPS_1_1_0) {
|
||||
this.parsers['v1_1_0'] = ol.parser.ogc.WMSCapabilities_v1_1_0;
|
||||
}
|
||||
if (ol.ENABLE_WMSCAPS_1_1_1) {
|
||||
this.parsers['v1_1_1'] = ol.parser.ogc.WMSCapabilities_v1_1_1;
|
||||
}
|
||||
if (ol.ENABLE_WMSCAPS_1_1_1_WMSC) {
|
||||
this.parsers['v1_1_1_WMSC'] = ol.parser.ogc.WMSCapabilities_v1_1_1_WMSC;
|
||||
}
|
||||
if (ol.ENABLE_WMSCAPS_1_3_0) {
|
||||
this.parsers['v1_3_0'] = ol.parser.ogc.WMSCapabilities_v1_3_0;
|
||||
}
|
||||
goog.base(this, opt_options);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.WMSCapabilities, ol.parser.ogc.Versioned);
|
||||
@@ -1,317 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.WMSCapabilities_v1');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.parser.XML');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read [WMS](http://www.opengeospatial.org/standards/wms) capabilities
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.parser.XML}
|
||||
*/
|
||||
ol.parser.ogc.WMSCapabilities_v1 = function() {
|
||||
this.defaultNamespaceURI = 'http://www.opengis.net/wms';
|
||||
this.errorProperty = 'service';
|
||||
this.readers = {
|
||||
'http://www.opengis.net/wms': {
|
||||
'Service': function(node, obj) {
|
||||
obj['service'] = {};
|
||||
this.readChildNodes(node, obj['service']);
|
||||
},
|
||||
'Name': function(node, obj) {
|
||||
obj['name'] = this.getChildValue(node);
|
||||
},
|
||||
'Title': function(node, obj) {
|
||||
obj['title'] = this.getChildValue(node);
|
||||
},
|
||||
'Abstract': function(node, obj) {
|
||||
obj['abstract'] = this.getChildValue(node);
|
||||
},
|
||||
'BoundingBox': function(node, obj) {
|
||||
var bbox = {};
|
||||
bbox['bbox'] = [
|
||||
parseFloat(node.getAttribute('minx')),
|
||||
parseFloat(node.getAttribute('miny')),
|
||||
parseFloat(node.getAttribute('maxx')),
|
||||
parseFloat(node.getAttribute('maxy'))
|
||||
];
|
||||
var res = {
|
||||
x: parseFloat(node.getAttribute('resx')),
|
||||
y: parseFloat(node.getAttribute('resy'))
|
||||
};
|
||||
if (! (isNaN(res.x) && isNaN(res.y))) {
|
||||
bbox['res'] = res;
|
||||
}
|
||||
// return the bbox so that descendant classes can set the
|
||||
// CRS and SRS and add it to the obj
|
||||
return bbox;
|
||||
},
|
||||
'OnlineResource': function(node, obj) {
|
||||
obj['href'] = this.getAttributeNS(node, 'http://www.w3.org/1999/xlink',
|
||||
'href');
|
||||
},
|
||||
'ContactInformation': function(node, obj) {
|
||||
obj['contactInformation'] = {};
|
||||
this.readChildNodes(node, obj['contactInformation']);
|
||||
},
|
||||
'ContactPersonPrimary': function(node, obj) {
|
||||
obj['personPrimary'] = {};
|
||||
this.readChildNodes(node, obj['personPrimary']);
|
||||
},
|
||||
'ContactPerson': function(node, obj) {
|
||||
obj['person'] = this.getChildValue(node);
|
||||
},
|
||||
'ContactOrganization': function(node, obj) {
|
||||
obj['organization'] = this.getChildValue(node);
|
||||
},
|
||||
'ContactPosition': function(node, obj) {
|
||||
obj['position'] = this.getChildValue(node);
|
||||
},
|
||||
'ContactAddress': function(node, obj) {
|
||||
obj['contactAddress'] = {};
|
||||
this.readChildNodes(node, obj['contactAddress']);
|
||||
},
|
||||
'AddressType': function(node, obj) {
|
||||
obj['type'] = this.getChildValue(node);
|
||||
},
|
||||
'Address': function(node, obj) {
|
||||
obj['address'] = this.getChildValue(node);
|
||||
},
|
||||
'City': function(node, obj) {
|
||||
obj['city'] = this.getChildValue(node);
|
||||
},
|
||||
'StateOrProvince': function(node, obj) {
|
||||
obj['stateOrProvince'] = this.getChildValue(node);
|
||||
},
|
||||
'PostCode': function(node, obj) {
|
||||
obj['postcode'] = this.getChildValue(node);
|
||||
},
|
||||
'Country': function(node, obj) {
|
||||
obj['country'] = this.getChildValue(node);
|
||||
},
|
||||
'ContactVoiceTelephone': function(node, obj) {
|
||||
obj['phone'] = this.getChildValue(node);
|
||||
},
|
||||
'ContactFacsimileTelephone': function(node, obj) {
|
||||
obj['fax'] = this.getChildValue(node);
|
||||
},
|
||||
'ContactElectronicMailAddress': function(node, obj) {
|
||||
obj['email'] = this.getChildValue(node);
|
||||
},
|
||||
'Fees': function(node, obj) {
|
||||
var fees = this.getChildValue(node);
|
||||
if (fees && fees.toLowerCase() != 'none') {
|
||||
obj['fees'] = fees;
|
||||
}
|
||||
},
|
||||
'AccessConstraints': function(node, obj) {
|
||||
var constraints = this.getChildValue(node);
|
||||
if (constraints && constraints.toLowerCase() != 'none') {
|
||||
obj['accessConstraints'] = constraints;
|
||||
}
|
||||
},
|
||||
'Capability': function(node, obj) {
|
||||
obj['capability'] = {};
|
||||
obj['capability']['nestedLayers'] = [];
|
||||
obj['capability']['layers'] = [];
|
||||
this.readChildNodes(node, obj['capability']);
|
||||
},
|
||||
'Request': function(node, obj) {
|
||||
obj['request'] = {};
|
||||
this.readChildNodes(node, obj['request']);
|
||||
},
|
||||
'GetCapabilities': function(node, obj) {
|
||||
obj['getcapabilities'] = {};
|
||||
obj['getcapabilities']['formats'] = [];
|
||||
this.readChildNodes(node, obj['getcapabilities']);
|
||||
},
|
||||
'Format': function(node, obj) {
|
||||
if (goog.isArray(obj['formats'])) {
|
||||
obj['formats'].push(this.getChildValue(node));
|
||||
} else {
|
||||
obj['format'] = this.getChildValue(node);
|
||||
}
|
||||
},
|
||||
'DCPType': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'HTTP': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'Get': function(node, obj) {
|
||||
obj['get'] = {};
|
||||
this.readChildNodes(node, obj['get']);
|
||||
},
|
||||
'Post': function(node, obj) {
|
||||
obj['post'] = {};
|
||||
this.readChildNodes(node, obj['post']);
|
||||
},
|
||||
'GetMap': function(node, obj) {
|
||||
obj['getmap'] = {};
|
||||
obj['getmap']['formats'] = [];
|
||||
this.readChildNodes(node, obj['getmap']);
|
||||
},
|
||||
'GetFeatureInfo': function(node, obj) {
|
||||
obj['getfeatureinfo'] = {};
|
||||
obj['getfeatureinfo']['formats'] = [];
|
||||
this.readChildNodes(node, obj['getfeatureinfo']);
|
||||
},
|
||||
'Exception': function(node, obj) {
|
||||
obj['exception'] = {};
|
||||
obj['exception']['formats'] = [];
|
||||
this.readChildNodes(node, obj['exception']);
|
||||
},
|
||||
'Layer': function(node, obj) {
|
||||
var parentLayer, capability;
|
||||
if (obj['capability']) {
|
||||
capability = obj['capability'];
|
||||
parentLayer = obj;
|
||||
} else {
|
||||
capability = obj;
|
||||
}
|
||||
var attrNode = node.getAttributeNode('queryable');
|
||||
var queryable = (attrNode && attrNode.specified) ?
|
||||
node.getAttribute('queryable') : null;
|
||||
attrNode = node.getAttributeNode('cascaded');
|
||||
var cascaded = (attrNode && attrNode.specified) ?
|
||||
node.getAttribute('cascaded') : null;
|
||||
attrNode = node.getAttributeNode('opaque');
|
||||
var opaque = (attrNode && attrNode.specified) ?
|
||||
node.getAttribute('opaque') : null;
|
||||
var noSubsets = node.getAttribute('noSubsets');
|
||||
var fixedWidth = node.getAttribute('fixedWidth');
|
||||
var fixedHeight = node.getAttribute('fixedHeight');
|
||||
var parent = parentLayer || {};
|
||||
var layer = {
|
||||
'nestedLayers': [],
|
||||
'styles': parentLayer ? [].concat(parentLayer['styles']) : [],
|
||||
'srs': {},
|
||||
'metadataURLs': [],
|
||||
'bbox': {},
|
||||
'llbbox': parent['llbbox'],
|
||||
'dimensions': {},
|
||||
'authorityURLs': {},
|
||||
'identifiers': {},
|
||||
'keywords': [],
|
||||
'queryable': (queryable && queryable !== '') ?
|
||||
(queryable === '1' || queryable === 'true') :
|
||||
(parent['queryable'] || false),
|
||||
'cascaded': (cascaded !== null) ? parseInt(cascaded, 10) :
|
||||
(parent['cascaded'] || 0),
|
||||
'opaque': opaque ?
|
||||
(opaque === '1' || opaque === 'true') :
|
||||
(parent['opaque'] || false),
|
||||
'noSubsets': (noSubsets !== null) ?
|
||||
(noSubsets === '1' || noSubsets === 'true') :
|
||||
(parent['noSubsets'] || false),
|
||||
'fixedWidth': (fixedWidth !== null) ?
|
||||
parseInt(fixedWidth, 10) : (parent['fixedWidth'] || 0),
|
||||
'fixedHeight': (fixedHeight !== null) ?
|
||||
parseInt(fixedHeight, 10) : (parent['fixedHeight'] || 0),
|
||||
'minScale': parent['minScale'],
|
||||
'maxScale': parent['maxScale'],
|
||||
'attribution': parent['attribution']
|
||||
};
|
||||
if (parentLayer) {
|
||||
goog.object.extend(layer['srs'], parent['srs']);
|
||||
goog.object.extend(layer['bbox'], parent['bbox']);
|
||||
goog.object.extend(layer['dimensions'], parent['dimensions']);
|
||||
goog.object.extend(layer['authorityURLs'], parent['authorityURLs']);
|
||||
}
|
||||
obj['nestedLayers'].push(layer);
|
||||
layer['capability'] = capability;
|
||||
this.readChildNodes(node, layer);
|
||||
delete layer['capability'];
|
||||
if (layer['name']) {
|
||||
var parts = layer['name'].split(':'),
|
||||
request = capability['request'],
|
||||
gfi = request['getfeatureinfo'];
|
||||
if (parts.length > 0) {
|
||||
layer['prefix'] = parts[0];
|
||||
}
|
||||
capability['layers'].push(layer);
|
||||
if (!goog.isDef(layer['formats'])) {
|
||||
layer['formats'] = request['getmap']['formats'];
|
||||
}
|
||||
if (!goog.isDef(layer['infoFormats']) && gfi) {
|
||||
layer['infoFormats'] = gfi['formats'];
|
||||
}
|
||||
}
|
||||
},
|
||||
'Attribution': function(node, obj) {
|
||||
obj['attribution'] = {};
|
||||
this.readChildNodes(node, obj['attribution']);
|
||||
},
|
||||
'LogoURL': function(node, obj) {
|
||||
obj['logo'] = {
|
||||
'width': node.getAttribute('width'),
|
||||
'height': node.getAttribute('height')
|
||||
};
|
||||
this.readChildNodes(node, obj['logo']);
|
||||
},
|
||||
'Style': function(node, obj) {
|
||||
var style = {};
|
||||
obj['styles'].push(style);
|
||||
this.readChildNodes(node, style);
|
||||
},
|
||||
'LegendURL': function(node, obj) {
|
||||
var legend = {
|
||||
'width': node.getAttribute('width'),
|
||||
'height': node.getAttribute('height')
|
||||
};
|
||||
obj['legend'] = legend;
|
||||
this.readChildNodes(node, legend);
|
||||
},
|
||||
'MetadataURL': function(node, obj) {
|
||||
var metadataURL = {'type': node.getAttribute('type')};
|
||||
obj['metadataURLs'].push(metadataURL);
|
||||
this.readChildNodes(node, metadataURL);
|
||||
},
|
||||
'DataURL': function(node, obj) {
|
||||
obj['dataURL'] = {};
|
||||
this.readChildNodes(node, obj['dataURL']);
|
||||
},
|
||||
'FeatureListURL': function(node, obj) {
|
||||
obj['featureListURL'] = {};
|
||||
this.readChildNodes(node, obj['featureListURL']);
|
||||
},
|
||||
'AuthorityURL': function(node, obj) {
|
||||
var name = node.getAttribute('name');
|
||||
var authority = {};
|
||||
this.readChildNodes(node, authority);
|
||||
obj['authorityURLs'][name] = authority['href'];
|
||||
},
|
||||
'Identifier': function(node, obj) {
|
||||
var authority = node.getAttribute('authority');
|
||||
obj['identifiers'][authority] = this.getChildValue(node);
|
||||
},
|
||||
'KeywordList': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'SRS': function(node, obj) {
|
||||
obj['srs'][this.getChildValue(node)] = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.WMSCapabilities_v1, ol.parser.XML);
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|Document|Element} data Data to read.
|
||||
* @return {Object} An object representing the document.
|
||||
*/
|
||||
ol.parser.ogc.WMSCapabilities_v1.prototype.read = function(data) {
|
||||
if (goog.isString(data)) {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
if (data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var obj = {};
|
||||
this.readNode(data, obj);
|
||||
return obj;
|
||||
};
|
||||
@@ -1,66 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.WMSCapabilities_v1_0_0');
|
||||
|
||||
goog.require('goog.object');
|
||||
goog.require('goog.string');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities_v1_1_0');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read [WMS](http://www.opengeospatial.org/standards/wms) capabilities
|
||||
* version 1.0.0
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.parser.ogc.WMSCapabilities_v1_1_0}
|
||||
*/
|
||||
ol.parser.ogc.WMSCapabilities_v1_0_0 = function() {
|
||||
goog.base(this);
|
||||
this.version = '1.0.0';
|
||||
goog.object.extend(this.readers['http://www.opengis.net/wms'], {
|
||||
'Format': function(node, obj) {
|
||||
for (var i = 0, ii = node.childNodes.length; i < ii; i++) {
|
||||
var child = node.childNodes[i];
|
||||
var local = child.localName || child.nodeName.split(':').pop();
|
||||
if (goog.isArray(obj['formats'])) {
|
||||
obj['formats'].push(local);
|
||||
} else {
|
||||
obj['format'] = local;
|
||||
}
|
||||
}
|
||||
},
|
||||
'Keywords': function(node, obj) {
|
||||
if (!goog.isDef(obj['keywords'])) {
|
||||
obj['keywords'] = [];
|
||||
}
|
||||
var keywords = this.getChildValue(node).split(/ +/);
|
||||
for (var i = 0, ii = keywords.length; i < ii; ++i) {
|
||||
if (!goog.string.isEmpty(keywords[i])) {
|
||||
obj['keywords'].push({'value': keywords[i]});
|
||||
}
|
||||
}
|
||||
},
|
||||
'OnlineResource': function(node, obj) {
|
||||
obj['href'] = this.getChildValue(node);
|
||||
},
|
||||
'Get': function(node, obj) {
|
||||
obj['get'] = {'href': node.getAttribute('onlineResource')};
|
||||
},
|
||||
'Post': function(node, obj) {
|
||||
obj['post'] = {'href': node.getAttribute('onlineResource')};
|
||||
},
|
||||
'Map': function(node, obj) {
|
||||
var reader = this.readers[this.defaultNamespaceURI]['GetMap'];
|
||||
reader.apply(this, arguments);
|
||||
},
|
||||
'Capabilities': function(node, obj) {
|
||||
var reader = this.readers[this.defaultNamespaceURI]['GetCapabilities'];
|
||||
reader.apply(this, arguments);
|
||||
},
|
||||
'FeatureInfo': function(node, obj) {
|
||||
var reader = this.readers[this.defaultNamespaceURI]['GetFeatureInfo'];
|
||||
reader.apply(this, arguments);
|
||||
}
|
||||
});
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.WMSCapabilities_v1_0_0,
|
||||
ol.parser.ogc.WMSCapabilities_v1_1_0);
|
||||
@@ -1,101 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.WMSCapabilities_v1_1');
|
||||
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities_v1');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.ogc.WMSCapabilities_v1}
|
||||
*/
|
||||
ol.parser.ogc.WMSCapabilities_v1_1 = function() {
|
||||
goog.base(this);
|
||||
var bboxreader = this.readers['http://www.opengis.net/wms']['BoundingBox'];
|
||||
goog.object.extend(this.readers['http://www.opengis.net/wms'], {
|
||||
'WMT_MS_Capabilities': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'Keyword': function(node, obj) {
|
||||
if (obj['keywords']) {
|
||||
obj['keywords'].push({'value': this.getChildValue(node)});
|
||||
}
|
||||
},
|
||||
'DescribeLayer': function(node, obj) {
|
||||
obj['describelayer'] = {'formats': []};
|
||||
this.readChildNodes(node, obj['describelayer']);
|
||||
},
|
||||
'GetLegendGraphic': function(node, obj) {
|
||||
obj['getlegendgraphic'] = {'formats': []};
|
||||
this.readChildNodes(node, obj['getlegendgraphic']);
|
||||
},
|
||||
'GetStyles': function(node, obj) {
|
||||
obj['getstyles'] = {'formats': []};
|
||||
this.readChildNodes(node, obj['getstyles']);
|
||||
},
|
||||
'PutStyles': function(node, obj) {
|
||||
obj['putstyles'] = {'formats': []};
|
||||
this.readChildNodes(node, obj['putstyles']);
|
||||
},
|
||||
'UserDefinedSymbolization': function(node, obj) {
|
||||
var userSymbols = {
|
||||
'supportSLD': parseInt(node.getAttribute('SupportSLD'), 10) == 1,
|
||||
'userLayer': parseInt(node.getAttribute('UserLayer'), 10) == 1,
|
||||
'userStyle': parseInt(node.getAttribute('UserStyle'), 10) == 1,
|
||||
'remoteWFS': parseInt(node.getAttribute('RemoteWFS'), 10) == 1
|
||||
};
|
||||
obj['userSymbols'] = userSymbols;
|
||||
},
|
||||
'LatLonBoundingBox': function(node, obj) {
|
||||
obj['llbbox'] = [
|
||||
parseFloat(node.getAttribute('minx')),
|
||||
parseFloat(node.getAttribute('miny')),
|
||||
parseFloat(node.getAttribute('maxx')),
|
||||
parseFloat(node.getAttribute('maxy'))
|
||||
];
|
||||
},
|
||||
'BoundingBox': function(node, obj) {
|
||||
var bbox = bboxreader.apply(this, arguments);
|
||||
bbox['srs'] = node.getAttribute('SRS');
|
||||
obj['bbox'][bbox['srs']] = bbox;
|
||||
},
|
||||
'ScaleHint': function(node, obj) {
|
||||
var min = parseFloat(node.getAttribute('min'));
|
||||
var max = parseFloat(node.getAttribute('max'));
|
||||
var rad2 = Math.pow(2, 0.5);
|
||||
var dpi = (25.4 / 0.28);
|
||||
var ipm = 39.37;
|
||||
if (min !== 0) {
|
||||
obj['maxScale'] = parseFloat((min / rad2) * ipm * dpi);
|
||||
}
|
||||
if (max != Infinity) {
|
||||
obj['minScale'] = parseFloat((max / rad2) * ipm * dpi);
|
||||
}
|
||||
},
|
||||
'Dimension': function(node, obj) {
|
||||
var name = node.getAttribute('name').toLowerCase();
|
||||
var dim = {
|
||||
'name': name,
|
||||
'units': node.getAttribute('units'),
|
||||
'unitsymbol': node.getAttribute('unitSymbol')
|
||||
};
|
||||
obj['dimensions'][dim.name] = dim;
|
||||
},
|
||||
'Extent': function(node, obj) {
|
||||
var name = node.getAttribute('name').toLowerCase();
|
||||
if (name in obj['dimensions']) {
|
||||
var extent = obj['dimensions'][name];
|
||||
extent['nearestVal'] =
|
||||
node.getAttribute('nearestValue') === '1';
|
||||
extent['multipleVal'] =
|
||||
node.getAttribute('multipleValues') === '1';
|
||||
extent['current'] = node.getAttribute('current') === '1';
|
||||
extent['default'] = node.getAttribute('default') || '';
|
||||
var values = this.getChildValue(node);
|
||||
extent['values'] = values.split(',');
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.WMSCapabilities_v1_1,
|
||||
ol.parser.ogc.WMSCapabilities_v1);
|
||||
@@ -1,29 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.WMSCapabilities_v1_1_0');
|
||||
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities_v1_1');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read [WMS](http://www.opengeospatial.org/standards/wms) capabilities
|
||||
* version 1.1.0
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.parser.ogc.WMSCapabilities_v1_1}
|
||||
*/
|
||||
ol.parser.ogc.WMSCapabilities_v1_1_0 = function() {
|
||||
goog.base(this);
|
||||
this.version = '1.1.0';
|
||||
goog.object.extend(this.readers['http://www.opengis.net/wms'], {
|
||||
'SRS': function(node, obj) {
|
||||
var srs = this.getChildValue(node);
|
||||
var values = srs.split(/ +/);
|
||||
for (var i = 0, ii = values.length; i < ii; i++) {
|
||||
obj['srs'][values[i]] = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.WMSCapabilities_v1_1_0,
|
||||
ol.parser.ogc.WMSCapabilities_v1_1);
|
||||
@@ -1,25 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.WMSCapabilities_v1_1_1');
|
||||
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities_v1_1');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read [WMS](http://www.opengeospatial.org/standards/wms) capabilities
|
||||
* version 1.1.1
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.parser.ogc.WMSCapabilities_v1_1}
|
||||
*/
|
||||
ol.parser.ogc.WMSCapabilities_v1_1_1 = function() {
|
||||
goog.base(this);
|
||||
this.version = '1.1.1';
|
||||
goog.object.extend(this.readers['http://www.opengis.net/wms'], {
|
||||
'SRS': function(node, obj) {
|
||||
obj['srs'][this.getChildValue(node)] = true;
|
||||
}
|
||||
});
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.WMSCapabilities_v1_1_1,
|
||||
ol.parser.ogc.WMSCapabilities_v1_1);
|
||||
@@ -1,48 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.WMSCapabilities_v1_1_1_WMSC');
|
||||
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities_v1_1_1');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.ogc.WMSCapabilities_v1_1_1}
|
||||
*/
|
||||
ol.parser.ogc.WMSCapabilities_v1_1_1_WMSC = function() {
|
||||
goog.base(this);
|
||||
this.profile = 'WMSC';
|
||||
goog.object.extend(this.readers['http://www.opengis.net/wms'], {
|
||||
'VendorSpecificCapabilities': function(node, obj) {
|
||||
obj['vendorSpecific'] = {'tileSets': []};
|
||||
this.readChildNodes(node, obj['vendorSpecific']);
|
||||
},
|
||||
'TileSet': function(node, vendorSpecific) {
|
||||
var tileset = {'srs': {}, 'bbox': {}, 'resolutions': []};
|
||||
this.readChildNodes(node, tileset);
|
||||
vendorSpecific.tileSets.push(tileset);
|
||||
},
|
||||
'Resolutions': function(node, tileset) {
|
||||
var res = this.getChildValue(node).split(' ');
|
||||
for (var i = 0, ii = res.length; i < ii; i++) {
|
||||
if (res[i] !== '') {
|
||||
tileset['resolutions'].push(parseFloat(res[i]));
|
||||
}
|
||||
}
|
||||
},
|
||||
'Width': function(node, tileset) {
|
||||
tileset['width'] = parseInt(this.getChildValue(node), 10);
|
||||
},
|
||||
'Height': function(node, tileset) {
|
||||
tileset['height'] = parseInt(this.getChildValue(node), 10);
|
||||
},
|
||||
'Layers': function(node, tileset) {
|
||||
tileset['layers'] = this.getChildValue(node);
|
||||
},
|
||||
'Styles': function(node, tileset) {
|
||||
tileset['styles'] = this.getChildValue(node);
|
||||
}
|
||||
});
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.WMSCapabilities_v1_1_1_WMSC,
|
||||
ol.parser.ogc.WMSCapabilities_v1_1_1);
|
||||
@@ -1,114 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.WMSCapabilities_v1_3_0');
|
||||
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.parser.ogc.WMSCapabilities_v1');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read [WMS](http://www.opengeospatial.org/standards/wms) capabilities
|
||||
* version 1.3.0
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.parser.ogc.WMSCapabilities_v1}
|
||||
*/
|
||||
ol.parser.ogc.WMSCapabilities_v1_3_0 = function() {
|
||||
goog.base(this);
|
||||
var bboxreader = this.readers['http://www.opengis.net/wms']['BoundingBox'];
|
||||
goog.object.extend(this.readers['http://www.opengis.net/wms'], {
|
||||
'WMS_Capabilities': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'LayerLimit': function(node, obj) {
|
||||
obj['layerLimit'] = parseInt(this.getChildValue(node), 10);
|
||||
},
|
||||
'MaxWidth': function(node, obj) {
|
||||
obj['maxWidth'] = parseInt(this.getChildValue(node), 10);
|
||||
},
|
||||
'MaxHeight': function(node, obj) {
|
||||
obj['maxHeight'] = parseInt(this.getChildValue(node), 10);
|
||||
},
|
||||
'BoundingBox': function(node, obj) {
|
||||
var bbox = bboxreader.apply(this, arguments);
|
||||
bbox['srs'] = node.getAttribute('CRS');
|
||||
obj['bbox'][bbox['srs']] = bbox;
|
||||
},
|
||||
'CRS': function(node, obj) {
|
||||
// CRS is the synonym of SRS
|
||||
this.readers['http://www.opengis.net/wms']['SRS'].apply(this, arguments);
|
||||
},
|
||||
'EX_GeographicBoundingBox': function(node, obj) {
|
||||
// replacement of LatLonBoundingBox
|
||||
obj['llbbox'] = [];
|
||||
this.readChildNodes(node, obj['llbbox']);
|
||||
},
|
||||
'westBoundLongitude': function(node, obj) {
|
||||
obj[0] = this.getChildValue(node);
|
||||
},
|
||||
'eastBoundLongitude': function(node, obj) {
|
||||
obj[2] = this.getChildValue(node);
|
||||
},
|
||||
'southBoundLatitude': function(node, obj) {
|
||||
obj[1] = this.getChildValue(node);
|
||||
},
|
||||
'northBoundLatitude': function(node, obj) {
|
||||
obj[3] = this.getChildValue(node);
|
||||
},
|
||||
'MinScaleDenominator': function(node, obj) {
|
||||
obj['maxScale'] = parseFloat(this.getChildValue(node)).toPrecision(16);
|
||||
},
|
||||
'MaxScaleDenominator': function(node, obj) {
|
||||
obj['minScale'] = parseFloat(this.getChildValue(node)).toPrecision(16);
|
||||
},
|
||||
'Dimension': function(node, obj) {
|
||||
// dimension has extra attributes: default, multipleValues,
|
||||
// nearestValue, current which used to be part of Extent. It now
|
||||
// also contains the values.
|
||||
var name = node.getAttribute('name').toLowerCase();
|
||||
var dim = {
|
||||
'name': name,
|
||||
'units': node.getAttribute('units'),
|
||||
'unitsymbol': node.getAttribute('unitSymbol'),
|
||||
'nearestVal': node.getAttribute('nearestValue') === '1',
|
||||
'multipleVal': node.getAttribute('multipleValues') === '1',
|
||||
'default': node.getAttribute('default') || '',
|
||||
'current': node.getAttribute('current') === '1',
|
||||
'values': this.getChildValue(node).split(',')
|
||||
};
|
||||
// Theoretically there can be more dimensions with the same
|
||||
// name, but with a different unit. Until we meet such a case,
|
||||
// let's just keep the same structure as the WMS 1.1
|
||||
// GetCapabilities parser uses. We will store the last
|
||||
// one encountered.
|
||||
obj['dimensions'][dim['name']] = dim;
|
||||
},
|
||||
'Keyword': function(node, obj) {
|
||||
var keyword = {'value': this.getChildValue(node),
|
||||
'vocabulary': node.getAttribute('vocabulary')};
|
||||
if (obj['keywords']) {
|
||||
obj['keywords'].push(keyword);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.readers['sld'] = {
|
||||
'UserDefinedSymbolization': function(node, obj) {
|
||||
var readers = this.readers['http://www.opengis.net/wms'];
|
||||
readers.UserDefinedSymbolization.apply(this, arguments);
|
||||
// add the two extra attributes
|
||||
var value = node.getAttribute('InlineFeature');
|
||||
obj['userSymbols']['inlineFeature'] = parseInt(value, 10) == 1;
|
||||
value = node.getAttribute('RemoteWCS');
|
||||
obj['userSymbols']['remoteWCS'] = parseInt(value, 10) == 1;
|
||||
},
|
||||
'DescribeLayer': function(node, obj) {
|
||||
var readers = this.readers['http://www.opengis.net/wms'];
|
||||
readers.DescribeLayer.apply(this, arguments);
|
||||
},
|
||||
'GetLegendGraphic': function(node, obj) {
|
||||
var readers = this.readers['http://www.opengis.net/wms'];
|
||||
readers.GetLegendGraphic.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.WMSCapabilities_v1_3_0,
|
||||
ol.parser.ogc.WMSCapabilities_v1);
|
||||
@@ -1,2 +0,0 @@
|
||||
@exportSymbol ol.parser.ogc.WMTSCapabilities
|
||||
@exportProperty ol.parser.ogc.WMTSCapabilities.prototype.read
|
||||
@@ -1,22 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.WMTSCapabilities');
|
||||
goog.require('ol.parser.ogc.Versioned');
|
||||
goog.require('ol.parser.ogc.WMTSCapabilities_v1_0_0');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read [WMTS](http://www.opengeospatial.org/standards/wmts) capabilities
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object=} opt_options Options which will be set on this object.
|
||||
* @extends {ol.parser.ogc.Versioned}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.ogc.WMTSCapabilities = function(opt_options) {
|
||||
opt_options = opt_options || {};
|
||||
opt_options['defaultVersion'] = '1.0.0';
|
||||
this.parsers = {};
|
||||
this.parsers['v1_0_0'] = ol.parser.ogc.WMTSCapabilities_v1_0_0;
|
||||
goog.base(this, opt_options);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.WMTSCapabilities, ol.parser.ogc.Versioned);
|
||||
@@ -1,169 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.WMTSCapabilities_v1_0_0');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.coordinate');
|
||||
goog.require('ol.parser.XML');
|
||||
goog.require('ol.parser.ogc.OWSCommon_v1_1_0');
|
||||
goog.require('ol.proj');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read [WMTS](http://www.opengeospatial.org/standards/wmts) capabilities
|
||||
* version 1.0
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.parser.XML}
|
||||
*/
|
||||
ol.parser.ogc.WMTSCapabilities_v1_0_0 = function() {
|
||||
this.defaultNamespaceURI = 'http://www.opengis.net/wmts/1.0';
|
||||
this.errorProperty = 'serviceIdentification';
|
||||
this.readers = {
|
||||
'http://www.opengis.net/wmts/1.0': {
|
||||
'Capabilities': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'Contents': function(node, obj) {
|
||||
obj['contents'] = {};
|
||||
obj['contents']['layers'] = [];
|
||||
obj['contents']['tileMatrixSets'] = {};
|
||||
this.readChildNodes(node, obj['contents']);
|
||||
},
|
||||
'Layer': function(node, obj) {
|
||||
var layer = {
|
||||
'styles': [],
|
||||
'formats': [],
|
||||
'dimensions': [],
|
||||
'tileMatrixSetLinks': []
|
||||
};
|
||||
layer['layers'] = [];
|
||||
this.readChildNodes(node, layer);
|
||||
obj['layers'].push(layer);
|
||||
},
|
||||
'Style': function(node, obj) {
|
||||
var style = {};
|
||||
style['isDefault'] = (node.getAttribute('isDefault') === 'true');
|
||||
this.readChildNodes(node, style);
|
||||
obj['styles'].push(style);
|
||||
},
|
||||
'Format': function(node, obj) {
|
||||
obj['formats'].push(this.getChildValue(node));
|
||||
},
|
||||
'TileMatrixSetLink': function(node, obj) {
|
||||
var tileMatrixSetLink = {};
|
||||
this.readChildNodes(node, tileMatrixSetLink);
|
||||
obj['tileMatrixSetLinks'].push(tileMatrixSetLink);
|
||||
},
|
||||
'TileMatrixSet': function(node, obj) {
|
||||
// node could be child of wmts:Contents or wmts:TileMatrixSetLink
|
||||
// duck type wmts:Contents by looking for layers
|
||||
if (obj['layers']) {
|
||||
// TileMatrixSet as object type in schema
|
||||
var tileMatrixSet = {
|
||||
'matrixIds': []
|
||||
};
|
||||
this.readChildNodes(node, tileMatrixSet);
|
||||
obj['tileMatrixSets'][tileMatrixSet['identifier']] = tileMatrixSet;
|
||||
} else {
|
||||
// TileMatrixSet as string type in schema
|
||||
obj['tileMatrixSet'] = this.getChildValue(node);
|
||||
}
|
||||
},
|
||||
'TileMatrix': function(node, obj) {
|
||||
var tileMatrix = {
|
||||
'supportedCRS': obj['supportedCRS']
|
||||
};
|
||||
this.readChildNodes(node, tileMatrix);
|
||||
obj['matrixIds'].push(tileMatrix);
|
||||
},
|
||||
'ScaleDenominator': function(node, obj) {
|
||||
obj['scaleDenominator'] = parseFloat(this.getChildValue(node));
|
||||
},
|
||||
'TopLeftCorner': function(node, obj) {
|
||||
var topLeftCorner = this.getChildValue(node);
|
||||
var coords = topLeftCorner.split(' ');
|
||||
var axisOrientation =
|
||||
ol.proj.get(obj['supportedCRS']).getAxisOrientation();
|
||||
obj['topLeftCorner'] = ol.coordinate.fromProjectedArray(
|
||||
[parseFloat(coords[0]), parseFloat(coords[1])], axisOrientation);
|
||||
},
|
||||
'TileWidth': function(node, obj) {
|
||||
obj['tileWidth'] = parseInt(this.getChildValue(node), 10);
|
||||
},
|
||||
'TileHeight': function(node, obj) {
|
||||
obj['tileHeight'] = parseInt(this.getChildValue(node), 10);
|
||||
},
|
||||
'MatrixWidth': function(node, obj) {
|
||||
obj['matrixWidth'] = parseInt(this.getChildValue(node), 10);
|
||||
},
|
||||
'MatrixHeight': function(node, obj) {
|
||||
obj['matrixHeight'] = parseInt(this.getChildValue(node), 10);
|
||||
},
|
||||
'ResourceURL': function(node, obj) {
|
||||
var resourceType = node.getAttribute('resourceType');
|
||||
var format = node.getAttribute('format');
|
||||
var template = node.getAttribute('template');
|
||||
if (!obj['resourceUrls']) {
|
||||
obj['resourceUrls'] = {};
|
||||
}
|
||||
if (!obj['resourceUrls'][resourceType]) {
|
||||
obj['resourceUrls'][resourceType] = {};
|
||||
}
|
||||
if (!obj['resourceUrls'][resourceType][format]) {
|
||||
obj['resourceUrls'][resourceType][format] = [];
|
||||
}
|
||||
obj['resourceUrls'][resourceType][format].push(template);
|
||||
},
|
||||
'WSDL': function(node, obj) {
|
||||
obj['wsdl'] = {};
|
||||
obj['wsdl']['href'] = this.getAttributeNS(node,
|
||||
'http://www.w3.org/1999/xlink', 'href');
|
||||
// TODO: other attributes of <WSDL> element
|
||||
},
|
||||
'ServiceMetadataURL': function(node, obj) {
|
||||
obj['serviceMetadataUrl'] = {};
|
||||
obj['serviceMetadataUrl']['href'] =
|
||||
this.getAttributeNS(node, 'http://www.w3.org/1999/xlink', 'href');
|
||||
// TODO: other attributes of <ServiceMetadataURL> element
|
||||
},
|
||||
'LegendURL': function(node, obj) {
|
||||
obj['legend'] = {};
|
||||
obj['legend']['href'] = this.getAttributeNS(node,
|
||||
'http://www.w3.org/1999/xlink', 'href');
|
||||
obj['legend']['format'] = node.getAttribute('format');
|
||||
},
|
||||
'Dimension': function(node, obj) {
|
||||
var dimension = {'values': []};
|
||||
this.readChildNodes(node, dimension);
|
||||
obj['dimensions'].push(dimension);
|
||||
},
|
||||
'Default': function(node, obj) {
|
||||
obj['default'] = this.getChildValue(node);
|
||||
},
|
||||
'Value': function(node, obj) {
|
||||
obj['values'].push(this.getChildValue(node));
|
||||
}
|
||||
}
|
||||
};
|
||||
var ows = new ol.parser.ogc.OWSCommon_v1_1_0();
|
||||
this.readers['http://www.opengis.net/ows/1.1'] =
|
||||
ows.readers['http://www.opengis.net/ows/1.1'];
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.WMTSCapabilities_v1_0_0, ol.parser.XML);
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|Document|Element} data Data to read.
|
||||
* @return {Object} An object representing the document.
|
||||
*/
|
||||
ol.parser.ogc.WMTSCapabilities_v1_0_0.prototype.read = function(data) {
|
||||
if (goog.isString(data)) {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
if (data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var obj = {};
|
||||
this.readNode(data, obj);
|
||||
return obj;
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
goog.provide('ol.parser.Parser');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.Parser = function() {};
|
||||
@@ -1,335 +0,0 @@
|
||||
goog.provide('ol.parser.polyline');
|
||||
|
||||
|
||||
/**
|
||||
* Encode a list of coordinates in a flat array and return an encoded string
|
||||
*
|
||||
* Attention: This function will modify the passed array!
|
||||
*
|
||||
* @param {Array.<number>} flatPoints A flat array of coordinates.
|
||||
* @param {number=} opt_dimension The dimension of the coordinates in the array.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeFlatCoordinates =
|
||||
function(flatPoints, opt_dimension) {
|
||||
var dimension = opt_dimension || 2;
|
||||
return ol.parser.polyline.encodeDeltas(flatPoints, dimension);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode a list of coordinates from an encoded string into a flat array
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @param {number=} opt_dimension The dimension of the coordinates in the
|
||||
* encoded string.
|
||||
* @return {Array.<number>} A flat array of coordinates.
|
||||
*/
|
||||
ol.parser.polyline.decodeFlatCoordinates = function(encoded, opt_dimension) {
|
||||
var dimension = opt_dimension || 2;
|
||||
return ol.parser.polyline.decodeDeltas(encoded, dimension);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode a list of n-dimensional points and return an encoded string
|
||||
*
|
||||
* Attention: This function will modify the passed array!
|
||||
*
|
||||
* @param {Array.<number>} numbers A list of n-dimensional points.
|
||||
* @param {number} dimension The dimension of the points in the list.
|
||||
* @param {number=} opt_factor The factor by which the numbers will be
|
||||
* multiplied. The remaining decimal places will get rounded away.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeDeltas = function(numbers, dimension, opt_factor) {
|
||||
var factor = opt_factor || 1e5;
|
||||
var d;
|
||||
|
||||
var lastNumbers = new Array(dimension);
|
||||
for (d = 0; d < dimension; ++d) {
|
||||
lastNumbers[d] = 0;
|
||||
}
|
||||
|
||||
var numbersLength = numbers.length;
|
||||
for (var i = 0; i < numbersLength;) {
|
||||
for (d = 0; d < dimension; ++d, ++i) {
|
||||
var num = numbers[i];
|
||||
var delta = num - lastNumbers[d];
|
||||
lastNumbers[d] = num;
|
||||
|
||||
numbers[i] = delta;
|
||||
}
|
||||
}
|
||||
|
||||
return ol.parser.polyline.encodeFloats(numbers, factor);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode a list of n-dimensional points from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @param {number} dimension The dimension of the points in the encoded string.
|
||||
* @param {number=} opt_factor The factor by which the resulting numbers will
|
||||
* be divided.
|
||||
* @return {Array.<number>} A list of n-dimensional points.
|
||||
*/
|
||||
ol.parser.polyline.decodeDeltas = function(encoded, dimension, opt_factor) {
|
||||
var factor = opt_factor || 1e5;
|
||||
var d;
|
||||
|
||||
var lastNumbers = new Array(dimension);
|
||||
for (d = 0; d < dimension; ++d) {
|
||||
lastNumbers[d] = 0;
|
||||
}
|
||||
|
||||
var numbers = ol.parser.polyline.decodeFloats(encoded, factor);
|
||||
|
||||
var numbersLength = numbers.length;
|
||||
for (var i = 0; i < numbersLength;) {
|
||||
for (d = 0; d < dimension; ++d, ++i) {
|
||||
lastNumbers[d] += numbers[i];
|
||||
|
||||
numbers[i] = lastNumbers[d];
|
||||
}
|
||||
}
|
||||
|
||||
return numbers;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode a list of floating point numbers and return an encoded string
|
||||
*
|
||||
* Attention: This function will modify the passed array!
|
||||
*
|
||||
* @param {Array.<number>} numbers A list of floating point numbers.
|
||||
* @param {number=} opt_factor The factor by which the numbers will be
|
||||
* multiplied. The remaining decimal places will get rounded away.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeFloats = function(numbers, opt_factor) {
|
||||
var factor = opt_factor || 1e5;
|
||||
|
||||
var numbersLength = numbers.length;
|
||||
for (var i = 0; i < numbersLength; ++i) {
|
||||
numbers[i] = Math.round(numbers[i] * factor);
|
||||
}
|
||||
|
||||
return ol.parser.polyline.encodeSignedIntegers(numbers);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode a list of floating point numbers from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @param {number=} opt_factor The factor by which the result will be divided.
|
||||
* @return {Array.<number>} A list of floating point numbers.
|
||||
*/
|
||||
ol.parser.polyline.decodeFloats = function(encoded, opt_factor) {
|
||||
var factor = opt_factor || 1e5;
|
||||
|
||||
var numbers = ol.parser.polyline.decodeSignedIntegers(encoded);
|
||||
|
||||
var numbersLength = numbers.length;
|
||||
for (var i = 0; i < numbersLength; ++i) {
|
||||
numbers[i] /= factor;
|
||||
}
|
||||
|
||||
return numbers;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode a list of signed integers and return an encoded string
|
||||
*
|
||||
* Attention: This function will modify the passed array!
|
||||
*
|
||||
* @param {Array.<number>} numbers A list of signed integers.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeSignedIntegers = function(numbers) {
|
||||
var numbersLength = numbers.length;
|
||||
for (var i = 0; i < numbersLength; ++i) {
|
||||
var num = numbers[i];
|
||||
|
||||
var signedNum = num << 1;
|
||||
if (num < 0) {
|
||||
signedNum = ~(signedNum);
|
||||
}
|
||||
|
||||
numbers[i] = signedNum;
|
||||
}
|
||||
|
||||
return ol.parser.polyline.encodeUnsignedIntegers(numbers);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode a list of signed integers from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @return {Array.<number>} A list of signed integers.
|
||||
*/
|
||||
ol.parser.polyline.decodeSignedIntegers = function(encoded) {
|
||||
var numbers = ol.parser.polyline.decodeUnsignedIntegers(encoded);
|
||||
|
||||
var numbersLength = numbers.length;
|
||||
for (var i = 0; i < numbersLength; ++i) {
|
||||
var num = numbers[i];
|
||||
numbers[i] = (num & 1) ? ~(num >> 1) : (num >> 1);
|
||||
}
|
||||
|
||||
return numbers;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode a list of unsigned integers and return an encoded string
|
||||
*
|
||||
* @param {Array.<number>} numbers A list of unsigned integers.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeUnsignedIntegers = function(numbers) {
|
||||
var encoded = '';
|
||||
|
||||
var numbersLength = numbers.length;
|
||||
for (var i = 0; i < numbersLength; ++i) {
|
||||
encoded += ol.parser.polyline.encodeUnsignedInteger(numbers[i]);
|
||||
}
|
||||
|
||||
return encoded;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode a list of unsigned integers from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @return {Array.<number>} A list of unsigned integers.
|
||||
*/
|
||||
ol.parser.polyline.decodeUnsignedIntegers = function(encoded) {
|
||||
var numbers = [];
|
||||
|
||||
var current = 0;
|
||||
var shift = 0;
|
||||
|
||||
var encodedLength = encoded.length;
|
||||
for (var i = 0; i < encodedLength; ++i) {
|
||||
var b = encoded.charCodeAt(i) - 63;
|
||||
|
||||
current |= (b & 0x1f) << shift;
|
||||
|
||||
if (b < 0x20) {
|
||||
numbers.push(current);
|
||||
current = 0;
|
||||
shift = 0;
|
||||
} else {
|
||||
shift += 5;
|
||||
}
|
||||
}
|
||||
|
||||
return numbers;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode one single floating point number and return an encoded string
|
||||
*
|
||||
* @param {number} num Floating point number that should be encoded.
|
||||
* @param {number=} opt_factor The factor by which num will be multiplied.
|
||||
* The remaining decimal places will get rounded away.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeFloat = function(num, opt_factor) {
|
||||
num = Math.round(num * (opt_factor || 1e5));
|
||||
return ol.parser.polyline.encodeSignedInteger(num);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode one single floating point number from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @param {number=} opt_factor The factor by which the result will be divided.
|
||||
* @return {number} The decoded floating point number.
|
||||
*/
|
||||
ol.parser.polyline.decodeFloat = function(encoded, opt_factor) {
|
||||
var result = ol.parser.polyline.decodeSignedInteger(encoded);
|
||||
return result / (opt_factor || 1e5);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode one single signed integer and return an encoded string
|
||||
*
|
||||
* @param {number} num Signed integer that should be encoded.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeSignedInteger = function(num) {
|
||||
var signedNum = num << 1;
|
||||
if (num < 0) {
|
||||
signedNum = ~(signedNum);
|
||||
}
|
||||
|
||||
return ol.parser.polyline.encodeUnsignedInteger(signedNum);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode one single signed integer from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @return {number} The decoded signed integer.
|
||||
*/
|
||||
ol.parser.polyline.decodeSignedInteger = function(encoded) {
|
||||
var result = ol.parser.polyline.decodeUnsignedInteger(encoded);
|
||||
return ((result & 1) ? ~(result >> 1) : (result >> 1));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode one single unsigned integer and return an encoded string
|
||||
*
|
||||
* @param {number} num Unsigned integer that should be encoded.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeUnsignedInteger = function(num) {
|
||||
var value, encoded = '';
|
||||
while (num >= 0x20) {
|
||||
value = (0x20 | (num & 0x1f)) + 63;
|
||||
encoded += (String.fromCharCode(value));
|
||||
num >>= 5;
|
||||
}
|
||||
value = num + 63;
|
||||
encoded += (String.fromCharCode(value));
|
||||
return encoded;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode one single unsigned integer from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @return {number} The decoded unsigned integer.
|
||||
*/
|
||||
ol.parser.polyline.decodeUnsignedInteger = function(encoded) {
|
||||
var result = 0;
|
||||
var shift = 0;
|
||||
|
||||
var encodedLength = encoded.length;
|
||||
for (var i = 0; i < encodedLength; ++i) {
|
||||
var b = encoded.charCodeAt(i) - 63;
|
||||
|
||||
result |= (b & 0x1f) << shift;
|
||||
|
||||
if (b < 0x20)
|
||||
break;
|
||||
|
||||
shift += 5;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
@exportSymbol ol.parser.TopoJSON
|
||||
@@ -1,382 +0,0 @@
|
||||
goog.provide('ol.parser.TopoJSON');
|
||||
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.CoordinateArray');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.Parser');
|
||||
goog.require('ol.parser.StringFeatureParser');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read [TopoJSON](https://github.com/mbostock/topojson)
|
||||
*
|
||||
* @constructor
|
||||
* @implements {ol.parser.StringFeatureParser}
|
||||
* @extends {ol.parser.Parser}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.TopoJSON = function() {};
|
||||
goog.inherits(ol.parser.TopoJSON, ol.parser.Parser);
|
||||
goog.addSingletonGetter(ol.parser.TopoJSON);
|
||||
|
||||
|
||||
/**
|
||||
* Concatenate arcs into a coordinate array.
|
||||
* @param {Array.<number>} indices Indices of arcs to concatenate. Negative
|
||||
* values indicate arcs need to be reversed.
|
||||
* @param {Array.<ol.CoordinateArray>} arcs Arcs (already transformed).
|
||||
* @return {ol.CoordinateArray} Coordinate array.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.concatenateArcs_ = function(indices, arcs) {
|
||||
var coordinates = [];
|
||||
var index, arc;
|
||||
for (var i = 0, ii = indices.length; i < ii; ++i) {
|
||||
index = indices[i];
|
||||
if (i > 0) {
|
||||
// splicing together arcs, discard last point
|
||||
coordinates.pop();
|
||||
}
|
||||
if (index >= 0) {
|
||||
// forward arc
|
||||
arc = arcs[index];
|
||||
} else {
|
||||
// reverse arc
|
||||
arc = arcs[~index].slice().reverse();
|
||||
}
|
||||
coordinates.push.apply(coordinates, arc);
|
||||
}
|
||||
// provide fresh copies of coordinate arrays
|
||||
for (var j = 0, jj = coordinates.length; j < jj; ++j) {
|
||||
coordinates[j] = coordinates[j].slice();
|
||||
}
|
||||
return coordinates;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a TopoJSON string.
|
||||
* @param {string} str TopoJSON string.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.read = function(str) {
|
||||
var topology = /** @type {TopoJSONTopology} */ (JSON.parse(str));
|
||||
return this.readFeaturesFromObject(topology).features;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create features from a TopoJSON topology string.
|
||||
*
|
||||
* @param {string} str TopoJSON topology string.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.readFeaturesFromString = function(str) {
|
||||
var topology = /** @type {TopoJSONTopology} */ (JSON.parse(str));
|
||||
if (topology.type !== 'Topology') {
|
||||
throw new Error('Not a "Topology" type object');
|
||||
}
|
||||
return {
|
||||
features: this.readFeaturesFromTopology_(topology),
|
||||
metadata: {projection: 'EPSG:4326'}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create features from a TopoJSON topology object.
|
||||
*
|
||||
* @param {TopoJSONTopology} topology TopoJSON topology object.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.readFeaturesFromObject = function(topology) {
|
||||
if (topology.type !== 'Topology') {
|
||||
throw new Error('Not a "Topology" type object');
|
||||
}
|
||||
return {
|
||||
features: this.readFeaturesFromTopology_(topology),
|
||||
metadata: {projection: 'EPSG:4326'}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a feature from a TopoJSON geometry object.
|
||||
*
|
||||
* @param {TopoJSONGeometry} object TopoJSON geometry object.
|
||||
* @param {Array.<ol.CoordinateArray>} arcs Array of arcs.
|
||||
* @param {Array.<number>} scale Scale for each dimension.
|
||||
* @param {Array.<number>} translate Translation for each dimension.
|
||||
* @return {ol.Feature} Feature.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.readFeatureFromGeometry_ = function(object, arcs,
|
||||
scale, translate) {
|
||||
var geometry;
|
||||
var type = object.type;
|
||||
if (type === 'Point') {
|
||||
geometry = this.readPoint_(/** @type {TopoJSONPoint} */ (object), scale,
|
||||
translate);
|
||||
} else if (type === 'LineString') {
|
||||
geometry = this.readLineString_(/** @type {TopoJSONLineString} */ (object),
|
||||
arcs);
|
||||
} else if (type === 'Polygon') {
|
||||
geometry = this.readPolygon_(/** @type {TopoJSONPolygon} */ (object), arcs);
|
||||
} else if (type === 'MultiPoint') {
|
||||
geometry = this.readMultiPoint_(/** @type {TopoJSONMultiPoint} */ (object),
|
||||
scale, translate);
|
||||
} else if (type === 'MultiLineString') {
|
||||
geometry = this.readMultiLineString_(
|
||||
/** @type {TopoJSONMultiLineString} */(object), arcs);
|
||||
} else if (type === 'MultiPolygon') {
|
||||
geometry = this.readMultiPolygon_(
|
||||
/** @type {TopoJSONMultiPolygon} */ (object), arcs);
|
||||
} else {
|
||||
throw new Error('Unsupported geometry type: ' + type);
|
||||
}
|
||||
var feature = new ol.Feature();
|
||||
feature.setGeometry(geometry);
|
||||
if (goog.isDef(object.id)) {
|
||||
feature.setId(String(object.id));
|
||||
}
|
||||
return feature;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create features from a TopoJSON GeometryCollection object.
|
||||
*
|
||||
* @param {TopoJSONGeometryCollection} collection TopoJSON GeometryCollection
|
||||
* object.
|
||||
* @param {Array.<ol.CoordinateArray>} arcs Array of arcs.
|
||||
* @param {Array.<number>} scale Scale for each dimension.
|
||||
* @param {Array.<number>} translate Translation for each dimension.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.readFeaturesFromGeometryCollection_ = function(
|
||||
collection, arcs, scale, translate) {
|
||||
var geometries = collection.geometries;
|
||||
var num = geometries.length;
|
||||
var features = new Array(num);
|
||||
for (var i = 0; i < num; ++i) {
|
||||
features[i] = this.readFeatureFromGeometry_(geometries[i], arcs, scale,
|
||||
translate);
|
||||
}
|
||||
return features;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {TopoJSONTopology} topology TopoJSON object.
|
||||
* @return {Array.<ol.Feature>} Parsed features.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.readFeaturesFromTopology_ = function(topology) {
|
||||
var transform = topology.transform;
|
||||
var scale = transform.scale;
|
||||
var translate = transform.translate;
|
||||
var arcs = topology.arcs;
|
||||
this.transformArcs_(arcs, scale, translate);
|
||||
var objects = topology.objects;
|
||||
var features = [];
|
||||
for (var key in objects) {
|
||||
if (objects[key].type === 'GeometryCollection') {
|
||||
features.push.apply(features, this.readFeaturesFromGeometryCollection_(
|
||||
/** @type {TopoJSONGeometryCollection} */ (objects[key]),
|
||||
arcs, scale, translate));
|
||||
} else {
|
||||
features.push(this.readFeatureFromGeometry_(
|
||||
/** @type {TopoJSONGeometry} */ (objects[key]),
|
||||
arcs, scale, translate));
|
||||
}
|
||||
}
|
||||
return features;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a linestring from a TopoJSON geometry object.
|
||||
*
|
||||
* @param {TopoJSONLineString} object TopoJSON object.
|
||||
* @param {Array.<ol.CoordinateArray>} arcs Array of arcs.
|
||||
* @return {ol.geom.LineString} Geometry.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.readLineString_ = function(object, arcs) {
|
||||
var coordinates = this.concatenateArcs_(object.arcs, arcs);
|
||||
return new ol.geom.LineString(coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a multi-linestring from a TopoJSON geometry object.
|
||||
*
|
||||
* @param {TopoJSONMultiLineString} object TopoJSON object.
|
||||
* @param {Array.<ol.CoordinateArray>} arcs Array of arcs.
|
||||
* @return {ol.geom.MultiLineString} Geometry.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.readMultiLineString_ = function(object, arcs) {
|
||||
var array = object.arcs; // I'm out of good names
|
||||
var num = array.length;
|
||||
var coordinates = new Array(num);
|
||||
for (var i = 0; i < num; ++i) {
|
||||
coordinates[i] = this.concatenateArcs_(array[i], arcs);
|
||||
}
|
||||
return new ol.geom.MultiLineString(coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a multi-point from a TopoJSON geometry object.
|
||||
*
|
||||
* @param {TopoJSONMultiPoint} object TopoJSON object.
|
||||
* @param {Array.<number>} scale Scale for each dimension.
|
||||
* @param {Array.<number>} translate Translation for each dimension.
|
||||
* @return {ol.geom.MultiPoint} Geometry.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.readMultiPoint_ = function(object, scale,
|
||||
translate) {
|
||||
var coordinates = object.coordinates;
|
||||
for (var i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
this.transformVertex_(coordinates[i], scale, translate);
|
||||
}
|
||||
return new ol.geom.MultiPoint(coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a multi-polygon from a TopoJSON geometry object.
|
||||
*
|
||||
* @param {TopoJSONMultiPolygon} object TopoJSON object.
|
||||
* @param {Array.<ol.CoordinateArray>} arcs Array of arcs.
|
||||
* @return {ol.geom.MultiPolygon} Geometry.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.readMultiPolygon_ = function(object, arcs) {
|
||||
var array = object.arcs;
|
||||
var numPolys = array.length;
|
||||
var coordinates = new Array(numPolys);
|
||||
var polyArray, numRings, ringCoords, j;
|
||||
for (var i = 0; i < numPolys; ++i) {
|
||||
// for each polygon
|
||||
polyArray = array[i];
|
||||
numRings = polyArray.length;
|
||||
ringCoords = new Array(numRings);
|
||||
for (j = 0; j < numRings; ++j) {
|
||||
// for each ring
|
||||
ringCoords[j] = this.concatenateArcs_(polyArray[j], arcs);
|
||||
}
|
||||
coordinates[i] = ringCoords;
|
||||
}
|
||||
return new ol.geom.MultiPolygon(coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a point from a TopoJSON geometry object.
|
||||
*
|
||||
* @param {TopoJSONPoint} object TopoJSON object.
|
||||
* @param {Array.<number>} scale Scale for each dimension.
|
||||
* @param {Array.<number>} translate Translation for each dimension.
|
||||
* @return {ol.geom.Point} Geometry.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.readPoint_ = function(object, scale, translate) {
|
||||
var coordinates = object.coordinates;
|
||||
this.transformVertex_(coordinates, scale, translate);
|
||||
return new ol.geom.Point(coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a polygon from a TopoJSON geometry object.
|
||||
*
|
||||
* @param {TopoJSONPolygon} object TopoJSON object.
|
||||
* @param {Array.<ol.CoordinateArray>} arcs Array of arcs.
|
||||
* @return {ol.geom.Polygon} Geometry.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.readPolygon_ = function(object, arcs) {
|
||||
var array = object.arcs; // I'm out of good names
|
||||
var num = array.length;
|
||||
var coordinates = new Array(num);
|
||||
for (var i = 0; i < num; ++i) {
|
||||
coordinates[i] = this.concatenateArcs_(array[i], arcs);
|
||||
}
|
||||
return new ol.geom.Polygon(coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Apply a linear transform to array of arcs. The provided array of arcs is
|
||||
* modified in place.
|
||||
*
|
||||
* @param {Array.<ol.CoordinateArray>} arcs Array of arcs.
|
||||
* @param {Array.<number>} scale Scale for each dimension.
|
||||
* @param {Array.<number>} translate Translation for each dimension.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.transformArcs_ = function(arcs, scale, translate) {
|
||||
for (var i = 0, ii = arcs.length; i < ii; ++i) {
|
||||
this.transformArc_(arcs[i], scale, translate);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Apply a linear transform to an arc. The provided arc is modified in place.
|
||||
*
|
||||
* @param {ol.CoordinateArray} arc Arc.
|
||||
* @param {Array.<number>} scale Scale for each dimension.
|
||||
* @param {Array.<number>} translate Translation for each dimension.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.transformArc_ = function(arc, scale, translate) {
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
var vertex;
|
||||
for (var i = 0, ii = arc.length; i < ii; ++i) {
|
||||
vertex = arc[i];
|
||||
x += vertex[0];
|
||||
y += vertex[1];
|
||||
vertex[0] = x;
|
||||
vertex[1] = y;
|
||||
this.transformVertex_(vertex, scale, translate);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Apply a linear transform to a vertex. The provided vertex is modified in
|
||||
* place.
|
||||
*
|
||||
* @param {ol.Coordinate} vertex Vertex.
|
||||
* @param {Array.<number>} scale Scale for each dimension.
|
||||
* @param {Array.<number>} translate Translation for each dimension.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.TopoJSON.prototype.transformVertex_ = function(vertex, scale,
|
||||
translate) {
|
||||
vertex[0] = vertex[0] * scale[0] + translate[0];
|
||||
vertex[1] = vertex[1] * scale[1] + translate[1];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a TopoJSON string.
|
||||
* @param {string} str TopoJSON string.
|
||||
* @return {Array.<ol.Feature>} Array of features.
|
||||
*/
|
||||
ol.parser.TopoJSON.read = function(str) {
|
||||
return ol.parser.TopoJSON.getInstance().read(str);
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
@exportSymbol ol.parser.WKT
|
||||
@exportProperty ol.parser.WKT.prototype.read
|
||||
@exportProperty ol.parser.WKT.prototype.write
|
||||
@exportProperty ol.parser.WKT.read
|
||||
@exportProperty ol.parser.WKT.write
|
||||
@@ -1,392 +0,0 @@
|
||||
goog.provide('ol.parser.WKT');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.string');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.geom.GeometryCollection');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
goog.require('ol.geom.MultiPoint');
|
||||
goog.require('ol.geom.MultiPolygon');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.Parser');
|
||||
goog.require('ol.parser.StringFeatureParser');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.Parser}
|
||||
* @implements {ol.parser.StringFeatureParser}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.WKT = function() {
|
||||
};
|
||||
goog.inherits(ol.parser.WKT, ol.parser.Parser);
|
||||
goog.addSingletonGetter(ol.parser.WKT);
|
||||
|
||||
|
||||
/**
|
||||
* Constants for regExes.
|
||||
* @enum {RegExp}
|
||||
*/
|
||||
ol.parser.WKT.regExes = {
|
||||
typeStr: /^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/,
|
||||
spaces: /\s+/,
|
||||
parenComma: /\)\s*,\s*\(/,
|
||||
doubleParenComma: /\)\s*\)\s*,\s*\(\s*\(/,
|
||||
trimParens: /^\s*\(?(.*?)\)?\s*$/,
|
||||
geomCollection: /,\s*([A-Za-z])/g,
|
||||
removeNewLine: /[\n\r]/g
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} str WKT point.
|
||||
* @return {ol.geom.Point} Parsed point.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.parsePoint_ = function(str) {
|
||||
var coords = goog.string.trim(str).split(ol.parser.WKT.regExes.spaces);
|
||||
return new ol.geom.Point(goog.array.map(coords, parseFloat));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} str WKT linestring.
|
||||
* @return {ol.geom.LineString} Parsed linestring.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.parseLineString_ = function(str) {
|
||||
var points = goog.string.trim(str).split(',');
|
||||
var coordinates = [];
|
||||
for (var i = 0, ii = points.length; i < ii; ++i) {
|
||||
coordinates.push(this.parsePoint_.apply(this,
|
||||
[points[i]]).getCoordinates());
|
||||
}
|
||||
return new ol.geom.LineString(coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} str WKT multipoint.
|
||||
* @return {ol.geom.MultiPoint} Parsed multipoint.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.parseMultiPoint_ = function(str) {
|
||||
var point;
|
||||
var points = goog.string.trim(str).split(',');
|
||||
var parts = [];
|
||||
for (var i = 0, ii = points.length; i < ii; ++i) {
|
||||
point = points[i].replace(ol.parser.WKT.regExes.trimParens, '$1');
|
||||
parts.push(this.parsePoint_.apply(this, [point]));
|
||||
}
|
||||
return ol.geom.MultiPoint.fromParts(parts);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} str WKT multilinestring.
|
||||
* @return {ol.geom.MultiLineString} Parsed multilinestring.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.parseMultiLineString_ = function(str) {
|
||||
var line;
|
||||
var lines = goog.string.trim(str).split(ol.parser.WKT.regExes.parenComma);
|
||||
var parts = [];
|
||||
for (var i = 0, ii = lines.length; i < ii; ++i) {
|
||||
line = lines[i].replace(ol.parser.WKT.regExes.trimParens, '$1');
|
||||
parts.push(this.parseLineString_.apply(this, [line]));
|
||||
}
|
||||
return ol.geom.MultiLineString.fromParts(parts);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} str WKT polygon.
|
||||
* @return {ol.geom.Polygon} Parsed polygon.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.parsePolygon_ = function(str) {
|
||||
var ring, linestring, linearring;
|
||||
var rings = goog.string.trim(str).split(ol.parser.WKT.regExes.parenComma);
|
||||
var coordinates = [];
|
||||
for (var i = 0, ii = rings.length; i < ii; ++i) {
|
||||
ring = rings[i].replace(ol.parser.WKT.regExes.trimParens, '$1');
|
||||
linestring = this.parseLineString_.apply(this, [ring]).getCoordinates();
|
||||
coordinates.push(linestring);
|
||||
}
|
||||
return new ol.geom.Polygon(coordinates);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} str WKT multipolygon.
|
||||
* @return {ol.geom.MultiPolygon} Parsed multipolygon.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.parseMultiPolygon_ = function(str) {
|
||||
var polygon;
|
||||
var polygons = goog.string.trim(str).split(
|
||||
ol.parser.WKT.regExes.doubleParenComma);
|
||||
var parts = [];
|
||||
for (var i = 0, ii = polygons.length; i < ii; ++i) {
|
||||
polygon = polygons[i].replace(ol.parser.WKT.regExes.trimParens, '$1');
|
||||
parts.push(this.parsePolygon_.apply(this, [polygon]));
|
||||
}
|
||||
return ol.geom.MultiPolygon.fromParts(parts);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} str WKT geometrycollection.
|
||||
* @return {ol.geom.GeometryCollection} Parsed geometrycollection.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.parseGeometryCollection_ = function(str) {
|
||||
// separate components of the collection with |
|
||||
str = str.replace(ol.parser.WKT.regExes.geomCollection, '|$1');
|
||||
var wktArray = goog.string.trim(str).split('|');
|
||||
var components = [];
|
||||
for (var i = 0, ii = wktArray.length; i < ii; ++i) {
|
||||
components.push(this.parse_.apply(this, [wktArray[i]]));
|
||||
}
|
||||
return new ol.geom.GeometryCollection(components);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Point} geom Point geometry.
|
||||
* @return {string} Coordinates part of Point as WKT.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.encodePoint_ = function(geom) {
|
||||
var coordinates = geom.getCoordinates();
|
||||
return coordinates[0] + ' ' + coordinates[1];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.MultiPoint} geom MultiPoint geometry.
|
||||
* @return {string} Coordinates part of MultiPoint as WKT.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.encodeMultiPoint_ = function(geom) {
|
||||
var array = [];
|
||||
var components = geom.getComponents();
|
||||
for (var i = 0, ii = components.length; i < ii; ++i) {
|
||||
array.push('(' + this.encodePoint_.apply(this, [components[i]]) + ')');
|
||||
}
|
||||
return array.join(',');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.GeometryCollection} geom GeometryCollection geometry.
|
||||
* @return {string} Coordinates part of GeometryCollection as WKT.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.encodeGeometryCollection_ = function(geom) {
|
||||
var array = [];
|
||||
var components = geom.getComponents();
|
||||
for (var i = 0, ii = components.length; i < ii; ++i) {
|
||||
array.push(this.encode_.apply(this, [components[i]]));
|
||||
}
|
||||
return array.join(',');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.LineString} geom LineString geometry.
|
||||
* @return {string} Coordinates part of LineString as WKT.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.encodeLineString_ = function(geom) {
|
||||
var coordinates = geom.getCoordinates();
|
||||
var array = [];
|
||||
for (var i = 0, ii = coordinates.length; i < ii; ++i) {
|
||||
array.push(coordinates[i][0] + ' ' + coordinates[i][1]);
|
||||
}
|
||||
return array.join(',');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.MultiLineString} geom MultiLineString geometry.
|
||||
* @return {string} Coordinates part of MultiLineString as WKT.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.encodeMultiLineString_ = function(geom) {
|
||||
var array = [];
|
||||
var components = geom.getComponents();
|
||||
for (var i = 0, ii = components.length; i < ii; ++i) {
|
||||
array.push('(' + this.encodeLineString_.apply(this,
|
||||
[components[i]]) + ')');
|
||||
}
|
||||
return array.join(',');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.Polygon} geom Polygon geometry.
|
||||
* @return {string} Coordinates part of Polygon as WKT.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.encodePolygon_ = function(geom) {
|
||||
var array = [];
|
||||
var rings = geom.getRings();
|
||||
for (var i = 0, ii = rings.length; i < ii; ++i) {
|
||||
array.push('(' + this.encodeLineString_.apply(this,
|
||||
[rings[i]]) + ')');
|
||||
}
|
||||
return array.join(',');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.geom.MultiPolygon} geom MultiPolygon geometry.
|
||||
* @return {string} Coordinates part of MultiPolygon as WKT.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.encodeMultiPolygon_ = function(geom) {
|
||||
var array = [];
|
||||
var components = geom.getComponents();
|
||||
for (var i = 0, ii = components.length; i < ii; ++i) {
|
||||
array.push('(' + this.encodePolygon_.apply(this, [components[i]]) + ')');
|
||||
}
|
||||
return array.join(',');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a WKT string.
|
||||
* @param {string} wkt WKT string.
|
||||
* @return {ol.geom.Geometry|ol.geom.GeometryCollection|undefined}
|
||||
* The geometry created.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.parse_ = function(wkt) {
|
||||
wkt = wkt.replace(ol.parser.WKT.regExes.removeNewLine, ' ');
|
||||
var matches = ol.parser.WKT.regExes.typeStr.exec(wkt);
|
||||
var geometry;
|
||||
if (matches) {
|
||||
var type = matches[1].toLowerCase();
|
||||
var str = matches[2];
|
||||
switch (type) {
|
||||
case 'point':
|
||||
geometry = this.parsePoint_(str);
|
||||
break;
|
||||
case 'multipoint':
|
||||
geometry = this.parseMultiPoint_(str);
|
||||
break;
|
||||
case 'linestring':
|
||||
geometry = this.parseLineString_(str);
|
||||
break;
|
||||
case 'multilinestring':
|
||||
geometry = this.parseMultiLineString_(str);
|
||||
break;
|
||||
case 'polygon':
|
||||
geometry = this.parsePolygon_(str);
|
||||
break;
|
||||
case 'multipolygon':
|
||||
geometry = this.parseMultiPolygon_(str);
|
||||
break;
|
||||
case 'geometrycollection':
|
||||
geometry = this.parseGeometryCollection_(str);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Bad geometry type: ' + type);
|
||||
}
|
||||
}
|
||||
return geometry;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode a geometry as WKT.
|
||||
* @param {ol.geom.Geometry} geom The geometry to encode.
|
||||
* @return {string} WKT string for the geometry.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.WKT.prototype.encode_ = function(geom) {
|
||||
var type = geom.getType();
|
||||
var result = type.toUpperCase() + '(';
|
||||
if (geom instanceof ol.geom.Point) {
|
||||
result += this.encodePoint_(geom);
|
||||
} else if (geom instanceof ol.geom.MultiPoint) {
|
||||
result += this.encodeMultiPoint_(geom);
|
||||
} else if (geom instanceof ol.geom.LineString) {
|
||||
result += this.encodeLineString_(geom);
|
||||
} else if (geom instanceof ol.geom.MultiLineString) {
|
||||
result += this.encodeMultiLineString_(geom);
|
||||
} else if (geom instanceof ol.geom.Polygon) {
|
||||
result += this.encodePolygon_(geom);
|
||||
} else if (geom instanceof ol.geom.MultiPolygon) {
|
||||
result += this.encodeMultiPolygon_(geom);
|
||||
} else if (geom instanceof ol.geom.GeometryCollection) {
|
||||
result += this.encodeGeometryCollection_(geom);
|
||||
} else {
|
||||
throw new Error('Bad geometry type: ' + type);
|
||||
}
|
||||
return result + ')';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a WKT string.
|
||||
* @param {string} str WKT string.
|
||||
* @return {ol.geom.Geometry|undefined} Parsed geometry.
|
||||
*/
|
||||
ol.parser.WKT.prototype.read = function(str) {
|
||||
return this.parse_(str);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a WKT document provided as a string.
|
||||
* @param {string} str WKT document.
|
||||
* @return {ol.parser.ReadFeaturesResult} Features and metadata.
|
||||
*/
|
||||
ol.parser.WKT.prototype.readFeaturesFromString = function(str) {
|
||||
var geom = this.read(str);
|
||||
var obj = /** @type {ol.parser.ReadFeaturesResult} */
|
||||
({});
|
||||
if (goog.isDef(geom)) {
|
||||
var feature = new ol.Feature();
|
||||
feature.setGeometry(geom);
|
||||
obj.features = [feature];
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Write out a geometry as a WKT string.
|
||||
* @param {ol.geom.Geometry} geom The geometry to encode.
|
||||
* @return {string} WKT for the geometry.
|
||||
*/
|
||||
ol.parser.WKT.prototype.write = function(geom) {
|
||||
return this.encode_(geom);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a WKT string.
|
||||
* @param {string} str WKT string.
|
||||
* @return {ol.geom.Geometry|undefined} Parsed geometry.
|
||||
*/
|
||||
ol.parser.WKT.read = function(str) {
|
||||
return ol.parser.WKT.getInstance().read(str);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Write out a geometry as a WKT string.
|
||||
* @param {ol.geom.Geometry} geom The geometry to encode.
|
||||
* @return {string} WKT for the geometry.
|
||||
*/
|
||||
ol.parser.WKT.write = function(geom) {
|
||||
return ol.parser.WKT.getInstance().write(geom);
|
||||
};
|
||||
@@ -1,296 +0,0 @@
|
||||
goog.provide('ol.parser.XML');
|
||||
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.parser.Parser');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.Parser}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.XML = function() {
|
||||
if (goog.global.ActiveXObject) {
|
||||
this.xmldom = new ActiveXObject('Microsoft.XMLDOM');
|
||||
}
|
||||
this.regExes = {
|
||||
trimSpace: (/^\s*|\s*$/g),
|
||||
removeSpace: (/\s*/g),
|
||||
splitSpace: (/\s+/),
|
||||
trimComma: (/\s*,\s*/g)
|
||||
};
|
||||
};
|
||||
goog.inherits(ol.parser.XML, ol.parser.Parser);
|
||||
|
||||
|
||||
/**
|
||||
* Shorthand for applying one of the named readers given the node
|
||||
* namespace and local name. Readers take two args (node, obj) and
|
||||
* generally extend or modify the second.
|
||||
*
|
||||
* @param {Element|Document} node The node to be read (required).
|
||||
* @param {Object} obj The object to be modified (optional).
|
||||
* @return {Object} The input object, modified (or a new one if none was
|
||||
* provided).
|
||||
*/
|
||||
ol.parser.XML.prototype.readNode = function(node, obj) {
|
||||
if (!obj) {
|
||||
obj = {};
|
||||
}
|
||||
var group = this.readers[node.namespaceURI] ||
|
||||
this.readers[this.defaultNamespaceURI];
|
||||
if (group) {
|
||||
var local = node.localName || node.nodeName.split(':').pop();
|
||||
var reader = group[local] || group['*'];
|
||||
if (reader) {
|
||||
reader.apply(this, [node, obj]);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Shorthand for applying the named readers to all children of a node.
|
||||
* For each child of type 1 (element), <readSelf> is called.
|
||||
*
|
||||
* @param {Element|Document} node The node to be read (required).
|
||||
* @param {Object} obj The object to be modified (optional).
|
||||
* @return {Object} The input object, modified.
|
||||
*/
|
||||
ol.parser.XML.prototype.readChildNodes = function(node, obj) {
|
||||
if (!obj) {
|
||||
obj = {};
|
||||
}
|
||||
var children = node.childNodes;
|
||||
var child;
|
||||
for (var i = 0, len = children.length; i < len; ++i) {
|
||||
child = children[i];
|
||||
if (child.nodeType == 1) {
|
||||
this.readNode(child, obj);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the textual value of the node if it exists, or return an
|
||||
* optional default string. Returns an empty string if no first child
|
||||
* exists and no default value is supplied.
|
||||
*
|
||||
* @param {Element} node The element used to look for a first child value.
|
||||
* @param {string} def Optional string to return in the event that no
|
||||
* first child value exists.
|
||||
* @return {string} The value of the first child of the given node.
|
||||
*/
|
||||
ol.parser.XML.prototype.getChildValue = function(node, def) {
|
||||
var value = def || '';
|
||||
if (node) {
|
||||
for (var child = node.firstChild; child; child = child.nextSibling) {
|
||||
switch (child.nodeType) {
|
||||
case 3: // text node
|
||||
case 4: // cdata section
|
||||
value += child.nodeValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get an attribute node given the namespace URI and local name.
|
||||
*
|
||||
* @param {Element} node Node on which to search for attribute nodes.
|
||||
* @param {string} uri Namespace URI.
|
||||
* @param {string} name Local name of the attribute (without the prefix).
|
||||
* @return {?Element} An attribute node or null if none found.
|
||||
*/
|
||||
ol.parser.XML.prototype.getAttributeNodeNS = function(node, uri, name) {
|
||||
var attributeNode = null;
|
||||
if (node.getAttributeNodeNS) {
|
||||
attributeNode = node.getAttributeNodeNS(uri, name);
|
||||
} else {
|
||||
var attributes = node.attributes;
|
||||
var potentialNode, fullName;
|
||||
for (var i = 0, len = attributes.length; i < len; ++i) {
|
||||
potentialNode = attributes[i];
|
||||
if (potentialNode.namespaceURI == uri) {
|
||||
fullName = (potentialNode.prefix) ?
|
||||
(potentialNode.prefix + ':' + name) : name;
|
||||
if (fullName == potentialNode.nodeName) {
|
||||
attributeNode = potentialNode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return attributeNode;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get an attribute value given the namespace URI and local name.
|
||||
*
|
||||
* @param {Element} node Node on which to search for an attribute.
|
||||
* @param {string} uri Namespace URI.
|
||||
* @param {string} name Local name of the attribute (without the prefix).
|
||||
* @return {string} An attribute value or and empty string if none found.
|
||||
*/
|
||||
ol.parser.XML.prototype.getAttributeNS = function(node, uri, name) {
|
||||
var attributeValue = '';
|
||||
if (node.getAttributeNS) {
|
||||
attributeValue = node.getAttributeNS(uri, name) || '';
|
||||
} else {
|
||||
var attributeNode = this.getAttributeNodeNS(node, uri, name);
|
||||
if (attributeNode) {
|
||||
attributeValue = attributeNode.nodeValue;
|
||||
}
|
||||
}
|
||||
return attributeValue;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a new element with namespace. This node can be appended to
|
||||
* another node with the standard node.appendChild method. For
|
||||
* cross-browser support, this method must be used instead of
|
||||
* document.createElementNS.
|
||||
*
|
||||
* @param {string} name The qualified name of the element (prefix:localname).
|
||||
* @param {string=} opt_uri Namespace URI for the element.
|
||||
* @return {Element} A DOM element with namespace.
|
||||
*/
|
||||
ol.parser.XML.prototype.createElementNS = function(name, opt_uri) {
|
||||
var uri = opt_uri ? opt_uri : this.defaultNamespaceURI;
|
||||
var element;
|
||||
if (this.xmldom) {
|
||||
element = this.xmldom.createNode(1, name, uri);
|
||||
} else {
|
||||
element = document.createElementNS(uri, name);
|
||||
}
|
||||
return element;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Shorthand for applying one of the named writers and appending the
|
||||
* results to a node.
|
||||
*
|
||||
* @param {string} name The name of a node to generate. Only use a local name.
|
||||
* @param {Object|string|number} obj Structure containing data for the writer.
|
||||
* @param {?string=} opt_uri The name space uri to which the node
|
||||
* belongs.
|
||||
* @param {Element=} opt_parent Result will be appended to this node. If no
|
||||
* parent is supplied, the node will not be appended to anything.
|
||||
* @return {?Element} The child node.
|
||||
*/
|
||||
ol.parser.XML.prototype.writeNode = function(name, obj, opt_uri, opt_parent) {
|
||||
var child = null;
|
||||
if (goog.isDef(this.writers)) {
|
||||
var uri = opt_uri ? opt_uri : this.defaultNamespaceURI;
|
||||
child = this.writers[uri][name].apply(this, [obj]);
|
||||
if (opt_parent && child) {
|
||||
opt_parent.appendChild(child);
|
||||
}
|
||||
}
|
||||
return child;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a text node. This node can be appended to another node with
|
||||
* the standard node.appendChild method. For cross-browser support,
|
||||
* this method must be used instead of document.createTextNode.
|
||||
*
|
||||
* @param {string} text The text of the node.
|
||||
* @return {Element} A DOM text node.
|
||||
*/
|
||||
ol.parser.XML.prototype.createTextNode = function(text) {
|
||||
var node;
|
||||
if (this.xmldom) {
|
||||
node = this.xmldom.createTextNode(text);
|
||||
} else {
|
||||
node = document.createTextNode(text);
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Adds a new attribute or changes the value of an attribute with the given
|
||||
* namespace and name.
|
||||
*
|
||||
* @param {Element} node Element node on which to set the attribute.
|
||||
* @param {string} uri Namespace URI for the attribute.
|
||||
* @param {string} name Qualified name (prefix:localname) for the attribute.
|
||||
* @param {string} value Attribute value.
|
||||
*/
|
||||
ol.parser.XML.prototype.setAttributeNS = function(node, uri, name, value) {
|
||||
if (node.setAttributeNS) {
|
||||
node.setAttributeNS(uri, name, value);
|
||||
} else {
|
||||
if (this.xmldom) {
|
||||
if (uri) {
|
||||
var attribute = node.ownerDocument.createNode(
|
||||
2, name, uri);
|
||||
attribute.nodeValue = value;
|
||||
node.setAttributeNode(attribute);
|
||||
} else {
|
||||
node.setAttribute(name, value);
|
||||
}
|
||||
} else {
|
||||
throw new Error('setAttributeNS not implemented');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Serializes a node.
|
||||
*
|
||||
* @param {Element} node Element node to serialize.
|
||||
* @return {string} The serialized XML string.
|
||||
*/
|
||||
ol.parser.XML.prototype.serialize = function(node) {
|
||||
if (this.xmldom) {
|
||||
return node.xml;
|
||||
} else if (node.nodeType == 1) {
|
||||
// Add nodes to a document before serializing. Everything else
|
||||
// is serialized as is. This is also needed to get all namespaces
|
||||
// defined in some browsers such as Chrome (xmlns attributes).
|
||||
var doc = document.implementation.createDocument('', '', null);
|
||||
if (doc.importNode) {
|
||||
doc.appendChild(doc.importNode(node, true));
|
||||
} else {
|
||||
doc.appendChild(node);
|
||||
}
|
||||
return goog.dom.xml.serialize(doc);
|
||||
} else {
|
||||
return goog.dom.xml.serialize(node);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a document fragment node that can be appended to another node
|
||||
* created by createElementNS. This will call
|
||||
* document.createDocumentFragment outside of IE. In IE, the ActiveX
|
||||
* object's createDocumentFragment method is used.
|
||||
*
|
||||
* @return {Element} A document fragment.
|
||||
*/
|
||||
ol.parser.XML.prototype.createDocumentFragment = function() {
|
||||
var element;
|
||||
if (this.xmldom) {
|
||||
element = this.xmldom.createDocumentFragment();
|
||||
} else {
|
||||
element = document.createDocumentFragment();
|
||||
}
|
||||
return element;
|
||||
};
|
||||
Reference in New Issue
Block a user