Implement readProjection on ol.format.WFS and add WFS JSONP example
This commit is contained in:
@@ -7,6 +7,7 @@ goog.require('ol.format.GML');
|
||||
goog.require('ol.format.XMLFeature');
|
||||
goog.require('ol.format.XSD');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.xml');
|
||||
|
||||
|
||||
@@ -644,3 +645,50 @@ ol.format.WFS.prototype.writeTransaction = function(inserts, updates, deletes,
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Read the projection from a WFS source.
|
||||
*
|
||||
* @function
|
||||
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||
* @return {?ol.proj.Projection} Projection.
|
||||
*/
|
||||
ol.format.WFS.prototype.readProjection;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.WFS.prototype.readProjectionFromDocument = function(doc) {
|
||||
goog.asserts.assert(doc.nodeType == goog.dom.NodeType.DOCUMENT);
|
||||
for (var n = doc.firstChild; !goog.isNull(n); n = n.nextSibling) {
|
||||
if (n.nodeType == goog.dom.NodeType.ELEMENT) {
|
||||
return this.readProjectionFromNode(n);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.format.WFS.prototype.readProjectionFromNode = function(node) {
|
||||
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
|
||||
goog.asserts.assert(node.localName == 'FeatureCollection');
|
||||
node = node.firstElementChild.firstElementChild;
|
||||
if (goog.isDefAndNotNull(node)) {
|
||||
for (var n = node.firstElementChild; !goog.isNull(n);
|
||||
n = n.nextElementSibling) {
|
||||
if (!(n.childNodes.length === 0 ||
|
||||
(n.childNodes.length === 1 &&
|
||||
n.firstChild.nodeType === 3))) {
|
||||
var objectStack = [{}];
|
||||
ol.format.GML.readGeometry(n, objectStack);
|
||||
return ol.proj.get(objectStack.pop().srsName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
@@ -59,7 +59,8 @@ ol.proj.EPSG3857.CODES = [
|
||||
'EPSG:102100',
|
||||
'EPSG:102113',
|
||||
'EPSG:900913',
|
||||
'urn:ogc:def:crs:EPSG:6.18:3:3857'
|
||||
'urn:ogc:def:crs:EPSG:6.18:3:3857',
|
||||
'http://www.opengis.net/gml/srs/epsg.xml#3857'
|
||||
];
|
||||
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ ol.source.FormatVector.prototype.readFeatures = function(source) {
|
||||
var features = format.readFeatures(source);
|
||||
var featureProjection = format.readProjection(source);
|
||||
var projection = this.getProjection();
|
||||
if (!goog.isNull(projection)) {
|
||||
if (!goog.isNull(projection) && !goog.isNull(featureProjection)) {
|
||||
if (!ol.proj.equivalent(featureProjection, projection)) {
|
||||
var transform = ol.proj.getTransform(featureProjection, projection);
|
||||
var i, ii;
|
||||
|
||||
Reference in New Issue
Block a user