Merge remote-tracking branch 'upstream/master' into webgl-point

This commit is contained in:
Éric Lemoine
2014-11-03 15:02:22 +01:00
53 changed files with 2164 additions and 1024 deletions

View File

@@ -69,9 +69,6 @@ ol.control.Attribution = function(opt_options) {
var tipLabel = goog.isDef(options.tipLabel) ?
options.tipLabel : 'Attributions';
var tip = goog.dom.createDom(goog.dom.TagName.SPAN, {
'role' : 'tooltip'
}, tipLabel);
/**
* @private
@@ -96,10 +93,9 @@ ol.control.Attribution = function(opt_options) {
*/
this.labelSpan_ = label;
var button = goog.dom.createDom(goog.dom.TagName.BUTTON, {
'class': 'ol-has-tooltip',
'type': 'button'
'type': 'button',
'title': tipLabel
}, this.labelSpan_);
goog.dom.appendChild(button, tip);
var buttonHandler = new ol.pointer.PointerEventHandler(button);
this.registerDisposable(buttonHandler);
@@ -115,12 +111,12 @@ ol.control.Attribution = function(opt_options) {
this.blur();
}, false);
var element = goog.dom.createDom(goog.dom.TagName.DIV, {
'class': className + ' ' + ol.css.CLASS_UNSELECTABLE + ' ' +
ol.css.CLASS_CONTROL +
(this.collapsed_ && this.collapsible_ ? ' ol-collapsed' : '') +
(this.collapsible_ ? '' : ' ol-uncollapsible')
}, this.ulElement_, button);
var cssClasses = className + ' ' + ol.css.CLASS_UNSELECTABLE + ' ' +
ol.css.CLASS_CONTROL +
(this.collapsed_ && this.collapsible_ ? ' ol-collapsed' : '') +
(this.collapsible_ ? '' : ' ol-uncollapsible');
var element = goog.dom.createDom(goog.dom.TagName.DIV,
cssClasses, this.ulElement_, button);
goog.base(this, {
element: element,

View File

@@ -40,16 +40,11 @@ ol.control.FullScreen = function(opt_options) {
var tipLabel = goog.isDef(options.tipLabel) ?
options.tipLabel : 'Toggle full-screen';
var tip = goog.dom.createDom(goog.dom.TagName.SPAN, {
'role' : 'tooltip'
}, tipLabel);
var button = goog.dom.createDom(goog.dom.TagName.BUTTON, {
'class': this.cssClassName_ + '-' + goog.dom.fullscreen.isFullScreen() +
' ol-has-tooltip',
'type': 'button'
'class': this.cssClassName_ + '-' + goog.dom.fullscreen.isFullScreen(),
'type': 'button',
'title': tipLabel
});
goog.dom.appendChild(button, tip);
var buttonHandler = new ol.pointer.PointerEventHandler(button);
this.registerDisposable(buttonHandler);
goog.events.listen(buttonHandler,
@@ -69,7 +64,7 @@ ol.control.FullScreen = function(opt_options) {
this.handleFullScreenChange_, false, this);
var cssClasses = this.cssClassName_ + ' ' + ol.css.CLASS_UNSELECTABLE +
' ' + ol.css.CLASS_CONTROL +
' ' + ol.css.CLASS_CONTROL + ' ' +
(!goog.dom.fullscreen.isSupported() ? ol.css.CLASS_UNSUPPORTED : '');
var element = goog.dom.createDom(goog.dom.TagName.DIV, cssClasses, button);

View File

@@ -46,9 +46,7 @@ ol.control.MousePosition = function(opt_options) {
var className = goog.isDef(options.className) ?
options.className : 'ol-mouse-position';
var element = goog.dom.createDom(goog.dom.TagName.DIV, {
'class': className
});
var element = goog.dom.createDom(goog.dom.TagName.DIV, className);
goog.base(this, {
element: element,

View File

@@ -57,9 +57,6 @@ ol.control.OverviewMap = function(opt_options) {
var tipLabel = goog.isDef(options.tipLabel) ?
options.tipLabel : 'Overview map';
var tip = goog.dom.createDom(goog.dom.TagName.SPAN, {
'role' : 'tooltip'
}, tipLabel);
/**
* @private
@@ -83,10 +80,9 @@ ol.control.OverviewMap = function(opt_options) {
*/
this.labelSpan_ = label;
var button = goog.dom.createDom(goog.dom.TagName.BUTTON, {
'class': 'ol-has-tooltip',
'type': 'button'
'type': 'button',
'title': tipLabel
}, this.labelSpan_);
goog.dom.appendChild(button, tip);
var buttonHandler = new ol.pointer.PointerEventHandler(button);
this.registerDisposable(buttonHandler);
@@ -138,12 +134,12 @@ ol.control.OverviewMap = function(opt_options) {
});
this.ovmap_.addOverlay(this.boxOverlay_);
var element = goog.dom.createDom(goog.dom.TagName.DIV, {
'class': className + ' ' + ol.css.CLASS_UNSELECTABLE + ' ' +
ol.css.CLASS_CONTROL +
(this.collapsed_ && this.collapsible_ ? ' ol-collapsed' : '') +
(this.collapsible_ ? '' : ' ol-uncollapsible')
}, ovmapDiv, button);
var cssClasses = className + ' ' + ol.css.CLASS_UNSELECTABLE + ' ' +
ol.css.CLASS_CONTROL +
(this.collapsed_ && this.collapsible_ ? ' ol-collapsed' : '') +
(this.collapsible_ ? '' : ' ol-uncollapsible');
var element = goog.dom.createDom(goog.dom.TagName.DIV,
cssClasses, ovmapDiv, button);
goog.base(this, {
element: element,

View File

@@ -38,19 +38,16 @@ ol.control.Rotate = function(opt_options) {
* @private
*/
this.label_ = goog.dom.createDom(goog.dom.TagName.SPAN,
{ 'class': 'ol-compass' },
goog.isDef(options.label) ? options.label : '\u21E7');
'ol-compass', goog.isDef(options.label) ? options.label : '\u21E7');
var tipLabel = goog.isDef(options.tipLabel) ?
options.tipLabel : 'Reset rotation';
var tip = goog.dom.createDom(goog.dom.TagName.SPAN, {
'role' : 'tooltip'
}, tipLabel);
var button = goog.dom.createDom(goog.dom.TagName.BUTTON, {
'class': className + '-reset ol-has-tooltip',
'type' : 'button'
}, tip, this.label_);
'class': className + '-reset',
'type' : 'button',
'title': tipLabel
}, this.label_);
var handler = new ol.pointer.PointerEventHandler(button);
this.registerDisposable(handler);

View File

@@ -66,17 +66,15 @@ ol.control.ScaleLine = function(opt_options) {
* @private
* @type {Element}
*/
this.innerElement_ = goog.dom.createDom(goog.dom.TagName.DIV, {
'class': className + '-inner'
});
this.innerElement_ = goog.dom.createDom(goog.dom.TagName.DIV,
className + '-inner');
/**
* @private
* @type {Element}
*/
this.element_ = goog.dom.createDom(goog.dom.TagName.DIV, {
'class': className + ' ' + ol.css.CLASS_UNSELECTABLE
}, this.innerElement_);
this.element_ = goog.dom.createDom(goog.dom.TagName.DIV,
className + ' ' + ol.css.CLASS_UNSELECTABLE, this.innerElement_);
/**
* @private

View File

@@ -41,13 +41,11 @@ ol.control.Zoom = function(opt_options) {
var zoomOutTipLabel = goog.isDef(options.zoomOutTipLabel) ?
options.zoomOutTipLabel : 'Zoom out';
var tTipZoomIn = goog.dom.createDom(goog.dom.TagName.SPAN, {
'role' : 'tooltip'
}, zoomInTipLabel);
var inElement = goog.dom.createDom(goog.dom.TagName.BUTTON, {
'class': className + '-in ol-has-tooltip',
'type' : 'button'
}, tTipZoomIn, zoomInLabel);
'class': className + '-in',
'type' : 'button',
'title': zoomInTipLabel
}, zoomInLabel);
var inElementHandler = new ol.pointer.PointerEventHandler(inElement);
this.registerDisposable(inElementHandler);
@@ -65,13 +63,11 @@ ol.control.Zoom = function(opt_options) {
this.blur();
}, false);
var tTipsZoomOut = goog.dom.createDom(goog.dom.TagName.SPAN, {
'role' : 'tooltip'
}, zoomOutTipLabel);
var outElement = goog.dom.createDom(goog.dom.TagName.BUTTON, {
'class': className + '-out ol-has-tooltip',
'type' : 'button'
}, tTipsZoomOut, zoomOutLabel);
'class': className + '-out',
'type' : 'button',
'title': zoomOutTipLabel
}, zoomOutLabel);
var outElementHandler = new ol.pointer.PointerEventHandler(outElement);
this.registerDisposable(outElementHandler);

View File

@@ -35,14 +35,10 @@ ol.control.ZoomToExtent = function(opt_options) {
var tipLabel = goog.isDef(options.tipLabel) ?
options.tipLabel : 'Fit to extent';
var tip = goog.dom.createDom(goog.dom.TagName.SPAN, {
'role' : 'tooltip'
}, tipLabel);
var button = goog.dom.createDom(goog.dom.TagName.BUTTON, {
'class': 'ol-has-tooltip',
'type': 'button'
'type': 'button',
'title': tipLabel
});
goog.dom.appendChild(button, tip);
var buttonHandler = new ol.pointer.PointerEventHandler(button);
this.registerDisposable(buttonHandler);

218
src/ol/format/gml/gml2.js Normal file
View File

@@ -0,0 +1,218 @@
goog.provide('ol.format.GML2');
goog.require('goog.asserts');
goog.require('goog.dom');
goog.require('goog.dom.NodeType');
goog.require('goog.object');
goog.require('ol.extent');
goog.require('ol.format.GML');
goog.require('ol.format.GMLBase');
goog.require('ol.format.XSD');
goog.require('ol.proj');
goog.require('ol.xml');
/**
* @classdesc
* Feature format for reading and writing data in the GML format,
* version 2.1.2.
*
* @constructor
* @param {olx.format.GMLOptions=} opt_options Optional configuration object.
* @extends {ol.format.GMLBase}
* @api
*/
ol.format.GML2 = function(opt_options) {
var options = /** @type {olx.format.GMLOptions} */
(goog.isDef(opt_options) ? opt_options : {});
goog.base(this, options);
/**
* @inheritDoc
*/
this.schemaLocation = goog.isDef(options.schemaLocation) ?
options.schemaLocation : ol.format.GML2.schemaLocation_;
};
goog.inherits(ol.format.GML2, ol.format.GMLBase);
/**
* @const
* @type {string}
* @private
*/
ol.format.GML2.schemaLocation_ = 'http://www.opengis.net/gml ' +
'http://schemas.opengis.net/gml/2.1.2/feature.xsd';
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
* @return {Array.<number>|undefined} Flat coordinates.
*/
ol.format.GML2.prototype.readFlatCoordinates_ = function(node, objectStack) {
var s = ol.xml.getAllTextContent(node, false).replace(/^\s*|\s*$/g, '');
var context = objectStack[0];
goog.asserts.assert(goog.isObject(context));
var containerSrs = goog.object.get(context, 'srsName');
var containerDimension = node.parentNode.getAttribute('srsDimension');
var axisOrientation = 'enu';
if (!goog.isNull(containerSrs)) {
var proj = ol.proj.get(containerSrs);
axisOrientation = proj.getAxisOrientation();
}
var coords = s.split(/[\s,]+/);
// The "dimension" attribute is from the GML 3.0.1 spec.
var dim = 2;
if (!goog.isNull(node.getAttribute('srsDimension'))) {
dim = ol.format.XSD.readNonNegativeIntegerString(
node.getAttribute('srsDimension'));
} else if (!goog.isNull(node.getAttribute('dimension'))) {
dim = ol.format.XSD.readNonNegativeIntegerString(
node.getAttribute('dimension'));
} else if (!goog.isNull(containerDimension)) {
dim = ol.format.XSD.readNonNegativeIntegerString(containerDimension);
}
var x, y, z;
var flatCoordinates = [];
for (var i = 0, ii = coords.length; i < ii; i += dim) {
x = parseFloat(coords[i]);
y = parseFloat(coords[i + 1]);
z = (dim === 3) ? parseFloat(coords[i + 2]) : 0;
if (axisOrientation.substr(0, 2) === 'en') {
flatCoordinates.push(x, y, z);
} else {
flatCoordinates.push(y, x, z);
}
}
return flatCoordinates;
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
* @return {ol.Extent|undefined} Envelope.
*/
ol.format.GML2.prototype.readBox_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'Box');
var flatCoordinates = ol.xml.pushParseAndPop(
/** @type {Array.<number>} */ ([null]),
this.BOX_PARSERS_, node, objectStack, this);
return ol.extent.createOrUpdate(flatCoordinates[1][0],
flatCoordinates[1][1], flatCoordinates[1][3],
flatCoordinates[1][4]);
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
*/
ol.format.GML2.prototype.innerBoundaryIsParser_ =
function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'innerBoundaryIs');
var flatLinearRing = ol.xml.pushParseAndPop(
/** @type {Array.<number>|undefined} */ (undefined),
this.RING_PARSERS, node, objectStack, this);
if (goog.isDef(flatLinearRing)) {
var flatLinearRings = /** @type {Array.<Array.<number>>} */
(objectStack[objectStack.length - 1]);
goog.asserts.assert(goog.isArray(flatLinearRings));
goog.asserts.assert(flatLinearRings.length > 0);
flatLinearRings.push(flatLinearRing);
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
*/
ol.format.GML2.prototype.outerBoundaryIsParser_ =
function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'outerBoundaryIs');
var flatLinearRing = ol.xml.pushParseAndPop(
/** @type {Array.<number>|undefined} */ (undefined),
this.RING_PARSERS, node, objectStack, this);
if (goog.isDef(flatLinearRing)) {
var flatLinearRings = /** @type {Array.<Array.<number>>} */
(objectStack[objectStack.length - 1]);
goog.asserts.assert(goog.isArray(flatLinearRings));
goog.asserts.assert(flatLinearRings.length > 0);
flatLinearRings[0] = flatLinearRing;
}
};
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GML2.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS_ = Object({
'http://www.opengis.net/gml' : {
'coordinates': ol.xml.makeReplacer(
ol.format.GML2.prototype.readFlatCoordinates_)
}
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GML2.prototype.FLAT_LINEAR_RINGS_PARSERS_ = Object({
'http://www.opengis.net/gml' : {
'innerBoundaryIs': ol.format.GML2.prototype.innerBoundaryIsParser_,
'outerBoundaryIs': ol.format.GML2.prototype.outerBoundaryIsParser_
}
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GML2.prototype.BOX_PARSERS_ = Object({
'http://www.opengis.net/gml' : {
'coordinates': ol.xml.makeArrayPusher(
ol.format.GML2.prototype.readFlatCoordinates_)
}
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GML2.prototype.GEOMETRY_PARSERS_ = Object({
'http://www.opengis.net/gml' : {
'Point': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPoint),
'MultiPoint': ol.xml.makeReplacer(
ol.format.GMLBase.prototype.readMultiPoint),
'LineString': ol.xml.makeReplacer(
ol.format.GMLBase.prototype.readLineString),
'MultiLineString': ol.xml.makeReplacer(
ol.format.GMLBase.prototype.readMultiLineString),
'LinearRing' : ol.xml.makeReplacer(
ol.format.GMLBase.prototype.readLinearRing),
'Polygon': ol.xml.makeReplacer(ol.format.GMLBase.prototype.readPolygon),
'MultiPolygon': ol.xml.makeReplacer(
ol.format.GMLBase.prototype.readMultiPolygon),
'Box': ol.xml.makeReplacer(ol.format.GML2.prototype.readBox_)
}
});

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,564 @@
// FIXME Envelopes should not be treated as geometries! readEnvelope_ is part
// of GEOMETRY_PARSERS_ and methods using GEOMETRY_PARSERS_ do not expect
// envelopes/extents, only geometries!
goog.provide('ol.format.GMLBase');
goog.require('goog.asserts');
goog.require('goog.dom');
goog.require('goog.dom.NodeType');
goog.require('goog.object');
goog.require('goog.string');
goog.require('ol.Feature');
goog.require('ol.array');
goog.require('ol.format.Feature');
goog.require('ol.format.XMLFeature');
goog.require('ol.geom.Geometry');
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.proj');
goog.require('ol.xml');
/**
* @classdesc
* Abstract base class; normally only used for creating subclasses and not
* instantiated in apps.
* Feature base format for reading and writing data in the GML format.
* This class cannot be instantiate, it contains only base content that
* is shared with versioned format classes ol.format.GML2 and
* ol.format.GML3.
*
* @constructor
* @param {olx.format.GMLOptions=} opt_options
* Optional configuration object.
* @extends {ol.format.XMLFeature}
* @api
*/
ol.format.GMLBase = function(opt_options) {
var options = /** @type {olx.format.GMLOptions} */
(goog.isDef(opt_options) ? opt_options : {});
/**
* @protected
* @type {string}
*/
this.featureType = options.featureType;
/**
* @protected
* @type {string}
*/
this.featureNS = options.featureNS;
/**
* @protected
* @type {string}
*/
this.srsName = options.srsName;
/**
* @protected
* @type {string}
*/
this.schemaLocation = '';
goog.base(this);
};
goog.inherits(ol.format.GMLBase, ol.format.XMLFeature);
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @return {Array.<ol.Feature>} Features.
* @private
*/
ol.format.GMLBase.prototype.readFeatures_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
var localName = ol.xml.getLocalName(node);
var features;
if (localName == 'FeatureCollection') {
features = ol.xml.pushParseAndPop(null,
this.FEATURE_COLLECTION_PARSERS, node,
objectStack, this);
} else if (localName == 'featureMembers' || localName == 'featureMember') {
var context = objectStack[0];
goog.asserts.assert(goog.isObject(context));
var featureType = goog.object.get(context, 'featureType');
if (!goog.isDef(featureType) && !goog.isNull(node.firstElementChild)) {
var member = node.firstElementChild;
featureType = member.nodeName.split(':').pop();
goog.object.set(context, 'featureType', featureType);
goog.object.set(context, 'featureNS', member.namespaceURI);
}
var parsers = {};
var parsersNS = {};
parsers[featureType] = (localName == 'featureMembers') ?
ol.xml.makeArrayPusher(this.readFeature_, this) :
ol.xml.makeReplacer(this.readFeature_, this);
parsersNS[goog.object.get(context, 'featureNS')] = parsers;
features = ol.xml.pushParseAndPop([], parsersNS, node, objectStack);
}
if (!goog.isDef(features)) {
features = [];
}
return features;
};
/**
* @type {Object.<string, Object.<string, Object>>}
*/
ol.format.GMLBase.prototype.FEATURE_COLLECTION_PARSERS = Object({
'http://www.opengis.net/gml': {
'featureMember': ol.xml.makeArrayPusher(
ol.format.GMLBase.prototype.readFeatures_),
'featureMembers': ol.xml.makeReplacer(
ol.format.GMLBase.prototype.readFeatures_)
}
});
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @return {ol.geom.Geometry|undefined} Geometry.
*/
ol.format.GMLBase.prototype.readGeometryElement = function(node, objectStack) {
var context = objectStack[0];
goog.asserts.assert(goog.isObject(context));
goog.object.set(context, 'srsName',
node.firstElementChild.getAttribute('srsName'));
var geometry = ol.xml.pushParseAndPop(/** @type {ol.geom.Geometry} */(null),
this.GEOMETRY_PARSERS_, node, objectStack, this);
if (goog.isDefAndNotNull(geometry)) {
return /** @type {ol.geom.Geometry} */ (
ol.format.Feature.transformWithOptions(geometry, false, context));
} else {
return undefined;
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @return {ol.Feature} Feature.
* @private
*/
ol.format.GMLBase.prototype.readFeature_ = function(node, objectStack) {
var n;
var fid = node.getAttribute('fid') ||
ol.xml.getAttributeNS(node, 'http://www.opengis.net/gml', 'id');
var values = {}, geometryName;
for (n = node.firstElementChild; !goog.isNull(n);
n = n.nextElementSibling) {
var localName = ol.xml.getLocalName(n);
// Assume attribute elements have one child node and that the child
// is a text node. Otherwise assume it is a geometry node.
if (n.childNodes.length === 0 ||
(n.childNodes.length === 1 &&
n.firstChild.nodeType === 3)) {
var value = ol.xml.getAllTextContent(n, false);
if (goog.string.isEmpty(value)) {
value = undefined;
}
values[localName] = value;
} else {
// boundedBy is an extent and must not be considered as a geometry
if (localName !== 'boundedBy') {
geometryName = localName;
}
values[localName] = this.readGeometryElement(n, objectStack);
}
}
var feature = new ol.Feature(values);
if (goog.isDef(geometryName)) {
feature.setGeometryName(geometryName);
}
if (fid) {
feature.setId(fid);
}
return feature;
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @return {ol.geom.Point|undefined} Point.
*/
ol.format.GMLBase.prototype.readPoint = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'Point');
var flatCoordinates =
this.readFlatCoordinatesFromNode_(node, objectStack);
if (goog.isDefAndNotNull(flatCoordinates)) {
var point = new ol.geom.Point(null);
goog.asserts.assert(flatCoordinates.length == 3);
point.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates);
return point;
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @return {ol.geom.MultiPoint|undefined} MultiPoint.
*/
ol.format.GMLBase.prototype.readMultiPoint = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'MultiPoint');
var coordinates = ol.xml.pushParseAndPop(
/** @type {Array.<Array.<number>>} */ ([]),
this.MULTIPOINT_PARSERS_, node, objectStack, this);
if (goog.isDef(coordinates)) {
return new ol.geom.MultiPoint(coordinates);
} else {
return undefined;
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @return {ol.geom.MultiLineString|undefined} MultiLineString.
*/
ol.format.GMLBase.prototype.readMultiLineString = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'MultiLineString');
var lineStrings = ol.xml.pushParseAndPop(
/** @type {Array.<ol.geom.LineString>} */ ([]),
this.MULTILINESTRING_PARSERS_, node, objectStack, this);
if (goog.isDef(lineStrings)) {
var multiLineString = new ol.geom.MultiLineString(null);
multiLineString.setLineStrings(lineStrings);
return multiLineString;
} else {
return undefined;
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @return {ol.geom.MultiPolygon|undefined} MultiPolygon.
*/
ol.format.GMLBase.prototype.readMultiPolygon = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'MultiPolygon');
var polygons = ol.xml.pushParseAndPop(
/** @type {Array.<ol.geom.Polygon>} */ ([]),
this.MULTIPOLYGON_PARSERS_, node, objectStack, this);
if (goog.isDef(polygons)) {
var multiPolygon = new ol.geom.MultiPolygon(null);
multiPolygon.setPolygons(polygons);
return multiPolygon;
} else {
return undefined;
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
*/
ol.format.GMLBase.prototype.pointMemberParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'pointMember' ||
node.localName == 'pointMembers');
ol.xml.parseNode(this.POINTMEMBER_PARSERS_,
node, objectStack, this);
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
*/
ol.format.GMLBase.prototype.lineStringMemberParser_ =
function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'lineStringMember' ||
node.localName == 'lineStringMembers');
ol.xml.parseNode(this.LINESTRINGMEMBER_PARSERS_,
node, objectStack, this);
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
*/
ol.format.GMLBase.prototype.polygonMemberParser_ =
function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'polygonMember' ||
node.localName == 'polygonMembers');
ol.xml.parseNode(this.POLYGONMEMBER_PARSERS_, node,
objectStack, this);
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @return {ol.geom.LineString|undefined} LineString.
*/
ol.format.GMLBase.prototype.readLineString = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'LineString');
var flatCoordinates =
this.readFlatCoordinatesFromNode_(node, objectStack);
if (goog.isDefAndNotNull(flatCoordinates)) {
var lineString = new ol.geom.LineString(null);
lineString.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates);
return lineString;
} else {
return undefined;
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
* @return {Array.<number>|undefined} LinearRing flat coordinates.
*/
ol.format.GMLBase.prototype.readFlatLinearRing_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'LinearRing');
var ring = ol.xml.pushParseAndPop(/** @type {Array.<number>} */(null),
this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node,
objectStack, this);
if (goog.isDefAndNotNull(ring)) {
return ring;
} else {
return undefined;
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @return {ol.geom.LinearRing|undefined} LinearRing.
*/
ol.format.GMLBase.prototype.readLinearRing = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'LinearRing');
var flatCoordinates =
this.readFlatCoordinatesFromNode_(node, objectStack);
if (goog.isDef(flatCoordinates)) {
var ring = new ol.geom.LinearRing(null);
ring.setFlatCoordinates(ol.geom.GeometryLayout.XYZ, flatCoordinates);
return ring;
} else {
return undefined;
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @return {ol.geom.Polygon|undefined} Polygon.
*/
ol.format.GMLBase.prototype.readPolygon = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'Polygon');
var flatLinearRings = ol.xml.pushParseAndPop(
/** @type {Array.<Array.<number>>} */ ([null]),
this.FLAT_LINEAR_RINGS_PARSERS_, node, objectStack, this);
if (goog.isDef(flatLinearRings) &&
!goog.isNull(flatLinearRings[0])) {
var polygon = new ol.geom.Polygon(null);
var flatCoordinates = flatLinearRings[0];
var ends = [flatCoordinates.length];
var i, ii;
for (i = 1, ii = flatLinearRings.length; i < ii; ++i) {
ol.array.safeExtend(flatCoordinates, flatLinearRings[i]);
ends.push(flatCoordinates.length);
}
polygon.setFlatCoordinates(
ol.geom.GeometryLayout.XYZ, flatCoordinates, ends);
return polygon;
} else {
return undefined;
}
};
/**
* @param {Node} node Node.
* @param {Array.<*>} objectStack Object stack.
* @private
* @return {Array.<number>} Flat coordinates.
*/
ol.format.GMLBase.prototype.readFlatCoordinatesFromNode_ =
function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
return /** @type {Array.<number>} */ (ol.xml.pushParseAndPop(
null,
this.GEOMETRY_FLAT_COORDINATES_PARSERS_, node,
objectStack, this));
};
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GMLBase.prototype.MULTIPOINT_PARSERS_ = Object({
'http://www.opengis.net/gml' : {
'pointMember': ol.xml.makeArrayPusher(
ol.format.GMLBase.prototype.pointMemberParser_),
'pointMembers': ol.xml.makeArrayPusher(
ol.format.GMLBase.prototype.pointMemberParser_)
}
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GMLBase.prototype.MULTILINESTRING_PARSERS_ = Object({
'http://www.opengis.net/gml' : {
'lineStringMember': ol.xml.makeArrayPusher(
ol.format.GMLBase.prototype.lineStringMemberParser_),
'lineStringMembers': ol.xml.makeArrayPusher(
ol.format.GMLBase.prototype.lineStringMemberParser_)
}
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GMLBase.prototype.MULTIPOLYGON_PARSERS_ = Object({
'http://www.opengis.net/gml' : {
'polygonMember': ol.xml.makeArrayPusher(
ol.format.GMLBase.prototype.polygonMemberParser_),
'polygonMembers': ol.xml.makeArrayPusher(
ol.format.GMLBase.prototype.polygonMemberParser_)
}
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GMLBase.prototype.POINTMEMBER_PARSERS_ = Object({
'http://www.opengis.net/gml' : {
'Point': ol.xml.makeArrayPusher(
ol.format.GMLBase.prototype.readFlatCoordinatesFromNode_)
}
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GMLBase.prototype.LINESTRINGMEMBER_PARSERS_ = Object({
'http://www.opengis.net/gml' : {
'LineString': ol.xml.makeArrayPusher(
ol.format.GMLBase.prototype.readLineString)
}
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @private
*/
ol.format.GMLBase.prototype.POLYGONMEMBER_PARSERS_ = Object({
'http://www.opengis.net/gml' : {
'Polygon': ol.xml.makeArrayPusher(
ol.format.GMLBase.prototype.readPolygon)
}
});
/**
* @const
* @type {Object.<string, Object.<string, ol.xml.Parser>>}
* @protected
*/
ol.format.GMLBase.prototype.RING_PARSERS = Object({
'http://www.opengis.net/gml' : {
'LinearRing': ol.xml.makeReplacer(
ol.format.GMLBase.prototype.readFlatLinearRing_)
}
});
/**
* @inheritDoc
*/
ol.format.GMLBase.prototype.readGeometryFromNode =
function(node, opt_options) {
var geometry = this.readGeometryElement(node,
[this.getReadOptions(node, goog.isDef(opt_options) ? opt_options : {})]);
return goog.isDef(geometry) ? geometry : null;
};
/**
* Read all features from a GML FeatureCollection.
*
* @function
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
* @param {olx.format.ReadOptions=} opt_options Options.
* @return {Array.<ol.Feature>} Features.
* @api stable
*/
ol.format.GMLBase.prototype.readFeatures;
/**
* @inheritDoc
*/
ol.format.GMLBase.prototype.readFeaturesFromNode =
function(node, opt_options) {
var options = {
'featureType': this.featureType,
'featureNS': this.featureNS
};
if (goog.isDef(opt_options)) {
goog.object.extend(options, this.getReadOptions(node, opt_options));
}
return this.readFeatures_(node, [options]);
};
/**
* @inheritDoc
*/
ol.format.GMLBase.prototype.readProjectionFromNode = function(node) {
return ol.proj.get(goog.isDef(this.srsName_) ? this.srsName_ :
node.firstElementChild.getAttribute('srsName'));
};

View File

@@ -100,7 +100,7 @@ ol.format.GPX.parseLink_ = function(node, objectStack) {
if (!goog.isNull(href)) {
goog.object.set(values, 'link', href);
}
ol.xml.parse(ol.format.GPX.LINK_PARSERS_, node, objectStack);
ol.xml.parseNode(ol.format.GPX.LINK_PARSERS_, node, objectStack);
};
@@ -164,7 +164,7 @@ ol.format.GPX.parseTrkSeg_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'trkseg');
var values = /** @type {Object} */ (objectStack[objectStack.length - 1]);
ol.xml.parse(ol.format.GPX.TRKSEG_PARSERS_, node, objectStack);
ol.xml.parseNode(ol.format.GPX.TRKSEG_PARSERS_, node, objectStack);
var flatCoordinates = /** @type {Array.<number>} */
(goog.object.get(values, 'flatCoordinates'));
var ends = /** @type {Array.<number>} */ (goog.object.get(values, 'ends'));

View File

@@ -1000,7 +1000,7 @@ ol.format.KML.DataParser_ = function(node, objectStack) {
ol.format.KML.ExtendedDataParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'ExtendedData');
ol.xml.parse(ol.format.KML.EXTENDED_DATA_PARSERS_, node, objectStack);
ol.xml.parseNode(ol.format.KML.EXTENDED_DATA_PARSERS_, node, objectStack);
};
@@ -1066,7 +1066,7 @@ ol.format.KML.PlacemarkStyleMapParser_ = function(node, objectStack) {
ol.format.KML.SchemaDataParser_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT);
goog.asserts.assert(node.localName == 'SchemaData');
ol.xml.parse(ol.format.KML.SCHEMA_DATA_PARSERS_, node, objectStack);
ol.xml.parseNode(ol.format.KML.SCHEMA_DATA_PARSERS_, node, objectStack);
};
@@ -1655,7 +1655,7 @@ ol.format.KML.prototype.readName = function(source) {
} else if (ol.xml.isNode(source)) {
return this.readNameFromNode(/** @type {Node} */ (source));
} else if (goog.isString(source)) {
var doc = ol.xml.load(source);
var doc = ol.xml.parse(source);
return this.readNameFromDocument(doc);
} else {
goog.asserts.fail();

View File

@@ -3,7 +3,8 @@ goog.provide('ol.format.WFS');
goog.require('goog.asserts');
goog.require('goog.dom.NodeType');
goog.require('goog.object');
goog.require('ol.format.GML');
goog.require('ol.format.GML3');
goog.require('ol.format.GMLBase');
goog.require('ol.format.XMLFeature');
goog.require('ol.format.XSD');
goog.require('ol.geom.Geometry');
@@ -15,8 +16,9 @@ goog.require('ol.xml');
/**
* @classdesc
* Feature format for reading and writing data in the WFS format.
* Currently only supports WFS version 1.1.0.
* Also see {@link ol.format.GML} which is used by this format.
* By default, supports WFS version 1.1.0. You can pass a GML format
* as option if you want to read a WFS that contains GML2 (WFS 1.0.0).
* Also see {@link ol.format.GMLBase} which is used by this format.
*
* @constructor
* @param {olx.format.WFSOptions=} opt_options
@@ -40,6 +42,13 @@ ol.format.WFS = function(opt_options) {
*/
this.featureNS_ = options.featureNS;
/**
* @private
* @type {ol.format.GMLBase}
*/
this.gmlFormat_ = goog.isDef(options.gmlFormat) ?
options.gmlFormat : new ol.format.GML3();
/**
* @private
* @type {string}
@@ -119,7 +128,8 @@ ol.format.WFS.prototype.readFeaturesFromNode = function(node, opt_options) {
goog.isDef(opt_options) ? opt_options : {}));
var objectStack = [context];
var features = ol.xml.pushParseAndPop([],
ol.format.GML.FEATURE_COLLECTION_PARSERS, node, objectStack);
this.gmlFormat_.FEATURE_COLLECTION_PARSERS, node,
objectStack, this.gmlFormat_);
if (!goog.isDef(features)) {
features = [];
}
@@ -139,7 +149,7 @@ ol.format.WFS.prototype.readTransactionResponse = function(source) {
} else if (ol.xml.isNode(source)) {
return this.readTransactionResponseFromNode(/** @type {Node} */ (source));
} else if (goog.isString(source)) {
var doc = ol.xml.load(source);
var doc = ol.xml.parse(source);
return this.readTransactionResponseFromDocument(doc);
} else {
goog.asserts.fail();
@@ -162,7 +172,7 @@ ol.format.WFS.prototype.readFeatureCollectionMetadata = function(source) {
return this.readFeatureCollectionMetadataFromNode(
/** @type {Node} */ (source));
} else if (goog.isString(source)) {
var doc = ol.xml.load(source);
var doc = ol.xml.parse(source);
return this.readFeatureCollectionMetadataFromDocument(doc);
} else {
goog.asserts.fail();
@@ -196,7 +206,7 @@ ol.format.WFS.prototype.readFeatureCollectionMetadataFromDocument =
ol.format.WFS.FEATURE_COLLECTION_PARSERS_ = {
'http://www.opengis.net/gml': {
'boundedBy': ol.xml.makeObjectPropertySetter(
ol.format.GML.readGeometry, 'bounds')
ol.format.GMLBase.prototype.readGeometryElement, 'bounds')
}
};
@@ -215,7 +225,7 @@ ol.format.WFS.prototype.readFeatureCollectionMetadataFromNode = function(node) {
goog.object.set(result, 'numberOfFeatures', value);
return ol.xml.pushParseAndPop(
/** @type {ol.format.WFS.FeatureCollectionMetadata} */ (result),
ol.format.WFS.FEATURE_COLLECTION_PARSERS_, node, []);
ol.format.WFS.FEATURE_COLLECTION_PARSERS_, node, [], this.gmlFormat_);
};
@@ -268,7 +278,7 @@ ol.format.WFS.OGC_FID_PARSERS_ = {
* @private
*/
ol.format.WFS.fidParser_ = function(node, objectStack) {
ol.xml.parse(ol.format.WFS.OGC_FID_PARSERS_, node, objectStack);
ol.xml.parseNode(ol.format.WFS.OGC_FID_PARSERS_, node, objectStack);
};
@@ -363,7 +373,7 @@ ol.format.WFS.writeFeature_ = function(node, feature, objectStack) {
var featureNS = goog.object.get(context, 'featureNS');
var child = ol.xml.createElementNS(featureNS, featureType);
node.appendChild(child);
ol.format.GML.writeFeature(child, feature, objectStack);
ol.format.GML3.prototype.writeFeatureElement(child, feature, objectStack);
};
@@ -457,7 +467,8 @@ ol.format.WFS.writeProperty_ = function(node, pair, objectStack) {
var value = ol.xml.createElementNS('http://www.opengis.net/wfs', 'Value');
node.appendChild(value);
if (pair.value instanceof ol.geom.Geometry) {
ol.format.GML.writeGeometry(value, pair.value, objectStack);
ol.format.GML3.prototype.writeGeometryElement(value,
pair.value, objectStack);
} else {
ol.format.XSD.writeStringTextNode(value, pair.value);
}
@@ -564,7 +575,7 @@ ol.format.WFS.writeOgcBBOX_ = function(node, bbox, objectStack) {
var bboxNode = ol.xml.createElementNS('http://www.opengis.net/ogc', 'BBOX');
node.appendChild(bboxNode);
ol.format.WFS.writeOgcPropertyName_(bboxNode, geometryName, objectStack);
ol.format.GML.writeGeometry(bboxNode, bbox, objectStack);
ol.format.GML3.prototype.writeGeometryElement(bboxNode, bbox, objectStack);
};
@@ -746,7 +757,7 @@ ol.format.WFS.prototype.readProjectionFromNode = function(node) {
(n.childNodes.length === 1 &&
n.firstChild.nodeType === 3))) {
var objectStack = [{}];
ol.format.GML.readGeometry(n, objectStack);
this.gmlFormat_.readGeometryElement(n, objectStack);
return ol.proj.get(objectStack.pop().srsName);
}
}

View File

@@ -602,7 +602,7 @@ ol.format.WKT.Parser.prototype.parseGeometry_ = function() {
return new ctor(coordinates);
}
}
this.raiseError_();
throw new Error(this.formatErrorMessage_());
};
@@ -622,7 +622,7 @@ ol.format.WKT.Parser.prototype.parseGeometryCollectionText_ = function() {
} else if (this.isEmptyGeometry_()) {
return [];
}
this.raiseError_();
throw new Error(this.formatErrorMessage_());
};
@@ -639,7 +639,7 @@ ol.format.WKT.Parser.prototype.parsePointText_ = function() {
} else if (this.isEmptyGeometry_()) {
return null;
}
this.raiseError_();
throw new Error(this.formatErrorMessage_());
};
@@ -656,7 +656,7 @@ ol.format.WKT.Parser.prototype.parseLineStringText_ = function() {
} else if (this.isEmptyGeometry_()) {
return [];
}
this.raiseError_();
throw new Error(this.formatErrorMessage_());
};
@@ -673,7 +673,7 @@ ol.format.WKT.Parser.prototype.parsePolygonText_ = function() {
} else if (this.isEmptyGeometry_()) {
return [];
}
this.raiseError_();
throw new Error(this.formatErrorMessage_());
};
@@ -695,7 +695,7 @@ ol.format.WKT.Parser.prototype.parseMultiPointText_ = function() {
} else if (this.isEmptyGeometry_()) {
return [];
}
this.raiseError_();
throw new Error(this.formatErrorMessage_());
};
@@ -713,7 +713,7 @@ ol.format.WKT.Parser.prototype.parseMultiLineStringText_ = function() {
} else if (this.isEmptyGeometry_()) {
return [];
}
this.raiseError_();
throw new Error(this.formatErrorMessage_());
};
@@ -730,7 +730,7 @@ ol.format.WKT.Parser.prototype.parseMultiPolygonText_ = function() {
} else if (this.isEmptyGeometry_()) {
return [];
}
this.raiseError_();
throw new Error(this.formatErrorMessage_());
};
@@ -751,7 +751,7 @@ ol.format.WKT.Parser.prototype.parsePoint_ = function() {
if (coordinates.length == this.dimension_) {
return coordinates;
}
this.raiseError_();
throw new Error(this.formatErrorMessage_());
};
@@ -822,12 +822,13 @@ ol.format.WKT.Parser.prototype.isEmptyGeometry_ = function() {
/**
* Create an error message for an unexpected token error.
* @return {string} Error message.
* @private
*/
ol.format.WKT.Parser.prototype.raiseError_ = function() {
throw new Error('Unexpected `' + this.token_.value +
'` at position ' + this.token_.position +
' in `' + this.lexer_.wkt + '`');
ol.format.WKT.Parser.prototype.formatErrorMessage_ = function() {
return 'Unexpected `' + this.token_.value + '` at position ' +
this.token_.position + ' in `' + this.lexer_.wkt + '`';
};

View File

@@ -43,7 +43,7 @@ ol.format.XMLFeature.prototype.readFeature = function(source, opt_options) {
} else if (ol.xml.isNode(source)) {
return this.readFeatureFromNode(/** @type {Node} */ (source), opt_options);
} else if (goog.isString(source)) {
var doc = ol.xml.load(source);
var doc = ol.xml.parse(source);
return this.readFeatureFromDocument(doc, opt_options);
} else {
goog.asserts.fail();
@@ -86,7 +86,7 @@ ol.format.XMLFeature.prototype.readFeatures = function(source, opt_options) {
} else if (ol.xml.isNode(source)) {
return this.readFeaturesFromNode(/** @type {Node} */ (source), opt_options);
} else if (goog.isString(source)) {
var doc = ol.xml.load(source);
var doc = ol.xml.parse(source);
return this.readFeaturesFromDocument(doc, opt_options);
} else {
goog.asserts.fail();
@@ -134,7 +134,7 @@ ol.format.XMLFeature.prototype.readGeometry = function(source, opt_options) {
} else if (ol.xml.isNode(source)) {
return this.readGeometryFromNode(/** @type {Node} */ (source), opt_options);
} else if (goog.isString(source)) {
var doc = ol.xml.load(source);
var doc = ol.xml.parse(source);
return this.readGeometryFromDocument(doc, opt_options);
} else {
goog.asserts.fail();
@@ -170,7 +170,7 @@ ol.format.XMLFeature.prototype.readProjection = function(source) {
} else if (ol.xml.isNode(source)) {
return this.readProjectionFromNode(/** @type {Node} */ (source));
} else if (goog.isString(source)) {
var doc = ol.xml.load(source);
var doc = ol.xml.parse(source);
return this.readProjectionFromDocument(doc);
} else {
goog.asserts.fail();

View File

@@ -25,7 +25,7 @@ ol.format.XML.prototype.read = function(source) {
} else if (ol.xml.isNode(source)) {
return this.readFromNode(/** @type {Node} */ (source));
} else if (goog.isString(source)) {
var doc = ol.xml.load(source);
var doc = ol.xml.parse(source);
return this.readFromDocument(doc);
} else {
goog.asserts.fail();

View File

@@ -20,9 +20,10 @@ goog.require('ol.extent');
* @param {Array.<ol.Attribution>} attributions Attributions.
* @param {string} src Image source URI.
* @param {?string} crossOrigin Cross origin.
* @param {ol.ImageLoadFunctionType} imageLoadFunction Image load function.
*/
ol.Image =
function(extent, resolution, pixelRatio, attributions, src, crossOrigin) {
ol.Image = function(extent, resolution, pixelRatio, attributions, src,
crossOrigin, imageLoadFunction) {
goog.base(this, extent, resolution, pixelRatio, ol.ImageState.IDLE,
attributions);
@@ -59,6 +60,13 @@ ol.Image =
* @type {ol.ImageState}
*/
this.state = ol.ImageState.IDLE;
/**
* @private
* @type {ol.ImageLoadFunctionType}
*/
this.imageLoadFunction_ = imageLoadFunction;
};
goog.inherits(ol.Image, ol.ImageBase);
@@ -66,8 +74,9 @@ goog.inherits(ol.Image, ol.ImageBase);
/**
* @param {Object=} opt_context Object.
* @return {HTMLCanvasElement|Image|HTMLVideoElement} Image.
* @api
*/
ol.Image.prototype.getImageElement = function(opt_context) {
ol.Image.prototype.getImage = function(opt_context) {
if (goog.isDef(opt_context)) {
var image;
var key = goog.getUid(opt_context);
@@ -126,7 +135,7 @@ ol.Image.prototype.load = function() {
goog.events.listenOnce(this.image_, goog.events.EventType.LOAD,
this.handleImageLoad_, false, this)
];
this.image_.src = this.src_;
this.imageLoadFunction_(this, this.src_);
}
};

View File

@@ -95,7 +95,7 @@ ol.ImageBase.prototype.getExtent = function() {
* @param {Object=} opt_context Object.
* @return {HTMLCanvasElement|Image|HTMLVideoElement} Image.
*/
ol.ImageBase.prototype.getImageElement = goog.abstractMethod;
ol.ImageBase.prototype.getImage = goog.abstractMethod;
/**

View File

@@ -33,6 +33,6 @@ goog.inherits(ol.ImageCanvas, ol.ImageBase);
/**
* @inheritDoc
*/
ol.ImageCanvas.prototype.getImageElement = function(opt_context) {
ol.ImageCanvas.prototype.getImage = function(opt_context) {
return this.canvas_;
};

View File

@@ -0,0 +1,21 @@
goog.provide('ol.ImageLoadFunctionType');
/**
* A function that takes an {@link ol.Image} for the image and a `{string}` for
* the src as arguments. It is supposed to make it so the underlying image
* {@link ol.Image#getImage} is assigned the content specified by the src. If
* not specified, the default is
*
* function(image, src) {
* image.getImage().src = src;
* }
*
* Providing a custom `imageLoadFunction` can be useful to load images with
* post requests or - in general - through XHR requests, where the src of the
* image element would be set to a data URI when the content is loaded.
*
* @typedef {function(ol.Image, string)}
* @api
*/
ol.ImageLoadFunctionType;

View File

@@ -105,13 +105,7 @@ goog.exportProperty(
*/
ol.layer.Layer.prototype.getSourceState = function() {
var source = this.getSource();
var state;
if (!goog.isNull(source)) {
state = source.getState();
} else {
state = ol.source.State.UNDEFINED;
}
return state;
return goog.isNull(source) ? ol.source.State.UNDEFINED : source.getState();
};

View File

@@ -60,30 +60,26 @@ ol.layer.Base = function(options) {
goog.base(this);
/**
* @type {Object.<string, *>}
*/
var properties = goog.object.clone(options);
/** @type {number} */
properties.brightness = goog.isDef(properties.brightness) ?
properties.brightness : 0;
/** @type {number} */
properties.contrast = goog.isDef(properties.contrast) ?
properties.contrast : 1;
/** @type {number} */
properties.hue = goog.isDef(properties.hue) ? properties.hue : 0;
/** @type {number} */
properties.opacity = goog.isDef(properties.opacity) ? properties.opacity : 1;
/** @type {number} */
properties.saturation = goog.isDef(properties.saturation) ?
properties.saturation : 1;
/** @type {boolean} */
properties.visible = goog.isDef(properties.visible) ?
properties.visible : true;
/** @type {number} */
properties.maxResolution = goog.isDef(properties.maxResolution) ?
properties.maxResolution : Infinity;
/** @type {number} */
properties.minResolution = goog.isDef(properties.minResolution) ?
properties.minResolution : 0;
properties[ol.layer.LayerProperty.BRIGHTNESS] =
goog.isDef(options.brightness) ? options.brightness : 0;
properties[ol.layer.LayerProperty.CONTRAST] =
goog.isDef(options.contrast) ? options.contrast : 1;
properties[ol.layer.LayerProperty.HUE] =
goog.isDef(options.hue) ? options.hue : 0;
properties[ol.layer.LayerProperty.OPACITY] =
goog.isDef(options.opacity) ? options.opacity : 1;
properties[ol.layer.LayerProperty.SATURATION] =
goog.isDef(options.saturation) ? options.saturation : 1;
properties[ol.layer.LayerProperty.VISIBLE] =
goog.isDef(options.visible) ? options.visible : true;
properties[ol.layer.LayerProperty.MAX_RESOLUTION] =
goog.isDef(options.maxResolution) ? options.maxResolution : Infinity;
properties[ol.layer.LayerProperty.MIN_RESOLUTION] =
goog.isDef(options.minResolution) ? options.minResolution : 0;
this.setProperties(properties);
};

View File

@@ -678,7 +678,7 @@ ol.proj.cloneTransform = function(input, opt_output, opt_dimension) {
*/
ol.proj.transform = function(coordinate, source, destination) {
var transformFn = ol.proj.getTransform(source, destination);
return transformFn(coordinate);
return transformFn(coordinate, undefined, coordinate.length);
};

View File

@@ -69,7 +69,7 @@ ol.renderer.canvas.ImageLayer.prototype.forEachFeatureAtPixel =
*/
ol.renderer.canvas.ImageLayer.prototype.getImage = function() {
return goog.isNull(this.image_) ?
null : this.image_.getImageElement();
null : this.image_.getImage();
};

View File

@@ -129,7 +129,7 @@ ol.renderer.dom.ImageLayer.prototype.prepareFrame =
(imageExtent[0] - viewCenter[0]) / imageResolution,
(viewCenter[1] - imageExtent[3]) / imageResolution);
if (image != this.image_) {
var imageElement = image.getImageElement(this);
var imageElement = image.getImage(this);
// Bootstrap sets the style max-width: 100% for all images, which breaks
// prevents the image from being displayed in FireFox. Workaround by
// overriding the max-width style.

View File

@@ -48,7 +48,7 @@ ol.renderer.webgl.ImageLayer.prototype.createTexture_ = function(image) {
// http://www.khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences#Non-Power_of_Two_Texture_Support
// http://learningwebgl.com/blog/?p=2101
var imageElement = image.getImageElement();
var imageElement = image.getImage();
var gl = this.getWebGLMapRenderer().getGL();
var texture = gl.createTexture();

View File

@@ -91,7 +91,7 @@ ol.source.FormatVector.prototype.loadFeaturesFromURL =
source = xhrIo.getResponseXml();
}
if (!goog.isDefAndNotNull(source)) {
source = ol.xml.load(xhrIo.getResponseText());
source = ol.xml.parse(xhrIo.getResponseText());
}
} else {
goog.asserts.fail();

View File

@@ -3,6 +3,7 @@ goog.provide('ol.source.ImageMapGuide');
goog.require('goog.object');
goog.require('goog.uri.utils');
goog.require('ol.Image');
goog.require('ol.ImageLoadFunctionType');
goog.require('ol.ImageUrlFunction');
goog.require('ol.extent');
goog.require('ol.source.Image');
@@ -59,6 +60,13 @@ ol.source.ImageMapGuide = function(options) {
*/
this.imageUrlFunction_ = imageUrlFunction;
/**
* @private
* @type {ol.ImageLoadFunctionType}
*/
this.imageLoadFunction_ = goog.isDef(options.imageLoadFunction) ?
options.imageLoadFunction : ol.source.Image.defaultImageLoadFunction;
/**
* @private
* @type {boolean}
@@ -140,7 +148,8 @@ ol.source.ImageMapGuide.prototype.getImage =
var imageUrl = this.imageUrlFunction_(extent, size, projection);
if (goog.isDef(imageUrl)) {
image = new ol.Image(extent, resolution, pixelRatio,
this.getAttributions(), imageUrl, this.crossOrigin_);
this.getAttributions(), imageUrl, this.crossOrigin_,
this.imageLoadFunction_);
} else {
image = null;
}

View File

@@ -88,3 +88,14 @@ ol.source.Image.prototype.findNearestResolution =
* @return {ol.ImageBase} Single image.
*/
ol.source.Image.prototype.getImage = goog.abstractMethod;
/**
* Default image load function for image sources that use ol.Image image
* instances.
* @param {ol.Image} image Image.
* @param {string} src Source.
*/
ol.source.Image.defaultImageLoadFunction = function(image, src) {
image.getImage().src = src;
};

View File

@@ -34,6 +34,9 @@ ol.source.ImageStatic = function(options) {
var crossOrigin = goog.isDef(options.crossOrigin) ?
options.crossOrigin : null;
var imageLoadFunction = goog.isDef(options.imageLoadFunction) ?
options.imageLoadFunction : ol.source.Image.defaultImageLoadFunction;
goog.base(this, {
attributions: attributions,
logo: options.logo,
@@ -46,7 +49,7 @@ ol.source.ImageStatic = function(options) {
* @type {ol.Image}
*/
this.image_ = new ol.Image(imageExtent, resolution, 1, attributions,
options.url, crossOrigin);
options.url, crossOrigin, imageLoadFunction);
};
goog.inherits(ol.source.ImageStatic, ol.source.Image);

View File

@@ -8,6 +8,7 @@ goog.require('goog.string');
goog.require('goog.uri.utils');
goog.require('ol');
goog.require('ol.Image');
goog.require('ol.ImageLoadFunctionType');
goog.require('ol.extent');
goog.require('ol.proj');
goog.require('ol.source.Image');
@@ -49,6 +50,13 @@ ol.source.ImageWMS = function(opt_options) {
*/
this.url_ = options.url;
/**
* @private
* @type {ol.ImageLoadFunctionType}
*/
this.imageLoadFunction_ = goog.isDef(options.imageLoadFunction) ?
options.imageLoadFunction : ol.source.Image.defaultImageLoadFunction;
/**
* @private
* @type {Object}
@@ -235,7 +243,7 @@ ol.source.ImageWMS.prototype.getImage =
projection, params);
this.image_ = new ol.Image(extent, resolution, pixelRatio,
this.getAttributions(), url, this.crossOrigin_);
this.getAttributions(), url, this.crossOrigin_, this.imageLoadFunction_);
this.renderedRevision_ = this.getRevision();

View File

@@ -39,6 +39,12 @@ ol.source.TileJSON = function(options) {
tileLoadFunction: options.tileLoadFunction
});
/**
* @type {boolean|undefined}
* @private
*/
this.wrapX_ = options.wrapX;
var request = new goog.net.Jsonp(options.url);
request.send(undefined, goog.bind(this.handleTileJSONResponse, this));
@@ -76,7 +82,8 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function(tileJSON) {
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
tileGrid.createTileCoordTransform({
extent: extent
extent: extent,
wrapX: this.wrapX_
}),
ol.TileUrlFunction.createFromTemplates(tileJSON.tiles));

View File

@@ -59,7 +59,8 @@ ol.source.WMTS = function(options) {
// FIXME: should we guess this requestEncoding from options.url(s)
// structure? that would mean KVP only if a template is not provided.
var requestEncoding = goog.isDef(options.requestEncoding) ?
options.requestEncoding : ol.source.WMTSRequestEncoding.KVP;
/** @type {ol.source.WMTSRequestEncoding} */ (options.requestEncoding) :
ol.source.WMTSRequestEncoding.KVP;
// FIXME: should we create a default tileGrid?
// we could issue a getCapabilities xhr to retrieve missing configuration

View File

@@ -1,5 +1,3 @@
// FIXME bulk inserts
goog.provide('ol.structs.RBush');
goog.require('goog.array');

View File

@@ -0,0 +1,299 @@
goog.provide('ol.style.RegularShape');
goog.require('goog.dom');
goog.require('goog.dom.TagName');
goog.require('ol.color');
goog.require('ol.render.canvas');
goog.require('ol.style.Fill');
goog.require('ol.style.Image');
goog.require('ol.style.ImageState');
goog.require('ol.style.Stroke');
/**
* @classdesc
* Set regular shape style for vector features.
*
* @constructor
* @param {olx.style.RegularShapeOptions=} opt_options Options.
* @extends {ol.style.Image}
* @api
*/
ol.style.RegularShape = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
/**
* @private
* @type {HTMLCanvasElement}
*/
this.canvas_ = /** @type {HTMLCanvasElement} */
(goog.dom.createElement(goog.dom.TagName.CANVAS));
/**
* @private
* @type {HTMLCanvasElement}
*/
this.hitDetectionCanvas_ = null;
/**
* @private
* @type {ol.style.Fill}
*/
this.fill_ = goog.isDef(options.fill) ? options.fill : null;
/**
* @private
* @type {Array.<number>}
*/
this.origin_ = [0, 0];
/**
* @private
* @type {number}
*/
this.points_ = options.points;
/**
* @private
* @type {number}
*/
this.radius_ = options.radius;
/**
* @private
* @type {number}
*/
this.radius2_ =
goog.isDef(options.radius2) ? options.radius2 : options.radius;
/**
* @private
* @type {number}
*/
this.angle_ = goog.isDef(options.angle) ? options.angle : 0;
/**
* @private
* @type {ol.style.Stroke}
*/
this.stroke_ = goog.isDef(options.stroke) ? options.stroke : null;
var size = this.render_();
/**
* @private
* @type {Array.<number>}
*/
this.anchor_ = [size / 2, size / 2];
/**
* @private
* @type {ol.Size}
*/
this.size_ = [size, size];
/**
* @type {boolean}
*/
var snapToPixel = goog.isDef(options.snapToPixel) ?
options.snapToPixel : true;
goog.base(this, {
opacity: 1,
rotateWithView: false,
rotation: 0,
scale: 1,
snapToPixel: snapToPixel
});
};
goog.inherits(ol.style.RegularShape, ol.style.Image);
/**
* @inheritDoc
* @api
*/
ol.style.RegularShape.prototype.getAnchor = function() {
return this.anchor_;
};
/**
* @return {ol.style.Fill} Fill style.
* @api
*/
ol.style.RegularShape.prototype.getFill = function() {
return this.fill_;
};
/**
* @inheritDoc
*/
ol.style.RegularShape.prototype.getHitDetectionImage = function(pixelRatio) {
return this.hitDetectionCanvas_;
};
/**
* @inheritDoc
* @api
*/
ol.style.RegularShape.prototype.getImage = function(pixelRatio) {
return this.canvas_;
};
/**
* @inheritDoc
*/
ol.style.RegularShape.prototype.getImageState = function() {
return ol.style.ImageState.LOADED;
};
/**
* @inheritDoc
* @api
*/
ol.style.RegularShape.prototype.getOrigin = function() {
return this.origin_;
};
/**
* @return {number} Radius.
* @api
*/
ol.style.RegularShape.prototype.getRadius = function() {
return this.radius_;
};
/**
* @inheritDoc
* @api
*/
ol.style.RegularShape.prototype.getSize = function() {
return this.size_;
};
/**
* @return {ol.style.Stroke} Stroke style.
* @api
*/
ol.style.RegularShape.prototype.getStroke = function() {
return this.stroke_;
};
/**
* @inheritDoc
*/
ol.style.RegularShape.prototype.listenImageChange = goog.nullFunction;
/**
* @inheritDoc
*/
ol.style.RegularShape.prototype.load = goog.nullFunction;
/**
* @inheritDoc
*/
ol.style.RegularShape.prototype.unlistenImageChange = goog.nullFunction;
/**
* @private
* @return {number} Size.
*/
ol.style.RegularShape.prototype.render_ = function() {
var canvas = this.canvas_;
var strokeStyle, strokeWidth;
if (goog.isNull(this.stroke_)) {
strokeWidth = 0;
} else {
strokeStyle = ol.color.asString(this.stroke_.getColor());
strokeWidth = this.stroke_.getWidth();
if (!goog.isDef(strokeWidth)) {
strokeWidth = ol.render.canvas.defaultLineWidth;
}
}
var size = 2 * (this.radius_ + strokeWidth) + 1;
// draw the regular shape on the canvas
canvas.height = size;
canvas.width = size;
// canvas.width and height are rounded to the closest integer
size = canvas.width;
var context = /** @type {CanvasRenderingContext2D} */
(canvas.getContext('2d'));
var i, angle0, radiusC;
context.beginPath();
if (this.radius2_ !== this.radius_) {
this.points_ = 2 * this.points_;
}
for (i = 0; i <= this.points_; i++) {
angle0 = i * 2 * Math.PI / this.points_ - Math.PI / 2 + this.angle_;
radiusC = i % 2 === 0 ? this.radius_ : this.radius2_;
context.lineTo(size / 2 + radiusC * Math.cos(angle0),
size / 2 + radiusC * Math.sin(angle0));
}
if (!goog.isNull(this.fill_)) {
context.fillStyle = ol.color.asString(this.fill_.getColor());
context.fill();
}
if (!goog.isNull(this.stroke_)) {
context.strokeStyle = strokeStyle;
context.lineWidth = strokeWidth;
context.stroke();
}
// deal with the hit detection canvas
if (!goog.isNull(this.fill_)) {
this.hitDetectionCanvas_ = canvas;
} else {
this.hitDetectionCanvas_ = /** @type {HTMLCanvasElement} */
(goog.dom.createElement(goog.dom.TagName.CANVAS));
canvas = this.hitDetectionCanvas_;
canvas.height = size;
canvas.width = size;
context = /** @type {CanvasRenderingContext2D} */
(canvas.getContext('2d'));
context.beginPath();
if (this.radius2_ !== this.radius_) {
this.points_ = 2 * this.points_;
}
for (i = 0; i <= this.points_; i++) {
angle0 = i * 2 * Math.PI / this.points_ - Math.PI / 2 + this.angle_;
radiusC = i % 2 === 0 ? this.radius_ : this.radius2_;
context.lineTo(size / 2 + radiusC * Math.cos(angle0),
size / 2 + radiusC * Math.sin(angle0));
}
context.fillStyle = ol.render.canvas.defaultFillStyle;
context.fill();
if (!goog.isNull(this.stroke_)) {
context.strokeStyle = strokeStyle;
context.lineWidth = strokeWidth;
context.stroke();
}
}
return size;
};

View File

@@ -77,9 +77,12 @@ ol.xml.createElementNS =
/**
* Recursively grab all text content of child nodes into a single string.
* @param {Node} node Node.
* @param {boolean} normalizeWhitespace Normalize whitespace.
* @param {boolean} normalizeWhitespace Normalize whitespace: remove all line
* breaks.
* @return {string} All text content.
* @api
*/
ol.xml.getAllTextContent = function(node, normalizeWhitespace) {
return ol.xml.getAllTextContent_(node, normalizeWhitespace, []).join('');
@@ -88,7 +91,8 @@ ol.xml.getAllTextContent = function(node, normalizeWhitespace) {
/**
* @param {Node} node Node.
* @param {boolean} normalizeWhitespace Normalize whitespace.
* @param {boolean} normalizeWhitespace Normalize whitespace: remove all line
* breaks.
* @param {Array.<String|string>} accumulator Accumulator.
* @private
* @return {Array.<String|string>} Accumulator.
@@ -332,10 +336,12 @@ ol.xml.setAttributeNS =
/**
* Parse an XML string to a XML Document
* @param {string} xml XML.
* @return {Document} Document.
* @api
*/
ol.xml.load = function(xml) {
ol.xml.parse = function(xml) {
return new DOMParser().parseFromString(xml, 'application/xml');
};
@@ -379,7 +385,8 @@ ol.xml.makeArrayPusher = function(valueReader, opt_this) {
* @param {Array.<*>} objectStack Object stack.
*/
function(node, objectStack) {
var value = valueReader.call(opt_this, node, objectStack);
var value = valueReader.call(goog.isDef(opt_this) ? opt_this : this,
node, objectStack);
if (goog.isDef(value)) {
var array = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isArray(array));
@@ -402,7 +409,8 @@ ol.xml.makeReplacer = function(valueReader, opt_this) {
* @param {Array.<*>} objectStack Object stack.
*/
function(node, objectStack) {
var value = valueReader.call(opt_this, node, objectStack);
var value = valueReader.call(goog.isDef(opt_this) ? opt_this : this,
node, objectStack);
if (goog.isDef(value)) {
objectStack[objectStack.length - 1] = value;
}
@@ -426,7 +434,8 @@ ol.xml.makeObjectPropertyPusher =
* @param {Array.<*>} objectStack Object stack.
*/
function(node, objectStack) {
var value = valueReader.call(opt_this, node, objectStack);
var value = valueReader.call(goog.isDef(opt_this) ? opt_this : this,
node, objectStack);
if (goog.isDef(value)) {
var object = /** @type {Object} */
(objectStack[objectStack.length - 1]);
@@ -456,7 +465,8 @@ ol.xml.makeObjectPropertySetter =
* @param {Array.<*>} objectStack Object stack.
*/
function(node, objectStack) {
var value = valueReader.call(opt_this, node, objectStack);
var value = valueReader.call(goog.isDef(opt_this) ? opt_this : this,
node, objectStack);
if (goog.isDef(value)) {
var object = /** @type {Object} */
(objectStack[objectStack.length - 1]);
@@ -494,7 +504,8 @@ ol.xml.makeParsersNS = function(namespaceURIs, parsers, opt_parsersNS) {
*/
ol.xml.makeChildAppender = function(nodeWriter, opt_this) {
return function(node, value, objectStack) {
nodeWriter.call(opt_this, node, value, objectStack);
nodeWriter.call(goog.isDef(opt_this) ? opt_this : this,
node, value, objectStack);
var parent = objectStack[objectStack.length - 1];
goog.asserts.assert(goog.isObject(parent));
var parentNode = parent.node;
@@ -636,7 +647,7 @@ ol.xml.makeStructureNS = function(namespaceURIs, structure, opt_structureNS) {
* @param {Array.<*>} objectStack Object stack.
* @param {*=} opt_this The object to use as `this`.
*/
ol.xml.parse = function(parsersNS, node, objectStack, opt_this) {
ol.xml.parseNode = function(parsersNS, node, objectStack, opt_this) {
var n;
for (n = node.firstElementChild; !goog.isNull(n); n = n.nextElementSibling) {
var parsers = parsersNS[n.namespaceURI];
@@ -663,7 +674,7 @@ ol.xml.parse = function(parsersNS, node, objectStack, opt_this) {
ol.xml.pushParseAndPop = function(
object, parsersNS, node, objectStack, opt_this) {
objectStack.push(object);
ol.xml.parse(parsersNS, node, objectStack, opt_this);
ol.xml.parseNode(parsersNS, node, objectStack, opt_this);
return objectStack.pop();
};