Merge branch 'master' of github.com:openlayers/ol3 into vector

Resolved conflicts:
  src/ol/renderer/canvas/canvasrenderer.js
This commit is contained in:
Tim Schaub
2013-02-20 00:38:07 -07:00
38 changed files with 1717 additions and 219 deletions

View File

@@ -5,9 +5,10 @@ goog.require('goog.dom.TagName');
/**
* @return {boolean} Is supported.
* @const
* @type {boolean} Is supported.
*/
ol.canvas.isSupported = function() {
ol.canvas.SUPPORTED = (function() {
if (!('HTMLCanvasElement' in goog.global)) {
return false;
}
@@ -18,4 +19,4 @@ ol.canvas.isSupported = function() {
} catch (e) {
return false;
}
};
})();

View File

@@ -1,5 +1,4 @@
// FIXME handle date line wrap
// FIXME does not handle image sources
goog.provide('ol.control.Attribution');
@@ -10,11 +9,12 @@ goog.require('goog.events');
goog.require('goog.object');
goog.require('goog.style');
goog.require('ol.Attribution');
goog.require('ol.FrameState');
goog.require('ol.MapEvent');
goog.require('ol.MapEventType');
goog.require('ol.TileRange');
goog.require('ol.control.Control');
goog.require('ol.source.TileSource');
goog.require('ol.source.Source');
@@ -66,16 +66,46 @@ ol.control.Attribution = function(attributionOptions) {
goog.inherits(ol.control.Attribution, ol.control.Control);
/**
* @param {?Object.<string, Object.<string, ol.TileRange>>} usedTiles Used
* tiles.
* @param {Object.<string, ol.source.Source>} sources Sources.
* @return {Object.<string, ol.Attribution>} Attributions.
*/
ol.control.Attribution.prototype.getTileSourceAttributions =
function(usedTiles, sources) {
/** @type {Object.<string, ol.Attribution>} */
var attributions = {};
var i, tileRanges, tileSource, tileSourceAttribution,
tileSourceAttributionKey, tileSourceAttributions, tileSourceKey, z;
for (tileSourceKey in usedTiles) {
goog.asserts.assert(tileSourceKey in sources);
tileSource = sources[tileSourceKey];
tileSourceAttributions = tileSource.getAttributions();
if (goog.isNull(tileSourceAttributions)) {
continue;
}
tileRanges = usedTiles[tileSourceKey];
for (i = 0; i < tileSourceAttributions.length; ++i) {
tileSourceAttribution = tileSourceAttributions[i];
tileSourceAttributionKey = goog.getUid(tileSourceAttribution).toString();
if (tileSourceAttributionKey in attributions) {
continue;
}
if (tileSourceAttribution.intersectsAnyTileRange(tileRanges)) {
attributions[tileSourceAttributionKey] = tileSourceAttribution;
}
}
}
return attributions;
};
/**
* @param {ol.MapEvent} mapEvent Map event.
*/
ol.control.Attribution.prototype.handleMapPostrender = function(mapEvent) {
var frameState = mapEvent.frameState;
if (goog.isNull(frameState)) {
this.updateElement_(null);
} else {
this.updateElement_(frameState.usedTiles);
}
this.updateElement_(mapEvent.frameState);
};
@@ -99,12 +129,11 @@ ol.control.Attribution.prototype.setMap = function(map) {
/**
* @private
* @param {?Object.<string, Object.<string, ol.TileRange>>} usedTiles Used
* tiles.
* @param {?ol.FrameState} frameState Frame state.
*/
ol.control.Attribution.prototype.updateElement_ = function(usedTiles) {
ol.control.Attribution.prototype.updateElement_ = function(frameState) {
if (goog.isNull(usedTiles)) {
if (goog.isNull(frameState)) {
if (this.renderedVisible_) {
goog.style.showElement(this.element, false);
this.renderedVisible_ = false;
@@ -116,15 +145,13 @@ ol.control.Attribution.prototype.updateElement_ = function(usedTiles) {
/** @type {Object.<string, boolean>} */
var attributionsToRemove = {};
/** @type {Object.<string, ol.source.TileSource>} */
var tileSources = {};
/** @type {Object.<string, ol.source.Source>} */
var sources = {};
var layers = map.getLayers();
if (goog.isDef(layers)) {
layers.forEach(function(layer) {
var source = layer.getSource();
if (source instanceof ol.source.TileSource) {
tileSources[goog.getUid(source).toString()] = source;
}
sources[goog.getUid(source).toString()] = source;
var attributions = source.getAttributions();
if (!goog.isNull(attributions)) {
var attribution, i;
@@ -138,34 +165,16 @@ ol.control.Attribution.prototype.updateElement_ = function(usedTiles) {
}
/** @type {Object.<string, ol.Attribution>} */
var attributions = {};
var i, tileRanges, tileSource, tileSourceAttribution,
tileSourceAttributionKey, tileSourceAttributions, tileSourceKey, z;
for (tileSourceKey in usedTiles) {
goog.asserts.assert(tileSourceKey in tileSources);
tileSource = tileSources[tileSourceKey];
tileSourceAttributions = tileSource.getAttributions();
if (goog.isNull(tileSourceAttributions)) {
continue;
}
tileRanges = usedTiles[tileSourceKey];
for (i = 0; i < tileSourceAttributions.length; ++i) {
tileSourceAttribution = tileSourceAttributions[i];
tileSourceAttributionKey = goog.getUid(tileSourceAttribution).toString();
if (tileSourceAttributionKey in attributions) {
continue;
}
if (tileSourceAttribution.intersectsAnyTileRange(tileRanges)) {
attributions[tileSourceAttributionKey] = tileSourceAttribution;
}
}
}
var attributions = goog.object.clone(frameState.attributions);
var tileSourceAttributions = this.getTileSourceAttributions(
frameState.usedTiles, sources);
goog.object.extend(attributions, tileSourceAttributions);
/** @type {Array.<number>} */
var attributionKeys =
goog.array.map(goog.object.getKeys(attributions), Number);
goog.array.sort(attributionKeys);
var attributionElement, attributionKey;
var i, attributionElement, attributionKey;
for (i = 0; i < attributionKeys.length; ++i) {
attributionKey = attributionKeys[i].toString();
if (attributionKey in this.attributionElements_) {

View File

@@ -88,3 +88,19 @@ ol.Coordinate.toStringXY = function(coordinate, opt_precision) {
return '';
}
};
/**
* Create an ol.Coordinate from an Array and take into account axis order.
* @param {Array} array The array with coordinates.
* @param {string} axis the axis info.
* @return {ol.Coordinate} The coordinate created.
*/
ol.Coordinate.fromProjectedArray = function(array, axis) {
var firstAxis = axis.charAt(0);
if (firstAxis === 'n' || firstAxis === 's') {
return new ol.Coordinate(array[1], array[0]);
} else {
return new ol.Coordinate(array[0], array[1]);
}
};

View File

@@ -6,6 +6,7 @@ goog.provide('ol.PostRenderFunction');
goog.provide('ol.PreRenderFunction');
goog.require('goog.vec.Mat4');
goog.require('ol.Attribution');
goog.require('ol.Color');
goog.require('ol.Extent');
goog.require('ol.Size');
@@ -18,6 +19,7 @@ goog.require('ol.layer.LayerState');
/**
* @typedef {{animate: boolean,
* attributions: Object.<string, ol.Attribution>,
* backgroundColor: ol.Color,
* coordinateToPixelMatrix: goog.vec.Mat4.Number,
* extent: (null|ol.Extent),

View File

@@ -42,7 +42,7 @@ ol.Geolocation = function(opt_positionOptions) {
*/
this.position_ = null;
if (ol.Geolocation.isSupported) {
if (ol.Geolocation.SUPPORTED) {
goog.events.listen(
this, ol.Object.getChangedEventType(ol.GeolocationProperty.PROJECTION),
this.handleProjectionChanged_, false, this);
@@ -86,9 +86,10 @@ ol.Geolocation.prototype.handleProjectionChanged_ = function() {
/**
* @const
* @type {boolean} Is supported.
*/
ol.Geolocation.isSupported = 'geolocation' in navigator;
ol.Geolocation.SUPPORTED = 'geolocation' in navigator;
/**

View File

@@ -5,6 +5,7 @@ goog.require('goog.array');
goog.require('goog.events');
goog.require('goog.events.EventTarget');
goog.require('goog.events.EventType');
goog.require('ol.Attribution');
goog.require('ol.Extent');
@@ -27,8 +28,15 @@ ol.ImageState = {
* @param {number} resolution Resolution.
* @param {string} src Image source URI.
* @param {?string} crossOrigin Cross origin.
* @param {Array.<ol.Attribution>} attributions Attributions.
*/
ol.Image = function(extent, resolution, src, crossOrigin) {
ol.Image = function(extent, resolution, src, crossOrigin, attributions) {
/**
* @private
* @type {Array.<ol.Attribution>}
*/
this.attributions_ = attributions;
/**
* @private
@@ -86,6 +94,14 @@ ol.Image.prototype.dispatchChangeEvent = function() {
};
/**
* @return {Array.<ol.Attribution>} Attributions.
*/
ol.Image.prototype.getAttributions = function() {
return this.attributions_;
};
/**
* @return {ol.Extent} Extent.
*/

View File

@@ -58,11 +58,11 @@ goog.require('ol.interaction.condition');
goog.require('ol.layer.Layer');
goog.require('ol.renderer.Map');
goog.require('ol.renderer.canvas.Map');
goog.require('ol.renderer.canvas.isSupported');
goog.require('ol.renderer.canvas.SUPPORTED');
goog.require('ol.renderer.dom.Map');
goog.require('ol.renderer.dom.isSupported');
goog.require('ol.renderer.dom.SUPPORTED');
goog.require('ol.renderer.webgl.Map');
goog.require('ol.renderer.webgl.isSupported');
goog.require('ol.renderer.webgl.SUPPORTED');
/**
@@ -664,6 +664,7 @@ ol.Map.prototype.renderFrame_ = function(time) {
var view2DState = view2D.getView2DState();
frameState = {
animate: false,
attributions: {},
backgroundColor: goog.isDef(backgroundColor) ?
backgroundColor : new ol.Color(255, 255, 255, 1),
coordinateToPixelMatrix: this.coordinateToPixelMatrix_,
@@ -857,17 +858,17 @@ ol.Map.createOptionsInternal = function(mapOptions) {
for (i = 0; i < rendererHints.length; ++i) {
rendererHint = rendererHints[i];
if (rendererHint == ol.RendererHint.CANVAS) {
if (ol.ENABLE_CANVAS && ol.renderer.canvas.isSupported()) {
if (ol.ENABLE_CANVAS && ol.renderer.canvas.SUPPORTED) {
rendererConstructor = ol.renderer.canvas.Map;
break;
}
} else if (rendererHint == ol.RendererHint.DOM) {
if (ol.ENABLE_DOM && ol.renderer.dom.isSupported()) {
if (ol.ENABLE_DOM && ol.renderer.dom.SUPPORTED) {
rendererConstructor = ol.renderer.dom.Map;
break;
}
} else if (rendererHint == ol.RendererHint.WEBGL) {
if (ol.ENABLE_WEBGL && ol.renderer.webgl.isSupported()) {
if (ol.ENABLE_WEBGL && ol.renderer.webgl.SUPPORTED) {
rendererConstructor = ol.renderer.webgl.Map;
break;
}

View File

@@ -0,0 +1,214 @@
goog.provide('ol.parser.ogc.OWSCommon_v1');
goog.require('ol.Extent');
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['http://www.opengis.net/ows'];
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'] = new ol.Extent(parseFloat(obj['left']),
parseFloat(obj['bottom']), parseFloat(obj['right']),
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);

View File

@@ -0,0 +1,45 @@
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);

View File

@@ -0,0 +1,2 @@
@exportSymbol ol.parser.ogc.WMTSCapabilities
@exportProperty ol.parser.ogc.WMTSCapabilities.prototype.read

View File

@@ -0,0 +1,19 @@
goog.provide('ol.parser.ogc.WMTSCapabilities');
goog.require('ol.parser.ogc.Versioned');
goog.require('ol.parser.ogc.WMTSCapabilities_v1_0_0');
/**
* @constructor
* @param {Object=} opt_options Options which will be set on this object.
* @extends {ol.parser.ogc.Versioned}
*/
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);

View File

@@ -0,0 +1,161 @@
goog.provide('ol.parser.ogc.WMTSCapabilities_v1_0_0');
goog.require('goog.dom.xml');
goog.require('ol.Coordinate');
goog.require('ol.Projection');
goog.require('ol.parser.XML');
goog.require('ol.parser.ogc.OWSCommon_v1_1_0');
/**
* @constructor
* @extends {ol.parser.XML}
*/
ol.parser.ogc.WMTSCapabilities_v1_0_0 = function() {
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 axis = ol.Projection.getFromCode(obj['supportedCRS']).getAxis();
obj['topLeftCorner'] = ol.Coordinate.fromProjectedArray(
[parseFloat(coords[0]), parseFloat(coords[1])], axis);
},
'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) {
obj['resourceUrl'] = obj['resourceUrl'] || {};
var resourceType = node.getAttribute('resourceType');
if (!obj['resourceUrls']) {
obj['resourceUrls'] = [];
}
var resourceUrl = obj['resourceUrl'][resourceType] = {
'format': node.getAttribute('format'),
'template': node.getAttribute('template'),
'resourceType': resourceType
};
obj['resourceUrls'].push(resourceUrl);
},
'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 (typeof data == 'string') {
data = goog.dom.xml.loadXml(data);
}
if (data && data.nodeType == 9) {
data = data.documentElement;
}
var obj = {};
this.readNode(data, obj);
return obj;
};

View File

@@ -6,6 +6,12 @@ goog.provide('ol.parser.XML');
* @constructor
*/
ol.parser.XML = function() {
this.regExes = {
trimSpace: (/^\s*|\s*$/g),
removeSpace: (/\s*/g),
splitSpace: (/\s+/),
trimComma: (/\s*,\s*/g)
};
};

View File

@@ -15,6 +15,12 @@ goog.require('ol.TransformFunction');
ol.ENABLE_PROJ4JS = true;
/**
* @const {boolean} Have Proj4js.
*/
ol.HAVE_PROJ4JS = ol.ENABLE_PROJ4JS && typeof Proj4js == 'object';
/**
* @enum {string}
*/
@@ -30,8 +36,9 @@ ol.ProjectionUnits = {
* @param {string} code Code.
* @param {ol.ProjectionUnits} units Units.
* @param {ol.Extent} extent Extent.
* @param {string=} opt_axis Axis order.
*/
ol.Projection = function(code, units, extent) {
ol.Projection = function(code, units, extent, opt_axis) {
/**
* @private
@@ -51,6 +58,12 @@ ol.Projection = function(code, units, extent) {
*/
this.extent_ = extent;
/**
* @private
* @type {string}
*/
this.axis_ = opt_axis || 'enu';
};
@@ -78,6 +91,14 @@ ol.Projection.prototype.getUnits = function() {
};
/**
* @return {string} Axis.
*/
ol.Projection.prototype.getAxis = function() {
return this.axis_;
};
/**
* @constructor
@@ -253,7 +274,7 @@ ol.Projection.addTransform = function(source, destination, transformFn) {
*/
ol.Projection.getFromCode = function(code) {
var projection = ol.Projection.projections_[code];
if (ol.Projection.isProj4jsSupported() && !goog.isDef(projection)) {
if (ol.HAVE_PROJ4JS && !goog.isDef(projection)) {
projection = ol.Projection.getProj4jsProjectionFromCode_(code);
}
if (!goog.isDef(projection)) {
@@ -319,7 +340,7 @@ ol.Projection.getTransform = function(source, destination) {
goog.object.containsKey(transforms[sourceCode], destinationCode)) {
transform = transforms[sourceCode][destinationCode];
}
if (ol.Projection.isProj4jsSupported() && !goog.isDef(transform)) {
if (ol.HAVE_PROJ4JS && !goog.isDef(transform)) {
var proj4jsSource;
if (source instanceof ol.Proj4jsProjection) {
proj4jsSource = source;
@@ -373,14 +394,6 @@ ol.Projection.getTransformFromCodes = function(sourceCode, destinationCode) {
};
/**
* @return {boolean} True if Proj4js is available and enabled.
*/
ol.Projection.isProj4jsSupported = function() {
return ol.ENABLE_PROJ4JS && 'Proj4js' in goog.global;
};
/**
* @param {ol.Coordinate} point Point.
* @return {ol.Coordinate} Unaltered point (same reference).
@@ -528,6 +541,7 @@ ol.Projection.EPSG_4326_EXTENT_ = new ol.Extent(-180, -90, 180, 90);
*/
ol.Projection.EPSG_4326_LIKE_CODES_ = [
'CRS:84',
'urn:ogc:def:crs:OGC:1.3:CRS84',
'EPSG:4326',
'urn:ogc:def:crs:EPSG:6.6:4326'
];
@@ -545,7 +559,9 @@ ol.Projection.EPSG_4326_LIKE_PROJECTIONS = goog.array.map(
return new ol.Projection(
code,
ol.ProjectionUnits.DEGREES,
ol.Projection.EPSG_4326_EXTENT_);
ol.Projection.EPSG_4326_EXTENT_,
code === 'CRS:84' || code === 'urn:ogc:def:crs:OGC:1.3:CRS84' ?
'enu' : 'neu');
});

View File

@@ -94,6 +94,7 @@ ol.renderer.canvas.ImageLayer.prototype.renderFrame =
if (!goog.isNull(this.image_)) {
image = this.image_;
var imageExtent = image.getExtent();
var imageResolution = image.getResolution();
var transform = this.transform_;
@@ -111,5 +112,7 @@ ol.renderer.canvas.ImageLayer.prototype.renderFrame =
(imageExtent.minX - viewCenter.x) / imageResolution,
(viewCenter.y - imageExtent.maxY) / imageResolution,
0);
this.updateAttributions(frameState.attributions, image.getAttributions());
}
};

View File

@@ -1,5 +1,5 @@
goog.provide('ol.renderer.canvas.Renderer');
goog.provide('ol.renderer.canvas.isSupported');
goog.provide('ol.renderer.canvas.SUPPORTED');
goog.require('goog.asserts');
goog.require('goog.vec.Mat4');
@@ -17,9 +17,10 @@ goog.require('ol.style.SymbolizerLiteral');
/**
* @return {boolean} Is supported.
* @const
* @type {boolean} Is supported.
*/
ol.renderer.canvas.isSupported = ol.canvas.isSupported;
ol.renderer.canvas.SUPPORTED = ol.canvas.SUPPORTED;
@@ -291,4 +292,3 @@ ol.renderer.canvas.Renderer.renderShape = function(shape) {
}
return canvas;
};

View File

@@ -106,6 +106,8 @@ ol.renderer.dom.ImageLayer.prototype.renderFrame =
this.image_ = image;
}
this.setTransform(transform);
this.updateAttributions(frameState.attributions, image.getAttributions());
}
};

View File

@@ -1,9 +1,8 @@
goog.provide('ol.renderer.dom.isSupported');
goog.require('goog.functions');
goog.provide('ol.renderer.dom.SUPPORTED');
/**
* @return {boolean} Is supported.
* @const
* @type {boolean} Is supported.
*/
ol.renderer.dom.isSupported = goog.functions.TRUE;
ol.renderer.dom.SUPPORTED = true;

View File

@@ -2,6 +2,7 @@ goog.provide('ol.renderer.Layer');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('ol.Attribution');
goog.require('ol.FrameState');
goog.require('ol.Image');
goog.require('ol.ImageState');
@@ -201,6 +202,23 @@ ol.renderer.Layer.prototype.scheduleExpireCache =
};
/**
* @protected
* @param {Object.<string, ol.Attribution>} attributionsSet Attributions
* set (target).
* @param {Array.<ol.Attribution>} attributions Attributions (source).
*/
ol.renderer.Layer.prototype.updateAttributions =
function(attributionsSet, attributions) {
var i;
var attribution;
for (i = 0; i < attributions.length; ++i) {
attribution = attributions[i];
attributionsSet[goog.getUid(attribution).toString()] = attribution;
}
};
/**
* @protected
* @param {Object.<string, Object.<string, ol.TileRange>>} usedTiles Used tiles.

View File

@@ -198,6 +198,8 @@ ol.renderer.webgl.ImageLayer.prototype.renderFrame =
this.image_ = image;
this.texture_ = texture;
this.updateAttributions(frameState.attributions, image.getAttributions());
}
};

View File

@@ -1,9 +1,10 @@
goog.provide('ol.renderer.webgl.isSupported');
goog.provide('ol.renderer.webgl.SUPPORTED');
goog.require('ol.webgl');
/**
* @return {boolean} Is supported.
* @const
* @type {boolean} Is supported.
*/
ol.renderer.webgl.isSupported = ol.webgl.isSupported;
ol.renderer.webgl.SUPPORTED = ol.webgl.SUPPORTED;

View File

@@ -84,7 +84,8 @@ ol.source.ImageSource.prototype.createImage =
var imageUrl = this.imageUrlFunction(extent, size);
if (goog.isDef(imageUrl)) {
image = new ol.Image(
extent, resolution, imageUrl, this.crossOrigin_);
extent, resolution, imageUrl, this.crossOrigin_,
this.getAttributions());
}
return image;
};

View File

@@ -42,13 +42,6 @@ ol.tilegrid.TileGrid = function(tileGridOptions) {
*/
this.numResolutions_ = this.resolutions_.length;
/**
* @private
* @type {ol.Extent}
*/
this.extent_ = goog.isDef(tileGridOptions.extent) ?
tileGridOptions.extent : null;
/**
* @private
* @type {ol.Coordinate}
@@ -98,14 +91,6 @@ ol.tilegrid.TileGrid.prototype.forEachTileCoordParentTileRange =
};
/**
* @return {ol.Extent} Extent.
*/
ol.tilegrid.TileGrid.prototype.getExtent = function() {
return this.extent_;
};
/**
* @param {number} z Z.
* @return {ol.Coordinate} Origin.
@@ -183,10 +168,10 @@ ol.tilegrid.TileGrid.prototype.getTileRangeExtent = function(z, tileRange) {
*/
ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndResolution = function(
extent, resolution) {
var min = this.getTileCoordForCoordAndResolution(
var min = this.getTileCoordForCoordAndResolution_(
new ol.Coordinate(extent.minX, extent.minY), resolution);
var max = this.getTileCoordForCoordAndResolution(
new ol.Coordinate(extent.maxX, extent.maxY), resolution);
var max = this.getTileCoordForCoordAndResolution_(
new ol.Coordinate(extent.maxX, extent.maxY), resolution, true);
return new ol.TileRange(min.x, min.y, max.x, max.y);
};
@@ -233,46 +218,48 @@ ol.tilegrid.TileGrid.prototype.getTileCoordExtent = function(tileCoord) {
/**
* Get the tile coordinate for the given map coordinate and resolution. This
* method considers that coordinates that intersect tile boundaries should be
* assigned the higher tile coordinate.
*
* @param {ol.Coordinate} coordinate Coordinate.
* @param {number} resolution Resolution.
* @return {ol.TileCoord} Tile coordinate.
*/
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function(
coordinate, resolution) {
return this.getTileCoordForCoordAndResolution_(coordinate, resolution);
};
/**
* @param {ol.Coordinate} coordinate Coordinate.
* @param {number} resolution Resolution.
* @param {boolean=} opt_reverseIntersectionPolicy Instead of letting edge
* intersections go to the higher tile coordinate, let edge intersections
* go to the lower tile coordinate.
* @return {ol.TileCoord} Tile coordinate.
* @private
*/
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution_ = function(
coordinate, resolution, opt_reverseIntersectionPolicy) {
var z = this.getZForResolution(resolution);
var scale = resolution / this.getResolution(z);
var origin = this.getOrigin(z);
var offsetFromOrigin = new ol.Coordinate(
Math.floor((coordinate.x - origin.x) / resolution),
Math.floor((coordinate.y - origin.y) / resolution));
var tileSize = this.getTileSize();
tileSize = new ol.Size(tileSize.width / scale,
tileSize.height / scale);
var x, y;
x = Math.floor(offsetFromOrigin.x / tileSize.width);
y = Math.floor(offsetFromOrigin.y / tileSize.height);
var x = scale * (coordinate.x - origin.x) / (resolution * tileSize.width);
var y = scale * (coordinate.y - origin.y) / (resolution * tileSize.height);
var tileCoord = new ol.TileCoord(z, x, y);
var tileCoordPixelBounds = this.getPixelBoundsForTileCoordAndResolution(
tileCoord, resolution);
// adjust x to allow for stretched tiles
if (offsetFromOrigin.x < tileCoordPixelBounds.minX) {
tileCoord.x -= 1;
} else if (offsetFromOrigin.x >= tileCoordPixelBounds.maxX) {
tileCoord.x += 1;
}
// adjust y to allow for stretched tiles
if (offsetFromOrigin.y < tileCoordPixelBounds.minY) {
tileCoord.y -= 1;
} else if (offsetFromOrigin.y >= tileCoordPixelBounds.maxY) {
tileCoord.y += 1;
if (!opt_reverseIntersectionPolicy) {
x = Math.floor(x);
y = Math.floor(y);
} else {
x = Math.ceil(x) - 1;
y = Math.ceil(y) - 1;
}
return tileCoord;
return new ol.TileCoord(z, x, y);
};
@@ -284,7 +271,7 @@ ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function(
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndZ =
function(coordinate, z) {
var resolution = this.getResolution(z);
return this.getTileCoordForCoordAndResolution(coordinate, resolution);
return this.getTileCoordForCoordAndResolution_(coordinate, resolution);
};
@@ -333,8 +320,9 @@ ol.tilegrid.createForProjection =
opt_tileSize : new ol.Size(ol.DEFAULT_TILE_SIZE, ol.DEFAULT_TILE_SIZE);
var resolutions = new Array(maxZoom + 1);
goog.asserts.assert(tileSize.width == tileSize.height);
size = size / tileSize.width;
for (var z = 0, zz = resolutions.length; z < zz; ++z) {
resolutions[z] = size / (tileSize.width << z);
resolutions[z] = size / Math.pow(2, z);
}
return new ol.tilegrid.TileGrid({
origin: projectionExtent.getTopLeft(),

View File

@@ -17,9 +17,9 @@ ol.tilegrid.XYZ = function(xyzOptions) {
var resolutions = new Array(xyzOptions.maxZoom + 1);
var z;
var size = 2 * ol.Projection.EPSG_3857_HALF_SIZE / ol.DEFAULT_TILE_SIZE;
for (z = 0; z <= xyzOptions.maxZoom; ++z) {
resolutions[z] =
2 * ol.Projection.EPSG_3857_HALF_SIZE / (ol.DEFAULT_TILE_SIZE << z);
resolutions[z] = size / Math.pow(2, z);
}
goog.base(this, {

View File

@@ -7,6 +7,9 @@ goog.require('ol.TileCoord');
/**
* A representation of a contiguous block of tiles. A tile range is specified
* by its min/max tile coordinates and is inclusive of coordinates.
*
* @constructor
* @extends {ol.Rectangle}
* @param {number} minX Minimum X.
@@ -15,7 +18,27 @@ goog.require('ol.TileCoord');
* @param {number} maxY Maximum Y.
*/
ol.TileRange = function(minX, minY, maxX, maxY) {
goog.base(this, minX, minY, maxX, maxY);
/**
* @type {number}
*/
this.minX = minX;
/**
* @type {number}
*/
this.minY = minY;
/**
* @type {number}
*/
this.maxX = maxX;
/**
* @type {number}
*/
this.maxY = maxY;
};
goog.inherits(ol.TileRange, ol.Rectangle);

View File

@@ -56,7 +56,7 @@ ol.View2D = function(opt_view2DOptions) {
projectionExtent.maxX - projectionExtent.minX,
projectionExtent.maxY - projectionExtent.minY);
values[ol.View2DProperty.RESOLUTION] =
size / (ol.DEFAULT_TILE_SIZE << view2DOptions.zoom);
size / (ol.DEFAULT_TILE_SIZE * Math.pow(2, view2DOptions.zoom));
}
values[ol.View2DProperty.ROTATION] = view2DOptions.rotation;
this.setValues(values);

View File

@@ -45,9 +45,10 @@ ol.webgl.getContext = function(canvas, opt_attributes) {
/**
* @return {boolean} Is supported.
* @const
* @type {boolean} Is supported.
*/
ol.webgl.isSupported = function() {
ol.webgl.SUPPORTED = (function() {
if (!('WebGLRenderingContext' in goog.global)) {
return false;
}
@@ -57,4 +58,4 @@ ol.webgl.isSupported = function() {
} catch (e) {
return false;
}
};
})();