diff --git a/examples/vector-wfs.html b/examples/vector-wfs.html new file mode 100644 index 0000000000..f7c85f0e5d --- /dev/null +++ b/examples/vector-wfs.html @@ -0,0 +1,56 @@ + + + + + + + + + + + WFS example + + + + + +
+ +
+
+
+
+
+ +
+ +
+

WFS example

+

Example of using WFS with a BBOX strategy.

+
+

See the vector-wfs.js source to see how this is done.

+
+
vector, WFS, bbox, loading, server
+
+
+
+   +
+
+ +
+ +
+ + + + + + + diff --git a/examples/vector-wfs.js b/examples/vector-wfs.js new file mode 100644 index 0000000000..22d722287e --- /dev/null +++ b/examples/vector-wfs.js @@ -0,0 +1,60 @@ +goog.require('ol.Map'); +goog.require('ol.View2D'); +goog.require('ol.format.GeoJSON'); +goog.require('ol.layer.Tile'); +goog.require('ol.layer.Vector'); +goog.require('ol.loadingstrategy'); +goog.require('ol.source.BingMaps'); +goog.require('ol.source.ServerVector'); +goog.require('ol.style.Stroke'); +goog.require('ol.style.Style'); +goog.require('ol.tilegrid.XYZ'); + +var loadFeatures = function(response) { + vectorSource.addFeatures(vectorSource.readFeatures(response)); +}; + +var vectorSource = new ol.source.ServerVector({ + format: new ol.format.GeoJSON(), + loader: function(extent, resolution, projection) { + var url = 'http://demo.opengeo.org/geoserver/wfs?service=WFS&' + + 'version=1.1.0&request=GetFeature&typename=osm:water_areas&' + + 'outputFormat=text/javascript&format_options=callback:loadFeatures' + + '&srsname=EPSG:3857&bbox=' + extent.join(','); + $.ajax({ + url: url, + dataType: 'jsonp' + }); + }, + strategy: ol.loadingstrategy.createTile(new ol.tilegrid.XYZ({ + maxZoom: 19 + })), + projection: 'EPSG:3857' +}); + +var vector = new ol.layer.Vector({ + source: vectorSource, + style: new ol.style.Style({ + stroke: new ol.style.Stroke({ + color: 'rgba(0, 0, 255, 1.0)', + width: 2 + }) + }) +}); + +var raster = new ol.layer.Tile({ + source: new ol.source.BingMaps({ + imagerySet: 'Aerial', + key: 'Ak-dzM4wZjSqTlzveKz5u0d4IQ4bRzVI309GxmkgSVr1ewS6iPSrOvOKhA-CJlm3' + }) +}); + +var map = new ol.Map({ + layers: [raster, vector], + target: document.getElementById('map'), + view: new ol.View2D({ + center: [-8908887.277395891, 5381918.072437216], + maxZoom: 19, + zoom: 12 + }) +}); diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 0b251f0257..36413713cf 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -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; +}; diff --git a/src/ol/proj/epsg3857projection.js b/src/ol/proj/epsg3857projection.js index 1137e4a343..7c7fb374d4 100644 --- a/src/ol/proj/epsg3857projection.js +++ b/src/ol/proj/epsg3857projection.js @@ -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' ]; diff --git a/src/ol/source/formatvectorsource.js b/src/ol/source/formatvectorsource.js index 3b3ad39fd6..b980d94b4c 100644 --- a/src/ol/source/formatvectorsource.js +++ b/src/ol/source/formatvectorsource.js @@ -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;