Use object literals and use generic tile layer
This commit is contained in:
@@ -16,14 +16,13 @@
|
|||||||
"exports/ol/collection.js",
|
"exports/ol/collection.js",
|
||||||
"exports/ol/coordinate.js",
|
"exports/ol/coordinate.js",
|
||||||
"exports/ol/extent.js",
|
"exports/ol/extent.js",
|
||||||
"exports/ol/layer/bingmaps.js",
|
"exports/ol/layer/tilelayer.js",
|
||||||
"exports/ol/layer/mapquest.js",
|
|
||||||
"exports/ol/layer/openstreetmap.js",
|
|
||||||
"exports/ol/layer/tilejson.js",
|
|
||||||
"exports/ol/layer/stamen.js",
|
|
||||||
"exports/ol/map.js",
|
"exports/ol/map.js",
|
||||||
"exports/ol/object.js",
|
"exports/ol/object.js",
|
||||||
"exports/ol/projection.js"
|
"exports/ol/projection.js",
|
||||||
|
"exports/ol/source/mapquest.js",
|
||||||
|
"exports/ol/source/openstreetmap.js",
|
||||||
|
"exports/ol/source/stamen.js"
|
||||||
],
|
],
|
||||||
|
|
||||||
"output-wrapper": "(function(){%output%})();"
|
"output-wrapper": "(function(){%output%})();"
|
||||||
|
|||||||
@@ -18,7 +18,9 @@
|
|||||||
<script src="../../build/ol.js" type="text/javascript"></script>
|
<script src="../../build/ol.js" type="text/javascript"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
var layer = new ol.layer.MapQuestOpenAerial();
|
var layer = new ol.layer.TileLayer({
|
||||||
|
source: new ol.source.MapQuestOpenAerial()
|
||||||
|
});
|
||||||
var map = new ol.Map(document.getElementById('map'), {
|
var map = new ol.Map(document.getElementById('map'), {
|
||||||
center: new ol.Coordinate(0, 0),
|
center: new ol.Coordinate(0, 0),
|
||||||
layers: new ol.Collection([layer]),
|
layers: new ol.Collection([layer]),
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ goog.require('ol.Coordinate');
|
|||||||
goog.require('ol.Map');
|
goog.require('ol.Map');
|
||||||
goog.require('ol.MapOptions'); // FIXME this should not be required
|
goog.require('ol.MapOptions'); // FIXME this should not be required
|
||||||
goog.require('ol.control.Zoom');
|
goog.require('ol.control.Zoom');
|
||||||
goog.require('ol.layer.MapQuestOpenAerial');
|
goog.require('ol.source.MapQuestOpenAerial');
|
||||||
|
|
||||||
|
|
||||||
if (goog.DEBUG) {
|
if (goog.DEBUG) {
|
||||||
@@ -15,7 +15,9 @@ if (goog.DEBUG) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var layer = new ol.layer.MapQuestOpenAerial();
|
var layer = new ol.layer.TileLayer({
|
||||||
|
source: new ol.source.MapQuestOpenAerial()
|
||||||
|
});
|
||||||
var map = new ol.Map(document.getElementById('map'), {
|
var map = new ol.Map(document.getElementById('map'), {
|
||||||
center: new ol.Coordinate(0, 0),
|
center: new ol.Coordinate(0, 0),
|
||||||
layers: new ol.Collection([layer]),
|
layers: new ol.Collection([layer]),
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ goog.require('ol.RendererHint');
|
|||||||
goog.require('ol.control.Attribution');
|
goog.require('ol.control.Attribution');
|
||||||
goog.require('ol.control.MousePosition');
|
goog.require('ol.control.MousePosition');
|
||||||
goog.require('ol.interaction.Keyboard');
|
goog.require('ol.interaction.Keyboard');
|
||||||
goog.require('ol.layer.MapQuestOpenAerial');
|
goog.require('ol.layer.TileLayer');
|
||||||
|
goog.require('ol.source.MapQuestOpenAerial');
|
||||||
|
|
||||||
|
|
||||||
if (goog.DEBUG) {
|
if (goog.DEBUG) {
|
||||||
@@ -16,7 +17,9 @@ if (goog.DEBUG) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var layer = new ol.layer.MapQuestOpenAerial();
|
var layer = new ol.layer.TileLayer({
|
||||||
|
source: new ol.source.MapQuestOpenAerial()
|
||||||
|
});
|
||||||
|
|
||||||
var domMap = new ol.Map(document.getElementById('domMap'), {
|
var domMap = new ol.Map(document.getElementById('domMap'), {
|
||||||
center: new ol.Coordinate(0, 0),
|
center: new ol.Coordinate(0, 0),
|
||||||
|
|||||||
@@ -4,16 +4,23 @@ goog.require('ol.Map');
|
|||||||
goog.require('ol.Projection');
|
goog.require('ol.Projection');
|
||||||
goog.require('ol.RendererHint');
|
goog.require('ol.RendererHint');
|
||||||
goog.require('ol.control.Attribution');
|
goog.require('ol.control.Attribution');
|
||||||
goog.require('ol.layer.BingMaps');
|
goog.require('ol.layer.TileLayer');
|
||||||
goog.require('ol.layer.TileJSON');
|
goog.require('ol.source.BingMaps');
|
||||||
|
goog.require('ol.source.TileJSON');
|
||||||
|
|
||||||
|
|
||||||
var layers = new ol.Collection([
|
var layers = new ol.Collection([
|
||||||
new ol.layer.BingMaps(
|
new ol.layer.TileLayer({
|
||||||
ol.BingMapsStyle.AERIAL,
|
source: new ol.source.BingMaps({
|
||||||
'AheP841R-MsLErKQChaTba_xDoOCl40-EeTubD9uNhNAyQTePwFY9iVD1_pyqqlE'),
|
key: 'AheP841R-MsLErKQChaTba_xDoOCl40-EeTubD9uNhNAyQTePwFY9iVD1_pyqqlE',
|
||||||
new ol.layer.TileJSON(
|
style: ol.BingMapsStyle.AERIAL
|
||||||
'http://api.tiles.mapbox.com/v3/mapbox.va-quake-aug.jsonp')
|
})
|
||||||
|
}),
|
||||||
|
new ol.layer.TileLayer({
|
||||||
|
source: new ol.source.TileJSON({
|
||||||
|
uri: 'http://api.tiles.mapbox.com/v3/mapbox.va-quake-aug.jsonp'
|
||||||
|
})
|
||||||
|
})
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var webglMap = new ol.Map(document.getElementById('webglMap'), {
|
var webglMap = new ol.Map(document.getElementById('webglMap'), {
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
goog.require('ol.layer.BingMaps');
|
|
||||||
|
|
||||||
goog.exportSymbol('ol.layer.BingMaps', ol.layer.BingMaps);
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
goog.require('ol.layer.MapQuestOSM');
|
|
||||||
goog.require('ol.layer.MapQuestOpenAerial');
|
|
||||||
|
|
||||||
goog.exportSymbol('ol.layer.MapQuestOSM', ol.layer.MapQuestOSM);
|
|
||||||
goog.exportSymbol('ol.layer.MapQuestOpenAerial', ol.layer.MapQuestOpenAerial);
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
goog.require('ol.layer.OpenStreetMap');
|
|
||||||
|
|
||||||
goog.exportSymbol('ol.layer.OpenStreetMap', ol.layer.OpenStreetMap);
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
goog.require('ol.layer.Stamen');
|
|
||||||
|
|
||||||
goog.exportSymbol('ol.layer.Stamen', ol.layer.Stamen);
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
goog.require('ol.layer.TileJSON');
|
|
||||||
|
|
||||||
goog.exportSymbol('ol.layer.TileJSON', ol.layer.TileJSON);
|
|
||||||
3
exports/ol/layer/tilelayer.js
Normal file
3
exports/ol/layer/tilelayer.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
goog.require('ol.layer.TileLayer');
|
||||||
|
|
||||||
|
goog.exportSymbol('ol.layer.TileLayer', ol.layer.TileLayer);
|
||||||
3
exports/ol/source/bingmaps.js
Normal file
3
exports/ol/source/bingmaps.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
goog.require('ol.source.BingMaps');
|
||||||
|
|
||||||
|
goog.exportSymbol('ol.source.BingMaps', ol.source.BingMaps);
|
||||||
5
exports/ol/source/mapquest.js
Normal file
5
exports/ol/source/mapquest.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
goog.require('ol.source.MapQuestOSM');
|
||||||
|
goog.require('ol.source.MapQuestOpenAerial');
|
||||||
|
|
||||||
|
goog.exportSymbol('ol.source.MapQuestOSM', ol.source.MapQuestOSM);
|
||||||
|
goog.exportSymbol('ol.source.MapQuestOpenAerial', ol.source.MapQuestOpenAerial);
|
||||||
3
exports/ol/source/openstreetmap.js
Normal file
3
exports/ol/source/openstreetmap.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
goog.require('ol.source.OpenStreetMap');
|
||||||
|
|
||||||
|
goog.exportSymbol('ol.source.OpenStreetMap', ol.source.OpenStreetMap);
|
||||||
3
exports/ol/source/stamen.js
Normal file
3
exports/ol/source/stamen.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
goog.require('ol.source.Stamen');
|
||||||
|
|
||||||
|
goog.exportSymbol('ol.source.Stamen', ol.source.Stamen);
|
||||||
3
exports/ol/source/tilejson.js
Normal file
3
exports/ol/source/tilejson.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
goog.require('ol.source.TileJSON');
|
||||||
|
|
||||||
|
goog.exportSymbol('ol.source.TileJSON', ol.source.TileJSON);
|
||||||
@@ -181,8 +181,8 @@ ol.control.Attribution.prototype.getLayerAttributionVisiblities_ =
|
|||||||
}
|
}
|
||||||
|
|
||||||
var mapZ;
|
var mapZ;
|
||||||
if (source instanceof ol.TileSource) {
|
if (source instanceof ol.source.TileSource) {
|
||||||
var tileSource = /** @type {ol.TileSource} */ source;
|
var tileSource = /** @type {ol.source.TileSource} */ source;
|
||||||
var tileGrid = tileSource.getTileGrid();
|
var tileGrid = tileSource.getTileGrid();
|
||||||
mapZ = tileGrid.getZForResolution(mapResolution);
|
mapZ = tileGrid.getZForResolution(mapResolution);
|
||||||
}
|
}
|
||||||
@@ -214,7 +214,7 @@ ol.control.Attribution.prototype.getLayerAttributionVisiblities_ =
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!goog.isNull(coverageAreas)) {
|
if (!goog.isNull(coverageAreas)) {
|
||||||
if (source instanceof ol.TileSource) {
|
if (source instanceof ol.source.TileSource) {
|
||||||
attributionVisible = goog.array.some(
|
attributionVisible = goog.array.some(
|
||||||
coverageAreas,
|
coverageAreas,
|
||||||
function(coverageArea, index) {
|
function(coverageArea, index) {
|
||||||
|
|||||||
@@ -1,9 +1,24 @@
|
|||||||
goog.provide('ol.layer.Layer');
|
goog.provide('ol.layer.Layer');
|
||||||
|
goog.provide('ol.layer.LayerOptions');
|
||||||
goog.provide('ol.layer.LayerProperty');
|
goog.provide('ol.layer.LayerProperty');
|
||||||
|
|
||||||
|
goog.require('goog.events');
|
||||||
|
goog.require('goog.events.EventType');
|
||||||
goog.require('goog.math');
|
goog.require('goog.math');
|
||||||
goog.require('ol.Object');
|
goog.require('ol.Object');
|
||||||
goog.require('ol.Source');
|
goog.require('ol.source.Source');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{brightness: (number|undefined),
|
||||||
|
* contrast: (number|undefined),
|
||||||
|
* hue: (number|undefined),
|
||||||
|
* opacity: (number|undefined),
|
||||||
|
* saturation: (number|undefined),
|
||||||
|
* source: ol.source.Source,
|
||||||
|
* visible: (boolean|undefined)}}
|
||||||
|
*/
|
||||||
|
ol.layer.LayerOptions;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,34 +38,47 @@ ol.layer.LayerProperty = {
|
|||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.Object}
|
* @extends {ol.Object}
|
||||||
* @param {ol.Source} source Source.
|
* @param {ol.layer.LayerOptions} layerOptions LayerOptions.
|
||||||
* @param {Object.<string, *>=} opt_values Values.
|
|
||||||
*/
|
*/
|
||||||
ol.layer.Layer = function(source, opt_values) {
|
ol.layer.Layer = function(layerOptions) {
|
||||||
|
|
||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.Source}
|
* @type {ol.source.Source}
|
||||||
*/
|
*/
|
||||||
this.source_ = source;
|
this.source_ = layerOptions.source;
|
||||||
|
|
||||||
this.setBrightness(0);
|
this.setBrightness(
|
||||||
this.setContrast(0);
|
goog.isDef(layerOptions.brightness) ? layerOptions.brightness : 0);
|
||||||
this.setHue(0);
|
this.setContrast(
|
||||||
this.setOpacity(1);
|
goog.isDef(layerOptions.contrast) ? layerOptions.contrast : 0);
|
||||||
this.setSaturation(0);
|
this.setHue(
|
||||||
this.setVisible(true);
|
goog.isDef(layerOptions.hue) ? layerOptions.hue : 0);
|
||||||
|
this.setOpacity(
|
||||||
|
goog.isDef(layerOptions.opacity) ? layerOptions.opacity : 1);
|
||||||
|
this.setSaturation(
|
||||||
|
goog.isDef(layerOptions.saturation) ? layerOptions.saturation : 0);
|
||||||
|
this.setVisible(
|
||||||
|
goog.isDef(layerOptions.visible) ? layerOptions.visible : true);
|
||||||
|
|
||||||
if (goog.isDef(opt_values)) {
|
if (!this.source_.isReady()) {
|
||||||
this.setValues(opt_values);
|
goog.events.listenOnce(this.source_, goog.events.EventType.LOAD,
|
||||||
|
this.handleSourceLoad_, false, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.layer.Layer, ol.Object);
|
goog.inherits(ol.layer.Layer, ol.Object);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
ol.layer.Layer.prototype.dispatchLoadEvent = function() {
|
||||||
|
this.dispatchEvent(goog.events.EventType.LOAD);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {number} Brightness.
|
* @return {number} Brightness.
|
||||||
*/
|
*/
|
||||||
@@ -112,7 +140,7 @@ goog.exportProperty(
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {ol.Source} Source.
|
* @return {ol.source.Source} Source.
|
||||||
*/
|
*/
|
||||||
ol.layer.Layer.prototype.getSource = function() {
|
ol.layer.Layer.prototype.getSource = function() {
|
||||||
return this.source_;
|
return this.source_;
|
||||||
@@ -131,6 +159,14 @@ goog.exportProperty(
|
|||||||
ol.layer.Layer.prototype.getVisible);
|
ol.layer.Layer.prototype.getVisible);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
ol.layer.Layer.prototype.handleSourceLoad_ = function() {
|
||||||
|
this.dispatchLoadEvent();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {boolean} Is ready.
|
* @return {boolean} Is ready.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
goog.provide('ol.layer.OpenStreetMap');
|
|
||||||
goog.provide('ol.source.OpenStreetMap');
|
|
||||||
|
|
||||||
goog.require('ol.TileUrlFunction');
|
|
||||||
goog.require('ol.layer.TileLayer');
|
|
||||||
goog.require('ol.source.XYZ');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @constructor
|
|
||||||
* @extends {ol.layer.TileLayer}
|
|
||||||
* @param {Object.<string, *>=} opt_values Values.
|
|
||||||
*/
|
|
||||||
ol.layer.OpenStreetMap = function(opt_values) {
|
|
||||||
var tileSource = new ol.source.OpenStreetMap();
|
|
||||||
goog.base(this, tileSource, opt_values);
|
|
||||||
};
|
|
||||||
goog.inherits(ol.layer.OpenStreetMap, ol.layer.TileLayer);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @constructor
|
|
||||||
* @extends {ol.source.XYZ}
|
|
||||||
*/
|
|
||||||
ol.source.OpenStreetMap = function() {
|
|
||||||
|
|
||||||
var tileUrlFunction = ol.TileUrlFunction.createFromTemplate(
|
|
||||||
'http://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png');
|
|
||||||
|
|
||||||
var attribution = new ol.Attribution(
|
|
||||||
'© <a href="http://www.openstreetmap.org">OpenStreetMap</a> ' +
|
|
||||||
'contributors, ' +
|
|
||||||
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA</a>');
|
|
||||||
|
|
||||||
goog.base(this, 18, tileUrlFunction, [attribution]);
|
|
||||||
|
|
||||||
};
|
|
||||||
goog.inherits(ol.source.OpenStreetMap, ol.source.XYZ);
|
|
||||||
@@ -1,25 +1,25 @@
|
|||||||
goog.provide('ol.layer.TileLayer');
|
goog.provide('ol.layer.TileLayer');
|
||||||
|
|
||||||
goog.require('ol.TileSource');
|
|
||||||
goog.require('ol.layer.Layer');
|
goog.require('ol.layer.Layer');
|
||||||
|
goog.require('ol.layer.LayerOptions');
|
||||||
|
goog.require('ol.source.TileSource');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.layer.Layer}
|
* @extends {ol.layer.Layer}
|
||||||
* @param {ol.TileSource} tileSource Tile source.
|
* @param {ol.layer.LayerOptions} layerOptions Layer options.
|
||||||
* @param {Object.<string, *>=} opt_values Values.
|
|
||||||
*/
|
*/
|
||||||
ol.layer.TileLayer = function(tileSource, opt_values) {
|
ol.layer.TileLayer = function(layerOptions) {
|
||||||
goog.base(this, tileSource, opt_values);
|
goog.base(this, layerOptions);
|
||||||
};
|
};
|
||||||
goog.inherits(ol.layer.TileLayer, ol.layer.Layer);
|
goog.inherits(ol.layer.TileLayer, ol.layer.Layer);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {ol.TileSource} Source.
|
* @return {ol.source.TileSource} Source.
|
||||||
*/
|
*/
|
||||||
ol.layer.TileLayer.prototype.getTileSource = function() {
|
ol.layer.TileLayer.prototype.getTileSource = function() {
|
||||||
return /** @type {ol.TileSource} */ this.getSource();
|
return /** @type {ol.source.TileSource} */ this.getSource();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
goog.provide('ol.layer.XYZ');
|
|
||||||
goog.provide('ol.source.XYZ');
|
|
||||||
goog.provide('ol.tilegrid.XYZ');
|
|
||||||
|
|
||||||
goog.require('goog.math');
|
|
||||||
goog.require('ol.Attribution');
|
|
||||||
goog.require('ol.Coordinate');
|
|
||||||
goog.require('ol.Projection');
|
|
||||||
goog.require('ol.Size');
|
|
||||||
goog.require('ol.TileCoord');
|
|
||||||
goog.require('ol.TileGrid');
|
|
||||||
goog.require('ol.TileSource');
|
|
||||||
goog.require('ol.TileUrlFunction');
|
|
||||||
goog.require('ol.layer.Layer');
|
|
||||||
goog.require('ol.layer.TileLayer');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @constructor
|
|
||||||
* @extends {ol.TileGrid}
|
|
||||||
* @param {number} maxZoom Maximum zoom.
|
|
||||||
* @param {ol.Size=} opt_tileSize Tile size.
|
|
||||||
*/
|
|
||||||
ol.tilegrid.XYZ = function(maxZoom, opt_tileSize) {
|
|
||||||
|
|
||||||
var resolutions = new Array(maxZoom + 1);
|
|
||||||
var z;
|
|
||||||
for (z = 0; z <= maxZoom; ++z) {
|
|
||||||
resolutions[z] = ol.Projection.EPSG_3857_HALF_SIZE / (128 << z);
|
|
||||||
}
|
|
||||||
|
|
||||||
var extent = ol.Projection.EPSG_3857_EXTENT;
|
|
||||||
var origin = new ol.Coordinate(
|
|
||||||
-ol.Projection.EPSG_3857_HALF_SIZE, ol.Projection.EPSG_3857_HALF_SIZE);
|
|
||||||
|
|
||||||
goog.base(this, resolutions, extent, origin, opt_tileSize);
|
|
||||||
|
|
||||||
};
|
|
||||||
goog.inherits(ol.tilegrid.XYZ, ol.TileGrid);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
ol.tilegrid.XYZ.prototype.forEachTileCoordParentTileRange =
|
|
||||||
function(tileCoord, callback, opt_obj) {
|
|
||||||
var x = tileCoord.x;
|
|
||||||
var y = tileCoord.y;
|
|
||||||
var z = tileCoord.z;
|
|
||||||
var tileRange;
|
|
||||||
while (true) {
|
|
||||||
z -= 1;
|
|
||||||
if (z < 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
x = Math.floor(x / 2);
|
|
||||||
y = Math.floor(y / 2);
|
|
||||||
tileRange = new ol.TileRange(x, y, x, y);
|
|
||||||
if (callback.call(opt_obj, z, tileRange)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @constructor
|
|
||||||
* @extends {ol.layer.TileLayer}
|
|
||||||
* @param {number} maxZoom Maximum zoom.
|
|
||||||
* @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL function.
|
|
||||||
* @param {Array.<ol.Attribution>=} opt_attributions Attributions.
|
|
||||||
* @param {string=} opt_crossOrigin Cross origin.
|
|
||||||
* @param {Object.<string, *>=} opt_values Values.
|
|
||||||
*/
|
|
||||||
ol.layer.XYZ = function(
|
|
||||||
maxZoom, tileUrlFunction, opt_attributions, opt_crossOrigin, opt_values) {
|
|
||||||
var tileSource = new ol.source.XYZ(
|
|
||||||
maxZoom, tileUrlFunction, opt_attributions, opt_crossOrigin);
|
|
||||||
goog.base(this, tileSource, opt_values);
|
|
||||||
};
|
|
||||||
goog.inherits(ol.layer.XYZ, ol.layer.TileLayer);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @constructor
|
|
||||||
* @extends {ol.TileSource}
|
|
||||||
* @param {number} maxZoom Maximum zoom.
|
|
||||||
* @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL function.
|
|
||||||
* @param {Array.<ol.Attribution>=} opt_attributions Attributions.
|
|
||||||
* @param {string=} opt_crossOrigin Cross origin.
|
|
||||||
*/
|
|
||||||
ol.source.XYZ =
|
|
||||||
function(maxZoom, tileUrlFunction, opt_attributions, opt_crossOrigin) {
|
|
||||||
|
|
||||||
var projection = ol.Projection.getFromCode('EPSG:3857');
|
|
||||||
var tileGrid = new ol.tilegrid.XYZ(maxZoom);
|
|
||||||
var tileUrlFunction2 = ol.TileUrlFunction.withTileCoordTransform(
|
|
||||||
function(tileCoord) {
|
|
||||||
var n = 1 << tileCoord.z;
|
|
||||||
var y = -tileCoord.y - 1;
|
|
||||||
if (y < 0 || n <= y) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
var x = goog.math.modulo(tileCoord.x, n);
|
|
||||||
return new ol.TileCoord(tileCoord.z, x, y);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
tileUrlFunction);
|
|
||||||
var extent = projection.getExtent();
|
|
||||||
|
|
||||||
goog.base(this, projection, tileGrid, tileUrlFunction2, extent,
|
|
||||||
opt_attributions, opt_crossOrigin);
|
|
||||||
|
|
||||||
};
|
|
||||||
goog.inherits(ol.source.XYZ, ol.TileSource);
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
goog.provide('ol.Source');
|
|
||||||
|
|
||||||
goog.require('goog.functions');
|
|
||||||
goog.require('ol.Attribution');
|
|
||||||
goog.require('ol.Extent');
|
|
||||||
goog.require('ol.Projection');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @constructor
|
|
||||||
* @param {ol.Projection} projection Projection.
|
|
||||||
* @param {ol.Extent=} opt_extent Extent.
|
|
||||||
* @param {Array.<ol.Attribution>=} opt_attributions Attributions.
|
|
||||||
*/
|
|
||||||
ol.Source = function(projection, opt_extent, opt_attributions) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {ol.Projection}
|
|
||||||
*/
|
|
||||||
this.projection_ = projection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {ol.Extent}
|
|
||||||
*/
|
|
||||||
this.extent_ = opt_extent || projection.getExtent();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {Array.<ol.Attribution>}
|
|
||||||
*/
|
|
||||||
this.attributions_ = opt_attributions || null;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {Array.<ol.Attribution>} Attributions.
|
|
||||||
*/
|
|
||||||
ol.Source.prototype.getAttributions = function() {
|
|
||||||
return this.attributions_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {ol.Extent} Extent.
|
|
||||||
*/
|
|
||||||
ol.Source.prototype.getExtent = function() {
|
|
||||||
return this.extent_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {ol.Projection} Projection.
|
|
||||||
*/
|
|
||||||
ol.Source.prototype.getProjection = function() {
|
|
||||||
return this.projection_;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {Array.<number>|undefined} Resolutions.
|
|
||||||
*/
|
|
||||||
ol.Source.prototype.getResolutions = goog.abstractMethod;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {boolean} Is ready.
|
|
||||||
*/
|
|
||||||
ol.Source.prototype.isReady = goog.functions.TRUE;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Array.<ol.Attribution>} attributions Attributions.
|
|
||||||
*/
|
|
||||||
ol.Source.prototype.setAttributions = function(attributions) {
|
|
||||||
this.attributions_ = attributions;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.Extent} extent Extent.
|
|
||||||
*/
|
|
||||||
ol.Source.prototype.setExtent = function(extent) {
|
|
||||||
this.extent_ = extent;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.Projection} projection Projetion.
|
|
||||||
*/
|
|
||||||
ol.Source.prototype.setProjection = function(projection) {
|
|
||||||
this.projection_ = projection;
|
|
||||||
};
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
goog.provide('ol.layer.BingMaps');
|
|
||||||
goog.provide('ol.source.BingMaps');
|
goog.provide('ol.source.BingMaps');
|
||||||
|
|
||||||
goog.require('goog.Uri');
|
goog.require('goog.Uri');
|
||||||
@@ -6,8 +5,7 @@ goog.require('goog.events');
|
|||||||
goog.require('goog.events.EventType');
|
goog.require('goog.events.EventType');
|
||||||
goog.require('goog.net.Jsonp');
|
goog.require('goog.net.Jsonp');
|
||||||
goog.require('ol.TileCoverageArea');
|
goog.require('ol.TileCoverageArea');
|
||||||
goog.require('ol.TileSource');
|
goog.require('ol.source.TileSource');
|
||||||
goog.require('ol.layer.TileLayer');
|
|
||||||
goog.require('ol.tilegrid.XYZ');
|
goog.require('ol.tilegrid.XYZ');
|
||||||
|
|
||||||
|
|
||||||
@@ -23,43 +21,32 @@ ol.BingMapsStyle = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @typedef {{culture: (string|undefined),
|
||||||
* @extends {ol.layer.TileLayer}
|
* key: string,
|
||||||
* @param {ol.BingMapsStyle} style Bing Maps style.
|
* style: ol.BingMapsStyle}}
|
||||||
* @param {string} key Key.
|
|
||||||
* @param {string=} opt_culture Culture.
|
|
||||||
* @param {Object.<string, *>=} opt_values Values.
|
|
||||||
*/
|
*/
|
||||||
ol.layer.BingMaps = function(style, key, opt_culture, opt_values) {
|
ol.source.BingMapsOptions;
|
||||||
var tileSource = new ol.source.BingMaps(style, key, opt_culture,
|
|
||||||
function(tileSource) {
|
|
||||||
this.dispatchEvent(goog.events.EventType.LOAD);
|
|
||||||
}, this);
|
|
||||||
goog.base(this, tileSource, opt_values);
|
|
||||||
};
|
|
||||||
goog.inherits(ol.layer.BingMaps, ol.layer.TileLayer);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.TileSource}
|
* @extends {ol.source.TileSource}
|
||||||
* @param {ol.BingMapsStyle} style Bing Maps style.
|
* @param {ol.source.BingMapsOptions} bingMapsOptions Bing Maps options.
|
||||||
* @param {string} key Key.
|
|
||||||
* @param {string=} opt_culture Culture.
|
|
||||||
* @param {?function(ol.source.BingMaps)=} opt_callback Callback.
|
|
||||||
* @param {*=} opt_obj Object.
|
|
||||||
*/
|
*/
|
||||||
ol.source.BingMaps =
|
ol.source.BingMaps = function(bingMapsOptions) {
|
||||||
function(style, key, opt_culture, opt_callback, opt_obj) {
|
|
||||||
|
goog.base(this, {
|
||||||
|
projection: ol.Projection.getFromCode('EPSG:3857')
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.culture_ = opt_culture || 'en-us';
|
this.culture_ = goog.isDef(bingMapsOptions.culture) ?
|
||||||
|
bingMapsOptions.culture : 'en-us';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -67,34 +54,17 @@ ol.source.BingMaps =
|
|||||||
*/
|
*/
|
||||||
this.ready_ = false;
|
this.ready_ = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {?function(ol.source.BingMaps)}
|
|
||||||
*/
|
|
||||||
this.callback_ = opt_callback || null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {*}
|
|
||||||
*/
|
|
||||||
this.object_ = opt_obj;
|
|
||||||
|
|
||||||
var uri = new goog.Uri(
|
var uri = new goog.Uri(
|
||||||
'http://dev.virtualearth.net/REST/v1/Imagery/Metadata/' + style);
|
'http://dev.virtualearth.net/REST/v1/Imagery/Metadata/' +
|
||||||
|
bingMapsOptions.style);
|
||||||
var jsonp = new goog.net.Jsonp(uri, 'jsonp');
|
var jsonp = new goog.net.Jsonp(uri, 'jsonp');
|
||||||
jsonp.send({
|
jsonp.send({
|
||||||
'include': 'ImageryProviders',
|
'include': 'ImageryProviders',
|
||||||
'key': key
|
'key': bingMapsOptions.key
|
||||||
}, goog.bind(this.handleImageryMetadataResponse, this));
|
}, goog.bind(this.handleImageryMetadataResponse, this));
|
||||||
|
|
||||||
var projection = ol.Projection.getFromCode('EPSG:3857');
|
|
||||||
var extent = projection.getExtent();
|
|
||||||
|
|
||||||
goog.base(
|
|
||||||
this, projection, null, ol.TileUrlFunction.nullTileUrlFunction, extent);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.source.BingMaps, ol.TileSource);
|
goog.inherits(ol.source.BingMaps, ol.source.TileSource);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,7 +88,10 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse =
|
|||||||
var zoomMin = resource.zoomMin;
|
var zoomMin = resource.zoomMin;
|
||||||
var zoomMax = resource.zoomMax;
|
var zoomMax = resource.zoomMax;
|
||||||
var tileSize = new ol.Size(resource.imageWidth, resource.imageHeight);
|
var tileSize = new ol.Size(resource.imageWidth, resource.imageHeight);
|
||||||
var tileGrid = new ol.tilegrid.XYZ(zoomMax, tileSize);
|
var tileGrid = new ol.tilegrid.XYZ({
|
||||||
|
maxZoom: zoomMax,
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
this.tileGrid = tileGrid;
|
this.tileGrid = tileGrid;
|
||||||
|
|
||||||
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||||
@@ -172,11 +145,7 @@ ol.source.BingMaps.prototype.handleImageryMetadataResponse =
|
|||||||
|
|
||||||
this.ready_ = true;
|
this.ready_ = true;
|
||||||
|
|
||||||
if (!goog.isNull(this.callback_)) {
|
this.dispatchLoadEvent();
|
||||||
this.callback_.call(this.object_, this);
|
|
||||||
this.callback_ = null;
|
|
||||||
this.object_ = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1,21 +1,16 @@
|
|||||||
goog.provide('ol.layer.MapQuestOSM');
|
goog.provide('ol.source.MapQuestOSM');
|
||||||
goog.provide('ol.layer.MapQuestOpenAerial');
|
goog.provide('ol.source.MapQuestOpenAerial');
|
||||||
|
|
||||||
goog.require('ol.Attribution');
|
goog.require('ol.Attribution');
|
||||||
goog.require('ol.TileUrlFunction');
|
goog.require('ol.source.XYZ');
|
||||||
goog.require('ol.layer.XYZ');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.layer.XYZ}
|
* @extends {ol.source.XYZ}
|
||||||
* @param {Object.<string, *>=} opt_values Values.
|
|
||||||
*/
|
*/
|
||||||
ol.layer.MapQuestOSM = function(opt_values) {
|
ol.source.MapQuestOSM = function() {
|
||||||
|
|
||||||
var tileUrlFunction = ol.TileUrlFunction.createFromTemplate(
|
|
||||||
'http://otile{1-4}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg');
|
|
||||||
|
|
||||||
var attributions = [
|
var attributions = [
|
||||||
new ol.Attribution(
|
new ol.Attribution(
|
||||||
@@ -29,22 +24,22 @@ ol.layer.MapQuestOSM = function(opt_values) {
|
|||||||
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA</a>')
|
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA</a>')
|
||||||
];
|
];
|
||||||
|
|
||||||
goog.base(this, 18, tileUrlFunction, attributions);
|
goog.base(this, {
|
||||||
|
attributions: attributions,
|
||||||
|
maxZoom: 28,
|
||||||
|
url: 'http://otile{1-4}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg'
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.layer.MapQuestOSM, ol.layer.XYZ);
|
goog.inherits(ol.source.MapQuestOSM, ol.source.XYZ);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.layer.XYZ}
|
* @extends {ol.source.XYZ}
|
||||||
* @param {Object.<string, *>=} opt_values Values.
|
|
||||||
*/
|
*/
|
||||||
ol.layer.MapQuestOpenAerial = function(opt_values) {
|
ol.source.MapQuestOpenAerial = function() {
|
||||||
|
|
||||||
var tileUrlFunction = ol.TileUrlFunction.createFromTemplate(
|
|
||||||
'http://oatile{1-4}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg');
|
|
||||||
|
|
||||||
var attributions = [
|
var attributions = [
|
||||||
new ol.Attribution(
|
new ol.Attribution(
|
||||||
@@ -56,7 +51,11 @@ ol.layer.MapQuestOpenAerial = function(opt_values) {
|
|||||||
'U.S. Depart. of Agriculture, Farm Service Agency')
|
'U.S. Depart. of Agriculture, Farm Service Agency')
|
||||||
];
|
];
|
||||||
|
|
||||||
goog.base(this, 18, tileUrlFunction, attributions);
|
goog.base(this, {
|
||||||
|
attributions: attributions,
|
||||||
|
maxZoom: 18,
|
||||||
|
url: 'http://oatile{1-4}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg'
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.layer.MapQuestOpenAerial, ol.layer.XYZ);
|
goog.inherits(ol.source.MapQuestOpenAerial, ol.source.XYZ);
|
||||||
25
src/ol/source/openstreetmap.js
Normal file
25
src/ol/source/openstreetmap.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
goog.provide('ol.source.OpenStreetMap');
|
||||||
|
|
||||||
|
goog.require('ol.source.XYZ');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @extends {ol.source.XYZ}
|
||||||
|
*/
|
||||||
|
ol.source.OpenStreetMap = function() {
|
||||||
|
|
||||||
|
var attribution = new ol.Attribution(
|
||||||
|
'© <a href="http://www.openstreetmap.org">OpenStreetMap</a> ' +
|
||||||
|
'contributors, ' +
|
||||||
|
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA</a>');
|
||||||
|
|
||||||
|
goog.base(this, {
|
||||||
|
attributions: [attribution],
|
||||||
|
maxZoom: 18,
|
||||||
|
url: 'http://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
goog.inherits(ol.source.OpenStreetMap, ol.source.XYZ);
|
||||||
119
src/ol/source/source.js
Normal file
119
src/ol/source/source.js
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
goog.provide('ol.source.Source');
|
||||||
|
|
||||||
|
goog.require('goog.events.EventTarget');
|
||||||
|
goog.require('goog.events.EventType');
|
||||||
|
goog.require('goog.functions');
|
||||||
|
goog.require('ol.Attribution');
|
||||||
|
goog.require('ol.Extent');
|
||||||
|
goog.require('ol.Projection');
|
||||||
|
goog.require('ol.TileUrlFunction');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{attribtions: (Array.<ol.Attribution>|undefined),
|
||||||
|
* extent: (ol.Extent|undefined),
|
||||||
|
* projection: (ol.Projection|undefined)}}
|
||||||
|
*/
|
||||||
|
ol.source.SourceOptions;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @extends {goog.events.EventTarget}
|
||||||
|
* @param {ol.source.SourceOptions} sourceOptions Source options.
|
||||||
|
*/
|
||||||
|
ol.source.Source = function(sourceOptions) {
|
||||||
|
|
||||||
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.Projection}
|
||||||
|
*/
|
||||||
|
this.projection_ = goog.isDef(sourceOptions.projection) ?
|
||||||
|
sourceOptions.projection : null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {ol.Extent}
|
||||||
|
*/
|
||||||
|
this.extent_ = goog.isDef(sourceOptions.extent) ?
|
||||||
|
sourceOptions.extent : sourceOptions.projection.getExtent();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {Array.<ol.Attribution>}
|
||||||
|
*/
|
||||||
|
this.attributions_ = goog.isDef(sourceOptions.attributions) ?
|
||||||
|
sourceOptions.attributions : null;
|
||||||
|
|
||||||
|
};
|
||||||
|
goog.inherits(ol.source.Source, goog.events.EventTarget);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
ol.source.Source.prototype.dispatchLoadEvent = function() {
|
||||||
|
this.dispatchEvent(goog.events.EventType.LOAD);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Array.<ol.Attribution>} Attributions.
|
||||||
|
*/
|
||||||
|
ol.source.Source.prototype.getAttributions = function() {
|
||||||
|
return this.attributions_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {ol.Extent} Extent.
|
||||||
|
*/
|
||||||
|
ol.source.Source.prototype.getExtent = function() {
|
||||||
|
return this.extent_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {ol.Projection} Projection.
|
||||||
|
*/
|
||||||
|
ol.source.Source.prototype.getProjection = function() {
|
||||||
|
return this.projection_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {Array.<number>|undefined} Resolutions.
|
||||||
|
*/
|
||||||
|
ol.source.Source.prototype.getResolutions = goog.abstractMethod;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {boolean} Is ready.
|
||||||
|
*/
|
||||||
|
ol.source.Source.prototype.isReady = goog.functions.TRUE;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Array.<ol.Attribution>} attributions Attributions.
|
||||||
|
*/
|
||||||
|
ol.source.Source.prototype.setAttributions = function(attributions) {
|
||||||
|
this.attributions_ = attributions;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.Extent} extent Extent.
|
||||||
|
*/
|
||||||
|
ol.source.Source.prototype.setExtent = function(extent) {
|
||||||
|
this.extent_ = extent;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.Projection} projection Projetion.
|
||||||
|
*/
|
||||||
|
ol.source.Source.prototype.setProjection = function(projection) {
|
||||||
|
this.projection_ = projection;
|
||||||
|
};
|
||||||
@@ -1,26 +1,14 @@
|
|||||||
// FIXME Configure minZoom when supported by TileGrid
|
// FIXME Configure minZoom when supported by TileGrid
|
||||||
|
|
||||||
goog.provide('ol.layer.Stamen');
|
|
||||||
goog.provide('ol.source.Stamen');
|
goog.provide('ol.source.Stamen');
|
||||||
|
|
||||||
goog.require('ol.TileUrlFunction');
|
goog.require('ol.source.XYZ');
|
||||||
goog.require('ol.layer.XYZ');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
ol.StamenProvider = {
|
ol.source.StamenFlavor = {
|
||||||
TERRAIN: 'terrain',
|
|
||||||
TONER: 'toner',
|
|
||||||
WATERCOLOR: 'watercolor'
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @enum {string}
|
|
||||||
*/
|
|
||||||
ol.StamenFlavor = {
|
|
||||||
TERRAIN_BACKGROUND: 'background',
|
TERRAIN_BACKGROUND: 'background',
|
||||||
TERRAIN_LABELS: 'labels',
|
TERRAIN_LABELS: 'labels',
|
||||||
TERRAIN_LINES: 'lines',
|
TERRAIN_LINES: 'lines',
|
||||||
@@ -38,21 +26,38 @@ ol.StamenFlavor = {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Object.<ol.StamenProvider,
|
* @typedef {{flavor: ol.source.StamenFlavor,
|
||||||
|
* provider: ol.source.StamenProvider}}
|
||||||
|
*/
|
||||||
|
ol.source.StamenOptions;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @enum {string}
|
||||||
|
*/
|
||||||
|
ol.source.StamenProvider = {
|
||||||
|
TERRAIN: 'terrain',
|
||||||
|
TONER: 'toner',
|
||||||
|
WATERCOLOR: 'watercolor'
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Object.<ol.source.StamenProvider,
|
||||||
* {type: string, minZoom: number, maxZoom: number}>}
|
* {type: string, minZoom: number, maxZoom: number}>}
|
||||||
*/
|
*/
|
||||||
ol.StamenProviderConfig = {};
|
ol.source.StamenProviderConfig = {};
|
||||||
ol.StamenProviderConfig[ol.StamenProvider.TERRAIN] = {
|
ol.source.StamenProviderConfig[ol.source.StamenProvider.TERRAIN] = {
|
||||||
type: 'jpg',
|
type: 'jpg',
|
||||||
minZoom: 4,
|
minZoom: 4,
|
||||||
maxZoom: 18
|
maxZoom: 18
|
||||||
};
|
};
|
||||||
ol.StamenProviderConfig[ol.StamenProvider.TONER] = {
|
ol.source.StamenProviderConfig[ol.source.StamenProvider.TONER] = {
|
||||||
type: 'png',
|
type: 'png',
|
||||||
minZoom: 0,
|
minZoom: 0,
|
||||||
maxZoom: 20
|
maxZoom: 20
|
||||||
};
|
};
|
||||||
ol.StamenProviderConfig[ol.StamenProvider.WATERCOLOR] = {
|
ol.source.StamenProviderConfig[ol.source.StamenProvider.WATERCOLOR] = {
|
||||||
type: 'jpg',
|
type: 'jpg',
|
||||||
minZoom: 3,
|
minZoom: 3,
|
||||||
maxZoom: 16
|
maxZoom: 16
|
||||||
@@ -62,21 +67,10 @@ ol.StamenProviderConfig[ol.StamenProvider.WATERCOLOR] = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.layer.XYZ}
|
* @extends {ol.source.XYZ}
|
||||||
* @param {ol.StamenProvider} provider Provider.
|
* @param {ol.source.StamenOptions} stamenOptions Stamen options.
|
||||||
* @param {ol.StamenFlavor=} opt_flavor Flavor.
|
|
||||||
* @param {Object.<string, *>=} opt_values Values.
|
|
||||||
*/
|
*/
|
||||||
ol.layer.Stamen = function(provider, opt_flavor, opt_values) {
|
ol.source.Stamen = function(stamenOptions) {
|
||||||
|
|
||||||
var config = ol.StamenProviderConfig[provider];
|
|
||||||
|
|
||||||
var layer = provider;
|
|
||||||
if (goog.isDef(opt_flavor)) {
|
|
||||||
layer += '-' + opt_flavor;
|
|
||||||
}
|
|
||||||
var tileUrlFunction = ol.TileUrlFunction.createFromTemplate(
|
|
||||||
'http://{a-d}.tile.stamen.com/' + layer + '/{z}/{x}/{y}.' + config.type);
|
|
||||||
|
|
||||||
var attribution = new ol.Attribution(
|
var attribution = new ol.Attribution(
|
||||||
'Map tiles by <a href="http://stamen.com">Stamen Design</a>, ' +
|
'Map tiles by <a href="http://stamen.com">Stamen Design</a>, ' +
|
||||||
@@ -86,7 +80,18 @@ ol.layer.Stamen = function(provider, opt_flavor, opt_values) {
|
|||||||
'under ' +
|
'under ' +
|
||||||
'<a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.');
|
'<a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.');
|
||||||
|
|
||||||
goog.base(this, config.maxZoom, tileUrlFunction, [attribution]);
|
var layer = stamenOptions.provider;
|
||||||
|
if (goog.isDef(stamenOptions.flavor)) {
|
||||||
|
layer += '-' + stamenOptions.flavor;
|
||||||
|
}
|
||||||
|
|
||||||
|
var config = ol.source.StamenProviderConfig[stamenOptions.provider];
|
||||||
|
|
||||||
|
goog.base(this, {
|
||||||
|
attributions: [attribution],
|
||||||
|
maxZoom: config.maxZoom,
|
||||||
|
url: 'http://{a-d}.tile.stamen.com/' + layer + '/{z}/{x}/{y}.' + config.type
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.layer.Stamen, ol.layer.XYZ);
|
goog.inherits(ol.source.Stamen, ol.source.XYZ);
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
// FIXME add some error checking
|
// FIXME add some error checking
|
||||||
// FIXME check order of async callbacks
|
// FIXME check order of async callbacks
|
||||||
// FIXME use minzoom when supported by ol.TileGrid
|
// FIXME use minzoom when supported by ol.tilegrid.TileGrid
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see http://mapbox.com/developers/api/
|
* @see http://mapbox.com/developers/api/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
goog.provide('ol.layer.TileJSON');
|
|
||||||
goog.provide('ol.source.TileJSON');
|
goog.provide('ol.source.TileJSON');
|
||||||
goog.provide('ol.tilejson');
|
goog.provide('ol.tilejson');
|
||||||
|
|
||||||
@@ -14,10 +13,16 @@ goog.require('goog.asserts');
|
|||||||
goog.require('goog.events.EventType');
|
goog.require('goog.events.EventType');
|
||||||
goog.require('goog.net.jsloader');
|
goog.require('goog.net.jsloader');
|
||||||
goog.require('goog.string');
|
goog.require('goog.string');
|
||||||
|
goog.require('ol.Projection');
|
||||||
goog.require('ol.TileCoverageArea');
|
goog.require('ol.TileCoverageArea');
|
||||||
goog.require('ol.TileSource');
|
|
||||||
goog.require('ol.TileUrlFunction');
|
goog.require('ol.TileUrlFunction');
|
||||||
goog.require('ol.layer.TileLayer');
|
goog.require('ol.source.TileSource');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{uri: string}}
|
||||||
|
*/
|
||||||
|
ol.source.TileJSONOptions;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,46 +44,14 @@ goog.exportSymbol('grid', grid);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.layer.TileLayer}
|
* @extends {ol.source.TileSource}
|
||||||
* @param {string} url URL.
|
* @param {ol.source.TileJSONOptions} tileJsonOptions TileJSON optios.
|
||||||
* @param {Object.<string, *>=} opt_values Values.
|
|
||||||
*/
|
*/
|
||||||
ol.layer.TileJSON = function(url, opt_values) {
|
ol.source.TileJSON = function(tileJsonOptions) {
|
||||||
goog.asserts.assert(goog.string.endsWith(url, '.jsonp'));
|
|
||||||
var tileSource = new ol.source.TileJSON(url, function(tileSource) {
|
|
||||||
this.dispatchEvent(goog.events.EventType.LOAD);
|
|
||||||
}, this);
|
|
||||||
goog.base(this, tileSource, opt_values);
|
|
||||||
};
|
|
||||||
goog.inherits(ol.layer.TileJSON, ol.layer.TileLayer);
|
|
||||||
|
|
||||||
|
goog.base(this, {
|
||||||
|
projection: ol.Projection.getFromCode('EPSG:3857')
|
||||||
/**
|
});
|
||||||
* @constructor
|
|
||||||
* @extends {ol.TileSource}
|
|
||||||
* @param {string} uri URI.
|
|
||||||
* @param {?function(ol.source.TileJSON)=} opt_callback Callback.
|
|
||||||
* @param {*=} opt_obj Object.
|
|
||||||
*/
|
|
||||||
ol.source.TileJSON = function(uri, opt_callback, opt_obj) {
|
|
||||||
|
|
||||||
var projection = ol.Projection.getFromCode('EPSG:3857');
|
|
||||||
|
|
||||||
goog.base(
|
|
||||||
this, projection, null, ol.TileUrlFunction.nullTileUrlFunction, null);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {?function(ol.source.TileJSON)}
|
|
||||||
*/
|
|
||||||
this.callback_ = opt_callback || null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {*}
|
|
||||||
*/
|
|
||||||
this.object_ = opt_obj;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -90,11 +63,12 @@ ol.source.TileJSON = function(uri, opt_callback, opt_obj) {
|
|||||||
* @private
|
* @private
|
||||||
* @type {!goog.async.Deferred}
|
* @type {!goog.async.Deferred}
|
||||||
*/
|
*/
|
||||||
this.deferred_ = goog.net.jsloader.load(uri, {cleanupWhenDone: true});
|
this.deferred_ =
|
||||||
|
goog.net.jsloader.load(tileJsonOptions.uri, {cleanupWhenDone: true});
|
||||||
this.deferred_.addCallback(this.handleTileJSONResponse, this);
|
this.deferred_.addCallback(this.handleTileJSONResponse, this);
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.source.TileJSON, ol.TileSource);
|
goog.inherits(ol.source.TileJSON, ol.source.TileSource);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,7 +100,9 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function() {
|
|||||||
var minzoom = tileJSON.minzoom || 0;
|
var minzoom = tileJSON.minzoom || 0;
|
||||||
goog.asserts.assert(minzoom === 0); // FIXME
|
goog.asserts.assert(minzoom === 0); // FIXME
|
||||||
var maxzoom = tileJSON.maxzoom || 22;
|
var maxzoom = tileJSON.maxzoom || 22;
|
||||||
var tileGrid = new ol.tilegrid.XYZ(maxzoom);
|
var tileGrid = new ol.tilegrid.XYZ({
|
||||||
|
maxZoom: maxzoom
|
||||||
|
});
|
||||||
this.tileGrid = tileGrid;
|
this.tileGrid = tileGrid;
|
||||||
|
|
||||||
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
this.tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||||
@@ -164,11 +140,7 @@ ol.source.TileJSON.prototype.handleTileJSONResponse = function() {
|
|||||||
|
|
||||||
this.ready_ = true;
|
this.ready_ = true;
|
||||||
|
|
||||||
if (!goog.isNull(this.callback_)) {
|
this.dispatchLoadEvent();
|
||||||
this.callback_.call(this.object_, this);
|
|
||||||
this.callback_ = null;
|
|
||||||
this.object_ = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
118
src/ol/source/tilesource.js
Normal file
118
src/ol/source/tilesource.js
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
goog.provide('ol.source.TileSource');
|
||||||
|
goog.provide('ol.source.TileSourceOptions');
|
||||||
|
|
||||||
|
goog.require('ol.Attribution');
|
||||||
|
goog.require('ol.Extent');
|
||||||
|
goog.require('ol.Projection');
|
||||||
|
goog.require('ol.Tile');
|
||||||
|
goog.require('ol.TileCoord');
|
||||||
|
goog.require('ol.TileUrlFunction');
|
||||||
|
goog.require('ol.TileUrlFunctionType');
|
||||||
|
goog.require('ol.source.Source');
|
||||||
|
goog.require('ol.tilegrid.TileGrid');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
|
||||||
|
* crossOrigin: (string|undefined),
|
||||||
|
* extent: (ol.Extent|undefined),
|
||||||
|
* projection: (ol.Projection|undefined),
|
||||||
|
* tileGrid: (ol.tilegrid.TileGrid|undefined),
|
||||||
|
* tileUrlFunction: (ol.TileUrlFunctionType|undefined)}}
|
||||||
|
*/
|
||||||
|
ol.source.TileSourceOptions;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @extends {ol.source.Source}
|
||||||
|
* @param {ol.source.TileSourceOptions} tileSourceOptions Tile source options.
|
||||||
|
*/
|
||||||
|
ol.source.TileSource = function(tileSourceOptions) {
|
||||||
|
|
||||||
|
goog.base(this, {
|
||||||
|
attributions: tileSourceOptions.attributions,
|
||||||
|
extent: tileSourceOptions.extent,
|
||||||
|
projection: tileSourceOptions.projection
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @protected
|
||||||
|
* @type {ol.tilegrid.TileGrid}
|
||||||
|
*/
|
||||||
|
this.tileGrid = goog.isDef(tileSourceOptions.tileGrid) ?
|
||||||
|
tileSourceOptions.tileGrid : null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @protected
|
||||||
|
* @type {ol.TileUrlFunctionType}
|
||||||
|
*/
|
||||||
|
this.tileUrlFunction = goog.isDef(tileSourceOptions.tileUrlFunction) ?
|
||||||
|
tileSourceOptions.tileUrlFunction :
|
||||||
|
ol.TileUrlFunction.nullTileUrlFunction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {?string}
|
||||||
|
*/
|
||||||
|
this.crossOrigin_ = goog.isDef(tileSourceOptions.crossOrigin) ?
|
||||||
|
tileSourceOptions.crossOrigin : 'anonymous';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {Object.<string, ol.Tile>}
|
||||||
|
* FIXME will need to expire elements from this cache
|
||||||
|
* FIXME see elemoine's work with goog.structs.LinkedMap
|
||||||
|
*/
|
||||||
|
this.tileCache_ = {};
|
||||||
|
|
||||||
|
};
|
||||||
|
goog.inherits(ol.source.TileSource, ol.source.Source);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.source.TileSource.prototype.getResolutions = function() {
|
||||||
|
return this.tileGrid.getResolutions();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||||
|
* @return {ol.Tile} Tile.
|
||||||
|
*/
|
||||||
|
ol.source.TileSource.prototype.getTile = function(tileCoord) {
|
||||||
|
var key = tileCoord.toString();
|
||||||
|
if (goog.object.containsKey(this.tileCache_, key)) {
|
||||||
|
return this.tileCache_[key];
|
||||||
|
} else {
|
||||||
|
var tileUrl = this.getTileCoordUrl(tileCoord);
|
||||||
|
var tile;
|
||||||
|
if (goog.isDef(tileUrl)) {
|
||||||
|
tile = new ol.Tile(tileCoord, tileUrl, this.crossOrigin_);
|
||||||
|
} else {
|
||||||
|
tile = null;
|
||||||
|
}
|
||||||
|
this.tileCache_[key] = tile;
|
||||||
|
return tile;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||||
|
* @return {string|undefined} Tile URL.
|
||||||
|
*/
|
||||||
|
ol.source.TileSource.prototype.getTileCoordUrl = function(tileCoord) {
|
||||||
|
return this.tileUrlFunction(tileCoord);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {ol.tilegrid.TileGrid} Tile grid.
|
||||||
|
*/
|
||||||
|
ol.source.TileSource.prototype.getTileGrid = function() {
|
||||||
|
return this.tileGrid;
|
||||||
|
};
|
||||||
109
src/ol/source/xyz.js
Normal file
109
src/ol/source/xyz.js
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
// FIXME add minZoom support
|
||||||
|
|
||||||
|
goog.provide('ol.source.XYZ');
|
||||||
|
goog.provide('ol.source.XYZOptions');
|
||||||
|
|
||||||
|
goog.require('goog.math');
|
||||||
|
goog.require('ol.Attribution');
|
||||||
|
goog.require('ol.Coordinate');
|
||||||
|
goog.require('ol.Projection');
|
||||||
|
goog.require('ol.Size');
|
||||||
|
goog.require('ol.TileCoord');
|
||||||
|
goog.require('ol.TileUrlFunction');
|
||||||
|
goog.require('ol.TileUrlFunctionType');
|
||||||
|
goog.require('ol.source.TileSource');
|
||||||
|
goog.require('ol.tilegrid.XYZ');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
|
||||||
|
* crossOrigin: (string|undefined),
|
||||||
|
* extent: (ol.Extent|undefined),
|
||||||
|
* maxZoom: number,
|
||||||
|
* tileUrlFunction: (ol.TileUrlFunctionType|undefined),
|
||||||
|
* url: (string|undefined),
|
||||||
|
* urls: (Array.<string>|undefined)}}
|
||||||
|
*/
|
||||||
|
ol.source.XYZOptions;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @extends {ol.source.TileSource}
|
||||||
|
* @param {ol.source.XYZOptions} xyzOptions XYZ options.
|
||||||
|
*/
|
||||||
|
ol.source.XYZ = function(xyzOptions) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {ol.TileUrlFunctionType}
|
||||||
|
*/
|
||||||
|
var tileUrlFunction = ol.TileUrlFunction.nullTileUrlFunction;
|
||||||
|
// FIXME use goog.nullFunction ?
|
||||||
|
if (goog.isDef(xyzOptions.tileUrlFunction)) {
|
||||||
|
tileUrlFunction = xyzOptions.tileUrlFunction;
|
||||||
|
} else if (goog.isDef(xyzOptions.urls)) {
|
||||||
|
tileUrlFunction = ol.TileUrlFunction.createFromTemplates(xyzOptions.urls);
|
||||||
|
} else if (goog.isDef(xyzOptions.url)) {
|
||||||
|
tileUrlFunction = ol.TileUrlFunction.createFromTemplate(xyzOptions.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
var tileGrid = new ol.tilegrid.XYZ({
|
||||||
|
maxZoom: xyzOptions.maxZoom
|
||||||
|
});
|
||||||
|
|
||||||
|
// FIXME factor out common code
|
||||||
|
var extent = xyzOptions.extent;
|
||||||
|
if (goog.isDefAndNotNull(extent)) {
|
||||||
|
|
||||||
|
tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||||
|
function(tileCoord) {
|
||||||
|
if (xyzOptions.maxZoom < tileCoord.z) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var n = 1 << tileCoord.z;
|
||||||
|
var y = -tileCoord.y - 1;
|
||||||
|
if (y < 0 || n <= y) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var x = goog.math.modulo(tileCoord.x, n);
|
||||||
|
var tileExtent = tileGrid.getTileCoordExtent(
|
||||||
|
new ol.TileCoord(tileCoord.z, x, tileCoord.y));
|
||||||
|
// FIXME we shouldn't need a typecast here
|
||||||
|
if (!tileExtent.intersects(/** @type {ol.Extent} */ (extent))) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new ol.TileCoord(tileCoord.z, x, y);
|
||||||
|
},
|
||||||
|
tileUrlFunction);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||||
|
function(tileCoord) {
|
||||||
|
if (xyzOptions.maxZoom < tileCoord.z) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var n = 1 << tileCoord.z;
|
||||||
|
var y = -tileCoord.y - 1;
|
||||||
|
if (y < 0 || n <= y) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
var x = goog.math.modulo(tileCoord.x, n);
|
||||||
|
return new ol.TileCoord(tileCoord.z, x, y);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tileUrlFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
goog.base(this, {
|
||||||
|
attributions: xyzOptions.attributions,
|
||||||
|
crossOrigin: xyzOptions.crossOrigin,
|
||||||
|
extent: xyzOptions.extent,
|
||||||
|
projection: ol.Projection.getFromCode('EPSG:3857'),
|
||||||
|
tileGrid: tileGrid,
|
||||||
|
tileUrlFunction: tileUrlFunction
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
goog.inherits(ol.source.XYZ, ol.source.TileSource);
|
||||||
@@ -2,14 +2,14 @@ goog.provide('ol.TileCoverageArea');
|
|||||||
|
|
||||||
goog.require('ol.CoverageArea');
|
goog.require('ol.CoverageArea');
|
||||||
goog.require('ol.Extent');
|
goog.require('ol.Extent');
|
||||||
goog.require('ol.TileGrid');
|
goog.require('ol.tilegrid.TileGrid');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.CoverageArea}
|
* @extends {ol.CoverageArea}
|
||||||
* @param {ol.TileGrid} tileGrid Tile grid.
|
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
|
||||||
* @param {ol.Extent} extent Extent.
|
* @param {ol.Extent} extent Extent.
|
||||||
* @param {number} minZ Minimum Z.
|
* @param {number} minZ Minimum Z.
|
||||||
* @param {number} maxZ Maximum Z.
|
* @param {number} maxZ Maximum Z.
|
||||||
@@ -20,7 +20,7 @@ ol.TileCoverageArea = function(tileGrid, extent, minZ, maxZ) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.TileGrid}
|
* @type {ol.tilegrid.TileGrid}
|
||||||
*/
|
*/
|
||||||
this.tileGrid_ = tileGrid;
|
this.tileGrid_ = tileGrid;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// FIXME cope with tile grids whose minium zoom is not zero
|
// FIXME cope with tile grids whose minium zoom is not zero
|
||||||
|
|
||||||
goog.provide('ol.TileGrid');
|
goog.provide('ol.tilegrid.TileGrid');
|
||||||
|
goog.provide('ol.tilegrid.TileGridOptions');
|
||||||
|
|
||||||
goog.require('goog.array');
|
goog.require('goog.array');
|
||||||
goog.require('goog.asserts');
|
goog.require('goog.asserts');
|
||||||
@@ -13,22 +14,29 @@ goog.require('ol.TileRange');
|
|||||||
goog.require('ol.array');
|
goog.require('ol.array');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{extent: (ol.Extent|undefined),
|
||||||
|
* origin: (ol.Coordinate|undefined),
|
||||||
|
* origins: (Array.<ol.Coordinate>|undefined),
|
||||||
|
* resolutions: !Array.<number>,
|
||||||
|
* tileSize: (ol.Size|undefined)}}
|
||||||
|
*/
|
||||||
|
ol.tilegrid.TileGridOptions;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {!Array.<number>} resolutions Resolutions.
|
* @param {ol.tilegrid.TileGridOptions} tileGridOptions Tile grid options.
|
||||||
* @param {ol.Extent} extent Extent.
|
|
||||||
* @param {ol.Coordinate|!Array.<ol.Coordinate>} origin Origin.
|
|
||||||
* @param {ol.Size=} opt_tileSize Tile size.
|
|
||||||
*/
|
*/
|
||||||
ol.TileGrid = function(resolutions, extent, origin, opt_tileSize) {
|
ol.tilegrid.TileGrid = function(tileGridOptions) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Array.<number>}
|
* @type {!Array.<number>}
|
||||||
*/
|
*/
|
||||||
this.resolutions_ = resolutions;
|
this.resolutions_ = tileGridOptions.resolutions;
|
||||||
goog.asserts.assert(goog.array.isSorted(resolutions, function(a, b) {
|
goog.asserts.assert(goog.array.isSorted(this.resolutions_, function(a, b) {
|
||||||
return b - a;
|
return b - a;
|
||||||
}, true));
|
}, true));
|
||||||
|
|
||||||
@@ -42,34 +50,32 @@ ol.TileGrid = function(resolutions, extent, origin, opt_tileSize) {
|
|||||||
* @private
|
* @private
|
||||||
* @type {ol.Extent}
|
* @type {ol.Extent}
|
||||||
*/
|
*/
|
||||||
this.extent_ = extent;
|
this.extent_ = goog.isDef(tileGridOptions.extent) ?
|
||||||
|
tileGridOptions.extent : null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.Coordinate}
|
* @type {ol.Coordinate}
|
||||||
*/
|
*/
|
||||||
this.origin_ = null;
|
this.origin_ = goog.isDef(tileGridOptions.origin) ?
|
||||||
|
tileGridOptions.origin : null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Array.<ol.Coordinate>}
|
* @type {Array.<ol.Coordinate>}
|
||||||
*/
|
*/
|
||||||
this.origins_ = null;
|
this.origins_ = null;
|
||||||
|
if (goog.isDef(tileGridOptions.origins)) {
|
||||||
if (origin instanceof ol.Coordinate) {
|
this.origins_ = tileGridOptions.origins;
|
||||||
this.origin_ = origin;
|
goog.asserts.assert(this.origins_.length == this.resolutions_.length);
|
||||||
} else if (goog.isArray(origin)) {
|
|
||||||
goog.asserts.assert(origin.length == this.numResolutions_);
|
|
||||||
this.origins_ = origin;
|
|
||||||
} else {
|
|
||||||
goog.asserts.assert(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.Size}
|
* @type {ol.Size}
|
||||||
*/
|
*/
|
||||||
this.tileSize_ = opt_tileSize || new ol.Size(256, 256);
|
this.tileSize_ = goog.isDef(tileGridOptions.tileSize) ?
|
||||||
|
tileGridOptions.tileSize : new ol.Size(256, 256);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,7 +87,7 @@ ol.TileGrid = function(resolutions, extent, origin, opt_tileSize) {
|
|||||||
* @param {T=} opt_obj Object.
|
* @param {T=} opt_obj Object.
|
||||||
* @template T
|
* @template T
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.forEachTileCoordParentTileRange =
|
ol.tilegrid.TileGrid.prototype.forEachTileCoordParentTileRange =
|
||||||
function(tileCoord, callback, opt_obj) {
|
function(tileCoord, callback, opt_obj) {
|
||||||
var tileCoordExtent = this.getTileCoordExtent(tileCoord);
|
var tileCoordExtent = this.getTileCoordExtent(tileCoord);
|
||||||
var z = tileCoord.z - 1;
|
var z = tileCoord.z - 1;
|
||||||
@@ -98,7 +104,7 @@ ol.TileGrid.prototype.forEachTileCoordParentTileRange =
|
|||||||
/**
|
/**
|
||||||
* @return {ol.Extent} Extent.
|
* @return {ol.Extent} Extent.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getExtent = function() {
|
ol.tilegrid.TileGrid.prototype.getExtent = function() {
|
||||||
return this.extent_;
|
return this.extent_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -107,7 +113,7 @@ ol.TileGrid.prototype.getExtent = function() {
|
|||||||
* @param {number} z Z.
|
* @param {number} z Z.
|
||||||
* @return {ol.Coordinate} Origin.
|
* @return {ol.Coordinate} Origin.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getOrigin = function(z) {
|
ol.tilegrid.TileGrid.prototype.getOrigin = function(z) {
|
||||||
if (!goog.isNull(this.origin_)) {
|
if (!goog.isNull(this.origin_)) {
|
||||||
return this.origin_;
|
return this.origin_;
|
||||||
} else {
|
} else {
|
||||||
@@ -123,8 +129,8 @@ ol.TileGrid.prototype.getOrigin = function(z) {
|
|||||||
* @param {number} resolution Resolution.
|
* @param {number} resolution Resolution.
|
||||||
* @return {ol.PixelBounds} Pixel bounds.
|
* @return {ol.PixelBounds} Pixel bounds.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getPixelBoundsForTileCoordAndResolution = function(
|
ol.tilegrid.TileGrid.prototype.getPixelBoundsForTileCoordAndResolution =
|
||||||
tileCoord, resolution) {
|
function(tileCoord, resolution) {
|
||||||
var scale = resolution / this.getResolution(tileCoord.z);
|
var scale = resolution / this.getResolution(tileCoord.z);
|
||||||
var tileSize = this.getTileSize();
|
var tileSize = this.getTileSize();
|
||||||
tileSize = new ol.Size(tileSize.width / scale,
|
tileSize = new ol.Size(tileSize.width / scale,
|
||||||
@@ -142,7 +148,7 @@ ol.TileGrid.prototype.getPixelBoundsForTileCoordAndResolution = function(
|
|||||||
* @param {number} z Z.
|
* @param {number} z Z.
|
||||||
* @return {number} Resolution.
|
* @return {number} Resolution.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getResolution = function(z) {
|
ol.tilegrid.TileGrid.prototype.getResolution = function(z) {
|
||||||
goog.asserts.assert(0 <= z && z < this.numResolutions_);
|
goog.asserts.assert(0 <= z && z < this.numResolutions_);
|
||||||
return this.resolutions_[z];
|
return this.resolutions_[z];
|
||||||
};
|
};
|
||||||
@@ -151,7 +157,7 @@ ol.TileGrid.prototype.getResolution = function(z) {
|
|||||||
/**
|
/**
|
||||||
* @return {Array.<number>} Resolutions.
|
* @return {Array.<number>} Resolutions.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getResolutions = function() {
|
ol.tilegrid.TileGrid.prototype.getResolutions = function() {
|
||||||
return this.resolutions_;
|
return this.resolutions_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -161,7 +167,7 @@ ol.TileGrid.prototype.getResolutions = function() {
|
|||||||
* @param {ol.TileRange} tileRange Tile range.
|
* @param {ol.TileRange} tileRange Tile range.
|
||||||
* @return {ol.Extent} Extent.
|
* @return {ol.Extent} Extent.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getTileRangeExtent = function(z, tileRange) {
|
ol.tilegrid.TileGrid.prototype.getTileRangeExtent = function(z, tileRange) {
|
||||||
var origin = this.getOrigin(z);
|
var origin = this.getOrigin(z);
|
||||||
var resolution = this.getResolution(z);
|
var resolution = this.getResolution(z);
|
||||||
var tileSize = this.tileSize_;
|
var tileSize = this.tileSize_;
|
||||||
@@ -178,7 +184,7 @@ ol.TileGrid.prototype.getTileRangeExtent = function(z, tileRange) {
|
|||||||
* @param {number} resolution Resolution.
|
* @param {number} resolution Resolution.
|
||||||
* @return {ol.TileRange} Tile range.
|
* @return {ol.TileRange} Tile range.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getTileRangeForExtentAndResolution = function(
|
ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndResolution = function(
|
||||||
extent, resolution) {
|
extent, resolution) {
|
||||||
var min = this.getTileCoordForCoordAndResolution(
|
var min = this.getTileCoordForCoordAndResolution(
|
||||||
new ol.Coordinate(extent.minX, extent.minY), resolution);
|
new ol.Coordinate(extent.minX, extent.minY), resolution);
|
||||||
@@ -193,7 +199,7 @@ ol.TileGrid.prototype.getTileRangeForExtentAndResolution = function(
|
|||||||
* @param {number} z Z.
|
* @param {number} z Z.
|
||||||
* @return {ol.TileRange} Tile range.
|
* @return {ol.TileRange} Tile range.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getTileRangeForExtentAndZ = function(extent, z) {
|
ol.tilegrid.TileGrid.prototype.getTileRangeForExtentAndZ = function(extent, z) {
|
||||||
var resolution = this.getResolution(z);
|
var resolution = this.getResolution(z);
|
||||||
return this.getTileRangeForExtentAndResolution(extent, resolution);
|
return this.getTileRangeForExtentAndResolution(extent, resolution);
|
||||||
};
|
};
|
||||||
@@ -203,7 +209,7 @@ ol.TileGrid.prototype.getTileRangeForExtentAndZ = function(extent, z) {
|
|||||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||||
* @return {ol.Coordinate} Tile center.
|
* @return {ol.Coordinate} Tile center.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getTileCoordCenter = function(tileCoord) {
|
ol.tilegrid.TileGrid.prototype.getTileCoordCenter = function(tileCoord) {
|
||||||
var origin = this.getOrigin(tileCoord.z);
|
var origin = this.getOrigin(tileCoord.z);
|
||||||
var resolution = this.getResolution(tileCoord.z);
|
var resolution = this.getResolution(tileCoord.z);
|
||||||
var tileSize = this.tileSize_;
|
var tileSize = this.tileSize_;
|
||||||
@@ -217,7 +223,7 @@ ol.TileGrid.prototype.getTileCoordCenter = function(tileCoord) {
|
|||||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||||
* @return {ol.Extent} Extent.
|
* @return {ol.Extent} Extent.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getTileCoordExtent = function(tileCoord) {
|
ol.tilegrid.TileGrid.prototype.getTileCoordExtent = function(tileCoord) {
|
||||||
var origin = this.getOrigin(tileCoord.z);
|
var origin = this.getOrigin(tileCoord.z);
|
||||||
var resolution = this.getResolution(tileCoord.z);
|
var resolution = this.getResolution(tileCoord.z);
|
||||||
var tileSize = this.tileSize_;
|
var tileSize = this.tileSize_;
|
||||||
@@ -234,7 +240,7 @@ ol.TileGrid.prototype.getTileCoordExtent = function(tileCoord) {
|
|||||||
* @param {number} resolution Resolution.
|
* @param {number} resolution Resolution.
|
||||||
* @return {ol.TileCoord} Tile coordinate.
|
* @return {ol.TileCoord} Tile coordinate.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getTileCoordForCoordAndResolution = function(
|
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndResolution = function(
|
||||||
coordinate, resolution) {
|
coordinate, resolution) {
|
||||||
var z = this.getZForResolution(resolution);
|
var z = this.getZForResolution(resolution);
|
||||||
var scale = resolution / this.getResolution(z);
|
var scale = resolution / this.getResolution(z);
|
||||||
@@ -278,7 +284,8 @@ ol.TileGrid.prototype.getTileCoordForCoordAndResolution = function(
|
|||||||
* @param {number} z Z.
|
* @param {number} z Z.
|
||||||
* @return {ol.TileCoord} Tile coordinate.
|
* @return {ol.TileCoord} Tile coordinate.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getTileCoordForCoordAndZ = function(coordinate, z) {
|
ol.tilegrid.TileGrid.prototype.getTileCoordForCoordAndZ =
|
||||||
|
function(coordinate, z) {
|
||||||
var resolution = this.getResolution(z);
|
var resolution = this.getResolution(z);
|
||||||
return this.getTileCoordForCoordAndResolution(coordinate, resolution);
|
return this.getTileCoordForCoordAndResolution(coordinate, resolution);
|
||||||
};
|
};
|
||||||
@@ -288,7 +295,7 @@ ol.TileGrid.prototype.getTileCoordForCoordAndZ = function(coordinate, z) {
|
|||||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||||
* @return {number} Tile resolution.
|
* @return {number} Tile resolution.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getTileCoordResolution = function(tileCoord) {
|
ol.tilegrid.TileGrid.prototype.getTileCoordResolution = function(tileCoord) {
|
||||||
goog.asserts.assert(0 <= tileCoord.z && tileCoord.z < this.numResolutions_);
|
goog.asserts.assert(0 <= tileCoord.z && tileCoord.z < this.numResolutions_);
|
||||||
return this.resolutions_[tileCoord.z];
|
return this.resolutions_[tileCoord.z];
|
||||||
};
|
};
|
||||||
@@ -297,7 +304,7 @@ ol.TileGrid.prototype.getTileCoordResolution = function(tileCoord) {
|
|||||||
/**
|
/**
|
||||||
* @return {ol.Size} Tile size.
|
* @return {ol.Size} Tile size.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getTileSize = function() {
|
ol.tilegrid.TileGrid.prototype.getTileSize = function() {
|
||||||
return this.tileSize_;
|
return this.tileSize_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -306,6 +313,6 @@ ol.TileGrid.prototype.getTileSize = function() {
|
|||||||
* @param {number} resolution Resolution.
|
* @param {number} resolution Resolution.
|
||||||
* @return {number} Z.
|
* @return {number} Z.
|
||||||
*/
|
*/
|
||||||
ol.TileGrid.prototype.getZForResolution = function(resolution) {
|
ol.tilegrid.TileGrid.prototype.getZForResolution = function(resolution) {
|
||||||
return ol.array.linearFindNearest(this.resolutions_, resolution);
|
return ol.array.linearFindNearest(this.resolutions_, resolution);
|
||||||
};
|
};
|
||||||
64
src/ol/tilegrid/xyz.js
Normal file
64
src/ol/tilegrid/xyz.js
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
goog.provide('ol.tilegrid.XYZ');
|
||||||
|
goog.provide('ol.tilegrid.XYZOptions');
|
||||||
|
|
||||||
|
goog.require('ol.Coordinate');
|
||||||
|
goog.require('ol.Projection');
|
||||||
|
goog.require('ol.Size');
|
||||||
|
goog.require('ol.TileRange');
|
||||||
|
goog.require('ol.tilegrid.TileGrid');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{maxZoom: number}}
|
||||||
|
*/
|
||||||
|
ol.tilegrid.XYZOptions;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @extends {ol.tilegrid.TileGrid}
|
||||||
|
* @param {ol.tilegrid.XYZOptions} xyzOptions XYZ options.
|
||||||
|
*/
|
||||||
|
ol.tilegrid.XYZ = function(xyzOptions) {
|
||||||
|
|
||||||
|
var resolutions = new Array(xyzOptions.maxZoom + 1);
|
||||||
|
var z;
|
||||||
|
for (z = 0; z <= xyzOptions.maxZoom; ++z) {
|
||||||
|
resolutions[z] = ol.Projection.EPSG_3857_HALF_SIZE / (128 << z);
|
||||||
|
}
|
||||||
|
|
||||||
|
goog.base(this, {
|
||||||
|
extent: ol.Projection.EPSG_3857_EXTENT,
|
||||||
|
origin: new ol.Coordinate(-ol.Projection.EPSG_3857_HALF_SIZE,
|
||||||
|
ol.Projection.EPSG_3857_HALF_SIZE),
|
||||||
|
resolutions: resolutions,
|
||||||
|
tileSize: new ol.Size(256, 256)
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
goog.inherits(ol.tilegrid.XYZ, ol.tilegrid.TileGrid);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.tilegrid.XYZ.prototype.forEachTileCoordParentTileRange =
|
||||||
|
function(tileCoord, callback, opt_obj) {
|
||||||
|
var x = tileCoord.x;
|
||||||
|
var y = tileCoord.y;
|
||||||
|
var z = tileCoord.z;
|
||||||
|
var tileRange;
|
||||||
|
while (true) {
|
||||||
|
z -= 1;
|
||||||
|
if (z < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
x = Math.floor(x / 2);
|
||||||
|
y = Math.floor(y / 2);
|
||||||
|
tileRange = new ol.TileRange(x, y, x, y);
|
||||||
|
if (callback.call(opt_obj, z, tileRange)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
goog.provide('ol.TileSource');
|
|
||||||
|
|
||||||
goog.require('ol.Attribution');
|
|
||||||
goog.require('ol.Source');
|
|
||||||
goog.require('ol.Tile');
|
|
||||||
goog.require('ol.TileCoord');
|
|
||||||
goog.require('ol.TileGrid');
|
|
||||||
goog.require('ol.TileUrlFunctionType');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @constructor
|
|
||||||
* @extends {ol.Source}
|
|
||||||
* @param {ol.Projection} projection Projection.
|
|
||||||
* @param {ol.TileGrid} tileGrid Tile grid.
|
|
||||||
* @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL.
|
|
||||||
* @param {ol.Extent=} opt_extent Extent.
|
|
||||||
* @param {Array.<string>=} opt_attributions Attributions.
|
|
||||||
* @param {?string=} opt_crossOrigin Cross origin.
|
|
||||||
*/
|
|
||||||
ol.TileSource = function(projection, tileGrid, tileUrlFunction, opt_extent,
|
|
||||||
opt_attributions, opt_crossOrigin) {
|
|
||||||
|
|
||||||
goog.base(this, projection, opt_extent, opt_attributions);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @protected
|
|
||||||
* @type {ol.TileGrid}
|
|
||||||
*/
|
|
||||||
this.tileGrid = tileGrid;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @protected
|
|
||||||
* @type {ol.TileUrlFunctionType}
|
|
||||||
*/
|
|
||||||
this.tileUrlFunction = tileUrlFunction;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {?string}
|
|
||||||
*/
|
|
||||||
this.crossOrigin_ = opt_crossOrigin || 'anonymous';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
* @type {Object.<string, ol.Tile>}
|
|
||||||
* FIXME will need to expire elements from this cache
|
|
||||||
* FIXME see elemoine's work with goog.structs.LinkedMap
|
|
||||||
*/
|
|
||||||
this.tileCache_ = {};
|
|
||||||
|
|
||||||
};
|
|
||||||
goog.inherits(ol.TileSource, ol.Source);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
ol.TileSource.prototype.getResolutions = function() {
|
|
||||||
return this.tileGrid.getResolutions();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
|
||||||
* @return {ol.Tile} Tile.
|
|
||||||
*/
|
|
||||||
ol.TileSource.prototype.getTile = function(tileCoord) {
|
|
||||||
var key = tileCoord.toString();
|
|
||||||
if (goog.object.containsKey(this.tileCache_, key)) {
|
|
||||||
return this.tileCache_[key];
|
|
||||||
} else {
|
|
||||||
var tileUrl = this.getTileCoordUrl(tileCoord);
|
|
||||||
var tile;
|
|
||||||
if (goog.isDef(tileUrl)) {
|
|
||||||
tile = new ol.Tile(tileCoord, tileUrl, this.crossOrigin_);
|
|
||||||
} else {
|
|
||||||
tile = null;
|
|
||||||
}
|
|
||||||
this.tileCache_[key] = tile;
|
|
||||||
return tile;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
|
||||||
* @return {string|undefined} Tile URL.
|
|
||||||
*/
|
|
||||||
ol.TileSource.prototype.getTileCoordUrl = function(tileCoord) {
|
|
||||||
return this.tileUrlFunction(tileCoord);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return {ol.TileGrid} Tile grid.
|
|
||||||
*/
|
|
||||||
ol.TileSource.prototype.getTileGrid = function() {
|
|
||||||
return this.tileGrid;
|
|
||||||
};
|
|
||||||
@@ -81,7 +81,8 @@
|
|||||||
<script type="text/javascript" src="spec/ol/tilerange.test.js"></script>
|
<script type="text/javascript" src="spec/ol/tilerange.test.js"></script>
|
||||||
<script type="text/javascript" src="spec/ol/tileurlfunction.test.js"></script>
|
<script type="text/javascript" src="spec/ol/tileurlfunction.test.js"></script>
|
||||||
<script type="text/javascript" src="spec/ol/resolutionconstraint.test.js"></script>
|
<script type="text/javascript" src="spec/ol/resolutionconstraint.test.js"></script>
|
||||||
<script type="text/javascript" src="spec/ol/layer/xyz.test.js"></script>
|
<script type="text/javascript" src="spec/ol/source/xyz.test.js"></script>
|
||||||
|
<script type="text/javascript" src="spec/ol/tilegrid/xyz.test.js"></script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ describe('ol.source.XYZ', function() {
|
|||||||
var xyzTileSource, tileGrid;
|
var xyzTileSource, tileGrid;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
xyzTileSource = new ol.source.XYZ(
|
xyzTileSource = new ol.source.XYZ({
|
||||||
6, ol.TileUrlFunction.createFromTemplate('{z}/{x}/{y}'));
|
maxZoom: 6,
|
||||||
|
url: '{z}/{x}/{y}'
|
||||||
|
});
|
||||||
tileGrid = xyzTileSource.getTileGrid();
|
tileGrid = xyzTileSource.getTileGrid();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -72,7 +74,7 @@ describe('ol.source.XYZ', function() {
|
|||||||
|
|
||||||
describe('forEachTileCoordParentTileRange', function() {
|
describe('forEachTileCoordParentTileRange', function() {
|
||||||
it('iterates as expected', function() {
|
it('iterates as expected', function() {
|
||||||
var xyzTileGrid = new ol.tilegrid.XYZ(6);
|
var xyzTileGrid = new ol.tilegrid.XYZ({maxZoom: 6});
|
||||||
|
|
||||||
var tileCoord = new ol.TileCoord(5, 11, 21);
|
var tileCoord = new ol.TileCoord(5, 11, 21);
|
||||||
var zs = [], tileRanges = [];
|
var zs = [], tileRanges = [];
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
describe('ol.TileGrid', function() {
|
describe('ol.tilegrid.TileGrid', function() {
|
||||||
var extent;
|
var extent;
|
||||||
var resolutions;
|
var resolutions;
|
||||||
var origin;
|
var origin;
|
||||||
@@ -16,16 +16,25 @@ describe('ol.TileGrid', function() {
|
|||||||
describe('create valid', function() {
|
describe('create valid', function() {
|
||||||
it('does not throw an exception', function() {
|
it('does not throw an exception', function() {
|
||||||
expect(function() {
|
expect(function() {
|
||||||
return new ol.TileGrid(resolutions, extent, origin, tileSize);
|
return new ol.tilegrid.TileGrid({
|
||||||
|
resolutions: resolutions,
|
||||||
|
extent: extent,
|
||||||
|
origin: origin,
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('create with duplicate resolutions', function() {
|
describe('create with duplicate resolutions', function() {
|
||||||
it('throws an exception', function() {
|
it('throws an exception', function() {
|
||||||
var resolutions = [100, 50, 50, 25, 10];
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
return new ol.TileGrid(resolutions, extent, origin, tileSize);
|
return new ol.tilegrid.TileGrid({
|
||||||
|
resolutions: [100, 50, 50, 25, 10],
|
||||||
|
extent: extent,
|
||||||
|
origin: origin,
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
}).toThrow();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -34,37 +43,51 @@ describe('ol.TileGrid', function() {
|
|||||||
it('throws an exception', function() {
|
it('throws an exception', function() {
|
||||||
var resolutions = [100, 25, 50, 10];
|
var resolutions = [100, 25, 50, 10];
|
||||||
expect(function() {
|
expect(function() {
|
||||||
return new ol.TileGrid(resolutions, extent, origin, tileSize);
|
return new ol.tilegrid.TileGrid({
|
||||||
|
resolutions: resolutions,
|
||||||
|
extent: extent,
|
||||||
|
origin: origin,
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
}).toThrow();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('create with multiple origins', function() {
|
describe('create with multiple origins', function() {
|
||||||
it('does not throw an exception', function() {
|
it('does not throw an exception', function() {
|
||||||
var resolutions = [100, 50, 25, 10];
|
|
||||||
var origins = [origin, origin, origin, origin];
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
return new ol.TileGrid(resolutions, extent, origins, tileSize);
|
return new ol.tilegrid.TileGrid({
|
||||||
|
resolutions: [100, 50, 25, 10],
|
||||||
|
extent: extent,
|
||||||
|
origins: [origin, origin, origin, origin],
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('create with too few origins', function() {
|
describe('create with too few origins', function() {
|
||||||
it('throws an exception', function() {
|
it('throws an exception', function() {
|
||||||
var resolutions = [100, 50, 25, 10];
|
|
||||||
var origins = [origin, origin, origin];
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
return new ol.TileGrid(resolutions, extent, origins, tileSize);
|
return new ol.tilegrid.TileGrid({
|
||||||
|
resolutions: [100, 50, 25, 10],
|
||||||
|
extent: extent,
|
||||||
|
origins: [origin, origin, origin],
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
}).toThrow();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('create with too many origins', function() {
|
describe('create with too many origins', function() {
|
||||||
it('throws an exception', function() {
|
it('throws an exception', function() {
|
||||||
var resolutions = [100, 50, 25, 10];
|
|
||||||
var origins = [origin, origin, origin, origin, origin];
|
|
||||||
expect(function() {
|
expect(function() {
|
||||||
return new ol.TileGrid(resolutions, extent, origins, tileSize);
|
return new ol.tilegrid.TileGrid({
|
||||||
|
resolutions: [100, 50, 25, 10],
|
||||||
|
extent: extent,
|
||||||
|
origins: [origin, origin, origin, origin, origin],
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
}).toThrow();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -74,7 +97,12 @@ describe('ol.TileGrid', function() {
|
|||||||
describe('Y North, X East', function() {
|
describe('Y North, X East', function() {
|
||||||
it('returns the expected TileCoord', function() {
|
it('returns the expected TileCoord', function() {
|
||||||
origin = new ol.Coordinate(0, 0);
|
origin = new ol.Coordinate(0, 0);
|
||||||
var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize);
|
var tileGrid = new ol.tilegrid.TileGrid({
|
||||||
|
resolutions: resolutions,
|
||||||
|
extent: extent,
|
||||||
|
origin: origin,
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
var tileCoord;
|
var tileCoord;
|
||||||
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndZ(
|
tileCoord = tileGrid.getTileCoordForCoordAndZ(
|
||||||
@@ -106,7 +134,12 @@ describe('ol.TileGrid', function() {
|
|||||||
describe('Y South, X East', function() {
|
describe('Y South, X East', function() {
|
||||||
it('returns the expected TileCoord', function() {
|
it('returns the expected TileCoord', function() {
|
||||||
origin = new ol.Coordinate(0, 100000);
|
origin = new ol.Coordinate(0, 100000);
|
||||||
var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize);
|
var tileGrid = new ol.tilegrid.TileGrid({
|
||||||
|
resolutions: resolutions,
|
||||||
|
extent: extent,
|
||||||
|
origin: origin,
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
var tileCoord;
|
var tileCoord;
|
||||||
|
|
||||||
tileCoord = tileGrid.getTileCoordForCoordAndZ(
|
tileCoord = tileGrid.getTileCoordForCoordAndZ(
|
||||||
@@ -139,7 +172,12 @@ describe('ol.TileGrid', function() {
|
|||||||
describe('getTileCoordForCoordAndResolution', function() {
|
describe('getTileCoordForCoordAndResolution', function() {
|
||||||
it('returns the expected TileCoord', function() {
|
it('returns the expected TileCoord', function() {
|
||||||
var tileSize = new ol.Size(256, 256);
|
var tileSize = new ol.Size(256, 256);
|
||||||
var tileGrid = new ol.TileGrid([10], extent, origin, tileSize);
|
var tileGrid = new ol.tilegrid.TileGrid({
|
||||||
|
resolutions: [10],
|
||||||
|
extent: extent,
|
||||||
|
origin: origin,
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
|
|
||||||
var coordinate;
|
var coordinate;
|
||||||
var tileCoord;
|
var tileCoord;
|
||||||
@@ -221,7 +259,12 @@ describe('ol.TileGrid', function() {
|
|||||||
describe('getTileCoordForCoordAndResolution fractional', function() {
|
describe('getTileCoordForCoordAndResolution fractional', function() {
|
||||||
it('returns the expected TileCoord', function() {
|
it('returns the expected TileCoord', function() {
|
||||||
var tileSize = new ol.Size(256, 256);
|
var tileSize = new ol.Size(256, 256);
|
||||||
var tileGrid = new ol.TileGrid([1 / 3], extent, origin, tileSize);
|
var tileGrid = new ol.tilegrid.TileGrid({
|
||||||
|
resolutions: [1 / 3],
|
||||||
|
extent: extent,
|
||||||
|
origin: origin,
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
|
|
||||||
var coordinate;
|
var coordinate;
|
||||||
var tileCoord;
|
var tileCoord;
|
||||||
@@ -315,7 +358,12 @@ describe('ol.TileGrid', function() {
|
|||||||
|
|
||||||
describe('getTileCoordCenter', function() {
|
describe('getTileCoordCenter', function() {
|
||||||
it('returns the expected center', function() {
|
it('returns the expected center', function() {
|
||||||
var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize);
|
var tileGrid = new ol.tilegrid.TileGrid({
|
||||||
|
resolutions: resolutions,
|
||||||
|
extent: extent,
|
||||||
|
origin: origin,
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
var center;
|
var center;
|
||||||
|
|
||||||
center = tileGrid.getTileCoordCenter(new ol.TileCoord(0, 0, 0));
|
center = tileGrid.getTileCoordCenter(new ol.TileCoord(0, 0, 0));
|
||||||
@@ -334,7 +382,12 @@ describe('ol.TileGrid', function() {
|
|||||||
|
|
||||||
describe('getTileCoordExent', function() {
|
describe('getTileCoordExent', function() {
|
||||||
it('returns the expected extend', function() {
|
it('returns the expected extend', function() {
|
||||||
var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize);
|
var tileGrid = new ol.tilegrid.TileGrid({
|
||||||
|
resolutions: resolutions,
|
||||||
|
extent: extent,
|
||||||
|
origin: origin,
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
var tileCoordExtent;
|
var tileCoordExtent;
|
||||||
|
|
||||||
tileCoordExtent = tileGrid.getTileCoordExtent(new ol.TileCoord(0, 0, 0));
|
tileCoordExtent = tileGrid.getTileCoordExtent(new ol.TileCoord(0, 0, 0));
|
||||||
@@ -359,7 +412,12 @@ describe('ol.TileGrid', function() {
|
|||||||
|
|
||||||
describe('getTileRangeForExtentAndZ', function() {
|
describe('getTileRangeForExtentAndZ', function() {
|
||||||
it('returns the expected TileRange', function() {
|
it('returns the expected TileRange', function() {
|
||||||
var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize);
|
var tileGrid = new ol.tilegrid.TileGrid({
|
||||||
|
resolutions: resolutions,
|
||||||
|
extent: extent,
|
||||||
|
origin: origin,
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
var e = new ol.Extent(45000, 5000, 55000, 15000);
|
var e = new ol.Extent(45000, 5000, 55000, 15000);
|
||||||
var tileRange;
|
var tileRange;
|
||||||
|
|
||||||
@@ -391,7 +449,12 @@ describe('ol.TileGrid', function() {
|
|||||||
|
|
||||||
describe('forEachTileCoordParentTileRange', function() {
|
describe('forEachTileCoordParentTileRange', function() {
|
||||||
it('iterates as expected', function() {
|
it('iterates as expected', function() {
|
||||||
var tileGrid = new ol.TileGrid(resolutions, extent, origin, tileSize);
|
var tileGrid = new ol.tilegrid.TileGrid({
|
||||||
|
resolutions: resolutions,
|
||||||
|
extent: extent,
|
||||||
|
origin: origin,
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
var zs = [], tileRanges = [];
|
var zs = [], tileRanges = [];
|
||||||
|
|
||||||
tileGrid.forEachTileCoordParentTileRange(
|
tileGrid.forEachTileCoordParentTileRange(
|
||||||
@@ -427,8 +490,12 @@ describe('ol.TileGrid', function() {
|
|||||||
|
|
||||||
describe('getZForResolution (exact)', function() {
|
describe('getZForResolution (exact)', function() {
|
||||||
it('returns the expected z value', function() {
|
it('returns the expected z value', function() {
|
||||||
var tileGrid =
|
var tileGrid = new ol.tilegrid.TileGrid({
|
||||||
new ol.TileGrid(resolutions, extent, origin, tileSize);
|
resolutions: resolutions,
|
||||||
|
extent: extent,
|
||||||
|
origin: origin,
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
|
|
||||||
expect(tileGrid.getZForResolution(1000)).toEqual(0);
|
expect(tileGrid.getZForResolution(1000)).toEqual(0);
|
||||||
expect(tileGrid.getZForResolution(500)).toEqual(1);
|
expect(tileGrid.getZForResolution(500)).toEqual(1);
|
||||||
@@ -439,9 +506,12 @@ describe('ol.TileGrid', function() {
|
|||||||
|
|
||||||
describe('getZForResolution (approcimate)', function() {
|
describe('getZForResolution (approcimate)', function() {
|
||||||
it('returns the expected z value', function() {
|
it('returns the expected z value', function() {
|
||||||
var tileGrid =
|
var tileGrid = new ol.tilegrid.TileGrid({
|
||||||
new ol.TileGrid(resolutions, extent, origin, tileSize);
|
resolutions: resolutions,
|
||||||
|
extent: extent,
|
||||||
|
origin: origin,
|
||||||
|
tileSize: tileSize
|
||||||
|
});
|
||||||
|
|
||||||
expect(tileGrid.getZForResolution(2000)).toEqual(0);
|
expect(tileGrid.getZForResolution(2000)).toEqual(0);
|
||||||
expect(tileGrid.getZForResolution(1000)).toEqual(0);
|
expect(tileGrid.getZForResolution(1000)).toEqual(0);
|
||||||
@@ -465,4 +535,4 @@ goog.require('ol.Coordinate');
|
|||||||
goog.require('ol.Extent');
|
goog.require('ol.Extent');
|
||||||
goog.require('ol.Size');
|
goog.require('ol.Size');
|
||||||
goog.require('ol.TileCoord');
|
goog.require('ol.TileCoord');
|
||||||
goog.require('ol.TileGrid');
|
goog.require('ol.tilegrid.TileGrid');
|
||||||
|
|||||||
Reference in New Issue
Block a user