Merge pull request #979 from tschaub/xyz

Export ol.source.XYZ.
This commit is contained in:
Tim Schaub
2013-09-11 07:55:57 -07:00
6 changed files with 104 additions and 22 deletions

56
examples/xyz-esri.html Normal file
View File

@@ -0,0 +1,56 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<link rel="stylesheet" href="../css/ol.css" type="text/css">
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="../resources/layout.css" type="text/css">
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
<title>XYZ Esri example</title>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="./">OpenLayers 3 Examples</a>
<ul class="nav pull-right">
<li><iframe class="github-watch-button" src="http://ghbtns.com/github-btn.html?user=openlayers&repo=ol3&type=watch&count=true"
allowtransparency="true" frameborder="0" scrolling="0" height="20" width="90"></iframe></li>
<li><a href="https://twitter.com/share" class="twitter-share-button" data-count="none" data-hashtags="openlayers">&nbsp;</a></li>
<li><div class="g-plusone-wrapper"><div class="g-plusone" data-size="medium" data-annotation="none"></div></div></li>
</ul>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div id="map" class="map"></div>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<h4 id="title">XYZ Esri example</h4>
<p id="shortdesc">Example of a XYZ source using Esri tiles.</p>
<div id="docs">
<p>See the <a href="xyz-esri.js" target="_blank">xyz-esri.js source</a> for details on how this is done.</p>
</div>
<div id="tags">xyz, esri</div>
</div>
</div>
</div>
<script src="loader.js?id=xyz-esri" type="text/javascript"></script>
<script src="../resources/social-links.js" type="text/javascript"></script>
</body>
</html>

24
examples/xyz-esri.js Normal file
View File

@@ -0,0 +1,24 @@
goog.require('ol.Map');
goog.require('ol.RendererHint');
goog.require('ol.View2D');
goog.require('ol.layer.Tile');
goog.require('ol.proj');
goog.require('ol.source.XYZ');
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.XYZ({
url: 'http://server.arcgisonline.com/ArcGIS/rest/services/' +
'World_Topo_Map/MapServer/tile/{z}/{y}/{x}'
})
})
],
renderer: ol.RendererHint.CANVAS,
view: new ol.View2D({
center: ol.proj.transform([-121.1, 47.5], 'EPSG:4326', 'EPSG:3857'),
zoom: 7
})
});

View File

@@ -605,6 +605,25 @@
* @property {Array.<string>|undefined} urls Urls.
*/
/**
* @typedef {Object} ol.source.XYZOptions
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
* @property {null|string|undefined} crossOrigin Cross origin setting for image
* requests.
* @property {ol.Extent|undefined} extent Extent.
* @property {string|undefined} logo Logo.
* @property {ol.ProjectionLike} projection Projection.
* @property {number|undefined} maxZoom Optional max zoom level. The default is
* 18.
* @property {number|undefined} minZoom Unsupported (TODO: remove this).
* @property {ol.TileUrlFunctionType|undefined} tileUrlFunction Optional
* function to get tile URL given a tile coordinate and the projection.
* Required if url or urls are not provided.
* @property {string|undefined} url URL template. Must include '{x}', '{y}',
* and '{z}' placeholders.
* @property {Array.<string>|undefined} urls An array of URL templates.
*/
/**
* @typedef {Object} ol.style.IconOptions
* @property {string|ol.expr.Expression} url Icon image url.

View File

@@ -23,8 +23,6 @@ ol.source.OSM = function(opt_options) {
attributions = ol.source.OSM.ATTRIBUTIONS;
}
var maxZoom = goog.isDef(options.maxZoom) ? options.maxZoom : 18;
var url = goog.isDef(options.url) ?
options.url : 'http://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png';
@@ -32,7 +30,7 @@ ol.source.OSM = function(opt_options) {
attributions: attributions,
crossOrigin: 'anonymous',
opaque: true,
maxZoom: maxZoom,
maxZoom: options.maxZoom,
url: url
});

View File

@@ -0,0 +1 @@
@exportClass ol.source.XYZ ol.source.XYZOptions

View File

@@ -1,8 +1,6 @@
goog.provide('ol.source.XYZ');
goog.provide('ol.source.XYZOptions');
goog.require('ol.Attribution');
goog.require('ol.Projection');
goog.require('ol.TileUrlFunction');
goog.require('ol.TileUrlFunctionType');
goog.require('ol.proj');
@@ -10,21 +8,6 @@ goog.require('ol.source.TileImage');
goog.require('ol.tilegrid.XYZ');
/**
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
* crossOrigin: (string|undefined),
* extent: (ol.Extent|undefined),
* logo: (string|undefined),
* maxZoom: number,
* minZoom: (number|undefined),
* projection: (ol.Projection|undefined),
* tileUrlFunction: (ol.TileUrlFunctionType|undefined),
* url: (string|undefined),
* urls: (Array.<string>|undefined)}}
*/
ol.source.XYZOptions;
/**
* @constructor
@@ -49,9 +32,10 @@ ol.source.XYZ = function(options) {
ol.TileUrlFunction.expandUrl(options.url));
}
var maxZoom = goog.isDef(options.maxZoom) ? options.maxZoom : 18;
var tileGrid = new ol.tilegrid.XYZ({
maxZoom: options.maxZoom,
minZoom: options.minZoom
maxZoom: maxZoom
});
var tileCoordTransform = tileGrid.createTileCoordTransform({