Merge branch 'master' of github.com:openlayers/ol3 into vector
Conflicts: src/objectliterals.exports
This commit is contained in:
@@ -26,17 +26,8 @@
|
||||
<div class="container-fluid">
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span4">
|
||||
<h4>Canvas</h4>
|
||||
<div id="canvasMap" class="map"></div>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<h4>WebGL</h4>
|
||||
<div id="webglMap" class="map"></div>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<h4>DOM</h4>
|
||||
<div id="domMap" class="map"></div>
|
||||
<div class="span12">
|
||||
<div id="map" class="map"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -53,6 +44,8 @@
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="loader.js?id=canvas-tiles" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.RendererHint');
|
||||
goog.require('ol.RendererHints');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
goog.require('ol.projection');
|
||||
@@ -9,41 +9,25 @@ goog.require('ol.source.OpenStreetMap');
|
||||
goog.require('ol.tilegrid.XYZ');
|
||||
|
||||
|
||||
var layers = [
|
||||
new ol.layer.TileLayer({
|
||||
source: new ol.source.OpenStreetMap()
|
||||
}),
|
||||
new ol.layer.TileLayer({
|
||||
source: new ol.source.DebugTileSource({
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: new ol.tilegrid.XYZ({
|
||||
maxZoom: 22
|
||||
var map = new ol.Map({
|
||||
layers: [
|
||||
new ol.layer.TileLayer({
|
||||
source: new ol.source.OpenStreetMap()
|
||||
}),
|
||||
new ol.layer.TileLayer({
|
||||
source: new ol.source.DebugTileSource({
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: new ol.tilegrid.XYZ({
|
||||
maxZoom: 22
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
];
|
||||
|
||||
var webglMap = new ol.Map({
|
||||
],
|
||||
renderers: ol.RendererHints.createFromQueryData(),
|
||||
target: 'map',
|
||||
view: new ol.View2D({
|
||||
center: ol.projection.transform(
|
||||
new ol.Coordinate(-0.1275, 51.507222), 'EPSG:4326', 'EPSG:3857'),
|
||||
zoom: 10
|
||||
}),
|
||||
layers: layers,
|
||||
renderer: ol.RendererHint.WEBGL,
|
||||
target: 'webglMap'
|
||||
})
|
||||
});
|
||||
|
||||
var domMap = new ol.Map({
|
||||
renderer: ol.RendererHint.DOM,
|
||||
target: 'domMap'
|
||||
});
|
||||
domMap.bindTo('layers', webglMap);
|
||||
domMap.bindTo('view', webglMap);
|
||||
|
||||
var canvasMap = new ol.Map({
|
||||
renderer: ol.RendererHint.CANVAS,
|
||||
target: 'canvasMap'
|
||||
});
|
||||
canvasMap.bindTo('layers', webglMap);
|
||||
canvasMap.bindTo('view', webglMap);
|
||||
|
||||
54
examples/wmts-from-capabilities.html
Normal file
54
examples/wmts-from-capabilities.html
Normal file
@@ -0,0 +1,54 @@
|
||||
<!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="bootstrap/css/bootstrap.min.css" type="text/css">
|
||||
<link rel="stylesheet" href="examples.css" type="text/css">
|
||||
<link rel="stylesheet" href="bootstrap/css/bootstrap-responsive.min.css" type="text/css">
|
||||
<title>WMTS from capabilities example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
<a class="brand" href="example-list.html">OpenLayers 3 Examples</a>
|
||||
<ul class="nav pull-right">
|
||||
<li><a href="https://github.com/openlayers/ol3"><i class="icon-github"></i></a></li>
|
||||
<li><a href="https://twitter.com/openlayers"><i class="icon-twitter"></i></a></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="span4">
|
||||
<h4 id="title">WMTS from capabilities example</h4>
|
||||
<p id="shortdesc">Example of a WMTS source built from a WMTS getCapabilities response.</p>
|
||||
<div id="docs">
|
||||
<p>See the <a href="wmts-from-capabilities.js" target="_blank">wmts-from-capabilities.js source</a> to see how this is done.</p>
|
||||
</div>
|
||||
<div id="tags">wmts</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/proj4js-compressed.js" type="text/javascript"></script>
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/defs/EPSG21781.js" type="text/javascript"></script>
|
||||
<script src="loader.js?id=wmts-from-capabilities" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
47
examples/wmts-from-capabilities.js
Normal file
47
examples/wmts-from-capabilities.js
Normal file
@@ -0,0 +1,47 @@
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.RendererHints');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
goog.require('ol.parser.ogc.WMTSCapabilities');
|
||||
goog.require('ol.projection');
|
||||
goog.require('ol.source.WMTS');
|
||||
|
||||
|
||||
var map, capabilities;
|
||||
var parser = new ol.parser.ogc.WMTSCapabilities();
|
||||
var projection = ol.projection.configureProj4jsProjection({
|
||||
code: 'EPSG:21781',
|
||||
extent: new ol.Extent(485869.5728, 76443.1884, 837076.5648, 299941.7864)
|
||||
});
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'http://wmts.geo.admin.ch/1.0.0/WMTSCapabilities.xml', true);
|
||||
|
||||
|
||||
/**
|
||||
* onload handler for the XHR request.
|
||||
*/
|
||||
xhr.onload = function() {
|
||||
if (xhr.status == 200) {
|
||||
capabilities = parser.read(xhr.responseXML);
|
||||
var wmtsOptions = ol.source.WMTS.optionsFromCapabilities(
|
||||
capabilities, 'ch.swisstopo.pixelkarte-farbe');
|
||||
map = new ol.Map({
|
||||
layers: [
|
||||
new ol.layer.TileLayer({
|
||||
source: new ol.source.WMTS(wmtsOptions)
|
||||
})
|
||||
],
|
||||
renderers: ol.RendererHints.createFromQueryData(),
|
||||
target: 'map',
|
||||
view: new ol.View2D({
|
||||
center: projection.getExtent().getCenter(),
|
||||
projection: projection,
|
||||
zoom: 1
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
52
examples/wmts.html
Normal file
52
examples/wmts.html
Normal file
@@ -0,0 +1,52 @@
|
||||
<!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="bootstrap/css/bootstrap.min.css" type="text/css">
|
||||
<link rel="stylesheet" href="examples.css" type="text/css">
|
||||
<link rel="stylesheet" href="bootstrap/css/bootstrap-responsive.min.css" type="text/css">
|
||||
<title>WMTS example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
<a class="brand" href="example-list.html">OpenLayers 3 Examples</a>
|
||||
<ul class="nav pull-right">
|
||||
<li><a href="https://github.com/openlayers/ol3"><i class="icon-github"></i></a></li>
|
||||
<li><a href="https://twitter.com/openlayers"><i class="icon-twitter"></i></a></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="span4">
|
||||
<h4 id="title">WMTS example</h4>
|
||||
<p id="shortdesc">Example of a WMTS source.</p>
|
||||
<div id="docs">
|
||||
<p>See the <a href="wmts.js" target="_blank">wmts.js source</a> to see how this is done.</p>
|
||||
</div>
|
||||
<div id="tags">wmts</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="loader.js?id=wmts" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
54
examples/wmts.js
Normal file
54
examples/wmts.js
Normal file
@@ -0,0 +1,54 @@
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.RendererHint');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
goog.require('ol.projection');
|
||||
goog.require('ol.source.OpenStreetMap');
|
||||
goog.require('ol.source.WMTS');
|
||||
goog.require('ol.tilegrid.WMTS');
|
||||
|
||||
|
||||
var projection = ol.projection.get('EPSG:900913');
|
||||
var projectionExtent = projection.getExtent();
|
||||
var size = projectionExtent.getWidth() / 256;
|
||||
var resolutions = new Array(26);
|
||||
var matrixIds = new Array(26);
|
||||
for (var z = 0; z < 26; ++z) {
|
||||
// generate resolutions and matrixIds arrays for this WMTS
|
||||
resolutions[z] = size / Math.pow(2, z);
|
||||
matrixIds[z] = 'EPSG:900913:' + z;
|
||||
}
|
||||
|
||||
var map = new ol.Map({
|
||||
layers: [
|
||||
new ol.layer.TileLayer({
|
||||
source: new ol.source.OpenStreetMap(),
|
||||
opacity: 0.7
|
||||
}),
|
||||
new ol.layer.TileLayer({
|
||||
source: new ol.source.WMTS({
|
||||
url: 'http://v2.suite.opengeo.org/geoserver/gwc/service/wmts/',
|
||||
layer: 'medford:buildings',
|
||||
matrixSet: 'EPSG:900913',
|
||||
format: 'image/png',
|
||||
projection: projection,
|
||||
tileGrid: new ol.tilegrid.WMTS({
|
||||
origin: projectionExtent.getTopLeft(),
|
||||
resolutions: resolutions,
|
||||
matrixIds: matrixIds
|
||||
}),
|
||||
style: '_null',
|
||||
crossOrigin: null, // FIXME: this should be the default
|
||||
extent: new ol.Extent(-13682835, 5204068, -13667473, 5221690)
|
||||
})
|
||||
})
|
||||
],
|
||||
renderer: ol.RendererHint.CANVAS,
|
||||
target: 'map',
|
||||
view: new ol.View2D({
|
||||
center: new ol.Coordinate(-13677832, 5213272),
|
||||
zoom: 13
|
||||
})
|
||||
});
|
||||
@@ -155,38 +155,21 @@
|
||||
@exportObjectLiteralProperty ol.source.TiledWMSOptions.url string|undefined
|
||||
@exportObjectLiteralProperty ol.source.TiledWMSOptions.urls Array.<string>|undefined
|
||||
|
||||
@exportObjectLiteral ol.style.IconOptions
|
||||
@exportObjectLiteralProperty ol.style.IconOptions.url string|ol.Expression
|
||||
@exportObjectLiteralProperty ol.style.IconOptions.width number|ol.Expression|undefined
|
||||
@exportObjectLiteralProperty ol.style.IconOptions.height number|ol.Expression|undefined
|
||||
@exportObjectLiteralProperty ol.style.IconOptions.opacity number|ol.Expression|undefined
|
||||
@exportObjectLiteralProperty ol.style.IconOptions.rotation number|ol.Expression|undefined
|
||||
|
||||
@exportObjectLiteral ol.style.LineOptions
|
||||
@exportObjectLiteralProperty ol.style.LineOptions.strokeColor string|ol.Expression|undefined
|
||||
@exportObjectLiteralProperty ol.style.LineOptions.strokeWidth number|ol.Expression|undefined
|
||||
@exportObjectLiteralProperty ol.style.LineOptions.opacity number|ol.Expression|undefined
|
||||
|
||||
@exportObjectLiteral ol.style.PolygonOptions
|
||||
@exportObjectLiteralProperty ol.style.PolygonOptions.fillColor string|ol.Expression|undefined
|
||||
@exportObjectLiteralProperty ol.style.PolygonOptions.strokeColor string|ol.Expression|undefined
|
||||
@exportObjectLiteralProperty ol.style.PolygonOptions.strokeWidth number|ol.Expression|undefined
|
||||
@exportObjectLiteralProperty ol.style.PolygonOptions.opacity number|ol.Expression|undefined
|
||||
|
||||
@exportObjectLiteral ol.style.RuleOptions
|
||||
@exportObjectLiteralProperty ol.style.RuleOptions.filter ol.filter.Filter|undefined
|
||||
@exportObjectLiteralProperty ol.style.RuleOptions.symbolizers Array.<ol.style.Symbolizer>|undefined
|
||||
|
||||
@exportObjectLiteral ol.style.ShapeOptions
|
||||
@exportObjectLiteralProperty ol.style.ShapeOptions.type ol.style.ShapeType|undefined
|
||||
@exportObjectLiteralProperty ol.style.ShapeOptions.size number|ol.Expression|undefined
|
||||
@exportObjectLiteralProperty ol.style.ShapeOptions.fillColor string|ol.Expression|undefined
|
||||
@exportObjectLiteralProperty ol.style.ShapeOptions.strokeColor string|ol.Expression|undefined
|
||||
@exportObjectLiteralProperty ol.style.ShapeOptions.strokeWidth number|ol.Expression|undefined
|
||||
@exportObjectLiteralProperty ol.style.ShapeOptions.opacity number|ol.Expression|undefined
|
||||
|
||||
@exportObjectLiteral ol.style.StyleOptions
|
||||
@exportObjectLiteralProperty ol.style.StyleOptions.rules Array.<ol.style.Rule>
|
||||
@exportObjectLiteral ol.source.WMTSOptions
|
||||
@exportObjectLiteralProperty ol.source.WMTSOptions.attributions Array.<ol.Attribution>|undefined
|
||||
@exportObjectLiteralProperty ol.source.WMTSOptions.crossOrigin string|null|undefined
|
||||
@exportObjectLiteralProperty ol.source.WMTSOptions.extent ol.Extent|undefined
|
||||
@exportObjectLiteralProperty ol.source.WMTSOptions.tileGrid ol.tilegrid.WMTS
|
||||
@exportObjectLiteralProperty ol.source.WMTSOptions.projection ol.Projection|undefined
|
||||
@exportObjectLiteralProperty ol.source.WMTSOptions.requestEncoding ol.source.WMTSRequestEncoding|undefined
|
||||
@exportObjectLiteralProperty ol.source.WMTSOptions.layer string
|
||||
@exportObjectLiteralProperty ol.source.WMTSOptions.style string
|
||||
@exportObjectLiteralProperty ol.source.WMTSOptions.format string|undefined
|
||||
@exportObjectLiteralProperty ol.source.WMTSOptions.matrixSet string
|
||||
@exportObjectLiteralProperty ol.source.WMTSOptions.dimensions Object|undefined
|
||||
@exportObjectLiteralProperty ol.source.WMTSOptions.url string|undefined
|
||||
@exportObjectLiteralProperty ol.source.WMTSOptions.maxZoom number|undefined
|
||||
@exportObjectLiteralProperty ol.source.WMTSOptions.urls Array.<string>|undefined
|
||||
|
||||
@exportObjectLiteral ol.tilegrid.TileGridOptions
|
||||
@exportObjectLiteralProperty ol.tilegrid.TileGridOptions.origin ol.Coordinate|undefined
|
||||
@@ -195,6 +178,14 @@
|
||||
@exportObjectLiteralProperty ol.tilegrid.TileGridOptions.tileSize ol.Size|undefined
|
||||
@exportObjectLiteralProperty ol.tilegrid.TileGridOptions.tileSizes Array.<ol.Size>|undefined
|
||||
|
||||
@exportObjectLiteral ol.tilegrid.WMTSOptions
|
||||
@exportObjectLiteralProperty ol.tilegrid.WMTSOptions.origin ol.Coordinate|undefined
|
||||
@exportObjectLiteralProperty ol.tilegrid.WMTSOptions.origins Array.<ol.Coordinate>|undefined
|
||||
@exportObjectLiteralProperty ol.tilegrid.WMTSOptions.resolutions !Array.<number>
|
||||
@exportObjectLiteralProperty ol.tilegrid.WMTSOptions.matrixIds !Array.<string>
|
||||
@exportObjectLiteralProperty ol.tilegrid.WMTSOptions.tileSize ol.Size|undefined
|
||||
@exportObjectLiteralProperty ol.tilegrid.WMTSOptions.tileSizes Array.<ol.Size>|undefined
|
||||
|
||||
@exportObjectLiteral ol.tilegrid.XYZOptions
|
||||
@exportObjectLiteralProperty ol.tilegrid.XYZOptions.maxZoom number
|
||||
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
@exportSymbol ol.Coordinate
|
||||
@exportProperty ol.Coordinate.toStringHDMS
|
||||
@exportSymbol ol.Coordinate.createStringXY
|
||||
@exportSymbol ol.Coordinate.toStringHDMS
|
||||
@exportSymbol ol.Coordinate.toStringXY
|
||||
@exportSymbol ol.Coordinate.fromProjectedArray
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
@exportSymbol ol.Extent
|
||||
@exportProperty ol.Extent.prototype.getCenter
|
||||
@exportProperty ol.Extent.prototype.getHeight
|
||||
@exportProperty ol.Extent.prototype.getWidth
|
||||
@exportProperty ol.Extent.prototype.containsCoordinate
|
||||
@exportProperty ol.Extent.prototype.containsExtent
|
||||
@exportProperty ol.Extent.prototype.getBottomLeft
|
||||
@exportProperty ol.Extent.prototype.getBottomRight
|
||||
@exportProperty ol.Extent.prototype.getTopLeft
|
||||
@exportProperty ol.Extent.prototype.getTopRight
|
||||
@exportProperty ol.Extent.prototype.transform
|
||||
|
||||
@@ -45,6 +45,35 @@ ol.Extent.boundingExtent = function(var_args) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate} center Center.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} rotation Rotation.
|
||||
* @param {ol.Size} size Size.
|
||||
* @return {ol.Extent} Extent.
|
||||
*/
|
||||
ol.Extent.getForView2DAndSize = function(center, resolution, rotation, size) {
|
||||
var dx = resolution * size.width / 2;
|
||||
var dy = resolution * size.height / 2;
|
||||
var cosRotation = Math.cos(rotation);
|
||||
var sinRotation = Math.sin(rotation);
|
||||
var xs = [-dx, -dx, dx, dx];
|
||||
var ys = [-dy, dy, -dy, dy];
|
||||
var i, x, y;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
x = xs[i];
|
||||
y = ys[i];
|
||||
xs[i] = center.x + x * cosRotation - y * sinRotation;
|
||||
ys[i] = center.y + x * sinRotation + y * cosRotation;
|
||||
}
|
||||
var minX = Math.min.apply(null, xs);
|
||||
var minY = Math.min.apply(null, ys);
|
||||
var maxX = Math.max.apply(null, xs);
|
||||
var maxY = Math.max.apply(null, ys);
|
||||
return new ol.Extent(minX, minY, maxX, maxY);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the passed coordinate is contained or on the edge
|
||||
* of the extent.
|
||||
|
||||
@@ -728,24 +728,8 @@ ol.Map.prototype.renderFrame_ = function(time) {
|
||||
|
||||
if (!goog.isNull(frameState)) {
|
||||
// FIXME works for View2D only
|
||||
var center = view2DState.center;
|
||||
var resolution = view2DState.resolution;
|
||||
var rotation = view2DState.rotation;
|
||||
var x = resolution * size.width / 2;
|
||||
var y = resolution * size.height / 2;
|
||||
var corners = [
|
||||
new ol.Coordinate(-x, -y),
|
||||
new ol.Coordinate(-x, y),
|
||||
new ol.Coordinate(x, -y),
|
||||
new ol.Coordinate(x, y)
|
||||
];
|
||||
var corner;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
corner = corners[i];
|
||||
corner.rotate(rotation);
|
||||
corner.add(center);
|
||||
}
|
||||
frameState.extent = ol.Extent.boundingExtent.apply(null, corners);
|
||||
frameState.extent = ol.Extent.getForView2DAndSize(view2DState.center,
|
||||
view2DState.resolution, view2DState.rotation, frameState.size);
|
||||
}
|
||||
|
||||
this.frameState_ = frameState;
|
||||
|
||||
@@ -67,7 +67,7 @@ ol.parser.ogc.WMTSCapabilities_v1_0_0 = function() {
|
||||
},
|
||||
'TileMatrix': function(node, obj) {
|
||||
var tileMatrix = {
|
||||
'supportedCRS': obj.supportedCRS
|
||||
'supportedCRS': obj['supportedCRS']
|
||||
};
|
||||
this.readChildNodes(node, tileMatrix);
|
||||
obj['matrixIds'].push(tileMatrix);
|
||||
|
||||
335
src/ol/parser/polyline.js
Normal file
335
src/ol/parser/polyline.js
Normal file
@@ -0,0 +1,335 @@
|
||||
goog.provide('ol.parser.polyline');
|
||||
|
||||
|
||||
/**
|
||||
* Encode a list of coordinates in a flat array and return an encoded string
|
||||
*
|
||||
* Attention: This function will modify the passed array!
|
||||
*
|
||||
* @param {Array.<number>} flatPoints A flat array of coordinates.
|
||||
* @param {number=} opt_dimension The dimension of the coordinates in the array.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeFlatCoordinates =
|
||||
function(flatPoints, opt_dimension) {
|
||||
var dimension = opt_dimension || 2;
|
||||
return ol.parser.polyline.encodeDeltas(flatPoints, dimension);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode a list of coordinates from an encoded string into a flat array
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @param {number=} opt_dimension The dimension of the coordinates in the
|
||||
* encoded string.
|
||||
* @return {Array.<number>} A flat array of coordinates.
|
||||
*/
|
||||
ol.parser.polyline.decodeFlatCoordinates = function(encoded, opt_dimension) {
|
||||
var dimension = opt_dimension || 2;
|
||||
return ol.parser.polyline.decodeDeltas(encoded, dimension);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode a list of n-dimensional points and return an encoded string
|
||||
*
|
||||
* Attention: This function will modify the passed array!
|
||||
*
|
||||
* @param {Array.<number>} numbers A list of n-dimensional points.
|
||||
* @param {number} dimension The dimension of the points in the list.
|
||||
* @param {number=} opt_factor The factor by which the numbers will be
|
||||
* multiplied. The remaining decimal places will get rounded away.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeDeltas = function(numbers, dimension, opt_factor) {
|
||||
var factor = opt_factor || 1e5;
|
||||
var d;
|
||||
|
||||
var lastNumbers = new Array(dimension);
|
||||
for (d = 0; d < dimension; ++d) {
|
||||
lastNumbers[d] = 0;
|
||||
}
|
||||
|
||||
var numbersLength = numbers.length;
|
||||
for (var i = 0; i < numbersLength;) {
|
||||
for (d = 0; d < dimension; ++d, ++i) {
|
||||
var num = numbers[i];
|
||||
var delta = num - lastNumbers[d];
|
||||
lastNumbers[d] = num;
|
||||
|
||||
numbers[i] = delta;
|
||||
}
|
||||
}
|
||||
|
||||
return ol.parser.polyline.encodeFloats(numbers, factor);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode a list of n-dimensional points from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @param {number} dimension The dimension of the points in the encoded string.
|
||||
* @param {number=} opt_factor The factor by which the resulting numbers will
|
||||
* be divided.
|
||||
* @return {Array.<number>} A list of n-dimensional points.
|
||||
*/
|
||||
ol.parser.polyline.decodeDeltas = function(encoded, dimension, opt_factor) {
|
||||
var factor = opt_factor || 1e5;
|
||||
var d;
|
||||
|
||||
var lastNumbers = new Array(dimension);
|
||||
for (d = 0; d < dimension; ++d) {
|
||||
lastNumbers[d] = 0;
|
||||
}
|
||||
|
||||
var numbers = ol.parser.polyline.decodeFloats(encoded, factor);
|
||||
|
||||
var numbersLength = numbers.length;
|
||||
for (var i = 0; i < numbersLength;) {
|
||||
for (d = 0; d < dimension; ++d, ++i) {
|
||||
lastNumbers[d] += numbers[i];
|
||||
|
||||
numbers[i] = lastNumbers[d];
|
||||
}
|
||||
}
|
||||
|
||||
return numbers;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode a list of floating point numbers and return an encoded string
|
||||
*
|
||||
* Attention: This function will modify the passed array!
|
||||
*
|
||||
* @param {Array.<number>} numbers A list of floating point numbers.
|
||||
* @param {number=} opt_factor The factor by which the numbers will be
|
||||
* multiplied. The remaining decimal places will get rounded away.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeFloats = function(numbers, opt_factor) {
|
||||
var factor = opt_factor || 1e5;
|
||||
|
||||
var numbersLength = numbers.length;
|
||||
for (var i = 0; i < numbersLength; ++i) {
|
||||
numbers[i] = Math.round(numbers[i] * factor);
|
||||
}
|
||||
|
||||
return ol.parser.polyline.encodeSignedIntegers(numbers);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode a list of floating point numbers from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @param {number=} opt_factor The factor by which the result will be divided.
|
||||
* @return {Array.<number>} A list of floating point numbers.
|
||||
*/
|
||||
ol.parser.polyline.decodeFloats = function(encoded, opt_factor) {
|
||||
var factor = opt_factor || 1e5;
|
||||
|
||||
var numbers = ol.parser.polyline.decodeSignedIntegers(encoded);
|
||||
|
||||
var numbersLength = numbers.length;
|
||||
for (var i = 0; i < numbersLength; ++i) {
|
||||
numbers[i] /= factor;
|
||||
}
|
||||
|
||||
return numbers;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode a list of signed integers and return an encoded string
|
||||
*
|
||||
* Attention: This function will modify the passed array!
|
||||
*
|
||||
* @param {Array.<number>} numbers A list of signed integers.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeSignedIntegers = function(numbers) {
|
||||
var numbersLength = numbers.length;
|
||||
for (var i = 0; i < numbersLength; ++i) {
|
||||
var num = numbers[i];
|
||||
|
||||
var signedNum = num << 1;
|
||||
if (num < 0) {
|
||||
signedNum = ~(signedNum);
|
||||
}
|
||||
|
||||
numbers[i] = signedNum;
|
||||
}
|
||||
|
||||
return ol.parser.polyline.encodeUnsignedIntegers(numbers);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode a list of signed integers from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @return {Array.<number>} A list of signed integers.
|
||||
*/
|
||||
ol.parser.polyline.decodeSignedIntegers = function(encoded) {
|
||||
var numbers = ol.parser.polyline.decodeUnsignedIntegers(encoded);
|
||||
|
||||
var numbersLength = numbers.length;
|
||||
for (var i = 0; i < numbersLength; ++i) {
|
||||
var num = numbers[i];
|
||||
numbers[i] = (num & 1) ? ~(num >> 1) : (num >> 1);
|
||||
}
|
||||
|
||||
return numbers;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode a list of unsigned integers and return an encoded string
|
||||
*
|
||||
* @param {Array.<number>} numbers A list of unsigned integers.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeUnsignedIntegers = function(numbers) {
|
||||
var encoded = '';
|
||||
|
||||
var numbersLength = numbers.length;
|
||||
for (var i = 0; i < numbersLength; ++i) {
|
||||
encoded += ol.parser.polyline.encodeUnsignedInteger(numbers[i]);
|
||||
}
|
||||
|
||||
return encoded;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode a list of unsigned integers from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @return {Array.<number>} A list of unsigned integers.
|
||||
*/
|
||||
ol.parser.polyline.decodeUnsignedIntegers = function(encoded) {
|
||||
var numbers = [];
|
||||
|
||||
var current = 0;
|
||||
var shift = 0;
|
||||
|
||||
var encodedLength = encoded.length;
|
||||
for (var i = 0; i < encodedLength; ++i) {
|
||||
var b = encoded.charCodeAt(i) - 63;
|
||||
|
||||
current |= (b & 0x1f) << shift;
|
||||
|
||||
if (b < 0x20) {
|
||||
numbers.push(current);
|
||||
current = 0;
|
||||
shift = 0;
|
||||
} else {
|
||||
shift += 5;
|
||||
}
|
||||
}
|
||||
|
||||
return numbers;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode one single floating point number and return an encoded string
|
||||
*
|
||||
* @param {number} num Floating point number that should be encoded.
|
||||
* @param {number=} opt_factor The factor by which num will be multiplied.
|
||||
* The remaining decimal places will get rounded away.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeFloat = function(num, opt_factor) {
|
||||
num = Math.round(num * (opt_factor || 1e5));
|
||||
return ol.parser.polyline.encodeSignedInteger(num);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode one single floating point number from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @param {number=} opt_factor The factor by which the result will be divided.
|
||||
* @return {number} The decoded floating point number.
|
||||
*/
|
||||
ol.parser.polyline.decodeFloat = function(encoded, opt_factor) {
|
||||
var result = ol.parser.polyline.decodeSignedInteger(encoded);
|
||||
return result / (opt_factor || 1e5);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode one single signed integer and return an encoded string
|
||||
*
|
||||
* @param {number} num Signed integer that should be encoded.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeSignedInteger = function(num) {
|
||||
var signedNum = num << 1;
|
||||
if (num < 0) {
|
||||
signedNum = ~(signedNum);
|
||||
}
|
||||
|
||||
return ol.parser.polyline.encodeUnsignedInteger(signedNum);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode one single signed integer from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @return {number} The decoded signed integer.
|
||||
*/
|
||||
ol.parser.polyline.decodeSignedInteger = function(encoded) {
|
||||
var result = ol.parser.polyline.decodeUnsignedInteger(encoded);
|
||||
return ((result & 1) ? ~(result >> 1) : (result >> 1));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Encode one single unsigned integer and return an encoded string
|
||||
*
|
||||
* @param {number} num Unsigned integer that should be encoded.
|
||||
* @return {string} The encoded string.
|
||||
*/
|
||||
ol.parser.polyline.encodeUnsignedInteger = function(num) {
|
||||
var value, encoded = '';
|
||||
while (num >= 0x20) {
|
||||
value = (0x20 | (num & 0x1f)) + 63;
|
||||
encoded += (String.fromCharCode(value));
|
||||
num >>= 5;
|
||||
}
|
||||
value = num + 63;
|
||||
encoded += (String.fromCharCode(value));
|
||||
return encoded;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Decode one single unsigned integer from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @return {number} The decoded unsigned integer.
|
||||
*/
|
||||
ol.parser.polyline.decodeUnsignedInteger = function(encoded) {
|
||||
var result = 0;
|
||||
var shift = 0;
|
||||
|
||||
var encodedLength = encoded.length;
|
||||
for (var i = 0; i < encodedLength; ++i) {
|
||||
var b = encoded.charCodeAt(i) - 63;
|
||||
|
||||
result |= (b & 0x1f) << shift;
|
||||
|
||||
if (b < 0x20)
|
||||
break;
|
||||
|
||||
shift += 5;
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
@@ -6,6 +6,7 @@ goog.provide('ol.renderer.canvas.TileLayer');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.vec.Mat4');
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Size');
|
||||
goog.require('ol.Tile');
|
||||
goog.require('ol.TileCoord');
|
||||
@@ -103,8 +104,17 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
||||
var z = tileGrid.getZForResolution(view2DState.resolution);
|
||||
var tileSize = tileGrid.getTileSize(z);
|
||||
var tileResolution = tileGrid.getResolution(z);
|
||||
var center = view2DState.center;
|
||||
var extent;
|
||||
if (tileResolution == view2DState.resolution) {
|
||||
center = this.snapCenterToPixel(center, tileResolution, frameState.size);
|
||||
extent = ol.Extent.getForView2DAndSize(
|
||||
center, tileResolution, view2DState.rotation, frameState.size);
|
||||
} else {
|
||||
extent = frameState.extent;
|
||||
}
|
||||
var tileRange = tileGrid.getTileRangeForExtentAndResolution(
|
||||
frameState.extent, tileResolution);
|
||||
extent, tileResolution);
|
||||
var tileRangeWidth = tileRange.getWidth();
|
||||
var tileRangeHeight = tileRange.getHeight();
|
||||
|
||||
@@ -238,7 +248,7 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
||||
}
|
||||
|
||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||
tileSource.useLowResolutionTiles(z, frameState.extent, tileGrid);
|
||||
tileSource.useLowResolutionTiles(z, extent, tileGrid);
|
||||
this.scheduleExpireCache(frameState, tileSource);
|
||||
|
||||
var transform = this.transform_;
|
||||
@@ -253,8 +263,8 @@ ol.renderer.canvas.TileLayer.prototype.renderFrame =
|
||||
1);
|
||||
goog.vec.Mat4.translate(
|
||||
transform,
|
||||
(origin.x - view2DState.center.x) / tileResolution,
|
||||
(view2DState.center.y - origin.y) / tileResolution,
|
||||
(origin.x - center.x) / tileResolution,
|
||||
(center.y - origin.y) / tileResolution,
|
||||
0);
|
||||
|
||||
};
|
||||
|
||||
@@ -90,8 +90,17 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
||||
}
|
||||
var z = tileGrid.getZForResolution(view2DState.resolution);
|
||||
var tileResolution = tileGrid.getResolution(z);
|
||||
var center = view2DState.center;
|
||||
var extent;
|
||||
if (tileResolution == view2DState.resolution) {
|
||||
center = this.snapCenterToPixel(center, tileResolution, frameState.size);
|
||||
extent = ol.Extent.getForView2DAndSize(
|
||||
center, tileResolution, view2DState.rotation, frameState.size);
|
||||
} else {
|
||||
extent = frameState.extent;
|
||||
}
|
||||
var tileRange = tileGrid.getTileRangeForExtentAndResolution(
|
||||
frameState.extent, tileResolution);
|
||||
extent, tileResolution);
|
||||
|
||||
/** @type {Object.<number, Object.<string, ol.Tile>>} */
|
||||
var tilesToDrawByZ = {};
|
||||
@@ -146,7 +155,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
||||
tileLayerZ = this.tileLayerZs_[tileLayerZKey];
|
||||
} else {
|
||||
tileCoordOrigin =
|
||||
tileGrid.getTileCoordForCoordAndZ(view2DState.center, tileLayerZKey);
|
||||
tileGrid.getTileCoordForCoordAndZ(center, tileLayerZKey);
|
||||
tileLayerZ = new ol.renderer.dom.TileLayerZ_(tileGrid, tileCoordOrigin);
|
||||
newTileLayerZKeys[tileLayerZKey] = true;
|
||||
this.tileLayerZs_[tileLayerZKey] = tileLayerZ;
|
||||
@@ -183,8 +192,8 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
||||
resolution / view2DState.resolution, 1);
|
||||
goog.vec.Mat4.translate(
|
||||
transform,
|
||||
(origin.x - view2DState.center.x) / resolution,
|
||||
(view2DState.center.y - origin.y) / resolution,
|
||||
(origin.x - center.x) / resolution,
|
||||
(center.y - origin.y) / resolution,
|
||||
0);
|
||||
tileLayerZ.setTransform(transform);
|
||||
if (tileLayerZKey in newTileLayerZKeys) {
|
||||
@@ -201,7 +210,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
||||
} else {
|
||||
if (!frameState.viewHints[ol.ViewHint.ANIMATING] &&
|
||||
!frameState.viewHints[ol.ViewHint.INTERACTING]) {
|
||||
tileLayerZ.removeTilesOutsideExtent(frameState.extent);
|
||||
tileLayerZ.removeTilesOutsideExtent(extent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,7 +226,7 @@ ol.renderer.dom.TileLayer.prototype.renderFrame =
|
||||
}
|
||||
|
||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||
tileSource.useLowResolutionTiles(z, frameState.extent, tileGrid);
|
||||
tileSource.useLowResolutionTiles(z, extent, tileGrid);
|
||||
this.scheduleExpireCache(frameState, tileSource);
|
||||
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ goog.provide('ol.renderer.Layer');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.Attribution');
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.FrameState');
|
||||
goog.require('ol.Image');
|
||||
goog.require('ol.ImageState');
|
||||
@@ -299,3 +300,18 @@ ol.renderer.Layer.prototype.createGetTileIfLoadedFunction =
|
||||
return isLoadedFunction(tile) ? tile : null;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate} center Center.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {ol.Size} size Size.
|
||||
* @return {ol.Coordinate} Snapped center.
|
||||
* @protected
|
||||
*/
|
||||
ol.renderer.Layer.prototype.snapCenterToPixel =
|
||||
function(center, resolution, size) {
|
||||
return new ol.Coordinate(
|
||||
resolution * (Math.round(center.x / resolution) + (size.width % 2) / 2),
|
||||
resolution * (Math.round(center.y / resolution) + (size.height % 2) / 2));
|
||||
};
|
||||
|
||||
@@ -282,7 +282,6 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
||||
|
||||
var view2DState = frameState.view2DState;
|
||||
var projection = view2DState.projection;
|
||||
var center = view2DState.center;
|
||||
|
||||
var tileLayer = this.getTileLayer();
|
||||
var tileSource = tileLayer.getTileSource();
|
||||
@@ -293,8 +292,17 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
||||
}
|
||||
var z = tileGrid.getZForResolution(view2DState.resolution);
|
||||
var tileResolution = tileGrid.getResolution(z);
|
||||
var center = view2DState.center;
|
||||
var extent;
|
||||
if (tileResolution == view2DState.resolution) {
|
||||
center = this.snapCenterToPixel(center, tileResolution, frameState.size);
|
||||
extent = ol.Extent.getForView2DAndSize(
|
||||
center, tileResolution, view2DState.rotation, frameState.size);
|
||||
} else {
|
||||
extent = frameState.extent;
|
||||
}
|
||||
var tileRange = tileGrid.getTileRangeForExtentAndResolution(
|
||||
frameState.extent, tileResolution);
|
||||
extent, tileResolution);
|
||||
|
||||
var framebufferExtent;
|
||||
if (!goog.isNull(this.renderedTileRange_) &&
|
||||
@@ -460,14 +468,14 @@ ol.renderer.webgl.TileLayer.prototype.renderFrame =
|
||||
}
|
||||
|
||||
this.updateUsedTiles(frameState.usedTiles, tileSource, z, tileRange);
|
||||
tileSource.useLowResolutionTiles(z, frameState.extent, tileGrid);
|
||||
tileSource.useLowResolutionTiles(z, extent, tileGrid);
|
||||
this.scheduleExpireCache(frameState, tileSource);
|
||||
|
||||
goog.vec.Mat4.makeIdentity(this.texCoordMatrix_);
|
||||
goog.vec.Mat4.translate(this.texCoordMatrix_,
|
||||
(view2DState.center.x - framebufferExtent.minX) /
|
||||
(center.x - framebufferExtent.minX) /
|
||||
(framebufferExtent.maxX - framebufferExtent.minX),
|
||||
(view2DState.center.y - framebufferExtent.minY) /
|
||||
(center.y - framebufferExtent.minY) /
|
||||
(framebufferExtent.maxY - framebufferExtent.minY),
|
||||
0);
|
||||
goog.vec.Mat4.rotateZ(this.texCoordMatrix_, view2DState.rotation);
|
||||
|
||||
2
src/ol/source/wmtssource.exports
Normal file
2
src/ol/source/wmtssource.exports
Normal file
@@ -0,0 +1,2 @@
|
||||
@exportClass ol.source.WMTS ol.source.WMTSOptions
|
||||
@exportSymbol ol.source.WMTS.optionsFromCapabilities
|
||||
260
src/ol/source/wmtssource.js
Normal file
260
src/ol/source/wmtssource.js
Normal file
@@ -0,0 +1,260 @@
|
||||
goog.provide('ol.source.WMTS');
|
||||
goog.provide('ol.source.WMTSRequestEncoding');
|
||||
|
||||
goog.require('ol.Attribution');
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Projection');
|
||||
goog.require('ol.TileCoord');
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.TileUrlFunctionType');
|
||||
goog.require('ol.projection');
|
||||
goog.require('ol.source.ImageTileSource');
|
||||
goog.require('ol.tilegrid.WMTS');
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.source.WMTSRequestEncoding = {
|
||||
KVP: 'KVP', // see spec §8
|
||||
REST: 'REST' // see spec §10
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.source.ImageTileSource}
|
||||
* @param {ol.source.WMTSOptions} wmtsOptions WMTS options.
|
||||
*/
|
||||
ol.source.WMTS = function(wmtsOptions) {
|
||||
|
||||
// TODO: add support for TileMatrixLimits
|
||||
|
||||
var version = goog.isDef(wmtsOptions.version) ?
|
||||
wmtsOptions.version : '1.0.0';
|
||||
var format = goog.isDef(wmtsOptions.format) ?
|
||||
wmtsOptions.format : 'image/jpeg';
|
||||
var dimensions = wmtsOptions.dimensions || {};
|
||||
|
||||
// FIXME: should we guess this requestEncoding from wmtsOptions.url(s)
|
||||
// structure? that would mean KVP only if a template is not provided.
|
||||
var requestEncoding = goog.isDef(wmtsOptions.requestEncoding) ?
|
||||
wmtsOptions.requestEncoding : ol.source.WMTSRequestEncoding.KVP;
|
||||
|
||||
// FIXME: should we create a default tileGrid?
|
||||
// we could issue a getCapabilities xhr to retrieve missing configuration
|
||||
var tileGrid = wmtsOptions.tileGrid;
|
||||
|
||||
var context = {
|
||||
'Layer': wmtsOptions.layer,
|
||||
'style': wmtsOptions.style,
|
||||
'TileMatrixSet': wmtsOptions.matrixSet
|
||||
};
|
||||
goog.object.extend(context, dimensions);
|
||||
var kvpParams;
|
||||
if (requestEncoding == ol.source.WMTSRequestEncoding.KVP) {
|
||||
kvpParams = {
|
||||
'Service': 'WMTS',
|
||||
'Request': 'GetTile',
|
||||
'Version': version,
|
||||
'Format': format,
|
||||
'TileMatrix': '{TileMatrix}',
|
||||
'TileRow': '{TileRow}',
|
||||
'TileCol': '{TileCol}'
|
||||
};
|
||||
goog.object.extend(kvpParams, context);
|
||||
}
|
||||
|
||||
// TODO: factorize the code below so that it is usable by all sources
|
||||
var urls = wmtsOptions.urls;
|
||||
if (!goog.isDef(urls)) {
|
||||
urls = [];
|
||||
var url = wmtsOptions.url;
|
||||
goog.asserts.assert(goog.isDef(url));
|
||||
var match = /\{(\d)-(\d)\}/.exec(url) || /\{([a-z])-([a-z])\}/.exec(url);
|
||||
if (match) {
|
||||
var startCharCode = match[1].charCodeAt(0);
|
||||
var stopCharCode = match[2].charCodeAt(0);
|
||||
var charCode;
|
||||
for (charCode = startCharCode; charCode <= stopCharCode; ++charCode) {
|
||||
urls.push(url.replace(match[0], String.fromCharCode(charCode)));
|
||||
}
|
||||
} else {
|
||||
urls.push(url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} template Template.
|
||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||
*/
|
||||
function createFromWMTSTemplate(template) {
|
||||
return function(tileCoord) {
|
||||
if (goog.isNull(tileCoord)) {
|
||||
return undefined;
|
||||
} else {
|
||||
var localContext = {
|
||||
'TileMatrix': tileGrid.getMatrixId(tileCoord.z),
|
||||
'TileCol': tileCoord.x,
|
||||
'TileRow': tileCoord.y
|
||||
};
|
||||
if (requestEncoding != ol.source.WMTSRequestEncoding.KVP) {
|
||||
goog.object.extend(localContext, context);
|
||||
}
|
||||
var url = template;
|
||||
for (var key in localContext) {
|
||||
// FIXME: should we filter properties with hasOwnProperty?
|
||||
url = url.replace('{' + key + '}', localContext[key])
|
||||
.replace('%7B' + key + '%7D', localContext[key]);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var tileUrlFunction = ol.TileUrlFunction.createFromTileUrlFunctions(
|
||||
goog.array.map(urls, function(url) {
|
||||
if (goog.isDef(kvpParams)) {
|
||||
// TODO: we may want to create our own appendParams function
|
||||
// so that params order conforms to wmts spec guidance,
|
||||
// and so that we can avoid to escape special template params
|
||||
url = goog.uri.utils.appendParamsFromMap(url, kvpParams);
|
||||
}
|
||||
return createFromWMTSTemplate(url);
|
||||
}));
|
||||
|
||||
tileUrlFunction = ol.TileUrlFunction.withTileCoordTransform(
|
||||
function(tileCoord, tileGrid, projection) {
|
||||
if (tileGrid.getResolutions().length <= tileCoord.z) {
|
||||
return null;
|
||||
}
|
||||
var x = tileCoord.x;
|
||||
var y = -tileCoord.y - 1;
|
||||
var tileExtent = tileGrid.getTileCoordExtent(tileCoord);
|
||||
var projectionExtent = projection.getExtent();
|
||||
var extent = goog.isDef(wmtsOptions.extent) ?
|
||||
wmtsOptions.extent : projectionExtent;
|
||||
|
||||
if (!goog.isNull(extent) && projection.isGlobal() &&
|
||||
extent.minX === projectionExtent.minX &&
|
||||
extent.maxX === projectionExtent.maxX) {
|
||||
var numCols = Math.ceil(
|
||||
(extent.maxX - extent.minX) /
|
||||
(tileExtent.maxX - tileExtent.minX));
|
||||
x = goog.math.modulo(x, numCols);
|
||||
tileExtent = tileGrid.getTileCoordExtent(
|
||||
new ol.TileCoord(tileCoord.z, x, tileCoord.y));
|
||||
}
|
||||
if (!tileExtent.intersects(extent)) {
|
||||
return null;
|
||||
}
|
||||
return new ol.TileCoord(tileCoord.z, x, y);
|
||||
},
|
||||
tileUrlFunction);
|
||||
|
||||
goog.base(this, {
|
||||
attributions: wmtsOptions.attributions,
|
||||
crossOrigin: wmtsOptions.crossOrigin,
|
||||
extent: wmtsOptions.extent,
|
||||
projection: wmtsOptions.projection,
|
||||
tileGrid: tileGrid,
|
||||
tileUrlFunction: tileUrlFunction
|
||||
});
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.WMTS, ol.source.ImageTileSource);
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} wmtsCap An object representing the capabilities document.
|
||||
* @param {string} layer The layer identifier.
|
||||
* @return {ol.source.WMTSOptions} WMTS source options object.
|
||||
*/
|
||||
ol.source.WMTS.optionsFromCapabilities = function(wmtsCap, layer) {
|
||||
|
||||
// TODO: add support for TileMatrixLimits
|
||||
|
||||
var layers = wmtsCap['contents']['layers'];
|
||||
var l = goog.array.find(layers, function(elt, index, array) {
|
||||
return elt['identifier'] == layer;
|
||||
});
|
||||
goog.asserts.assert(!goog.isNull(l));
|
||||
goog.asserts.assert(l['tileMatrixSetLinks'].length > 0);
|
||||
var matrixSet = /** @type {string} */
|
||||
(l['tileMatrixSetLinks'][0]['tileMatrixSet']);
|
||||
var format = /** @type {string} */ (l['formats'][0]);
|
||||
var idx = goog.array.findIndex(l['styles'], function(elt, index, array) {
|
||||
return elt['isDefault'];
|
||||
});
|
||||
if (idx < 0) {
|
||||
idx = 0;
|
||||
}
|
||||
var style = /** @type {string} */ (l['styles'][idx]['identifier']);
|
||||
|
||||
var dimensions = {};
|
||||
goog.array.forEach(l['dimensions'], function(elt, index, array) {
|
||||
var key = elt['identifier'];
|
||||
var value = elt['default'];
|
||||
if (goog.isDef(value)) {
|
||||
goog.asserts.assert(goog.array.indexOf(elt['values'], value) >= 0);
|
||||
} else {
|
||||
value = elt['values'][0];
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(value));
|
||||
dimensions[key] = value;
|
||||
});
|
||||
|
||||
var matrixSets = wmtsCap['contents']['tileMatrixSets'];
|
||||
goog.asserts.assert(matrixSet in matrixSets);
|
||||
var matrixSetObj = matrixSets[matrixSet];
|
||||
|
||||
var tileGrid = ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet(
|
||||
matrixSetObj);
|
||||
|
||||
var projection = ol.projection.get(matrixSetObj['supportedCRS']);
|
||||
|
||||
var gets = wmtsCap['operationsMetadata']['GetTile']['dcp']['http']['get'];
|
||||
var encodings = goog.object.getKeys(
|
||||
gets[0]['constraints']['GetEncoding']['allowedValues']);
|
||||
goog.asserts.assert(encodings.length > 0);
|
||||
var requestEncoding = /** @type {ol.source.WMTSRequestEncoding} */
|
||||
(encodings[0]);
|
||||
// TODO: arcgis support, quote from ol2:
|
||||
// The OGC documentation is not clear if we should use REST or RESTful,
|
||||
// ArcGis use RESTful, and OpenLayers use REST.
|
||||
|
||||
var urls;
|
||||
switch (requestEncoding) {
|
||||
case ol.source.WMTSRequestEncoding.REST:
|
||||
goog.asserts.assert(l['resourceUrls'].hasOwnProperty('tile'));
|
||||
goog.asserts.assert(l['resourceUrls']['tile'].hasOwnProperty(format));
|
||||
urls = /** @type {Array.<string>} */
|
||||
(l['resourceUrls']['tile'][format]);
|
||||
break;
|
||||
case ol.source.WMTSRequestEncoding.KVP:
|
||||
urls = [];
|
||||
goog.array.forEach(gets, function(elt, index, array) {
|
||||
if (elt['constraints']['GetEncoding']['allowedValues'].hasOwnProperty(
|
||||
ol.source.WMTSRequestEncoding.KVP)) {
|
||||
urls.push(/** @type {string} */ (elt['url']));
|
||||
}
|
||||
});
|
||||
goog.asserts.assert(urls.length > 0);
|
||||
break;
|
||||
default:
|
||||
goog.asserts.assert(false);
|
||||
}
|
||||
|
||||
return {
|
||||
urls: urls,
|
||||
layer: layer,
|
||||
matrixSet: matrixSet,
|
||||
format: format,
|
||||
projection: projection,
|
||||
requestEncoding: requestEncoding,
|
||||
tileGrid: tileGrid,
|
||||
style: style,
|
||||
dimensions: dimensions
|
||||
};
|
||||
};
|
||||
1
src/ol/tilegrid/wmtstilegrid.exports
Normal file
1
src/ol/tilegrid/wmtstilegrid.exports
Normal file
@@ -0,0 +1 @@
|
||||
@exportClass ol.tilegrid.WMTS ol.tilegrid.WMTSOptions
|
||||
83
src/ol/tilegrid/wmtstilegrid.js
Normal file
83
src/ol/tilegrid/wmtstilegrid.js
Normal file
@@ -0,0 +1,83 @@
|
||||
goog.provide('ol.tilegrid.WMTS');
|
||||
|
||||
goog.require('ol.Size');
|
||||
goog.require('ol.projection');
|
||||
goog.require('ol.tilegrid.TileGrid');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.tilegrid.TileGrid}
|
||||
* @param {ol.tilegrid.WMTSOptions} wmtsOptions WMTS options.
|
||||
*/
|
||||
ol.tilegrid.WMTS = function(wmtsOptions) {
|
||||
|
||||
goog.asserts.assert(
|
||||
wmtsOptions.resolutions.length == wmtsOptions.matrixIds.length);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!Array.<string>}
|
||||
*/
|
||||
this.matrixIds_ = wmtsOptions.matrixIds;
|
||||
// FIXME: should the matrixIds become optionnal?
|
||||
|
||||
goog.base(this, {
|
||||
origin: wmtsOptions.origin,
|
||||
origins: wmtsOptions.origins,
|
||||
resolutions: wmtsOptions.resolutions,
|
||||
tileSize: wmtsOptions.tileSize,
|
||||
tileSizes: wmtsOptions.tileSizes
|
||||
});
|
||||
|
||||
};
|
||||
goog.inherits(ol.tilegrid.WMTS, ol.tilegrid.TileGrid);
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} z Z.
|
||||
* @return {string} MatrixId..
|
||||
*/
|
||||
ol.tilegrid.WMTS.prototype.getMatrixId = function(z) {
|
||||
goog.asserts.assert(0 <= z && z < this.matrixIds_.length);
|
||||
return this.matrixIds_[z];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<string>} MatrixIds.
|
||||
*/
|
||||
ol.tilegrid.WMTS.prototype.getMatrixIds = function() {
|
||||
return this.matrixIds_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} matrixSet An object representing a matrixSet in the
|
||||
* capabilities document.
|
||||
* @return {ol.tilegrid.WMTS} WMTS tileGrid instance.
|
||||
*/
|
||||
ol.tilegrid.WMTS.createFromCapabilitiesMatrixSet =
|
||||
function(matrixSet) {
|
||||
|
||||
var resolutions = [];
|
||||
var matrixIds = [];
|
||||
var origins = [];
|
||||
var tileSizes = [];
|
||||
var projection = ol.projection.get(matrixSet['supportedCRS']);
|
||||
var metersPerUnit = projection.getMetersPerUnit();
|
||||
goog.array.forEach(matrixSet['matrixIds'], function(elt, index, array) {
|
||||
matrixIds.push(elt['identifier']);
|
||||
origins.push(elt['topLeftCorner']);
|
||||
resolutions.push(elt['scaleDenominator'] * 0.28E-3 / metersPerUnit);
|
||||
tileSizes.push(new ol.Size(elt['tileWidth'], elt['tileHeight']));
|
||||
});
|
||||
|
||||
return new ol.tilegrid.WMTS({
|
||||
origins: origins,
|
||||
resolutions: resolutions,
|
||||
matrixIds: matrixIds,
|
||||
tileSizes: tileSizes
|
||||
});
|
||||
};
|
||||
@@ -60,6 +60,9 @@ ol.TileUrlFunction.createFromTemplates = function(templates) {
|
||||
* @return {ol.TileUrlFunctionType} Tile URL function.
|
||||
*/
|
||||
ol.TileUrlFunction.createFromTileUrlFunctions = function(tileUrlFunctions) {
|
||||
if (tileUrlFunctions.length === 1) {
|
||||
return tileUrlFunctions[0];
|
||||
}
|
||||
return function(tileCoord, tileGrid, projection) {
|
||||
if (goog.isNull(tileCoord)) {
|
||||
return undefined;
|
||||
|
||||
@@ -97,8 +97,59 @@ describe('ol.Extent', function() {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('getForView2DAndSize', function() {
|
||||
|
||||
it('works for a unit square', function() {
|
||||
var extent = ol.Extent.getForView2DAndSize(
|
||||
new ol.Coordinate(0, 0), 1, 0, new ol.Size(1, 1));
|
||||
expect(extent.minX).toBe(-0.5);
|
||||
expect(extent.minY).toBe(-0.5);
|
||||
expect(extent.maxX).toBe(0.5);
|
||||
expect(extent.maxY).toBe(0.5);
|
||||
});
|
||||
|
||||
it('works for center', function() {
|
||||
var extent = ol.Extent.getForView2DAndSize(
|
||||
new ol.Coordinate(5, 10), 1, 0, new ol.Size(1, 1));
|
||||
expect(extent.minX).toBe(4.5);
|
||||
expect(extent.minY).toBe(9.5);
|
||||
expect(extent.maxX).toBe(5.5);
|
||||
expect(extent.maxY).toBe(10.5);
|
||||
});
|
||||
|
||||
it('works for rotation', function() {
|
||||
var extent = ol.Extent.getForView2DAndSize(
|
||||
new ol.Coordinate(0, 0), 1, Math.PI / 4, new ol.Size(1, 1));
|
||||
expect(extent.minX).toRoughlyEqual(-Math.sqrt(0.5), 1e-9);
|
||||
expect(extent.minY).toRoughlyEqual(-Math.sqrt(0.5), 1e-9);
|
||||
expect(extent.maxX).toRoughlyEqual(Math.sqrt(0.5), 1e-9);
|
||||
expect(extent.maxY).toRoughlyEqual(Math.sqrt(0.5), 1e-9);
|
||||
});
|
||||
|
||||
it('works for resolution', function() {
|
||||
var extent = ol.Extent.getForView2DAndSize(
|
||||
new ol.Coordinate(0, 0), 2, 0, new ol.Size(1, 1));
|
||||
expect(extent.minX).toBe(-1);
|
||||
expect(extent.minY).toBe(-1);
|
||||
expect(extent.maxX).toBe(1);
|
||||
expect(extent.maxY).toBe(1);
|
||||
});
|
||||
|
||||
it('works for size', function() {
|
||||
var extent = ol.Extent.getForView2DAndSize(
|
||||
new ol.Coordinate(0, 0), 1, 0, new ol.Size(10, 5));
|
||||
expect(extent.minX).toBe(-5);
|
||||
expect(extent.minY).toBe(-2.5);
|
||||
expect(extent.maxX).toBe(5);
|
||||
expect(extent.maxY).toBe(2.5);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Coordinate');
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Size');
|
||||
goog.require('ol.projection');
|
||||
|
||||
262
test/spec/ol/parser/polyline.test.js
Normal file
262
test/spec/ol/parser/polyline.test.js
Normal file
@@ -0,0 +1,262 @@
|
||||
goog.provide('ol.test.parser.polyline');
|
||||
|
||||
describe('ol.parser.polyline', function() {
|
||||
|
||||
var flatPoints, encodedFlatPoints;
|
||||
var floats, smallFloats, encodedFloats;
|
||||
var signedIntegers, encodedSignedIntegers;
|
||||
var unsignedIntegers, encodedUnsignedIntegers;
|
||||
|
||||
function resetTestingData() {
|
||||
flatPoints = [38.50000, -120.20000,
|
||||
40.70000, -120.95000,
|
||||
43.25200, -126.45300];
|
||||
encodedFlatPoints = '_p~iF~ps|U_ulLnnqC_mqNvxq`@';
|
||||
|
||||
floats = [0.00, 0.15, -0.01, -0.16, 0.16, 0.01];
|
||||
smallFloats = [0.00000, 0.00015, -0.00001, -0.00016, 0.00016, 0.00001];
|
||||
encodedFloats = '?]@^_@A';
|
||||
|
||||
signedIntegers = [0, 15, -1, -16, 16, 1];
|
||||
encodedSignedIntegers = '?]@^_@A';
|
||||
|
||||
unsignedIntegers = [0, 30, 1, 31, 32, 2, 174];
|
||||
encodedUnsignedIntegers = '?]@^_@AmD';
|
||||
}
|
||||
|
||||
// Reset testing data
|
||||
beforeEach(resetTestingData);
|
||||
|
||||
|
||||
|
||||
describe('encodeFlatCoordinates', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeFlatCoordinates = ol.parser.polyline.encodeFlatCoordinates;
|
||||
|
||||
// from the "Encoded Polyline Algorithm Format" page at Google
|
||||
expect(encodeFlatCoordinates(flatPoints)).toEqual(encodedFlatPoints);
|
||||
});
|
||||
});
|
||||
|
||||
describe('decodeFlatCoordinates', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeFlatCoordinates = ol.parser.polyline.decodeFlatCoordinates;
|
||||
|
||||
// from the "Encoded Polyline Algorithm Format" page at Google
|
||||
expect(decodeFlatCoordinates(encodedFlatPoints)).toEqual(flatPoints);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('encodeDeltas', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeDeltas = ol.parser.polyline.encodeDeltas;
|
||||
|
||||
expect(encodeDeltas(flatPoints, 2)).toEqual(encodedFlatPoints);
|
||||
});
|
||||
});
|
||||
|
||||
describe('decodeDeltas', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeDeltas = ol.parser.polyline.decodeDeltas;
|
||||
|
||||
expect(decodeDeltas(encodedFlatPoints, 2)).toEqual(flatPoints);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('encodeFloats', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeFloats = ol.parser.polyline.encodeFloats;
|
||||
|
||||
expect(encodeFloats(smallFloats)).toEqual(encodedFloats);
|
||||
|
||||
resetTestingData();
|
||||
expect(encodeFloats(smallFloats, 1e5)).toEqual(encodedFloats);
|
||||
|
||||
expect(encodeFloats(floats, 1e2)).toEqual(encodedFloats);
|
||||
});
|
||||
});
|
||||
|
||||
describe('decodeFloats', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeFloats = ol.parser.polyline.decodeFloats;
|
||||
|
||||
expect(decodeFloats(encodedFloats)).toEqual(smallFloats);
|
||||
expect(decodeFloats(encodedFloats, 1e5)).toEqual(smallFloats);
|
||||
expect(decodeFloats(encodedFloats, 1e2)).toEqual(floats);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('encodeSignedIntegers', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeSignedIntegers = ol.parser.polyline.encodeSignedIntegers;
|
||||
|
||||
expect(encodeSignedIntegers(
|
||||
signedIntegers)).toEqual(encodedSignedIntegers);
|
||||
});
|
||||
});
|
||||
|
||||
describe('decodeSignedIntegers', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeSignedIntegers = ol.parser.polyline.decodeSignedIntegers;
|
||||
|
||||
expect(decodeSignedIntegers(
|
||||
encodedSignedIntegers)).toEqual(signedIntegers);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('encodeUnsignedIntegers', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeUnsignedIntegers = ol.parser.polyline.encodeUnsignedIntegers;
|
||||
|
||||
expect(encodeUnsignedIntegers(
|
||||
unsignedIntegers)).toEqual(encodedUnsignedIntegers);
|
||||
});
|
||||
});
|
||||
|
||||
describe('decodeUnsignedIntegers', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeUnsignedIntegers = ol.parser.polyline.decodeUnsignedIntegers;
|
||||
|
||||
expect(decodeUnsignedIntegers(
|
||||
encodedUnsignedIntegers)).toEqual(unsignedIntegers);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('encodeFloat', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeFloat = ol.parser.polyline.encodeFloat;
|
||||
|
||||
expect(encodeFloat(0.00000)).toEqual('?');
|
||||
expect(encodeFloat(-0.00001)).toEqual('@');
|
||||
expect(encodeFloat(0.00001)).toEqual('A');
|
||||
expect(encodeFloat(-0.00002)).toEqual('B');
|
||||
expect(encodeFloat(0.00002)).toEqual('C');
|
||||
expect(encodeFloat(0.00015)).toEqual(']');
|
||||
expect(encodeFloat(-0.00016)).toEqual('^');
|
||||
|
||||
expect(encodeFloat(-0.1, 10)).toEqual('@');
|
||||
expect(encodeFloat(0.1, 10)).toEqual('A');
|
||||
|
||||
expect(encodeFloat(16 * 32 / 1e5)).toEqual('__@');
|
||||
expect(encodeFloat(16 * 32 * 32 / 1e5)).toEqual('___@');
|
||||
|
||||
// from the "Encoded Polyline Algorithm Format" page at Google
|
||||
expect(encodeFloat(-179.9832104)).toEqual('`~oia@');
|
||||
});
|
||||
});
|
||||
|
||||
describe('decodeFloat', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeFloat = ol.parser.polyline.decodeFloat;
|
||||
|
||||
expect(decodeFloat('?')).toEqual(0.00000);
|
||||
expect(decodeFloat('@')).toEqual(-0.00001);
|
||||
expect(decodeFloat('A')).toEqual(0.00001);
|
||||
expect(decodeFloat('B')).toEqual(-0.00002);
|
||||
expect(decodeFloat('C')).toEqual(0.00002);
|
||||
expect(decodeFloat(']')).toEqual(0.00015);
|
||||
expect(decodeFloat('^')).toEqual(-0.00016);
|
||||
|
||||
expect(decodeFloat('@', 10)).toEqual(-0.1);
|
||||
expect(decodeFloat('A', 10)).toEqual(0.1);
|
||||
|
||||
expect(decodeFloat('__@')).toEqual(16 * 32 / 1e5);
|
||||
expect(decodeFloat('___@')).toEqual(16 * 32 * 32 / 1e5);
|
||||
|
||||
// from the "Encoded Polyline Algorithm Format" page at Google
|
||||
expect(decodeFloat('`~oia@')).toEqual(-179.98321);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('encodeSignedInteger', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeSignedInteger = ol.parser.polyline.encodeSignedInteger;
|
||||
|
||||
expect(encodeSignedInteger(0)).toEqual('?');
|
||||
expect(encodeSignedInteger(-1)).toEqual('@');
|
||||
expect(encodeSignedInteger(1)).toEqual('A');
|
||||
expect(encodeSignedInteger(-2)).toEqual('B');
|
||||
expect(encodeSignedInteger(2)).toEqual('C');
|
||||
expect(encodeSignedInteger(15)).toEqual(']');
|
||||
expect(encodeSignedInteger(-16)).toEqual('^');
|
||||
|
||||
expect(encodeSignedInteger(16)).toEqual('_@');
|
||||
expect(encodeSignedInteger(16 * 32)).toEqual('__@');
|
||||
expect(encodeSignedInteger(16 * 32 * 32)).toEqual('___@');
|
||||
});
|
||||
});
|
||||
|
||||
describe('decodeSignedInteger', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeSignedInteger = ol.parser.polyline.decodeSignedInteger;
|
||||
|
||||
expect(decodeSignedInteger('?')).toEqual(0);
|
||||
expect(decodeSignedInteger('@')).toEqual(-1);
|
||||
expect(decodeSignedInteger('A')).toEqual(1);
|
||||
expect(decodeSignedInteger('B')).toEqual(-2);
|
||||
expect(decodeSignedInteger('C')).toEqual(2);
|
||||
expect(decodeSignedInteger(']')).toEqual(15);
|
||||
expect(decodeSignedInteger('^')).toEqual(-16);
|
||||
|
||||
expect(decodeSignedInteger('_@')).toEqual(16);
|
||||
expect(decodeSignedInteger('__@')).toEqual(16 * 32);
|
||||
expect(decodeSignedInteger('___@')).toEqual(16 * 32 * 32);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('encodeUnsignedInteger', function() {
|
||||
it('returns expected value', function() {
|
||||
var encodeUnsignedInteger = ol.parser.polyline.encodeUnsignedInteger;
|
||||
|
||||
expect(encodeUnsignedInteger(0)).toEqual('?');
|
||||
expect(encodeUnsignedInteger(1)).toEqual('@');
|
||||
expect(encodeUnsignedInteger(2)).toEqual('A');
|
||||
expect(encodeUnsignedInteger(30)).toEqual(']');
|
||||
expect(encodeUnsignedInteger(31)).toEqual('^');
|
||||
expect(encodeUnsignedInteger(32)).toEqual('_@');
|
||||
|
||||
expect(encodeUnsignedInteger(32 * 32)).toEqual('__@');
|
||||
expect(encodeUnsignedInteger(5 * 32 * 32)).toEqual('__D');
|
||||
expect(encodeUnsignedInteger(32 * 32 * 32)).toEqual('___@');
|
||||
|
||||
// from the "Encoded Polyline Algorithm Format" page at Google
|
||||
expect(encodeUnsignedInteger(174)).toEqual('mD');
|
||||
});
|
||||
});
|
||||
|
||||
describe('decodeUnsignedInteger', function() {
|
||||
it('returns expected value', function() {
|
||||
var decodeUnsignedInteger = ol.parser.polyline.decodeUnsignedInteger;
|
||||
|
||||
expect(decodeUnsignedInteger('?')).toEqual(0);
|
||||
expect(decodeUnsignedInteger('@')).toEqual(1);
|
||||
expect(decodeUnsignedInteger('A')).toEqual(2);
|
||||
expect(decodeUnsignedInteger(']')).toEqual(30);
|
||||
expect(decodeUnsignedInteger('^')).toEqual(31);
|
||||
expect(decodeUnsignedInteger('_@')).toEqual(32);
|
||||
|
||||
expect(decodeUnsignedInteger('__@')).toEqual(32 * 32);
|
||||
expect(decodeUnsignedInteger('__D')).toEqual(5 * 32 * 32);
|
||||
expect(decodeUnsignedInteger('___@')).toEqual(32 * 32 * 32);
|
||||
|
||||
// from the "Encoded Polyline Algorithm Format" page at Google
|
||||
expect(decodeUnsignedInteger('mD')).toEqual(174);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('ol.parser.polyline');
|
||||
Reference in New Issue
Block a user