Removing old code
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
<!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>Style with rules example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
<a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
|
||||
</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">Style with rules example</h4>
|
||||
<p id="shortdesc">Draws features with rule based styles.</p>
|
||||
<div id="docs">
|
||||
<p>See the <a href="style-rules.js" target="_blank">style-rules.js source</a> to see how this is done.</p>
|
||||
</div>
|
||||
<div id="tags">vector, geojson, style</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="loader.js?id=style-rules" type="text/javascript"></script>
|
||||
<script src="../resources/example-behaviour.js" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,134 +0,0 @@
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.RendererHint');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.control');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.source.Vector');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.Rule');
|
||||
goog.require('ol.style.Shape');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Style');
|
||||
goog.require('ol.style.Text');
|
||||
|
||||
|
||||
var style = new ol.style.Style({rules: [
|
||||
new ol.style.Rule({
|
||||
filter: 'where == "outer"',
|
||||
symbolizers: [
|
||||
new ol.style.Stroke({
|
||||
color: ol.expr.parse('color'),
|
||||
width: 4,
|
||||
opacity: 1,
|
||||
zIndex: 1
|
||||
})
|
||||
]
|
||||
}),
|
||||
new ol.style.Rule({
|
||||
filter: 'where == "inner"',
|
||||
symbolizers: [
|
||||
new ol.style.Stroke({
|
||||
color: '#013',
|
||||
width: 4,
|
||||
opacity: 1
|
||||
}),
|
||||
new ol.style.Stroke({
|
||||
color: ol.expr.parse('color'),
|
||||
width: 2,
|
||||
opacity: 1
|
||||
})
|
||||
]
|
||||
}),
|
||||
new ol.style.Rule({
|
||||
filter: 'geometryType("Point")',
|
||||
symbolizers: [
|
||||
new ol.style.Shape({
|
||||
size: 40,
|
||||
fill: new ol.style.Fill({color: '#013'})
|
||||
}),
|
||||
new ol.style.Text({
|
||||
color: '#bada55',
|
||||
text: ol.expr.parse('label'),
|
||||
fontFamily: 'Calibri,sans-serif',
|
||||
fontSize: 14
|
||||
})
|
||||
]
|
||||
})
|
||||
]});
|
||||
|
||||
var vector = new ol.layer.Vector({
|
||||
style: style,
|
||||
source: new ol.source.Vector({
|
||||
features: [
|
||||
new ol.Feature({
|
||||
color: '#BADA55',
|
||||
where: 'inner',
|
||||
geometry: new ol.geom.LineString(
|
||||
[[-10000000, -10000000], [10000000, 10000000]])
|
||||
}),
|
||||
new ol.Feature({
|
||||
color: '#BADA55',
|
||||
where: 'inner',
|
||||
geometry: new ol.geom.LineString(
|
||||
[[-10000000, 10000000], [10000000, -10000000]])
|
||||
}),
|
||||
new ol.Feature({
|
||||
color: '#013',
|
||||
where: 'outer',
|
||||
geometry: new ol.geom.LineString(
|
||||
[[-10000000, -10000000], [-10000000, 10000000]])
|
||||
}),
|
||||
new ol.Feature({
|
||||
color: '#013',
|
||||
where: 'outer',
|
||||
geometry: new ol.geom.LineString(
|
||||
[[-10000000, 10000000], [10000000, 10000000]])
|
||||
}),
|
||||
new ol.Feature({
|
||||
color: '#013',
|
||||
where: 'outer',
|
||||
geometry: new ol.geom.LineString(
|
||||
[[10000000, 10000000], [10000000, -10000000]])
|
||||
}),
|
||||
new ol.Feature({
|
||||
color: '#013',
|
||||
where: 'outer',
|
||||
geometry: new ol.geom.LineString(
|
||||
[[10000000, -10000000], [-10000000, -10000000]])
|
||||
}),
|
||||
new ol.Feature({
|
||||
label: 'South',
|
||||
geometry: new ol.geom.Point([0, -6000000])
|
||||
}),
|
||||
new ol.Feature({
|
||||
label: 'West',
|
||||
geometry: new ol.geom.Point([-6000000, 0])
|
||||
}),
|
||||
new ol.Feature({
|
||||
label: 'North',
|
||||
geometry: new ol.geom.Point([0, 6000000])
|
||||
}),
|
||||
new ol.Feature({
|
||||
label: 'East',
|
||||
geometry: new ol.geom.Point([6000000, 0])
|
||||
})
|
||||
]
|
||||
})
|
||||
});
|
||||
|
||||
var map = new ol.Map({
|
||||
layers: [vector],
|
||||
controls: ol.control.defaults({
|
||||
attribution: false
|
||||
}),
|
||||
renderer: ol.RendererHint.CANVAS,
|
||||
target: 'map',
|
||||
view: new ol.View2D({
|
||||
center: [0, 0],
|
||||
zoom: 1
|
||||
})
|
||||
});
|
||||
@@ -1,50 +0,0 @@
|
||||
<!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>Synthetic data example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
<a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
|
||||
</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">Synthetic data example</h4>
|
||||
<p id="shortdesc">Synthetic data example.</p>
|
||||
<div id="docs">
|
||||
<p>See the <a href="synthetic-data.js" target="_blank">synthetic-data.js source</a> to see how this is done.</p>
|
||||
</div>
|
||||
<div id="tags">vector</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="loader.js?id=synthetic-data" type="text/javascript"></script>
|
||||
<script src="../resources/example-behaviour.js" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,80 +0,0 @@
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.Overlay');
|
||||
goog.require('ol.RendererHint');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.parser.GeoJSON');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.MapQuestOpenAerial');
|
||||
goog.require('ol.source.Vector');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.Rule');
|
||||
goog.require('ol.style.Shape');
|
||||
goog.require('ol.style.ShapeType');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Style');
|
||||
|
||||
|
||||
var raster = new ol.layer.Tile({
|
||||
source: new ol.source.MapQuestOpenAerial()
|
||||
});
|
||||
|
||||
// build up some GeoJSON features
|
||||
var count = 20000;
|
||||
var features = new Array(count);
|
||||
var e = 18000000;
|
||||
for (var i = 0; i < count; ++i) {
|
||||
features[i] = {
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
i: i,
|
||||
size: i % 2 ? 10 : 20
|
||||
},
|
||||
geometry: {
|
||||
type: 'Point',
|
||||
coordinates: [
|
||||
2 * e * Math.random() - e, 2 * e * Math.random() - e
|
||||
]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var vector = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
projection: ol.proj.get('EPSG:3857'),
|
||||
parser: new ol.parser.GeoJSON(),
|
||||
data: {
|
||||
type: 'FeatureCollection',
|
||||
features: features
|
||||
}
|
||||
}),
|
||||
style: new ol.style.Style({rules: [
|
||||
new ol.style.Rule({
|
||||
symbolizers: [
|
||||
new ol.style.Shape({
|
||||
type: ol.style.ShapeType.CIRCLE,
|
||||
size: ol.expr.parse('size'),
|
||||
stroke: new ol.style.Stroke({color: '#666666'}),
|
||||
fill: new ol.style.Fill({color: '#bada55'})
|
||||
})
|
||||
]
|
||||
})
|
||||
]})
|
||||
});
|
||||
|
||||
var popup = new ol.Overlay({
|
||||
element: document.getElementById('popup')
|
||||
});
|
||||
|
||||
var map = new ol.Map({
|
||||
layers: [vector],
|
||||
renderer: ol.RendererHint.CANVAS,
|
||||
target: 'map',
|
||||
view: new ol.View2D({
|
||||
center: [0, 0],
|
||||
zoom: 2
|
||||
}),
|
||||
overlays: [popup]
|
||||
});
|
||||
@@ -1,56 +0,0 @@
|
||||
<!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>Vector layer with styling from SLD 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"> </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="span4">
|
||||
<h4 id="title">Vector layer example</h4>
|
||||
<p id="shortdesc">Example of a countries vector layer with country labels at higher zoom levels, styling info coming from SLD.</p>
|
||||
<div id="docs">
|
||||
<p>See the <a href="vector-layer-sld.js" target="_blank">vector-layer-sld.js source</a> to see how this is done.</p>
|
||||
</div>
|
||||
<div id="tags">vector, geojson, style, SLD, Styled Layer Descriptor</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="loader.js?id=vector-layer-sld" type="text/javascript"></script>
|
||||
<script src="../resources/social-links.js" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,54 +0,0 @@
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.RendererHint');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.control');
|
||||
goog.require('ol.control.ScaleLine');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.parser.GeoJSON');
|
||||
goog.require('ol.parser.ogc.SLD');
|
||||
goog.require('ol.source.MapQuest');
|
||||
goog.require('ol.source.Vector');
|
||||
|
||||
|
||||
var raster = new ol.layer.Tile({
|
||||
source: new ol.source.MapQuest({layer: 'sat'})
|
||||
});
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'data/countries.sld', true);
|
||||
|
||||
|
||||
/**
|
||||
* onload handler for the XHR request.
|
||||
*/
|
||||
xhr.onload = function() {
|
||||
if (xhr.status == 200) {
|
||||
var map = new ol.Map({
|
||||
controls: ol.control.defaults().extend([
|
||||
new ol.control.ScaleLine()
|
||||
]),
|
||||
layers: [raster],
|
||||
renderer: ol.RendererHint.CANVAS,
|
||||
target: 'map',
|
||||
view: new ol.View2D({
|
||||
center: [0, 0],
|
||||
zoom: 1
|
||||
})
|
||||
});
|
||||
var units = map.getView().getView2D().getProjection().getUnits();
|
||||
var sld = new ol.parser.ogc.SLD().read(xhr.responseText, {
|
||||
units: units
|
||||
});
|
||||
var style = sld.namedLayers['countries'].userStyles[0];
|
||||
var vector = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
parser: new ol.parser.GeoJSON(),
|
||||
url: 'data/countries.geojson'
|
||||
}),
|
||||
style: style
|
||||
});
|
||||
map.getLayers().push(vector);
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
@@ -1,49 +0,0 @@
|
||||
<!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>WMTS Capabilities parsing example</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
<a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container-fluid">
|
||||
|
||||
<div class="row-fluid">
|
||||
|
||||
<div class="span4">
|
||||
<h4 id="title">WMTS Capabilities parsing example</h4>
|
||||
<p id="shortdesc">Example of parsing a WMTS Capabilities document.</p>
|
||||
<div id="docs">
|
||||
<p>See the <a href="wmts-capabilities.js" target="_blank">wmts-capabilities.js source</a> to see how this is done.</p>
|
||||
</div>
|
||||
<div id="tags">wmts, WMTSCapabilities</div>
|
||||
</div>
|
||||
|
||||
<div class="span8">
|
||||
<pre id="log"></pre>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/1.1.0/proj4js-compressed.js" type="text/javascript"></script>
|
||||
<script src="loader.js?id=wmts-capabilities" type="text/javascript"></script>
|
||||
<script src="../resources/example-behaviour.js" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,26 +0,0 @@
|
||||
goog.require('ol.parser.ogc.WMTSCapabilities');
|
||||
goog.require('ol.proj.common');
|
||||
|
||||
ol.proj.common.add();
|
||||
Proj4js.defs['EPSG:31256'] = '+proj=tmerc +lat_0=0 ' +
|
||||
'+lon_0=16.33333333333333 +k=1 +x_0=0 +y_0=-5000000 +ellps=bessel ' +
|
||||
'+towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232 ' +
|
||||
'+units=m +no_defs';
|
||||
var parser = new ol.parser.ogc.WMTSCapabilities(), result;
|
||||
var url = 'data/WMTSCapabilities.xml';
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
|
||||
|
||||
/**
|
||||
* onload handler for the XHR request.
|
||||
*/
|
||||
xhr.onload = function() {
|
||||
if (xhr.status == 200) {
|
||||
result = parser.read(xhr.responseXML);
|
||||
document.getElementById('log').innerHTML =
|
||||
window.JSON.stringify(result, undefined, 2);
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
@@ -1,50 +0,0 @@
|
||||
<!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>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="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
|
||||
</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">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="loader.js?id=wmts-from-capabilities" type="text/javascript"></script>
|
||||
<script src="../resources/example-behaviour.js" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,42 +0,0 @@
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.RendererHint');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.parser.ogc.WMTSCapabilities');
|
||||
goog.require('ol.source.WMTS');
|
||||
|
||||
|
||||
var map, capabilities;
|
||||
var parser = new ol.parser.ogc.WMTSCapabilities();
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'data/WMTSCapabilities.xml', true);
|
||||
|
||||
|
||||
/**
|
||||
* onload handler for the XHR request.
|
||||
*/
|
||||
xhr.onload = function() {
|
||||
if (xhr.status == 200) {
|
||||
capabilities = parser.read(xhr.responseXML);
|
||||
map = new ol.Map({
|
||||
layers: [
|
||||
new ol.layer.Tile({
|
||||
source: new ol.source.WMTS(ol.source.WMTS.optionsFromCapabilities(
|
||||
capabilities, 'fmzk'))
|
||||
}),
|
||||
new ol.layer.Tile({
|
||||
source: new ol.source.WMTS(ol.source.WMTS.optionsFromCapabilities(
|
||||
capabilities, 'beschriftung'))
|
||||
})
|
||||
],
|
||||
renderer: ol.RendererHint.CANVAS,
|
||||
target: 'map',
|
||||
view: new ol.View2D({
|
||||
center: [1823849, 6143760],
|
||||
zoom: 11
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
@@ -1,59 +0,0 @@
|
||||
<!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>IGN WMTS example</title>
|
||||
<style>
|
||||
.ol-logo ul li {
|
||||
margin-right: 3px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
<a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
|
||||
</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">IGN WMTS example</h4>
|
||||
<p id="shortdesc">Demonstrates displaying IGN (France) WMTS layers.</p>
|
||||
<div id="docs">
|
||||
<p>In this example two IGN WMTS layers are displayed: <em>Ortho imagery and Cadastral parcels.</em>.
|
||||
For more information on IGN's WMTS service see the
|
||||
<a href="http://professionnels.ign.fr/api-sig">IGN Géoportail API web page</a> (french).</p>
|
||||
<p>See the <a href="wmts-ign.js" target="_blank">wmts-ign.js source</a> to see how this is done.</p>
|
||||
</div>
|
||||
<div id="tags">french, ign, geoportail, 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="loader.js?id=wmts-ign" type="text/javascript"></script>
|
||||
<script src="../resources/example-behaviour.js" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,86 +0,0 @@
|
||||
goog.require('ol.Attribution');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.RendererHint');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.parser.ogc.WMTSCapabilities');
|
||||
goog.require('ol.source.WMTS');
|
||||
|
||||
|
||||
// The WMTS Capabilities document includes IGNF:WGS84G as a supported
|
||||
// CRS. We include the Proj4js definition of that projection to prevent
|
||||
// Proj4js from requesting that definition from spatialreference.org.
|
||||
|
||||
Proj4js.defs['IGNF:WGS84G'] = '+title=World Geodetic System 1984 ' +
|
||||
'+proj=longlat +towgs84=0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,' +
|
||||
'0.000000 +a=6378137.0000 +rf=298.2572221010000 +units=m +no_defs <>';
|
||||
|
||||
// API key valid for "localhost" and "ol3js.org". Expiration date
|
||||
// is 21/06/2014.
|
||||
var key = 'crrypaoz7j1ifbalcobnumb0';
|
||||
|
||||
var map = new ol.Map({
|
||||
renderer: ol.RendererHint.CANVAS,
|
||||
target: 'map'
|
||||
});
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
// data/IGNWMTSCapabilities.xml downloaded from
|
||||
// http://wxs.ign.fr/cle/geoportail/wmts?SERVICE=WMTS&REQUEST=GetCapabilities
|
||||
// Stored locally because of the Same Origin Policy.
|
||||
xhr.open('GET', 'data/IGNWMTSCapabilities.xml', true);
|
||||
|
||||
|
||||
/**
|
||||
* onload handler for the XHR request.
|
||||
*/
|
||||
xhr.onload = function() {
|
||||
if (xhr.status == 200) {
|
||||
var parser = new ol.parser.ogc.WMTSCapabilities();
|
||||
var capabilities = parser.read(xhr.responseXML);
|
||||
|
||||
var wmtsUrl = 'http://wxs.ign.fr/' + key + '/geoportail/wmts';
|
||||
|
||||
var layerIdentifiers = [
|
||||
'ORTHOIMAGERY.ORTHOPHOTOS',
|
||||
'CADASTRALPARCELS.PARCELS'
|
||||
];
|
||||
var layerLogos = [
|
||||
'http://gpp3-wxs.ign.fr/static/logos/PLANETOBSERVER/PLANETOBSERVER.gif',
|
||||
'http://gpp3-wxs.ign.fr/static/logos/IGN/IGN.gif'
|
||||
];
|
||||
|
||||
var attribution = new ol.Attribution({
|
||||
html: '<a href="http://www.geoportail.fr/" target="_blank">' +
|
||||
'<img src="http://api.ign.fr/geoportail/api/js/latest/' +
|
||||
'theme/geoportal/img/logo_gp.gif"></a>'
|
||||
});
|
||||
|
||||
var sourceOptions;
|
||||
var source;
|
||||
var layer;
|
||||
var i;
|
||||
|
||||
for (i = 0; i < layerIdentifiers.length; ++i) {
|
||||
sourceOptions = ol.source.WMTS.optionsFromCapabilities(
|
||||
capabilities, layerIdentifiers[i]);
|
||||
// we need to set the URL because it must include the key.
|
||||
sourceOptions.urls = [wmtsUrl];
|
||||
sourceOptions.attributions = [attribution];
|
||||
sourceOptions.logo = layerLogos[i];
|
||||
source = new ol.source.WMTS(sourceOptions);
|
||||
layer = new ol.layer.Tile({source: source});
|
||||
map.addLayer(layer);
|
||||
}
|
||||
|
||||
var view = new ol.View2D();
|
||||
view.fitExtent(
|
||||
[257596.65942095537, 6250898.984085131,
|
||||
262082.55751844167, 6251854.446938695],
|
||||
/** @type {ol.Size} */ (map.getSize()));
|
||||
map.setView(view);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
@@ -1,96 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.ExceptionReport');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.parser.XML');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.XML}
|
||||
*/
|
||||
ol.parser.ogc.ExceptionReport = function() {
|
||||
var exceptionReader = function(node, exceptionReport) {
|
||||
var exception = {
|
||||
code: node.getAttribute('exceptionCode'),
|
||||
locator: node.getAttribute('locator'),
|
||||
texts: []
|
||||
};
|
||||
exceptionReport.exceptions.push(exception);
|
||||
this.readChildNodes(node, exception);
|
||||
};
|
||||
var exceptionTextReader = function(node, exception) {
|
||||
var text = this.getChildValue(node);
|
||||
exception.texts.push(text);
|
||||
};
|
||||
this.readers = {
|
||||
'http://www.opengis.net/ogc': {
|
||||
'ServiceExceptionReport': function(node, obj) {
|
||||
obj['exceptionReport'] = {};
|
||||
obj['exceptionReport']['exceptions'] = [];
|
||||
this.readChildNodes(node, obj['exceptionReport']);
|
||||
},
|
||||
'ServiceException': function(node, exceptionReport) {
|
||||
var exception = {};
|
||||
exception['code'] = node.getAttribute('code');
|
||||
exception['locator'] = node.getAttribute('locator');
|
||||
exception['text'] = this.getChildValue(node);
|
||||
exceptionReport['exceptions'].push(exception);
|
||||
}
|
||||
},
|
||||
'http://www.opengis.net/ows': {
|
||||
'ExceptionReport': function(node, obj) {
|
||||
obj.success = false;
|
||||
obj.exceptionReport = {
|
||||
version: node.getAttribute('version'),
|
||||
language: node.getAttribute('language'),
|
||||
exceptions: []
|
||||
};
|
||||
this.readChildNodes(node, obj.exceptionReport);
|
||||
},
|
||||
'Exception': function(node, exceptionReport) {
|
||||
exceptionReader.apply(this, arguments);
|
||||
},
|
||||
'ExceptionText': function(node, exception) {
|
||||
exceptionTextReader.apply(this, arguments);
|
||||
}
|
||||
},
|
||||
'http://www.opengis.net/ows/1.1': {
|
||||
'ExceptionReport': function(node, obj) {
|
||||
obj.exceptionReport = {
|
||||
version: node.getAttribute('version'),
|
||||
language: node.getAttribute('xml:lang'),
|
||||
exceptions: []
|
||||
};
|
||||
this.readChildNodes(node, obj.exceptionReport);
|
||||
},
|
||||
'Exception': function(node, exceptionReport) {
|
||||
exceptionReader.apply(this, arguments);
|
||||
},
|
||||
'ExceptionText': function(node, exception) {
|
||||
exceptionTextReader.apply(this, arguments);
|
||||
}
|
||||
}
|
||||
};
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.ExceptionReport, ol.parser.XML);
|
||||
|
||||
|
||||
/**
|
||||
* Read OGC exception report data from a string, and return an object with
|
||||
* information about the exceptions.
|
||||
*
|
||||
* @param {string|Document} data to read/parse.
|
||||
* @return {Object} Information about the exceptions that occurred.
|
||||
*/
|
||||
ol.parser.ogc.ExceptionReport.prototype.read = function(data) {
|
||||
if (goog.isString(data)) {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
var exceptionInfo = {};
|
||||
exceptionInfo['exceptionReport'] = null;
|
||||
if (data) {
|
||||
this.readChildNodes(data, exceptionInfo);
|
||||
}
|
||||
return exceptionInfo;
|
||||
};
|
||||
@@ -1,121 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.Versioned');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.parser.ogc.ExceptionReport');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object=} opt_options Options which will be set on this object.
|
||||
*/
|
||||
ol.parser.ogc.Versioned = function(opt_options) {
|
||||
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||
this.options = options;
|
||||
this.defaultVersion = options.defaultVersion || null;
|
||||
this.version = options.version;
|
||||
this.profile = options.profile;
|
||||
if (goog.isDef(options.allowFallback)) {
|
||||
this.allowFallback = options.allowFallback;
|
||||
} else {
|
||||
this.allowFallback = false;
|
||||
}
|
||||
if (goog.isDef(options.stringifyOutput)) {
|
||||
this.stringifyOutput = options.stringifyOutput;
|
||||
} else {
|
||||
this.stringifyOutput = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} root root element.
|
||||
* @param {Object=} opt_options optional configuration object.
|
||||
* @return {string} the version to use.
|
||||
*/
|
||||
ol.parser.ogc.Versioned.prototype.getVersion = function(root, opt_options) {
|
||||
var version;
|
||||
// read
|
||||
if (root) {
|
||||
version = this.version;
|
||||
if (!version) {
|
||||
version = root.getAttribute('version');
|
||||
if (!version) {
|
||||
version = this.defaultVersion;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// write
|
||||
version = (opt_options && opt_options.version) ||
|
||||
this.version || this.defaultVersion;
|
||||
}
|
||||
return version;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} version the version to use.
|
||||
* @return {Object} the parser to use.
|
||||
*/
|
||||
ol.parser.ogc.Versioned.prototype.getParser = function(version) {
|
||||
version = version || this.defaultVersion;
|
||||
var profile = this.profile ? '_' + this.profile : '';
|
||||
if (!this.parser || this.parser.VERSION != version) {
|
||||
var format = this.parsers['v' + version.replace(/\./g, '_') + profile];
|
||||
if (!format) {
|
||||
if (profile !== '' && this.allowFallback) {
|
||||
// fallback to the non-profiled version of the parser
|
||||
profile = '';
|
||||
format = this.parsers['v' + version.replace(/\./g, '_') + profile];
|
||||
}
|
||||
if (!format) {
|
||||
throw 'Can\'t find a parser for version ' +
|
||||
version + profile;
|
||||
}
|
||||
}
|
||||
this.parser = new format(this.options);
|
||||
}
|
||||
return this.parser;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Write a document.
|
||||
*
|
||||
* @param {Object} obj An object representing the document.
|
||||
* @param {Object=} opt_options Optional configuration object.
|
||||
* @return {Element|string} the XML created.
|
||||
*/
|
||||
ol.parser.ogc.Versioned.prototype.write = function(obj, opt_options) {
|
||||
var version = this.getVersion(null, opt_options);
|
||||
this.parser = this.getParser(version);
|
||||
var root = this.parser.write(obj, opt_options);
|
||||
if (this.stringifyOutput === false) {
|
||||
return root;
|
||||
} else {
|
||||
return goog.dom.xml.serialize(root);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|Document} data Data to read.
|
||||
* @param {Object=} opt_options Options for the reader.
|
||||
* @return {Object} An object representing the document.
|
||||
*/
|
||||
ol.parser.ogc.Versioned.prototype.read = function(data, opt_options) {
|
||||
if (goog.isString(data)) {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
var root = data.documentElement;
|
||||
var version = this.getVersion(root);
|
||||
this.parser = this.getParser(version);
|
||||
var obj = this.parser.read(data, opt_options);
|
||||
var errorProperty = this.parser.errorProperty || null;
|
||||
if (errorProperty !== null && obj[errorProperty] === undefined) {
|
||||
// an error must have happened, so parse it and report back
|
||||
var format = new ol.parser.ogc.ExceptionReport();
|
||||
obj.error = format.read(data);
|
||||
}
|
||||
obj.version = version;
|
||||
return obj;
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
goog.provide('ol.parser.Parser');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.Parser = function() {};
|
||||
@@ -1,296 +0,0 @@
|
||||
goog.provide('ol.parser.XML');
|
||||
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.parser.Parser');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.Parser}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.XML = function() {
|
||||
if (goog.global.ActiveXObject) {
|
||||
this.xmldom = new ActiveXObject('Microsoft.XMLDOM');
|
||||
}
|
||||
this.regExes = {
|
||||
trimSpace: (/^\s*|\s*$/g),
|
||||
removeSpace: (/\s*/g),
|
||||
splitSpace: (/\s+/),
|
||||
trimComma: (/\s*,\s*/g)
|
||||
};
|
||||
};
|
||||
goog.inherits(ol.parser.XML, ol.parser.Parser);
|
||||
|
||||
|
||||
/**
|
||||
* Shorthand for applying one of the named readers given the node
|
||||
* namespace and local name. Readers take two args (node, obj) and
|
||||
* generally extend or modify the second.
|
||||
*
|
||||
* @param {Element|Document} node The node to be read (required).
|
||||
* @param {Object} obj The object to be modified (optional).
|
||||
* @return {Object} The input object, modified (or a new one if none was
|
||||
* provided).
|
||||
*/
|
||||
ol.parser.XML.prototype.readNode = function(node, obj) {
|
||||
if (!obj) {
|
||||
obj = {};
|
||||
}
|
||||
var group = this.readers[node.namespaceURI] ||
|
||||
this.readers[this.defaultNamespaceURI];
|
||||
if (group) {
|
||||
var local = node.localName || node.nodeName.split(':').pop();
|
||||
var reader = group[local] || group['*'];
|
||||
if (reader) {
|
||||
reader.apply(this, [node, obj]);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Shorthand for applying the named readers to all children of a node.
|
||||
* For each child of type 1 (element), <readSelf> is called.
|
||||
*
|
||||
* @param {Element|Document} node The node to be read (required).
|
||||
* @param {Object} obj The object to be modified (optional).
|
||||
* @return {Object} The input object, modified.
|
||||
*/
|
||||
ol.parser.XML.prototype.readChildNodes = function(node, obj) {
|
||||
if (!obj) {
|
||||
obj = {};
|
||||
}
|
||||
var children = node.childNodes;
|
||||
var child;
|
||||
for (var i = 0, len = children.length; i < len; ++i) {
|
||||
child = children[i];
|
||||
if (child.nodeType == 1) {
|
||||
this.readNode(child, obj);
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the textual value of the node if it exists, or return an
|
||||
* optional default string. Returns an empty string if no first child
|
||||
* exists and no default value is supplied.
|
||||
*
|
||||
* @param {Element} node The element used to look for a first child value.
|
||||
* @param {string} def Optional string to return in the event that no
|
||||
* first child value exists.
|
||||
* @return {string} The value of the first child of the given node.
|
||||
*/
|
||||
ol.parser.XML.prototype.getChildValue = function(node, def) {
|
||||
var value = def || '';
|
||||
if (node) {
|
||||
for (var child = node.firstChild; child; child = child.nextSibling) {
|
||||
switch (child.nodeType) {
|
||||
case 3: // text node
|
||||
case 4: // cdata section
|
||||
value += child.nodeValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get an attribute node given the namespace URI and local name.
|
||||
*
|
||||
* @param {Element} node Node on which to search for attribute nodes.
|
||||
* @param {string} uri Namespace URI.
|
||||
* @param {string} name Local name of the attribute (without the prefix).
|
||||
* @return {?Element} An attribute node or null if none found.
|
||||
*/
|
||||
ol.parser.XML.prototype.getAttributeNodeNS = function(node, uri, name) {
|
||||
var attributeNode = null;
|
||||
if (node.getAttributeNodeNS) {
|
||||
attributeNode = node.getAttributeNodeNS(uri, name);
|
||||
} else {
|
||||
var attributes = node.attributes;
|
||||
var potentialNode, fullName;
|
||||
for (var i = 0, len = attributes.length; i < len; ++i) {
|
||||
potentialNode = attributes[i];
|
||||
if (potentialNode.namespaceURI == uri) {
|
||||
fullName = (potentialNode.prefix) ?
|
||||
(potentialNode.prefix + ':' + name) : name;
|
||||
if (fullName == potentialNode.nodeName) {
|
||||
attributeNode = potentialNode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return attributeNode;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get an attribute value given the namespace URI and local name.
|
||||
*
|
||||
* @param {Element} node Node on which to search for an attribute.
|
||||
* @param {string} uri Namespace URI.
|
||||
* @param {string} name Local name of the attribute (without the prefix).
|
||||
* @return {string} An attribute value or and empty string if none found.
|
||||
*/
|
||||
ol.parser.XML.prototype.getAttributeNS = function(node, uri, name) {
|
||||
var attributeValue = '';
|
||||
if (node.getAttributeNS) {
|
||||
attributeValue = node.getAttributeNS(uri, name) || '';
|
||||
} else {
|
||||
var attributeNode = this.getAttributeNodeNS(node, uri, name);
|
||||
if (attributeNode) {
|
||||
attributeValue = attributeNode.nodeValue;
|
||||
}
|
||||
}
|
||||
return attributeValue;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a new element with namespace. This node can be appended to
|
||||
* another node with the standard node.appendChild method. For
|
||||
* cross-browser support, this method must be used instead of
|
||||
* document.createElementNS.
|
||||
*
|
||||
* @param {string} name The qualified name of the element (prefix:localname).
|
||||
* @param {string=} opt_uri Namespace URI for the element.
|
||||
* @return {Element} A DOM element with namespace.
|
||||
*/
|
||||
ol.parser.XML.prototype.createElementNS = function(name, opt_uri) {
|
||||
var uri = opt_uri ? opt_uri : this.defaultNamespaceURI;
|
||||
var element;
|
||||
if (this.xmldom) {
|
||||
element = this.xmldom.createNode(1, name, uri);
|
||||
} else {
|
||||
element = document.createElementNS(uri, name);
|
||||
}
|
||||
return element;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Shorthand for applying one of the named writers and appending the
|
||||
* results to a node.
|
||||
*
|
||||
* @param {string} name The name of a node to generate. Only use a local name.
|
||||
* @param {Object|string|number} obj Structure containing data for the writer.
|
||||
* @param {?string=} opt_uri The name space uri to which the node
|
||||
* belongs.
|
||||
* @param {Element=} opt_parent Result will be appended to this node. If no
|
||||
* parent is supplied, the node will not be appended to anything.
|
||||
* @return {?Element} The child node.
|
||||
*/
|
||||
ol.parser.XML.prototype.writeNode = function(name, obj, opt_uri, opt_parent) {
|
||||
var child = null;
|
||||
if (goog.isDef(this.writers)) {
|
||||
var uri = opt_uri ? opt_uri : this.defaultNamespaceURI;
|
||||
child = this.writers[uri][name].apply(this, [obj]);
|
||||
if (opt_parent && child) {
|
||||
opt_parent.appendChild(child);
|
||||
}
|
||||
}
|
||||
return child;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a text node. This node can be appended to another node with
|
||||
* the standard node.appendChild method. For cross-browser support,
|
||||
* this method must be used instead of document.createTextNode.
|
||||
*
|
||||
* @param {string} text The text of the node.
|
||||
* @return {Element} A DOM text node.
|
||||
*/
|
||||
ol.parser.XML.prototype.createTextNode = function(text) {
|
||||
var node;
|
||||
if (this.xmldom) {
|
||||
node = this.xmldom.createTextNode(text);
|
||||
} else {
|
||||
node = document.createTextNode(text);
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Adds a new attribute or changes the value of an attribute with the given
|
||||
* namespace and name.
|
||||
*
|
||||
* @param {Element} node Element node on which to set the attribute.
|
||||
* @param {string} uri Namespace URI for the attribute.
|
||||
* @param {string} name Qualified name (prefix:localname) for the attribute.
|
||||
* @param {string} value Attribute value.
|
||||
*/
|
||||
ol.parser.XML.prototype.setAttributeNS = function(node, uri, name, value) {
|
||||
if (node.setAttributeNS) {
|
||||
node.setAttributeNS(uri, name, value);
|
||||
} else {
|
||||
if (this.xmldom) {
|
||||
if (uri) {
|
||||
var attribute = node.ownerDocument.createNode(
|
||||
2, name, uri);
|
||||
attribute.nodeValue = value;
|
||||
node.setAttributeNode(attribute);
|
||||
} else {
|
||||
node.setAttribute(name, value);
|
||||
}
|
||||
} else {
|
||||
throw new Error('setAttributeNS not implemented');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Serializes a node.
|
||||
*
|
||||
* @param {Element} node Element node to serialize.
|
||||
* @return {string} The serialized XML string.
|
||||
*/
|
||||
ol.parser.XML.prototype.serialize = function(node) {
|
||||
if (this.xmldom) {
|
||||
return node.xml;
|
||||
} else if (node.nodeType == 1) {
|
||||
// Add nodes to a document before serializing. Everything else
|
||||
// is serialized as is. This is also needed to get all namespaces
|
||||
// defined in some browsers such as Chrome (xmlns attributes).
|
||||
var doc = document.implementation.createDocument('', '', null);
|
||||
if (doc.importNode) {
|
||||
doc.appendChild(doc.importNode(node, true));
|
||||
} else {
|
||||
doc.appendChild(node);
|
||||
}
|
||||
return goog.dom.xml.serialize(doc);
|
||||
} else {
|
||||
return goog.dom.xml.serialize(node);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a document fragment node that can be appended to another node
|
||||
* created by createElementNS. This will call
|
||||
* document.createDocumentFragment outside of IE. In IE, the ActiveX
|
||||
* object's createDocumentFragment method is used.
|
||||
*
|
||||
* @return {Element} A document fragment.
|
||||
*/
|
||||
ol.parser.XML.prototype.createDocumentFragment = function() {
|
||||
var element;
|
||||
if (this.xmldom) {
|
||||
element = this.xmldom.createDocumentFragment();
|
||||
} else {
|
||||
element = document.createDocumentFragment();
|
||||
}
|
||||
return element;
|
||||
};
|
||||
@@ -1,881 +0,0 @@
|
||||
/**
|
||||
* @typedef {Object} ol.AttributionOptions
|
||||
* @property {string} html HTML markup for this attribution.
|
||||
* @property {Object.<string, Array.<ol.TileRange>>|undefined} tileRanges
|
||||
* Tile ranges (FOR INTERNAL USE ONLY).
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.DeviceOrientationOptions
|
||||
* @property {boolean|undefined} tracking Start tracking. Default is `false`.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.GeolocationOptions
|
||||
* @property {boolean|undefined} tracking Start Tracking. Default is `false`.
|
||||
* @property {GeolocationPositionOptions|undefined} trackingOptions Tracking options.
|
||||
* @property {ol.proj.ProjectionLike} projection Projection.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.GetFeatureInfoOptions
|
||||
* @property {ol.Pixel} pixel Pixel coordinate relative to the map viewport.
|
||||
* @property {Array.<ol.layer.Layer>|undefined} layers Layers to restrict the
|
||||
* query to. All map layers will be queried if not provided.
|
||||
* @property {function(Array.<Array.<string|undefined>>)} success Callback for
|
||||
* successful queries. The passed argument is the resulting feature
|
||||
* information for each layer, with array indices being the same as in the
|
||||
* passed `layers` array or in the layer collection as returned from
|
||||
* `ol.Map#getLayers()` if no `layers` were provided.
|
||||
* @property {function()|undefined} error Callback for unsuccessful queries.
|
||||
* Note that queries with no matching features trigger the success callback,
|
||||
* not the error callback.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.GetFeaturesOptions
|
||||
* @property {ol.Pixel} pixel Pixel coordinate relative to the map viewport.
|
||||
* @property {Array.<ol.layer.Layer>|undefined} layers Layers to restrict the
|
||||
* query to. All layers will be queried if not provided.
|
||||
* @property {function(Array.<Array.<ol.Feature|undefined>>)} success Callback
|
||||
* for successful queries. The passed argument is the resulting features for
|
||||
* each layer, with array indices being the same as in the passed `layers`
|
||||
* array or in the layer collection as returned from `ol.Map#getLayers()` if
|
||||
* no layers were provided.
|
||||
* @property {function()|undefined} error Callback for unsuccessful queries.
|
||||
* Note that queries with no matching features trigger the success callback,
|
||||
* not the error callback.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* Object literal with config options for the map.
|
||||
* @typedef {Object} ol.MapOptions
|
||||
* @property {ol.Collection|Array.<ol.control.Control>|undefined} controls
|
||||
* Controls initially added to the map.
|
||||
* @property {ol.Collection|Array.<ol.interaction.Interaction>|undefined} interactions
|
||||
* Interactions that are initially added to the map.
|
||||
* @property {Array.<ol.layer.Base>|ol.Collection|undefined} layers Layers.
|
||||
* @property {ol.Collection|Array.<ol.Overlay>|undefined} overlays
|
||||
* Overlays initially added to the map.
|
||||
* @property {ol.RendererHint|undefined} renderer Renderer.
|
||||
* @property {Array.<ol.RendererHint>|undefined} renderers Renderers.
|
||||
* @property {Element|string|undefined} target The container for the map.
|
||||
* @property {ol.IView|undefined} view The map's view. Currently
|
||||
* {@link ol.View2D} is available as view.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* Object literal with config options for the overlay.
|
||||
* @typedef {Object} ol.OverlayOptions
|
||||
* @property {Element|undefined} element The overlay element.
|
||||
* @property {ol.Coordinate|undefined} position The overlay position in map
|
||||
* projection.
|
||||
* @property {ol.OverlayPositioning|undefined} positioning Positioning.
|
||||
* @property {boolean|undefined} stopEvent Whether event propagation to the map
|
||||
* viewport should be stopped. Default is `true`. If `true` the overlay is
|
||||
* placed in the same container as that of the controls
|
||||
* (`ol-overlaycontainer-stopevent`).
|
||||
* @property {boolean|undefined} insertFirst Whether the overlay is inserted
|
||||
* first in the overlay container, or appended. Default is `true`. If the
|
||||
* overlay is placed in the same container as that of the controls (see
|
||||
* the `stopEvent` option) you will probably set `insertFirst` to `true`
|
||||
* so the overlay is displayed below the controls.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* Object literal with config options for the Proj4js projection.
|
||||
* @typedef {Object} ol.Proj4jsProjectionOptions
|
||||
* @property {string} code The SRS identifier code, e.g. `EPSG:31256`.
|
||||
* @property {ol.Extent|undefined} extent The validity extent for the SRS.
|
||||
* @property {boolean|undefined} global Whether the projection is valid for the
|
||||
* whole globe. Default is `false`.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* Object literal with config options for the projection.
|
||||
* @typedef {Object} ol.ProjectionOptions
|
||||
* @property {string} code The SRS identifier code, e.g. `EPSG:4326`.
|
||||
* @property {ol.proj.Units} units Units.
|
||||
* @property {ol.Extent|undefined} extent The validity extent for the SRS.
|
||||
* @property {string|undefined} axisOrientation The axis orientation as
|
||||
* specified in Proj4. The default is `enu`.
|
||||
* @property {boolean|undefined} global Whether the projection is valid for the
|
||||
* whole globe. Default is `false`.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* Object literal with config options for the view.
|
||||
* @typedef {Object} ol.View2DOptions
|
||||
* @property {ol.Coordinate|undefined} center The initial center for the view.
|
||||
* The coordinate system for the center is specified with the `projection`
|
||||
* option. Default is `undefined`, and layer sources will not be fetched if
|
||||
* this is not set.
|
||||
* @property {ol.Extent|undefined} extent The extent that constrains the center,
|
||||
* in other words, center cannot be set outside this extent.
|
||||
* Default is `undefined`.
|
||||
* @property {number|undefined} maxResolution The maximum resolution used to
|
||||
* determine the resolution constraint. It is used together with `maxZoom`
|
||||
* and `zoomFactor`. If unspecified it is calculated in such a way that the
|
||||
* projection's validity extent fits in a 256x256 px tile. If the projection
|
||||
* is Spherical Mercator (the default) then `maxResolution` defaults to
|
||||
* `40075016.68557849 / 256 = 156543.03392804097`.
|
||||
* @property {number|undefined} maxZoom The maximum zoom level used to determine
|
||||
* the resolution constraint. It is used together with `maxResolution` and
|
||||
* `zoomFactor`. Default is `28`.
|
||||
* @property {ol.proj.ProjectionLike} projection The projection. Default is
|
||||
* `EPSG:3857` (Spherical Mercator).
|
||||
* @property {number|undefined} resolution The initial resolution for the view.
|
||||
* The units are `projection` units per pixel (e.g. meters per pixel).
|
||||
* An alternative to setting this is to set `zoom`. Default is `undefined`,
|
||||
* and layer sources will not be fetched if neither this nor `zoom` are
|
||||
* defined.
|
||||
* @property {Array.<number>|undefined} resolutions Resolutions to determine the
|
||||
* resolution constraint. If set the `maxResolution`, `maxZoom` and
|
||||
* `zoomFactor` options are ignored.
|
||||
* @property {number|undefined} rotation The initial rotation for the view
|
||||
* in radians (positive rotation clockwise). Default is `0`.
|
||||
* @property {number|undefined} zoom Only used if `resolution` is not defined.
|
||||
* Zoom level used to calculate the initial resolution for the view.
|
||||
* The initial resolution is determined using the
|
||||
* `ol.View2D#constrainResolution` method.
|
||||
* @property {number|undefined} zoomFactor The zoom factor used to determine the
|
||||
* resolution constraint. Used together with `maxResolution` and `maxZoom`.
|
||||
* Default is `2`.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.animation.BounceOptions
|
||||
* @property {number} resolution The resolution to start the bounce from, typically `map.getView().getResolution()`.
|
||||
* @property {number|undefined} start The start time of the animation. Default is immediately.
|
||||
* @property {number|undefined} duration The duration of the animation in milliseconds. Default is `1000`.
|
||||
* @property {function(number):number|undefined} easing The easing function to use. Default is `ol.easing.upAndDown`
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.animation.PanOptions
|
||||
* @property {ol.Coordinate} source The location to start panning from, typically `map.getView().getCenter()`.
|
||||
* @property {number|undefined} start The start time of the animation. Default is immediately.
|
||||
* @property {number|undefined} duration The duration of the animation in milliseconds. Default is `1000`.
|
||||
* @property {function(number):number|undefined} easing The easing function to use. Default is `ol.easing.inAndOut`
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.animation.RotateOptions
|
||||
* @property {number} rotation The rotation to apply, in radians.
|
||||
* @property {number|undefined} start The start time of the animation. Default is immediately.
|
||||
* @property {number|undefined} duration The duration of the animation in milliseconds. Default is `1000`.
|
||||
* @property {function(number):number|undefined} easing The easing function to use. Default is `ol.easing.inAndOut`
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.animation.ZoomOptions
|
||||
* @property {number} resolution number The resolution to begin zooming from, typically `map.getView().getResolution()`.
|
||||
* @property {number|undefined} start The start time of the animation. Default is immediately.
|
||||
* @property {number|undefined} duration The duration of the animation in milliseconds. Default is `1000`.
|
||||
* @property {function(number):number|undefined} easing Easing function.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.control.AttributionOptions
|
||||
* @property {string|undefined} className CSS class name. Default is `ol-attribution`.
|
||||
* @property {Element|undefined} target Target.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.control.ControlOptions
|
||||
* @property {Element|undefined} element Element.
|
||||
* @property {Element|undefined} target Target.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.control.DefaultsOptions
|
||||
* @property {boolean|undefined} attribution Attribution.
|
||||
* @property {ol.control.AttributionOptions|undefined} attributionOptions
|
||||
* Attribution options.
|
||||
* @property {boolean|undefined} logo Logo.
|
||||
* @property {ol.control.LogoOptions|undefined} logoOptions Logo options.
|
||||
* @property {boolean|undefined} zoom Zoom.
|
||||
* @property {ol.control.ZoomOptions|undefined} zoomOptions Zoom options.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.control.FullScreenOptions
|
||||
* @property {string|undefined} className CSS class name. Default is `ol-full-screen`.
|
||||
* @property {boolean|undefined} keys Full keyboard access.
|
||||
* @property {Element|undefined} target Target.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.control.LogoOptions
|
||||
* @property {string|undefined} className CSS class name. Default is `ol-logo`.
|
||||
* @property {Element|undefined} target Target.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.control.MousePositionOptions
|
||||
* @property {string|undefined} className CSS class name. Default is `ol-mouse-position`.
|
||||
* @property {ol.CoordinateFormatType|undefined} coordinateFormat Coordinate
|
||||
* format.
|
||||
* @property {ol.proj.ProjectionLike} projection Projection.
|
||||
* @property {Element|undefined} target Target.
|
||||
* @property {string|undefined} undefinedHTML Markup for undefined coordinates.
|
||||
* Default is `` (empty string).
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.control.ScaleLineOptions
|
||||
* @property {string|undefined} className CSS Class name. Default is `ol-scale-line`.
|
||||
* @property {number|undefined} minWidth Minimum width in pixels.
|
||||
* @property {Element|undefined} target Target.
|
||||
* @property {ol.control.ScaleLineUnits|undefined} units Units.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.control.ZoomOptions
|
||||
* @property {number|undefined} duration Animation duration in milliseconds. Default is `250`.
|
||||
* @property {string|undefined} className CSS class name. Default is `ol-zoom`.
|
||||
* @property {number|undefined} delta The zoom delta applied on each click.
|
||||
* @property {Element|undefined} target Target.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.control.ZoomSliderOptions
|
||||
* @property {string|undefined} className CSS class name.
|
||||
* @property {number|undefined} maxResolution Maximum resolution.
|
||||
* @property {number|undefined} minResolution Minimum resolution.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.control.ZoomToExtentOptions
|
||||
* @property {string|undefined} className Class name. Default is `ol-zoom-extent`.
|
||||
* @property {Element|undefined} target Target.
|
||||
* @property {ol.Extent|undefined} extent The extent to zoom to. If
|
||||
* undefined the validity extent of the view projection is used.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.interaction.DoubleClickZoomOptions
|
||||
* @property {number|undefined} duration Animation duration in milliseconds. Default is `250`.
|
||||
* @property {number|undefined} delta The zoom delta applied on each double
|
||||
* click, default is `1`.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.interaction.DragPanOptions
|
||||
* @property {ol.Kinetic|undefined} kinetic Kinetic inertia to apply to the pan.
|
||||
* @property {ol.events.ConditionType|undefined} condition A conditional
|
||||
* modifier (i.e. Shift key) that determines if the interaction is active
|
||||
* or not, default is no modifiers.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.interaction.DragRotateOptions
|
||||
* @property {ol.events.ConditionType|undefined} condition A conditional
|
||||
* modifier (i.e. Shift key) that determines if the interaction is active
|
||||
* or not, default is both shift and alt keys.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.interaction.DragRotateAndZoomOptions
|
||||
* @property {ol.events.ConditionType|undefined} condition A conditional
|
||||
* modifier (i.e. Shift key) that determines if the interaction is active
|
||||
* or not, default is shify key.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.interaction.DragZoomOptions
|
||||
* @property {ol.events.ConditionType|undefined} condition A conditional
|
||||
* modifier (i.e. Shift key) that determines if the interaction is active
|
||||
* or not, default is shift key.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interactions for the map. Default is `true` for all options.
|
||||
* @typedef {Object} ol.interaction.DefaultsOptions
|
||||
* @property {boolean|undefined} altShiftDragRotate Whether Alt-Shift-drag
|
||||
* rotate is desired.
|
||||
* @property {boolean|undefined} doubleClickZoom Whether double click zoom is
|
||||
* desired.
|
||||
* @property {boolean|undefined} dragPan Whether drag-pan is desired.
|
||||
* @property {boolean|undefined} keyboard Whether keyboard interaction is
|
||||
* desired.
|
||||
* @property {boolean|undefined} mouseWheelZoom Whether mousewheel zoom is
|
||||
* desired.
|
||||
* @property {boolean|undefined} shiftDragZoom Whether Shift-drag zoom is
|
||||
* desired.
|
||||
* @property {boolean|undefined} touchPan Whether touch pan is
|
||||
* desired.
|
||||
* @property {boolean|undefined} touchRotate Whether touch rotate is desired.
|
||||
* @property {boolean|undefined} touchZoom Whether touch zoom is desired.
|
||||
* @property {number|undefined} zoomDelta Zoom delta.
|
||||
* @property {number|undefined} zoomDuration Zoom duration.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.interaction.KeyboardPanOptions
|
||||
* @property {ol.events.ConditionType|undefined} condition A conditional
|
||||
* modifier (i.e. Shift key) that determines if the interaction is active
|
||||
* or not, default is no modifiers.
|
||||
* @property {number|undefined} pixelDelta Pixel The amount to pan on each key
|
||||
* press
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.interaction.KeyboardZoomOptions
|
||||
* @property {number|undefined} duration Animation duration in milliseconds. Default is `100`.
|
||||
* @property {ol.events.ConditionType|undefined} condition A conditional
|
||||
* modifier (i.e. Shift key) that determines if the interaction is active
|
||||
* or not, default is no modifiers.
|
||||
* @property {number|undefined} delta The amount to zoom on each key press.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.interaction.MouseWheelZoomOptions
|
||||
* @property {number|undefined} duration Animation duration in milliseconds. Default is `250`.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.interaction.SelectOptions
|
||||
* @property {ol.events.ConditionType|undefined} addCondition A conditional
|
||||
* modifier (e.g. shift key) that determines if the selection is added to
|
||||
* the current selection. By default, a shift-click adds to the current
|
||||
* selection.
|
||||
* @property {ol.events.ConditionType|undefined} condition A conditional
|
||||
* modifier (e.g. shift key) that determines if the interaction is active
|
||||
* (i.e. selection occurs) or not. By default, a click with no modifier keys
|
||||
* toggles the selection.
|
||||
* @property {undefined|function(ol.layer.Layer):boolean} layerFilter Filter
|
||||
* function to restrict selection to a subset of layers.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.interaction.TouchPanOptions
|
||||
* @property {ol.Kinetic|undefined} kinetic Kinetic inertia to apply to the
|
||||
* pan.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.interaction.TouchRotateOptions
|
||||
* @property {number|undefined} threshold Minimal angle to start a rotation.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.interaction.TouchZoomOptions
|
||||
* @property {number|undefined} duration Animation duration in milliseconds. Default is `400`.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.layer.BaseOptions
|
||||
* @property {number|undefined} brightness Brightness.
|
||||
* @property {number|undefined} contrast Contrast.
|
||||
* @property {number|undefined} hue Hue.
|
||||
* @property {number|undefined} opacity Opacity.
|
||||
* @property {number|undefined} saturation Saturation.
|
||||
* @property {boolean|undefined} visible Visibility.
|
||||
* @property {number|undefined} minResolution The minimum resolution
|
||||
* (inclusive) at which this layer will be visible.
|
||||
* @property {number|undefined} maxResolution The maximum resolution
|
||||
* (exclusive) below which this layer will be visible.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.layer.LayerOptions
|
||||
* @property {number|undefined} brightness Brightness.
|
||||
* @property {number|undefined} contrast Contrast.
|
||||
* @property {number|undefined} hue Hue.
|
||||
* @property {number|undefined} opacity Opacity. 0-1. Default is `1`.
|
||||
* @property {number|undefined} saturation Saturation.
|
||||
* @property {ol.source.Source} source Source for this layer.
|
||||
* @property {boolean|undefined} visible Visibility. Default is `true` (visible).
|
||||
* @property {number|undefined} minResolution The minimum resolution
|
||||
* (inclusive) at which this layer will be visible.
|
||||
* @property {number|undefined} maxResolution The maximum resolution
|
||||
* (exclusive) below which this layer will be visible.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.layer.GroupOptions
|
||||
* @property {number|undefined} brightness Brightness.
|
||||
* @property {number|undefined} contrast Contrast.
|
||||
* @property {number|undefined} hue Hue.
|
||||
* @property {number|undefined} opacity Opacity.
|
||||
* @property {number|undefined} saturation Saturation.
|
||||
* @property {boolean|undefined} visible Visibility.
|
||||
* @property {number|undefined} minResolution The minimum resolution
|
||||
* (inclusive) at which this layer will be visible.
|
||||
* @property {number|undefined} maxResolution The maximum resolution
|
||||
* (exclusive) below which this layer will be visible.
|
||||
* @property {Array.<ol.layer.Base>|ol.Collection|undefined} layers Child layers.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.layer.TileOptions
|
||||
* @property {number|undefined} brightness Brightness.
|
||||
* @property {number|undefined} contrast Contrast.
|
||||
* @property {number|undefined} hue Hue.
|
||||
* @property {number|undefined} opacity Opacity. 0-1. Default is `1`.
|
||||
* @property {number|undefined} preload Preload.
|
||||
* @property {number|undefined} saturation Saturation.
|
||||
* @property {ol.source.Source} source Source for this layer.
|
||||
* @property {boolean|undefined} visible Visibility. Default is `true` (visible).
|
||||
* @property {number|undefined} minResolution The minimum resolution
|
||||
* (inclusive) at which this layer will be visible.
|
||||
* @property {number|undefined} maxResolution The maximum resolution
|
||||
* (exclusive) below which this layer will be visible.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.layer.VectorLayerOptions
|
||||
* @property {function(Array.<ol.Feature>):string|undefined} transformFeatureInfo
|
||||
* Function to render an array of
|
||||
* features into feature info markup. If not provided, a comma separated
|
||||
* list of the unique ids of the resulting features will be returned.
|
||||
* @property {number|undefined} opacity Opacity. 0-1. Default is `1`.
|
||||
* @property {ol.source.Source} source Source for this layer.
|
||||
* @property {ol.style.Style|undefined} style Style.
|
||||
* @property {boolean|undefined} visible Visibility. Default is `true` (visible).
|
||||
* @property {number|undefined} minResolution The minimum resolution
|
||||
* (inclusive) at which this layer will be visible.
|
||||
* @property {number|undefined} maxResolution The maximum resolution
|
||||
* (exclusive) below which this layer will be visible.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.parser.KMLOptions
|
||||
* @property {boolean|undefined} extractAttributes Should we extract attributes
|
||||
* from the KML? Default is `true`.
|
||||
* @property {boolean|undefined} extractStyles Should we extract styles from the
|
||||
* KML? Default is `false`.
|
||||
* @property {number|undefined} maxDepth Maximum depth to follow network links.
|
||||
* Default is `0`, which means we don't follow network links at all.
|
||||
* @property {Array.<string>|undefined} trackAttributes Track attributes to
|
||||
* parse.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.parser.GMLReadOptions
|
||||
* @property {string|undefined} axisOrientation The axis orientation.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.parser.GMLWriteOptions
|
||||
* @property {ol.proj.ProjectionLike} srsName The srsName to use when writing.
|
||||
* @property {string|undefined} axisOrientation The axis orientation.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.parser.GMLOptions
|
||||
* @property {boolean|undefined} curve Write gml:Curve instead of
|
||||
* gml:LineString elements. This also affects the elements in multi-part
|
||||
* geometries. Default is `false`. This only applies to GML version 3.
|
||||
* @property {boolean|undefined} extractAttributes Should we extract attributes
|
||||
* from the GML? Default is `true`.
|
||||
* @property {string|undefined} featureNS The feature namespace. If not set it
|
||||
* will be automatically configured from the GML.
|
||||
* @property {Array.<string>|string|undefined} featureType The local
|
||||
* (without prefix) feature typeName(s).
|
||||
* @property {string|undefined} geometryName Name of geometry element.
|
||||
* Defaults to `geometry`. If null, it will be set on <read> when the
|
||||
* first geometry is parsed.
|
||||
* @property {boolean|undefined} multiCurve Write gml:MultiCurve instead of
|
||||
* gml:MultiLineString. Since the latter is deprecated in GML 3, the
|
||||
* default is `true`. This only applies to GML version 3.
|
||||
* @property {boolean|undefined} multiSurface Write gml:multiSurface instead
|
||||
* of gml:MultiPolygon. Since the latter is deprecated in GML 3, the
|
||||
* default is `true`. This only applies to GML version 3.
|
||||
* @property {string|undefined} schemaLocation Optional schemaLocation to use
|
||||
* when writing out the GML, this will override the default provided.
|
||||
* @property {boolean|undefined} surface Write gml:Surface instead of
|
||||
* gml:Polygon elements. This also affects the elements in multi-part
|
||||
* geometries. Default is `false`. This only applies to GML version 3.
|
||||
* @property {ol.parser.GMLReadOptions|undefined} readOptions readOptions to
|
||||
* use for this instance.
|
||||
* @property {ol.parser.GMLWriteOptions|undefined} writeOptions writeOptions
|
||||
* to use for this instance.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.parser.GPXOptions
|
||||
* @property {string|undefined} creator The creator attribute to be added to
|
||||
* the written GPX files. Defaults to `OpenLayers`.
|
||||
* @property {string|undefined} defaultDesc Default description for the
|
||||
* waypoints/tracks in the case where the feature has no `description`
|
||||
* attribute. Default is `No description available`.
|
||||
* @property {boolean|undefined} extractAttributes Should we extract attributes
|
||||
* from the GPX? Default is `true`.
|
||||
* @property {boolean|undefined} extractWaypoints Extract waypoints from GPX.
|
||||
* Default is `true`.
|
||||
* @property {boolean|undefined} extractTracks Extract tracks from GPX.
|
||||
* Default is `true`.
|
||||
* @property {boolean|undefined} extractRoutes Extract routes from GPX.
|
||||
* Default is `true`.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.parser.GPXWriteOptions
|
||||
* @property {Array.<ol.Feature>|ol.Feature} features The features to write
|
||||
* out.
|
||||
* @property {Object|undefined} metadata Metadata key/value pair with keys:
|
||||
* name, desc and author.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.source.BingMapsOptions
|
||||
* @property {string|undefined} culture Culture.
|
||||
* @property {string} key Bing Maps API key. Get yours at
|
||||
* http://bingmapsportal.com/.
|
||||
* @property {string} style Style.
|
||||
* @property {ol.TileLoadFunctionType|undefined} tileLoadFunction Optional
|
||||
* function to load a tile given a URL.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.source.MapQuestOptions
|
||||
* @property {ol.TileLoadFunctionType|undefined} tileLoadFunction Optional
|
||||
* function to load a tile given a URL.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.source.TileDebugOptions
|
||||
* @property {ol.Extent|undefined} extent Extent.
|
||||
* @property {ol.proj.ProjectionLike} projection Projection.
|
||||
* @property {ol.tilegrid.TileGrid|undefined} tileGrid Tile grid.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.source.OSMOptions
|
||||
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
|
||||
* @property {number|undefined} maxZoom Max zoom.
|
||||
* @property {ol.TileLoadFunctionType|undefined} tileLoadFunction Optional
|
||||
* function to load a tile given a URL.
|
||||
* @property {string|undefined} url URL.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.source.ImageWMSOptions
|
||||
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
|
||||
* @property {null|string|undefined} crossOrigin crossOrigin setting for image
|
||||
* requests.
|
||||
* @property {ol.Extent|undefined} extent Extent.
|
||||
* @property {ol.source.WMSGetFeatureInfoOptions|undefined}
|
||||
* getFeatureInfoOptions Options for GetFeatureInfo.
|
||||
* @property {Object.<string,*>} params WMS request parameters. At least a
|
||||
* `LAYERS` param is required. `STYLES` is `` by default. `VERSION` is
|
||||
* `1.3.0` by default. `WIDTH`, `HEIGHT`, `BBOX` and `CRS` (`SRS` for WMS
|
||||
* version < 1.3.0) will be set dynamically.
|
||||
* @property {ol.proj.ProjectionLike} projection Projection.
|
||||
* @property {number|undefined} ratio Ratio. 1 means image requests are the size
|
||||
* of the map viewport, 2 means twice the size of the map viewport, and so
|
||||
* on.
|
||||
* @property {Array.<number>|undefined} resolutions Resolutions. If specified,
|
||||
* requests will be made for these resolutions only.
|
||||
* @property {string|undefined} url WMS service URL.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.source.StamenOptions
|
||||
* @property {string} layer Layer.
|
||||
* @property {number|undefined} minZoom Minimum zoom.
|
||||
* @property {number|undefined} maxZoom Maximum zoom.
|
||||
* @property {boolean|undefined} opaque Whether the layer is opaque.
|
||||
* @property {ol.TileLoadFunctionType|undefined} tileLoadFunction Optional
|
||||
* function to load a tile given a URL.
|
||||
* @property {string|undefined} url URL.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.source.ImageStaticOptions
|
||||
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
|
||||
* @property {null|string|undefined} crossOrigin crossOrigin setting for image
|
||||
* requests.
|
||||
* @property {ol.Extent|undefined} extent Extent.
|
||||
* @property {ol.Extent|undefined} imageExtent Extent of the image.
|
||||
* @property {ol.Size|undefined} imageSize Size of the image.
|
||||
* @property {ol.proj.ProjectionLike} projection Projection.
|
||||
* @property {string|undefined} url URL.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.source.TileJSONOptions
|
||||
* @property {null|string|undefined} crossOrigin crossOrigin setting for image
|
||||
* requests.
|
||||
* @property {ol.TileLoadFunctionType|undefined} tileLoadFunction Optional
|
||||
* function to load a tile given a URL.
|
||||
* @property {string} url URL.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.source.TileWMSOptions
|
||||
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
|
||||
* @property {Object.<string,*>} params WMS request parameters. At least a
|
||||
* `LAYERS` param is required. `STYLES` is `` by default. `VERSION` is
|
||||
* `1.3.0` by default. `WIDTH`, `HEIGHT`, `BBOX` and `CRS` (`SRS` for WMS
|
||||
* version < 1.3.0) will be set dynamically.
|
||||
* @property {null|string|undefined} crossOrigin crossOrigin setting for image
|
||||
* requests.
|
||||
* @property {ol.Extent|undefined} extent Extent.
|
||||
* @property {ol.source.WMSGetFeatureInfoOptions|undefined}
|
||||
* getFeatureInfoOptions Options for GetFeatureInfo.
|
||||
* @property {string|undefined} logo Logo.
|
||||
* @property {ol.tilegrid.TileGrid|undefined} tileGrid Tile grid.
|
||||
* @property {number|undefined} maxZoom Maximum zoom.
|
||||
* @property {ol.proj.ProjectionLike} projection Projection.
|
||||
* @property {ol.TileLoadFunctionType|undefined} tileLoadFunction Optional
|
||||
* function to load a tile given a URL.
|
||||
* @property {string|undefined} url WMS service URL.
|
||||
* @property {Array.<string>|undefined} urls WMS service urls. Use this instead
|
||||
* of `url` when the WMS supports multiple urls for GetMap requests.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.source.VectorOptions
|
||||
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
|
||||
* @property {Object|string|undefined} data Data to parse.
|
||||
* @property {ol.Extent|undefined} extent Extent.
|
||||
* @property {string|undefined} logo Logo.
|
||||
* @property {ol.parser.Parser} parser Parser instance to parse data
|
||||
* provided as `data` or fetched from `url`.
|
||||
* @property {ol.proj.ProjectionLike|undefined} projection Projection. Usually the
|
||||
* projection is provided by the parser, so this only needs to be set if
|
||||
* the parser does not know the SRS (e.g. in some GML flavors), or if the
|
||||
* projection determined by the parser needs to be overridden.
|
||||
* @property {string|undefined} url Server url providing the vector data.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.source.Vector2Options
|
||||
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
|
||||
* @property {ol.Extent|undefined} extent Extent.
|
||||
* @property {Array.<ol.geom2.LineStringCollection>|undefined}
|
||||
* lineStringCollections Line string collections.
|
||||
* @property {Array.<ol.geom2.PointCollection>|undefined} pointCollections
|
||||
* Point collections.
|
||||
* @property {ol.proj.ProjectionLike} projection Projection.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.source.WMSGetFeatureInfoOptions
|
||||
* @property {ol.source.WMSGetFeatureInfoMethod} method Method for requesting
|
||||
* GetFeatureInfo. Default is `ol.source.WMSGetFeatureInfoMethod.IFRAME`.
|
||||
* @property {Object} params Params for the GetFeatureInfo request. Default is
|
||||
* `{'INFO_FORMAT': 'text/html'}`.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.source.WMTSOptions
|
||||
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
|
||||
* @property {string|null|undefined} crossOrigin crossOrigin setting for image
|
||||
* requests.
|
||||
* @property {ol.Extent|undefined} extent Extent.
|
||||
* @property {string|undefined} logo Logo.
|
||||
* @property {ol.tilegrid.WMTS} tileGrid Tile grid.
|
||||
* @property {ol.proj.ProjectionLike} projection Projection.
|
||||
* @property {ol.source.WMTSRequestEncoding|undefined} requestEncoding Request
|
||||
* encoding.
|
||||
* @property {string} layer Layer.
|
||||
* @property {string} style Style.
|
||||
* @property {string|undefined} version WMTS version. Default to `1.0.0`.
|
||||
* @property {string|undefined} format Format.
|
||||
* @property {string} matrixSet Matrix set.
|
||||
* @property {Object|undefined} dimensions Dimensions.
|
||||
* @property {string|undefined} url URL.
|
||||
* @property {number|undefined} maxZoom Maximum zoom.
|
||||
* @property {ol.TileLoadFunctionType|undefined} tileLoadFunction Optional
|
||||
* function to load a tile given a URL.
|
||||
* @property {Array.<string>|undefined} urls Urls.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @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.proj.ProjectionLike} projection Projection.
|
||||
* @property {number|undefined} maxZoom Optional max zoom level. Default is `18`.
|
||||
* @property {number|undefined} minZoom Unsupported (TODO: remove this).
|
||||
* @property {ol.TileLoadFunctionType|undefined} tileLoadFunction Optional
|
||||
* function to load a tile given a URL.
|
||||
* @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.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.style.IconOptions
|
||||
* @property {string|ol.expr.Expression} url Icon image URL.
|
||||
* @property {number|ol.expr.Expression|undefined} width Width of the icon
|
||||
* in pixels. Default is the width of the icon image.
|
||||
* @property {number|ol.expr.Expression|undefined} height Height of the
|
||||
* icon in pixels. Default is the height of the icon image.
|
||||
* @property {number|ol.expr.Expression|undefined} opacity Icon opacity
|
||||
* (0-1).
|
||||
* @property {number|ol.expr.Expression|undefined} rotation Rotation in
|
||||
* radians (positive rotation clockwise).
|
||||
* @property {number|ol.expr.Expression|undefined} xOffset Pixel offset from the
|
||||
* point to the center of the icon (positive values shift image left).
|
||||
* @property {number|ol.expr.Expression|undefined} yOffset Pixel offset from the
|
||||
* point to the center of the icon (positive values shift image down).
|
||||
* @property {number|ol.expr.Expression|undefined} zIndex Stack order.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.style.FillOptions
|
||||
* @property {string|ol.expr.Expression|undefined} color Fill color as hex color
|
||||
* code.
|
||||
* @property {number|ol.expr.Expression|undefined} opacity Opacity (0-1).
|
||||
* @property {number|ol.expr.Expression|undefined} zIndex Stack order.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.style.RuleOptions
|
||||
* @property {ol.expr.Expression|string|undefined} filter Filter.
|
||||
* @property {number|undefined} maxResolution Optional maximum resolution. If
|
||||
* a value is provided, the rule will apply at resolutions less than
|
||||
* this value.
|
||||
* @property {number|undefined} minResolution Optional minimum resolution. If
|
||||
* a value is provided, the rule will apply at resolutions greater than or
|
||||
* equal to this value.
|
||||
* @property {Array.<ol.style.Symbolizer>|undefined} symbolizers Symbolizers.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.style.ShapeOptions
|
||||
* @property {ol.style.ShapeType|undefined} type Type.
|
||||
* @property {number|ol.expr.Expression|undefined} size Size in pixels.
|
||||
* @property {ol.style.Fill|undefined} fill Fill symbolizer for shape.
|
||||
* @property {ol.style.Stroke|undefined} stroke Stroke symbolizer for shape.
|
||||
* @property {number|ol.expr.Expression|undefined} zIndex Stack order.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.style.StrokeOptions
|
||||
* @property {string|ol.expr.Expression|undefined} color Stroke color as hex
|
||||
* color code.
|
||||
* @property {number|ol.expr.Expression|undefined} opacity Stroke opacity (0-1).
|
||||
* @property {number|ol.expr.Expression|undefined} width Stroke width in pixels.
|
||||
* @property {number|ol.expr.Expression|undefined} zIndex Stack order.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.style.StyleOptions
|
||||
* @property {Array.<ol.style.Rule>|undefined} rules Rules.
|
||||
* @property {Array.<ol.style.Symbolizer>|undefined} symbolizers Symbolizers
|
||||
* (that apply if no rules are provided or where none of the provided rules
|
||||
* apply).
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.style.TextOptions
|
||||
* @property {string|ol.expr.Expression|undefined} color Color.
|
||||
* @property {string|ol.expr.Expression|undefined} fontFamily Font family.
|
||||
* @property {number|ol.expr.Expression|undefined} fontSize Font size in pixels.
|
||||
* @property {string|ol.expr.Expression|undefined} fontWeight Font weight.
|
||||
* @property {string|ol.expr.Expression} text Text for the label.
|
||||
* @property {number|ol.expr.Expression|undefined} opacity Opacity (0-1).
|
||||
* @property {ol.style.Stroke|undefined} stroke Stroke symbolizer for text.
|
||||
* @property {number|ol.expr.Expression|undefined} zIndex Stack order.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.tilegrid.TileGridOptions
|
||||
* @property {number|undefined} minZoom Minimum zoom.
|
||||
* @property {ol.Coordinate|undefined} origin Origin.
|
||||
* @property {Array.<ol.Coordinate>|undefined} origins Origins.
|
||||
* @property {!Array.<number>} resolutions Resolutions.
|
||||
* @property {ol.Size|undefined} tileSize Tile size.
|
||||
* @property {Array.<ol.Size>|undefined} tileSizes Tile sizes.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.tilegrid.WMTSOptions
|
||||
* @property {ol.Coordinate|undefined} origin Origin.
|
||||
* @property {Array.<ol.Coordinate>|undefined} origins Origins.
|
||||
* @property {!Array.<number>} resolutions Resolutions.
|
||||
* @property {!Array.<string>} matrixIds matrix IDs.
|
||||
* @property {ol.Size|undefined} tileSize Tile size.
|
||||
* @property {Array.<ol.Size>|undefined} tileSizes Tile sizes.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} ol.tilegrid.XYZOptions
|
||||
* @property {number} maxZoom Maximum zoom.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
@@ -1,3 +0,0 @@
|
||||
/**
|
||||
* @namespace ol.expr
|
||||
*/
|
||||
@@ -1,309 +0,0 @@
|
||||
goog.provide('ol.expr');
|
||||
goog.provide('ol.expr.functions');
|
||||
|
||||
goog.require('ol.Extent');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Expression');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Parser');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
|
||||
|
||||
/**
|
||||
* Evaluate an expression with a feature. The feature attributes will be used
|
||||
* as the evaluation scope. The `ol.expr.lib` functions will be used as
|
||||
* function scope. The feature itself will be used as the `this` argument.
|
||||
*
|
||||
* @param {ol.expr.Expression} expr The expression.
|
||||
* @param {ol.Feature=} opt_feature The feature.
|
||||
* @return {*} The result of the expression.
|
||||
*/
|
||||
ol.expr.evaluateFeature = function(expr, opt_feature) {
|
||||
var scope;
|
||||
if (goog.isDef(opt_feature)) {
|
||||
scope = opt_feature.getAttributes();
|
||||
}
|
||||
return expr.evaluate(scope, ol.expr.lib, opt_feature);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse an expression.
|
||||
* @param {string} source The expression source (e.g. `'foo + 2'`).
|
||||
* @return {ol.expr.Expression} An expression instance that can be
|
||||
* evaluated within some scope to provide a value.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.expr.parse = function(source) {
|
||||
var parser = new ol.expr.Parser();
|
||||
return parser.parse(source);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Register a library function to be used in expressions.
|
||||
* @param {string} name The function name (e.g. 'myFunc').
|
||||
* @param {function(this:ol.Feature)} func The function to be called in an
|
||||
* expression. This function will be called with a feature as the `this`
|
||||
* argument when the expression is evaluated in the context of a features.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.expr.register = function(name, func) {
|
||||
ol.expr.lib[name] = func;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether an expression is a call expression that calls one of the
|
||||
* `ol.expr.lib` functions.
|
||||
*
|
||||
* @param {ol.expr.Expression} expr The candidate expression.
|
||||
* @return {string|undefined} If the candidate expression is a call to a lib
|
||||
* function, the return will be the function name. If not, the return will be
|
||||
* `undefined`.
|
||||
*/
|
||||
ol.expr.isLibCall = function(expr) {
|
||||
var name;
|
||||
if (expr instanceof ol.expr.Call) {
|
||||
var callee = expr.getCallee();
|
||||
if (callee instanceof ol.expr.Identifier) {
|
||||
name = callee.getName();
|
||||
if (!ol.expr.lib.hasOwnProperty(name)) {
|
||||
name = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
return name;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Library of well-known functions. These are available to expressions parsed
|
||||
* with `ol.expr.parse`.
|
||||
*
|
||||
* @type {Object.<string, function(...)>}
|
||||
*/
|
||||
ol.expr.lib = {};
|
||||
|
||||
|
||||
/**
|
||||
* Enumeration of library function names.
|
||||
*
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.expr.functions = {
|
||||
CONCAT: 'concat',
|
||||
COUNTER: 'counter',
|
||||
EXTENT: 'extent',
|
||||
FID: 'fid',
|
||||
GEOMETRY_TYPE: 'geometryType',
|
||||
RENDER_INTENT: 'renderIntent',
|
||||
INTERSECTS: 'intersects',
|
||||
CONTAINS: 'contains',
|
||||
DWITHIN: 'dwithin',
|
||||
WITHIN: 'within',
|
||||
LIKE: 'like',
|
||||
IEQ: 'ieq',
|
||||
INEQ: 'ineq'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Concatenate strings. All provided arguments will be cast to string and
|
||||
* concatenated.
|
||||
* @param {...string} var_args Strings to concatenate.
|
||||
* @return {string} All input arguments concatenated as strings.
|
||||
* @this {ol.Feature}
|
||||
*/
|
||||
ol.expr.lib[ol.expr.functions.CONCAT] = function(var_args) {
|
||||
var str = '';
|
||||
for (var i = 0, ii = arguments.length; i < ii; ++i) {
|
||||
str += String(arguments[i]);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns a counter which increases every time this function is called.
|
||||
* @param {number=} opt_start Start. If not provided, the counter starts at 1.
|
||||
* @return {number} Counter.
|
||||
*/
|
||||
ol.expr.lib[ol.expr.functions.COUNTER] = (function() {
|
||||
var counter = 0;
|
||||
return function(opt_start) {
|
||||
var result = ++counter;
|
||||
if (goog.isDef(opt_start)) {
|
||||
result += opt_start;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a feature's extent intersects the provided extent.
|
||||
* @param {number} minX Minimum x-coordinate value.
|
||||
* @param {number} minY Minimum y-coordinate value.
|
||||
* @param {number} maxX Maximum x-coordinate value.
|
||||
* @param {number} maxY Maximum y-coordinate value.
|
||||
* @param {string=} opt_projection Projection of the extent.
|
||||
* @param {string=} opt_attribute Name of the geometry attribute to use.
|
||||
* @return {boolean} The provided extent intersects the feature's extent.
|
||||
* @this {ol.Feature}
|
||||
*/
|
||||
ol.expr.lib[ol.expr.functions.EXTENT] = function(minX, minY, maxX, maxY,
|
||||
opt_projection, opt_attribute) {
|
||||
var intersects = false;
|
||||
var geometry = goog.isDef(opt_attribute) ?
|
||||
this.get(opt_attribute) : this.getGeometry();
|
||||
if (geometry) {
|
||||
intersects = ol.extent.intersects(geometry.getBounds(),
|
||||
[minX, minY, maxX, maxY]);
|
||||
}
|
||||
return intersects;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine if the feature identifier matches any of the provided values.
|
||||
* @param {...string} var_args Feature identifiers.
|
||||
* @return {boolean} The feature's identifier matches one of the given values.
|
||||
* @this {ol.Feature}
|
||||
*/
|
||||
ol.expr.lib[ol.expr.functions.FID] = function(var_args) {
|
||||
var matches = false;
|
||||
var id = this.getId();
|
||||
if (goog.isDef(id)) {
|
||||
for (var i = 0, ii = arguments.length; i < ii; ++i) {
|
||||
if (arguments[i] === id) {
|
||||
matches = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return matches;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine if two strings are like one another, based on simple pattern
|
||||
* matching.
|
||||
* @param {string} value The string to test.
|
||||
* @param {string} pattern The comparison pattern.
|
||||
* @param {string} wildCard The wildcard character to use.
|
||||
* @param {string} singleChar The single character to use.
|
||||
* @param {string} escapeChar The escape character to use.
|
||||
* @param {boolean} matchCase Should we match case or not?
|
||||
* @this {ol.Feature}
|
||||
*/
|
||||
ol.expr.lib[ol.expr.functions.LIKE] = function(value, pattern, wildCard,
|
||||
singleChar, escapeChar, matchCase) {
|
||||
if (wildCard == '.') {
|
||||
throw new Error('"." is an unsupported wildCard character for ' +
|
||||
'the "like" function');
|
||||
}
|
||||
// set UMN MapServer defaults for unspecified parameters
|
||||
wildCard = goog.isDef(wildCard) ? wildCard : '*';
|
||||
singleChar = goog.isDef(singleChar) ? singleChar : '.';
|
||||
escapeChar = goog.isDef(escapeChar) ? escapeChar : '!';
|
||||
pattern = pattern.replace(
|
||||
new RegExp('\\' + escapeChar + '(.|$)', 'g'), '\\$1');
|
||||
pattern = pattern.replace(
|
||||
new RegExp('\\' + singleChar, 'g'), '.');
|
||||
pattern = pattern.replace(
|
||||
new RegExp('\\' + wildCard, 'g'), '.*');
|
||||
pattern = pattern.replace(
|
||||
new RegExp('\\\\.\\*', 'g'), '\\' + wildCard);
|
||||
pattern = pattern.replace(
|
||||
new RegExp('\\\\\\.', 'g'), '\\' + singleChar);
|
||||
var modifiers = (matchCase === false) ? 'gi' : 'g';
|
||||
return new RegExp(pattern, modifiers).test(value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Case insensitive comparison for equality.
|
||||
* @param {*} first First value.
|
||||
* @param {*} second Second value.
|
||||
* @this {ol.Feature}
|
||||
*/
|
||||
ol.expr.lib[ol.expr.functions.IEQ] = function(first, second) {
|
||||
if (goog.isString(first) && goog.isString(second)) {
|
||||
return first.toUpperCase() == second.toUpperCase();
|
||||
} else {
|
||||
return first == second;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Case insensitive comparison for non-equality.
|
||||
* @param {*} first First value.
|
||||
* @param {*} second Second value.
|
||||
* @this {ol.Feature}
|
||||
*/
|
||||
ol.expr.lib[ol.expr.functions.INEQ] = function(first, second) {
|
||||
if (goog.isString(first) && goog.isString(second)) {
|
||||
return first.toUpperCase() != second.toUpperCase();
|
||||
} else {
|
||||
return first != second;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a feature's default geometry is of the given type.
|
||||
* @param {ol.geom.GeometryType} type Geometry type.
|
||||
* @return {boolean} The feature's default geometry is of the given type.
|
||||
* @this {ol.Feature}
|
||||
*/
|
||||
ol.expr.lib[ol.expr.functions.GEOMETRY_TYPE] = function(type) {
|
||||
var same = false;
|
||||
var geometry = this.getGeometry();
|
||||
if (geometry) {
|
||||
same = geometry.getType() === type;
|
||||
}
|
||||
return same;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a feature's renderIntent matches the given one.
|
||||
* @param {string} renderIntent Render intent.
|
||||
* @return {boolean} The feature's renderIntent matches the given one.
|
||||
* @this {ol.Feature}
|
||||
*/
|
||||
ol.expr.lib[ol.expr.functions.RENDER_INTENT] = function(renderIntent) {
|
||||
return this.getRenderIntent() == renderIntent;
|
||||
};
|
||||
|
||||
|
||||
ol.expr.lib[ol.expr.functions.INTERSECTS] = function(geom, opt_projection,
|
||||
opt_attribute) {
|
||||
throw new Error('Spatial function not implemented: ' +
|
||||
ol.expr.functions.INTERSECTS);
|
||||
};
|
||||
|
||||
|
||||
ol.expr.lib[ol.expr.functions.WITHIN] = function(geom, opt_projection,
|
||||
opt_attribute) {
|
||||
throw new Error('Spatial function not implemented: ' +
|
||||
ol.expr.functions.WITHIN);
|
||||
};
|
||||
|
||||
|
||||
ol.expr.lib[ol.expr.functions.CONTAINS] = function(geom, opt_projeciton,
|
||||
opt_attribute) {
|
||||
throw new Error('Spatial function not implemented: ' +
|
||||
ol.expr.functions.CONTAINS);
|
||||
};
|
||||
|
||||
|
||||
ol.expr.lib[ol.expr.functions.DWITHIN] = function(geom, distance, units,
|
||||
opt_projection, opt_attribute) {
|
||||
throw new Error('Spatial function not implemented: ' +
|
||||
ol.expr.functions.DWITHIN);
|
||||
};
|
||||
@@ -1,626 +0,0 @@
|
||||
goog.provide('ol.expr.Call');
|
||||
goog.provide('ol.expr.Comparison');
|
||||
goog.provide('ol.expr.ComparisonOp');
|
||||
goog.provide('ol.expr.Expression');
|
||||
goog.provide('ol.expr.Identifier');
|
||||
goog.provide('ol.expr.Literal');
|
||||
goog.provide('ol.expr.Logical');
|
||||
goog.provide('ol.expr.LogicalOp');
|
||||
goog.provide('ol.expr.Math');
|
||||
goog.provide('ol.expr.MathOp');
|
||||
goog.provide('ol.expr.Member');
|
||||
goog.provide('ol.expr.Not');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Base class for all expressions. Instances of ol.expr.Expression
|
||||
* correspond to a limited set of ECMAScript 5.1 expressions.
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-11
|
||||
*
|
||||
* This base class should not be constructed directly. Instead, use one of
|
||||
* the subclass constructors.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.expr.Expression = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* Evaluate the expression and return the result.
|
||||
*
|
||||
* @param {Object=} opt_scope Evaluation scope. All properties of this object
|
||||
* will be available as variables when evaluating the expression. If not
|
||||
* provided, `null` will be used.
|
||||
* @param {Object=} opt_fns Optional scope for looking up functions. If not
|
||||
* provided, functions will be looked in the evaluation scope.
|
||||
* @param {Object=} opt_this Object to use as this when evaluating call
|
||||
* expressions. If not provided, `this` will resolve to a new object.
|
||||
* @return {*} Result of the expression.
|
||||
*/
|
||||
ol.expr.Expression.prototype.evaluate = goog.abstractMethod;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A call expression (e.g. `foo(bar)`).
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.expr.Expression}
|
||||
* @param {ol.expr.Expression} callee An expression that resolves to a
|
||||
* function.
|
||||
* @param {Array.<ol.expr.Expression>} args Arguments.
|
||||
*/
|
||||
ol.expr.Call = function(callee, args) {
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.callee_ = callee;
|
||||
|
||||
/**
|
||||
* @type {Array.<ol.expr.Expression>}
|
||||
* @private
|
||||
*/
|
||||
this.args_ = args;
|
||||
|
||||
};
|
||||
goog.inherits(ol.expr.Call, ol.expr.Expression);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.expr.Call.prototype.evaluate = function(opt_scope, opt_fns, opt_this) {
|
||||
var fnScope = goog.isDefAndNotNull(opt_fns) ? opt_fns : opt_scope;
|
||||
var fn = this.callee_.evaluate(fnScope);
|
||||
if (!fn || !goog.isFunction(fn)) {
|
||||
throw new Error('Expected function but found ' + fn);
|
||||
}
|
||||
var thisArg = goog.isDef(opt_this) ? opt_this : {};
|
||||
|
||||
var len = this.args_.length;
|
||||
var values = new Array(len);
|
||||
for (var i = 0; i < len; ++i) {
|
||||
values[i] = this.args_[i].evaluate(opt_scope, opt_fns, opt_this);
|
||||
}
|
||||
return fn.apply(thisArg, values);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the argument list.
|
||||
* @return {Array.<ol.expr.Expression>} The argument.
|
||||
*/
|
||||
ol.expr.Call.prototype.getArgs = function() {
|
||||
return this.args_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the callee expression.
|
||||
* @return {ol.expr.Expression} The callee expression.
|
||||
*/
|
||||
ol.expr.Call.prototype.getCallee = function() {
|
||||
return this.callee_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.expr.ComparisonOp = {
|
||||
EQ: '==',
|
||||
NEQ: '!=',
|
||||
STRICT_EQ: '===',
|
||||
STRICT_NEQ: '!==',
|
||||
GT: '>',
|
||||
LT: '<',
|
||||
GTE: '>=',
|
||||
LTE: '<='
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A comparison expression (e.g. `foo >= 42`, `bar != "chicken"`).
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.expr.Expression}
|
||||
* @param {ol.expr.ComparisonOp} operator Comparison operator.
|
||||
* @param {ol.expr.Expression} left Left expression.
|
||||
* @param {ol.expr.Expression} right Right expression.
|
||||
*/
|
||||
ol.expr.Comparison = function(operator, left, right) {
|
||||
|
||||
/**
|
||||
* @type {ol.expr.ComparisonOp}
|
||||
* @private
|
||||
*/
|
||||
this.operator_ = operator;
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.left_ = left;
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.right_ = right;
|
||||
|
||||
};
|
||||
goog.inherits(ol.expr.Comparison, ol.expr.Expression);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a given string is a valid comparison operator.
|
||||
* @param {string} candidate Operator to test.
|
||||
* @return {boolean} The operator is valid.
|
||||
*/
|
||||
ol.expr.Comparison.isValidOp = (function() {
|
||||
var valid = {};
|
||||
for (var key in ol.expr.ComparisonOp) {
|
||||
valid[ol.expr.ComparisonOp[key]] = true;
|
||||
}
|
||||
return function isValidOp(candidate) {
|
||||
return !!valid[candidate];
|
||||
};
|
||||
}());
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.expr.Comparison.prototype.evaluate = function(opt_scope, opt_fns, opt_this) {
|
||||
var result;
|
||||
var rightVal = this.right_.evaluate(opt_scope, opt_fns, opt_this);
|
||||
var leftVal = this.left_.evaluate(opt_scope, opt_fns, opt_this);
|
||||
|
||||
var op = this.operator_;
|
||||
if (op === ol.expr.ComparisonOp.EQ) {
|
||||
result = leftVal == rightVal;
|
||||
} else if (op === ol.expr.ComparisonOp.NEQ) {
|
||||
result = leftVal != rightVal;
|
||||
} else if (op === ol.expr.ComparisonOp.STRICT_EQ) {
|
||||
result = leftVal === rightVal;
|
||||
} else if (op === ol.expr.ComparisonOp.STRICT_NEQ) {
|
||||
result = leftVal !== rightVal;
|
||||
} else if (op === ol.expr.ComparisonOp.GT) {
|
||||
result = leftVal > rightVal;
|
||||
} else if (op === ol.expr.ComparisonOp.LT) {
|
||||
result = leftVal < rightVal;
|
||||
} else if (op === ol.expr.ComparisonOp.GTE) {
|
||||
result = leftVal >= rightVal;
|
||||
} else if (op === ol.expr.ComparisonOp.LTE) {
|
||||
result = leftVal <= rightVal;
|
||||
} else {
|
||||
throw new Error('Unsupported comparison operator: ' + this.operator_);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the comparison operator.
|
||||
* @return {string} The comparison operator.
|
||||
*/
|
||||
ol.expr.Comparison.prototype.getOperator = function() {
|
||||
return this.operator_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the left expression.
|
||||
* @return {ol.expr.Expression} The left expression.
|
||||
*/
|
||||
ol.expr.Comparison.prototype.getLeft = function() {
|
||||
return this.left_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the right expression.
|
||||
* @return {ol.expr.Expression} The right expression.
|
||||
*/
|
||||
ol.expr.Comparison.prototype.getRight = function() {
|
||||
return this.right_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* An identifier expression (e.g. `foo`).
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.expr.Expression}
|
||||
* @param {string} name An identifier name.
|
||||
*/
|
||||
ol.expr.Identifier = function(name) {
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
this.name_ = name;
|
||||
|
||||
};
|
||||
goog.inherits(ol.expr.Identifier, ol.expr.Expression);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.expr.Identifier.prototype.evaluate = function(opt_scope) {
|
||||
if (!goog.isDefAndNotNull(opt_scope)) {
|
||||
throw new Error('Attempt to evaluate identifier with no scope');
|
||||
}
|
||||
return opt_scope[this.name_];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the identifier name.
|
||||
* @return {string} The identifier name.
|
||||
*/
|
||||
ol.expr.Identifier.prototype.getName = function() {
|
||||
return this.name_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A literal expression (e.g. `"chicken"`, `42`, `true`, `null`).
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.expr.Expression}
|
||||
* @param {string|number|boolean|Date|null} value A literal value.
|
||||
*/
|
||||
ol.expr.Literal = function(value) {
|
||||
|
||||
/**
|
||||
* @type {string|number|boolean|Date|null}
|
||||
* @private
|
||||
*/
|
||||
this.value_ = value;
|
||||
|
||||
};
|
||||
goog.inherits(ol.expr.Literal, ol.expr.Expression);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.expr.Literal.prototype.evaluate = function() {
|
||||
return this.value_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the literal value.
|
||||
* @return {string|number|boolean|Date|null} The literal value.
|
||||
*/
|
||||
ol.expr.Literal.prototype.getValue = function() {
|
||||
return this.value_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.expr.LogicalOp = {
|
||||
AND: '&&',
|
||||
OR: '||'
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A binary logical expression (e.g. `foo && bar`, `bar || "chicken"`).
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.expr.Expression}
|
||||
* @param {ol.expr.LogicalOp} operator Logical operator.
|
||||
* @param {ol.expr.Expression} left Left expression.
|
||||
* @param {ol.expr.Expression} right Right expression.
|
||||
*/
|
||||
ol.expr.Logical = function(operator, left, right) {
|
||||
|
||||
/**
|
||||
* @type {ol.expr.LogicalOp}
|
||||
* @private
|
||||
*/
|
||||
this.operator_ = operator;
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.left_ = left;
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.right_ = right;
|
||||
|
||||
};
|
||||
goog.inherits(ol.expr.Logical, ol.expr.Expression);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a given string is a valid logical operator.
|
||||
* @param {string} candidate Operator to test.
|
||||
* @return {boolean} The operator is valid.
|
||||
*/
|
||||
ol.expr.Logical.isValidOp = (function() {
|
||||
var valid = {};
|
||||
for (var key in ol.expr.LogicalOp) {
|
||||
valid[ol.expr.LogicalOp[key]] = true;
|
||||
}
|
||||
return function isValidOp(candidate) {
|
||||
return !!valid[candidate];
|
||||
};
|
||||
}());
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.expr.Logical.prototype.evaluate = function(opt_scope, opt_fns,
|
||||
opt_this) {
|
||||
var result;
|
||||
var rightVal = this.right_.evaluate(opt_scope, opt_fns, opt_this);
|
||||
var leftVal = this.left_.evaluate(opt_scope, opt_fns, opt_this);
|
||||
|
||||
if (this.operator_ === ol.expr.LogicalOp.AND) {
|
||||
result = leftVal && rightVal;
|
||||
} else if (this.operator_ === ol.expr.LogicalOp.OR) {
|
||||
result = leftVal || rightVal;
|
||||
} else {
|
||||
throw new Error('Unsupported logical operator: ' + this.operator_);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the logical operator.
|
||||
* @return {string} The logical operator.
|
||||
*/
|
||||
ol.expr.Logical.prototype.getOperator = function() {
|
||||
return this.operator_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the left expression.
|
||||
* @return {ol.expr.Expression} The left expression.
|
||||
*/
|
||||
ol.expr.Logical.prototype.getLeft = function() {
|
||||
return this.left_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the right expression.
|
||||
* @return {ol.expr.Expression} The right expression.
|
||||
*/
|
||||
ol.expr.Logical.prototype.getRight = function() {
|
||||
return this.right_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.expr.MathOp = {
|
||||
ADD: '+',
|
||||
SUBTRACT: '-',
|
||||
MULTIPLY: '*',
|
||||
DIVIDE: '/',
|
||||
MOD: '%'
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A math expression (e.g. `foo + 42`, `bar % 10`).
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.expr.Expression}
|
||||
* @param {ol.expr.MathOp} operator Math operator.
|
||||
* @param {ol.expr.Expression} left Left expression.
|
||||
* @param {ol.expr.Expression} right Right expression.
|
||||
*/
|
||||
ol.expr.Math = function(operator, left, right) {
|
||||
|
||||
/**
|
||||
* @type {ol.expr.MathOp}
|
||||
* @private
|
||||
*/
|
||||
this.operator_ = operator;
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.left_ = left;
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.right_ = right;
|
||||
|
||||
};
|
||||
goog.inherits(ol.expr.Math, ol.expr.Expression);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a given string is a valid math operator.
|
||||
* @param {string} candidate Operator to test.
|
||||
* @return {boolean} The operator is valid.
|
||||
*/
|
||||
ol.expr.Math.isValidOp = (function() {
|
||||
var valid = {};
|
||||
for (var key in ol.expr.MathOp) {
|
||||
valid[ol.expr.MathOp[key]] = true;
|
||||
}
|
||||
return function isValidOp(candidate) {
|
||||
return !!valid[candidate];
|
||||
};
|
||||
}());
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.expr.Math.prototype.evaluate = function(opt_scope, opt_fns, opt_this) {
|
||||
var result;
|
||||
var rightVal = this.right_.evaluate(opt_scope, opt_fns, opt_this);
|
||||
var leftVal = this.left_.evaluate(opt_scope, opt_fns, opt_this);
|
||||
|
||||
var op = this.operator_;
|
||||
if (op === ol.expr.MathOp.ADD) {
|
||||
result = leftVal + rightVal;
|
||||
} else if (op === ol.expr.MathOp.SUBTRACT) {
|
||||
result = Number(leftVal) - Number(rightVal);
|
||||
} else if (op === ol.expr.MathOp.MULTIPLY) {
|
||||
result = Number(leftVal) * Number(rightVal);
|
||||
} else if (op === ol.expr.MathOp.DIVIDE) {
|
||||
result = Number(leftVal) / Number(rightVal);
|
||||
} else if (op === ol.expr.MathOp.MOD) {
|
||||
result = Number(leftVal) % Number(rightVal);
|
||||
} else {
|
||||
throw new Error('Unsupported math operator: ' + this.operator_);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the math operator.
|
||||
* @return {string} The math operator.
|
||||
*/
|
||||
ol.expr.Math.prototype.getOperator = function() {
|
||||
return this.operator_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the left expression.
|
||||
* @return {ol.expr.Expression} The left expression.
|
||||
*/
|
||||
ol.expr.Math.prototype.getLeft = function() {
|
||||
return this.left_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the right expression.
|
||||
* @return {ol.expr.Expression} The right expression.
|
||||
*/
|
||||
ol.expr.Math.prototype.getRight = function() {
|
||||
return this.right_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A member expression (e.g. `foo.bar`).
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.expr.Expression}
|
||||
* @param {ol.expr.Expression} object An expression that resolves to an
|
||||
* object.
|
||||
* @param {ol.expr.Identifier} property Identifier with name of property.
|
||||
*/
|
||||
ol.expr.Member = function(object, property) {
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.object_ = object;
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Identifier}
|
||||
* @private
|
||||
*/
|
||||
this.property_ = property;
|
||||
|
||||
};
|
||||
goog.inherits(ol.expr.Member, ol.expr.Expression);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.expr.Member.prototype.evaluate = function(opt_scope, opt_fns,
|
||||
opt_this) {
|
||||
var obj = this.object_.evaluate(opt_scope, opt_fns, opt_this);
|
||||
if (!goog.isObject(obj)) {
|
||||
throw new Error('Expected member expression to evaluate to an object ' +
|
||||
'but got ' + obj);
|
||||
}
|
||||
return this.property_.evaluate(/** @type {Object} */ (obj));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the object expression.
|
||||
* @return {ol.expr.Expression} The object.
|
||||
*/
|
||||
ol.expr.Member.prototype.getObject = function() {
|
||||
return this.object_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the property expression.
|
||||
* @return {ol.expr.Identifier} The property.
|
||||
*/
|
||||
ol.expr.Member.prototype.getProperty = function() {
|
||||
return this.property_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A logical not expression (e.g. `!foo`).
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.expr.Expression}
|
||||
* @param {ol.expr.Expression} argument Expression to negate.
|
||||
*/
|
||||
ol.expr.Not = function(argument) {
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.argument_ = argument;
|
||||
|
||||
};
|
||||
goog.inherits(ol.expr.Not, ol.expr.Expression);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.expr.Not.prototype.evaluate = function(opt_scope, opt_fns, opt_this) {
|
||||
return !this.argument_.evaluate(opt_scope, opt_fns, opt_this);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the argument (the negated expression).
|
||||
* @return {ol.expr.Expression} The argument.
|
||||
*/
|
||||
ol.expr.Not.prototype.getArgument = function() {
|
||||
return this.argument_;
|
||||
};
|
||||
@@ -1,900 +0,0 @@
|
||||
/**
|
||||
* The logic and naming of methods here are inspired by Esprima (BSD Licensed).
|
||||
* Esprima (http://esprima.org) includes the following copyright notices:
|
||||
*
|
||||
* Copyright (C) 2013 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
* Copyright (C) 2013 Thaddee Tyl <thaddee.tyl@gmail.com>
|
||||
* Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
* Copyright (C) 2012 Mathias Bynens <mathias@qiwi.be>
|
||||
* Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
|
||||
* Copyright (C) 2012 Kris Kowal <kris.kowal@cixar.com>
|
||||
* Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com>
|
||||
* Copyright (C) 2012 Arpad Borsos <arpad.borsos@googlemail.com>
|
||||
* Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
*/
|
||||
|
||||
goog.provide('ol.expr.Char'); // TODO: remove this - see #785
|
||||
goog.provide('ol.expr.Lexer');
|
||||
goog.provide('ol.expr.Token');
|
||||
goog.provide('ol.expr.TokenType');
|
||||
goog.provide('ol.expr.UnexpectedToken');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.debug.Error');
|
||||
|
||||
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
ol.expr.Char = {
|
||||
AMPERSAND: 38,
|
||||
BACKSLASH: 92,
|
||||
BANG: 33, // !
|
||||
CARRIAGE_RETURN: 13,
|
||||
COMMA: 44,
|
||||
DIGIT_0: 48,
|
||||
DIGIT_7: 55,
|
||||
DIGIT_9: 57,
|
||||
DOLLAR: 36,
|
||||
DOUBLE_QUOTE: 34,
|
||||
DOT: 46,
|
||||
EQUAL: 61,
|
||||
FORM_FEED: 0xC,
|
||||
GREATER: 62,
|
||||
LEFT_PAREN: 40,
|
||||
LESS: 60,
|
||||
LINE_FEED: 10,
|
||||
LINE_SEPARATOR: 0x2028,
|
||||
LOWER_A: 97,
|
||||
LOWER_E: 101,
|
||||
LOWER_F: 102,
|
||||
LOWER_X: 120,
|
||||
LOWER_Z: 122,
|
||||
MINUS: 45,
|
||||
NONBREAKING_SPACE: 0xA0,
|
||||
PARAGRAPH_SEPARATOR: 0x2029,
|
||||
PERCENT: 37,
|
||||
PIPE: 124,
|
||||
PLUS: 43,
|
||||
RIGHT_PAREN: 41,
|
||||
SINGLE_QUOTE: 39,
|
||||
SLASH: 47,
|
||||
SPACE: 32,
|
||||
STAR: 42,
|
||||
TAB: 9,
|
||||
TILDE: 126,
|
||||
UNDERSCORE: 95,
|
||||
UPPER_A: 65,
|
||||
UPPER_E: 69,
|
||||
UPPER_F: 70,
|
||||
UPPER_X: 88,
|
||||
UPPER_Z: 90,
|
||||
VERTICAL_TAB: 0xB
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.expr.TokenType = {
|
||||
BOOLEAN_LITERAL: 'Boolean',
|
||||
EOF: '<end>',
|
||||
IDENTIFIER: 'Identifier',
|
||||
KEYWORD: 'Keyword',
|
||||
NULL_LITERAL: 'Null',
|
||||
NUMERIC_LITERAL: 'Numeric',
|
||||
PUNCTUATOR: 'Punctuator',
|
||||
STRING_LITERAL: 'String',
|
||||
UNKNOWN: 'Unknown'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{type: (ol.expr.TokenType),
|
||||
* value: (string|number|boolean|null),
|
||||
* index: (number)}}
|
||||
*/
|
||||
ol.expr.Token;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Lexer constructor. Provides a tokenizer for a limited subset of ECMAScript
|
||||
* 5.1 expressions (http://www.ecma-international.org/ecma-262/5.1/#sec-11).
|
||||
*
|
||||
* @constructor
|
||||
* @param {string} source Source code.
|
||||
*/
|
||||
ol.expr.Lexer = function(source) {
|
||||
|
||||
/**
|
||||
* Source code.
|
||||
* @type {string}
|
||||
* @private
|
||||
*/
|
||||
this.source_ = source;
|
||||
|
||||
/**
|
||||
* Source length.
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.length_ = source.length;
|
||||
|
||||
/**
|
||||
* Current character index.
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.index_ = 0;
|
||||
|
||||
/**
|
||||
* Next character index (only set after `peek`ing).
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.nextIndex_ = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Scan the next token and throw if it isn't a punctuator that matches input.
|
||||
* @param {string} value Token value.
|
||||
*/
|
||||
ol.expr.Lexer.prototype.expect = function(value) {
|
||||
var match = this.match(value);
|
||||
if (!match) {
|
||||
throw new ol.expr.UnexpectedToken({
|
||||
type: ol.expr.TokenType.UNKNOWN,
|
||||
value: this.getCurrentChar_(),
|
||||
index: this.index_
|
||||
});
|
||||
}
|
||||
this.skip();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Increment the current character index.
|
||||
*
|
||||
* @param {number} delta Delta by which the index is advanced.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.increment_ = function(delta) {
|
||||
this.index_ += delta;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.3
|
||||
*
|
||||
* @param {number} code The unicode of a character.
|
||||
* @return {boolean} The character is a decimal digit.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.isDecimalDigit_ = function(code) {
|
||||
return (
|
||||
code >= ol.expr.Char.DIGIT_0 &&
|
||||
code <= ol.expr.Char.DIGIT_9);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-7.6.1.2
|
||||
*
|
||||
* @param {string} id A string identifier.
|
||||
* @return {boolean} The identifier is a future reserved word.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.isFutureReservedWord_ = function(id) {
|
||||
return (
|
||||
id === 'class' ||
|
||||
id === 'enum' ||
|
||||
id === 'export' ||
|
||||
id === 'extends' ||
|
||||
id === 'import' ||
|
||||
id === 'super');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.3
|
||||
*
|
||||
* @param {number} code The unicode of a character.
|
||||
* @return {boolean} The character is a hex digit.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.isHexDigit_ = function(code) {
|
||||
return this.isDecimalDigit_(code) ||
|
||||
(code >= ol.expr.Char.LOWER_A &&
|
||||
code <= ol.expr.Char.LOWER_F) ||
|
||||
(code >= ol.expr.Char.UPPER_A &&
|
||||
code <= ol.expr.Char.UPPER_F);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-7.6
|
||||
* Doesn't deal with non-ascii identifiers.
|
||||
*
|
||||
* @param {number} code The unicode of a character.
|
||||
* @return {boolean} The character is a valid identifier part.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.isIdentifierPart_ = function(code) {
|
||||
return this.isIdentifierStart_(code) ||
|
||||
(code >= ol.expr.Char.DIGIT_0 &&
|
||||
code <= ol.expr.Char.DIGIT_9);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-7.6
|
||||
* Doesn't yet deal with non-ascii identifiers.
|
||||
*
|
||||
* @param {number} code The unicode of a character.
|
||||
* @return {boolean} The character is a valid identifier start.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.isIdentifierStart_ = function(code) {
|
||||
return (code === ol.expr.Char.DOLLAR) ||
|
||||
(code === ol.expr.Char.UNDERSCORE) ||
|
||||
(code >= ol.expr.Char.UPPER_A &&
|
||||
code <= ol.expr.Char.UPPER_Z) ||
|
||||
(code >= ol.expr.Char.LOWER_A &&
|
||||
code <= ol.expr.Char.LOWER_Z);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine if the given identifier is an ECMAScript keyword. These cannot
|
||||
* be used as identifiers in programs. There is no real reason these could not
|
||||
* be used in ol.exprs - but they are reserved for future use.
|
||||
*
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-7.6.1.1
|
||||
*
|
||||
* @param {string} id Identifier.
|
||||
* @return {boolean} The identifier is a keyword.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.isKeyword_ = function(id) {
|
||||
return (
|
||||
id === 'break' ||
|
||||
id === 'case' ||
|
||||
id === 'catch' ||
|
||||
id === 'continue' ||
|
||||
id === 'debugger' ||
|
||||
id === 'default' ||
|
||||
id === 'delete' ||
|
||||
id === 'do' ||
|
||||
id === 'else' ||
|
||||
id === 'finally' ||
|
||||
id === 'for' ||
|
||||
id === 'function' ||
|
||||
id === 'if' ||
|
||||
id === 'in' ||
|
||||
id === 'instanceof' ||
|
||||
id === 'new' ||
|
||||
id === 'return' ||
|
||||
id === 'switch' ||
|
||||
id === 'this' ||
|
||||
id === 'throw' ||
|
||||
id === 'try' ||
|
||||
id === 'typeof' ||
|
||||
id === 'var' ||
|
||||
id === 'void' ||
|
||||
id === 'while' ||
|
||||
id === 'with');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-7.3
|
||||
*
|
||||
* @param {number} code The unicode of a character.
|
||||
* @return {boolean} The character is a line terminator.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.isLineTerminator_ = function(code) {
|
||||
return (code === ol.expr.Char.LINE_FEED) ||
|
||||
(code === ol.expr.Char.CARRIAGE_RETURN) ||
|
||||
(code === ol.expr.Char.LINE_SEPARATOR) ||
|
||||
(code === ol.expr.Char.PARAGRAPH_SEPARATOR);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.3
|
||||
*
|
||||
* @param {number} code The unicode of a character.
|
||||
* @return {boolean} The character is an octal digit.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.isOctalDigit_ = function(code) {
|
||||
return (
|
||||
code >= ol.expr.Char.DIGIT_0 &&
|
||||
code <= ol.expr.Char.DIGIT_7);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-7.2
|
||||
*
|
||||
* @param {number} code The unicode of a character.
|
||||
* @return {boolean} The character is whitespace.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.isWhitespace_ = function(code) {
|
||||
return (code === ol.expr.Char.SPACE) ||
|
||||
(code === ol.expr.Char.TAB) ||
|
||||
(code === ol.expr.Char.VERTICAL_TAB) ||
|
||||
(code === ol.expr.Char.FORM_FEED) ||
|
||||
(code === ol.expr.Char.NONBREAKING_SPACE) ||
|
||||
(code >= 0x1680 && '\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005' +
|
||||
'\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\uFEFF'
|
||||
.indexOf(String.fromCharCode(code)) > 0);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the unicode of the character at the given offset from the current index.
|
||||
*
|
||||
* @param {number} delta Offset from current index.
|
||||
* @return {number} The character code.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.getCharCode_ = function(delta) {
|
||||
return this.source_.charCodeAt(this.index_ + delta);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the character at the current index.
|
||||
*
|
||||
* @return {string} The current character.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.getCurrentChar_ = function() {
|
||||
return this.source_[this.index_];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the unicode of the character at the current index.
|
||||
*
|
||||
* @return {number} The current character code.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.getCurrentCharCode_ = function() {
|
||||
return this.getCharCode_(0);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the upcoming token matches the given punctuator.
|
||||
* @param {string} value Punctuator value.
|
||||
* @return {boolean} The token matches.
|
||||
*/
|
||||
ol.expr.Lexer.prototype.match = function(value) {
|
||||
var token = this.peek();
|
||||
return (
|
||||
token.type === ol.expr.TokenType.PUNCTUATOR &&
|
||||
token.value === value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Scan the next token.
|
||||
*
|
||||
* @return {ol.expr.Token} Next token.
|
||||
*/
|
||||
ol.expr.Lexer.prototype.next = function() {
|
||||
var code = this.skipWhitespace_();
|
||||
|
||||
if (this.index_ >= this.length_) {
|
||||
return {
|
||||
type: ol.expr.TokenType.EOF,
|
||||
value: null,
|
||||
index: this.index_
|
||||
};
|
||||
}
|
||||
|
||||
// check for common punctuation
|
||||
if (code === ol.expr.Char.LEFT_PAREN ||
|
||||
code === ol.expr.Char.RIGHT_PAREN) {
|
||||
return this.scanPunctuator_(code);
|
||||
}
|
||||
|
||||
// check for string literal
|
||||
if (code === ol.expr.Char.SINGLE_QUOTE ||
|
||||
code === ol.expr.Char.DOUBLE_QUOTE) {
|
||||
return this.scanStringLiteral_(code);
|
||||
}
|
||||
|
||||
// check for identifier
|
||||
if (this.isIdentifierStart_(code)) {
|
||||
return this.scanIdentifier_(code);
|
||||
}
|
||||
|
||||
// check dot punctuation or decimal
|
||||
if (code === ol.expr.Char.DOT) {
|
||||
if (this.isDecimalDigit_(this.getCharCode_(1))) {
|
||||
return this.scanNumericLiteral_(code);
|
||||
}
|
||||
return this.scanPunctuator_(code);
|
||||
}
|
||||
|
||||
// check for numeric literal
|
||||
if (this.isDecimalDigit_(code)) {
|
||||
return this.scanNumericLiteral_(code);
|
||||
}
|
||||
|
||||
// all the rest is punctuation
|
||||
return this.scanPunctuator_(code);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Peek at the next token, but don't advance the index.
|
||||
*
|
||||
* @return {ol.expr.Token} The upcoming token.
|
||||
*/
|
||||
ol.expr.Lexer.prototype.peek = function() {
|
||||
var currentIndex = this.index_;
|
||||
var token = this.next();
|
||||
this.nextIndex_ = this.index_;
|
||||
this.index_ = currentIndex;
|
||||
return token;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Scan hex literal as numeric token.
|
||||
*
|
||||
* @param {number} code The current character code.
|
||||
* @return {ol.expr.Token} Numeric literal token.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.scanHexLiteral_ = function(code) {
|
||||
var str = '';
|
||||
var start = this.index_ - 2;
|
||||
|
||||
while (this.index_ < this.length_) {
|
||||
if (!this.isHexDigit_(code)) {
|
||||
break;
|
||||
}
|
||||
str += String.fromCharCode(code);
|
||||
this.increment_(1);
|
||||
code = this.getCurrentCharCode_();
|
||||
}
|
||||
|
||||
if (str.length === 0 || this.isIdentifierStart_(code)) {
|
||||
throw new ol.expr.UnexpectedToken({
|
||||
type: ol.expr.TokenType.UNKNOWN,
|
||||
value: String.fromCharCode(code),
|
||||
index: this.index_
|
||||
});
|
||||
}
|
||||
|
||||
goog.asserts.assert(!isNaN(parseInt('0x' + str, 16)), 'Valid hex: ' + str);
|
||||
|
||||
return {
|
||||
type: ol.expr.TokenType.NUMERIC_LITERAL,
|
||||
value: parseInt('0x' + str, 16),
|
||||
index: start
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Scan identifier token.
|
||||
*
|
||||
* @param {number} code The current character code.
|
||||
* @return {ol.expr.Token} Identifier token.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.scanIdentifier_ = function(code) {
|
||||
goog.asserts.assert(this.isIdentifierStart_(code),
|
||||
'Must be called with a valid identifier');
|
||||
|
||||
var start = this.index_;
|
||||
this.increment_(1);
|
||||
|
||||
while (this.index_ < this.length_) {
|
||||
code = this.getCurrentCharCode_();
|
||||
if (this.isIdentifierPart_(code)) {
|
||||
this.increment_(1);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
var id = this.source_.slice(start, this.index_);
|
||||
|
||||
var type;
|
||||
if (id.length === 1) {
|
||||
type = ol.expr.TokenType.IDENTIFIER;
|
||||
} else if (this.isKeyword_(id)) {
|
||||
type = ol.expr.TokenType.KEYWORD;
|
||||
} else if (id === 'null') {
|
||||
type = ol.expr.TokenType.NULL_LITERAL;
|
||||
} else if (id === 'true' || id === 'false') {
|
||||
type = ol.expr.TokenType.BOOLEAN_LITERAL;
|
||||
} else {
|
||||
type = ol.expr.TokenType.IDENTIFIER;
|
||||
}
|
||||
|
||||
return {
|
||||
type: type,
|
||||
value: id,
|
||||
index: start
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Scan numeric literal token.
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.3
|
||||
*
|
||||
* @param {number} code The current character code.
|
||||
* @return {ol.expr.Token} Numeric literal token.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.scanNumericLiteral_ = function(code) {
|
||||
goog.asserts.assert(
|
||||
code === ol.expr.Char.DOT || this.isDecimalDigit_(code),
|
||||
'Valid start for numeric literal: ' + String.fromCharCode(code));
|
||||
|
||||
// start assembling numeric string
|
||||
var str = '';
|
||||
var start = this.index_;
|
||||
|
||||
if (code !== ol.expr.Char.DOT) {
|
||||
|
||||
if (code === ol.expr.Char.DIGIT_0) {
|
||||
var nextCode = this.getCharCode_(1);
|
||||
|
||||
// hex literals start with 0X or 0x
|
||||
if (nextCode === ol.expr.Char.UPPER_X ||
|
||||
nextCode === ol.expr.Char.LOWER_X) {
|
||||
this.increment_(2);
|
||||
return this.scanHexLiteral_(this.getCurrentCharCode_());
|
||||
}
|
||||
|
||||
// octals start with 0
|
||||
if (this.isOctalDigit_(nextCode)) {
|
||||
this.increment_(1);
|
||||
return this.scanOctalLiteral_(nextCode);
|
||||
}
|
||||
|
||||
// numbers like 09 not allowed
|
||||
if (this.isDecimalDigit_(nextCode)) {
|
||||
throw new ol.expr.UnexpectedToken({
|
||||
type: ol.expr.TokenType.UNKNOWN,
|
||||
value: String.fromCharCode(nextCode),
|
||||
index: this.index_
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// scan all decimal chars
|
||||
while (this.isDecimalDigit_(code)) {
|
||||
str += String.fromCharCode(code);
|
||||
this.increment_(1);
|
||||
code = this.getCurrentCharCode_();
|
||||
}
|
||||
}
|
||||
|
||||
// scan fractional part
|
||||
if (code === ol.expr.Char.DOT) {
|
||||
str += String.fromCharCode(code);
|
||||
this.increment_(1);
|
||||
code = this.getCurrentCharCode_();
|
||||
|
||||
// scan all decimal chars
|
||||
while (this.isDecimalDigit_(code)) {
|
||||
str += String.fromCharCode(code);
|
||||
this.increment_(1);
|
||||
code = this.getCurrentCharCode_();
|
||||
}
|
||||
}
|
||||
|
||||
// scan exponent
|
||||
if (code === ol.expr.Char.UPPER_E ||
|
||||
code === ol.expr.Char.LOWER_E) {
|
||||
str += 'E';
|
||||
this.increment_(1);
|
||||
|
||||
code = this.getCurrentCharCode_();
|
||||
if (code === ol.expr.Char.PLUS ||
|
||||
code === ol.expr.Char.MINUS) {
|
||||
str += String.fromCharCode(code);
|
||||
this.increment_(1);
|
||||
code = this.getCurrentCharCode_();
|
||||
}
|
||||
|
||||
if (!this.isDecimalDigit_(code)) {
|
||||
throw new ol.expr.UnexpectedToken({
|
||||
type: ol.expr.TokenType.UNKNOWN,
|
||||
value: String.fromCharCode(code),
|
||||
index: this.index_
|
||||
});
|
||||
}
|
||||
|
||||
// scan all decimal chars (TODO: unduplicate this)
|
||||
while (this.isDecimalDigit_(code)) {
|
||||
str += String.fromCharCode(code);
|
||||
this.increment_(1);
|
||||
code = this.getCurrentCharCode_();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isIdentifierStart_(code)) {
|
||||
throw new ol.expr.UnexpectedToken({
|
||||
type: ol.expr.TokenType.UNKNOWN,
|
||||
value: String.fromCharCode(code),
|
||||
index: this.index_
|
||||
});
|
||||
}
|
||||
|
||||
goog.asserts.assert(!isNaN(parseFloat(str)), 'Valid number: ' + str);
|
||||
|
||||
return {
|
||||
type: ol.expr.TokenType.NUMERIC_LITERAL,
|
||||
value: parseFloat(str),
|
||||
index: start
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Scan octal literal as numeric token.
|
||||
*
|
||||
* @param {number} code The current character code.
|
||||
* @return {ol.expr.Token} Numeric literal token.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.scanOctalLiteral_ = function(code) {
|
||||
goog.asserts.assert(this.isOctalDigit_(code));
|
||||
|
||||
var str = '0' + String.fromCharCode(code);
|
||||
var start = this.index_ - 1;
|
||||
this.increment_(1);
|
||||
|
||||
while (this.index_ < this.length_) {
|
||||
code = this.getCurrentCharCode_();
|
||||
if (!this.isOctalDigit_(code)) {
|
||||
break;
|
||||
}
|
||||
str += String.fromCharCode(code);
|
||||
this.increment_(1);
|
||||
}
|
||||
|
||||
code = this.getCurrentCharCode_();
|
||||
if (this.isIdentifierStart_(code) ||
|
||||
this.isDecimalDigit_(code)) {
|
||||
throw new ol.expr.UnexpectedToken({
|
||||
type: ol.expr.TokenType.UNKNOWN,
|
||||
value: String.fromCharCode(code),
|
||||
index: this.index_
|
||||
});
|
||||
}
|
||||
|
||||
goog.asserts.assert(!isNaN(parseInt(str, 8)), 'Valid octal: ' + str);
|
||||
|
||||
return {
|
||||
type: ol.expr.TokenType.NUMERIC_LITERAL,
|
||||
value: parseInt(str, 8),
|
||||
index: start
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Scan punctuator token (a subset of allowed tokens in 7.7).
|
||||
*
|
||||
* @param {number} code The current character code.
|
||||
* @return {ol.expr.Token} Punctuator token.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.scanPunctuator_ = function(code) {
|
||||
var start = this.index_;
|
||||
|
||||
// single char punctuation that also doesn't start longer punctuation
|
||||
// (we disallow assignment, so no += etc.)
|
||||
if (code === ol.expr.Char.DOT ||
|
||||
code === ol.expr.Char.LEFT_PAREN ||
|
||||
code === ol.expr.Char.RIGHT_PAREN ||
|
||||
code === ol.expr.Char.COMMA ||
|
||||
code === ol.expr.Char.PLUS ||
|
||||
code === ol.expr.Char.MINUS ||
|
||||
code === ol.expr.Char.STAR ||
|
||||
code === ol.expr.Char.SLASH ||
|
||||
code === ol.expr.Char.PERCENT ||
|
||||
code === ol.expr.Char.TILDE) {
|
||||
|
||||
this.increment_(1);
|
||||
return {
|
||||
type: ol.expr.TokenType.PUNCTUATOR,
|
||||
value: String.fromCharCode(code),
|
||||
index: start
|
||||
};
|
||||
}
|
||||
|
||||
// check for 2-character punctuation
|
||||
var nextCode = this.getCharCode_(1);
|
||||
|
||||
// assignment or comparison (and we don't allow assignment)
|
||||
if (nextCode === ol.expr.Char.EQUAL) {
|
||||
if (code === ol.expr.Char.BANG || code === ol.expr.Char.EQUAL) {
|
||||
// we're looking at !=, ==, !==, or ===
|
||||
this.increment_(2);
|
||||
|
||||
// check for triple
|
||||
if (this.getCurrentCharCode_() === ol.expr.Char.EQUAL) {
|
||||
this.increment_(1);
|
||||
return {
|
||||
type: ol.expr.TokenType.PUNCTUATOR,
|
||||
value: String.fromCharCode(code) + '==',
|
||||
index: start
|
||||
};
|
||||
} else {
|
||||
// != or ==
|
||||
return {
|
||||
type: ol.expr.TokenType.PUNCTUATOR,
|
||||
value: String.fromCharCode(code) + '=',
|
||||
index: start
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (code === ol.expr.Char.GREATER ||
|
||||
code === ol.expr.Char.LESS) {
|
||||
this.increment_(2);
|
||||
return {
|
||||
type: ol.expr.TokenType.PUNCTUATOR,
|
||||
value: String.fromCharCode(code) + '=',
|
||||
index: start
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// remaining 2-charcter punctuators are || and &&
|
||||
if (code === nextCode &&
|
||||
(code === ol.expr.Char.PIPE ||
|
||||
code === ol.expr.Char.AMPERSAND)) {
|
||||
|
||||
this.increment_(2);
|
||||
var str = String.fromCharCode(code);
|
||||
return {
|
||||
type: ol.expr.TokenType.PUNCTUATOR,
|
||||
value: str + str,
|
||||
index: start
|
||||
};
|
||||
}
|
||||
|
||||
// we don't allow 4-character punctuator (>>>=)
|
||||
// and the allowed 3-character punctuators (!==, ===) are already consumed
|
||||
|
||||
// other single character punctuators
|
||||
if (code === ol.expr.Char.GREATER ||
|
||||
code === ol.expr.Char.LESS ||
|
||||
code === ol.expr.Char.BANG ||
|
||||
code === ol.expr.Char.AMPERSAND ||
|
||||
code === ol.expr.Char.PIPE) {
|
||||
|
||||
this.increment_(1);
|
||||
return {
|
||||
type: ol.expr.TokenType.PUNCTUATOR,
|
||||
value: String.fromCharCode(code),
|
||||
index: start
|
||||
};
|
||||
}
|
||||
|
||||
throw new ol.expr.UnexpectedToken({
|
||||
type: ol.expr.TokenType.UNKNOWN,
|
||||
value: String.fromCharCode(code),
|
||||
index: this.index_
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Scan string literal token.
|
||||
*
|
||||
* @param {number} quote The current character code.
|
||||
* @return {ol.expr.Token} String literal token.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.scanStringLiteral_ = function(quote) {
|
||||
goog.asserts.assert(quote === ol.expr.Char.SINGLE_QUOTE ||
|
||||
quote === ol.expr.Char.DOUBLE_QUOTE,
|
||||
'Strings must start with a quote: ' + String.fromCharCode(quote));
|
||||
|
||||
var start = this.index_;
|
||||
this.increment_(1);
|
||||
|
||||
var str = '';
|
||||
var code;
|
||||
while (this.index_ < this.length_) {
|
||||
code = this.getCurrentCharCode_();
|
||||
this.increment_(1);
|
||||
if (code === quote) {
|
||||
quote = 0;
|
||||
break;
|
||||
}
|
||||
// look for escaped quote or backslash
|
||||
if (code === ol.expr.Char.BACKSLASH) {
|
||||
str += this.getCurrentChar_();
|
||||
this.increment_(1);
|
||||
} else {
|
||||
str += String.fromCharCode(code);
|
||||
}
|
||||
}
|
||||
|
||||
if (quote !== 0) {
|
||||
// unterminated string literal
|
||||
throw new ol.expr.UnexpectedToken(this.peek());
|
||||
}
|
||||
|
||||
return {
|
||||
type: ol.expr.TokenType.STRING_LITERAL,
|
||||
value: str,
|
||||
index: start
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* After peeking, skip may be called to advance the cursor without re-scanning.
|
||||
*/
|
||||
ol.expr.Lexer.prototype.skip = function() {
|
||||
this.index_ = this.nextIndex_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Skip all whitespace.
|
||||
* @return {number} The character code of the first non-whitespace character.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Lexer.prototype.skipWhitespace_ = function() {
|
||||
var code = NaN;
|
||||
while (this.index_ < this.length_) {
|
||||
code = this.getCurrentCharCode_();
|
||||
if (this.isWhitespace_(code)) {
|
||||
this.increment_(1);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return code;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Error object for unexpected tokens.
|
||||
* @param {ol.expr.Token} token The unexpected token.
|
||||
* @param {string=} opt_message Custom error message.
|
||||
* @constructor
|
||||
* @extends {goog.debug.Error}
|
||||
*/
|
||||
ol.expr.UnexpectedToken = function(token, opt_message) {
|
||||
var message = goog.isDef(opt_message) ? opt_message :
|
||||
'Unexpected token ' + token.value + ' at index ' + token.index;
|
||||
|
||||
goog.debug.Error.call(this, message);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Token}
|
||||
*/
|
||||
this.token = token;
|
||||
|
||||
};
|
||||
goog.inherits(ol.expr.UnexpectedToken, goog.debug.Error);
|
||||
|
||||
|
||||
/** @override */
|
||||
ol.expr.UnexpectedToken.prototype.name = 'UnexpectedToken';
|
||||
@@ -1,478 +0,0 @@
|
||||
/**
|
||||
* The logic and naming of methods here are inspired by Esprima (BSD Licensed).
|
||||
* Esprima (http://esprima.org) includes the following copyright notices:
|
||||
*
|
||||
* Copyright (C) 2013 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
* Copyright (C) 2013 Thaddee Tyl <thaddee.tyl@gmail.com>
|
||||
* Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
* Copyright (C) 2012 Mathias Bynens <mathias@qiwi.be>
|
||||
* Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl>
|
||||
* Copyright (C) 2012 Kris Kowal <kris.kowal@cixar.com>
|
||||
* Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com>
|
||||
* Copyright (C) 2012 Arpad Borsos <arpad.borsos@googlemail.com>
|
||||
* Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
*/
|
||||
|
||||
goog.provide('ol.expr.Parser');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
goog.require('ol.expr.Expression');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Lexer');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.Logical');
|
||||
goog.require('ol.expr.LogicalOp');
|
||||
goog.require('ol.expr.Math');
|
||||
goog.require('ol.expr.MathOp');
|
||||
goog.require('ol.expr.Member');
|
||||
goog.require('ol.expr.Not');
|
||||
goog.require('ol.expr.Token');
|
||||
goog.require('ol.expr.TokenType');
|
||||
goog.require('ol.expr.UnexpectedToken');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Instances of ol.expr.Parser parse a very limited set of ECMAScript
|
||||
* expressions (http://www.ecma-international.org/ecma-262/5.1/#sec-11).
|
||||
*
|
||||
* - Primary Expression (11.1):
|
||||
* - Identifier (e.g. `foo`)
|
||||
* - Literal (e.g. `"some string"` or `42`)
|
||||
* - Grouped (e.g. `(foo)`)
|
||||
* - Left-Hand-Side Expression (11.2):
|
||||
* - Property Accessors
|
||||
* - Dot notation only
|
||||
* - Function Calls
|
||||
* - Identifier with arguments only (e.g. `foo(bar, 42)`)
|
||||
* - Unary Operators (11.4)
|
||||
* - Logical Not (e.g. `!foo`)
|
||||
* - Multiplicitave Operators (11.5)
|
||||
* - Additive Operators (11.6)
|
||||
* - Relational Operators (11.8)
|
||||
* - <, >, <=, and >= only
|
||||
* - Equality Operators (11.9)
|
||||
* - Binary Logical Operators (11.11)
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
ol.expr.Parser = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine the precedence for the given token.
|
||||
*
|
||||
* @param {ol.expr.Token} token A token.
|
||||
* @return {number} The precedence for the given token. Higher gets more
|
||||
* precedence.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.binaryPrecedence_ = function(token) {
|
||||
var precedence = 0;
|
||||
if (token.type !== ol.expr.TokenType.PUNCTUATOR) {
|
||||
return precedence;
|
||||
}
|
||||
|
||||
switch (token.value) {
|
||||
case ol.expr.LogicalOp.OR:
|
||||
precedence = 1;
|
||||
break;
|
||||
case ol.expr.LogicalOp.AND:
|
||||
precedence = 2;
|
||||
break;
|
||||
case ol.expr.ComparisonOp.EQ:
|
||||
case ol.expr.ComparisonOp.NEQ:
|
||||
case ol.expr.ComparisonOp.STRICT_EQ:
|
||||
case ol.expr.ComparisonOp.STRICT_NEQ:
|
||||
precedence = 3;
|
||||
break;
|
||||
case ol.expr.ComparisonOp.GT:
|
||||
case ol.expr.ComparisonOp.LT:
|
||||
case ol.expr.ComparisonOp.GTE:
|
||||
case ol.expr.ComparisonOp.LTE:
|
||||
precedence = 4;
|
||||
break;
|
||||
case ol.expr.MathOp.ADD:
|
||||
case ol.expr.MathOp.SUBTRACT:
|
||||
precedence = 5;
|
||||
break;
|
||||
case ol.expr.MathOp.MULTIPLY:
|
||||
case ol.expr.MathOp.DIVIDE:
|
||||
case ol.expr.MathOp.MOD:
|
||||
precedence = 6;
|
||||
break;
|
||||
default:
|
||||
// punctuator is not a supported binary operator, that's fine
|
||||
break;
|
||||
}
|
||||
|
||||
return precedence;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a binary expression.
|
||||
*
|
||||
* @param {string} operator Operator.
|
||||
* @param {ol.expr.Expression} left Left expression.
|
||||
* @param {ol.expr.Expression} right Right expression.
|
||||
* @return {ol.expr.Expression} The expression.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.createBinaryExpression_ = function(operator,
|
||||
left, right) {
|
||||
var expr;
|
||||
if (ol.expr.Comparison.isValidOp(operator)) {
|
||||
expr = new ol.expr.Comparison(
|
||||
/** @type {ol.expr.ComparisonOp.<string>} */ (operator),
|
||||
left, right);
|
||||
} else if (ol.expr.Logical.isValidOp(operator)) {
|
||||
expr = new ol.expr.Logical(
|
||||
/** @type {ol.expr.LogicalOp.<string>} */ (operator),
|
||||
left, right);
|
||||
} else if (ol.expr.Math.isValidOp(operator)) {
|
||||
expr = new ol.expr.Math(
|
||||
/** @type {ol.expr.MathOp.<string>} */ (operator),
|
||||
left, right);
|
||||
} else {
|
||||
throw new Error('Unsupported binary operator: ' + operator);
|
||||
}
|
||||
return expr;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a call expression.
|
||||
*
|
||||
* @param {ol.expr.Expression} callee Expression for function.
|
||||
* @param {Array.<ol.expr.Expression>} args Arguments array.
|
||||
* @return {ol.expr.Call} Call expression.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.createCallExpression_ = function(callee, args) {
|
||||
return new ol.expr.Call(callee, args);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create an identifier expression.
|
||||
*
|
||||
* @param {string} name Identifier name.
|
||||
* @return {ol.expr.Identifier} Identifier expression.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.createIdentifier_ = function(name) {
|
||||
return new ol.expr.Identifier(name);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a literal expression.
|
||||
*
|
||||
* @param {string|number|boolean|null} value Literal value.
|
||||
* @return {ol.expr.Literal} The literal expression.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.createLiteral_ = function(value) {
|
||||
return new ol.expr.Literal(value);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a member expression.
|
||||
*
|
||||
* // TODO: make exp {ol.expr.Member|ol.expr.Identifier}
|
||||
* @param {ol.expr.Expression} object Expression.
|
||||
* @param {ol.expr.Identifier} property Member name.
|
||||
* @return {ol.expr.Member} The member expression.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.createMemberExpression_ = function(object,
|
||||
property) {
|
||||
return new ol.expr.Member(object, property);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create a unary expression. The only true unary operator supported here is
|
||||
* "!". For +/-, we apply the operator to literal expressions and return
|
||||
* another literal.
|
||||
*
|
||||
* @param {ol.expr.Token} op Operator.
|
||||
* @param {ol.expr.Expression} argument Expression.
|
||||
* @return {ol.expr.Expression} The unary expression.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.createUnaryExpression_ = function(op, argument) {
|
||||
goog.asserts.assert(op.value === '!' || op.value === '+' || op.value === '-');
|
||||
var expr;
|
||||
if (op.value === '!') {
|
||||
expr = new ol.expr.Not(argument);
|
||||
} else if (!(argument instanceof ol.expr.Literal)) {
|
||||
throw new ol.expr.UnexpectedToken(op);
|
||||
} else {
|
||||
// we've got +/- literal
|
||||
if (op.value === '+') {
|
||||
expr = this.createLiteral_(
|
||||
+ /** @type {number|string|boolean|null} */ (argument.evaluate()));
|
||||
} else {
|
||||
expr = this.createLiteral_(
|
||||
- /** @type {number|string|boolean|null} */ (argument.evaluate()));
|
||||
}
|
||||
}
|
||||
return expr;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse an expression.
|
||||
*
|
||||
* @param {string} source Expression source.
|
||||
* @return {ol.expr.Expression} Expression.
|
||||
*/
|
||||
ol.expr.Parser.prototype.parse = function(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var expr = this.parseExpression_(lexer);
|
||||
var token = lexer.peek();
|
||||
if (token.type !== ol.expr.TokenType.EOF) {
|
||||
throw new ol.expr.UnexpectedToken(token);
|
||||
}
|
||||
return expr;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse call arguments
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-11.2.4
|
||||
*
|
||||
* @param {ol.expr.Lexer} lexer Lexer.
|
||||
* @return {Array.<ol.expr.Expression>} Arguments.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.parseArguments_ = function(lexer) {
|
||||
var args = [];
|
||||
|
||||
lexer.expect('(');
|
||||
|
||||
if (!lexer.match(')')) {
|
||||
while (true) {
|
||||
args.push(this.parseBinaryExpression_(lexer));
|
||||
if (lexer.match(')')) {
|
||||
break;
|
||||
}
|
||||
lexer.expect(',');
|
||||
}
|
||||
}
|
||||
lexer.skip();
|
||||
|
||||
return args;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a binary expression. Supported binary expressions:
|
||||
*
|
||||
* - Multiplicative Operators (`*`, `/`, `%`)
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-11.5
|
||||
|
||||
* - Additive Operators (`+`, `-`)
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-11.6
|
||||
*
|
||||
* - Relational Operators (`<`, `>`, `<=`, `>=`)
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-11.8
|
||||
*
|
||||
* - Equality Operators (`==`, `!=`, `===`, `!==`)
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-11.9
|
||||
*
|
||||
* - Binary Logical Operators (`&&`, `||`)
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-11.11
|
||||
*
|
||||
* @param {ol.expr.Lexer} lexer Lexer.
|
||||
* @return {ol.expr.Expression} Expression.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.parseBinaryExpression_ = function(lexer) {
|
||||
var left = this.parseUnaryExpression_(lexer);
|
||||
|
||||
var operator = lexer.peek();
|
||||
var precedence = this.binaryPrecedence_(operator);
|
||||
if (precedence === 0) {
|
||||
// not a supported binary operator
|
||||
return left;
|
||||
}
|
||||
lexer.skip();
|
||||
|
||||
var right = this.parseUnaryExpression_(lexer);
|
||||
var stack = [left, operator, right];
|
||||
|
||||
precedence = this.binaryPrecedence_(lexer.peek());
|
||||
while (precedence > 0) {
|
||||
// TODO: cache operator precedence in stack
|
||||
while (stack.length > 2 &&
|
||||
(precedence <= this.binaryPrecedence_(stack[stack.length - 2]))) {
|
||||
right = stack.pop();
|
||||
operator = stack.pop();
|
||||
left = stack.pop();
|
||||
stack.push(this.createBinaryExpression_(operator.value, left, right));
|
||||
}
|
||||
stack.push(lexer.next());
|
||||
stack.push(this.parseUnaryExpression_(lexer));
|
||||
precedence = this.binaryPrecedence_(lexer.peek());
|
||||
}
|
||||
|
||||
var i = stack.length - 1;
|
||||
var expr = stack[i];
|
||||
while (i > 1) {
|
||||
expr = this.createBinaryExpression_(stack[i - 1].value, stack[i - 2], expr);
|
||||
i -= 2;
|
||||
}
|
||||
|
||||
return expr;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse a group expression.
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-11.1.6
|
||||
*
|
||||
* @param {ol.expr.Lexer} lexer Lexer.
|
||||
* @return {ol.expr.Expression} Expression.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.parseGroupExpression_ = function(lexer) {
|
||||
lexer.expect('(');
|
||||
var expr = this.parseExpression_(lexer);
|
||||
lexer.expect(')');
|
||||
return expr;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse left-hand-side expression. Limited to Member Expressions
|
||||
* and Call Expressions.
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-11.2
|
||||
*
|
||||
* @param {ol.expr.Lexer} lexer Lexer.
|
||||
* @return {ol.expr.Expression} Expression.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.parseLeftHandSideExpression_ = function(lexer) {
|
||||
var expr = this.parsePrimaryExpression_(lexer);
|
||||
var token = lexer.peek();
|
||||
if (token.value === '(') {
|
||||
// only allow calls on identifiers (e.g. `foo()` not `foo.bar()`)
|
||||
if (!(expr instanceof ol.expr.Identifier)) {
|
||||
// TODO: more helpful error messages for restricted syntax
|
||||
throw new ol.expr.UnexpectedToken(token);
|
||||
}
|
||||
var args = this.parseArguments_(lexer);
|
||||
expr = this.createCallExpression_(expr, args);
|
||||
} else {
|
||||
// TODO: throw if not Identifier
|
||||
while (token.value === '.') {
|
||||
var property = this.parseNonComputedMember_(lexer);
|
||||
expr = this.createMemberExpression_(expr, property);
|
||||
token = lexer.peek();
|
||||
}
|
||||
}
|
||||
return expr;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse non-computed member.
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-11.2
|
||||
*
|
||||
* @param {ol.expr.Lexer} lexer Lexer.
|
||||
* @return {ol.expr.Identifier} Expression.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.parseNonComputedMember_ = function(lexer) {
|
||||
lexer.expect('.');
|
||||
|
||||
var token = lexer.next();
|
||||
if (token.type !== ol.expr.TokenType.IDENTIFIER &&
|
||||
token.type !== ol.expr.TokenType.KEYWORD &&
|
||||
token.type !== ol.expr.TokenType.BOOLEAN_LITERAL &&
|
||||
token.type !== ol.expr.TokenType.NULL_LITERAL) {
|
||||
throw new ol.expr.UnexpectedToken(token);
|
||||
}
|
||||
|
||||
return this.createIdentifier_(String(token.value));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse primary expression.
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-11.1
|
||||
*
|
||||
* @param {ol.expr.Lexer} lexer Lexer.
|
||||
* @return {ol.expr.Expression} Expression.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.parsePrimaryExpression_ = function(lexer) {
|
||||
var token = lexer.peek();
|
||||
if (token.value === '(') {
|
||||
return this.parseGroupExpression_(lexer);
|
||||
}
|
||||
lexer.skip();
|
||||
var expr;
|
||||
var type = token.type;
|
||||
if (type === ol.expr.TokenType.IDENTIFIER) {
|
||||
expr = this.createIdentifier_(/** @type {string} */ (token.value));
|
||||
} else if (type === ol.expr.TokenType.STRING_LITERAL ||
|
||||
type === ol.expr.TokenType.NUMERIC_LITERAL) {
|
||||
// numeric and string literals are already the correct type
|
||||
expr = this.createLiteral_(token.value);
|
||||
} else if (type === ol.expr.TokenType.BOOLEAN_LITERAL) {
|
||||
// because booleans are valid member properties, tokens are still string
|
||||
expr = this.createLiteral_(token.value === 'true');
|
||||
} else if (type === ol.expr.TokenType.NULL_LITERAL) {
|
||||
expr = this.createLiteral_(null);
|
||||
} else {
|
||||
throw new ol.expr.UnexpectedToken(token);
|
||||
}
|
||||
return expr;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse expression with a unary operator. Limited to logical not operator.
|
||||
* http://www.ecma-international.org/ecma-262/5.1/#sec-11.4
|
||||
*
|
||||
* @param {ol.expr.Lexer} lexer Lexer.
|
||||
* @return {ol.expr.Expression} Expression.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.parseUnaryExpression_ = function(lexer) {
|
||||
var expr;
|
||||
var operator = lexer.peek();
|
||||
if (operator.type !== ol.expr.TokenType.PUNCTUATOR) {
|
||||
expr = this.parseLeftHandSideExpression_(lexer);
|
||||
} else if (operator.value === '!' || operator.value === '-' ||
|
||||
operator.value === '+') {
|
||||
lexer.skip();
|
||||
expr = this.parseUnaryExpression_(lexer);
|
||||
expr = this.createUnaryExpression_(operator, expr);
|
||||
} else {
|
||||
expr = this.parseLeftHandSideExpression_(lexer);
|
||||
}
|
||||
return expr;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Parse an expression.
|
||||
*
|
||||
* @param {ol.expr.Lexer} lexer Lexer.
|
||||
* @return {ol.expr.Expression} Expression.
|
||||
* @private
|
||||
*/
|
||||
ol.expr.Parser.prototype.parseExpression_ = function(lexer) {
|
||||
return this.parseBinaryExpression_(lexer);
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
/**
|
||||
* @namespace ol.parser
|
||||
*/
|
||||
@@ -1,37 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.Filter');
|
||||
goog.require('ol.parser.ogc.Filter_v1_0_0');
|
||||
goog.require('ol.parser.ogc.Filter_v1_1_0');
|
||||
goog.require('ol.parser.ogc.Versioned');
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable OGC Filter version 1.0.0.
|
||||
*/
|
||||
ol.ENABLE_OGCFILTER_1_0_0 = true;
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable OGC Filter version 1.1.0.
|
||||
*/
|
||||
ol.ENABLE_OGCFILTER_1_1_0 = true;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object=} opt_options Options which will be set on this object.
|
||||
* @extends {ol.parser.ogc.Versioned}
|
||||
*/
|
||||
ol.parser.ogc.Filter = function(opt_options) {
|
||||
opt_options = opt_options || {};
|
||||
opt_options['defaultVersion'] = '1.0.0';
|
||||
this.parsers = {};
|
||||
if (ol.ENABLE_OGCFILTER_1_0_0) {
|
||||
this.parsers['v1_0_0'] = ol.parser.ogc.Filter_v1_0_0;
|
||||
}
|
||||
if (ol.ENABLE_OGCFILTER_1_1_0) {
|
||||
this.parsers['v1_1_0'] = ol.parser.ogc.Filter_v1_1_0;
|
||||
}
|
||||
goog.base(this, opt_options);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.Filter, ol.parser.ogc.Versioned);
|
||||
@@ -1,654 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.Filter_v1');
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('goog.object');
|
||||
goog.require('goog.string');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.Logical');
|
||||
goog.require('ol.expr.LogicalOp');
|
||||
goog.require('ol.expr.Not');
|
||||
goog.require('ol.expr.functions');
|
||||
goog.require('ol.parser.XML');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.XML}
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1 = function() {
|
||||
this.defaultNamespaceURI = 'http://www.opengis.net/ogc';
|
||||
this.errorProperty = 'filter';
|
||||
this.readers = {
|
||||
'http://www.opengis.net/ogc': {
|
||||
_expression: function(node) {
|
||||
var expressions = [];
|
||||
var obj, value, numValue, expr;
|
||||
for (var child = node.firstChild; child; child = child.nextSibling) {
|
||||
switch (child.nodeType) {
|
||||
case 1:
|
||||
obj = this.readNode(child);
|
||||
if (obj.property) {
|
||||
expressions.push(obj.property);
|
||||
} else if (goog.isDef(obj.value)) {
|
||||
expressions.push(obj.value);
|
||||
}
|
||||
break;
|
||||
case 3: // text node
|
||||
case 4: // cdata section
|
||||
value = goog.string.trim(child.nodeValue);
|
||||
// no need to concatenate empty strings
|
||||
if (value) {
|
||||
// check for numeric values
|
||||
numValue = goog.string.toNumber(value);
|
||||
if (!isNaN(numValue)) {
|
||||
value = numValue;
|
||||
}
|
||||
expressions.push(new ol.expr.Literal(value));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if we have more than one property or literal, we concatenate them
|
||||
var num = expressions.length;
|
||||
if (num === 1) {
|
||||
expr = expressions[0];
|
||||
} else {
|
||||
expr = new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.CONCAT),
|
||||
expressions);
|
||||
}
|
||||
return expr;
|
||||
},
|
||||
'Filter': function(node, obj) {
|
||||
var container = {
|
||||
filters: []
|
||||
};
|
||||
this.readChildNodes(node, container);
|
||||
if (goog.isDef(container.fids)) {
|
||||
obj.filter = new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.FID),
|
||||
goog.object.getValues(container.fids));
|
||||
} else if (container.filters.length > 0) {
|
||||
obj.filter = container.filters[0];
|
||||
}
|
||||
},
|
||||
'FeatureId': function(node, obj) {
|
||||
var fid = node.getAttribute('fid');
|
||||
if (fid) {
|
||||
if (!goog.isDef(obj.fids)) {
|
||||
obj.fids = {};
|
||||
}
|
||||
if (!obj.fids.hasOwnProperty(fid)) {
|
||||
obj.fids[fid] = new ol.expr.Literal(fid);
|
||||
}
|
||||
}
|
||||
},
|
||||
'And': function(node, obj) {
|
||||
var container = {filters: []};
|
||||
this.readChildNodes(node, container);
|
||||
var filter = this.aggregateLogical_(container.filters,
|
||||
ol.expr.LogicalOp.AND);
|
||||
obj.filters.push(filter);
|
||||
},
|
||||
'Or': function(node, obj) {
|
||||
var container = {filters: []};
|
||||
this.readChildNodes(node, container);
|
||||
var filter = this.aggregateLogical_(container.filters,
|
||||
ol.expr.LogicalOp.OR);
|
||||
obj.filters.push(filter);
|
||||
},
|
||||
'Not': function(node, obj) {
|
||||
var container = {filters: []};
|
||||
this.readChildNodes(node, container);
|
||||
// Not is unary so can only contain 1 child filter
|
||||
obj.filters.push(new ol.expr.Not(
|
||||
container.filters[0]));
|
||||
},
|
||||
'PropertyIsNull': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.EQ,
|
||||
container.property,
|
||||
new ol.expr.Literal(null)));
|
||||
},
|
||||
'PropertyIsLessThan': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.LT,
|
||||
container.property,
|
||||
container.value));
|
||||
},
|
||||
'PropertyIsGreaterThan': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.GT,
|
||||
container.property,
|
||||
container.value));
|
||||
},
|
||||
'PropertyIsLessThanOrEqualTo': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.LTE,
|
||||
container.property,
|
||||
container.value));
|
||||
},
|
||||
'PropertyIsGreaterThanOrEqualTo': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.GTE,
|
||||
container.property,
|
||||
container.value));
|
||||
},
|
||||
'PropertyIsBetween': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Logical(ol.expr.LogicalOp.AND,
|
||||
new ol.expr.Comparison(ol.expr.ComparisonOp.GTE,
|
||||
container.property, container.lowerBoundary),
|
||||
new ol.expr.Comparison(ol.expr.ComparisonOp.LTE,
|
||||
container.property, container.upperBoundary)));
|
||||
},
|
||||
'Literal': function(node, obj) {
|
||||
var nodeValue = this.getChildValue(node);
|
||||
var value = goog.string.toNumber(nodeValue);
|
||||
obj.value = new ol.expr.Literal(isNaN(value) ? nodeValue : value);
|
||||
},
|
||||
'PropertyName': function(node, obj) {
|
||||
obj.property = new ol.expr.Identifier(this.getChildValue(node));
|
||||
},
|
||||
'LowerBoundary': function(node, obj) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
obj.lowerBoundary = readers._expression.call(this, node);
|
||||
},
|
||||
'UpperBoundary': function(node, obj) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
obj.upperBoundary = readers._expression.call(this, node);
|
||||
},
|
||||
_spatial: function(node, obj, identifier) {
|
||||
var args = [], container = {};
|
||||
this.readChildNodes(node, container);
|
||||
if (goog.isDef(container.geometry)) {
|
||||
args.push(new ol.expr.Literal(this.gmlParser_.createGeometry(
|
||||
container)));
|
||||
} else {
|
||||
args = [new ol.expr.Literal(container.bounds[0]),
|
||||
new ol.expr.Literal(container.bounds[1]),
|
||||
new ol.expr.Literal(container.bounds[2]),
|
||||
new ol.expr.Literal(container.bounds[3])];
|
||||
}
|
||||
if (goog.isDef(container.distance)) {
|
||||
args.push(container.distance);
|
||||
}
|
||||
if (goog.isDef(container.distanceUnits)) {
|
||||
args.push(container.distanceUnits);
|
||||
}
|
||||
args.push(new ol.expr.Literal(container.projection));
|
||||
if (goog.isDef(container.property)) {
|
||||
args.push(container.property);
|
||||
}
|
||||
obj.filters.push(new ol.expr.Call(new ol.expr.Identifier(
|
||||
identifier), args));
|
||||
},
|
||||
'BBOX': function(node, obj) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
readers._spatial.call(this, node, obj,
|
||||
ol.expr.functions.EXTENT);
|
||||
},
|
||||
'Intersects': function(node, obj) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
readers._spatial.call(this, node, obj,
|
||||
ol.expr.functions.INTERSECTS);
|
||||
},
|
||||
'Within': function(node, obj) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
readers._spatial.call(this, node, obj,
|
||||
ol.expr.functions.WITHIN);
|
||||
},
|
||||
'Contains': function(node, obj) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
readers._spatial.call(this, node, obj,
|
||||
ol.expr.functions.CONTAINS);
|
||||
},
|
||||
'DWithin': function(node, obj) {
|
||||
var readers = this.readers[this.defaultNamespaceURI];
|
||||
readers._spatial.call(this, node, obj,
|
||||
ol.expr.functions.DWITHIN);
|
||||
},
|
||||
'Distance': function(node, obj) {
|
||||
var value = goog.string.toNumber(this.getChildValue(node));
|
||||
obj.distance = new ol.expr.Literal(value);
|
||||
obj.distanceUnits = new ol.expr.Literal(node.getAttribute('units'));
|
||||
}
|
||||
}
|
||||
};
|
||||
this.writers = {
|
||||
'http://www.opengis.net/ogc': {
|
||||
'Filter': function(filter) {
|
||||
var node = this.createElementNS('ogc:Filter');
|
||||
this.writeNode(this.getFilterType_(filter), filter, null, node);
|
||||
return node;
|
||||
},
|
||||
'_featureIds': function(filter) {
|
||||
var node = this.createDocumentFragment();
|
||||
var args = filter.getArgs();
|
||||
for (var i = 0, ii = args.length; i < ii; i++) {
|
||||
goog.asserts.assert(args[i] instanceof ol.expr.Literal);
|
||||
this.writeNode('FeatureId', args[i].getValue(), null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'FeatureId': function(fid) {
|
||||
var node = this.createElementNS('ogc:FeatureId');
|
||||
node.setAttribute('fid', fid);
|
||||
return node;
|
||||
},
|
||||
'And': function(filter) {
|
||||
var node = this.createElementNS('ogc:And');
|
||||
var subFilters = [];
|
||||
this.getSubfiltersForLogical_(filter, subFilters);
|
||||
for (var i = 0, ii = subFilters.length; i < ii; ++i) {
|
||||
var subFilter = subFilters[i];
|
||||
if (goog.isDefAndNotNull(subFilter)) {
|
||||
this.writeNode(this.getFilterType_(subFilter), subFilter,
|
||||
null, node);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'Or': function(filter) {
|
||||
var node = this.createElementNS('ogc:Or');
|
||||
var subFilters = [];
|
||||
this.getSubfiltersForLogical_(filter, subFilters);
|
||||
for (var i = 0, ii = subFilters.length; i < ii; ++i) {
|
||||
var subFilter = subFilters[i];
|
||||
if (goog.isDefAndNotNull(subFilter)) {
|
||||
this.writeNode(this.getFilterType_(subFilter), subFilter,
|
||||
null, node);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'Not': function(filter) {
|
||||
var node = this.createElementNS('ogc:Not');
|
||||
var childFilter = filter.getArgument();
|
||||
this.writeNode(this.getFilterType_(childFilter), childFilter, null,
|
||||
node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsLessThan': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsLessThan');
|
||||
this.writeNode('PropertyName', filter.getLeft(), null, node);
|
||||
this.writeOgcExpression(filter.getRight(), node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsGreaterThan': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsGreaterThan');
|
||||
this.writeNode('PropertyName', filter.getLeft(), null, node);
|
||||
this.writeOgcExpression(filter.getRight(), node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsLessThanOrEqualTo': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsLessThanOrEqualTo');
|
||||
this.writeNode('PropertyName', filter.getLeft(), null, node);
|
||||
this.writeOgcExpression(filter.getRight(), node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsGreaterThanOrEqualTo': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsGreaterThanOrEqualTo');
|
||||
this.writeNode('PropertyName', filter.getLeft(), null, node);
|
||||
this.writeOgcExpression(filter.getRight(), node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsBetween': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsBetween');
|
||||
var property = filter.getLeft().getLeft();
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
var lower, upper;
|
||||
var filters = new Array(2);
|
||||
filters[0] = filter.getLeft();
|
||||
filters[1] = filter.getRight();
|
||||
for (var i = 0; i < 2; ++i) {
|
||||
var expr = filters[i].getRight();
|
||||
if (filters[i].getOperator() === ol.expr.ComparisonOp.GTE) {
|
||||
lower = expr;
|
||||
} else if (filters[i].getOperator() === ol.expr.ComparisonOp.LTE) {
|
||||
upper = expr;
|
||||
}
|
||||
}
|
||||
this.writeNode('LowerBoundary', lower, null, node);
|
||||
this.writeNode('UpperBoundary', upper, null, node);
|
||||
return node;
|
||||
},
|
||||
'PropertyName': function(expr) {
|
||||
goog.asserts.assert(expr instanceof ol.expr.Identifier);
|
||||
var node = this.createElementNS('ogc:PropertyName');
|
||||
node.appendChild(this.createTextNode(expr.getName()));
|
||||
return node;
|
||||
},
|
||||
'Literal': function(expr) {
|
||||
goog.asserts.assert(expr instanceof ol.expr.Literal);
|
||||
var node = this.createElementNS('ogc:Literal');
|
||||
node.appendChild(this.createTextNode(expr.getValue()));
|
||||
return node;
|
||||
},
|
||||
'LowerBoundary': function(expr) {
|
||||
var node = this.createElementNS('ogc:LowerBoundary');
|
||||
this.writeOgcExpression(expr, node);
|
||||
return node;
|
||||
},
|
||||
'UpperBoundary': function(expr) {
|
||||
var node = this.createElementNS('ogc:UpperBoundary');
|
||||
this.writeOgcExpression(expr, node);
|
||||
return node;
|
||||
},
|
||||
'INTERSECTS': function(filter) {
|
||||
return this.writeSpatial_(filter, 'Intersects');
|
||||
},
|
||||
'WITHIN': function(filter) {
|
||||
return this.writeSpatial_(filter, 'Within');
|
||||
},
|
||||
'CONTAINS': function(filter) {
|
||||
return this.writeSpatial_(filter, 'Contains');
|
||||
},
|
||||
'DWITHIN': function(filter) {
|
||||
var node = this.writeSpatial_(filter, 'DWithin');
|
||||
this.writeNode('Distance', filter, null, node);
|
||||
return node;
|
||||
},
|
||||
'Distance': function(filter) {
|
||||
var node = this.createElementNS('ogc:Distance');
|
||||
var args = filter.getArgs();
|
||||
goog.asserts.assert(args[2] instanceof ol.expr.Literal);
|
||||
node.setAttribute('units', args[2].getValue());
|
||||
goog.asserts.assert(args[1] instanceof ol.expr.Literal);
|
||||
node.appendChild(this.createTextNode(args[1].getValue()));
|
||||
return node;
|
||||
},
|
||||
'Function': function(filter) {
|
||||
var node = this.createElementNS('ogc:Function');
|
||||
node.setAttribute('name', filter.getCallee().getName());
|
||||
var params = filter.getArgs();
|
||||
for (var i = 0, len = params.length; i < len; i++) {
|
||||
this.writeOgcExpression(params[i], node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'PropertyIsNull': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsNull');
|
||||
this.writeNode('PropertyName', filter.getLeft(), null, node);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
};
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.Filter_v1, ol.parser.XML);
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.filterMap_ = {
|
||||
'&&': 'And',
|
||||
'||': 'Or',
|
||||
'!': 'Not',
|
||||
'==': 'PropertyIsEqualTo',
|
||||
'!=': 'PropertyIsNotEqualTo',
|
||||
'<': 'PropertyIsLessThan',
|
||||
'>': 'PropertyIsGreaterThan',
|
||||
'<=': 'PropertyIsLessThanOrEqualTo',
|
||||
'>=': 'PropertyIsGreaterThanOrEqualTo',
|
||||
'..': 'PropertyIsBetween',
|
||||
'like': 'PropertyIsLike',
|
||||
'null': 'PropertyIsNull',
|
||||
'extent': 'BBOX',
|
||||
'dwithin': 'DWITHIN',
|
||||
'within': 'WITHIN',
|
||||
'contains': 'CONTAINS',
|
||||
'intersects': 'INTERSECTS',
|
||||
'fid': '_featureIds',
|
||||
'ieq': 'PropertyIsEqualTo',
|
||||
'ineq': 'PropertyIsNotEqualTo'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.expr.Expression} filter The filter to determine the type of.
|
||||
* @return {string} The type of filter.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.getFilterType_ = function(filter) {
|
||||
var type;
|
||||
if (filter instanceof ol.expr.Logical ||
|
||||
filter instanceof ol.expr.Comparison) {
|
||||
type = filter.getOperator();
|
||||
var left = filter.getLeft();
|
||||
var right = filter.getRight();
|
||||
var isNull = (type === ol.expr.ComparisonOp.EQ &&
|
||||
right instanceof ol.expr.Literal && right.getValue() === null);
|
||||
if (isNull) {
|
||||
type = 'null';
|
||||
}
|
||||
var isBetween = (type === ol.expr.LogicalOp.AND &&
|
||||
left instanceof ol.expr.Comparison &&
|
||||
right instanceof ol.expr.Comparison &&
|
||||
left.getLeft() instanceof ol.expr.Identifier &&
|
||||
right.getLeft() instanceof ol.expr.Identifier &&
|
||||
left.getLeft().getName() === right.getLeft().getName() &&
|
||||
(left.getOperator() === ol.expr.ComparisonOp.LTE ||
|
||||
left.getOperator() === ol.expr.ComparisonOp.GTE) &&
|
||||
(right.getOperator() === ol.expr.ComparisonOp.LTE ||
|
||||
right.getOperator() === ol.expr.ComparisonOp.GTE));
|
||||
if (isBetween) {
|
||||
type = '..';
|
||||
}
|
||||
} else if (filter instanceof ol.expr.Call) {
|
||||
var callee = filter.getCallee();
|
||||
goog.asserts.assert(callee instanceof ol.expr.Identifier);
|
||||
type = callee.getName();
|
||||
} else if (filter instanceof ol.expr.Not) {
|
||||
type = '!';
|
||||
}
|
||||
var filterType = ol.parser.ogc.Filter_v1.filterMap_[type];
|
||||
if (!filterType) {
|
||||
throw new Error('Filter writing not supported for rule type: ' + type);
|
||||
}
|
||||
return filterType;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|Document|Element} data Data to read.
|
||||
* @return {Object} An object representing the document.
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.read = function(data) {
|
||||
if (goog.isString(data)) {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
if (data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var obj = {};
|
||||
this.readNode(data, obj);
|
||||
return obj.filter;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.expr.Expression} filter The filter to write out.
|
||||
* @return {string} The serialized filter.
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.write = function(filter) {
|
||||
var root = this.writeNode('Filter', filter);
|
||||
this.setAttributeNS(
|
||||
root, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation', this.schemaLocation);
|
||||
return this.serialize(root);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.expr.Expression} expr The value write out.
|
||||
* @param {Element} node The node to append to.
|
||||
* @return {Element} The node to which was appended.
|
||||
* @protected
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.writeOgcExpression = function(expr, node) {
|
||||
if (expr instanceof ol.expr.Call) {
|
||||
if (ol.expr.isLibCall(expr) === ol.expr.functions.CONCAT) {
|
||||
var args = expr.getArgs();
|
||||
for (var i = 0, ii = args.length; i < ii; ++i) {
|
||||
this.writeOgcExpression(args[i], node);
|
||||
}
|
||||
} else {
|
||||
this.writeNode('Function', expr, null, node);
|
||||
}
|
||||
} else if (expr instanceof ol.expr.Literal) {
|
||||
this.writeNode('Literal', expr, null, node);
|
||||
} else if (expr instanceof ol.expr.Identifier) {
|
||||
this.writeNode('PropertyName', expr, null, node);
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.expr.Logical} filter The filter to retrieve the sub filters from.
|
||||
* @param {Array.<ol.expr.Expression>} subFilters The sub filters retrieved.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.getSubfiltersForLogical_ = function(filter,
|
||||
subFilters) {
|
||||
var operator = filter.getOperator();
|
||||
var filters = new Array(2);
|
||||
filters[0] = filter.getLeft();
|
||||
filters[1] = filter.getRight();
|
||||
for (var i = 0; i < 2; ++i) {
|
||||
if (filters[i] instanceof ol.expr.Logical && filters[i].getOperator() ===
|
||||
operator) {
|
||||
this.getSubfiltersForLogical_(filters[i], subFilters);
|
||||
} else {
|
||||
subFilters.push(filters[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Since ol.expr.Logical can only have a left and a right, we need to nest
|
||||
* sub filters coming from OGC Filter.
|
||||
* @param {Array.<ol.expr.Expression>} filters The filters to aggregate.
|
||||
* @param {ol.expr.LogicalOp} operator The logical operator to use.
|
||||
* @return {ol.expr.Logical} The logical filter created.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.aggregateLogical_ = function(filters,
|
||||
operator) {
|
||||
var subFilters = [];
|
||||
var newFilters = [];
|
||||
// we only need to do this if we have more than 2 items
|
||||
if (filters.length > 2) {
|
||||
while (filters.length) {
|
||||
subFilters.push(filters.pop());
|
||||
if (subFilters.length === 2) {
|
||||
newFilters.push(new ol.expr.Logical(operator,
|
||||
subFilters[0], subFilters[1]));
|
||||
subFilters.length = 0;
|
||||
}
|
||||
}
|
||||
// there could be a single item left now
|
||||
if (subFilters.length === 1) {
|
||||
newFilters.push(subFilters[0]);
|
||||
}
|
||||
return this.aggregateLogical_(newFilters, operator);
|
||||
} else {
|
||||
return new ol.expr.Logical(operator, filters[0], filters[1]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.parser.ogc.GML_v2|ol.parser.ogc.GML_v3}
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.getGmlParser = function() {
|
||||
return this.gmlParser_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.parser.ogc.GML_v2|ol.parser.ogc.GML_v3} gml The GML parser to
|
||||
* use.
|
||||
* @protected
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.setGmlParser = function(gml) {
|
||||
this.gmlParser_ = gml;
|
||||
if (this.featureNS) {
|
||||
gml.setFeatureNS(this.featureNS);
|
||||
}
|
||||
for (var uri in this.gmlParser_.readers) {
|
||||
for (var key in this.gmlParser_.readers[uri]) {
|
||||
if (!goog.isDef(this.readers[uri])) {
|
||||
this.readers[uri] = {};
|
||||
}
|
||||
this.readers[uri][key] = goog.bind(this.gmlParser_.readers[uri][key],
|
||||
this.gmlParser_);
|
||||
}
|
||||
}
|
||||
for (uri in this.gmlParser_.writers) {
|
||||
for (key in this.gmlParser_.writers[uri]) {
|
||||
if (!goog.isDef(this.writers[uri])) {
|
||||
this.writers[uri] = {};
|
||||
}
|
||||
this.writers[uri][key] = goog.bind(this.gmlParser_.writers[uri][key],
|
||||
this.gmlParser_);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} featureNS Feature namespace.
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.setFeatureNS = function(featureNS) {
|
||||
this.featureNS = featureNS;
|
||||
if (goog.isDefAndNotNull(this.gmlParser_)) {
|
||||
this.setGmlParser(this.gmlParser_);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} featureType Feature type.
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.setFeatureType = function(featureType) {
|
||||
this.featureType = featureType;
|
||||
if (goog.isDefAndNotNull(this.gmlParser_)) {
|
||||
this.gmlParser_.featureType = featureType;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} srsName SRS name.
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1.prototype.setSrsName = function(srsName) {
|
||||
this.srsName = srsName;
|
||||
if (goog.isDefAndNotNull(this.gmlParser_)) {
|
||||
this.gmlParser_.applyWriteOptions({},
|
||||
/** @type {olx.parser.GMLWriteOptions} */ ({srsName: srsName}));
|
||||
}
|
||||
};
|
||||
@@ -1,185 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.Filter_v1_0_0');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.functions');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.parser.ogc.Filter_v1');
|
||||
goog.require('ol.parser.ogc.GML_v2');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.ogc.Filter_v1}
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1_0_0 = function() {
|
||||
goog.base(this);
|
||||
this.version = '1.0.0';
|
||||
this.schemaLocation = 'http://www.opengis.net/ogc ' +
|
||||
'http://schemas.opengis.net/filter/1.0.0/filter.xsd';
|
||||
goog.object.extend(this.readers['http://www.opengis.net/ogc'], {
|
||||
'PropertyIsEqualTo': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.EQ,
|
||||
container.property,
|
||||
container.value));
|
||||
},
|
||||
'PropertyIsNotEqualTo': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
obj.filters.push(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.NEQ,
|
||||
container.property,
|
||||
container.value));
|
||||
},
|
||||
'PropertyIsLike': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
var args = [];
|
||||
args.push(container.property, container.value,
|
||||
new ol.expr.Literal(node.getAttribute('wildCard')),
|
||||
new ol.expr.Literal(node.getAttribute('singleChar')),
|
||||
new ol.expr.Literal(node.getAttribute('escape')));
|
||||
obj.filters.push(new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.LIKE), args));
|
||||
}
|
||||
});
|
||||
goog.object.extend(this.writers['http://www.opengis.net/ogc'], {
|
||||
'PropertyIsEqualTo': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsEqualTo');
|
||||
var property = filter.getLeft();
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
this.writeOgcExpression(filter.getRight(), node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsNotEqualTo': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsNotEqualTo');
|
||||
var property = filter.getLeft();
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
this.writeOgcExpression(filter.getRight(), node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsLike': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsLike');
|
||||
var args = filter.getArgs();
|
||||
goog.asserts.assert(args[2] instanceof ol.expr.Literal);
|
||||
node.setAttribute('wildCard', args[2].getValue());
|
||||
goog.asserts.assert(args[3] instanceof ol.expr.Literal);
|
||||
node.setAttribute('singleChar', args[3].getValue());
|
||||
goog.asserts.assert(args[4] instanceof ol.expr.Literal);
|
||||
node.setAttribute('escape', args[4].getValue());
|
||||
var property = args[0];
|
||||
if (goog.isDef(property)) {
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
}
|
||||
this.writeNode('Literal', args[1], null, node);
|
||||
return node;
|
||||
},
|
||||
'BBOX': function(filter) {
|
||||
var node = this.createElementNS('ogc:BBOX');
|
||||
var args = filter.getArgs();
|
||||
goog.asserts.assert(args[0] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[1] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[2] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[3] instanceof ol.expr.Literal);
|
||||
var bbox = [
|
||||
args[0].getValue(), args[1].getValue(),
|
||||
args[2].getValue(), args[3].getValue()
|
||||
];
|
||||
var projection;
|
||||
if (args[4] instanceof ol.expr.Literal) {
|
||||
projection = args[4].getValue();
|
||||
}
|
||||
var property = args[5];
|
||||
// PropertyName is mandatory in 1.0.0, but e.g. GeoServer also
|
||||
// accepts filters without it.
|
||||
if (goog.isDefAndNotNull(property)) {
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
}
|
||||
var box = this.writeNode('Box', bbox,
|
||||
'http://www.opengis.net/gml');
|
||||
if (goog.isDefAndNotNull(projection)) {
|
||||
box.setAttribute('srsName', projection);
|
||||
}
|
||||
node.appendChild(box);
|
||||
return node;
|
||||
}
|
||||
});
|
||||
this.setGmlParser(new ol.parser.ogc.GML_v2());
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.Filter_v1_0_0,
|
||||
ol.parser.ogc.Filter_v1);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.expr.Call} filter The filter to write out.
|
||||
* @param {string} name The name of the spatial operator.
|
||||
* @return {Element} The node created.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1_0_0.prototype.writeSpatial_ = function(filter, name) {
|
||||
var node = this.createElementNS('ogc:' + name);
|
||||
var args = filter.getArgs();
|
||||
var property, geom = null, bbox, call, projection;
|
||||
if (args[0] instanceof ol.expr.Literal && goog.isNumber(args[0].getValue())) {
|
||||
goog.asserts.assert(args[1] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[2] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[3] instanceof ol.expr.Literal);
|
||||
bbox = [
|
||||
args[0].getValue(), args[1].getValue(),
|
||||
args[2].getValue(), args[3].getValue()
|
||||
];
|
||||
projection = args[4];
|
||||
property = args[5];
|
||||
} else if (args[0] instanceof ol.expr.Literal &&
|
||||
args[0].getValue() instanceof ol.geom.Geometry) {
|
||||
geom = args[0].getValue();
|
||||
if (name === 'DWithin') {
|
||||
projection = args[3];
|
||||
property = args[4];
|
||||
} else {
|
||||
projection = args[1];
|
||||
property = args[2];
|
||||
}
|
||||
} else if (args[0] instanceof ol.expr.Call) {
|
||||
call = args[0];
|
||||
if (name === 'DWithin') {
|
||||
projection = args[3];
|
||||
property = args[4];
|
||||
} else {
|
||||
projection = args[1];
|
||||
property = args[2];
|
||||
}
|
||||
}
|
||||
if (goog.isDefAndNotNull(property)) {
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
}
|
||||
if (goog.isDef(call)) {
|
||||
this.writeNode('Function', call, null, node);
|
||||
} else {
|
||||
var child;
|
||||
if (geom !== null) {
|
||||
child = this.gmlParser_.writeGeometry(geom);
|
||||
} else if (bbox.length === 4) {
|
||||
child = this.writeNode('Box', bbox,
|
||||
'http://www.opengis.net/gml');
|
||||
}
|
||||
if (goog.isDef(child)) {
|
||||
goog.asserts.assert(projection instanceof ol.expr.Literal);
|
||||
if (goog.isDefAndNotNull(projection.getValue())) {
|
||||
child.setAttribute('srsName', projection.getValue());
|
||||
}
|
||||
node.appendChild(child);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
};
|
||||
@@ -1,242 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.Filter_v1_1_0');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.functions');
|
||||
goog.require('ol.geom.Geometry');
|
||||
goog.require('ol.parser.ogc.Filter_v1');
|
||||
goog.require('ol.parser.ogc.GML_v3');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.ogc.Filter_v1}
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1_1_0 = function() {
|
||||
goog.base(this);
|
||||
this.version = '1.1.0';
|
||||
this.schemaLocation = 'http://www.opengis.net/ogc ' +
|
||||
'http://schemas.opengis.net/filter/1.1.0/filter.xsd';
|
||||
goog.object.extend(this.readers['http://www.opengis.net/ogc'], {
|
||||
'PropertyIsEqualTo': function(node, obj) {
|
||||
var matchCase = node.getAttribute('matchCase');
|
||||
var container = {}, filter;
|
||||
this.readChildNodes(node, container);
|
||||
if (matchCase === 'false' || matchCase === '0') {
|
||||
filter = new ol.expr.Call(new ol.expr.Identifier(ol.expr.functions.IEQ),
|
||||
[container.property, container.value]);
|
||||
} else {
|
||||
filter = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.EQ,
|
||||
container.property,
|
||||
container.value);
|
||||
}
|
||||
obj.filters.push(filter);
|
||||
},
|
||||
'PropertyIsNotEqualTo': function(node, obj) {
|
||||
var matchCase = node.getAttribute('matchCase');
|
||||
var container = {}, filter;
|
||||
this.readChildNodes(node, container);
|
||||
if (matchCase === 'false' || matchCase === '0') {
|
||||
filter = new ol.expr.Call(new ol.expr.Identifier(
|
||||
ol.expr.functions.INEQ),
|
||||
[container.property, container.value]);
|
||||
} else {
|
||||
filter = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.NEQ,
|
||||
container.property,
|
||||
container.value);
|
||||
}
|
||||
obj.filters.push(filter);
|
||||
},
|
||||
'PropertyIsLike': function(node, obj) {
|
||||
var container = {};
|
||||
this.readChildNodes(node, container);
|
||||
var args = [];
|
||||
args.push(container.property, container.value,
|
||||
new ol.expr.Literal(node.getAttribute('wildCard')),
|
||||
new ol.expr.Literal(node.getAttribute('singleChar')),
|
||||
new ol.expr.Literal(node.getAttribute('escapeChar')),
|
||||
new ol.expr.Literal(node.getAttribute('matchCase')));
|
||||
obj.filters.push(new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.LIKE), args));
|
||||
}
|
||||
});
|
||||
goog.object.extend(this.writers['http://www.opengis.net/ogc'], {
|
||||
'PropertyIsEqualTo': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsEqualTo');
|
||||
var property, value;
|
||||
if (filter instanceof ol.expr.Call) {
|
||||
var args = filter.getArgs();
|
||||
property = args[0];
|
||||
value = args[1];
|
||||
node.setAttribute('matchCase', false);
|
||||
} else {
|
||||
property = filter.getLeft();
|
||||
value = filter.getRight();
|
||||
}
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
this.writeOgcExpression(value, node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsNotEqualTo': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsNotEqualTo');
|
||||
var property, value;
|
||||
if (filter instanceof ol.expr.Call) {
|
||||
var args = filter.getArgs();
|
||||
property = args[0];
|
||||
value = args[1];
|
||||
node.setAttribute('matchCase', false);
|
||||
} else {
|
||||
property = filter.getLeft();
|
||||
value = filter.getRight();
|
||||
}
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
this.writeOgcExpression(value, node);
|
||||
return node;
|
||||
},
|
||||
'PropertyIsLike': function(filter) {
|
||||
var node = this.createElementNS('ogc:PropertyIsLike');
|
||||
var args = filter.getArgs();
|
||||
goog.asserts.assert(args[2] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[3] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[4] instanceof ol.expr.Literal);
|
||||
node.setAttribute('wildCard', args[2].getValue());
|
||||
node.setAttribute('singleChar', args[3].getValue());
|
||||
node.setAttribute('escapeChar', args[4].getValue());
|
||||
if (goog.isDefAndNotNull(args[5])) {
|
||||
goog.asserts.assert(args[5] instanceof ol.expr.Literal);
|
||||
node.setAttribute('matchCase', args[5].getValue());
|
||||
}
|
||||
var property = args[0];
|
||||
if (goog.isDef(property)) {
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
}
|
||||
this.writeNode('Literal', args[1], null, node);
|
||||
return node;
|
||||
},
|
||||
'BBOX': function(filter) {
|
||||
var node = this.createElementNS('ogc:BBOX');
|
||||
var args = filter.getArgs();
|
||||
goog.asserts.assert(args[0] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[1] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[2] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[3] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[4] instanceof ol.expr.Literal);
|
||||
var bbox = [
|
||||
args[0].getValue(), args[1].getValue(),
|
||||
args[2].getValue(), args[3].getValue()
|
||||
];
|
||||
var projection = args[4].getValue();
|
||||
var property = args[5];
|
||||
// PropertyName is optional in 1.1.0
|
||||
if (goog.isDefAndNotNull(property)) {
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
}
|
||||
var box = this.writeNode('Envelope', bbox,
|
||||
'http://www.opengis.net/gml');
|
||||
if (goog.isDefAndNotNull(projection)) {
|
||||
box.setAttribute('srsName', projection);
|
||||
}
|
||||
node.appendChild(box);
|
||||
return node;
|
||||
},
|
||||
'SortBy': function(sortProperties) {
|
||||
var node = this.createElementNS('ogc:SortBy');
|
||||
for (var i = 0, l = sortProperties.length; i < l; i++) {
|
||||
this.writeNode('SortProperty', sortProperties[i], null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'SortProperty': function(sortProperty) {
|
||||
var node = this.createElementNS('ogc:SortProperty');
|
||||
this.writeNode('PropertyName', sortProperty['property'], null, node);
|
||||
goog.asserts.assert(sortProperty['order'] instanceof ol.expr.Literal);
|
||||
this.writeNode('SortOrder',
|
||||
(sortProperty['order'].getValue() == 'DESC') ? 'DESC' : 'ASC', null,
|
||||
node);
|
||||
return node;
|
||||
},
|
||||
'SortOrder': function(value) {
|
||||
var node = this.createElementNS('ogc:SortOrder');
|
||||
node.appendChild(this.createTextNode(value));
|
||||
return node;
|
||||
}
|
||||
});
|
||||
this.setGmlParser(new ol.parser.ogc.GML_v3());
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.Filter_v1_1_0,
|
||||
ol.parser.ogc.Filter_v1);
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.expr.Call} filter The filter to write out.
|
||||
* @param {string} name The name of the spatial operator.
|
||||
* @return {Element} The node created.
|
||||
* @private
|
||||
*/
|
||||
ol.parser.ogc.Filter_v1_1_0.prototype.writeSpatial_ = function(filter, name) {
|
||||
var node = this.createElementNS('ogc:' + name);
|
||||
var args = filter.getArgs();
|
||||
var property, geom = null, bbox, call, projection;
|
||||
if (args[0] instanceof ol.expr.Literal && goog.isNumber(args[0].getValue())) {
|
||||
goog.asserts.assert(args[1] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[2] instanceof ol.expr.Literal);
|
||||
goog.asserts.assert(args[3] instanceof ol.expr.Literal);
|
||||
bbox = [
|
||||
args[0].getValue(), args[1].getValue(),
|
||||
args[2].getValue(), args[3].getValue()
|
||||
];
|
||||
projection = args[4];
|
||||
property = args[5];
|
||||
} else if (args[0] instanceof ol.expr.Literal &&
|
||||
args[0].getValue() instanceof ol.geom.Geometry) {
|
||||
geom = args[0].getValue();
|
||||
if (name === 'DWithin') {
|
||||
projection = args[3];
|
||||
property = args[4];
|
||||
} else {
|
||||
projection = args[1];
|
||||
property = args[2];
|
||||
}
|
||||
} else if (args[0] instanceof ol.expr.Call) {
|
||||
call = args[0];
|
||||
if (name === 'DWithin') {
|
||||
projection = args[3];
|
||||
property = args[4];
|
||||
} else {
|
||||
projection = args[1];
|
||||
property = args[2];
|
||||
}
|
||||
}
|
||||
if (goog.isDefAndNotNull(property)) {
|
||||
this.writeNode('PropertyName', property, null, node);
|
||||
}
|
||||
if (goog.isDef(call)) {
|
||||
this.writeNode('Function', call, null, node);
|
||||
} else {
|
||||
var child;
|
||||
if (geom !== null) {
|
||||
child = this.writeNode('_geometry', {value: geom},
|
||||
this.gmlParser_.featureNS).firstChild;
|
||||
} else if (bbox.length === 4) {
|
||||
child = this.writeNode('Envelope', bbox,
|
||||
'http://www.opengis.net/gml');
|
||||
}
|
||||
if (goog.isDef(child)) {
|
||||
goog.asserts.assert(projection instanceof ol.expr.Literal);
|
||||
if (goog.isDefAndNotNull(projection.getValue())) {
|
||||
child.setAttribute('srsName', projection.getValue());
|
||||
}
|
||||
node.appendChild(child);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
};
|
||||
@@ -1,214 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.OWSCommon_v1');
|
||||
goog.require('ol.parser.XML');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.XML}
|
||||
*/
|
||||
ol.parser.ogc.OWSCommon_v1 = function() {
|
||||
this.readers = {
|
||||
'http://www.opengis.net/ows': {
|
||||
'ServiceIdentification': function(node, obj) {
|
||||
obj['serviceIdentification'] = {};
|
||||
this.readChildNodes(node, obj['serviceIdentification']);
|
||||
},
|
||||
'Title': function(node, obj) {
|
||||
obj['title'] = this.getChildValue(node);
|
||||
},
|
||||
'Abstract': function(node, serviceIdentification) {
|
||||
serviceIdentification['abstract'] = this.getChildValue(node);
|
||||
},
|
||||
'Keywords': function(node, serviceIdentification) {
|
||||
serviceIdentification['keywords'] = {};
|
||||
this.readChildNodes(node, serviceIdentification['keywords']);
|
||||
},
|
||||
'Keyword': function(node, keywords) {
|
||||
keywords[this.getChildValue(node)] = true;
|
||||
},
|
||||
'ServiceType': function(node, serviceIdentification) {
|
||||
serviceIdentification['serviceType'] = {
|
||||
'codeSpace': node.getAttribute('codeSpace'),
|
||||
'value': this.getChildValue(node)};
|
||||
},
|
||||
'ServiceTypeVersion': function(node, serviceIdentification) {
|
||||
serviceIdentification['serviceTypeVersion'] = this.getChildValue(node);
|
||||
},
|
||||
'Fees': function(node, serviceIdentification) {
|
||||
serviceIdentification['fees'] = this.getChildValue(node);
|
||||
},
|
||||
'AccessConstraints': function(node, serviceIdentification) {
|
||||
serviceIdentification['accessConstraints'] =
|
||||
this.getChildValue(node);
|
||||
},
|
||||
'ServiceProvider': function(node, obj) {
|
||||
obj['serviceProvider'] = {};
|
||||
this.readChildNodes(node, obj['serviceProvider']);
|
||||
},
|
||||
'ProviderName': function(node, serviceProvider) {
|
||||
serviceProvider['providerName'] = this.getChildValue(node);
|
||||
},
|
||||
'ProviderSite': function(node, serviceProvider) {
|
||||
serviceProvider['providerSite'] = this.getAttributeNS(node,
|
||||
'http://www.w3.org/1999/xlink', 'href');
|
||||
},
|
||||
'ServiceContact': function(node, serviceProvider) {
|
||||
serviceProvider['serviceContact'] = {};
|
||||
this.readChildNodes(node, serviceProvider['serviceContact']);
|
||||
},
|
||||
'IndividualName': function(node, serviceContact) {
|
||||
serviceContact['individualName'] = this.getChildValue(node);
|
||||
},
|
||||
'PositionName': function(node, serviceContact) {
|
||||
serviceContact['positionName'] = this.getChildValue(node);
|
||||
},
|
||||
'ContactInfo': function(node, serviceContact) {
|
||||
serviceContact['contactInfo'] = {};
|
||||
this.readChildNodes(node, serviceContact['contactInfo']);
|
||||
},
|
||||
'Phone': function(node, contactInfo) {
|
||||
contactInfo['phone'] = {};
|
||||
this.readChildNodes(node, contactInfo['phone']);
|
||||
},
|
||||
'Voice': function(node, phone) {
|
||||
phone['voice'] = this.getChildValue(node);
|
||||
},
|
||||
'Address': function(node, contactInfo) {
|
||||
contactInfo['address'] = {};
|
||||
this.readChildNodes(node, contactInfo['address']);
|
||||
},
|
||||
'DeliveryPoint': function(node, address) {
|
||||
address['deliveryPoint'] = this.getChildValue(node);
|
||||
},
|
||||
'City': function(node, address) {
|
||||
address['city'] = this.getChildValue(node);
|
||||
},
|
||||
'AdministrativeArea': function(node, address) {
|
||||
address['administrativeArea'] = this.getChildValue(node);
|
||||
},
|
||||
'PostalCode': function(node, address) {
|
||||
address['postalCode'] = this.getChildValue(node);
|
||||
},
|
||||
'Country': function(node, address) {
|
||||
address['country'] = this.getChildValue(node);
|
||||
},
|
||||
'ElectronicMailAddress': function(node, address) {
|
||||
address['electronicMailAddress'] = this.getChildValue(node);
|
||||
},
|
||||
'Role': function(node, serviceContact) {
|
||||
serviceContact['role'] = this.getChildValue(node);
|
||||
},
|
||||
'OperationsMetadata': function(node, obj) {
|
||||
obj['operationsMetadata'] = {};
|
||||
this.readChildNodes(node, obj['operationsMetadata']);
|
||||
},
|
||||
'Operation': function(node, operationsMetadata) {
|
||||
var name = node.getAttribute('name');
|
||||
operationsMetadata[name] = {};
|
||||
this.readChildNodes(node, operationsMetadata[name]);
|
||||
},
|
||||
'DCP': function(node, operation) {
|
||||
operation['dcp'] = {};
|
||||
this.readChildNodes(node, operation['dcp']);
|
||||
},
|
||||
'HTTP': function(node, dcp) {
|
||||
dcp['http'] = {};
|
||||
this.readChildNodes(node, dcp['http']);
|
||||
},
|
||||
'Get': function(node, http) {
|
||||
if (!http['get']) {
|
||||
http['get'] = [];
|
||||
}
|
||||
var obj = {
|
||||
'url': this.getAttributeNS(node, 'http://www.w3.org/1999/xlink',
|
||||
'href')
|
||||
};
|
||||
this.readChildNodes(node, obj);
|
||||
http['get'].push(obj);
|
||||
},
|
||||
'Post': function(node, http) {
|
||||
if (!http['post']) {
|
||||
http['post'] = [];
|
||||
}
|
||||
var obj = {
|
||||
'url': this.getAttributeNS(node, 'http://www.w3.org/1999/xlink',
|
||||
'href')
|
||||
};
|
||||
this.readChildNodes(node, obj);
|
||||
http['post'].push(obj);
|
||||
},
|
||||
'Parameter': function(node, operation) {
|
||||
if (!operation['parameters']) {
|
||||
operation['parameters'] = {};
|
||||
}
|
||||
var name = node.getAttribute('name');
|
||||
operation['parameters'][name] = {};
|
||||
this.readChildNodes(node, operation['parameters'][name]);
|
||||
},
|
||||
'Constraint': function(node, obj) {
|
||||
if (!obj['constraints']) {
|
||||
obj['constraints'] = {};
|
||||
}
|
||||
var name = node.getAttribute('name');
|
||||
obj['constraints'][name] = {};
|
||||
this.readChildNodes(node, obj['constraints'][name]);
|
||||
},
|
||||
'Value': function(node, allowedValues) {
|
||||
allowedValues[this.getChildValue(node)] = true;
|
||||
},
|
||||
'OutputFormat': function(node, obj) {
|
||||
obj['formats'].push({'value': this.getChildValue(node)});
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'WGS84BoundingBox': function(node, obj) {
|
||||
var boundingBox = {};
|
||||
boundingBox['crs'] = node.getAttribute('crs');
|
||||
if (obj['BoundingBox']) {
|
||||
obj['BoundingBox'].push(boundingBox);
|
||||
} else {
|
||||
obj['projection'] = boundingBox['crs'];
|
||||
boundingBox = obj;
|
||||
}
|
||||
this.readChildNodes(node, boundingBox);
|
||||
},
|
||||
'BoundingBox': function(node, obj) {
|
||||
// FIXME: We consider that BoundingBox is the same as WGS84BoundingBox
|
||||
// LowerCorner = "min_x min_y"
|
||||
// UpperCorner = "max_x max_y"
|
||||
// It should normally depend on the projection
|
||||
var readers = this.readers[node.namespaceURI];
|
||||
readers['WGS84BoundingBox'].apply(this, [node, obj]);
|
||||
},
|
||||
'LowerCorner': function(node, obj) {
|
||||
var str = this.getChildValue(node).replace(
|
||||
this.regExes.trimSpace, '');
|
||||
str = str.replace(this.regExes.trimComma, ',');
|
||||
var pointList = str.split(this.regExes.splitSpace);
|
||||
obj['left'] = pointList[0];
|
||||
obj['bottom'] = pointList[1];
|
||||
},
|
||||
'UpperCorner': function(node, obj) {
|
||||
var str = this.getChildValue(node).replace(
|
||||
this.regExes.trimSpace, '');
|
||||
str = str.replace(this.regExes.trimComma, ',');
|
||||
var pointList = str.split(this.regExes.splitSpace);
|
||||
obj['right'] = pointList[0];
|
||||
obj['top'] = pointList[1];
|
||||
obj['bounds'] = [
|
||||
parseFloat(obj['left']), parseFloat(obj['right']),
|
||||
parseFloat(obj['bottom']), parseFloat(obj['top'])
|
||||
];
|
||||
delete obj['left'];
|
||||
delete obj['bottom'];
|
||||
delete obj['right'];
|
||||
delete obj['top'];
|
||||
},
|
||||
'Language': function(node, obj) {
|
||||
obj['language'] = this.getChildValue(node);
|
||||
}
|
||||
}
|
||||
};
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.OWSCommon_v1, ol.parser.XML);
|
||||
@@ -1,45 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.OWSCommon_v1_1_0');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.parser.ogc.OWSCommon_v1');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.ogc.OWSCommon_v1}
|
||||
*/
|
||||
ol.parser.ogc.OWSCommon_v1_1_0 = function() {
|
||||
goog.base(this);
|
||||
this.readers['http://www.opengis.net/ows/1.1'] =
|
||||
this.readers['http://www.opengis.net/ows'];
|
||||
goog.object.extend(this.readers['http://www.opengis.net/ows/1.1'], {
|
||||
'AllowedValues': function(node, parameter) {
|
||||
parameter['allowedValues'] = {};
|
||||
this.readChildNodes(node, parameter['allowedValues']);
|
||||
},
|
||||
'AnyValue': function(node, parameter) {
|
||||
parameter['anyValue'] = true;
|
||||
},
|
||||
'DataType': function(node, parameter) {
|
||||
parameter['dataType'] = this.getChildValue(node);
|
||||
},
|
||||
'Range': function(node, allowedValues) {
|
||||
allowedValues['range'] = {};
|
||||
this.readChildNodes(node, allowedValues['range']);
|
||||
},
|
||||
'MinimumValue': function(node, range) {
|
||||
range['minValue'] = this.getChildValue(node);
|
||||
},
|
||||
'MaximumValue': function(node, range) {
|
||||
range['maxValue'] = this.getChildValue(node);
|
||||
},
|
||||
'Identifier': function(node, obj) {
|
||||
obj['identifier'] = this.getChildValue(node);
|
||||
},
|
||||
'SupportedCRS': function(node, obj) {
|
||||
obj['supportedCRS'] = this.getChildValue(node);
|
||||
}
|
||||
});
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.OWSCommon_v1_1_0,
|
||||
ol.parser.ogc.OWSCommon_v1);
|
||||
@@ -1,27 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.SLD');
|
||||
goog.require('ol.parser.ogc.SLD_v1_0_0');
|
||||
goog.require('ol.parser.ogc.Versioned');
|
||||
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable SLD version 1.0.0.
|
||||
*/
|
||||
ol.ENABLE_SLD_1_0_0 = true;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object=} opt_options Options which will be set on this object.
|
||||
* @extends {ol.parser.ogc.Versioned}
|
||||
*/
|
||||
ol.parser.ogc.SLD = function(opt_options) {
|
||||
opt_options = opt_options || {};
|
||||
opt_options['defaultVersion'] = '1.0.0';
|
||||
this.parsers = {};
|
||||
if (ol.ENABLE_SLD_1_0_0) {
|
||||
this.parsers['v1_0_0'] = ol.parser.ogc.SLD_v1_0_0;
|
||||
}
|
||||
goog.base(this, opt_options);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.SLD, ol.parser.ogc.Versioned);
|
||||
@@ -1,732 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.SLD_v1');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.parser.XML');
|
||||
goog.require('ol.parser.ogc.Filter_v1_0_0');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.Icon');
|
||||
goog.require('ol.style.Rule');
|
||||
goog.require('ol.style.Shape');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Style');
|
||||
goog.require('ol.style.Text');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read Styled Layer Descriptor (SLD).
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.parser.XML}
|
||||
*/
|
||||
ol.parser.ogc.SLD_v1 = function() {
|
||||
this.defaultNamespaceURI = 'http://www.opengis.net/sld';
|
||||
this.readers = {};
|
||||
this.readers[this.defaultNamespaceURI] = {
|
||||
'StyledLayerDescriptor': function(node, sld) {
|
||||
sld.version = node.getAttribute('version');
|
||||
this.readChildNodes(node, sld);
|
||||
},
|
||||
'Name': function(node, obj) {
|
||||
obj.name = this.getChildValue(node);
|
||||
},
|
||||
'Title': function(node, obj) {
|
||||
obj.title = this.getChildValue(node);
|
||||
},
|
||||
'Abstract': function(node, obj) {
|
||||
obj.description = this.getChildValue(node);
|
||||
},
|
||||
'NamedLayer': function(node, sld) {
|
||||
var layer = {
|
||||
userStyles: [],
|
||||
namedStyles: []
|
||||
};
|
||||
this.readChildNodes(node, layer);
|
||||
sld.namedLayers[layer.name] = layer;
|
||||
},
|
||||
'NamedStyle': function(node, layer) {
|
||||
layer.namedStyles.push(
|
||||
this.getChildValue(node.firstChild)
|
||||
);
|
||||
},
|
||||
'UserStyle': function(node, layer) {
|
||||
var obj = {rules: []};
|
||||
this.featureTypeCounter = -1;
|
||||
this.readChildNodes(node, obj);
|
||||
layer.userStyles.push(new ol.style.Style(obj));
|
||||
},
|
||||
'FeatureTypeStyle': function(node, style) {
|
||||
++this.featureTypeCounter;
|
||||
var obj = {
|
||||
rules: style.rules
|
||||
};
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'Rule': function(node, obj) {
|
||||
var config = {symbolizers: []};
|
||||
this.readChildNodes(node, config);
|
||||
var rule = new ol.style.Rule(config);
|
||||
obj.rules.push(rule);
|
||||
},
|
||||
'ElseFilter': function(node, rule) {
|
||||
rule.elseFilter = true;
|
||||
},
|
||||
'MinScaleDenominator': function(node, rule) {
|
||||
rule.minResolution = this.getResolutionFromScaleDenominator_(
|
||||
parseFloat(this.getChildValue(node)));
|
||||
},
|
||||
'MaxScaleDenominator': function(node, rule) {
|
||||
rule.maxResolution = this.getResolutionFromScaleDenominator_(
|
||||
parseFloat(this.getChildValue(node)));
|
||||
},
|
||||
'TextSymbolizer': function(node, rule) {
|
||||
var config = {};
|
||||
this.readChildNodes(node, config);
|
||||
config.color = goog.isDef(config.fill) ? config.fill.fillColor :
|
||||
ol.parser.ogc.SLD_v1.defaults_.fontColor;
|
||||
delete config.fill;
|
||||
config.zIndex = this.featureTypeCounter;
|
||||
rule.symbolizers.push(
|
||||
new ol.style.Text(/** @type {olx.style.TextOptions} */(config))
|
||||
);
|
||||
},
|
||||
'Label': function(node, symbolizer) {
|
||||
var ogcreaders = this.readers[this.filter_.defaultNamespaceURI];
|
||||
var value = ogcreaders._expression.call(this, node);
|
||||
if (value) {
|
||||
symbolizer.text = value;
|
||||
}
|
||||
},
|
||||
'Font': function(node, symbolizer) {
|
||||
this.readChildNodes(node, symbolizer);
|
||||
},
|
||||
'Halo': function(node, symbolizer) {
|
||||
var obj = {};
|
||||
this.readChildNodes(node, obj);
|
||||
symbolizer.stroke = new ol.style.Stroke({
|
||||
color: goog.isDef(obj.fill.fillColor) ? obj.fill.fillColor :
|
||||
ol.parser.ogc.SLD_v1.defaults_.haloColor,
|
||||
width: goog.isDef(obj.haloRadius) ? obj.haloRadius * 2 :
|
||||
ol.parser.ogc.SLD_v1.defaults_.haloRadius,
|
||||
opacity: goog.isDef(obj.fill.fillOpacity) ? obj.fill.fillOpacity :
|
||||
ol.parser.ogc.SLD_v1.defaults_.haloOpacity
|
||||
});
|
||||
},
|
||||
'Radius': function(node, symbolizer) {
|
||||
var ogcreaders = this.readers[this.filter_.defaultNamespaceURI];
|
||||
var radius = ogcreaders._expression.call(this, node);
|
||||
goog.asserts.assertInstanceof(radius, ol.expr.Literal,
|
||||
'radius expected to be an ol.expr.Literal');
|
||||
if (goog.isDef(radius)) {
|
||||
symbolizer.haloRadius = radius.getValue();
|
||||
}
|
||||
},
|
||||
'LineSymbolizer': function(node, rule) {
|
||||
var config = {};
|
||||
this.readChildNodes(node, config);
|
||||
config.zIndex = this.featureTypeCounter;
|
||||
rule.symbolizers.push(
|
||||
new ol.style.Stroke(config)
|
||||
);
|
||||
},
|
||||
'PolygonSymbolizer': function(node, rule) {
|
||||
var config = {};
|
||||
this.readChildNodes(node, config);
|
||||
config.zIndex = this.featureTypeCounter;
|
||||
if (goog.isDef(config.fill)) {
|
||||
var fill = {
|
||||
color: config.fill.fillColor.getValue(),
|
||||
opacity: goog.isDef(config.fill.fillOpacity) ?
|
||||
config.fill.fillOpacity :
|
||||
ol.parser.ogc.SLD_v1.defaults_.fillOpacity
|
||||
};
|
||||
rule.symbolizers.push(
|
||||
new ol.style.Fill(fill)
|
||||
);
|
||||
delete config.fill;
|
||||
}
|
||||
if (goog.isDef(config.stroke)) {
|
||||
var stroke = {
|
||||
color: config.stroke.strokeColor.getValue(),
|
||||
opacity: goog.isDef(config.stroke.strokeOpacity) ?
|
||||
config.stroke.strokeOpacity :
|
||||
ol.parser.ogc.SLD_v1.defaults_.strokeOpacity,
|
||||
width: goog.isDef(config.stroke.strokeWidth) ?
|
||||
config.stroke.strokeWidth :
|
||||
ol.parser.ogc.SLD_v1.defaults_.strokeWidth
|
||||
};
|
||||
rule.symbolizers.push(
|
||||
new ol.style.Stroke(stroke)
|
||||
);
|
||||
delete config.stroke;
|
||||
}
|
||||
|
||||
},
|
||||
'PointSymbolizer': function(node, rule) {
|
||||
var config = {};
|
||||
this.readChildNodes(node, config);
|
||||
config.zIndex = this.featureTypeCounter;
|
||||
if (config.fill) {
|
||||
var fillConfig = {
|
||||
color: goog.isDef(config.fill.fillColor) ?
|
||||
config.fill.fillColor :
|
||||
ol.parser.ogc.SLD_v1.defaults_.fillColor,
|
||||
opacity: goog.isDef(config.fill.fillOpacity) ?
|
||||
config.fill.fillOpacity :
|
||||
ol.parser.ogc.SLD_v1.defaults_.fillOpacity
|
||||
};
|
||||
config.fill = new ol.style.Fill(fillConfig);
|
||||
}
|
||||
if (config.stroke) {
|
||||
var strokeConfig = {
|
||||
color: goog.isDef(config.stroke.strokeColor) ?
|
||||
config.stroke.strokeColor :
|
||||
ol.parser.ogc.SLD_v1.defaults_.strokeColor,
|
||||
width: goog.isDef(config.stroke.strokeWidth) ?
|
||||
config.stroke.strokeWidth :
|
||||
ol.parser.ogc.SLD_v1.defaults_.strokeWidth,
|
||||
opacity: goog.isDef(config.stroke.strokeOpacity) ?
|
||||
config.stroke.strokeOpacity :
|
||||
ol.parser.ogc.SLD_v1.defaults_.strokeOpacity
|
||||
};
|
||||
config.stroke = new ol.style.Stroke(strokeConfig);
|
||||
}
|
||||
var symbolizer;
|
||||
if (goog.isDef(config.externalGraphic)) {
|
||||
config.width = config.height = config.size;
|
||||
symbolizer = new ol.style.Icon(
|
||||
/** @type {olx.style.IconOptions} */(config));
|
||||
} else {
|
||||
symbolizer = new ol.style.Shape(config);
|
||||
}
|
||||
rule.symbolizers.push(symbolizer);
|
||||
},
|
||||
'Stroke': function(node, symbolizer) {
|
||||
var stroke = {};
|
||||
this.readChildNodes(node, stroke);
|
||||
symbolizer.stroke = stroke;
|
||||
},
|
||||
'Fill': function(node, symbolizer) {
|
||||
var fill = {};
|
||||
this.readChildNodes(node, fill);
|
||||
symbolizer.fill = fill;
|
||||
},
|
||||
'CssParameter': function(node, symbolizer) {
|
||||
var cssProperty = node.getAttribute('name');
|
||||
var symProperty = ol.parser.ogc.SLD_v1.cssMap_[cssProperty];
|
||||
if (symProperty) {
|
||||
var ogcreaders = this.readers[this.filter_.defaultNamespaceURI];
|
||||
symbolizer[symProperty] = ogcreaders._expression.call(this, node);
|
||||
}
|
||||
},
|
||||
'Graphic': function(node, symbolizer) {
|
||||
var graphic = {};
|
||||
// painter's order not respected here, clobber previous with next
|
||||
this.readChildNodes(node, graphic);
|
||||
// directly properties with names that match symbolizer properties
|
||||
var properties = [
|
||||
'stroke', 'fill', 'rotation', 'opacity'
|
||||
];
|
||||
var prop, value;
|
||||
for (var i = 0, ii = properties.length; i < ii; ++i) {
|
||||
prop = properties[i];
|
||||
value = graphic[prop];
|
||||
if (goog.isDef(value)) {
|
||||
symbolizer[prop] = value;
|
||||
}
|
||||
}
|
||||
// set other generic properties with specific graphic property names
|
||||
if (goog.isDef(graphic.graphicName)) {
|
||||
symbolizer.type = graphic.graphicName;
|
||||
}
|
||||
if (goog.isDef(graphic.size)) {
|
||||
var pointRadius = graphic.size / 2;
|
||||
if (isNaN(pointRadius)) {
|
||||
// likely a property name
|
||||
symbolizer.size = graphic.size;
|
||||
} else {
|
||||
symbolizer.size = graphic.size / 2;
|
||||
}
|
||||
}
|
||||
if (goog.isDef(graphic.href)) {
|
||||
symbolizer.url = graphic.href;
|
||||
}
|
||||
},
|
||||
'ExternalGraphic': function(node, graphic) {
|
||||
this.readChildNodes(node, graphic);
|
||||
},
|
||||
'Mark': function(node, graphic) {
|
||||
this.readChildNodes(node, graphic);
|
||||
},
|
||||
'WellKnownName': function(node, graphic) {
|
||||
graphic.graphicName = this.getChildValue(node);
|
||||
},
|
||||
'Opacity': function(node, obj) {
|
||||
var ogcreaders = this.readers[this.filter_.defaultNamespaceURI];
|
||||
obj.opacity = ogcreaders._expression.call(this, node);
|
||||
},
|
||||
'Size': function(node, obj) {
|
||||
var ogcreaders = this.readers[this.filter_.defaultNamespaceURI];
|
||||
obj.size = ogcreaders._expression.call(this, node);
|
||||
},
|
||||
'Rotation': function(node, obj) {
|
||||
var ogcreaders = this.readers[this.filter_.defaultNamespaceURI];
|
||||
obj.rotation = ogcreaders._expression.call(this, node);
|
||||
},
|
||||
'OnlineResource': function(node, obj) {
|
||||
obj.href = this.getAttributeNS(
|
||||
node, 'http://www.w3.org/1999/xlink', 'href'
|
||||
);
|
||||
},
|
||||
'Format': function(node, graphic) {
|
||||
graphic.graphicFormat = this.getChildValue(node);
|
||||
}
|
||||
};
|
||||
this.writers = {};
|
||||
this.writers[this.defaultNamespaceURI] = {
|
||||
'StyledLayerDescriptor': function(sld) {
|
||||
var node = this.createElementNS('sld:StyledLayerDescriptor');
|
||||
node.setAttribute('version', this.version);
|
||||
if (goog.isDef(sld.name)) {
|
||||
this.writeNode('Name', sld.name, null, node);
|
||||
}
|
||||
if (goog.isDef(sld.title)) {
|
||||
this.writeNode('Title', sld.title, null, node);
|
||||
}
|
||||
if (goog.isDef(sld.description)) {
|
||||
this.writeNode('Abstract', sld.description, null, node);
|
||||
}
|
||||
goog.object.forEach(sld.namedLayers, function(layer) {
|
||||
this.writeNode('NamedLayer', layer, null, node);
|
||||
}, this);
|
||||
return node;
|
||||
},
|
||||
'Name': function(name) {
|
||||
var node = this.createElementNS('sld:Name');
|
||||
node.appendChild(this.createTextNode(name));
|
||||
return node;
|
||||
},
|
||||
'Title': function(title) {
|
||||
var node = this.createElementNS('sld:Title');
|
||||
node.appendChild(this.createTextNode(title));
|
||||
return node;
|
||||
},
|
||||
'Abstract': function(description) {
|
||||
var node = this.createElementNS('sld:Abstract');
|
||||
node.appendChild(this.createTextNode(description));
|
||||
return node;
|
||||
},
|
||||
'NamedLayer': function(layer) {
|
||||
var node = this.createElementNS('sld:NamedLayer');
|
||||
this.writeNode('Name', layer.name, null, node);
|
||||
var i, ii;
|
||||
if (layer.namedStyles) {
|
||||
for (i = 0, ii = layer.namedStyles.length; i < ii; ++i) {
|
||||
this.writeNode('NamedStyle', layer.namedStyles[i], null, node);
|
||||
}
|
||||
}
|
||||
if (layer.userStyles) {
|
||||
for (i = 0, ii = layer.userStyles.length; i < ii; ++i) {
|
||||
this.writeNode('UserStyle', layer.userStyles[i], null, node);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'NamedStyle': function(name) {
|
||||
var node = this.createElementNS('sld:NamedStyle');
|
||||
this.writeNode('Name', name, null, node);
|
||||
return node;
|
||||
},
|
||||
'UserStyle': function(style) {
|
||||
var node = this.createElementNS('sld:UserStyle');
|
||||
var name = style.getName(), title = style.getTitle();
|
||||
if (goog.isDef(name)) {
|
||||
this.writeNode('Name', name, null, node);
|
||||
}
|
||||
if (goog.isDef(title)) {
|
||||
this.writeNode('Title', title, null, node);
|
||||
}
|
||||
// TODO sorting by zIndex
|
||||
this.writeNode('FeatureTypeStyle', style, null, node);
|
||||
return node;
|
||||
},
|
||||
'FeatureTypeStyle': function(style) {
|
||||
var node = this.createElementNS('sld:FeatureTypeStyle');
|
||||
var rules = style.getRules();
|
||||
for (var i = 0, ii = rules.length; i < ii; ++i) {
|
||||
this.writeNode('Rule', rules[i], null, node);
|
||||
}
|
||||
var symbolizers = style.getSymbolizers();
|
||||
if (symbolizers.length > 0) {
|
||||
// wrap this in a Rule with an ElseFilter
|
||||
var rule = new ol.style.Rule({symbolizers: symbolizers});
|
||||
rule.elseFilter = true;
|
||||
this.writeNode('Rule', rule, null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'Rule': function(rule) {
|
||||
var node = this.createElementNS('sld:Rule');
|
||||
var filter = rule.getFilter();
|
||||
var name = rule.getName(), title = rule.getTitle();
|
||||
if (goog.isDef(name)) {
|
||||
this.writeNode('Name', name, null, node);
|
||||
}
|
||||
if (goog.isDef(title)) {
|
||||
this.writeNode('Title', title, null, node);
|
||||
}
|
||||
if (rule.elseFilter === true) {
|
||||
this.writeNode('ElseFilter', null, null, node);
|
||||
} else if (filter) {
|
||||
this.writeNode('Filter', filter, this.filter_.defaultNamespaceURI,
|
||||
node);
|
||||
}
|
||||
var minResolution = rule.getMinResolution();
|
||||
if (minResolution > 0) {
|
||||
this.writeNode('MinScaleDenominator',
|
||||
this.getScaleDenominatorFromResolution_(minResolution),
|
||||
null, node);
|
||||
}
|
||||
var maxResolution = rule.getMaxResolution();
|
||||
if (maxResolution < Infinity) {
|
||||
this.writeNode('MaxScaleDenominator',
|
||||
this.getScaleDenominatorFromResolution_(maxResolution),
|
||||
null, node);
|
||||
}
|
||||
var type, symbolizer, symbolizers = rule.getSymbolizers();
|
||||
if (symbolizers) {
|
||||
for (var i = 0, ii = symbolizers.length; i < ii; ++i) {
|
||||
symbolizer = symbolizers[i];
|
||||
if (symbolizer instanceof ol.style.Text) {
|
||||
type = 'Text';
|
||||
} else if (symbolizer instanceof ol.style.Stroke) {
|
||||
type = 'Line';
|
||||
} else if (symbolizer instanceof ol.style.Fill) {
|
||||
type = 'Polygon';
|
||||
} else if (symbolizer instanceof ol.style.Shape ||
|
||||
symbolizer instanceof ol.style.Icon) {
|
||||
type = 'Point';
|
||||
}
|
||||
if (goog.isDef(type)) {
|
||||
this.writeNode(type + 'Symbolizer', symbolizer, null, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'PointSymbolizer': function(symbolizer) {
|
||||
var node = this.createElementNS('sld:PointSymbolizer');
|
||||
this.writeNode('Graphic', symbolizer, null, node);
|
||||
return node;
|
||||
},
|
||||
'Mark': function(symbolizer) {
|
||||
var node = this.createElementNS('sld:Mark');
|
||||
this.writeNode('WellKnownName', symbolizer.getType(), null, node);
|
||||
var fill = symbolizer.getFill();
|
||||
if (!goog.isNull(fill)) {
|
||||
this.writeNode('Fill', fill, null, node);
|
||||
}
|
||||
var stroke = symbolizer.getStroke();
|
||||
if (!goog.isNull(stroke)) {
|
||||
this.writeNode('Stroke', stroke, null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'WellKnownName': function(name) {
|
||||
var node = this.createElementNS('sld:WellKnownName');
|
||||
node.appendChild(this.createTextNode(name));
|
||||
return node;
|
||||
},
|
||||
'Graphic': function(symbolizer) {
|
||||
var node = this.createElementNS('sld:Graphic');
|
||||
var size;
|
||||
if (symbolizer instanceof ol.style.Icon) {
|
||||
this.writeNode('ExternalGraphic', symbolizer, null, node);
|
||||
var opacity = symbolizer.getOpacity();
|
||||
goog.asserts.assertInstanceof(opacity, ol.expr.Literal,
|
||||
'Only ol.expr.Literal supported for graphicOpacity');
|
||||
this.writeNode('Opacity', opacity.getValue(), null, node);
|
||||
size = symbolizer.getWidth();
|
||||
} else if (symbolizer instanceof ol.style.Shape) {
|
||||
this.writeNode('Mark', symbolizer, null, node);
|
||||
size = symbolizer.getSize();
|
||||
}
|
||||
this.writeNode('Size', size, null, node);
|
||||
if (symbolizer instanceof ol.style.Icon) {
|
||||
var rotation = symbolizer.getRotation();
|
||||
goog.asserts.assertInstanceof(rotation, ol.expr.Literal,
|
||||
'Only ol.expr.Literal supported for rotation');
|
||||
this.writeNode('Rotation', rotation.getValue(), null, node);
|
||||
}
|
||||
return node;
|
||||
},
|
||||
'PolygonSymbolizer': function(symbolizer) {
|
||||
var node = this.createElementNS('sld:PolygonSymbolizer');
|
||||
this.writeNode('Fill', symbolizer, null, node);
|
||||
return node;
|
||||
},
|
||||
'Fill': function(symbolizer) {
|
||||
var node = this.createElementNS('sld:Fill');
|
||||
var fillColor = symbolizer.getColor();
|
||||
var msg = 'Only ol.expr.Literal supported for Fill properties';
|
||||
goog.asserts.assertInstanceof(fillColor, ol.expr.Literal, msg);
|
||||
this.writeNode('CssParameter', {
|
||||
value: fillColor.getValue(),
|
||||
key: 'fillColor'
|
||||
}, null, node);
|
||||
var fillOpacity = symbolizer.getOpacity();
|
||||
goog.asserts.assertInstanceof(fillOpacity, ol.expr.Literal, msg);
|
||||
this.writeNode('CssParameter', {
|
||||
value: fillOpacity.getValue(),
|
||||
key: 'fillOpacity'
|
||||
}, null, node);
|
||||
return node;
|
||||
},
|
||||
'TextSymbolizer': function(symbolizer) {
|
||||
var node = this.createElementNS('sld:TextSymbolizer');
|
||||
var text = symbolizer.getText();
|
||||
this.writeNode('Label', text, null, node);
|
||||
this.writeNode('Font', symbolizer, null, node);
|
||||
var stroke = symbolizer.getStroke();
|
||||
if (!goog.isNull(stroke)) {
|
||||
this.writeNode('Halo', stroke, null, node);
|
||||
}
|
||||
var color = symbolizer.getColor();
|
||||
goog.asserts.assertInstanceof(color, ol.expr.Literal,
|
||||
'font color should be ol.expr.Literal');
|
||||
this.writeNode('Fill', symbolizer, null, node);
|
||||
return node;
|
||||
},
|
||||
'Halo': function(symbolizer) {
|
||||
var node = this.createElementNS('sld:Halo');
|
||||
goog.asserts.assertInstanceof(symbolizer.getWidth(), ol.expr.Literal,
|
||||
'Only ol.expr.Literal supported for haloRadius');
|
||||
this.writeNode('Radius', symbolizer.getWidth().getValue() / 2, null,
|
||||
node);
|
||||
this.writeNode('Fill', symbolizer, null, node);
|
||||
return node;
|
||||
},
|
||||
'Radius': function(value) {
|
||||
var node = this.createElementNS('sld:Radius');
|
||||
node.appendChild(this.createTextNode(value));
|
||||
return node;
|
||||
},
|
||||
'LineSymbolizer': function(symbolizer) {
|
||||
var node = this.createElementNS('sld:LineSymbolizer');
|
||||
this.writeNode('Stroke', symbolizer, null, node);
|
||||
return node;
|
||||
},
|
||||
'Stroke': function(symbolizer) {
|
||||
var node = this.createElementNS('sld:Stroke');
|
||||
var strokeColor = symbolizer.getColor();
|
||||
var msg = 'SLD writing of stroke properties only supported ' +
|
||||
'for ol.expr.Literal';
|
||||
goog.asserts.assertInstanceof(strokeColor, ol.expr.Literal, msg);
|
||||
this.writeNode('CssParameter', {
|
||||
value: strokeColor.getValue(),
|
||||
key: 'strokeColor'
|
||||
}, null, node);
|
||||
var strokeOpacity = symbolizer.getOpacity();
|
||||
goog.asserts.assertInstanceof(strokeOpacity, ol.expr.Literal, msg);
|
||||
this.writeNode('CssParameter', {
|
||||
value: strokeOpacity.getValue(),
|
||||
key: 'strokeOpacity'
|
||||
}, null, node);
|
||||
var strokeWidth = symbolizer.getWidth();
|
||||
goog.asserts.assertInstanceof(strokeWidth, ol.expr.Literal, msg);
|
||||
this.writeNode('CssParameter', {
|
||||
value: strokeWidth.getValue(),
|
||||
key: 'strokeWidth'
|
||||
}, null, node);
|
||||
// TODO strokeDashstyle and strokeLinecap
|
||||
return node;
|
||||
},
|
||||
'CssParameter': function(obj) {
|
||||
// not handling ogc:expressions for now
|
||||
var name = ol.parser.ogc.SLD_v1.getCssProperty_(obj.key);
|
||||
if (goog.isDef(name)) {
|
||||
var node = this.createElementNS('sld:CssParameter');
|
||||
node.setAttribute('name', name);
|
||||
node.appendChild(this.createTextNode(obj.value));
|
||||
return node;
|
||||
}
|
||||
},
|
||||
'Label': function(label) {
|
||||
var node = this.createElementNS('sld:Label');
|
||||
this.filter_.writeOgcExpression(label, node);
|
||||
return node;
|
||||
},
|
||||
'Font': function(symbolizer) {
|
||||
var node = this.createElementNS('sld:Font');
|
||||
this.writeNode('CssParameter', {
|
||||
key: 'fontFamily',
|
||||
value: symbolizer.getFontFamily().getValue()
|
||||
}, null, node);
|
||||
this.writeNode('CssParameter', {
|
||||
key: 'fontSize',
|
||||
value: symbolizer.getFontSize().getValue()
|
||||
}, null, node);
|
||||
// TODO fontWeight and fontStyle
|
||||
return node;
|
||||
},
|
||||
'MinScaleDenominator': function(scale) {
|
||||
var node = this.createElementNS('sld:MinScaleDenominator');
|
||||
node.appendChild(this.createTextNode(scale));
|
||||
return node;
|
||||
},
|
||||
'MaxScaleDenominator': function(scale) {
|
||||
var node = this.createElementNS('sld:MaxScaleDenominator');
|
||||
node.appendChild(this.createTextNode(scale));
|
||||
return node;
|
||||
},
|
||||
'Size': function(value) {
|
||||
var node = this.createElementNS('sld:Size');
|
||||
this.filter_.writeOgcExpression(value, node);
|
||||
return node;
|
||||
}
|
||||
};
|
||||
this.filter_ = new ol.parser.ogc.Filter_v1_0_0();
|
||||
for (var uri in this.filter_.readers) {
|
||||
for (var key in this.filter_.readers[uri]) {
|
||||
if (!goog.isDef(this.readers[uri])) {
|
||||
this.readers[uri] = {};
|
||||
}
|
||||
this.readers[uri][key] = goog.bind(this.filter_.readers[uri][key],
|
||||
this.filter_);
|
||||
}
|
||||
}
|
||||
for (var uri in this.filter_.writers) {
|
||||
for (var key in this.filter_.writers[uri]) {
|
||||
if (!goog.isDef(this.writers[uri])) {
|
||||
this.writers[uri] = {};
|
||||
}
|
||||
this.writers[uri][key] = goog.bind(this.filter_.writers[uri][key],
|
||||
this.filter_);
|
||||
}
|
||||
}
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.SLD_v1, ol.parser.XML);
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.parser.ogc.SLD_v1.cssMap_ = {
|
||||
'stroke': 'strokeColor',
|
||||
'stroke-opacity': 'strokeOpacity',
|
||||
'stroke-width': 'strokeWidth',
|
||||
'stroke-linecap': 'strokeLinecap',
|
||||
'stroke-dasharray': 'strokeDashstyle',
|
||||
'fill': 'fillColor',
|
||||
'fill-opacity': 'fillOpacity',
|
||||
'font-family': 'fontFamily',
|
||||
'font-size': 'fontSize',
|
||||
'font-weight': 'fontWeight',
|
||||
'font-style': 'fontStyle'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.parser.ogc.SLD_v1.defaults_ = {
|
||||
fillOpacity: 1,
|
||||
strokeOpacity: 1,
|
||||
strokeWidth: 1,
|
||||
strokeColor: '#000000',
|
||||
haloColor: '#FFFFFF',
|
||||
haloOpacity: 1,
|
||||
haloRadius: 1,
|
||||
fillColor: '#808080',
|
||||
fontColor: '#000000'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {string} sym Symbolizer property.
|
||||
* @return {string|undefined} The css property that matches the symbolizer
|
||||
* property.
|
||||
*/
|
||||
ol.parser.ogc.SLD_v1.getCssProperty_ = function(sym) {
|
||||
return goog.object.findKey(ol.parser.ogc.SLD_v1.cssMap_,
|
||||
function(value, key, obj) {
|
||||
return (sym === value);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {number} scaleDenominator The scale denominator to convert to
|
||||
* resolution.
|
||||
* @return {number} resolution.
|
||||
*/
|
||||
ol.parser.ogc.SLD_v1.prototype.getResolutionFromScaleDenominator_ =
|
||||
function(scaleDenominator) {
|
||||
var dpi = 25.4 / 0.28;
|
||||
var mpu = ol.METERS_PER_UNIT[this.units];
|
||||
return 1 / ((1 / scaleDenominator) * (mpu * 39.37) * dpi);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {number} resolution The resolution to convert to scale denominator.
|
||||
* @return {number} scale denominator.
|
||||
*/
|
||||
ol.parser.ogc.SLD_v1.prototype.getScaleDenominatorFromResolution_ =
|
||||
function(resolution) {
|
||||
var dpi = 25.4 / 0.28;
|
||||
var mpu = ol.METERS_PER_UNIT[this.units];
|
||||
return resolution * mpu * 39.37 * dpi;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|Document|Element} data Data to read.
|
||||
* @param {olx.parser.SLDReadOptions=} opt_options Read options.
|
||||
* @return {Object} An object representing the document.
|
||||
*/
|
||||
ol.parser.ogc.SLD_v1.prototype.read = function(data, opt_options) {
|
||||
var units = 'm';
|
||||
if (goog.isDef(opt_options) && goog.isDef(opt_options.units)) {
|
||||
units = opt_options.units;
|
||||
}
|
||||
this.units = units;
|
||||
if (goog.isString(data)) {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
if (data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var obj = {namedLayers: {}};
|
||||
this.readNode(data, obj);
|
||||
delete this.units;
|
||||
return obj;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} style The style to write out.
|
||||
* @param {olx.parser.SLDWriteOptions=} opt_options Write options.
|
||||
* @return {string} The serialized SLD.
|
||||
*/
|
||||
ol.parser.ogc.SLD_v1.prototype.write = function(style, opt_options) {
|
||||
var units = 'm';
|
||||
if (goog.isDef(opt_options) && goog.isDef(opt_options.units)) {
|
||||
units = opt_options.units;
|
||||
}
|
||||
this.units = units;
|
||||
var root = this.writeNode('StyledLayerDescriptor', style);
|
||||
this.setAttributeNS(
|
||||
root, 'http://www.w3.org/2001/XMLSchema-instance',
|
||||
'xsi:schemaLocation', this.schemaLocation);
|
||||
var result = this.serialize(root);
|
||||
delete this.units;
|
||||
return result;
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.SLD_v1_0_0');
|
||||
|
||||
goog.require('ol.parser.ogc.SLD_v1');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.parser.ogc.SLD_v1}
|
||||
*/
|
||||
ol.parser.ogc.SLD_v1_0_0 = function() {
|
||||
goog.base(this);
|
||||
this.version = '1.0.0';
|
||||
this.schemaLocation = 'http://www.opengis.net/sld ' +
|
||||
'http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd';
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.SLD_v1_0_0,
|
||||
ol.parser.ogc.SLD_v1);
|
||||
@@ -1,22 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.WMTSCapabilities');
|
||||
goog.require('ol.parser.ogc.Versioned');
|
||||
goog.require('ol.parser.ogc.WMTSCapabilities_v1_0_0');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read [WMTS](http://www.opengeospatial.org/standards/wmts) capabilities
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object=} opt_options Options which will be set on this object.
|
||||
* @extends {ol.parser.ogc.Versioned}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.parser.ogc.WMTSCapabilities = function(opt_options) {
|
||||
opt_options = opt_options || {};
|
||||
opt_options['defaultVersion'] = '1.0.0';
|
||||
this.parsers = {};
|
||||
this.parsers['v1_0_0'] = ol.parser.ogc.WMTSCapabilities_v1_0_0;
|
||||
goog.base(this, opt_options);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.WMTSCapabilities, ol.parser.ogc.Versioned);
|
||||
@@ -1,169 +0,0 @@
|
||||
goog.provide('ol.parser.ogc.WMTSCapabilities_v1_0_0');
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.coordinate');
|
||||
goog.require('ol.parser.XML');
|
||||
goog.require('ol.parser.ogc.OWSCommon_v1_1_0');
|
||||
goog.require('ol.proj');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read [WMTS](http://www.opengeospatial.org/standards/wmts) capabilities
|
||||
* version 1.0
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.parser.XML}
|
||||
*/
|
||||
ol.parser.ogc.WMTSCapabilities_v1_0_0 = function() {
|
||||
this.defaultNamespaceURI = 'http://www.opengis.net/wmts/1.0';
|
||||
this.errorProperty = 'serviceIdentification';
|
||||
this.readers = {
|
||||
'http://www.opengis.net/wmts/1.0': {
|
||||
'Capabilities': function(node, obj) {
|
||||
this.readChildNodes(node, obj);
|
||||
},
|
||||
'Contents': function(node, obj) {
|
||||
obj['contents'] = {};
|
||||
obj['contents']['layers'] = [];
|
||||
obj['contents']['tileMatrixSets'] = {};
|
||||
this.readChildNodes(node, obj['contents']);
|
||||
},
|
||||
'Layer': function(node, obj) {
|
||||
var layer = {
|
||||
'styles': [],
|
||||
'formats': [],
|
||||
'dimensions': [],
|
||||
'tileMatrixSetLinks': []
|
||||
};
|
||||
layer['layers'] = [];
|
||||
this.readChildNodes(node, layer);
|
||||
obj['layers'].push(layer);
|
||||
},
|
||||
'Style': function(node, obj) {
|
||||
var style = {};
|
||||
style['isDefault'] = (node.getAttribute('isDefault') === 'true');
|
||||
this.readChildNodes(node, style);
|
||||
obj['styles'].push(style);
|
||||
},
|
||||
'Format': function(node, obj) {
|
||||
obj['formats'].push(this.getChildValue(node));
|
||||
},
|
||||
'TileMatrixSetLink': function(node, obj) {
|
||||
var tileMatrixSetLink = {};
|
||||
this.readChildNodes(node, tileMatrixSetLink);
|
||||
obj['tileMatrixSetLinks'].push(tileMatrixSetLink);
|
||||
},
|
||||
'TileMatrixSet': function(node, obj) {
|
||||
// node could be child of wmts:Contents or wmts:TileMatrixSetLink
|
||||
// duck type wmts:Contents by looking for layers
|
||||
if (obj['layers']) {
|
||||
// TileMatrixSet as object type in schema
|
||||
var tileMatrixSet = {
|
||||
'matrixIds': []
|
||||
};
|
||||
this.readChildNodes(node, tileMatrixSet);
|
||||
obj['tileMatrixSets'][tileMatrixSet['identifier']] = tileMatrixSet;
|
||||
} else {
|
||||
// TileMatrixSet as string type in schema
|
||||
obj['tileMatrixSet'] = this.getChildValue(node);
|
||||
}
|
||||
},
|
||||
'TileMatrix': function(node, obj) {
|
||||
var tileMatrix = {
|
||||
'supportedCRS': obj['supportedCRS']
|
||||
};
|
||||
this.readChildNodes(node, tileMatrix);
|
||||
obj['matrixIds'].push(tileMatrix);
|
||||
},
|
||||
'ScaleDenominator': function(node, obj) {
|
||||
obj['scaleDenominator'] = parseFloat(this.getChildValue(node));
|
||||
},
|
||||
'TopLeftCorner': function(node, obj) {
|
||||
var topLeftCorner = this.getChildValue(node);
|
||||
var coords = topLeftCorner.split(' ');
|
||||
var axisOrientation =
|
||||
ol.proj.get(obj['supportedCRS']).getAxisOrientation();
|
||||
obj['topLeftCorner'] = ol.coordinate.fromProjectedArray(
|
||||
[parseFloat(coords[0]), parseFloat(coords[1])], axisOrientation);
|
||||
},
|
||||
'TileWidth': function(node, obj) {
|
||||
obj['tileWidth'] = parseInt(this.getChildValue(node), 10);
|
||||
},
|
||||
'TileHeight': function(node, obj) {
|
||||
obj['tileHeight'] = parseInt(this.getChildValue(node), 10);
|
||||
},
|
||||
'MatrixWidth': function(node, obj) {
|
||||
obj['matrixWidth'] = parseInt(this.getChildValue(node), 10);
|
||||
},
|
||||
'MatrixHeight': function(node, obj) {
|
||||
obj['matrixHeight'] = parseInt(this.getChildValue(node), 10);
|
||||
},
|
||||
'ResourceURL': function(node, obj) {
|
||||
var resourceType = node.getAttribute('resourceType');
|
||||
var format = node.getAttribute('format');
|
||||
var template = node.getAttribute('template');
|
||||
if (!obj['resourceUrls']) {
|
||||
obj['resourceUrls'] = {};
|
||||
}
|
||||
if (!obj['resourceUrls'][resourceType]) {
|
||||
obj['resourceUrls'][resourceType] = {};
|
||||
}
|
||||
if (!obj['resourceUrls'][resourceType][format]) {
|
||||
obj['resourceUrls'][resourceType][format] = [];
|
||||
}
|
||||
obj['resourceUrls'][resourceType][format].push(template);
|
||||
},
|
||||
'WSDL': function(node, obj) {
|
||||
obj['wsdl'] = {};
|
||||
obj['wsdl']['href'] = this.getAttributeNS(node,
|
||||
'http://www.w3.org/1999/xlink', 'href');
|
||||
// TODO: other attributes of <WSDL> element
|
||||
},
|
||||
'ServiceMetadataURL': function(node, obj) {
|
||||
obj['serviceMetadataUrl'] = {};
|
||||
obj['serviceMetadataUrl']['href'] =
|
||||
this.getAttributeNS(node, 'http://www.w3.org/1999/xlink', 'href');
|
||||
// TODO: other attributes of <ServiceMetadataURL> element
|
||||
},
|
||||
'LegendURL': function(node, obj) {
|
||||
obj['legend'] = {};
|
||||
obj['legend']['href'] = this.getAttributeNS(node,
|
||||
'http://www.w3.org/1999/xlink', 'href');
|
||||
obj['legend']['format'] = node.getAttribute('format');
|
||||
},
|
||||
'Dimension': function(node, obj) {
|
||||
var dimension = {'values': []};
|
||||
this.readChildNodes(node, dimension);
|
||||
obj['dimensions'].push(dimension);
|
||||
},
|
||||
'Default': function(node, obj) {
|
||||
obj['default'] = this.getChildValue(node);
|
||||
},
|
||||
'Value': function(node, obj) {
|
||||
obj['values'].push(this.getChildValue(node));
|
||||
}
|
||||
}
|
||||
};
|
||||
var ows = new ol.parser.ogc.OWSCommon_v1_1_0();
|
||||
this.readers['http://www.opengis.net/ows/1.1'] =
|
||||
ows.readers['http://www.opengis.net/ows/1.1'];
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.parser.ogc.WMTSCapabilities_v1_0_0, ol.parser.XML);
|
||||
|
||||
|
||||
/**
|
||||
* @param {string|Document|Element} data Data to read.
|
||||
* @return {Object} An object representing the document.
|
||||
*/
|
||||
ol.parser.ogc.WMTSCapabilities_v1_0_0.prototype.read = function(data) {
|
||||
if (goog.isString(data)) {
|
||||
data = goog.dom.xml.loadXml(data);
|
||||
}
|
||||
if (data && data.nodeType == 9) {
|
||||
data = data.documentElement;
|
||||
}
|
||||
var obj = {};
|
||||
this.readNode(data, obj);
|
||||
return obj;
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
/**
|
||||
* @namespace ol.style
|
||||
*/
|
||||
@@ -1,160 +0,0 @@
|
||||
goog.provide('ol.style.Fill');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Expression');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.style.PolygonLiteral');
|
||||
goog.require('ol.style.Symbolizer');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.style.Symbolizer}
|
||||
* @param {olx.style.FillOptions=} opt_options Polygon options.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.style.Fill = function(opt_options) {
|
||||
goog.base(this);
|
||||
var options = opt_options || {};
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.color_ = !goog.isDefAndNotNull(options.color) ?
|
||||
new ol.expr.Literal(ol.style.FillDefaults.color) :
|
||||
(options.color instanceof ol.expr.Expression) ?
|
||||
options.color : new ol.expr.Literal(options.color);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.opacity_ = !goog.isDefAndNotNull(options.opacity) ?
|
||||
new ol.expr.Literal(ol.style.FillDefaults.opacity) :
|
||||
(options.opacity instanceof ol.expr.Expression) ?
|
||||
options.opacity : new ol.expr.Literal(options.opacity);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.zIndex_ = !goog.isDefAndNotNull(options.zIndex) ?
|
||||
new ol.expr.Literal(ol.style.FillDefaults.zIndex) :
|
||||
(options.zIndex instanceof ol.expr.Expression) ?
|
||||
options.zIndex : new ol.expr.Literal(options.zIndex);
|
||||
|
||||
};
|
||||
goog.inherits(ol.style.Fill, ol.style.Symbolizer);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return {ol.style.PolygonLiteral} Literal shape symbolizer.
|
||||
*/
|
||||
ol.style.Fill.prototype.createLiteral = function(featureOrType) {
|
||||
var feature, type;
|
||||
if (featureOrType instanceof ol.Feature) {
|
||||
feature = featureOrType;
|
||||
var geometry = feature.getGeometry();
|
||||
type = geometry ? geometry.getType() : null;
|
||||
} else {
|
||||
type = featureOrType;
|
||||
}
|
||||
var literal = null;
|
||||
|
||||
if (type === ol.geom.GeometryType.POLYGON ||
|
||||
type === ol.geom.GeometryType.MULTI_POLYGON) {
|
||||
|
||||
var color = ol.expr.evaluateFeature(this.color_, feature);
|
||||
goog.asserts.assertString(
|
||||
color, 'color must be a string');
|
||||
|
||||
var opacity = Number(ol.expr.evaluateFeature(this.opacity_, feature));
|
||||
goog.asserts.assert(!isNaN(opacity), 'opacity must be a number');
|
||||
|
||||
var zIndex = Number(ol.expr.evaluateFeature(this.zIndex_, feature));
|
||||
goog.asserts.assert(!isNaN(zIndex), 'zIndex must be a number');
|
||||
|
||||
literal = new ol.style.PolygonLiteral({
|
||||
fillColor: color,
|
||||
fillOpacity: opacity,
|
||||
zIndex: zIndex
|
||||
});
|
||||
}
|
||||
|
||||
return literal;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the fill color.
|
||||
* @return {ol.expr.Expression} Fill color.
|
||||
*/
|
||||
ol.style.Fill.prototype.getColor = function() {
|
||||
return this.color_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the fill opacity.
|
||||
* @return {ol.expr.Expression} Fill opacity.
|
||||
*/
|
||||
ol.style.Fill.prototype.getOpacity = function() {
|
||||
return this.opacity_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the fill zIndex.
|
||||
* @return {ol.expr.Expression} Fill zIndex.
|
||||
*/
|
||||
ol.style.Fill.prototype.getZIndex = function() {
|
||||
return this.zIndex_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the fill color.
|
||||
* @param {ol.expr.Expression} color Fill color.
|
||||
*/
|
||||
ol.style.Fill.prototype.setColor = function(color) {
|
||||
goog.asserts.assertInstanceof(color, ol.expr.Expression);
|
||||
this.color_ = color;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the fill opacity.
|
||||
* @param {ol.expr.Expression} opacity Fill opacity.
|
||||
*/
|
||||
ol.style.Fill.prototype.setOpacity = function(opacity) {
|
||||
goog.asserts.assertInstanceof(opacity, ol.expr.Expression);
|
||||
this.opacity_ = opacity;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the fill zIndex.
|
||||
* @param {ol.expr.Expression} zIndex Fill zIndex.
|
||||
*/
|
||||
ol.style.Fill.prototype.setZIndex = function(zIndex) {
|
||||
goog.asserts.assertInstanceof(zIndex, ol.expr.Expression);
|
||||
this.zIndex_ = zIndex;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{fillColor: string,
|
||||
* fillOpacity: number,
|
||||
* zIndex: number}}
|
||||
*/
|
||||
ol.style.FillDefaults = {
|
||||
color: '#ffffff',
|
||||
opacity: 0.4,
|
||||
zIndex: 0
|
||||
};
|
||||
@@ -1,70 +0,0 @@
|
||||
goog.provide('ol.style.IconLiteral');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.style.PointLiteral');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{url: string,
|
||||
* width: (number|undefined),
|
||||
* height: (number|undefined),
|
||||
* opacity: number,
|
||||
* rotation: number,
|
||||
* xOffset: number,
|
||||
* yOffset: number,
|
||||
* zIndex: number}}
|
||||
*/
|
||||
ol.style.IconLiteralOptions;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.style.PointLiteral}
|
||||
* @param {ol.style.IconLiteralOptions} options Icon literal options.
|
||||
*/
|
||||
ol.style.IconLiteral = function(options) {
|
||||
|
||||
/** @type {string} */
|
||||
this.url = options.url;
|
||||
|
||||
/** @type {number|undefined} */
|
||||
this.width = options.width;
|
||||
|
||||
/** @type {number|undefined} */
|
||||
this.height = options.height;
|
||||
|
||||
/** @type {number} */
|
||||
this.opacity = options.opacity;
|
||||
|
||||
/** @type {number} */
|
||||
this.rotation = options.rotation;
|
||||
|
||||
/** @type {number} */
|
||||
this.xOffset = options.xOffset;
|
||||
|
||||
/** @type {number} */
|
||||
this.yOffset = options.yOffset;
|
||||
|
||||
goog.asserts.assertNumber(
|
||||
options.zIndex, 'zIndex must be a number');
|
||||
/** @type {number} */
|
||||
this.zIndex = options.zIndex;
|
||||
|
||||
};
|
||||
goog.inherits(ol.style.IconLiteral, ol.style.PointLiteral);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.style.IconLiteral.prototype.equals = function(other) {
|
||||
return this.url == other.url &&
|
||||
this.width == other.width &&
|
||||
this.height == other.height &&
|
||||
this.opacity == other.opacity &&
|
||||
this.rotation == other.rotation &&
|
||||
this.xOffset == other.xOffset &&
|
||||
this.yOffset == other.yOffset &&
|
||||
this.zIndex == other.zIndex;
|
||||
};
|
||||
@@ -1,329 +0,0 @@
|
||||
goog.provide('ol.style.Icon');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Expression');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.style.IconLiteral');
|
||||
goog.require('ol.style.Point');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.style.Point}
|
||||
* @param {olx.style.IconOptions} options Icon options.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.style.Icon = function(options) {
|
||||
goog.base(this);
|
||||
|
||||
goog.asserts.assert(options.url, 'url must be set');
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.url_ = (options.url instanceof ol.expr.Expression) ?
|
||||
options.url : new ol.expr.Literal(options.url);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.width_ = !goog.isDef(options.width) ?
|
||||
null :
|
||||
(options.width instanceof ol.expr.Expression) ?
|
||||
options.width : new ol.expr.Literal(options.width);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.height_ = !goog.isDef(options.height) ?
|
||||
null :
|
||||
(options.height instanceof ol.expr.Expression) ?
|
||||
options.height : new ol.expr.Literal(options.height);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.opacity_ = !goog.isDef(options.opacity) ?
|
||||
new ol.expr.Literal(ol.style.IconDefaults.opacity) :
|
||||
(options.opacity instanceof ol.expr.Expression) ?
|
||||
options.opacity : new ol.expr.Literal(options.opacity);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.rotation_ = !goog.isDef(options.rotation) ?
|
||||
new ol.expr.Literal(ol.style.IconDefaults.rotation) :
|
||||
(options.rotation instanceof ol.expr.Expression) ?
|
||||
options.rotation : new ol.expr.Literal(options.rotation);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.xOffset_ = !goog.isDef(options.xOffset) ?
|
||||
new ol.expr.Literal(ol.style.IconDefaults.xOffset) :
|
||||
(options.xOffset instanceof ol.expr.Expression) ?
|
||||
options.xOffset : new ol.expr.Literal(options.xOffset);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.yOffset_ = !goog.isDef(options.yOffset) ?
|
||||
new ol.expr.Literal(ol.style.IconDefaults.yOffset) :
|
||||
(options.yOffset instanceof ol.expr.Expression) ?
|
||||
options.yOffset : new ol.expr.Literal(options.yOffset);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.zIndex_ = !goog.isDefAndNotNull(options.zIndex) ?
|
||||
new ol.expr.Literal(ol.style.IconDefaults.zIndex) :
|
||||
(options.zIndex instanceof ol.expr.Expression) ?
|
||||
options.zIndex : new ol.expr.Literal(options.zIndex);
|
||||
|
||||
};
|
||||
goog.inherits(ol.style.Icon, ol.style.Point);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return {ol.style.IconLiteral} Literal shape symbolizer.
|
||||
*/
|
||||
ol.style.Icon.prototype.createLiteral = function(featureOrType) {
|
||||
var feature, type;
|
||||
if (featureOrType instanceof ol.Feature) {
|
||||
feature = featureOrType;
|
||||
var geometry = feature.getGeometry();
|
||||
type = geometry ? geometry.getType() : null;
|
||||
} else {
|
||||
type = featureOrType;
|
||||
}
|
||||
|
||||
var literal = null;
|
||||
if (type === ol.geom.GeometryType.POINT ||
|
||||
type === ol.geom.GeometryType.MULTI_POINT) {
|
||||
|
||||
var url = ol.expr.evaluateFeature(this.url_, feature);
|
||||
goog.asserts.assertString(url, 'url must be a string');
|
||||
goog.asserts.assert(url != '#', 'url must not be "#"');
|
||||
|
||||
var width;
|
||||
if (!goog.isNull(this.width_)) {
|
||||
width = Number(ol.expr.evaluateFeature(this.width_, feature));
|
||||
goog.asserts.assert(!isNaN(width), 'width must be a number');
|
||||
}
|
||||
|
||||
var height;
|
||||
if (!goog.isNull(this.height_)) {
|
||||
height = Number(ol.expr.evaluateFeature(this.height_, feature));
|
||||
goog.asserts.assertNumber(height, 'height must be a number');
|
||||
}
|
||||
|
||||
var opacity = Number(ol.expr.evaluateFeature(this.opacity_, feature));
|
||||
goog.asserts.assert(!isNaN(opacity), 'opacity must be a number');
|
||||
|
||||
var rotation = Number(ol.expr.evaluateFeature(this.rotation_, feature));
|
||||
goog.asserts.assert(!isNaN(rotation), 'rotation must be a number');
|
||||
|
||||
var xOffset = Number(ol.expr.evaluateFeature(this.xOffset_, feature));
|
||||
goog.asserts.assert(!isNaN(xOffset), 'xOffset must be a number');
|
||||
|
||||
var yOffset = Number(ol.expr.evaluateFeature(this.yOffset_, feature));
|
||||
goog.asserts.assert(!isNaN(yOffset), 'yOffset must be a number');
|
||||
|
||||
var zIndex = Number(ol.expr.evaluateFeature(this.zIndex_, feature));
|
||||
goog.asserts.assert(!isNaN(zIndex), 'zIndex must be a number');
|
||||
|
||||
literal = new ol.style.IconLiteral({
|
||||
url: url,
|
||||
width: width,
|
||||
height: height,
|
||||
opacity: opacity,
|
||||
rotation: rotation,
|
||||
xOffset: xOffset,
|
||||
yOffset: yOffset,
|
||||
zIndex: zIndex
|
||||
});
|
||||
}
|
||||
|
||||
return literal;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the height.
|
||||
* @return {ol.expr.Expression} Icon height.
|
||||
*/
|
||||
ol.style.Icon.prototype.getHeight = function() {
|
||||
return this.height_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the opacity.
|
||||
* @return {ol.expr.Expression} Opacity.
|
||||
*/
|
||||
ol.style.Icon.prototype.getOpacity = function() {
|
||||
return this.opacity_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the rotation.
|
||||
* @return {ol.expr.Expression} Icon rotation.
|
||||
*/
|
||||
ol.style.Icon.prototype.getRotation = function() {
|
||||
return this.rotation_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the URL.
|
||||
* @return {ol.expr.Expression} Icon URL.
|
||||
*/
|
||||
ol.style.Icon.prototype.getUrl = function() {
|
||||
return this.url_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the width.
|
||||
* @return {ol.expr.Expression} Icon width.
|
||||
*/
|
||||
ol.style.Icon.prototype.getWidth = function() {
|
||||
return this.width_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the xOffset.
|
||||
* @return {ol.expr.Expression} Icon xOffset.
|
||||
*/
|
||||
ol.style.Icon.prototype.getXOffset = function() {
|
||||
return this.xOffset_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the yOffset.
|
||||
* @return {ol.expr.Expression} Icon yOffset.
|
||||
*/
|
||||
ol.style.Icon.prototype.getYOffset = function() {
|
||||
return this.yOffset_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the zIndex.
|
||||
* @return {ol.expr.Expression} Icon zIndex.
|
||||
*/
|
||||
ol.style.Icon.prototype.getZIndex = function() {
|
||||
return this.zIndex_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the height.
|
||||
* @param {ol.expr.Expression} height Icon height.
|
||||
*/
|
||||
ol.style.Icon.prototype.setHeight = function(height) {
|
||||
goog.asserts.assertInstanceof(height, ol.expr.Expression);
|
||||
this.height_ = height;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the opacity.
|
||||
* @param {ol.expr.Expression} opacity Opacity.
|
||||
*/
|
||||
ol.style.Icon.prototype.setOpacity = function(opacity) {
|
||||
goog.asserts.assertInstanceof(opacity, ol.expr.Expression);
|
||||
this.opacity_ = opacity;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the rotation.
|
||||
* @param {ol.expr.Expression} rotation Icon rotation.
|
||||
*/
|
||||
ol.style.Icon.prototype.setRotation = function(rotation) {
|
||||
goog.asserts.assertInstanceof(rotation, ol.expr.Expression);
|
||||
this.rotation_ = rotation;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the URL.
|
||||
* @param {ol.expr.Expression} url Icon URL.
|
||||
*/
|
||||
ol.style.Icon.prototype.setUrl = function(url) {
|
||||
goog.asserts.assertInstanceof(url, ol.expr.Expression);
|
||||
this.url_ = url;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the width.
|
||||
* @param {ol.expr.Expression} width Icon width.
|
||||
*/
|
||||
ol.style.Icon.prototype.setWidth = function(width) {
|
||||
goog.asserts.assertInstanceof(width, ol.expr.Expression);
|
||||
this.width_ = width;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the xOffset.
|
||||
* @param {ol.expr.Expression} xOffset Icon xOffset.
|
||||
*/
|
||||
ol.style.Icon.prototype.setXOffset = function(xOffset) {
|
||||
goog.asserts.assertInstanceof(xOffset, ol.expr.Expression);
|
||||
this.xOffset_ = xOffset;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the yOffset.
|
||||
* @param {ol.expr.Expression} yOffset Icon yOffset.
|
||||
*/
|
||||
ol.style.Icon.prototype.setYOffset = function(yOffset) {
|
||||
goog.asserts.assertInstanceof(yOffset, ol.expr.Expression);
|
||||
this.yOffset_ = yOffset;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the zIndex.
|
||||
* @param {ol.expr.Expression} zIndex Icon zIndex.
|
||||
*/
|
||||
ol.style.Icon.prototype.setZIndex = function(zIndex) {
|
||||
goog.asserts.assertInstanceof(zIndex, ol.expr.Expression);
|
||||
this.zIndex_ = zIndex;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{opacity: number,
|
||||
* rotation: number,
|
||||
* xOffset: number,
|
||||
* yOffset: number,
|
||||
* zIndex: number}}
|
||||
*/
|
||||
ol.style.IconDefaults = {
|
||||
opacity: 1,
|
||||
rotation: 0,
|
||||
xOffset: 0,
|
||||
yOffset: 0,
|
||||
zIndex: 0
|
||||
};
|
||||
@@ -1,57 +0,0 @@
|
||||
goog.provide('ol.style.LineLiteral');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.style.Literal');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{color: string,
|
||||
* opacity: number,
|
||||
* width: number,
|
||||
* zIndex: number}}
|
||||
*/
|
||||
ol.style.LineLiteralOptions;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.style.Literal}
|
||||
* @param {ol.style.LineLiteralOptions} options Line literal options.
|
||||
*/
|
||||
ol.style.LineLiteral = function(options) {
|
||||
goog.base(this);
|
||||
|
||||
goog.asserts.assertString(
|
||||
options.color, 'color must be a string');
|
||||
/** @type {string} */
|
||||
this.color = options.color;
|
||||
|
||||
goog.asserts.assertNumber(
|
||||
options.opacity, 'opacity must be a number');
|
||||
/** @type {number} */
|
||||
this.opacity = options.opacity;
|
||||
|
||||
goog.asserts.assertNumber(
|
||||
options.width, 'width must be a number');
|
||||
/** @type {number} */
|
||||
this.width = options.width;
|
||||
|
||||
goog.asserts.assertNumber(
|
||||
options.zIndex, 'zIndex must be a number');
|
||||
/** @type {number} */
|
||||
this.zIndex = options.zIndex;
|
||||
|
||||
};
|
||||
goog.inherits(ol.style.LineLiteral, ol.style.Literal);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.style.LineLiteral.prototype.equals = function(other) {
|
||||
return this.color == other.color &&
|
||||
this.opacity == other.opacity &&
|
||||
this.width == other.width &&
|
||||
this.zIndex == other.zIndex;
|
||||
};
|
||||
@@ -1,16 +0,0 @@
|
||||
goog.provide('ol.style.Literal');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
ol.style.Literal = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.style.Literal} symbolizerLiteral Symbolizer literal to
|
||||
* compare to.
|
||||
* @return {boolean} Is the passed symbolizer literal equal to this instance?
|
||||
*/
|
||||
ol.style.Literal.prototype.equals = goog.abstractMethod;
|
||||
@@ -1,14 +0,0 @@
|
||||
goog.provide('ol.style.PointLiteral');
|
||||
|
||||
goog.require('ol.style.Literal');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.style.Literal}
|
||||
*/
|
||||
ol.style.PointLiteral = function() {
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.style.PointLiteral, ol.style.Literal);
|
||||
@@ -1,20 +0,0 @@
|
||||
goog.provide('ol.style.Point');
|
||||
|
||||
goog.require('ol.style.Symbolizer');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.style.Symbolizer}
|
||||
*/
|
||||
ol.style.Point = function() {
|
||||
goog.base(this);
|
||||
};
|
||||
goog.inherits(ol.style.Point, ol.style.Symbolizer);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.style.Point.prototype.createLiteral = goog.abstractMethod;
|
||||
@@ -1,89 +0,0 @@
|
||||
goog.provide('ol.style.PolygonLiteral');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.style.Literal');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{fillColor: (string|undefined),
|
||||
* fillOpacity: (number|undefined),
|
||||
* strokeColor: (string|undefined),
|
||||
* strokeOpacity: (number|undefined),
|
||||
* strokeWidth: (number|undefined),
|
||||
* zIndex: number}}
|
||||
*/
|
||||
ol.style.PolygonLiteralOptions;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.style.Literal}
|
||||
* @param {ol.style.PolygonLiteralOptions} options Polygon literal options.
|
||||
*/
|
||||
ol.style.PolygonLiteral = function(options) {
|
||||
goog.base(this);
|
||||
|
||||
/** @type {string|undefined} */
|
||||
this.fillColor = options.fillColor;
|
||||
if (goog.isDef(options.fillColor)) {
|
||||
goog.asserts.assertString(options.fillColor, 'fillColor must be a string');
|
||||
}
|
||||
|
||||
/** @type {number|undefined} */
|
||||
this.fillOpacity = options.fillOpacity;
|
||||
if (goog.isDef(options.fillOpacity)) {
|
||||
goog.asserts.assertNumber(
|
||||
options.fillOpacity, 'fillOpacity must be a number');
|
||||
}
|
||||
|
||||
/** @type {string|undefined} */
|
||||
this.strokeColor = options.strokeColor;
|
||||
if (goog.isDef(this.strokeColor)) {
|
||||
goog.asserts.assertString(
|
||||
this.strokeColor, 'strokeColor must be a string');
|
||||
}
|
||||
|
||||
/** @type {number|undefined} */
|
||||
this.strokeOpacity = options.strokeOpacity;
|
||||
if (goog.isDef(this.strokeOpacity)) {
|
||||
goog.asserts.assertNumber(
|
||||
this.strokeOpacity, 'strokeOpacity must be a number');
|
||||
}
|
||||
|
||||
/** @type {number|undefined} */
|
||||
this.strokeWidth = options.strokeWidth;
|
||||
if (goog.isDef(this.strokeWidth)) {
|
||||
goog.asserts.assertNumber(
|
||||
this.strokeWidth, 'strokeWidth must be a number');
|
||||
}
|
||||
|
||||
// fill and/or stroke properties must be defined
|
||||
var fillDef = goog.isDef(this.fillColor) && goog.isDef(this.fillOpacity);
|
||||
var strokeDef = goog.isDef(this.strokeColor) &&
|
||||
goog.isDef(this.strokeOpacity) &&
|
||||
goog.isDef(this.strokeWidth);
|
||||
goog.asserts.assert(fillDef || strokeDef,
|
||||
'Either fillColor and fillOpacity or ' +
|
||||
'strokeColor and strokeOpacity and strokeWidth must be set');
|
||||
|
||||
goog.asserts.assertNumber(
|
||||
options.zIndex, 'zIndex must be a number');
|
||||
/** @type {number} */
|
||||
this.zIndex = options.zIndex;
|
||||
|
||||
};
|
||||
goog.inherits(ol.style.PolygonLiteral, ol.style.Literal);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.style.PolygonLiteral.prototype.equals = function(other) {
|
||||
return this.fillColor == other.fillColor &&
|
||||
this.fillOpacity == other.fillOpacity &&
|
||||
this.strokeColor == other.strokeColor &&
|
||||
this.strokeOpacity == other.strokeOpacity &&
|
||||
this.strokeWidth == other.strokeWidth &&
|
||||
this.zIndex == other.zIndex;
|
||||
};
|
||||
@@ -1,134 +0,0 @@
|
||||
goog.provide('ol.style.Rule');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Expression');
|
||||
goog.require('ol.style.Symbolizer');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {olx.style.RuleOptions} options Rule options.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.style.Rule = function(options) {
|
||||
|
||||
|
||||
var filter = null;
|
||||
if (goog.isDef(options.filter)) {
|
||||
if (goog.isString(options.filter)) {
|
||||
filter = ol.expr.parse(options.filter);
|
||||
} else {
|
||||
goog.asserts.assert(options.filter instanceof ol.expr.Expression);
|
||||
filter = options.filter;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.filter_ = filter;
|
||||
|
||||
/**
|
||||
* @type {Array.<ol.style.Symbolizer>}
|
||||
* @private
|
||||
*/
|
||||
this.symbolizers_ = goog.isDef(options.symbolizers) ?
|
||||
options.symbolizers : [];
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.minResolution_ = goog.isDef(options.minResolution) ?
|
||||
options.minResolution : 0;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.maxResolution_ = goog.isDef(options.maxResolution) ?
|
||||
options.maxResolution : Infinity;
|
||||
|
||||
/**
|
||||
* @type {string|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.name_ = goog.isDef(options.name) ?
|
||||
options.name : undefined;
|
||||
|
||||
/**
|
||||
* @type {string|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.title_ = goog.isDef(options.title) ?
|
||||
options.title : undefined;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {number} resolution Map resolution.
|
||||
* @return {boolean} Does the rule apply to the feature?
|
||||
*/
|
||||
ol.style.Rule.prototype.applies = function(feature, resolution) {
|
||||
var applies = resolution >= this.minResolution_ &&
|
||||
resolution < this.maxResolution_;
|
||||
if (applies && !goog.isNull(this.filter_)) {
|
||||
applies = !!ol.expr.evaluateFeature(this.filter_, feature);
|
||||
}
|
||||
return applies;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {Array.<ol.style.Symbolizer>} Symbolizers.
|
||||
*/
|
||||
ol.style.Rule.prototype.getSymbolizers = function() {
|
||||
return this.symbolizers_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {ol.expr.Expression}
|
||||
*/
|
||||
ol.style.Rule.prototype.getFilter = function() {
|
||||
return this.filter_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number}
|
||||
*/
|
||||
ol.style.Rule.prototype.getMinResolution = function() {
|
||||
return this.minResolution_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {number}
|
||||
*/
|
||||
ol.style.Rule.prototype.getMaxResolution = function() {
|
||||
return this.maxResolution_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {string|undefined}
|
||||
*/
|
||||
ol.style.Rule.prototype.getName = function() {
|
||||
return this.name_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return {string|undefined}
|
||||
*/
|
||||
ol.style.Rule.prototype.getTitle = function() {
|
||||
return this.title_;
|
||||
};
|
||||
@@ -1,110 +0,0 @@
|
||||
goog.provide('ol.style.ShapeLiteral');
|
||||
goog.provide('ol.style.ShapeType');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.style.PointLiteral');
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.style.ShapeType = {
|
||||
CIRCLE: 'circle'
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{type: (ol.style.ShapeType),
|
||||
* size: (number),
|
||||
* fillColor: (string|undefined),
|
||||
* fillOpacity: (number|undefined),
|
||||
* strokeColor: (string|undefined),
|
||||
* strokeOpacity: (number|undefined),
|
||||
* strokeWidth: (number|undefined),
|
||||
* zIndex: number}}
|
||||
*/
|
||||
ol.style.ShapeLiteralOptions;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.style.PointLiteral}
|
||||
* @param {ol.style.ShapeLiteralOptions} options Shape literal options.
|
||||
*/
|
||||
ol.style.ShapeLiteral = function(options) {
|
||||
|
||||
goog.asserts.assertString(options.type, 'type must be a string');
|
||||
/** @type {ol.style.ShapeType} */
|
||||
this.type = options.type;
|
||||
|
||||
goog.asserts.assertNumber(options.size, 'size must be a number');
|
||||
/** @type {number} */
|
||||
this.size = options.size;
|
||||
|
||||
/** @type {string|undefined} */
|
||||
this.fillColor = options.fillColor;
|
||||
if (goog.isDef(options.fillColor)) {
|
||||
goog.asserts.assertString(options.fillColor, 'fillColor must be a string');
|
||||
}
|
||||
|
||||
/** @type {number|undefined} */
|
||||
this.fillOpacity = options.fillOpacity;
|
||||
if (goog.isDef(options.fillOpacity)) {
|
||||
goog.asserts.assertNumber(
|
||||
options.fillOpacity, 'fillOpacity must be a number');
|
||||
}
|
||||
|
||||
/** @type {string|undefined} */
|
||||
this.strokeColor = options.strokeColor;
|
||||
if (goog.isDef(this.strokeColor)) {
|
||||
goog.asserts.assertString(
|
||||
this.strokeColor, 'strokeColor must be a string');
|
||||
}
|
||||
|
||||
/** @type {number|undefined} */
|
||||
this.strokeOpacity = options.strokeOpacity;
|
||||
if (goog.isDef(this.strokeOpacity)) {
|
||||
goog.asserts.assertNumber(
|
||||
this.strokeOpacity, 'strokeOpacity must be a number');
|
||||
}
|
||||
|
||||
/** @type {number|undefined} */
|
||||
this.strokeWidth = options.strokeWidth;
|
||||
if (goog.isDef(this.strokeWidth)) {
|
||||
goog.asserts.assertNumber(
|
||||
this.strokeWidth, 'strokeWidth must be a number');
|
||||
}
|
||||
|
||||
// fill and/or stroke properties must be defined
|
||||
var fillDef = goog.isDef(this.fillColor) && goog.isDef(this.fillOpacity);
|
||||
var strokeDef = goog.isDef(this.strokeColor) &&
|
||||
goog.isDef(this.strokeOpacity) &&
|
||||
goog.isDef(this.strokeWidth);
|
||||
goog.asserts.assert(fillDef || strokeDef,
|
||||
'Either fillColor and fillOpacity or ' +
|
||||
'strokeColor and strokeOpacity and strokeWidth must be set');
|
||||
|
||||
goog.asserts.assertNumber(
|
||||
options.zIndex, 'zIndex must be a number');
|
||||
/** @type {number} */
|
||||
this.zIndex = options.zIndex;
|
||||
|
||||
};
|
||||
goog.inherits(ol.style.ShapeLiteral, ol.style.PointLiteral);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.style.ShapeLiteral.prototype.equals = function(other) {
|
||||
return this.type == other.type &&
|
||||
this.size == other.size &&
|
||||
this.fillColor == other.fillColor &&
|
||||
this.fillOpacity == other.fillOpacity &&
|
||||
this.strokeColor == other.strokeColor &&
|
||||
this.strokeOpacity == other.strokeOpacity &&
|
||||
this.strokeWidth == other.strokeWidth &&
|
||||
this.zIndex == other.zIndex;
|
||||
};
|
||||
@@ -1,241 +0,0 @@
|
||||
goog.provide('ol.style.Shape');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Expression');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.Point');
|
||||
goog.require('ol.style.ShapeLiteral');
|
||||
goog.require('ol.style.ShapeType');
|
||||
goog.require('ol.style.Stroke');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.style.Point}
|
||||
* @param {olx.style.ShapeOptions} options Shape options.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.style.Shape = function(options) {
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @type {ol.style.ShapeType}
|
||||
* @private
|
||||
*/
|
||||
this.type_ = /** @type {ol.style.ShapeType} */ (goog.isDef(options.type) ?
|
||||
options.type : ol.style.ShapeDefaults.type);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.size_ = !goog.isDefAndNotNull(options.size) ?
|
||||
new ol.expr.Literal(ol.style.ShapeDefaults.size) :
|
||||
(options.size instanceof ol.expr.Expression) ?
|
||||
options.size : new ol.expr.Literal(options.size);
|
||||
|
||||
/**
|
||||
* @type {ol.style.Fill}
|
||||
* @private
|
||||
*/
|
||||
this.fill_ = goog.isDefAndNotNull(options.fill) ? options.fill : null;
|
||||
|
||||
/**
|
||||
* @type {ol.style.Stroke}
|
||||
* @private
|
||||
*/
|
||||
this.stroke_ = goog.isDefAndNotNull(options.stroke) ? options.stroke : null;
|
||||
|
||||
// one of stroke or fill can be null, both null is user error
|
||||
goog.asserts.assert(this.fill_ || this.stroke_,
|
||||
'Stroke or fill must be provided');
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.zIndex_ = !goog.isDefAndNotNull(options.zIndex) ?
|
||||
new ol.expr.Literal(ol.style.ShapeDefaults.zIndex) :
|
||||
(options.zIndex instanceof ol.expr.Expression) ?
|
||||
options.zIndex : new ol.expr.Literal(options.zIndex);
|
||||
|
||||
};
|
||||
goog.inherits(ol.style.Shape, ol.style.Point);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return {ol.style.ShapeLiteral} Literal shape symbolizer.
|
||||
*/
|
||||
ol.style.Shape.prototype.createLiteral = function(featureOrType) {
|
||||
var feature, type;
|
||||
if (featureOrType instanceof ol.Feature) {
|
||||
feature = featureOrType;
|
||||
var geometry = feature.getGeometry();
|
||||
type = geometry ? geometry.getType() : null;
|
||||
} else {
|
||||
type = featureOrType;
|
||||
}
|
||||
|
||||
var literal = null;
|
||||
if (type === ol.geom.GeometryType.POINT ||
|
||||
type === ol.geom.GeometryType.MULTI_POINT) {
|
||||
var size = Number(ol.expr.evaluateFeature(this.size_, feature));
|
||||
goog.asserts.assert(!isNaN(size), 'size must be a number');
|
||||
|
||||
var fillColor, fillOpacity;
|
||||
if (!goog.isNull(this.fill_)) {
|
||||
fillColor = ol.expr.evaluateFeature(this.fill_.getColor(), feature);
|
||||
goog.asserts.assertString(
|
||||
fillColor, 'fillColor must be a string');
|
||||
fillOpacity = Number(ol.expr.evaluateFeature(
|
||||
this.fill_.getOpacity(), feature));
|
||||
goog.asserts.assert(!isNaN(fillOpacity), 'fillOpacity must be a number');
|
||||
}
|
||||
|
||||
var strokeColor, strokeOpacity, strokeWidth;
|
||||
if (!goog.isNull(this.stroke_)) {
|
||||
strokeColor = ol.expr.evaluateFeature(this.stroke_.getColor(), feature);
|
||||
goog.asserts.assertString(
|
||||
strokeColor, 'strokeColor must be a string');
|
||||
strokeOpacity = Number(ol.expr.evaluateFeature(
|
||||
this.stroke_.getOpacity(), feature));
|
||||
goog.asserts.assert(!isNaN(strokeOpacity),
|
||||
'strokeOpacity must be a number');
|
||||
strokeWidth = Number(ol.expr.evaluateFeature(
|
||||
this.stroke_.getWidth(), feature));
|
||||
goog.asserts.assert(!isNaN(strokeWidth), 'strokeWidth must be a number');
|
||||
}
|
||||
|
||||
var zIndex = Number(ol.expr.evaluateFeature(this.zIndex_, feature));
|
||||
goog.asserts.assert(!isNaN(zIndex), 'zIndex must be a number');
|
||||
|
||||
literal = new ol.style.ShapeLiteral({
|
||||
type: this.type_,
|
||||
size: size,
|
||||
fillColor: fillColor,
|
||||
fillOpacity: fillOpacity,
|
||||
strokeColor: strokeColor,
|
||||
strokeOpacity: strokeOpacity,
|
||||
strokeWidth: strokeWidth,
|
||||
zIndex: zIndex
|
||||
});
|
||||
}
|
||||
|
||||
return literal;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the fill.
|
||||
* @return {ol.style.Fill} Shape fill.
|
||||
*/
|
||||
ol.style.Shape.prototype.getFill = function() {
|
||||
return this.fill_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the shape size.
|
||||
* @return {ol.expr.Expression} Shape size.
|
||||
*/
|
||||
ol.style.Shape.prototype.getSize = function() {
|
||||
return this.size_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the stroke.
|
||||
* @return {ol.style.Stroke} Shape stroke.
|
||||
*/
|
||||
ol.style.Shape.prototype.getStroke = function() {
|
||||
return this.stroke_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the shape type.
|
||||
* @return {ol.style.ShapeType} Shape type.
|
||||
*/
|
||||
ol.style.Shape.prototype.getType = function() {
|
||||
return this.type_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the shape zIndex.
|
||||
* @return {ol.expr.Expression} Shape zIndex.
|
||||
*/
|
||||
ol.style.Shape.prototype.getZIndex = function() {
|
||||
return this.zIndex_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the fill.
|
||||
* @param {ol.style.Fill} fill Shape fill.
|
||||
*/
|
||||
ol.style.Shape.prototype.setFill = function(fill) {
|
||||
if (!goog.isNull(fill)) {
|
||||
goog.asserts.assertInstanceof(fill, ol.style.Fill);
|
||||
}
|
||||
this.fill_ = fill;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the shape size.
|
||||
* @param {ol.expr.Expression} size Shape size.
|
||||
*/
|
||||
ol.style.Shape.prototype.setSize = function(size) {
|
||||
goog.asserts.assertInstanceof(size, ol.expr.Expression);
|
||||
this.size_ = size;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the stroke.
|
||||
* @param {ol.style.Stroke} stroke Shape stroke.
|
||||
*/
|
||||
ol.style.Shape.prototype.setStroke = function(stroke) {
|
||||
if (!goog.isNull(stroke)) {
|
||||
goog.asserts.assertInstanceof(stroke, ol.style.Stroke);
|
||||
}
|
||||
this.stroke_ = stroke;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the shape type.
|
||||
* @param {ol.style.ShapeType} type Shape type.
|
||||
*/
|
||||
ol.style.Shape.prototype.setType = function(type) {
|
||||
this.type_ = type;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the shape zIndex.
|
||||
* @param {ol.expr.Expression} zIndex Shape zIndex.
|
||||
*/
|
||||
ol.style.Shape.prototype.setZIndex = function(zIndex) {
|
||||
goog.asserts.assertInstanceof(zIndex, ol.expr.Expression);
|
||||
this.zIndex_ = zIndex;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{type: ol.style.ShapeType,
|
||||
* size: number,
|
||||
* zIndex: number}}
|
||||
*/
|
||||
ol.style.ShapeDefaults = {
|
||||
type: ol.style.ShapeType.CIRCLE,
|
||||
size: 5,
|
||||
zIndex: 0
|
||||
};
|
||||
@@ -1,205 +0,0 @@
|
||||
goog.provide('ol.style.Stroke');
|
||||
goog.provide('ol.style.StrokeDefaults');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Expression');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.style.LineLiteral');
|
||||
goog.require('ol.style.PolygonLiteral');
|
||||
goog.require('ol.style.Symbolizer');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.style.Symbolizer}
|
||||
* @param {olx.style.StrokeOptions=} opt_options Stroke options.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.style.Stroke = function(opt_options) {
|
||||
goog.base(this);
|
||||
var options = opt_options || {};
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.color_ = !goog.isDefAndNotNull(options.color) ?
|
||||
new ol.expr.Literal(ol.style.StrokeDefaults.color) :
|
||||
(options.color instanceof ol.expr.Expression) ?
|
||||
options.color : new ol.expr.Literal(options.color);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.opacity_ = !goog.isDefAndNotNull(options.opacity) ?
|
||||
new ol.expr.Literal(ol.style.StrokeDefaults.opacity) :
|
||||
(options.opacity instanceof ol.expr.Expression) ?
|
||||
options.opacity : new ol.expr.Literal(options.opacity);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.width_ = !goog.isDefAndNotNull(options.width) ?
|
||||
new ol.expr.Literal(ol.style.StrokeDefaults.width) :
|
||||
(options.width instanceof ol.expr.Expression) ?
|
||||
options.width : new ol.expr.Literal(options.width);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.zIndex_ = !goog.isDefAndNotNull(options.zIndex) ?
|
||||
new ol.expr.Literal(ol.style.StrokeDefaults.zIndex) :
|
||||
(options.zIndex instanceof ol.expr.Expression) ?
|
||||
options.zIndex : new ol.expr.Literal(options.zIndex);
|
||||
|
||||
};
|
||||
goog.inherits(ol.style.Stroke, ol.style.Symbolizer);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return {ol.style.LineLiteral|ol.style.PolygonLiteral} Symbolizer literal.
|
||||
*/
|
||||
ol.style.Stroke.prototype.createLiteral = function(featureOrType) {
|
||||
var feature, type;
|
||||
if (featureOrType instanceof ol.Feature) {
|
||||
feature = featureOrType;
|
||||
var geometry = feature.getGeometry();
|
||||
type = geometry ? geometry.getType() : null;
|
||||
} else {
|
||||
type = featureOrType;
|
||||
}
|
||||
|
||||
var color = ol.expr.evaluateFeature(
|
||||
this.color_, feature);
|
||||
goog.asserts.assertString(color, 'color must be a string');
|
||||
|
||||
var opacity = Number(ol.expr.evaluateFeature(
|
||||
this.opacity_, feature));
|
||||
goog.asserts.assert(!isNaN(opacity), 'opacity must be a number');
|
||||
|
||||
var width = Number(ol.expr.evaluateFeature(
|
||||
this.width_, feature));
|
||||
goog.asserts.assert(!isNaN(width), 'width must be a number');
|
||||
|
||||
var zIndex = Number(ol.expr.evaluateFeature(this.zIndex_, feature));
|
||||
goog.asserts.assert(!isNaN(zIndex), 'zIndex must be a number');
|
||||
|
||||
var literal = null;
|
||||
if (type === ol.geom.GeometryType.LINE_STRING ||
|
||||
type === ol.geom.GeometryType.MULTI_LINE_STRING) {
|
||||
literal = new ol.style.LineLiteral({
|
||||
color: color,
|
||||
opacity: opacity,
|
||||
width: width,
|
||||
zIndex: zIndex
|
||||
});
|
||||
} else if (type === ol.geom.GeometryType.POLYGON ||
|
||||
type === ol.geom.GeometryType.MULTI_POLYGON) {
|
||||
literal = new ol.style.PolygonLiteral({
|
||||
strokeColor: color,
|
||||
strokeOpacity: opacity,
|
||||
strokeWidth: width,
|
||||
zIndex: zIndex
|
||||
});
|
||||
}
|
||||
|
||||
return literal;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the stroke color.
|
||||
* @return {ol.expr.Expression} Stroke color.
|
||||
*/
|
||||
ol.style.Stroke.prototype.getColor = function() {
|
||||
return this.color_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the stroke opacity.
|
||||
* @return {ol.expr.Expression} Stroke opacity.
|
||||
*/
|
||||
ol.style.Stroke.prototype.getOpacity = function() {
|
||||
return this.opacity_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the stroke width.
|
||||
* @return {ol.expr.Expression} Stroke width.
|
||||
*/
|
||||
ol.style.Stroke.prototype.getWidth = function() {
|
||||
return this.width_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the stroke zIndex.
|
||||
* @return {ol.expr.Expression} Stroke zIndex.
|
||||
*/
|
||||
ol.style.Stroke.prototype.getZIndex = function() {
|
||||
return this.zIndex_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the stroke color.
|
||||
* @param {ol.expr.Expression} color Stroke color.
|
||||
*/
|
||||
ol.style.Stroke.prototype.setColor = function(color) {
|
||||
goog.asserts.assertInstanceof(color, ol.expr.Expression);
|
||||
this.color_ = color;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the stroke opacity.
|
||||
* @param {ol.expr.Expression} opacity Stroke opacity.
|
||||
*/
|
||||
ol.style.Stroke.prototype.setOpacity = function(opacity) {
|
||||
goog.asserts.assertInstanceof(opacity, ol.expr.Expression);
|
||||
this.opacity_ = opacity;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the stroke width.
|
||||
* @param {ol.expr.Expression} width Stroke width.
|
||||
*/
|
||||
ol.style.Stroke.prototype.setWidth = function(width) {
|
||||
goog.asserts.assertInstanceof(width, ol.expr.Expression);
|
||||
this.width_ = width;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the stroke zIndex.
|
||||
* @param {ol.expr.Expression} zIndex Stroke zIndex.
|
||||
*/
|
||||
ol.style.Stroke.prototype.setZIndex = function(zIndex) {
|
||||
goog.asserts.assertInstanceof(zIndex, ol.expr.Expression);
|
||||
this.zIndex_ = zIndex;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{strokeColor: string,
|
||||
* strokeOpacity: number,
|
||||
* strokeWidth: number,
|
||||
* zIndex: number}}
|
||||
*/
|
||||
ol.style.StrokeDefaults = {
|
||||
color: '#696969',
|
||||
opacity: 0.75,
|
||||
width: 1.5,
|
||||
zIndex: 0
|
||||
};
|
||||
@@ -1,209 +0,0 @@
|
||||
goog.provide('ol.style');
|
||||
goog.provide('ol.style.Style');
|
||||
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.functions');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.Literal');
|
||||
goog.require('ol.style.PolygonLiteral');
|
||||
goog.require('ol.style.Rule');
|
||||
goog.require('ol.style.Shape');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Symbolizer');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {ol.style.StyleOptions} options Style options.
|
||||
* @todo stability experimental
|
||||
*/
|
||||
ol.style.Style = function(options) {
|
||||
|
||||
/**
|
||||
* @type {Array.<ol.style.Rule>}
|
||||
* @private
|
||||
*/
|
||||
this.rules_ = goog.isDef(options.rules) ? options.rules : [];
|
||||
|
||||
/**
|
||||
* Symbolizers that apply if no rules are given or where none of the given
|
||||
* rules apply (these are the "else" symbolizers).
|
||||
* @type {Array.<ol.style.Symbolizer>}
|
||||
* @private
|
||||
*/
|
||||
this.symbolizers_ = goog.isDef(options.symbolizers) ?
|
||||
options.symbolizers : [];
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Create an array of symbolizer literals for a feature.
|
||||
* @param {ol.Feature} feature Feature.
|
||||
* @param {number} resolution Map resolution.
|
||||
* @return {Array.<ol.style.Literal>} Symbolizer literals for the
|
||||
* feature.
|
||||
*/
|
||||
ol.style.Style.prototype.createLiterals = function(feature, resolution) {
|
||||
var rules = this.rules_,
|
||||
symbolizers = [],
|
||||
applies = false,
|
||||
rule;
|
||||
for (var i = 0, ii = rules.length; i < ii; ++i) {
|
||||
rule = rules[i];
|
||||
if (rule.applies(feature, resolution)) {
|
||||
applies = true;
|
||||
symbolizers.push.apply(symbolizers, rule.getSymbolizers());
|
||||
}
|
||||
} if (!applies) {
|
||||
// these are the "else" symbolizers
|
||||
symbolizers = this.symbolizers_;
|
||||
}
|
||||
return ol.style.Style.createLiterals(symbolizers, feature);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The default style.
|
||||
* @type {ol.style.Style}
|
||||
* @private
|
||||
*/
|
||||
ol.style.default_ = null;
|
||||
|
||||
|
||||
/**
|
||||
* Get the default style.
|
||||
* @return {ol.style.Style} The default style.
|
||||
*/
|
||||
ol.style.getDefault = function() {
|
||||
if (goog.isNull(ol.style.default_)) {
|
||||
ol.style.default_ = new ol.style.Style({
|
||||
rules: [
|
||||
new ol.style.Rule({
|
||||
filter: new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.RENDER_INTENT),
|
||||
[new ol.expr.Literal('select')]),
|
||||
symbolizers: [
|
||||
new ol.style.Shape({
|
||||
fill: new ol.style.Fill({
|
||||
color: '#ffffff',
|
||||
opacity: 0.7
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#696969',
|
||||
opacity: 0.9,
|
||||
width: 2.0
|
||||
})
|
||||
}),
|
||||
new ol.style.Fill({
|
||||
color: '#ffffff',
|
||||
opacity: 0.7
|
||||
}),
|
||||
new ol.style.Stroke({
|
||||
color: '#696969',
|
||||
opacity: 0.9,
|
||||
width: 2.0
|
||||
})
|
||||
]
|
||||
})
|
||||
],
|
||||
symbolizers: [
|
||||
new ol.style.Shape({
|
||||
fill: new ol.style.Fill(),
|
||||
stroke: new ol.style.Stroke()
|
||||
}),
|
||||
new ol.style.Fill(),
|
||||
new ol.style.Stroke()
|
||||
]
|
||||
});
|
||||
}
|
||||
return ol.style.default_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the default style.
|
||||
* @param {ol.style.Style} style The new default style.
|
||||
* @return {ol.style.Style} The default style.
|
||||
*/
|
||||
ol.style.setDefault = function(style) {
|
||||
ol.style.default_ = style;
|
||||
return style;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Given an array of symbolizers, generate an array of literals.
|
||||
* @param {Array.<ol.style.Symbolizer>} symbolizers List of symbolizers.
|
||||
* @param {ol.Feature|ol.geom.GeometryType} featureOrType Feature or geometry
|
||||
* type.
|
||||
* @return {Array.<ol.style.Literal>} Array of literals.
|
||||
*/
|
||||
ol.style.Style.createLiterals = function(symbolizers, featureOrType) {
|
||||
var length = symbolizers.length;
|
||||
var literals = new Array(length);
|
||||
for (var i = 0; i < length; ++i) {
|
||||
literals[i] = symbolizers[i].createLiteral(featureOrType);
|
||||
}
|
||||
return ol.style.Style.reduceLiterals_(literals);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Collapse partial polygon symbolizers and remove null symbolizers.
|
||||
* @param {Array.<ol.style.Literal>} literals Input literals.
|
||||
* @return {Array.<ol.style.Literal>} Reduced literals.
|
||||
* @private
|
||||
*/
|
||||
ol.style.Style.reduceLiterals_ = function(literals) {
|
||||
var reduced = [];
|
||||
var literal, stroke, fill, key, value;
|
||||
for (var i = 0, ii = literals.length; i < ii; ++i) {
|
||||
literal = literals[i];
|
||||
if (literal instanceof ol.style.PolygonLiteral) {
|
||||
if (goog.isDef(literal.strokeColor) &&
|
||||
!goog.isDef(literal.fillColor)) {
|
||||
// stroke only, check for previous fill only
|
||||
if (fill) {
|
||||
for (key in literal) {
|
||||
value = literal[key];
|
||||
if (goog.isDef(value)) {
|
||||
fill[key] = value;
|
||||
}
|
||||
}
|
||||
fill = null;
|
||||
} else {
|
||||
stroke = literal;
|
||||
reduced.push(stroke);
|
||||
}
|
||||
} else if (goog.isDef(literal.fillColor) &&
|
||||
!goog.isDef(literal.strokeColor)) {
|
||||
// fill only, check for previous stroke only
|
||||
if (stroke) {
|
||||
for (key in literal) {
|
||||
value = literal[key];
|
||||
if (goog.isDef(value)) {
|
||||
stroke[key] = value;
|
||||
}
|
||||
}
|
||||
stroke = null;
|
||||
} else {
|
||||
fill = literal;
|
||||
reduced.push(fill);
|
||||
}
|
||||
} else {
|
||||
// both stroke and fill, proceed
|
||||
reduced.push(literal);
|
||||
}
|
||||
} else if (literal) {
|
||||
reduced.push(literal);
|
||||
}
|
||||
}
|
||||
return reduced;
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
goog.provide('ol.style.Symbolizer');
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.style.Literal');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
ol.style.Symbolizer = function() {};
|
||||
|
||||
|
||||
/**
|
||||
* Create a literal from the symbolizer given a complete feature or a geometry
|
||||
* type.
|
||||
* @param {ol.geom.GeometryType|ol.Feature} featureOrType Feature for evaluating
|
||||
* expressions or a geometry type.
|
||||
* @return {ol.style.Literal} Literal symbolizer.
|
||||
*/
|
||||
ol.style.Symbolizer.prototype.createLiteral = goog.abstractMethod;
|
||||
@@ -1,106 +0,0 @@
|
||||
goog.provide('ol.style.TextLiteral');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.style.Literal');
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{color: string,
|
||||
* fontFamily: string,
|
||||
* fontSize: number,
|
||||
* fontWeight: string,
|
||||
* text: string,
|
||||
* opacity: number,
|
||||
* strokeColor: (string|undefined),
|
||||
* strokeOpacity: (number|undefined),
|
||||
* strokeWidth: (number|undefined),
|
||||
* zIndex: number}}
|
||||
*/
|
||||
ol.style.TextLiteralOptions;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.style.Literal}
|
||||
* @param {ol.style.TextLiteralOptions} options Text literal options.
|
||||
*/
|
||||
ol.style.TextLiteral = function(options) {
|
||||
|
||||
goog.asserts.assertString(options.color, 'color must be a string');
|
||||
/** @type {string} */
|
||||
this.color = options.color;
|
||||
|
||||
goog.asserts.assertString(options.fontFamily, 'fontFamily must be a string');
|
||||
/** @type {string} */
|
||||
this.fontFamily = options.fontFamily;
|
||||
|
||||
goog.asserts.assertNumber(options.fontSize, 'fontSize must be a number');
|
||||
/** @type {number} */
|
||||
this.fontSize = options.fontSize;
|
||||
|
||||
goog.asserts.assertString(options.fontWeight, 'fontWeight must be a string');
|
||||
/** @type {string} */
|
||||
this.fontWeight = options.fontWeight;
|
||||
|
||||
goog.asserts.assertString(options.text, 'text must be a string');
|
||||
/** @type {string} */
|
||||
this.text = options.text;
|
||||
|
||||
goog.asserts.assertNumber(options.opacity, 'opacity must be a number');
|
||||
/** @type {number} */
|
||||
this.opacity = options.opacity;
|
||||
|
||||
/** @type {string|undefined} */
|
||||
this.strokeColor = options.strokeColor;
|
||||
if (goog.isDef(this.strokeColor)) {
|
||||
goog.asserts.assertString(
|
||||
this.strokeColor, 'strokeColor must be a string');
|
||||
}
|
||||
|
||||
/** @type {number|undefined} */
|
||||
this.strokeOpacity = options.strokeOpacity;
|
||||
if (goog.isDef(this.strokeOpacity)) {
|
||||
goog.asserts.assertNumber(
|
||||
this.strokeOpacity, 'strokeOpacity must be a number');
|
||||
}
|
||||
|
||||
/** @type {number|undefined} */
|
||||
this.strokeWidth = options.strokeWidth;
|
||||
if (goog.isDef(this.strokeWidth)) {
|
||||
goog.asserts.assertNumber(
|
||||
this.strokeWidth, 'strokeWidth must be a number');
|
||||
}
|
||||
|
||||
// if any stroke property is defined, all must be defined
|
||||
var strokeDef = goog.isDef(this.strokeColor) &&
|
||||
goog.isDef(this.strokeOpacity) &&
|
||||
goog.isDef(this.strokeWidth);
|
||||
var strokeUndef = !goog.isDef(this.strokeColor) &&
|
||||
!goog.isDef(this.strokeOpacity) &&
|
||||
!goog.isDef(this.strokeWidth);
|
||||
goog.asserts.assert(strokeDef || strokeUndef,
|
||||
'If any stroke property is defined, all must be defined');
|
||||
|
||||
goog.asserts.assertNumber(options.zIndex, 'zIndex must be a number');
|
||||
/** @type {number} */
|
||||
this.zIndex = options.zIndex;
|
||||
|
||||
};
|
||||
goog.inherits(ol.style.TextLiteral, ol.style.Literal);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.style.TextLiteral.prototype.equals = function(other) {
|
||||
return this.color == other.color &&
|
||||
this.fontFamily == other.fontFamily &&
|
||||
this.fontSize == other.fontSize &&
|
||||
this.fontWeight == other.fontWeight &&
|
||||
this.opacity == other.opacity &&
|
||||
this.strokeColor == other.strokeColor &&
|
||||
this.strokeOpacity == other.strokeOpacity &&
|
||||
this.strokeWidth == other.strokeWidth &&
|
||||
this.zIndex == other.zIndex;
|
||||
};
|
||||
@@ -1,312 +0,0 @@
|
||||
goog.provide('ol.style.Text');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Expression');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.style.Symbolizer');
|
||||
goog.require('ol.style.TextLiteral');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends {ol.style.Symbolizer}
|
||||
* @param {olx.style.TextOptions} options Text options.
|
||||
*/
|
||||
ol.style.Text = function(options) {
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.color_ = !goog.isDef(options.color) ?
|
||||
new ol.expr.Literal(ol.style.TextDefaults.color) :
|
||||
(options.color instanceof ol.expr.Expression) ?
|
||||
options.color : new ol.expr.Literal(options.color);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.fontFamily_ = !goog.isDef(options.fontFamily) ?
|
||||
new ol.expr.Literal(ol.style.TextDefaults.fontFamily) :
|
||||
(options.fontFamily instanceof ol.expr.Expression) ?
|
||||
options.fontFamily : new ol.expr.Literal(options.fontFamily);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.fontSize_ = !goog.isDef(options.fontSize) ?
|
||||
new ol.expr.Literal(ol.style.TextDefaults.fontSize) :
|
||||
(options.fontSize instanceof ol.expr.Expression) ?
|
||||
options.fontSize : new ol.expr.Literal(options.fontSize);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.fontWeight_ = !goog.isDef(options.fontWeight) ?
|
||||
new ol.expr.Literal(ol.style.TextDefaults.fontWeight) :
|
||||
(options.fontWeight instanceof ol.expr.Expression) ?
|
||||
options.fontWeight : new ol.expr.Literal(options.fontWeight);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.text_ = (options.text instanceof ol.expr.Expression) ?
|
||||
options.text : new ol.expr.Literal(options.text);
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.opacity_ = !goog.isDef(options.opacity) ?
|
||||
new ol.expr.Literal(ol.style.TextDefaults.opacity) :
|
||||
(options.opacity instanceof ol.expr.Expression) ?
|
||||
options.opacity : new ol.expr.Literal(options.opacity);
|
||||
|
||||
/**
|
||||
* @type {ol.style.Stroke}
|
||||
* @private
|
||||
*/
|
||||
this.stroke_ = goog.isDefAndNotNull(options.stroke) ? options.stroke : null;
|
||||
|
||||
/**
|
||||
* @type {ol.expr.Expression}
|
||||
* @private
|
||||
*/
|
||||
this.zIndex_ = !goog.isDefAndNotNull(options.zIndex) ?
|
||||
new ol.expr.Literal(ol.style.TextDefaults.zIndex) :
|
||||
(options.zIndex instanceof ol.expr.Expression) ?
|
||||
options.zIndex : new ol.expr.Literal(options.zIndex);
|
||||
|
||||
};
|
||||
goog.inherits(ol.style.Text, ol.style.Symbolizer);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return {ol.style.TextLiteral} Literal text symbolizer.
|
||||
*/
|
||||
ol.style.Text.prototype.createLiteral = function(featureOrType) {
|
||||
var feature, type;
|
||||
if (featureOrType instanceof ol.Feature) {
|
||||
feature = featureOrType;
|
||||
var geometry = feature.getGeometry();
|
||||
type = geometry ? geometry.getType() : null;
|
||||
} else {
|
||||
type = featureOrType;
|
||||
}
|
||||
|
||||
var color = ol.expr.evaluateFeature(this.color_, feature);
|
||||
goog.asserts.assertString(color, 'color must be a string');
|
||||
|
||||
var fontFamily = ol.expr.evaluateFeature(this.fontFamily_, feature);
|
||||
goog.asserts.assertString(fontFamily, 'fontFamily must be a string');
|
||||
|
||||
var fontSize = Number(ol.expr.evaluateFeature(this.fontSize_, feature));
|
||||
goog.asserts.assert(!isNaN(fontSize), 'fontSize must be a number');
|
||||
|
||||
var fontWeight = ol.expr.evaluateFeature(this.fontWeight_, feature);
|
||||
goog.asserts.assertString(fontWeight, 'fontWeight must be a string');
|
||||
|
||||
var text = ol.expr.evaluateFeature(this.text_, feature);
|
||||
goog.asserts.assertString(text, 'text must be a string');
|
||||
|
||||
var opacity = Number(ol.expr.evaluateFeature(this.opacity_, feature));
|
||||
goog.asserts.assert(!isNaN(opacity), 'opacity must be a number');
|
||||
|
||||
var strokeColor, strokeOpacity, strokeWidth;
|
||||
if (!goog.isNull(this.stroke_)) {
|
||||
strokeColor = ol.expr.evaluateFeature(this.stroke_.getColor(), feature);
|
||||
goog.asserts.assertString(
|
||||
strokeColor, 'strokeColor must be a string');
|
||||
strokeOpacity = Number(ol.expr.evaluateFeature(
|
||||
this.stroke_.getOpacity(), feature));
|
||||
goog.asserts.assert(!isNaN(strokeOpacity),
|
||||
'strokeOpacity must be a number');
|
||||
strokeWidth = Number(ol.expr.evaluateFeature(
|
||||
this.stroke_.getWidth(), feature));
|
||||
goog.asserts.assert(!isNaN(strokeWidth), 'strokeWidth must be a number');
|
||||
}
|
||||
|
||||
var zIndex = Number(ol.expr.evaluateFeature(this.zIndex_, feature));
|
||||
goog.asserts.assert(!isNaN(zIndex), 'zIndex must be a number');
|
||||
|
||||
return new ol.style.TextLiteral({
|
||||
color: color,
|
||||
fontFamily: fontFamily,
|
||||
fontSize: fontSize,
|
||||
fontWeight: fontWeight,
|
||||
text: text,
|
||||
opacity: opacity,
|
||||
strokeColor: strokeColor,
|
||||
strokeOpacity: strokeOpacity,
|
||||
strokeWidth: strokeWidth,
|
||||
zIndex: zIndex
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the font color.
|
||||
* @return {ol.expr.Expression} Font color.
|
||||
*/
|
||||
ol.style.Text.prototype.getColor = function() {
|
||||
return this.color_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the font family.
|
||||
* @return {ol.expr.Expression} Font family.
|
||||
*/
|
||||
ol.style.Text.prototype.getFontFamily = function() {
|
||||
return this.fontFamily_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the font size.
|
||||
* @return {ol.expr.Expression} Font size.
|
||||
*/
|
||||
ol.style.Text.prototype.getFontSize = function() {
|
||||
return this.fontSize_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the font weight.
|
||||
* @return {ol.expr.Expression} Font weight.
|
||||
*/
|
||||
ol.style.Text.prototype.getFontWeight = function() {
|
||||
return this.fontWeight_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the opacity.
|
||||
* @return {ol.expr.Expression} Opacity.
|
||||
*/
|
||||
ol.style.Text.prototype.getOpacity = function() {
|
||||
return this.opacity_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the text.
|
||||
* @return {ol.expr.Expression} Text.
|
||||
*/
|
||||
ol.style.Text.prototype.getText = function() {
|
||||
return this.text_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the zIndex.
|
||||
* @return {ol.expr.Expression} Text.
|
||||
*/
|
||||
ol.style.Text.prototype.getZIndex = function() {
|
||||
return this.zIndex_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the stroke.
|
||||
* @return {ol.style.Stroke} Stroke.
|
||||
*/
|
||||
ol.style.Text.prototype.getStroke = function() {
|
||||
return this.stroke_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the font color.
|
||||
* @param {ol.expr.Expression} color Font color.
|
||||
*/
|
||||
ol.style.Text.prototype.setColor = function(color) {
|
||||
goog.asserts.assertInstanceof(color, ol.expr.Expression);
|
||||
this.color_ = color;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the font family.
|
||||
* @param {ol.expr.Expression} fontFamily Font family.
|
||||
*/
|
||||
ol.style.Text.prototype.setFontFamily = function(fontFamily) {
|
||||
goog.asserts.assertInstanceof(fontFamily, ol.expr.Expression);
|
||||
this.fontFamily_ = fontFamily;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the font size.
|
||||
* @param {ol.expr.Expression} fontSize Font size.
|
||||
*/
|
||||
ol.style.Text.prototype.setFontSize = function(fontSize) {
|
||||
goog.asserts.assertInstanceof(fontSize, ol.expr.Expression);
|
||||
this.fontSize_ = fontSize;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the font weight.
|
||||
* @param {ol.expr.Expression} fontWeight Font weight.
|
||||
*/
|
||||
ol.style.Text.prototype.setFontWeight = function(fontWeight) {
|
||||
goog.asserts.assertInstanceof(fontWeight, ol.expr.Expression);
|
||||
this.fontWeight_ = fontWeight;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the opacity.
|
||||
* @param {ol.expr.Expression} opacity Opacity.
|
||||
*/
|
||||
ol.style.Text.prototype.setOpacity = function(opacity) {
|
||||
goog.asserts.assertInstanceof(opacity, ol.expr.Expression);
|
||||
this.opacity_ = opacity;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the text.
|
||||
* @param {ol.expr.Expression} text Text.
|
||||
*/
|
||||
ol.style.Text.prototype.setText = function(text) {
|
||||
goog.asserts.assertInstanceof(text, ol.expr.Expression);
|
||||
this.text_ = text;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the zIndex.
|
||||
* @param {ol.expr.Expression} zIndex Text.
|
||||
*/
|
||||
ol.style.Text.prototype.setZIndex = function(zIndex) {
|
||||
goog.asserts.assertInstanceof(zIndex, ol.expr.Expression);
|
||||
this.zIndex_ = zIndex;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{color: string,
|
||||
* fontFamily: string,
|
||||
* fontSize: number,
|
||||
* fontWeight: string,
|
||||
* opacity: number,
|
||||
* zIndex: number}}
|
||||
*/
|
||||
ol.style.TextDefaults = {
|
||||
color: '#000',
|
||||
fontFamily: 'sans-serif',
|
||||
fontSize: 10,
|
||||
fontWeight: 'normal',
|
||||
opacity: 1,
|
||||
zIndex: 0
|
||||
};
|
||||
@@ -1,979 +0,0 @@
|
||||
goog.provide('ol.test.expression');
|
||||
|
||||
|
||||
describe('ol.expr.parse()', function() {
|
||||
|
||||
it('parses a subset of ECMAScript 5.1 expressions', function() {
|
||||
var expr = ol.expr.parse('foo');
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
});
|
||||
|
||||
describe('11.1 - primary expressions', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.1
|
||||
|
||||
it('parses identifier expressions', function() {
|
||||
var expr = ol.expr.parse('foo');
|
||||
expect(expr).to.be.a(ol.expr.Identifier);
|
||||
expect(expr.evaluate({foo: 'bar'})).to.be('bar');
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected', function() {
|
||||
var expr = ol.expr.parse(' foo ');
|
||||
expect(expr).to.be.a(ol.expr.Identifier);
|
||||
expect(expr.evaluate({foo: 'bar'})).to.be('bar');
|
||||
});
|
||||
|
||||
it('throws on invalid identifier expressions', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse('3foo');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('f');
|
||||
expect(token.index).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses string literal expressions', function() {
|
||||
var expr = ol.expr.parse('"foo"');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be('foo');
|
||||
});
|
||||
|
||||
it('throws on unterminated string', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse('"foo');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.type).to.be(ol.expr.TokenType.EOF);
|
||||
expect(token.index).to.be(4);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses numeric literal expressions', function() {
|
||||
var expr = ol.expr.parse('.42e+2');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be(42);
|
||||
});
|
||||
|
||||
it('throws on invalid number', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse('.42eX');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('X');
|
||||
expect(token.index).to.be(4);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses boolean literal expressions', function() {
|
||||
var expr = ol.expr.parse('false');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be(false);
|
||||
});
|
||||
|
||||
it('parses null literal expressions', function() {
|
||||
var expr = ol.expr.parse('null');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be(null);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('11.2 - left-hand-side expressions', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.2
|
||||
|
||||
it('parses member expressions with dot notation', function() {
|
||||
var expr = ol.expr.parse('foo.bar.baz');
|
||||
expect(expr).to.be.a(ol.expr.Member);
|
||||
var scope = {foo: {bar: {baz: 42}}};
|
||||
expect(expr.evaluate(scope)).to.be(42);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected', function() {
|
||||
var expr = ol.expr.parse(' foo . bar . baz ');
|
||||
expect(expr).to.be.a(ol.expr.Member);
|
||||
var scope = {foo: {bar: {baz: 42}}};
|
||||
expect(expr.evaluate(scope)).to.be(42);
|
||||
});
|
||||
|
||||
it('throws on invalid member expression', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse('foo.4bar');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('b');
|
||||
expect(token.index).to.be(5);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses call expressions with literal arguments', function() {
|
||||
var expr = ol.expr.parse('foo(42, "bar")');
|
||||
expect(expr).to.be.a(ol.expr.Call);
|
||||
var scope = {
|
||||
foo: function(num, str) {
|
||||
expect(num).to.be(42);
|
||||
expect(str).to.be('bar');
|
||||
return str + num;
|
||||
}
|
||||
};
|
||||
expect(expr.evaluate(scope)).to.be('bar42');
|
||||
});
|
||||
|
||||
it('throws on calls with unterminated arguments', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse('foo(42,)');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be(')');
|
||||
expect(token.index).to.be(7);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('11.3 - postfix expressions', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.3
|
||||
it('not supported');
|
||||
});
|
||||
|
||||
|
||||
describe('11.4 - unary operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.4
|
||||
|
||||
it('parses logical not operator', function() {
|
||||
var expr = ol.expr.parse('!foo');
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
expect(expr.evaluate({foo: true})).to.be(false);
|
||||
expect(expr.evaluate({foo: false})).to.be(true);
|
||||
expect(expr.evaluate({foo: ''})).to.be(true);
|
||||
expect(expr.evaluate({foo: 'foo'})).to.be(false);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected', function() {
|
||||
var expr = ol.expr.parse(' ! foo');
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
expect(expr.evaluate({foo: true})).to.be(false);
|
||||
expect(expr.evaluate({foo: false})).to.be(true);
|
||||
});
|
||||
|
||||
it('parses not preceeding call expression', function() {
|
||||
var lib = {
|
||||
foo: function() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
var expr = ol.expr.parse('!foo()');
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
expect(expr.evaluate(null, lib)).to.be(false);
|
||||
});
|
||||
|
||||
it('parses not in call argument', function() {
|
||||
var lib = {
|
||||
foo: function(arg) {
|
||||
return arg;
|
||||
}
|
||||
};
|
||||
var expr = ol.expr.parse('foo(!bar)');
|
||||
expect(expr).to.be.a(ol.expr.Call);
|
||||
expect(expr.evaluate({bar: true}, lib)).to.be(false);
|
||||
expect(expr.evaluate({bar: false}, lib)).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('11.5 - multiplicitave operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.5
|
||||
|
||||
it('parses * operator', function() {
|
||||
var expr = ol.expr.parse('foo*bar');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 10, bar: 20})).to.be(200);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with *', function() {
|
||||
var expr = ol.expr.parse(' foo * bar ');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 15, bar: 2})).to.be(30);
|
||||
});
|
||||
|
||||
it('parses / operator', function() {
|
||||
var expr = ol.expr.parse('foo/12');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 10})).to.be(10 / 12);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with /', function() {
|
||||
var expr = ol.expr.parse(' 4 / bar ');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({bar: 3})).to.be(4 / 3);
|
||||
});
|
||||
|
||||
it('parses % operator', function() {
|
||||
var expr = ol.expr.parse('12%foo');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 10})).to.be(2);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with %', function() {
|
||||
var expr = ol.expr.parse(' 4 %bar ');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({bar: 3})).to.be(1);
|
||||
});
|
||||
|
||||
it('parses * in call argument', function() {
|
||||
var lib = {
|
||||
foo: function(arg) {
|
||||
return arg;
|
||||
}
|
||||
};
|
||||
var expr = ol.expr.parse('foo(2 * bar)');
|
||||
expect(expr).to.be.a(ol.expr.Call);
|
||||
expect(expr.evaluate({bar: 3}, lib)).to.be(6);
|
||||
expect(expr.evaluate({bar: 4}, lib)).to.be(8);
|
||||
});
|
||||
|
||||
it('evaluates left to right for equal precedence', function() {
|
||||
var expr = ol.expr.parse('2 / 4 * 20 % 15');
|
||||
expect(expr.evaluate()).to.be(10);
|
||||
});
|
||||
|
||||
it('respects group precedence', function() {
|
||||
expect(ol.expr.parse('2 / 4 * (20 % 15)').evaluate()).to.be(2.5);
|
||||
expect(ol.expr.parse('2 / (4 * (20 % 15))').evaluate()).to.be(0.1);
|
||||
expect(ol.expr.parse('2 / ((4 * 20) % 15)').evaluate()).to.be(0.4);
|
||||
expect(ol.expr.parse('2 / (4 * 20) % 15').evaluate()).to.be(0.025);
|
||||
expect(ol.expr.parse('(2 / (4 * 20)) % 15').evaluate()).to.be(0.025);
|
||||
expect(ol.expr.parse('(2 / 4) * 20 % 15').evaluate()).to.be(10);
|
||||
expect(ol.expr.parse('((2 / 4) * 20) % 15').evaluate()).to.be(10);
|
||||
});
|
||||
|
||||
it('parses * in left side of comparison expression', function() {
|
||||
var expr = ol.expr.parse('foo * 2 >bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 4, bar: 7})).to.be(true);
|
||||
expect(expr.evaluate({foo: 4, bar: 8})).to.be(false);
|
||||
});
|
||||
|
||||
it('parses * in right side of comparison expression', function() {
|
||||
var expr = ol.expr.parse('foo > 2 * bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 4, bar: 1})).to.be(true);
|
||||
expect(expr.evaluate({foo: 4, bar: 2})).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('11.6 - additive operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.6
|
||||
|
||||
it('parses + operator', function() {
|
||||
var expr = ol.expr.parse('foo+bar');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 10, bar: 20})).to.be(30);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with +', function() {
|
||||
var expr = ol.expr.parse(' foo +10 ');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 15})).to.be(25);
|
||||
});
|
||||
|
||||
it('parses - operator', function() {
|
||||
var expr = ol.expr.parse('foo-bar');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 10, bar: 20})).to.be(-10);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with -', function() {
|
||||
var expr = ol.expr.parse(' foo- 10 ');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 15})).to.be(5);
|
||||
});
|
||||
|
||||
it('respects precedence', function() {
|
||||
expect(ol.expr.parse('2 + 4 * 20 - 15').evaluate()).to.be(67);
|
||||
expect(ol.expr.parse('(2 + 4) * 20 - 15').evaluate()).to.be(105);
|
||||
expect(ol.expr.parse('((2 + 4) * 20) - 15').evaluate()).to.be(105);
|
||||
expect(ol.expr.parse('(2 + (4 * 20)) - 15').evaluate()).to.be(67);
|
||||
expect(ol.expr.parse('2 + (4 * 20) - 15').evaluate()).to.be(67);
|
||||
expect(ol.expr.parse('2 + ((4 * 20) - 15)').evaluate()).to.be(67);
|
||||
expect(ol.expr.parse('2 + (4 * (20 - 15))').evaluate()).to.be(22);
|
||||
expect(ol.expr.parse('2 + 4 * (20 - 15)').evaluate()).to.be(22);
|
||||
});
|
||||
|
||||
it('parses + in call argument', function() {
|
||||
var lib = {
|
||||
foo: function(arg) {
|
||||
return arg;
|
||||
}
|
||||
};
|
||||
var expr = ol.expr.parse('foo(2 + bar)');
|
||||
expect(expr).to.be.a(ol.expr.Call);
|
||||
expect(expr.evaluate({bar: 3}, lib)).to.be(5);
|
||||
expect(expr.evaluate({bar: 4}, lib)).to.be(6);
|
||||
});
|
||||
|
||||
it('parses + in left side of comparison expression', function() {
|
||||
var expr = ol.expr.parse('foo+2>bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 4, bar: 5})).to.be(true);
|
||||
expect(expr.evaluate({foo: 4, bar: 6})).to.be(false);
|
||||
});
|
||||
|
||||
it('parses + in right side of comparison expression', function() {
|
||||
var expr = ol.expr.parse('foo >2 +bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 4, bar: 1})).to.be(true);
|
||||
expect(expr.evaluate({foo: 4, bar: 2})).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('11.7 - bitwise shift operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.7
|
||||
it('not supported');
|
||||
});
|
||||
|
||||
describe('11.8 - relational operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.8
|
||||
|
||||
it('parses < operator', function() {
|
||||
var expr = ol.expr.parse('foo<bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 10, bar: 20})).to.be(true);
|
||||
expect(expr.evaluate({foo: 100, bar: 20})).to.be(false);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with <', function() {
|
||||
var expr = ol.expr.parse(' foo <10 ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 15})).to.be(false);
|
||||
expect(expr.evaluate({foo: 5})).to.be(true);
|
||||
});
|
||||
|
||||
it('parses > operator', function() {
|
||||
var expr = ol.expr.parse('foo>bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 10, bar: 20})).to.be(false);
|
||||
expect(expr.evaluate({foo: 100, bar: 20})).to.be(true);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with >', function() {
|
||||
var expr = ol.expr.parse(' foo> 10 ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 15})).to.be(true);
|
||||
expect(expr.evaluate({foo: 5})).to.be(false);
|
||||
});
|
||||
|
||||
it('parses <= operator', function() {
|
||||
var expr = ol.expr.parse('foo<=bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 10, bar: 20})).to.be(true);
|
||||
expect(expr.evaluate({foo: 100, bar: 20})).to.be(false);
|
||||
expect(expr.evaluate({foo: 20, bar: 20})).to.be(true);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with <=', function() {
|
||||
var expr = ol.expr.parse(' foo<= 10 ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 15})).to.be(false);
|
||||
expect(expr.evaluate({foo: 5})).to.be(true);
|
||||
expect(expr.evaluate({foo: 10})).to.be(true);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with <=', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse(' foo< = 10 ');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('=');
|
||||
expect(token.index).to.be(6);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses >= operator', function() {
|
||||
var expr = ol.expr.parse('foo>=bar');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 10, bar: 20})).to.be(false);
|
||||
expect(expr.evaluate({foo: 100, bar: 20})).to.be(true);
|
||||
expect(expr.evaluate({foo: 20, bar: 20})).to.be(true);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with >=', function() {
|
||||
var expr = ol.expr.parse(' foo >=10 ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 15})).to.be(true);
|
||||
expect(expr.evaluate({foo: 5})).to.be(false);
|
||||
expect(expr.evaluate({foo: 10})).to.be(true);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with >=', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse(' 10 > =foo ');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('=');
|
||||
expect(token.index).to.be(6);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('11.9 - equality operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.9
|
||||
|
||||
it('parses == operator', function() {
|
||||
var expr = ol.expr.parse('foo==42');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: 41})).to.be(false);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(true);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with ==', function() {
|
||||
var expr = ol.expr.parse(' 42 ==foo ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: 41})).to.be(false);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(true);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with ==', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse(' 10 = =foo ');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('=');
|
||||
expect(token.index).to.be(4);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses != operator', function() {
|
||||
var expr = ol.expr.parse('foo!=42');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: 41})).to.be(true);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(false);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with !=', function() {
|
||||
var expr = ol.expr.parse(' 42 !=foo ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: 41})).to.be(true);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(false);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with !=', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse(' 10! =foo ');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('!');
|
||||
expect(token.index).to.be(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses === operator', function() {
|
||||
var expr = ol.expr.parse('42===foo');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: 41})).to.be(false);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(false);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with ===', function() {
|
||||
var expr = ol.expr.parse(' foo ===42 ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: 41})).to.be(false);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(false);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with ===', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse(' 10 = == foo ');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('=');
|
||||
expect(token.index).to.be(4);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses !== operator', function() {
|
||||
var expr = ol.expr.parse('foo!==42');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: 41})).to.be(true);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(true);
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected with !==', function() {
|
||||
var expr = ol.expr.parse(' 42 !== foo ');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: 41})).to.be(true);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(true);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with !==', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse(' 10 != = foo ');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('=');
|
||||
expect(token.index).to.be(7);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('11.10 - binary bitwise operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.10
|
||||
it('not supported');
|
||||
});
|
||||
|
||||
describe('11.11 - binary logical operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.11
|
||||
|
||||
it('parses && operator', function() {
|
||||
var expr = ol.expr.parse('foo&&bar');
|
||||
expect(expr).to.be.a(ol.expr.Logical);
|
||||
expect(expr.evaluate({foo: true, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: true, bar: false})).to.be(false);
|
||||
expect(expr.evaluate({foo: false, bar: true})).to.be(false);
|
||||
expect(expr.evaluate({foo: false, bar: false})).to.be(false);
|
||||
});
|
||||
|
||||
it('consumes space as expected with &&', function() {
|
||||
var expr = ol.expr.parse(' foo && bar ');
|
||||
expect(expr).to.be.a(ol.expr.Logical);
|
||||
expect(expr.evaluate({foo: true, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: true, bar: false})).to.be(false);
|
||||
expect(expr.evaluate({foo: false, bar: true})).to.be(false);
|
||||
expect(expr.evaluate({foo: false, bar: false})).to.be(false);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with &&', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse('true & & false');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('&');
|
||||
expect(token.index).to.be(5);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses || operator', function() {
|
||||
var expr = ol.expr.parse('foo||bar');
|
||||
expect(expr).to.be.a(ol.expr.Logical);
|
||||
expect(expr.evaluate({foo: true, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: true, bar: false})).to.be(true);
|
||||
expect(expr.evaluate({foo: false, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: false, bar: false})).to.be(false);
|
||||
});
|
||||
|
||||
it('consumes space as expected with ||', function() {
|
||||
var expr = ol.expr.parse(' foo || bar ');
|
||||
expect(expr).to.be.a(ol.expr.Logical);
|
||||
expect(expr.evaluate({foo: true, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: true, bar: false})).to.be(true);
|
||||
expect(expr.evaluate({foo: false, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: false, bar: false})).to.be(false);
|
||||
});
|
||||
|
||||
it('throws for invalid spacing with ||', function() {
|
||||
expect(function() {
|
||||
ol.expr.parse('true | | false');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('|');
|
||||
expect(token.index).to.be(5);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('11.12 - conditional operator', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.12
|
||||
it('not supported');
|
||||
});
|
||||
|
||||
describe('11.13 - assignment operators', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.13
|
||||
it('not supported');
|
||||
});
|
||||
|
||||
describe('11.14 - comma operator', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.14
|
||||
it('not supported');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.expr.lib', function() {
|
||||
|
||||
var parse = ol.expr.parse;
|
||||
var evaluate = ol.expr.evaluateFeature;
|
||||
|
||||
describe('concat()', function() {
|
||||
var feature = new ol.Feature({
|
||||
str: 'bar',
|
||||
num: 42,
|
||||
bool: false,
|
||||
nul: null
|
||||
});
|
||||
|
||||
it('concatenates strings', function() {
|
||||
expect(evaluate(parse('concat(str, "after")'), feature))
|
||||
.to.be('barafter');
|
||||
expect(evaluate(parse('concat("before", str)'), feature))
|
||||
.to.be('beforebar');
|
||||
expect(evaluate(parse('concat("a", str, "b")'), feature))
|
||||
.to.be('abarb');
|
||||
});
|
||||
|
||||
it('concatenates numbers as strings', function() {
|
||||
expect(evaluate(parse('concat(num, 0)'), feature))
|
||||
.to.be('420');
|
||||
expect(evaluate(parse('concat(0, num)'), feature))
|
||||
.to.be('042');
|
||||
expect(evaluate(parse('concat(42, 42)'), feature))
|
||||
.to.be('4242');
|
||||
expect(evaluate(parse('concat(str, num)'), feature))
|
||||
.to.be('bar42');
|
||||
});
|
||||
|
||||
it('concatenates booleans as strings', function() {
|
||||
expect(evaluate(parse('concat(bool, "foo")'), feature))
|
||||
.to.be('falsefoo');
|
||||
expect(evaluate(parse('concat(true, str)'), feature))
|
||||
.to.be('truebar');
|
||||
expect(evaluate(parse('concat(true, false)'), feature))
|
||||
.to.be('truefalse');
|
||||
});
|
||||
|
||||
it('concatenates nulls as strings', function() {
|
||||
expect(evaluate(parse('concat(nul, "foo")'), feature))
|
||||
.to.be('nullfoo');
|
||||
expect(evaluate(parse('concat(str, null)'), feature))
|
||||
.to.be('barnull');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('counter()', function() {
|
||||
|
||||
it('increases the counter with every call', function() {
|
||||
var counter = parse('counter()');
|
||||
var start = evaluate(counter);
|
||||
expect(evaluate(counter)).to.be(start + 1);
|
||||
expect(evaluate(counter)).to.be(start + 2);
|
||||
});
|
||||
|
||||
it('increases the counter, starting with a custom value', function() {
|
||||
var counterWithStart = parse('counter(1000)');
|
||||
var start = evaluate(counterWithStart);
|
||||
expect(start > 1000).to.be(true);
|
||||
expect(evaluate(counterWithStart)).to.be(start + 1);
|
||||
expect(evaluate(counterWithStart)).to.be(start + 2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('extent()', function() {
|
||||
|
||||
var nw = new ol.Feature({
|
||||
geom: new ol.geom.Polygon([[
|
||||
[-180, 90], [0, 90], [0, 0], [-180, 0], [-180, 90]
|
||||
]])
|
||||
});
|
||||
|
||||
var se = new ol.Feature({
|
||||
geom: new ol.geom.Polygon([[
|
||||
[180, -90], [0, -90], [0, 0], [180, 0], [180, -90]
|
||||
]])
|
||||
});
|
||||
|
||||
var north = parse('extent(-100, 40, 100, 60)');
|
||||
var south = parse('extent(-100, -60, 100, -40)');
|
||||
var east = parse('extent(80, -50, 100, 50)');
|
||||
var west = parse('extent(-100, -50, -80, 50)');
|
||||
|
||||
it('evaluates to true for features within given extent', function() {
|
||||
|
||||
expect(evaluate(north, nw)).to.be(true);
|
||||
expect(evaluate(south, nw)).to.be(false);
|
||||
expect(evaluate(east, nw)).to.be(false);
|
||||
expect(evaluate(west, nw)).to.be(true);
|
||||
|
||||
expect(evaluate(north, se)).to.be(false);
|
||||
expect(evaluate(south, se)).to.be(true);
|
||||
expect(evaluate(east, se)).to.be(true);
|
||||
expect(evaluate(west, se)).to.be(false);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('fid()', function() {
|
||||
|
||||
var one = new ol.Feature();
|
||||
one.setId('one');
|
||||
|
||||
var two = new ol.Feature();
|
||||
two.setId('two');
|
||||
|
||||
var three = new ol.Feature();
|
||||
three.setId('three');
|
||||
|
||||
var four = new ol.Feature();
|
||||
four.setId('four');
|
||||
|
||||
var odd = parse('fid("one", "three")');
|
||||
var even = parse('fid("two", "four")');
|
||||
var first = parse('fid("one")');
|
||||
var last = parse('fid("four")');
|
||||
var none = parse('fid("foo")');
|
||||
|
||||
it('evaluates to true if feature id matches', function() {
|
||||
expect(evaluate(odd, one)).to.be(true);
|
||||
expect(evaluate(odd, three)).to.be(true);
|
||||
expect(evaluate(even, two)).to.be(true);
|
||||
expect(evaluate(even, four)).to.be(true);
|
||||
expect(evaluate(first, one)).to.be(true);
|
||||
expect(evaluate(last, four)).to.be(true);
|
||||
});
|
||||
|
||||
it('evaluates to false if feature id doesn\'t match', function() {
|
||||
expect(evaluate(odd, two)).to.be(false);
|
||||
expect(evaluate(odd, four)).to.be(false);
|
||||
expect(evaluate(even, one)).to.be(false);
|
||||
expect(evaluate(even, three)).to.be(false);
|
||||
expect(evaluate(first, two)).to.be(false);
|
||||
expect(evaluate(first, three)).to.be(false);
|
||||
expect(evaluate(first, four)).to.be(false);
|
||||
expect(evaluate(last, one)).to.be(false);
|
||||
expect(evaluate(last, two)).to.be(false);
|
||||
expect(evaluate(last, three)).to.be(false);
|
||||
expect(evaluate(none, one)).to.be(false);
|
||||
expect(evaluate(none, two)).to.be(false);
|
||||
expect(evaluate(none, three)).to.be(false);
|
||||
expect(evaluate(none, four)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('geometryType()', function() {
|
||||
|
||||
var point = new ol.Feature({
|
||||
geom: new ol.geom.Point([0, 0])
|
||||
});
|
||||
|
||||
var line = new ol.Feature({
|
||||
geom: new ol.geom.LineString([[180, -90], [-180, 90]])
|
||||
});
|
||||
|
||||
var poly = new ol.Feature({
|
||||
geom: new ol.geom.Polygon([[
|
||||
[180, -90], [0, -90], [0, 0], [180, 0], [180, -90]
|
||||
]])
|
||||
});
|
||||
|
||||
var isPoint = parse('geometryType("Point")');
|
||||
var isLine = parse('geometryType("LineString")');
|
||||
var isPoly = parse('geometryType("Polygon")');
|
||||
var pointOrPoly = parse('geometryType("Point") || geometryType("Polygon")');
|
||||
|
||||
it('distinguishes point features', function() {
|
||||
expect(evaluate(isPoint, point)).to.be(true);
|
||||
expect(evaluate(isPoint, line)).to.be(false);
|
||||
expect(evaluate(isPoint, poly)).to.be(false);
|
||||
});
|
||||
|
||||
it('distinguishes line features', function() {
|
||||
expect(evaluate(isLine, point)).to.be(false);
|
||||
expect(evaluate(isLine, line)).to.be(true);
|
||||
expect(evaluate(isLine, poly)).to.be(false);
|
||||
});
|
||||
|
||||
it('distinguishes polygon features', function() {
|
||||
expect(evaluate(isPoly, point)).to.be(false);
|
||||
expect(evaluate(isPoly, line)).to.be(false);
|
||||
expect(evaluate(isPoly, poly)).to.be(true);
|
||||
});
|
||||
|
||||
it('can be composed in a logical expression', function() {
|
||||
expect(evaluate(pointOrPoly, point)).to.be(true);
|
||||
expect(evaluate(pointOrPoly, line)).to.be(false);
|
||||
expect(evaluate(pointOrPoly, poly)).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('like()', function() {
|
||||
|
||||
var one = new ol.Feature({foo: 'bar'});
|
||||
var two = new ol.Feature({foo: 'baz'});
|
||||
var three = new ol.Feature({foo: 'foo'});
|
||||
|
||||
var like = parse('like(foo, "ba")');
|
||||
|
||||
it('First and second feature match, third does not', function() {
|
||||
expect(evaluate(like, one), true);
|
||||
expect(evaluate(like, two), true);
|
||||
expect(evaluate(like, three), false);
|
||||
});
|
||||
|
||||
var uclike = parse('like(foo, "BA")');
|
||||
it('Matchcase is true by default', function() {
|
||||
expect(evaluate(uclike, one), false);
|
||||
expect(evaluate(uclike, two), false);
|
||||
expect(evaluate(uclike, three), false);
|
||||
});
|
||||
|
||||
var ilike = parse('like(foo, "BA", "*", ".", "!", false)');
|
||||
it('Using matchcase false, first two features match again', function() {
|
||||
expect(evaluate(ilike, one), true);
|
||||
expect(evaluate(ilike, two), true);
|
||||
expect(evaluate(uclike, three), false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ieq()', function() {
|
||||
|
||||
var one = new ol.Feature({foo: 'Bar'});
|
||||
var two = new ol.Feature({bar: 'Foo'});
|
||||
|
||||
var ieq1 = parse('ieq(foo, "bar")');
|
||||
var ieq2 = parse('ieq("foo", bar)');
|
||||
|
||||
it('case-insensitive equality for an attribute', function() {
|
||||
expect(evaluate(ieq1, one), true);
|
||||
});
|
||||
|
||||
it('case-insensitive equality for an attribute as second argument',
|
||||
function() {
|
||||
expect(evaluate(ieq2, two), true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ineq()', function() {
|
||||
|
||||
var one = new ol.Feature({foo: 'Bar'});
|
||||
var two = new ol.Feature({bar: 'Foo'});
|
||||
|
||||
var ieq1 = parse('ineq(foo, "bar")');
|
||||
var ieq2 = parse('ineq("foo", bar)');
|
||||
|
||||
it('case-insensitive non-equality for an attribute', function() {
|
||||
expect(evaluate(ieq1, one), false);
|
||||
});
|
||||
|
||||
it('case-insensitive non-equality for an attribute as second argument',
|
||||
function() {
|
||||
expect(evaluate(ieq2, two), false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('renderIntent()', function() {
|
||||
|
||||
var feature = new ol.Feature();
|
||||
feature.setRenderIntent('foo');
|
||||
|
||||
var isFoo = parse('renderIntent("foo")');
|
||||
var isBar = parse('renderIntent("bar")');
|
||||
|
||||
it('True when renderIntent matches', function() {
|
||||
expect(evaluate(isFoo, feature), true);
|
||||
});
|
||||
|
||||
it('False when renderIntent does not match', function() {
|
||||
expect(evaluate(isBar, feature), false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.expr.register()', function() {
|
||||
|
||||
var spy;
|
||||
beforeEach(function() {
|
||||
spy = sinon.spy();
|
||||
});
|
||||
|
||||
it('registers custom functions in ol.expr.lib', function() {
|
||||
ol.expr.register('someFunc', spy);
|
||||
expect(ol.expr.lib.someFunc).to.be(spy);
|
||||
});
|
||||
|
||||
it('allows custom functions to be called', function() {
|
||||
ol.expr.register('myFunc', spy);
|
||||
var expr = ol.expr.parse('myFunc(42)');
|
||||
expr.evaluate(null, ol.expr.lib);
|
||||
expect(spy.calledOnce);
|
||||
expect(spy.calledWithExactly(42));
|
||||
});
|
||||
|
||||
it('allows custom functions to be called with identifiers', function() {
|
||||
ol.expr.register('myFunc', spy);
|
||||
var expr = ol.expr.parse('myFunc(foo, 42)');
|
||||
expr.evaluate({foo: 'bar'}, ol.expr.lib);
|
||||
expect(spy.calledOnce).to.be(true);
|
||||
expect(spy.calledWithExactly('bar', 42)).to.be(true);
|
||||
});
|
||||
|
||||
it('allows custom functions to be called with custom this obj', function() {
|
||||
ol.expr.register('myFunc', spy);
|
||||
var expr = ol.expr.parse('myFunc(foo, 42)');
|
||||
var that = {};
|
||||
expr.evaluate({foo: 'bar'}, ol.expr.lib, that);
|
||||
expect(spy.calledOnce).to.be(true);
|
||||
expect(spy.calledWithExactly('bar', 42)).to.be(true);
|
||||
expect(spy.calledOn(that)).to.be(true);
|
||||
});
|
||||
|
||||
it('allows overriding existing ol.expr.lib functions', function() {
|
||||
var orig = ol.expr.lib.extent;
|
||||
expect(orig).not.to.be(spy);
|
||||
ol.expr.register('extent', spy);
|
||||
expect(ol.expr.lib.extent).to.be(spy);
|
||||
ol.expr.lib.extent = orig;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.Expression');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.Logical');
|
||||
goog.require('ol.expr.Math');
|
||||
goog.require('ol.expr.Member');
|
||||
goog.require('ol.expr.Not');
|
||||
goog.require('ol.expr.TokenType');
|
||||
goog.require('ol.expr.UnexpectedToken');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
@@ -1,638 +0,0 @@
|
||||
goog.provide('ol.test.expression.Expression');
|
||||
|
||||
|
||||
describe('ol.expr.Call', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Call(
|
||||
new ol.expr.Identifier('sqrt'),
|
||||
[new ol.expr.Literal(42)]);
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Call);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
var fns = {
|
||||
sqrt: function(value) {
|
||||
return Math.sqrt(value);
|
||||
},
|
||||
strConcat: function() {
|
||||
return Array.prototype.join.call(arguments, '');
|
||||
},
|
||||
discouraged: function() {
|
||||
return this.message;
|
||||
}
|
||||
};
|
||||
|
||||
it('calls method on scope with literal args', function() {
|
||||
var expr = new ol.expr.Call(
|
||||
new ol.expr.Identifier('sqrt'),
|
||||
[new ol.expr.Literal(42)]);
|
||||
expect(expr.evaluate(fns)).to.be(Math.sqrt(42));
|
||||
});
|
||||
|
||||
it('accepts a separate scope for functions', function() {
|
||||
var expr = new ol.expr.Call(
|
||||
new ol.expr.Identifier('sqrt'),
|
||||
[new ol.expr.Identifier('foo')]);
|
||||
expect(expr.evaluate({foo: 42}, fns)).to.be(Math.sqrt(42));
|
||||
});
|
||||
|
||||
it('accepts multiple expression arguments', function() {
|
||||
var expr = new ol.expr.Call(
|
||||
new ol.expr.Identifier('strConcat'),
|
||||
[
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(' comes after '),
|
||||
new ol.expr.Math(
|
||||
ol.expr.MathOp.SUBTRACT,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(1))
|
||||
]);
|
||||
expect(expr.evaluate({foo: 42}, fns)).to.be('42 comes after 41');
|
||||
});
|
||||
|
||||
it('accepts optional this arg', function() {
|
||||
var expr = new ol.expr.Call(
|
||||
new ol.expr.Identifier('discouraged'), []);
|
||||
|
||||
var thisArg = {
|
||||
message: 'avoid this'
|
||||
};
|
||||
|
||||
expect(expr.evaluate(fns, null, thisArg)).to.be('avoid this');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
var callee = new ol.expr.Identifier('sqrt');
|
||||
var args = [new ol.expr.Literal(42)];
|
||||
var expr = new ol.expr.Call(callee, args);
|
||||
|
||||
describe('#getArgs()', function() {
|
||||
it('gets the callee expression', function() {
|
||||
expect(expr.getArgs()).to.be(args);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getCallee()', function() {
|
||||
it('gets the callee expression', function() {
|
||||
expect(expr.getCallee()).to.be(callee);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('ol.expr.Comparison', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.EQ,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('compares with ==', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.EQ,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(true);
|
||||
expect(expr.evaluate({foo: true})).to.be(false);
|
||||
expect(expr.evaluate({bar: true})).to.be(false);
|
||||
});
|
||||
|
||||
it('compares with !=', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.NEQ,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(false);
|
||||
expect(expr.evaluate({foo: true})).to.be(true);
|
||||
expect(expr.evaluate({bar: true})).to.be(true);
|
||||
});
|
||||
|
||||
it('compares with ===', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.STRICT_EQ,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(false);
|
||||
expect(expr.evaluate({foo: true})).to.be(false);
|
||||
expect(expr.evaluate({bar: true})).to.be(false);
|
||||
});
|
||||
|
||||
it('compares with !==', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.STRICT_NEQ,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: '42'})).to.be(true);
|
||||
expect(expr.evaluate({foo: true})).to.be(true);
|
||||
expect(expr.evaluate({bar: true})).to.be(true);
|
||||
});
|
||||
|
||||
it('compares with >', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.GT,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: 41})).to.be(false);
|
||||
expect(expr.evaluate({foo: 43})).to.be(true);
|
||||
});
|
||||
|
||||
it('compares with <', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.LT,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(false);
|
||||
expect(expr.evaluate({foo: 41})).to.be(true);
|
||||
expect(expr.evaluate({foo: 43})).to.be(false);
|
||||
});
|
||||
|
||||
it('compares with >=', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.GTE,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: 41})).to.be(false);
|
||||
expect(expr.evaluate({foo: 43})).to.be(true);
|
||||
});
|
||||
|
||||
it('compares with <=', function() {
|
||||
var expr = new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.LTE,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(42));
|
||||
|
||||
expect(expr.evaluate({foo: 42})).to.be(true);
|
||||
expect(expr.evaluate({foo: 41})).to.be(true);
|
||||
expect(expr.evaluate({foo: 43})).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isValidOp()', function() {
|
||||
it('determines if a string is a valid operator', function() {
|
||||
expect(ol.expr.Comparison.isValidOp('<')).to.be(true);
|
||||
expect(ol.expr.Comparison.isValidOp('<')).to.be(true);
|
||||
expect(ol.expr.Comparison.isValidOp('<=')).to.be(true);
|
||||
expect(ol.expr.Comparison.isValidOp('<=')).to.be(true);
|
||||
expect(ol.expr.Comparison.isValidOp('==')).to.be(true);
|
||||
expect(ol.expr.Comparison.isValidOp('!=')).to.be(true);
|
||||
expect(ol.expr.Comparison.isValidOp('===')).to.be(true);
|
||||
expect(ol.expr.Comparison.isValidOp('!==')).to.be(true);
|
||||
|
||||
expect(ol.expr.Comparison.isValidOp('')).to.be(false);
|
||||
expect(ol.expr.Comparison.isValidOp('+')).to.be(false);
|
||||
expect(ol.expr.Comparison.isValidOp('-')).to.be(false);
|
||||
expect(ol.expr.Comparison.isValidOp('&&')).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
var op = ol.expr.ComparisonOp.LTE;
|
||||
var left = new ol.expr.Identifier('foo');
|
||||
var right = new ol.expr.Literal(42);
|
||||
var expr = new ol.expr.Comparison(op, left, right);
|
||||
|
||||
describe('#getOperator()', function() {
|
||||
it('gets the operator', function() {
|
||||
expect(expr.getOperator()).to.be(op);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getLeft()', function() {
|
||||
it('gets the left expression', function() {
|
||||
expect(expr.getLeft()).to.be(left);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getRight()', function() {
|
||||
it('gets the right expression', function() {
|
||||
expect(expr.getRight()).to.be(right);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.expr.Identifier', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Identifier('foo');
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Identifier);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('returns a number from the scope', function() {
|
||||
var expr = new ol.expr.Identifier('foo');
|
||||
expect(expr.evaluate({foo: 42})).to.be(42);
|
||||
});
|
||||
|
||||
it('returns a string from the scope', function() {
|
||||
var expr = new ol.expr.Identifier('foo');
|
||||
expect(expr.evaluate({foo: 'chicken'})).to.be('chicken');
|
||||
});
|
||||
|
||||
it('returns a boolean from the scope', function() {
|
||||
var expr = new ol.expr.Identifier('bar');
|
||||
expect(expr.evaluate({bar: false})).to.be(false);
|
||||
expect(expr.evaluate({bar: true})).to.be(true);
|
||||
});
|
||||
|
||||
it('returns a null from the scope', function() {
|
||||
var expr = new ol.expr.Identifier('nada');
|
||||
expect(expr.evaluate({nada: null})).to.be(null);
|
||||
});
|
||||
|
||||
it('works for unicode identifiers', function() {
|
||||
var expr = new ol.expr.Identifier('\u03c0');
|
||||
expect(expr.evaluate({'\u03c0': Math.PI})).to.be(Math.PI);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getName()', function() {
|
||||
var expr = new ol.expr.Identifier('asdf');
|
||||
expect(expr.getName()).to.be('asdf');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.expr.Literal', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Literal(true);
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('works for numeric literal', function() {
|
||||
var expr = new ol.expr.Literal(42e-11);
|
||||
expect(expr.evaluate()).to.be(4.2e-10);
|
||||
});
|
||||
|
||||
it('works for string literal', function() {
|
||||
var expr = new ol.expr.Literal('asdf');
|
||||
expect(expr.evaluate()).to.be('asdf');
|
||||
});
|
||||
|
||||
it('works for boolean literal', function() {
|
||||
var expr = new ol.expr.Literal(true);
|
||||
expect(expr.evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('works for null literal', function() {
|
||||
var expr = new ol.expr.Literal(null);
|
||||
expect(expr.evaluate()).to.be(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getValue()', function() {
|
||||
var expr = new ol.expr.Literal('asdf');
|
||||
expect(expr.getValue()).to.be('asdf');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('ol.expr.Logical', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Logical(
|
||||
ol.expr.LogicalOp.OR,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Identifier('bar'));
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Logical);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('applies || to resolved identifiers', function() {
|
||||
var expr = new ol.expr.Logical(
|
||||
ol.expr.LogicalOp.OR,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Identifier('bar'));
|
||||
|
||||
expect(expr.evaluate({foo: true, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: true, bar: false})).to.be(true);
|
||||
expect(expr.evaluate({foo: false, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: false, bar: false})).to.be(false);
|
||||
});
|
||||
|
||||
it('applies && to resolved identifiers', function() {
|
||||
var expr = new ol.expr.Logical(
|
||||
ol.expr.LogicalOp.AND,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Identifier('bar'));
|
||||
|
||||
expect(expr.evaluate({foo: true, bar: true})).to.be(true);
|
||||
expect(expr.evaluate({foo: true, bar: false})).to.be(false);
|
||||
expect(expr.evaluate({foo: false, bar: true})).to.be(false);
|
||||
expect(expr.evaluate({foo: false, bar: false})).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isValidOp()', function() {
|
||||
it('determines if a string is a valid operator', function() {
|
||||
expect(ol.expr.Logical.isValidOp('||')).to.be(true);
|
||||
expect(ol.expr.Logical.isValidOp('&&')).to.be(true);
|
||||
|
||||
expect(ol.expr.Logical.isValidOp('')).to.be(false);
|
||||
expect(ol.expr.Logical.isValidOp('+')).to.be(false);
|
||||
expect(ol.expr.Logical.isValidOp('<')).to.be(false);
|
||||
expect(ol.expr.Logical.isValidOp('|')).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
var op = ol.expr.LogicalOp.AND;
|
||||
var left = new ol.expr.Identifier('foo');
|
||||
var right = new ol.expr.Literal(false);
|
||||
var expr = new ol.expr.Logical(op, left, right);
|
||||
|
||||
describe('#getOperator()', function() {
|
||||
it('gets the operator', function() {
|
||||
expect(expr.getOperator()).to.be(op);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getLeft()', function() {
|
||||
it('gets the left expression', function() {
|
||||
expect(expr.getLeft()).to.be(left);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getRight()', function() {
|
||||
it('gets the right expression', function() {
|
||||
expect(expr.getRight()).to.be(right);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.expr.Math', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.ADD,
|
||||
new ol.expr.Literal(40),
|
||||
new ol.expr.Literal(2));
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('does + with numeric literal', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.ADD,
|
||||
new ol.expr.Literal(40),
|
||||
new ol.expr.Literal(2));
|
||||
|
||||
expect(expr.evaluate()).to.be(42);
|
||||
});
|
||||
|
||||
it('does + with string literal (note: subject to change)', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.ADD,
|
||||
new ol.expr.Literal('foo'),
|
||||
new ol.expr.Literal('bar'));
|
||||
|
||||
expect(expr.evaluate()).to.be('foobar');
|
||||
});
|
||||
|
||||
it('does + with identifiers', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.ADD,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Identifier('bar'));
|
||||
|
||||
expect(expr.evaluate({foo: 40, bar: 2})).to.be(42);
|
||||
});
|
||||
|
||||
it('does - with identifiers', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.SUBTRACT,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(2));
|
||||
|
||||
expect(expr.evaluate({foo: 40})).to.be(38);
|
||||
});
|
||||
|
||||
it('casts to number with - (note: this may throw later)', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.SUBTRACT,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(2));
|
||||
|
||||
expect(expr.evaluate({foo: '40'})).to.be(38);
|
||||
});
|
||||
|
||||
it('does * with identifiers', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.MULTIPLY,
|
||||
new ol.expr.Literal(2),
|
||||
new ol.expr.Identifier('foo'));
|
||||
|
||||
expect(expr.evaluate({foo: 21})).to.be(42);
|
||||
});
|
||||
|
||||
it('casts to number with * (note: this may throw later)', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.MULTIPLY,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(2));
|
||||
|
||||
expect(expr.evaluate({foo: '21'})).to.be(42);
|
||||
});
|
||||
|
||||
it('does % with identifiers', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.MOD,
|
||||
new ol.expr.Literal(97),
|
||||
new ol.expr.Identifier('foo'));
|
||||
|
||||
expect(expr.evaluate({foo: 55})).to.be(42);
|
||||
});
|
||||
|
||||
it('casts to number with % (note: this may throw later)', function() {
|
||||
var expr = new ol.expr.Math(
|
||||
ol.expr.MathOp.MOD,
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Literal(100));
|
||||
|
||||
expect(expr.evaluate({foo: '150'})).to.be(50);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isValidOp()', function() {
|
||||
it('determines if a string is a valid operator', function() {
|
||||
expect(ol.expr.Math.isValidOp('+')).to.be(true);
|
||||
expect(ol.expr.Math.isValidOp('-')).to.be(true);
|
||||
expect(ol.expr.Math.isValidOp('*')).to.be(true);
|
||||
expect(ol.expr.Math.isValidOp('/')).to.be(true);
|
||||
expect(ol.expr.Math.isValidOp('%')).to.be(true);
|
||||
|
||||
expect(ol.expr.Math.isValidOp('')).to.be(false);
|
||||
expect(ol.expr.Math.isValidOp('|')).to.be(false);
|
||||
expect(ol.expr.Math.isValidOp('&')).to.be(false);
|
||||
expect(ol.expr.Math.isValidOp('<')).to.be(false);
|
||||
expect(ol.expr.Math.isValidOp('||')).to.be(false);
|
||||
expect(ol.expr.Math.isValidOp('.')).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
var op = ol.expr.MathOp.MOD;
|
||||
var left = new ol.expr.Identifier('foo');
|
||||
var right = new ol.expr.Literal(20);
|
||||
var expr = new ol.expr.Math(op, left, right);
|
||||
|
||||
describe('#getOperator()', function() {
|
||||
it('gets the operator', function() {
|
||||
expect(expr.getOperator()).to.be(op);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getLeft()', function() {
|
||||
it('gets the left expression', function() {
|
||||
expect(expr.getLeft()).to.be(left);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getRight()', function() {
|
||||
it('gets the right expression', function() {
|
||||
expect(expr.getRight()).to.be(right);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.expr.Member', function() {
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Member(
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Identifier('bar'));
|
||||
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Member);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('accesses an object property', function() {
|
||||
|
||||
var expr = new ol.expr.Member(
|
||||
new ol.expr.Identifier('foo'),
|
||||
new ol.expr.Identifier('bar'));
|
||||
|
||||
var scope = {foo: {bar: 42}};
|
||||
expect(expr.evaluate(scope)).to.be(42);
|
||||
});
|
||||
});
|
||||
|
||||
var object = new ol.expr.Identifier('foo');
|
||||
var property = new ol.expr.Identifier('bar');
|
||||
var expr = new ol.expr.Member(object, property);
|
||||
|
||||
describe('#getObject()', function() {
|
||||
expect(expr.getObject()).to.be(object);
|
||||
});
|
||||
|
||||
describe('#getProperty()', function() {
|
||||
expect(expr.getProperty()).to.be(property);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('ol.expr.Not', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression', function() {
|
||||
var expr = new ol.expr.Not(
|
||||
new ol.expr.Literal(true));
|
||||
expect(expr).to.be.a(ol.expr.Expression);
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('returns the logical complement', function() {
|
||||
var expr = new ol.expr.Not(new ol.expr.Literal(true));
|
||||
expect(expr.evaluate()).to.be(false);
|
||||
|
||||
expr = new ol.expr.Not(new ol.expr.Literal(false));
|
||||
expect(expr.evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('negates a truthy string', function() {
|
||||
var expr = new ol.expr.Not(new ol.expr.Literal('asdf'));
|
||||
expect(expr.evaluate()).to.be(false);
|
||||
});
|
||||
|
||||
it('negates a falsy string', function() {
|
||||
var expr = new ol.expr.Not(new ol.expr.Literal(''));
|
||||
expect(expr.evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('negates a truthy number', function() {
|
||||
var expr = new ol.expr.Not(new ol.expr.Literal(42));
|
||||
expect(expr.evaluate()).to.be(false);
|
||||
});
|
||||
|
||||
it('negates a falsy number', function() {
|
||||
var expr = new ol.expr.Not(new ol.expr.Literal(NaN));
|
||||
expect(expr.evaluate()).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getArgument()', function() {
|
||||
var argument = new ol.expr.Literal(true);
|
||||
var expr = new ol.expr.Not(argument);
|
||||
expect(expr.getArgument()).to.be(argument);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
goog.require('ol.expr.Expression');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.Logical');
|
||||
goog.require('ol.expr.LogicalOp');
|
||||
goog.require('ol.expr.Math');
|
||||
goog.require('ol.expr.MathOp');
|
||||
goog.require('ol.expr.Member');
|
||||
goog.require('ol.expr.Not');
|
||||
@@ -1,509 +0,0 @@
|
||||
goog.provide('ol.test.expression.Lexer');
|
||||
|
||||
describe('ol.expr.Lexer', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new lexer', function() {
|
||||
var lexer = new ol.expr.Lexer('foo');
|
||||
expect(lexer).to.be.a(ol.expr.Lexer);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#next()', function() {
|
||||
|
||||
it('returns one token at a time', function() {
|
||||
var source = 'foo === "bar"';
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
|
||||
// scan first token
|
||||
var token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
expect(token.value).to.be('foo');
|
||||
|
||||
// scan second token
|
||||
token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
expect(token.value).to.be('===');
|
||||
|
||||
// scan third token
|
||||
token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
expect(token.value).to.be('bar');
|
||||
|
||||
// scan again
|
||||
token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.EOF);
|
||||
|
||||
// and again
|
||||
token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.EOF);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#peek()', function() {
|
||||
|
||||
var lexer;
|
||||
beforeEach(function() {
|
||||
lexer = new ol.expr.Lexer('foo > 42 && bar == "chicken"');
|
||||
});
|
||||
|
||||
it('looks ahead without consuming token', function() {
|
||||
var token = lexer.peek();
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
expect(token.value).to.be('foo');
|
||||
|
||||
token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
expect(token.value).to.be('foo');
|
||||
});
|
||||
|
||||
it('works after a couple scans', function() {
|
||||
var token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
expect(token.value).to.be('foo');
|
||||
|
||||
token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
expect(token.value).to.be('>');
|
||||
|
||||
token = lexer.peek();
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
expect(token.value).to.be(42);
|
||||
|
||||
token = lexer.next();
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
expect(token.value).to.be(42);
|
||||
});
|
||||
|
||||
it('returns the same thing when called multiple times', function() {
|
||||
var token = lexer.peek();
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
expect(token.value).to.be('foo');
|
||||
|
||||
for (var i = 0; i < 10; ++i) {
|
||||
token = lexer.peek();
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
expect(token.value).to.be('foo');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('#scanIdentifier_()', function() {
|
||||
|
||||
function scan(source, part) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var token = lexer.scanIdentifier_(lexer.getCurrentCharCode_());
|
||||
if (!part) {
|
||||
expect(token.index).to.be(0);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
it('works for short identifiers', function() {
|
||||
var token = scan('a');
|
||||
expect(token.value).to.be('a');
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works for longer identifiers', function() {
|
||||
var token = scan('foo');
|
||||
expect(token.value).to.be('foo');
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works for $ anywhere', function() {
|
||||
var token = scan('$foo$bar$');
|
||||
expect(token.value).to.be('$foo$bar$');
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works for _ anywhere', function() {
|
||||
var token = scan('_foo_bar_');
|
||||
expect(token.value).to.be('_foo_bar_');
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works for keywords', function() {
|
||||
var token = scan('delete');
|
||||
expect(token.value).to.be('delete');
|
||||
expect(token.type).to.be(ol.expr.TokenType.KEYWORD);
|
||||
});
|
||||
|
||||
it('works for null', function() {
|
||||
var token = scan('null');
|
||||
expect(token.value).to.be('null');
|
||||
expect(token.type).to.be(ol.expr.TokenType.NULL_LITERAL);
|
||||
});
|
||||
|
||||
it('works for boolean true', function() {
|
||||
var token = scan('true');
|
||||
expect(token.value).to.be('true');
|
||||
expect(token.type).to.be(ol.expr.TokenType.BOOLEAN_LITERAL);
|
||||
});
|
||||
|
||||
it('works for boolean false', function() {
|
||||
var token = scan('false');
|
||||
expect(token.value).to.be('false');
|
||||
expect(token.type).to.be(ol.expr.TokenType.BOOLEAN_LITERAL);
|
||||
});
|
||||
|
||||
it('works with unicode escape sequences', function() {
|
||||
var token = scan('\u006f\u006c\u0033');
|
||||
expect(token.value).to.be('ol3');
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works with hex escape sequences', function() {
|
||||
var token = scan('\x6f\x6c\x33');
|
||||
expect(token.value).to.be('ol3');
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('throws for identifiers starting with a number', function() {
|
||||
expect(function() {
|
||||
scan('4foo');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
it('throws for identifiers starting with a punctuation char', function() {
|
||||
expect(function() {
|
||||
scan('!foo');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
it('only scans valid identifier part', function() {
|
||||
var token = scan('foo>bar', true);
|
||||
expect(token.value).to.be('foo');
|
||||
expect(token.type).to.be(ol.expr.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#scanNumericLiteral_()', function() {
|
||||
|
||||
function scan(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var token = lexer.scanNumericLiteral_(lexer.getCurrentCharCode_());
|
||||
expect(token.index).to.be(0);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return token;
|
||||
}
|
||||
|
||||
it('works for integers', function() {
|
||||
var token = scan('123');
|
||||
expect(token.value).to.be(123);
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
});
|
||||
|
||||
it('throws for bogus integer', function() {
|
||||
expect(function() {
|
||||
scan('123z');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('z');
|
||||
expect(token.index).to.be(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('works for float', function() {
|
||||
var token = scan('123.456');
|
||||
expect(token.value).to.be(123.456);
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
});
|
||||
|
||||
it('throws for bogus float', function() {
|
||||
expect(function() {
|
||||
scan('123.4x4');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('x');
|
||||
expect(token.index).to.be(5);
|
||||
});
|
||||
});
|
||||
|
||||
it('works with exponent', function() {
|
||||
var token = scan('1.234e5');
|
||||
expect(token.value).to.be(1.234e5);
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
});
|
||||
|
||||
it('works with explicit positive exponent', function() {
|
||||
var token = scan('1.234e+5');
|
||||
expect(token.value).to.be(1.234e5);
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
});
|
||||
|
||||
it('works with negative exponent', function() {
|
||||
var token = scan('1.234e-5');
|
||||
expect(token.value).to.be(1.234e-5);
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
});
|
||||
|
||||
it('throws for bogus float', function() {
|
||||
expect(function() {
|
||||
scan('1.234eo4');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('o');
|
||||
expect(token.index).to.be(6);
|
||||
});
|
||||
});
|
||||
|
||||
it('works with octals', function() {
|
||||
var token = scan('02322');
|
||||
expect(token.value).to.be(1234);
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
});
|
||||
|
||||
it('throws for bogus octal', function() {
|
||||
// note that this is more strict than most es5 engines
|
||||
expect(function() {
|
||||
scan('02392');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('9');
|
||||
expect(token.index).to.be(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('works with hex', function() {
|
||||
var token = scan('0x4d2');
|
||||
expect(token.value).to.be(1234);
|
||||
expect(token.type).to.be(ol.expr.TokenType.NUMERIC_LITERAL);
|
||||
});
|
||||
|
||||
it('throws for bogus hex', function() {
|
||||
// note that this is more strict than most es5 engines
|
||||
expect(function() {
|
||||
scan('0x4G');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.value).to.be('G');
|
||||
expect(token.index).to.be(3);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#scanPunctuator_()', function() {
|
||||
|
||||
function scan(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var token = lexer.scanPunctuator_(lexer.getCurrentCharCode_());
|
||||
expect(token.index).to.be(0);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return token;
|
||||
}
|
||||
|
||||
it('works for dot', function() {
|
||||
var token = scan('.');
|
||||
expect(token.value).to.be('.');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for bang', function() {
|
||||
var token = scan('!');
|
||||
expect(token.value).to.be('!');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for double equal', function() {
|
||||
var token = scan('==');
|
||||
expect(token.value).to.be('==');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for triple equal', function() {
|
||||
var token = scan('===');
|
||||
expect(token.value).to.be('===');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for not double equal', function() {
|
||||
var token = scan('!=');
|
||||
expect(token.value).to.be('!=');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for not triple equal', function() {
|
||||
var token = scan('!==');
|
||||
expect(token.value).to.be('!==');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for logical or', function() {
|
||||
var token = scan('||');
|
||||
expect(token.value).to.be('||');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for logical and', function() {
|
||||
var token = scan('&&');
|
||||
expect(token.value).to.be('&&');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for plus', function() {
|
||||
var token = scan('+');
|
||||
expect(token.value).to.be('+');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for minus', function() {
|
||||
var token = scan('-');
|
||||
expect(token.value).to.be('-');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for star', function() {
|
||||
var token = scan('*');
|
||||
expect(token.value).to.be('*');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for slash', function() {
|
||||
var token = scan('/');
|
||||
expect(token.value).to.be('/');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
it('works for percent', function() {
|
||||
var token = scan('%');
|
||||
expect(token.value).to.be('%');
|
||||
expect(token.type).to.be(ol.expr.TokenType.PUNCTUATOR);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#scanStringLiteral_()', function() {
|
||||
|
||||
function scan(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var token = lexer.scanStringLiteral_(lexer.getCurrentCharCode_());
|
||||
expect(token.index).to.be(0);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return token;
|
||||
}
|
||||
|
||||
it('parses double quoted string', function() {
|
||||
var token = scan('"my string"');
|
||||
expect(token.value).to.be('my string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses double quoted string with internal single quotes', function() {
|
||||
var token = scan('"my \'quoted\' string"');
|
||||
expect(token.value).to.be('my \'quoted\' string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses double quoted string with escaped double quotes', function() {
|
||||
var token = scan('"my \\"quoted\\" string"');
|
||||
expect(token.value).to.be('my "quoted" string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses double quoted string with escaped backslash', function() {
|
||||
var token = scan('"my \\\ string"');
|
||||
expect(token.value).to.be('my \ string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses double quoted string with unicode escape sequences', function() {
|
||||
var token = scan('"\u006f\u006c\u0033"');
|
||||
expect(token.value).to.be('ol3');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses double quoted string with hex escape sequences', function() {
|
||||
var token = scan('"\x6f\x6c\x33"');
|
||||
expect(token.value).to.be('ol3');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses double quoted string with tab', function() {
|
||||
var token = scan('"a\ttab"');
|
||||
expect(token.value).to.be('a\ttab');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('throws on unterminated double quote', function() {
|
||||
expect(function() {
|
||||
scan('"never \'ending\' string');
|
||||
}).to.throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.type).to.be(ol.expr.TokenType.EOF);
|
||||
expect(token.index).to.be(22);
|
||||
});
|
||||
});
|
||||
|
||||
it('parses single quoted string', function() {
|
||||
var token = scan('\'my string\'');
|
||||
expect(token.value).to.be('my string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses single quoted string with internal double quotes', function() {
|
||||
var token = scan('\'my "quoted" string\'');
|
||||
expect(token.value).to.be('my "quoted" string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses single quoted string with escaped single quotes', function() {
|
||||
var token = scan('\'my \\\'quoted\\\' string\'');
|
||||
expect(token.value).to.be('my \'quoted\' string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses single quoted string with escaped backslash', function() {
|
||||
var token = scan('\'my \\\ string\'');
|
||||
expect(token.value).to.be('my \ string');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses single quoted string with unicode escape sequences', function() {
|
||||
var token = scan('\'\u006f\u006c\u0033\'');
|
||||
expect(token.value).to.be('ol3');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses single quoted string with hex escape sequences', function() {
|
||||
var token = scan('\'\x6f\x6c\x33\'');
|
||||
expect(token.value).to.be('ol3');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('parses single quoted string with tab', function() {
|
||||
var token = scan('\'a\ttab\'');
|
||||
expect(token.value).to.be('a\ttab');
|
||||
expect(token.type).to.be(ol.expr.TokenType.STRING_LITERAL);
|
||||
});
|
||||
|
||||
it('throws on unterminated single quote', function() {
|
||||
expect(function() {
|
||||
scan('\'never "ending" string');
|
||||
}).to.throwException(function(err) {
|
||||
expect(err).to.be.an(ol.expr.UnexpectedToken);
|
||||
var token = err.token;
|
||||
expect(token.type).to.be(ol.expr.TokenType.EOF);
|
||||
expect(token.index).to.be(22);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.expr.Lexer');
|
||||
goog.require('ol.expr.TokenType');
|
||||
goog.require('ol.expr.UnexpectedToken');
|
||||
@@ -1,275 +0,0 @@
|
||||
goog.provide('ol.test.expression.Parser');
|
||||
|
||||
describe('ol.expr.Parser', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates a new expression parser', function() {
|
||||
var parser = new ol.expr.Parser();
|
||||
expect(parser).to.be.a(ol.expr.Parser);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#parseArguments_()', function() {
|
||||
|
||||
function parse(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var parser = new ol.expr.Parser();
|
||||
var expr = parser.parseArguments_(lexer);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return expr;
|
||||
}
|
||||
|
||||
it('parses comma separated expressions in parens', function() {
|
||||
var args = parse('(1/3, "foo", true)');
|
||||
expect(args).length(3);
|
||||
|
||||
expect(args[0]).to.be.a(ol.expr.Math);
|
||||
expect(args[0].evaluate()).to.be(1 / 3);
|
||||
|
||||
expect(args[1]).to.be.a(ol.expr.Literal);
|
||||
expect(args[1].evaluate()).to.be('foo');
|
||||
|
||||
expect(args[2]).to.be.a(ol.expr.Literal);
|
||||
expect(args[2].evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('throws on invalid arg expression', function() {
|
||||
expect(function() {
|
||||
parse('(6e)');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
it('throws on unterminated args', function() {
|
||||
expect(function() {
|
||||
parse('("foo", 42, )');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#parseBinaryExpression_()', function() {
|
||||
|
||||
function parse(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var parser = new ol.expr.Parser();
|
||||
var expr = parser.parseBinaryExpression_(lexer);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return expr;
|
||||
}
|
||||
|
||||
it('works with multiplicitave operators', function() {
|
||||
var expr = parse('4 * 1e4');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate()).to.be(40000);
|
||||
|
||||
expect(parse('10/3').evaluate()).to.be(10 / 3);
|
||||
});
|
||||
|
||||
it('works with additive operators', function() {
|
||||
var expr = parse('4 +1e4');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate()).to.be(10004);
|
||||
|
||||
expect(parse('10-3').evaluate()).to.be(7);
|
||||
});
|
||||
|
||||
it('works with relational operators', function() {
|
||||
var expr = parse('4 < 1e4');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate()).to.be(true);
|
||||
|
||||
expect(parse('10<3').evaluate()).to.be(false);
|
||||
expect(parse('10 <= "10"').evaluate()).to.be(true);
|
||||
expect(parse('10 > "10"').evaluate()).to.be(false);
|
||||
expect(parse('10 >= 9').evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('works with equality operators', function() {
|
||||
var expr = parse('4 == 1e4');
|
||||
expect(expr).to.be.a(ol.expr.Comparison);
|
||||
expect(expr.evaluate()).to.be(false);
|
||||
|
||||
expect(parse('10!=3').evaluate()).to.be(true);
|
||||
expect(parse('10 == "10"').evaluate()).to.be(true);
|
||||
expect(parse('10 === "10"').evaluate()).to.be(false);
|
||||
expect(parse('10 !== "10"').evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('works with binary logical operators', function() {
|
||||
var expr = parse('true && false');
|
||||
expect(expr).to.be.a(ol.expr.Logical);
|
||||
expect(expr.evaluate()).to.be(false);
|
||||
|
||||
expect(parse('false||true').evaluate()).to.be(true);
|
||||
expect(parse('false || false').evaluate()).to.be(false);
|
||||
expect(parse('true &&true').evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('throws for invalid binary expression', function() {
|
||||
expect(function() {
|
||||
parse('4 * / 2');
|
||||
}).throwException();
|
||||
|
||||
expect(function() {
|
||||
parse('4 < / 2');
|
||||
}).throwException();
|
||||
|
||||
expect(function() {
|
||||
parse('4 * && 2');
|
||||
}).throwException();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#parseGroupExpression_()', function() {
|
||||
|
||||
function parse(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var parser = new ol.expr.Parser();
|
||||
var expr = parser.parseGroupExpression_(lexer);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return expr;
|
||||
}
|
||||
|
||||
it('parses grouped expressions', function() {
|
||||
var expr = parse('(3 * (foo + 2))');
|
||||
expect(expr).to.be.a(ol.expr.Math);
|
||||
expect(expr.evaluate({foo: 3})).to.be(15);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#parseLeftHandSideExpression_()', function() {
|
||||
|
||||
function parse(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var parser = new ol.expr.Parser();
|
||||
var expr = parser.parseLeftHandSideExpression_(lexer);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return expr;
|
||||
}
|
||||
|
||||
it('parses member expressions', function() {
|
||||
var expr = parse('foo.bar.bam');
|
||||
expect(expr).to.be.a(ol.expr.Member);
|
||||
});
|
||||
|
||||
it('throws on invalid member expression', function() {
|
||||
expect(function() {
|
||||
parse('foo.4');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
it('parses call expressions', function() {
|
||||
var expr = parse('foo(bar)');
|
||||
expect(expr).to.be.a(ol.expr.Call);
|
||||
var fns = {
|
||||
foo: function(arg) {
|
||||
expect(arguments).length(1);
|
||||
expect(arg).to.be('chicken');
|
||||
return 'got ' + arg;
|
||||
}
|
||||
};
|
||||
var scope = {
|
||||
bar: 'chicken'
|
||||
};
|
||||
expect(expr.evaluate(scope, fns)).to.be('got chicken');
|
||||
});
|
||||
|
||||
it('throws on invalid call expression', function() {
|
||||
expect(function() {
|
||||
parse('foo(*)');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('#parsePrimaryExpression_()', function() {
|
||||
|
||||
function parse(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var parser = new ol.expr.Parser();
|
||||
var expr = parser.parsePrimaryExpression_(lexer);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return expr;
|
||||
}
|
||||
|
||||
it('parses string literal', function() {
|
||||
var expr = parse('"foo"');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be('foo');
|
||||
});
|
||||
|
||||
it('parses numeric literal', function() {
|
||||
var expr = parse('.42e2');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be(42);
|
||||
});
|
||||
|
||||
it('parses boolean literal', function() {
|
||||
var expr = parse('.42e2');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be(42);
|
||||
});
|
||||
|
||||
it('parses null literal', function() {
|
||||
var expr = parse('null');
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.evaluate()).to.be(null);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#parseUnaryExpression_()', function() {
|
||||
|
||||
function parse(source) {
|
||||
var lexer = new ol.expr.Lexer(source);
|
||||
var parser = new ol.expr.Parser();
|
||||
var expr = parser.parseUnaryExpression_(lexer);
|
||||
expect(lexer.peek().type).to.be(ol.expr.TokenType.EOF);
|
||||
return expr;
|
||||
}
|
||||
|
||||
it('parses logical not', function() {
|
||||
var expr = parse('!foo');
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
expect(expr.evaluate({foo: true})).to.be(false);
|
||||
});
|
||||
|
||||
it('works with string literal', function() {
|
||||
var expr = parse('!"foo"');
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
expect(expr.evaluate()).to.be(false);
|
||||
});
|
||||
|
||||
it('works with empty string', function() {
|
||||
var expr = parse('!""');
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
expect(expr.evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
it('works with null', function() {
|
||||
var expr = parse('!null');
|
||||
expect(expr).to.be.a(ol.expr.Not);
|
||||
expect(expr.evaluate()).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.expr.Expression');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.Lexer');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.Logical');
|
||||
goog.require('ol.expr.Math');
|
||||
goog.require('ol.expr.Member');
|
||||
goog.require('ol.expr.Not');
|
||||
goog.require('ol.expr.Parser');
|
||||
goog.require('ol.expr.TokenType');
|
||||
@@ -1,74 +0,0 @@
|
||||
goog.provide('ol.test.parser.ogc.ExceptionReport');
|
||||
|
||||
|
||||
describe('ol.parser.ogc.exceptionreport', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.ExceptionReport();
|
||||
|
||||
describe('test read exception', function() {
|
||||
|
||||
it('OCG WMS 1.3.0 exceptions', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/exceptionreport/wms1_3_0.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var exceptions = parser.read(xml).exceptionReport.exceptions;
|
||||
expect(exceptions.length).to.be(4);
|
||||
var str = 'Plain text message about an error.';
|
||||
expect(goog.string.trim(exceptions[0].text)).to.be(str);
|
||||
expect(exceptions[1].code).to.be('InvalidUpdateSequence');
|
||||
str = ' Another error message, this one with a service exception ' +
|
||||
'code supplied. ';
|
||||
expect(exceptions[1].text).to.be(str);
|
||||
str = 'Error in module <foo.c>, line 42A message that includes angle ' +
|
||||
'brackets in text must be enclosed in a Character Data Section as' +
|
||||
' in this example. All XML-like markup is ignored except for this' +
|
||||
' sequence of three closing characters:';
|
||||
expect(goog.string.trim(exceptions[2].text), str);
|
||||
str = '<Module>foo.c</Module> <Error>An error occurred</Error> ' +
|
||||
'<Explanation>Similarly, actual XML can be enclosed in a CDATA ' +
|
||||
'section. A generic parser will ignore that XML, but ' +
|
||||
'application-specific software may choose to process it.' +
|
||||
'</Explanation>';
|
||||
expect(goog.string.trim(exceptions[3].text), str);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('test read exception OWSCommon 1.0.0', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/exceptionreport/ows1_0_0.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var report = parser.read(xml).exceptionReport;
|
||||
var exception = report.exceptions[0];
|
||||
|
||||
expect(report.version).to.eql('1.0.0');
|
||||
expect(report.language).to.eql('en');
|
||||
expect(exception.code).to.eql('InvalidParameterValue');
|
||||
expect(exception.locator).to.eql('foo');
|
||||
var msg = 'Update error: Error occured updating features';
|
||||
expect(exception.texts[0]).to.eql(msg);
|
||||
msg = 'Second exception line';
|
||||
expect(exception.texts[1]).to.eql(msg);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('test read exception OWSCommon 1.1.0', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/exceptionreport/ows1_1_0.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var report = parser.read(xml).exceptionReport;
|
||||
var exception = report.exceptions[0];
|
||||
|
||||
expect(report.version).to.eql('1.1.0');
|
||||
expect(report.language).to.eql('en');
|
||||
expect(exception.code).to.eql('InvalidParameterValue');
|
||||
expect(exception.locator).to.eql('foo');
|
||||
var msg = 'Update error: Error occured updating features';
|
||||
expect(exception.texts[0]).to.eql(msg);
|
||||
expect(exception.texts[1]).to.eql('Second exception line');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('goog.string');
|
||||
goog.require('ol.parser.ogc.ExceptionReport');
|
||||
@@ -1,284 +0,0 @@
|
||||
goog.provide('ol.test.parser.ogc.Filter_v1_0_0');
|
||||
|
||||
describe('ol.parser.ogc.Filter_v1_0_0', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.Filter_v1_0_0();
|
||||
|
||||
describe('reading and writing', function() {
|
||||
|
||||
it('handles intersects', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/intersects.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter instanceof ol.expr.Call).to.be(true);
|
||||
expect(filter.getCallee().getName()).to.equal(
|
||||
ol.expr.functions.INTERSECTS);
|
||||
var args = filter.getArgs();
|
||||
var geom = args[0];
|
||||
expect(geom.getValue() instanceof ol.geom.Polygon).to.be(true);
|
||||
expect(args[2].getName()).to.equal('Geometry');
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles within', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/within.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter instanceof ol.expr.Call).to.be(true);
|
||||
expect(filter.getCallee().getName()).to.equal(ol.expr.functions.WITHIN);
|
||||
var args = filter.getArgs();
|
||||
var geom = args[0];
|
||||
expect(geom.getValue() instanceof ol.geom.Polygon).to.be(true);
|
||||
expect(args[2].getName()).to.equal('Geometry');
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles contains', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/contains.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter instanceof ol.expr.Call).to.be(true);
|
||||
expect(filter.getCallee().getName()).to.equal(
|
||||
ol.expr.functions.CONTAINS);
|
||||
var args = filter.getArgs();
|
||||
var geom = args[0];
|
||||
expect(geom.getValue() instanceof ol.geom.Polygon).to.be(true);
|
||||
expect(args[2].getName()).to.equal('Geometry');
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles between', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/between.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter).to.be.a(ol.expr.Logical);
|
||||
expect(filter.getOperator()).to.equal(ol.expr.LogicalOp.AND);
|
||||
expect(filter.getLeft()).to.be.a(ol.expr.Comparison);
|
||||
expect(filter.getLeft().getOperator()).to.equal(
|
||||
ol.expr.ComparisonOp.GTE);
|
||||
expect(filter.getLeft().getLeft().getName()).to.equal('number');
|
||||
expect(filter.getLeft().getRight().getValue()).to.equal(0);
|
||||
expect(filter.getRight()).to.be.a(ol.expr.Comparison);
|
||||
expect(filter.getRight().getOperator()).to.equal(
|
||||
ol.expr.ComparisonOp.LTE);
|
||||
expect(filter.getRight().getLeft().getName()).to.equal('number');
|
||||
expect(filter.getRight().getRight().getValue()).to.equal(100);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles between without literals', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/between2.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter).to.be.a(ol.expr.Logical);
|
||||
expect(filter.getOperator()).to.equal(ol.expr.LogicalOp.AND);
|
||||
expect(filter.getLeft()).to.be.a(ol.expr.Comparison);
|
||||
expect(filter.getLeft().getOperator()).to.equal(
|
||||
ol.expr.ComparisonOp.GTE);
|
||||
expect(filter.getLeft().getLeft().getName()).to.equal('number');
|
||||
expect(filter.getLeft().getRight().getValue()).to.equal(0);
|
||||
expect(filter.getRight()).to.be.a(ol.expr.Comparison);
|
||||
expect(filter.getRight().getOperator()).to.equal(
|
||||
ol.expr.ComparisonOp.LTE);
|
||||
expect(filter.getRight().getLeft().getName()).to.equal('number');
|
||||
expect(filter.getRight().getRight().getValue()).to.equal(100);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles null', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/null.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter).to.be.a(ol.expr.Comparison);
|
||||
expect(filter.getLeft().getName()).to.equal('prop');
|
||||
expect(filter.getRight().getValue()).to.equal(null);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes BBOX', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/bbox.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.EXTENT),
|
||||
[new ol.expr.Literal(-180), new ol.expr.Literal(-90),
|
||||
new ol.expr.Literal(180), new ol.expr.Literal(90),
|
||||
new ol.expr.Literal('EPSG:4326'),
|
||||
new ol.expr.Identifier('the_geom')]);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes BBOX without geometry name', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/bbox_nogeom.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.EXTENT),
|
||||
[new ol.expr.Literal(-180), new ol.expr.Literal(-90),
|
||||
new ol.expr.Literal(180), new ol.expr.Literal(90),
|
||||
new ol.expr.Literal('EPSG:4326')]);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('reads DWithin', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/dwithin.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter).to.be.a(ol.expr.Call);
|
||||
var callee = filter.getCallee();
|
||||
expect(callee).to.be.a(ol.expr.Identifier);
|
||||
var name = callee.getName();
|
||||
expect(name).to.equal(ol.expr.functions.DWITHIN);
|
||||
var args = filter.getArgs();
|
||||
expect(args.length).to.equal(5);
|
||||
var distance = args[1];
|
||||
expect(distance).to.be.a(ol.expr.Literal);
|
||||
expect(distance.getValue()).to.equal(1000);
|
||||
var units = args[2];
|
||||
expect(units).to.be.a(ol.expr.Literal);
|
||||
expect(units.getValue()).to.equal('m');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes DWithin', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/dwithin.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Call(new ol.expr.Identifier(
|
||||
ol.expr.functions.DWITHIN),
|
||||
[new ol.expr.Literal(new ol.geom.Point([2488789, 289552])),
|
||||
new ol.expr.Literal(1000), new ol.expr.Literal('m'),
|
||||
new ol.expr.Literal(null), new ol.expr.Identifier('Geometry')]);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
filter = parser.read(xml);
|
||||
output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// the Filter Encoding spec doesn't allow for FID filters inside logical
|
||||
// filters however, to be liberal, we will write them without complaining
|
||||
describe('logical fid', function() {
|
||||
|
||||
it('writes logical [OR] with fid', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/logicalfeatureid.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Logical(ol.expr.LogicalOp.OR,
|
||||
new ol.expr.Call(new ol.expr.Identifier(ol.expr.functions.LIKE),
|
||||
[new ol.expr.Identifier('person'), new ol.expr.Literal('me'),
|
||||
new ol.expr.Literal('*'), new ol.expr.Literal('.'),
|
||||
new ol.expr.Literal('!')]),
|
||||
new ol.expr.Call(new ol.expr.Identifier(ol.expr.functions.FID),
|
||||
[new ol.expr.Literal('foo.1'), new ol.expr.Literal('foo.2')]));
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes logical [AND] with fid',
|
||||
function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/' +
|
||||
'logicalfeatureidand.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Logical(ol.expr.LogicalOp.AND,
|
||||
new ol.expr.Call(new ol.expr.Identifier(ol.expr.functions.LIKE),
|
||||
[new ol.expr.Identifier('person'), new ol.expr.Literal('me'),
|
||||
new ol.expr.Literal('*'), new ol.expr.Literal('.'),
|
||||
new ol.expr.Literal('!')]),
|
||||
new ol.expr.Call(new ol.expr.Identifier(ol.expr.functions.FID),
|
||||
[new ol.expr.Literal('foo.1'), new ol.expr.Literal('foo.2')]));
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes logical [NOT] with fid',
|
||||
function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_0_0/' +
|
||||
'logicalfeatureidnot.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Not(
|
||||
new ol.expr.Call(new ol.expr.Identifier(ol.expr.functions.FID),
|
||||
[new ol.expr.Literal('foo.2')]));
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('_expression reader', function() {
|
||||
var evaluate = ol.expr.evaluateFeature;
|
||||
|
||||
it('handles combined propertyname and text', function() {
|
||||
var xml = '<ogc:UpperBoundary xmlns:ogc="' +
|
||||
'http://www.opengis.net/ogc">10</ogc:UpperBoundary>';
|
||||
var reader = parser.readers['http://www.opengis.net/ogc'][
|
||||
'_expression'];
|
||||
var expr = reader.call(parser, goog.dom.xml.loadXml(
|
||||
xml).documentElement);
|
||||
expect(expr).to.be.a(ol.expr.Literal);
|
||||
expect(expr.getValue()).to.equal(10);
|
||||
xml = '<ogc:UpperBoundary xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'foo<ogc:PropertyName>x</ogc:PropertyName>bar</ogc:UpperBoundary>';
|
||||
expr = reader.call(parser, goog.dom.xml.loadXml(xml).documentElement);
|
||||
expect(evaluate(expr, new ol.Feature({x: 4}))).to.eql('foo4bar');
|
||||
});
|
||||
|
||||
it('handles combined propertyname and literal', function() {
|
||||
var reader = parser.readers['http://www.opengis.net/ogc'][
|
||||
'_expression'];
|
||||
var xml = '<ogc:UpperBoundary xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:Literal>bar</ogc:Literal>' +
|
||||
'<ogc:PropertyName>x</ogc:PropertyName>' +
|
||||
'<ogc:Literal>foo</ogc:Literal></ogc:UpperBoundary>';
|
||||
var expr = reader.call(parser, goog.dom.xml.loadXml(xml).documentElement);
|
||||
expect(evaluate(expr, new ol.Feature({x: 42}))).to.eql('bar42foo');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.Logical');
|
||||
goog.require('ol.expr.LogicalOp');
|
||||
goog.require('ol.expr.Not');
|
||||
goog.require('ol.expr.functions');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.parser.ogc.Filter_v1_0_0');
|
||||
@@ -1,245 +0,0 @@
|
||||
goog.provide('ol.test.parser.ogc.Filter_v1_1_0');
|
||||
|
||||
describe('ol.parser.ogc.Filter_v1_1_0', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.Filter_v1_1_0();
|
||||
|
||||
describe('reading and writing', function() {
|
||||
|
||||
it('reads filter', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/test.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
expect(filter instanceof ol.expr.Logical).to.be(true);
|
||||
expect(filter.getOperator()).to.equal(ol.expr.LogicalOp.OR);
|
||||
var filters = [];
|
||||
parser.getSubfiltersForLogical_(filter, filters);
|
||||
expect(filters.length).to.equal(5);
|
||||
expect(filters[0]).to.eql(new ol.expr.Logical(ol.expr.LogicalOp.AND,
|
||||
new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.GTE, new ol.expr.Identifier('number'),
|
||||
new ol.expr.Literal(1064866676)),
|
||||
new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.LTE, new ol.expr.Identifier('number'),
|
||||
new ol.expr.Literal(1065512599))));
|
||||
expect(filters[1]).to.eql(new ol.expr.Not(new ol.expr.Comparison(
|
||||
ol.expr.ComparisonOp.LTE, new ol.expr.Identifier('FOO'),
|
||||
new ol.expr.Literal(5000))));
|
||||
expect(filters[2] instanceof ol.expr.Call).to.be(true);
|
||||
expect(filters[2].getCallee().getName()).to.equal(
|
||||
ol.expr.functions.LIKE);
|
||||
expect(filters[2].getArgs()).to.eql([new ol.expr.Identifier('cat'),
|
||||
new ol.expr.Literal('*dog.food!*good'), new ol.expr.Literal('*'),
|
||||
new ol.expr.Literal('.'), new ol.expr.Literal('!'),
|
||||
new ol.expr.Literal(null)]);
|
||||
expect(filters[3] instanceof ol.expr.Call).to.be(true);
|
||||
expect(filters[3].getCallee().getName()).to.equal(
|
||||
ol.expr.functions.IEQ);
|
||||
expect(filters[3].getArgs()).to.eql([new ol.expr.Identifier('cat'),
|
||||
new ol.expr.Literal('dog')]);
|
||||
expect(filters[4] instanceof ol.expr.Comparison).to.be(true);
|
||||
expect(filters[4].getOperator()).to.equal(ol.expr.ComparisonOp.EQ);
|
||||
expect(filters[4].getLeft().getName()).to.equal('cat');
|
||||
expect(filters[4].getRight().getValue()).to.equal('dog');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('reads matchCase', function() {
|
||||
var cases = [{
|
||||
str:
|
||||
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:PropertyIsEqualTo>' +
|
||||
'<ogc:PropertyName>cat</ogc:PropertyName>' +
|
||||
'<ogc:Literal>dog</ogc:Literal>' +
|
||||
'</ogc:PropertyIsEqualTo>' +
|
||||
'</ogc:Filter>',
|
||||
exp: true
|
||||
}, {
|
||||
str:
|
||||
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:PropertyIsEqualTo matchCase="1">' +
|
||||
'<ogc:PropertyName>cat</ogc:PropertyName>' +
|
||||
'<ogc:Literal>dog</ogc:Literal>' +
|
||||
'</ogc:PropertyIsEqualTo>' +
|
||||
'</ogc:Filter>',
|
||||
exp: true
|
||||
}, {
|
||||
str:
|
||||
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:PropertyIsEqualTo matchCase="true">' +
|
||||
'<ogc:PropertyName>cat</ogc:PropertyName>' +
|
||||
'<ogc:Literal>dog</ogc:Literal>' +
|
||||
'</ogc:PropertyIsEqualTo>' +
|
||||
'</ogc:Filter>',
|
||||
exp: true
|
||||
}, {
|
||||
str:
|
||||
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:PropertyIsEqualTo matchCase="0">' +
|
||||
'<ogc:PropertyName>cat</ogc:PropertyName>' +
|
||||
'<ogc:Literal>dog</ogc:Literal>' +
|
||||
'</ogc:PropertyIsEqualTo>' +
|
||||
'</ogc:Filter>',
|
||||
exp: false
|
||||
}, {
|
||||
str:
|
||||
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:PropertyIsEqualTo matchCase="0">' +
|
||||
'<ogc:PropertyName>cat</ogc:PropertyName>' +
|
||||
'<ogc:Literal>dog</ogc:Literal>' +
|
||||
'</ogc:PropertyIsEqualTo>' +
|
||||
'</ogc:Filter>',
|
||||
exp: false
|
||||
}, {
|
||||
str:
|
||||
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:PropertyIsNotEqualTo matchCase="true">' +
|
||||
'<ogc:PropertyName>cat</ogc:PropertyName>' +
|
||||
'<ogc:Literal>dog</ogc:Literal>' +
|
||||
'</ogc:PropertyIsNotEqualTo>' +
|
||||
'</ogc:Filter>',
|
||||
exp: true
|
||||
}, {
|
||||
str:
|
||||
'<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
|
||||
'<ogc:PropertyIsNotEqualTo matchCase="false">' +
|
||||
'<ogc:PropertyName>cat</ogc:PropertyName>' +
|
||||
'<ogc:Literal>dog</ogc:Literal>' +
|
||||
'</ogc:PropertyIsNotEqualTo>' +
|
||||
'</ogc:Filter>',
|
||||
exp: false
|
||||
}];
|
||||
var filter, c;
|
||||
for (var i = 0; i < cases.length; ++i) {
|
||||
c = cases[i];
|
||||
filter = parser.read(c.str);
|
||||
var matchCase = (filter instanceof ol.expr.Call) ? false : true;
|
||||
expect(matchCase).to.equal(c.exp);
|
||||
}
|
||||
});
|
||||
|
||||
it('writes BBOX', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/bbox.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes BBOX without property name', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/bbox_nogeomname.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles intersects', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/intersects.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = parser.read(xml);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles functions', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/function.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Call(new ol.expr.Identifier(
|
||||
ol.expr.functions.INTERSECTS),
|
||||
[new ol.expr.Call(new ol.expr.Identifier('querySingle'),
|
||||
[new ol.expr.Literal('sf:restricted'),
|
||||
new ol.expr.Literal('the_geom'),
|
||||
new ol.expr.Literal('cat=3')]), new ol.expr.Literal(null),
|
||||
new ol.expr.Identifier('the_geom')]);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes custom functions', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/customfunction.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Logical(ol.expr.LogicalOp.AND,
|
||||
new ol.expr.Call(new ol.expr.Identifier(ol.expr.functions.INEQ),
|
||||
[new ol.expr.Identifier('FOO'), new ol.expr.Call(
|
||||
new ol.expr.Identifier('customFunction'),
|
||||
[new ol.expr.Literal('param1'), new ol.expr.Literal('param2')])]));
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes nested functions', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/nestedfunction.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Call(new ol.expr.Identifier(
|
||||
ol.expr.functions.DWITHIN),
|
||||
[new ol.expr.Call(new ol.expr.Identifier('collectGeometries'),
|
||||
[new ol.expr.Call(new ol.expr.Identifier('queryCollection'),
|
||||
[new ol.expr.Literal('sf:roads'),
|
||||
new ol.expr.Literal('the_geom'),
|
||||
new ol.expr.Literal('INCLUDE')])]), new ol.expr.Literal(200),
|
||||
new ol.expr.Literal('meters'),
|
||||
new ol.expr.Literal(null), new ol.expr.Identifier('the_geom')]);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes matchCase on like', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/likematchcase.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var filter = new ol.expr.Call(
|
||||
new ol.expr.Identifier(ol.expr.functions.LIKE),
|
||||
[new ol.expr.Identifier('person'), new ol.expr.Literal('*me*'),
|
||||
new ol.expr.Literal('*'), new ol.expr.Literal('.'),
|
||||
new ol.expr.Literal('!'), new ol.expr.Literal(false)]);
|
||||
var output = parser.write(filter);
|
||||
expect(goog.dom.xml.loadXml(output)).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('writes sortBy on like', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/filter_v1_1_0/sortby.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var writer = parser.writers['http://www.opengis.net/ogc']['SortBy'];
|
||||
var output = writer.call(parser, [{
|
||||
'property': new ol.expr.Identifier('Title'),
|
||||
'order': new ol.expr.Literal('ASC')
|
||||
},{
|
||||
'property': new ol.expr.Identifier('Relevance'),
|
||||
'order': new ol.expr.Literal('DESC')
|
||||
}]);
|
||||
expect(output).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.expr.Logical');
|
||||
goog.require('ol.expr.LogicalOp');
|
||||
goog.require('ol.expr.Not');
|
||||
goog.require('ol.expr.functions');
|
||||
goog.require('ol.parser.ogc.Filter_v1_1_0');
|
||||
@@ -1,90 +0,0 @@
|
||||
goog.provide('ol.test.parser.ogc.SLD_v1_0_0');
|
||||
|
||||
|
||||
describe('ol.parser.ogc.SLD_v1_0_0', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.SLD();
|
||||
var obj;
|
||||
|
||||
describe('reading and writing', function() {
|
||||
it('Handles reading', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/sld_v1_0_0.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
obj = parser.read(xml);
|
||||
expect(obj.version).to.equal('1.0.0');
|
||||
var style = obj.namedLayers['AAA161'].userStyles[0];
|
||||
expect(style).to.be.a(ol.style.Style);
|
||||
expect(style.rules_.length).to.equal(2);
|
||||
var first = style.rules_[0];
|
||||
expect(first).to.be.a(ol.style.Rule);
|
||||
expect(first.filter_).to.be.a(ol.expr.Comparison);
|
||||
expect(first.filter_.getLeft()).to.be.a(ol.expr.Identifier);
|
||||
expect(first.filter_.getLeft().getName()).to.equal('CTE');
|
||||
expect(first.filter_.getOperator()).to.equal(ol.expr.ComparisonOp.EQ);
|
||||
expect(first.filter_.getRight()).to.be.a(ol.expr.Literal);
|
||||
expect(first.filter_.getRight().getValue()).to.equal('V0305');
|
||||
expect(first.getSymbolizers().length).to.equal(3);
|
||||
expect(first.getSymbolizers()[0]).to.be.a(ol.style.Fill);
|
||||
expect(first.getSymbolizers()[0].getColor().getValue()).to.equal(
|
||||
'#ffffff');
|
||||
expect(first.getSymbolizers()[0].getOpacity().getValue()).to.equal(1);
|
||||
expect(first.getSymbolizers()[1]).to.be.a(ol.style.Stroke);
|
||||
expect(first.getSymbolizers()[1].getColor().getValue()).to.equal(
|
||||
'#000000');
|
||||
expect(first.getSymbolizers()[2]).to.be.a(ol.style.Text);
|
||||
expect(first.getSymbolizers()[2].getText()).to.be.a(ol.expr.Call);
|
||||
expect(first.getSymbolizers()[2].getText().getArgs().length).to.equal(
|
||||
3);
|
||||
expect(first.getSymbolizers()[2].getText().getArgs()[0]).to.be.a(
|
||||
ol.expr.Literal);
|
||||
expect(first.getSymbolizers()[2].getText().getArgs()[0].getValue()).
|
||||
to.equal('A');
|
||||
expect(first.getSymbolizers()[2].getText().getArgs()[1]).to.be.a(
|
||||
ol.expr.Identifier);
|
||||
expect(first.getSymbolizers()[2].getText().getArgs()[1].getName()).
|
||||
to.equal('FOO');
|
||||
expect(first.getSymbolizers()[2].getText().getArgs()[2]).to.be.a(
|
||||
ol.expr.Literal);
|
||||
expect(first.getSymbolizers()[2].getText().getArgs()[2].getValue()).
|
||||
to.equal('label');
|
||||
expect(first.getSymbolizers()[2].getColor().getValue()).to.equal(
|
||||
'#000000');
|
||||
expect(first.getSymbolizers()[2].getFontFamily().getValue()).to.equal(
|
||||
'Arial');
|
||||
expect(first.getSymbolizers()[2].getStroke()).to.be.a(ol.style.Stroke);
|
||||
expect(first.getSymbolizers()[2].getStroke().getColor().getValue())
|
||||
.to.equal('#ffffff');
|
||||
expect(first.getSymbolizers()[2].getStroke().getWidth().getValue())
|
||||
.to.equal(6);
|
||||
var second = style.rules_[1];
|
||||
expect(second.filter_).to.be.a(ol.expr.Comparison);
|
||||
expect(second.getSymbolizers().length).to.equal(2);
|
||||
expect(second.getSymbolizers()[0]).to.be.a(ol.style.Fill);
|
||||
expect(second.getSymbolizers()[1]).to.be.a(ol.style.Stroke);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('Handles write', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/sld_v1_0_0_write.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
expect(goog.dom.xml.loadXml(parser.write(obj))).to.xmleql(xml);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.dom.xml');
|
||||
goog.require('ol.parser.ogc.SLD_v1_0_0');
|
||||
goog.require('ol.parser.ogc.SLD');
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
goog.require('ol.expr.Identifier');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.Rule');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Style');
|
||||
goog.require('ol.style.Text');
|
||||
@@ -1,25 +0,0 @@
|
||||
goog.provide('ol.test.parser.ogc.Versioned');
|
||||
|
||||
describe('ol.parser.ogc.versioned', function() {
|
||||
|
||||
describe('test constructor', function() {
|
||||
var parser = new ol.parser.ogc.Versioned({version: '1.0.0'});
|
||||
it('new OpenLayers.Format.XML.VersionedOGC returns object', function() {
|
||||
expect(parser instanceof ol.parser.ogc.Versioned).to.be.ok();
|
||||
});
|
||||
it('constructor sets version correctly', function() {
|
||||
expect(parser.version).to.eql('1.0.0');
|
||||
});
|
||||
it('defaultVersion should be null if not specified', function() {
|
||||
expect(parser.defaultVersion).to.be(null);
|
||||
});
|
||||
it('format has a read function', function() {
|
||||
expect(typeof(parser.read)).to.eql('function');
|
||||
});
|
||||
it('format has a write function', function() {
|
||||
expect(typeof(parser.write)).to.eql('function');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('ol.parser.ogc.Versioned');
|
||||
@@ -1,159 +0,0 @@
|
||||
goog.provide('ol.test.parser.ogc.WMTSCapabilities_v1_0_0');
|
||||
|
||||
describe('ol.parser.ogc.wmtscapabilities_v1_0_0', function() {
|
||||
|
||||
var parser = new ol.parser.ogc.WMTSCapabilities();
|
||||
|
||||
describe('test ows', function() {
|
||||
it('Test ows', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmtscapabilities_v1_0_0/' +
|
||||
'ogcsample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var serviceIdentification = obj.serviceIdentification;
|
||||
var serviceProvider = obj.serviceProvider;
|
||||
var operationsMetadata = obj.operationsMetadata;
|
||||
var contactInfo = serviceProvider.serviceContact.contactInfo;
|
||||
|
||||
expect(serviceIdentification.title).to.eql('Web Map Tile Service');
|
||||
expect(serviceIdentification.serviceTypeVersion).to.eql('1.0.0');
|
||||
expect(serviceIdentification.serviceType.value).to.eql('OGC WMTS');
|
||||
expect(serviceProvider.providerName).to.eql('MiraMon');
|
||||
var url = 'http://www.creaf.uab.es/miramon';
|
||||
expect(serviceProvider.providerSite).to.eql(url);
|
||||
var name = 'Joan Maso Pau';
|
||||
expect(serviceProvider.serviceContact.individualName).to.eql(name);
|
||||
var position = 'Senior Software Engineer';
|
||||
expect(serviceProvider.serviceContact.positionName).to.eql(position);
|
||||
expect(contactInfo.address.administrativeArea).to.eql('Barcelona');
|
||||
expect(contactInfo.address.city).to.eql('Bellaterra');
|
||||
expect(contactInfo.address.country).to.eql('Spain');
|
||||
expect(contactInfo.address.deliveryPoint).to.eql('Fac Ciencies UAB');
|
||||
var email = 'joan.maso@uab.es';
|
||||
expect(contactInfo.address.electronicMailAddress).to.eql(email);
|
||||
expect(contactInfo.address.postalCode).to.eql('08193');
|
||||
expect(contactInfo.phone.voice).to.eql('+34 93 581 1312');
|
||||
var dcp = operationsMetadata.GetCapabilities.dcp;
|
||||
url = 'http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?';
|
||||
expect(dcp.http.get[0].url).to.eql(url);
|
||||
dcp = operationsMetadata.GetCapabilities.dcp;
|
||||
expect(dcp.http.get[0].constraints.GetEncoding.allowedValues).to.eql(
|
||||
{'KVP': true});
|
||||
url = 'http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?';
|
||||
dcp = operationsMetadata.GetFeatureInfo.dcp;
|
||||
expect(dcp.http.get[0].url).to.eql(url);
|
||||
dcp = operationsMetadata.GetFeatureInfo.dcp;
|
||||
expect(dcp.http.get[0].constraints).to.be(undefined);
|
||||
url = 'http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?';
|
||||
expect(operationsMetadata.GetTile.dcp.http.get[0].url).to.eql(url);
|
||||
dcp = operationsMetadata.GetTile.dcp;
|
||||
expect(dcp.http.get[0].constraints).to.be(undefined);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('test layers', function() {
|
||||
it('Test layers', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmtscapabilities_v1_0_0/' +
|
||||
'ogcsample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var contents = obj.contents;
|
||||
var layer = contents.layers[0];
|
||||
var wgs84Bbox = layer.bounds;
|
||||
var dimensions = layer.dimensions;
|
||||
|
||||
expect(contents.layers.length).to.eql(1);
|
||||
expect(layer['abstract']).to.eql('Coastline/shorelines (BA010)');
|
||||
expect(layer.identifier).to.eql('coastlines');
|
||||
expect(layer.title).to.eql('Coastlines');
|
||||
expect(layer.formats.length).to.eql(2);
|
||||
expect(layer.formats[0]).to.eql('image/png');
|
||||
expect(layer.formats[1]).to.eql('image/gif');
|
||||
expect(layer.styles.length).to.eql(2);
|
||||
expect(layer.styles[0].identifier).to.eql('DarkBlue');
|
||||
expect(layer.styles[0].isDefault).to.be.ok();
|
||||
expect(layer.styles[0].title).to.eql('Dark Blue');
|
||||
var url = 'http://www.miramon.uab.es/wmts/Coastlines/' +
|
||||
'coastlines_darkBlue.png';
|
||||
expect(layer.styles[0].legend.href).to.eql(url);
|
||||
expect(layer.styles[0].legend.format).to.eql('image/png');
|
||||
expect(layer.styles[1].identifier).to.eql('thickAndRed');
|
||||
expect(!layer.styles[1].isDefault).to.be.ok();
|
||||
expect(layer.styles[1].title).to.eql('Thick And Red');
|
||||
expect(layer.styles[1].legend).to.be(undefined);
|
||||
expect(layer.tileMatrixSetLinks.length).to.eql(1);
|
||||
expect(layer.tileMatrixSetLinks[0].tileMatrixSet).to.eql('BigWorld');
|
||||
expect(wgs84Bbox).to.be.an(Array);
|
||||
expect(wgs84Bbox[0]).to.eql(-180.0);
|
||||
expect(wgs84Bbox[1]).to.eql(180.0);
|
||||
expect(wgs84Bbox[2]).to.eql(-90.0);
|
||||
expect(wgs84Bbox[3]).to.eql(90.0);
|
||||
expect(layer.resourceUrls.hasOwnProperty('tile')).to.be.ok();
|
||||
var format = 'image/png';
|
||||
expect(layer.resourceUrls.tile.hasOwnProperty(format)).to.be.ok();
|
||||
expect(layer.resourceUrls.tile[format].length).to.eql(2);
|
||||
var tpl = 'http://a.example.com/wmts/coastlines/{TileMatrix}/' +
|
||||
'{TileRow}/{TileCol}.png';
|
||||
expect(layer.resourceUrls.tile[format][0]).to.eql(tpl);
|
||||
tpl = 'http://b.example.com/wmts/coastlines/{TileMatrix}/' +
|
||||
'{TileRow}/{TileCol}.png';
|
||||
expect(layer.resourceUrls.tile[format][1]).to.eql(tpl);
|
||||
expect(layer.resourceUrls.hasOwnProperty('FeatureInfo')).to.be.ok();
|
||||
format = 'application/gml+xml; version=3.1';
|
||||
expect(layer.resourceUrls.FeatureInfo.hasOwnProperty(format))
|
||||
.to.be.ok();
|
||||
expect(layer.resourceUrls.FeatureInfo[format].length).to.eql(1);
|
||||
tpl = 'http://www.example.com/wmts/coastlines/{TileMatrixSet}/' +
|
||||
'{TileMatrix}/{TileRow}/{TileCol}/{J}/{I}.xml';
|
||||
expect(layer.resourceUrls.FeatureInfo[format][0]).to.eql(tpl);
|
||||
expect(dimensions.length).to.eql(1);
|
||||
expect(dimensions[0].title).to.eql('Time');
|
||||
expect(dimensions[0]['abstract']).to.eql('Monthly datasets');
|
||||
expect(dimensions[0].identifier).to.eql('TIME');
|
||||
expect(dimensions[0]['default']).to.eql('default');
|
||||
expect(dimensions[0].values.length).to.eql(3);
|
||||
expect(dimensions[0].values[0]).to.eql('2007-05');
|
||||
expect(dimensions[0].values[1]).to.eql('2007-06');
|
||||
expect(dimensions[0].values[1]).to.eql('2007-06');
|
||||
expect(dimensions[0].values[2]).to.eql('2007-07');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('test tileMatrixSets', function() {
|
||||
it('Test tileMatrixSets', function(done) {
|
||||
var url = 'spec/ol/parser/ogc/xml/wmtscapabilities_v1_0_0/' +
|
||||
'ogcsample.xml';
|
||||
afterLoadXml(url, function(xml) {
|
||||
var obj = parser.read(xml);
|
||||
var tileMatrixSets = obj.contents.tileMatrixSets;
|
||||
var bigWorld = tileMatrixSets['BigWorld'];
|
||||
|
||||
expect(bigWorld).to.not.be(undefined);
|
||||
expect(bigWorld.identifier).to.eql('BigWorld');
|
||||
expect(bigWorld.matrixIds.length).to.eql(2);
|
||||
expect(bigWorld.matrixIds[0].identifier).to.eql('1e6');
|
||||
expect(bigWorld.matrixIds[0].matrixHeight).to.eql(50000);
|
||||
expect(bigWorld.matrixIds[0].matrixWidth).to.eql(60000);
|
||||
expect(bigWorld.matrixIds[0].scaleDenominator).to.eql(1000000);
|
||||
expect(bigWorld.matrixIds[0].tileWidth).to.eql(256);
|
||||
expect(bigWorld.matrixIds[0].tileHeight).to.eql(256);
|
||||
expect(bigWorld.matrixIds[0].topLeftCorner[0]).to.eql(-180);
|
||||
expect(bigWorld.matrixIds[0].topLeftCorner[1]).to.eql(84);
|
||||
expect(bigWorld.matrixIds[1].identifier).to.eql('2.5e6');
|
||||
expect(bigWorld.matrixIds[1].matrixHeight).to.eql(7000);
|
||||
expect(bigWorld.matrixIds[1].matrixWidth).to.eql(9000);
|
||||
expect(bigWorld.matrixIds[1].scaleDenominator).to.eql(2500000);
|
||||
expect(bigWorld.matrixIds[1].tileWidth).to.eql(256);
|
||||
expect(bigWorld.matrixIds[1].tileHeight).to.eql(256);
|
||||
expect(bigWorld.matrixIds[1].topLeftCorner[0]).to.eql(-180);
|
||||
expect(bigWorld.matrixIds[1].topLeftCorner[1]).to.eql(84);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
goog.require('ol.parser.ogc.WMTSCapabilities');
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ows:ExceptionReport language="en" version="1.0.0"
|
||||
xsi:schemaLocation="http://www.opengis.net/ows http://schemas.opengis.net/ows/1.0.0/owsExceptionReport.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows">
|
||||
<ows:Exception locator="foo" exceptionCode="InvalidParameterValue">
|
||||
<ows:ExceptionText>Update error: Error occured updating features</ows:ExceptionText>
|
||||
<ows:ExceptionText>Second exception line</ows:ExceptionText>
|
||||
</ows:Exception>
|
||||
</ows:ExceptionReport>
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ows:ExceptionReport xml:lang="en" version="1.1.0"
|
||||
xsi:schemaLocation="http://www.opengis.net/ows http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows/1.1">
|
||||
<ows:Exception locator="foo" exceptionCode="InvalidParameterValue">
|
||||
<ows:ExceptionText>Update error: Error occured updating features</ows:ExceptionText>
|
||||
<ows:ExceptionText>Second exception line</ows:ExceptionText>
|
||||
</ows:Exception>
|
||||
</ows:ExceptionReport>
|
||||
@@ -1,23 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:Or>
|
||||
<ogc:PropertyIsBetween>
|
||||
<ogc:PropertyName>number</ogc:PropertyName>
|
||||
<ogc:LowerBoundary>
|
||||
<ogc:Literal>1064866676</ogc:Literal>
|
||||
</ogc:LowerBoundary>
|
||||
<ogc:UpperBoundary>
|
||||
<ogc:Literal>1065512599</ogc:Literal>
|
||||
</ogc:UpperBoundary>
|
||||
</ogc:PropertyIsBetween>
|
||||
<ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
|
||||
<ogc:PropertyName>cat</ogc:PropertyName>
|
||||
<ogc:Literal>*dog.food!*good</ogc:Literal>
|
||||
</ogc:PropertyIsLike>
|
||||
<ogc:Not>
|
||||
<ogc:PropertyIsLessThanOrEqualTo>
|
||||
<ogc:PropertyName>FOO</ogc:PropertyName>
|
||||
<ogc:Literal>5000</ogc:Literal>
|
||||
</ogc:PropertyIsLessThanOrEqualTo>
|
||||
</ogc:Not>
|
||||
</ogc:Or>
|
||||
</ogc:Filter>
|
||||
@@ -1,8 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<ogc:BBOX>
|
||||
<ogc:PropertyName>the_geom</ogc:PropertyName>
|
||||
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">-180,-90 180,90</gml:coordinates>
|
||||
</gml:Box>
|
||||
</ogc:BBOX>
|
||||
</ogc:Filter>
|
||||
@@ -1,7 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<ogc:BBOX>
|
||||
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">-180,-90 180,90</gml:coordinates>
|
||||
</gml:Box>
|
||||
</ogc:BBOX>
|
||||
</ogc:Filter>
|
||||
@@ -1,11 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<ogc:PropertyIsBetween>
|
||||
<ogc:PropertyName>number</ogc:PropertyName>
|
||||
<ogc:LowerBoundary>
|
||||
<ogc:Literal>0</ogc:Literal>
|
||||
</ogc:LowerBoundary>
|
||||
<ogc:UpperBoundary>
|
||||
<ogc:Literal>100</ogc:Literal>
|
||||
</ogc:UpperBoundary>
|
||||
</ogc:PropertyIsBetween>
|
||||
</ogc:Filter>
|
||||
@@ -1,7 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:PropertyIsBetween>
|
||||
<ogc:PropertyName>number</ogc:PropertyName>
|
||||
<ogc:LowerBoundary>0</ogc:LowerBoundary>
|
||||
<ogc:UpperBoundary>100</ogc:UpperBoundary>
|
||||
</ogc:PropertyIsBetween>
|
||||
</ogc:Filter>
|
||||
@@ -1,12 +0,0 @@
|
||||
<Filter xmlns="http://www.opengis.net/ogc" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Contains>
|
||||
<PropertyName>Geometry</PropertyName>
|
||||
<gml:Polygon xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</Contains>
|
||||
</Filter>
|
||||
@@ -1,9 +0,0 @@
|
||||
<Filter xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<DWithin>
|
||||
<PropertyName>Geometry</PropertyName>
|
||||
<gml:Point xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2488789,289552</gml:coordinates>
|
||||
</gml:Point>
|
||||
<Distance units="m">1000</Distance>
|
||||
</DWithin>
|
||||
</Filter>
|
||||
@@ -1,12 +0,0 @@
|
||||
<Filter xmlns="http://www.opengis.net/ogc" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Intersects>
|
||||
<PropertyName>Geometry</PropertyName>
|
||||
<gml:Polygon xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</Intersects>
|
||||
</Filter>
|
||||
@@ -1,10 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<ogc:Or>
|
||||
<ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
|
||||
<ogc:PropertyName>person</ogc:PropertyName>
|
||||
<ogc:Literal>me</ogc:Literal>
|
||||
</ogc:PropertyIsLike>
|
||||
<ogc:FeatureId fid="foo.1"/>
|
||||
<ogc:FeatureId fid="foo.2"/>
|
||||
</ogc:Or>
|
||||
</ogc:Filter>
|
||||
@@ -1,10 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<ogc:And>
|
||||
<ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
|
||||
<ogc:PropertyName>person</ogc:PropertyName>
|
||||
<ogc:Literal>me</ogc:Literal>
|
||||
</ogc:PropertyIsLike>
|
||||
<ogc:FeatureId fid="foo.1"/>
|
||||
<ogc:FeatureId fid="foo.2"/>
|
||||
</ogc:And>
|
||||
</ogc:Filter>
|
||||
@@ -1,5 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<ogc:Not>
|
||||
<ogc:FeatureId fid="foo.2"/>
|
||||
</ogc:Not>
|
||||
</ogc:Filter>
|
||||
@@ -1,5 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd">
|
||||
<ogc:PropertyIsNull>
|
||||
<ogc:PropertyName>prop</ogc:PropertyName>
|
||||
</ogc:PropertyIsNull>
|
||||
</ogc:Filter>
|
||||
@@ -1,12 +0,0 @@
|
||||
<Filter xmlns="http://www.opengis.net/ogc" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Within>
|
||||
<PropertyName>Geometry</PropertyName>
|
||||
<gml:Polygon xmlns:gml="http://www.opengis.net/gml">
|
||||
<gml:outerBoundaryIs>
|
||||
<gml:LinearRing>
|
||||
<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>
|
||||
</gml:LinearRing>
|
||||
</gml:outerBoundaryIs>
|
||||
</gml:Polygon>
|
||||
</Within>
|
||||
</Filter>
|
||||
@@ -1,9 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<ogc:BBOX>
|
||||
<ogc:PropertyName>the_geom</ogc:PropertyName>
|
||||
<gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
||||
<gml:lowerCorner>-180 -90</gml:lowerCorner>
|
||||
<gml:upperCorner>180 90</gml:upperCorner>
|
||||
</gml:Envelope>
|
||||
</ogc:BBOX>
|
||||
</ogc:Filter>
|
||||
@@ -1,8 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<ogc:BBOX>
|
||||
<gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
||||
<gml:lowerCorner>-180 -90</gml:lowerCorner>
|
||||
<gml:upperCorner>180 90</gml:upperCorner>
|
||||
</gml:Envelope>
|
||||
</ogc:BBOX>
|
||||
</ogc:Filter>
|
||||
@@ -1,11 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<ogc:And>
|
||||
<ogc:PropertyIsNotEqualTo matchCase="false">
|
||||
<ogc:PropertyName>FOO</ogc:PropertyName>
|
||||
<ogc:Function name="customFunction">
|
||||
<ogc:Literal>param1</ogc:Literal>
|
||||
<ogc:Literal>param2</ogc:Literal>
|
||||
</ogc:Function>
|
||||
</ogc:PropertyIsNotEqualTo>
|
||||
</ogc:And>
|
||||
</ogc:Filter>
|
||||
@@ -1,10 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<ogc:Intersects>
|
||||
<ogc:PropertyName>the_geom</ogc:PropertyName>
|
||||
<ogc:Function name="querySingle">
|
||||
<ogc:Literal>sf:restricted</ogc:Literal>
|
||||
<ogc:Literal>the_geom</ogc:Literal>
|
||||
<ogc:Literal>cat=3</ogc:Literal>
|
||||
</ogc:Function>
|
||||
</ogc:Intersects>
|
||||
</ogc:Filter>
|
||||
@@ -1,9 +0,0 @@
|
||||
<Filter xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<Intersects>
|
||||
<PropertyName>Geometry</PropertyName>
|
||||
<gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
|
||||
<gml:lowerCorner>-180 -90</gml:lowerCorner>
|
||||
<gml:upperCorner>180 90</gml:upperCorner>
|
||||
</gml:Envelope>
|
||||
</Intersects>
|
||||
</Filter>
|
||||
@@ -1,6 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!" matchCase="false">
|
||||
<ogc:PropertyName>person</ogc:PropertyName>
|
||||
<ogc:Literal>*me*</ogc:Literal>
|
||||
</ogc:PropertyIsLike>
|
||||
</ogc:Filter>
|
||||
@@ -1,13 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<ogc:DWithin>
|
||||
<ogc:PropertyName>the_geom</ogc:PropertyName>
|
||||
<ogc:Function name="collectGeometries">
|
||||
<ogc:Function name="queryCollection">
|
||||
<ogc:Literal>sf:roads</ogc:Literal>
|
||||
<ogc:Literal>the_geom</ogc:Literal>
|
||||
<ogc:Literal>INCLUDE</ogc:Literal>
|
||||
</ogc:Function>
|
||||
</ogc:Function>
|
||||
<ogc:Distance units="meters">200</ogc:Distance>
|
||||
</ogc:DWithin>
|
||||
</ogc:Filter>
|
||||
@@ -1,10 +0,0 @@
|
||||
<ogc:SortBy xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:SortProperty>
|
||||
<ogc:PropertyName>Title</ogc:PropertyName>
|
||||
<ogc:SortOrder>ASC</ogc:SortOrder>
|
||||
</ogc:SortProperty>
|
||||
<ogc:SortProperty>
|
||||
<ogc:PropertyName>Relevance</ogc:PropertyName>
|
||||
<ogc:SortOrder>DESC</ogc:SortOrder>
|
||||
</ogc:SortProperty>
|
||||
</ogc:SortBy>
|
||||
@@ -1,31 +0,0 @@
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd">
|
||||
<ogc:Or>
|
||||
<ogc:PropertyIsBetween>
|
||||
<ogc:PropertyName>number</ogc:PropertyName>
|
||||
<ogc:LowerBoundary>
|
||||
<ogc:Literal>1064866676</ogc:Literal>
|
||||
</ogc:LowerBoundary>
|
||||
<ogc:UpperBoundary>
|
||||
<ogc:Literal>1065512599</ogc:Literal>
|
||||
</ogc:UpperBoundary>
|
||||
</ogc:PropertyIsBetween>
|
||||
<ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!">
|
||||
<ogc:PropertyName>cat</ogc:PropertyName>
|
||||
<ogc:Literal>*dog.food!*good</ogc:Literal>
|
||||
</ogc:PropertyIsLike>
|
||||
<ogc:Not>
|
||||
<ogc:PropertyIsLessThanOrEqualTo>
|
||||
<ogc:PropertyName>FOO</ogc:PropertyName>
|
||||
<ogc:Literal>5000</ogc:Literal>
|
||||
</ogc:PropertyIsLessThanOrEqualTo>
|
||||
</ogc:Not>
|
||||
<ogc:PropertyIsEqualTo>
|
||||
<ogc:PropertyName>cat</ogc:PropertyName>
|
||||
<ogc:Literal>dog</ogc:Literal>
|
||||
</ogc:PropertyIsEqualTo>
|
||||
<ogc:PropertyIsEqualTo matchCase="false">
|
||||
<ogc:PropertyName>cat</ogc:PropertyName>
|
||||
<ogc:Literal>dog</ogc:Literal>
|
||||
</ogc:PropertyIsEqualTo>
|
||||
</ogc:Or>
|
||||
</ogc:Filter>
|
||||
@@ -1,129 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld"
|
||||
xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
|
||||
<NamedLayer>
|
||||
<Name>AAA161</Name>
|
||||
<UserStyle>
|
||||
<FeatureTypeStyle>
|
||||
<Rule>
|
||||
<Name>stortsteen</Name>
|
||||
<ogc:Filter>
|
||||
<ogc:PropertyIsEqualTo>
|
||||
<ogc:PropertyName>CTE</ogc:PropertyName>
|
||||
<ogc:Literal>V0305</ogc:Literal>
|
||||
</ogc:PropertyIsEqualTo>
|
||||
</ogc:Filter>
|
||||
<MaxScaleDenominator>50000</MaxScaleDenominator>
|
||||
<PolygonSymbolizer>
|
||||
<Fill>
|
||||
<CssParameter name="fill">#ffffff</CssParameter>
|
||||
</Fill>
|
||||
<Stroke>
|
||||
<CssParameter name="stroke">#000000</CssParameter>
|
||||
</Stroke>
|
||||
</PolygonSymbolizer>
|
||||
<TextSymbolizer>
|
||||
<Label> A <ogc:PropertyName>FOO</ogc:PropertyName> label </Label>
|
||||
<Font>
|
||||
<CssParameter name="font-family">Arial</CssParameter>
|
||||
<CssParameter name="font-size">14</CssParameter>
|
||||
<CssParameter name="font-weight">bold</CssParameter>
|
||||
<CssParameter name="font-style">normal</CssParameter>
|
||||
</Font>
|
||||
<LabelPlacement>
|
||||
<PointPlacement>
|
||||
<AnchorPoint>
|
||||
<AnchorPointX>0.5</AnchorPointX>
|
||||
<AnchorPointY>0.5</AnchorPointY>
|
||||
</AnchorPoint>
|
||||
<Displacement>
|
||||
<DisplacementX>5</DisplacementX>
|
||||
<DisplacementY>5</DisplacementY>
|
||||
</Displacement>
|
||||
<Rotation>45</Rotation>
|
||||
</PointPlacement>
|
||||
</LabelPlacement>
|
||||
<Halo>
|
||||
<Radius>3</Radius>
|
||||
<Fill>
|
||||
<CssParameter name="fill">#ffffff</CssParameter>
|
||||
</Fill>
|
||||
</Halo>
|
||||
<Fill>
|
||||
<CssParameter name="fill">#000000</CssParameter>
|
||||
</Fill>
|
||||
</TextSymbolizer>
|
||||
</Rule>
|
||||
<Rule>
|
||||
<Name>betonbekleding</Name>
|
||||
<ogc:Filter>
|
||||
<ogc:PropertyIsLessThan>
|
||||
<ogc:PropertyName>CTE</ogc:PropertyName>
|
||||
<ogc:Literal>1000</ogc:Literal>
|
||||
</ogc:PropertyIsLessThan>
|
||||
</ogc:Filter>
|
||||
<MaxScaleDenominator>50000</MaxScaleDenominator>
|
||||
<PolygonSymbolizer>
|
||||
<Fill>
|
||||
<CssParameter name="fill">#ffff00</CssParameter>
|
||||
</Fill>
|
||||
<Stroke>
|
||||
<CssParameter name="stroke">#0000ff</CssParameter>
|
||||
</Stroke>
|
||||
</PolygonSymbolizer>
|
||||
</Rule>
|
||||
</FeatureTypeStyle>
|
||||
</UserStyle>
|
||||
</NamedLayer>
|
||||
<NamedLayer>
|
||||
<Name>Second Layer</Name>
|
||||
<UserStyle>
|
||||
<FeatureTypeStyle>
|
||||
<Rule>
|
||||
<Name>first rule second layer</Name>
|
||||
<ogc:Filter>
|
||||
<ogc:Or>
|
||||
<ogc:PropertyIsBetween>
|
||||
<ogc:PropertyName>number</ogc:PropertyName>
|
||||
<ogc:LowerBoundary>
|
||||
<ogc:Literal>1064866676</ogc:Literal>
|
||||
</ogc:LowerBoundary>
|
||||
<ogc:UpperBoundary>
|
||||
<ogc:Literal>1065512599</ogc:Literal>
|
||||
</ogc:UpperBoundary>
|
||||
</ogc:PropertyIsBetween>
|
||||
<ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
|
||||
<ogc:PropertyName>cat</ogc:PropertyName>
|
||||
<ogc:Literal>*dog.food!*good</ogc:Literal>
|
||||
</ogc:PropertyIsLike>
|
||||
<ogc:Not>
|
||||
<ogc:PropertyIsLessThanOrEqualTo>
|
||||
<ogc:PropertyName>FOO</ogc:PropertyName>
|
||||
<ogc:Literal>5000</ogc:Literal>
|
||||
</ogc:PropertyIsLessThanOrEqualTo>
|
||||
</ogc:Not>
|
||||
</ogc:Or>
|
||||
</ogc:Filter>
|
||||
<MaxScaleDenominator>10000</MaxScaleDenominator>
|
||||
<PointSymbolizer>
|
||||
<Graphic>
|
||||
<Mark>
|
||||
<WellKnownName>star</WellKnownName>
|
||||
<Fill>
|
||||
<CssParameter name="fill">lime</CssParameter>
|
||||
</Fill>
|
||||
<Stroke>
|
||||
<CssParameter name="stroke">olive</CssParameter>
|
||||
<CssParameter name="stroke-width">2</CssParameter>
|
||||
</Stroke>
|
||||
</Mark>
|
||||
<Size><ogc:PropertyName>SIZE</ogc:PropertyName></Size>
|
||||
</Graphic>
|
||||
</PointSymbolizer>
|
||||
</Rule>
|
||||
</FeatureTypeStyle>
|
||||
</UserStyle>
|
||||
</NamedLayer>
|
||||
</StyledLayerDescriptor>
|
||||
@@ -1,133 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<sld:StyledLayerDescriptor xmlns:sld="http://www.opengis.net/sld" version="1.0.0"
|
||||
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<sld:NamedLayer>
|
||||
<sld:Name>AAA161</sld:Name>
|
||||
<sld:UserStyle>
|
||||
<sld:FeatureTypeStyle>
|
||||
<sld:Rule>
|
||||
<sld:Name>stortsteen</sld:Name>
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:PropertyIsEqualTo>
|
||||
<ogc:PropertyName>CTE</ogc:PropertyName>
|
||||
<ogc:Literal>V0305</ogc:Literal>
|
||||
</ogc:PropertyIsEqualTo>
|
||||
</ogc:Filter>
|
||||
<sld:MaxScaleDenominator>49999.99999999999</sld:MaxScaleDenominator>
|
||||
<sld:PolygonSymbolizer>
|
||||
<sld:Fill>
|
||||
<sld:CssParameter name="fill">#ffffff</sld:CssParameter>
|
||||
<sld:CssParameter name="fill-opacity">1</sld:CssParameter>
|
||||
</sld:Fill>
|
||||
</sld:PolygonSymbolizer>
|
||||
<sld:LineSymbolizer>
|
||||
<sld:Stroke>
|
||||
<sld:CssParameter name="stroke">#000000</sld:CssParameter>
|
||||
<sld:CssParameter name="stroke-opacity">1</sld:CssParameter>
|
||||
<sld:CssParameter name="stroke-width">1</sld:CssParameter>
|
||||
</sld:Stroke>
|
||||
</sld:LineSymbolizer>
|
||||
<sld:TextSymbolizer>
|
||||
<sld:Label><ogc:Literal xmlns:ogc="http://www.opengis.net/ogc"
|
||||
>A</ogc:Literal><ogc:PropertyName
|
||||
xmlns:ogc="http://www.opengis.net/ogc"
|
||||
>FOO</ogc:PropertyName><ogc:Literal
|
||||
xmlns:ogc="http://www.opengis.net/ogc"
|
||||
>label</ogc:Literal></sld:Label>
|
||||
<sld:Font>
|
||||
<sld:CssParameter name="font-family">Arial</sld:CssParameter>
|
||||
<sld:CssParameter name="font-size">14</sld:CssParameter>
|
||||
</sld:Font>
|
||||
<sld:Halo>
|
||||
<sld:Radius>3</sld:Radius>
|
||||
<sld:Fill>
|
||||
<sld:CssParameter name="fill">#ffffff</sld:CssParameter>
|
||||
<sld:CssParameter name="fill-opacity">1</sld:CssParameter>
|
||||
</sld:Fill>
|
||||
</sld:Halo>
|
||||
<sld:Fill>
|
||||
<sld:CssParameter name="fill">#000000</sld:CssParameter>
|
||||
<sld:CssParameter name="fill-opacity">1</sld:CssParameter>
|
||||
</sld:Fill>
|
||||
</sld:TextSymbolizer>
|
||||
</sld:Rule>
|
||||
<sld:Rule>
|
||||
<sld:Name>betonbekleding</sld:Name>
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:PropertyIsLessThan>
|
||||
<ogc:PropertyName>CTE</ogc:PropertyName>
|
||||
<ogc:Literal>1000</ogc:Literal>
|
||||
</ogc:PropertyIsLessThan>
|
||||
</ogc:Filter>
|
||||
<sld:MaxScaleDenominator>49999.99999999999</sld:MaxScaleDenominator>
|
||||
<sld:PolygonSymbolizer>
|
||||
<sld:Fill>
|
||||
<sld:CssParameter name="fill">#ffff00</sld:CssParameter>
|
||||
<sld:CssParameter name="fill-opacity">1</sld:CssParameter>
|
||||
</sld:Fill>
|
||||
</sld:PolygonSymbolizer>
|
||||
<sld:LineSymbolizer>
|
||||
<sld:Stroke>
|
||||
<sld:CssParameter name="stroke">#0000ff</sld:CssParameter>
|
||||
<sld:CssParameter name="stroke-opacity">1</sld:CssParameter>
|
||||
<sld:CssParameter name="stroke-width">1</sld:CssParameter>
|
||||
</sld:Stroke>
|
||||
</sld:LineSymbolizer>
|
||||
</sld:Rule>
|
||||
</sld:FeatureTypeStyle>
|
||||
</sld:UserStyle>
|
||||
</sld:NamedLayer>
|
||||
<sld:NamedLayer>
|
||||
<sld:Name>Second Layer</sld:Name>
|
||||
<sld:UserStyle>
|
||||
<sld:FeatureTypeStyle>
|
||||
<sld:Rule>
|
||||
<sld:Name>first rule second layer</sld:Name>
|
||||
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
|
||||
<ogc:Or>
|
||||
<ogc:Not>
|
||||
<ogc:PropertyIsLessThanOrEqualTo>
|
||||
<ogc:PropertyName>FOO</ogc:PropertyName>
|
||||
<ogc:Literal>5000</ogc:Literal>
|
||||
</ogc:PropertyIsLessThanOrEqualTo>
|
||||
</ogc:Not>
|
||||
<ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
|
||||
<ogc:PropertyName>cat</ogc:PropertyName>
|
||||
<ogc:Literal>*dog.food!*good</ogc:Literal>
|
||||
</ogc:PropertyIsLike>
|
||||
<ogc:PropertyIsBetween>
|
||||
<ogc:PropertyName>number</ogc:PropertyName>
|
||||
<ogc:LowerBoundary>
|
||||
<ogc:Literal>1064866676</ogc:Literal>
|
||||
</ogc:LowerBoundary>
|
||||
<ogc:UpperBoundary>
|
||||
<ogc:Literal>1065512599</ogc:Literal>
|
||||
</ogc:UpperBoundary>
|
||||
</ogc:PropertyIsBetween>
|
||||
</ogc:Or>
|
||||
</ogc:Filter>
|
||||
<sld:MaxScaleDenominator>10000</sld:MaxScaleDenominator>
|
||||
<sld:PointSymbolizer>
|
||||
<sld:Graphic>
|
||||
<sld:Mark>
|
||||
<sld:WellKnownName>star</sld:WellKnownName>
|
||||
<sld:Fill>
|
||||
<sld:CssParameter name="fill">lime</sld:CssParameter>
|
||||
<sld:CssParameter name="fill-opacity">1</sld:CssParameter>
|
||||
</sld:Fill>
|
||||
<sld:Stroke>
|
||||
<sld:CssParameter name="stroke">olive</sld:CssParameter>
|
||||
<sld:CssParameter name="stroke-opacity">1</sld:CssParameter>
|
||||
<sld:CssParameter name="stroke-width">2</sld:CssParameter>
|
||||
</sld:Stroke>
|
||||
</sld:Mark>
|
||||
<sld:Size><ogc:PropertyName xmlns:ogc="http://www.opengis.net/ogc"
|
||||
>SIZE</ogc:PropertyName></sld:Size>
|
||||
</sld:Graphic>
|
||||
</sld:PointSymbolizer>
|
||||
</sld:Rule>
|
||||
</sld:FeatureTypeStyle>
|
||||
</sld:UserStyle>
|
||||
</sld:NamedLayer>
|
||||
</sld:StyledLayerDescriptor>
|
||||
@@ -1,70 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd" version="1.0.0">
|
||||
<ows:ServiceIdentification>
|
||||
<ows:Title>WorldTimeZones</ows:Title>
|
||||
<ows:ServiceType>OGC WMTS</ows:ServiceType>
|
||||
<ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
|
||||
</ows:ServiceIdentification>
|
||||
<ows:OperationsMetadata>
|
||||
<ows:Operation name="GetTile">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/WMTS/tile/1.0.0/">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>RESTful</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
<ows:Get xlink:href="http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/WMTS?">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>KVP</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
</ows:OperationsMetadata>
|
||||
<Contents>
|
||||
<Layer>
|
||||
<ows:Title>WorldTimeZones</ows:Title>
|
||||
<ows:Identifier>WorldTimeZones</ows:Identifier>
|
||||
<ows:BoundingBox crs="urn:ogc:def:crs:EPSG::102100">
|
||||
<ows:LowerCorner>-2.0037507067161843E7 -3.024097195838617E7</ows:LowerCorner>
|
||||
<ows:UpperCorner>2.0037507067161843E7 3.0240971458386205E7</ows:UpperCorner>
|
||||
</ows:BoundingBox>
|
||||
<ows:WGS84BoundingBox crs="urn:ogc:def:crs:OGC:2:84">
|
||||
<ows:LowerCorner>-179.99999550841463 -88.99999992161119</ows:LowerCorner>
|
||||
<ows:UpperCorner>179.99999550841463 88.99999992161118</ows:UpperCorner>
|
||||
</ows:WGS84BoundingBox>
|
||||
<Style isDefault="true">
|
||||
<ows:Title>Default Style</ows:Title>
|
||||
<ows:Identifier>default</ows:Identifier>
|
||||
</Style>
|
||||
<Format>image/png</Format>
|
||||
<TileMatrixSetLink>
|
||||
<TileMatrixSet>GoogleMapsCompatible</TileMatrixSet>
|
||||
</TileMatrixSetLink>
|
||||
<ResourceURL format="image/png" resourceType="tile" template="http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/WMTS/tile/1.0.0/WorldTimeZones/{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png" />
|
||||
</Layer>
|
||||
<TileMatrixSet>
|
||||
<ows:Title>GoogleMapsCompatible</ows:Title>
|
||||
<ows:Abstract>the wellknown 'GoogleMapsCompatible' tile matrix set defined by OGC WMTS specification</ows:Abstract>
|
||||
<ows:Identifier>GoogleMapsCompatible</ows:Identifier>
|
||||
<ows:SupportedCRS>urn:ogc:def:crs:EPSG:6.18:3:3857</ows:SupportedCRS>
|
||||
<WellKnownScaleSet>urn:ogc:def:wkss:OGC:1.0:GoogleMapsCompatible</WellKnownScaleSet>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>5</ows:Identifier>
|
||||
<ScaleDenominator>17471320.75089743</ScaleDenominator>
|
||||
<TopLeftCorner>-20037508.34278925 20037508.34278925</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>32</MatrixWidth>
|
||||
<MatrixHeight>32</MatrixHeight>
|
||||
</TileMatrix>
|
||||
</TileMatrixSet>
|
||||
</Contents>
|
||||
<ServiceMetadataURL xlink:href="http://sampleserver6.arcgisonline.com/arcgis/rest/services/WorldTimeZones/MapServer/WMTS/1.0.0/WMTSCapabilities.xml" />
|
||||
</Capabilities>
|
||||
@@ -1,92 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd" version="1.0.0">
|
||||
<ows:OperationsMetadata>
|
||||
<ows:Operation name="GetCapabilities">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://wmts.geo.admin.ch/1.0.0/WMTSCapabilities.xml">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>REST</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
<ows:Operation name="GetTile">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://wmts.geo.admin.ch/rest">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>REST</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
<ows:Get xlink:href="http://wmts1.geo.admin.ch/rest">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>REST</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
<ows:Get xlink:href="http://wmts.geo.admin.ch/kvp">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>KVP</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
<ows:Get xlink:href="http://wmts1.geo.admin.ch/kvp">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>KVP</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
</ows:OperationsMetadata>
|
||||
<Contents>
|
||||
<Layer>
|
||||
<ows:Title>Agglomérations et villes isolées</ows:Title>
|
||||
<ows:Abstract>Les agglomérations et villes isolées (communes non rattachées à une agglomération et comptant au moins 10`000 habitants) font partie des régions d’analyse de la statistique suisse. Ce niveau géographique est défini depuis plus de 100 ans, afin de mesurer l’urbanisation, phénomène fondamental structurant l’organisation du territoire. Sa fonction principale est de permettre une comparaison spatiale entre des espaces urbains inégalement délimités sur le plan institutionnel. Une version ancienne est appliquée pour la première fois en 1930, puis révisée en 1984 et 1990, toujours sur la base des recensements de la population. La version actuelle classe les 2896 communes de Suisse (état 2000) selon leur appartenance ou pas à une agglomération ou ville isolée en fonction de critères statistiques (Etat et évolution de la population, lien de continuité de la zone bâtie, rapport entre population active occupée et population résidante, structure économique et flux de pendulaires). Les agglomérations et les villes isolées forment l`espace urbain, les territoires restant l`espace rural. La définition des agglomérations de l’OFS n’a pas valeur d’obligation légale.</ows:Abstract>
|
||||
<ows:WGS84BoundingBox>
|
||||
<ows:LowerCorner>5.140242 45.398181</ows:LowerCorner>
|
||||
<ows:UpperCorner>11.47757 48.230651</ows:UpperCorner>
|
||||
</ows:WGS84BoundingBox>
|
||||
<ows:Identifier>ch.are.agglomerationen_isolierte_staedte-2000</ows:Identifier>
|
||||
<ows:Metadata xlink:href="http://www.swisstopo.admin.ch/SITiled/world/AdminBoundaries/metadata.htm"/>
|
||||
<Style>
|
||||
<ows:Title>Agglomérations et villes isolées</ows:Title>
|
||||
<ows:Identifier>ch.are.agglomerationen_isolierte_staedte-2000</ows:Identifier>
|
||||
<LegendURL format="image/png" xlink:href="http://api.geo.admin.ch/legend/ch.are.agglomerationen_isolierte_staedte-2000_fr.png" />
|
||||
</Style>
|
||||
<Format>image/png</Format>
|
||||
<Dimension>
|
||||
<ows:Identifier>Time</ows:Identifier>
|
||||
<Default>20090101</Default>
|
||||
<Value>20090101</Value>
|
||||
</Dimension>
|
||||
<TileMatrixSetLink>
|
||||
<TileMatrixSet>21781</TileMatrixSet>
|
||||
</TileMatrixSetLink>
|
||||
</Layer>
|
||||
<TileMatrixSet>
|
||||
<ows:Identifier>21781</ows:Identifier>
|
||||
<ows:SupportedCRS>urn:ogc:def:crs:EPSG:1.0:21781</ows:SupportedCRS>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>0</ows:Identifier>
|
||||
<ScaleDenominator>14285750.5715</ScaleDenominator>
|
||||
<TopLeftCorner>420000.0 350000.0</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>1</MatrixWidth>
|
||||
<MatrixHeight>1</MatrixHeight>
|
||||
</TileMatrix>
|
||||
</TileMatrixSet>
|
||||
</Contents>
|
||||
<ServiceMetadataURL xlink:href="http://www.opengis.uab.es/SITiled/world/1.0.0/WMTSCapabilities.xml"/>
|
||||
</Capabilities>
|
||||
@@ -1,78 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd" version="1.0.0">
|
||||
<ows:OperationsMetadata>
|
||||
<ows:Operation name="GetCapabilities">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://wmts.geo.admin.ch/1.0.0/WMTSCapabilities.xml">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>REST</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
<ows:Operation name="GetTile">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://wmts.geo.admin.ch/kvp">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>KVP</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
<ows:Get xlink:href="http://wmts.geo.admin.ch/rest">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>REST</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
</ows:OperationsMetadata>
|
||||
<Contents>
|
||||
<Layer>
|
||||
<ows:Title>Agglomérations et villes isolées</ows:Title>
|
||||
<ows:Abstract>Les agglomérations et villes isolées (communes non rattachées à une agglomération et comptant au moins 10`000 habitants) font partie des régions d’analyse de la statistique suisse. Ce niveau géographique est défini depuis plus de 100 ans, afin de mesurer l’urbanisation, phénomène fondamental structurant l’organisation du territoire. Sa fonction principale est de permettre une comparaison spatiale entre des espaces urbains inégalement délimités sur le plan institutionnel. Une version ancienne est appliquée pour la première fois en 1930, puis révisée en 1984 et 1990, toujours sur la base des recensements de la population. La version actuelle classe les 2896 communes de Suisse (état 2000) selon leur appartenance ou pas à une agglomération ou ville isolée en fonction de critères statistiques (Etat et évolution de la population, lien de continuité de la zone bâtie, rapport entre population active occupée et population résidante, structure économique et flux de pendulaires). Les agglomérations et les villes isolées forment l`espace urbain, les territoires restant l`espace rural. La définition des agglomérations de l’OFS n’a pas valeur d’obligation légale.</ows:Abstract>
|
||||
<ows:WGS84BoundingBox>
|
||||
<ows:LowerCorner>5.140242 45.398181</ows:LowerCorner>
|
||||
<ows:UpperCorner>11.47757 48.230651</ows:UpperCorner>
|
||||
</ows:WGS84BoundingBox>
|
||||
<ows:Identifier>ch.are.agglomerationen_isolierte_staedte-2000</ows:Identifier>
|
||||
<ows:Metadata xlink:href="http://www.swisstopo.admin.ch/SITiled/world/AdminBoundaries/metadata.htm"/>
|
||||
<Style>
|
||||
<ows:Title>Agglomérations et villes isolées</ows:Title>
|
||||
<ows:Identifier>ch.are.agglomerationen_isolierte_staedte-2000</ows:Identifier>
|
||||
<LegendURL format="image/png" xlink:href="http://api.geo.admin.ch/legend/ch.are.agglomerationen_isolierte_staedte-2000_fr.png" />
|
||||
</Style>
|
||||
<Format>image/png</Format>
|
||||
<Dimension>
|
||||
<ows:Identifier>Time</ows:Identifier>
|
||||
<Default>20090101</Default>
|
||||
<Value>20090101</Value>
|
||||
</Dimension>
|
||||
<TileMatrixSetLink>
|
||||
<TileMatrixSet>21781</TileMatrixSet>
|
||||
</TileMatrixSetLink>
|
||||
</Layer>
|
||||
<TileMatrixSet>
|
||||
<ows:Identifier>21781</ows:Identifier>
|
||||
<ows:SupportedCRS>urn:ogc:def:crs:EPSG:1.0:21781</ows:SupportedCRS>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>0</ows:Identifier>
|
||||
<ScaleDenominator>14285750.5715</ScaleDenominator>
|
||||
<TopLeftCorner>420000.0 350000.0</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>1</MatrixWidth>
|
||||
<MatrixHeight>1</MatrixHeight>
|
||||
</TileMatrix>
|
||||
</TileMatrixSet>
|
||||
</Contents>
|
||||
<ServiceMetadataURL xlink:href="http://www.opengis.uab.es/SITiled/world/1.0.0/WMTSCapabilities.xml"/>
|
||||
</Capabilities>
|
||||
@@ -1,160 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd" version="1.0.0">
|
||||
<ows:ServiceIdentification>
|
||||
<ows:Title>Web Map Tile Service</ows:Title>
|
||||
<ows:Abstract>Service that contrains the map access interface to some TileMatrixSets</ows:Abstract>
|
||||
<ows:Keywords>
|
||||
<ows:Keyword>tile</ows:Keyword>
|
||||
<ows:Keyword>tile matrix set</ows:Keyword>
|
||||
<ows:Keyword>map</ows:Keyword>
|
||||
</ows:Keywords>
|
||||
<ows:ServiceType>OGC WMTS</ows:ServiceType>
|
||||
<ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
|
||||
<ows:Fees>none</ows:Fees>
|
||||
<ows:AccessConstraints>none</ows:AccessConstraints>
|
||||
</ows:ServiceIdentification>
|
||||
<ows:ServiceProvider>
|
||||
<ows:ProviderName>MiraMon</ows:ProviderName>
|
||||
<ows:ProviderSite xlink:href="http://www.creaf.uab.es/miramon"/>
|
||||
<ows:ServiceContact>
|
||||
<ows:IndividualName>Joan Maso Pau</ows:IndividualName>
|
||||
<ows:PositionName>Senior Software Engineer</ows:PositionName>
|
||||
<ows:ContactInfo>
|
||||
<ows:Phone>
|
||||
<ows:Voice>+34 93 581 1312</ows:Voice>
|
||||
<ows:Facsimile>+34 93 581 4151</ows:Facsimile>
|
||||
</ows:Phone>
|
||||
<ows:Address>
|
||||
<ows:DeliveryPoint>Fac Ciencies UAB</ows:DeliveryPoint>
|
||||
<ows:City>Bellaterra</ows:City>
|
||||
<ows:AdministrativeArea>Barcelona</ows:AdministrativeArea>
|
||||
<ows:PostalCode>08193</ows:PostalCode>
|
||||
<ows:Country>Spain</ows:Country>
|
||||
<ows:ElectronicMailAddress>joan.maso@uab.es</ows:ElectronicMailAddress>
|
||||
</ows:Address>
|
||||
</ows:ContactInfo>
|
||||
</ows:ServiceContact>
|
||||
</ows:ServiceProvider>
|
||||
<ows:OperationsMetadata>
|
||||
<ows:Operation name="GetCapabilities">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>KVP</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
<ows:Operation name="GetTile">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?"/>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
<ows:Operation name="GetFeatureInfo">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?"/>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
</ows:OperationsMetadata>
|
||||
<Contents>
|
||||
<Layer>
|
||||
<ows:Title>Coastlines</ows:Title>
|
||||
<ows:Abstract>Coastline/shorelines (BA010)</ows:Abstract>
|
||||
<ows:WGS84BoundingBox>
|
||||
<ows:LowerCorner>-180 -90</ows:LowerCorner>
|
||||
<ows:UpperCorner>180 90</ows:UpperCorner>
|
||||
</ows:WGS84BoundingBox>
|
||||
<ows:Identifier>coastlines</ows:Identifier>
|
||||
<ResourceURL format="image/png" resourceType="tile"
|
||||
template="http://a.example.com/wmts/coastlines/{TileMatrix}/{TileRow}/{TileCol}.png" />
|
||||
<ResourceURL format="image/png" resourceType="tile"
|
||||
template="http://b.example.com/wmts/coastlines/{TileMatrix}/{TileRow}/{TileCol}.png" />
|
||||
<ResourceURL format="application/gml+xml; version=3.1" resourceType="FeatureInfo"
|
||||
template="http://www.example.com/wmts/coastlines/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}/{J}/{I}.xml" />
|
||||
<Style isDefault="true">
|
||||
<ows:Title>Dark Blue</ows:Title>
|
||||
<ows:Identifier>DarkBlue</ows:Identifier>
|
||||
<LegendURL format="image/png" xlink:href="http://www.miramon.uab.es/wmts/Coastlines/coastlines_darkBlue.png"/>
|
||||
</Style>
|
||||
<Style>
|
||||
<ows:Title>Thick And Red</ows:Title>
|
||||
<ows:Abstract>Specify this style if you want your maps to have thick red coastlines.
|
||||
</ows:Abstract>
|
||||
<ows:Identifier>thickAndRed</ows:Identifier>
|
||||
</Style>
|
||||
<Format>image/png</Format>
|
||||
<Format>image/gif</Format>
|
||||
<Dimension>
|
||||
<ows:Title>Time</ows:Title>
|
||||
<ows:Abstract>Monthly datasets</ows:Abstract>
|
||||
<ows:Identifier>TIME</ows:Identifier>
|
||||
<Value>2007-05</Value>
|
||||
<Value>2007-06</Value>
|
||||
<Value>2007-07</Value>
|
||||
<Default>default</Default>
|
||||
</Dimension>
|
||||
<TileMatrixSetLink>
|
||||
<TileMatrixSet>BigWorld</TileMatrixSet>
|
||||
</TileMatrixSetLink>
|
||||
</Layer>
|
||||
<TileMatrixSet>
|
||||
<ows:Identifier>BigWorld</ows:Identifier>
|
||||
<ows:SupportedCRS>urn:ogc:def:crs:OGC:1.3:CRS84</ows:SupportedCRS>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>1e6</ows:Identifier>
|
||||
<ScaleDenominator>1e6</ScaleDenominator>
|
||||
<TopLeftCorner>-180 84</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>60000</MatrixWidth>
|
||||
<MatrixHeight>50000</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>2.5e6</ows:Identifier>
|
||||
<ScaleDenominator>2.5e6</ScaleDenominator>
|
||||
<TopLeftCorner>-180 84</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>9000</MatrixWidth>
|
||||
<MatrixHeight>7000</MatrixHeight>
|
||||
</TileMatrix>
|
||||
</TileMatrixSet>
|
||||
</Contents>
|
||||
<Themes>
|
||||
<Theme>
|
||||
<ows:Title>Foundation</ows:Title>
|
||||
<ows:Abstract>"Digital Chart Of The World" data</ows:Abstract>
|
||||
<ows:Identifier>Foundation</ows:Identifier>
|
||||
<Theme>
|
||||
<ows:Title>Boundaries</ows:Title>
|
||||
<ows:Identifier>Boundaries</ows:Identifier>
|
||||
<LayerRef>coastlines</LayerRef>
|
||||
<LayerRef>politicalBoundaries</LayerRef>
|
||||
<LayerRef>depthContours</LayerRef>
|
||||
</Theme>
|
||||
<Theme>
|
||||
<ows:Title>Transportation</ows:Title>
|
||||
<ows:Identifier>Transportation</ows:Identifier>
|
||||
<LayerRef>roads</LayerRef>
|
||||
<LayerRef>railroads</LayerRef>
|
||||
<LayerRef>airports</LayerRef>
|
||||
</Theme>
|
||||
</Theme>
|
||||
<Theme>
|
||||
<ows:Title>World Geology</ows:Title>
|
||||
<ows:Identifier>World Geology</ows:Identifier>
|
||||
<LayerRef>worldAgeRockType</LayerRef>
|
||||
<LayerRef>worldFaultLines</LayerRef>
|
||||
<LayerRef>felsicMagmatic</LayerRef>
|
||||
<LayerRef>maficMagmatic</LayerRef>
|
||||
</Theme>
|
||||
</Themes>
|
||||
</Capabilities>
|
||||
@@ -1,72 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd" version="1.0.0">
|
||||
<ows:OperationsMetadata>
|
||||
<ows:Operation name="GetCapabilities">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://wmts.geo.admin.ch/1.0.0/WMTSCapabilities.xml">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>REST</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
<ows:Operation name="GetTile">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://wmts.geo.admin.ch/">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>REST</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
</ows:OperationsMetadata>
|
||||
<Contents>
|
||||
<Layer>
|
||||
<ows:Title>Agglomérations et villes isolées</ows:Title>
|
||||
<ows:Abstract>Les agglomérations et villes isolées (communes non rattachées à une agglomération et comptant au moins 10`000 habitants) font partie des régions d’analyse de la statistique suisse. Ce niveau géographique est défini depuis plus de 100 ans, afin de mesurer l’urbanisation, phénomène fondamental structurant l’organisation du territoire. Sa fonction principale est de permettre une comparaison spatiale entre des espaces urbains inégalement délimités sur le plan institutionnel. Une version ancienne est appliquée pour la première fois en 1930, puis révisée en 1984 et 1990, toujours sur la base des recensements de la population. La version actuelle classe les 2896 communes de Suisse (état 2000) selon leur appartenance ou pas à une agglomération ou ville isolée en fonction de critères statistiques (Etat et évolution de la population, lien de continuité de la zone bâtie, rapport entre population active occupée et population résidante, structure économique et flux de pendulaires). Les agglomérations et les villes isolées forment l`espace urbain, les territoires restant l`espace rural. La définition des agglomérations de l’OFS n’a pas valeur d’obligation légale.</ows:Abstract>
|
||||
<ows:WGS84BoundingBox>
|
||||
<ows:LowerCorner>5.140242 45.398181</ows:LowerCorner>
|
||||
<ows:UpperCorner>11.47757 48.230651</ows:UpperCorner>
|
||||
</ows:WGS84BoundingBox>
|
||||
<ows:Identifier>ch.are.agglomerationen_isolierte_staedte-2000</ows:Identifier>
|
||||
<ows:Metadata xlink:href="http://www.swisstopo.admin.ch/SITiled/world/AdminBoundaries/metadata.htm"/>
|
||||
<Style>
|
||||
<ows:Title>Agglomérations et villes isolées</ows:Title>
|
||||
<ows:Identifier>ch.are.agglomerationen_isolierte_staedte-2000</ows:Identifier>
|
||||
<LegendURL format="image/png" xlink:href="http://api.geo.admin.ch/legend/ch.are.agglomerationen_isolierte_staedte-2000_fr.png" />
|
||||
</Style>
|
||||
<Format>image/png</Format>
|
||||
<Dimension>
|
||||
<ows:Identifier>Time</ows:Identifier>
|
||||
<Default>20090101</Default>
|
||||
<Value>20090101</Value>
|
||||
</Dimension>
|
||||
<TileMatrixSetLink>
|
||||
<TileMatrixSet>21781</TileMatrixSet>
|
||||
</TileMatrixSetLink>
|
||||
<ResourceURL format="image/png" resourceType="tile" template="http://wmts.geo.admin.ch/1.0.0/ch.are.agglomerationen_isolierte_staedte-2000/default/{Time}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png"/>
|
||||
</Layer>
|
||||
<TileMatrixSet>
|
||||
<ows:Identifier>21781</ows:Identifier>
|
||||
<ows:SupportedCRS>urn:ogc:def:crs:EPSG:21781</ows:SupportedCRS>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>0</ows:Identifier>
|
||||
<ScaleDenominator>14285750.5715</ScaleDenominator>
|
||||
<TopLeftCorner>420000.0 350000.0</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>1</MatrixWidth>
|
||||
<MatrixHeight>1</MatrixHeight>
|
||||
</TileMatrix>
|
||||
</TileMatrixSet>
|
||||
</Contents>
|
||||
<ServiceMetadataURL xlink:href="http://www.opengis.uab.es/SITiled/world/1.0.0/WMTSCapabilities.xml"/>
|
||||
</Capabilities>
|
||||
@@ -1,72 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd" version="1.0.0">
|
||||
<ows:OperationsMetadata>
|
||||
<ows:Operation name="GetCapabilities">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://wmts.geo.admin.ch/1.0.0/WMTSCapabilities.xml">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>REST</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
<ows:Operation name="GetTile">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://wmts.geo.admin.ch/">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>REST</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
</ows:OperationsMetadata>
|
||||
<Contents>
|
||||
<Layer>
|
||||
<ows:Title>Agglomérations et villes isolées</ows:Title>
|
||||
<ows:Abstract>Les agglomérations et villes isolées (communes non rattachées à une agglomération et comptant au moins 10`000 habitants) font partie des régions d’analyse de la statistique suisse. Ce niveau géographique est défini depuis plus de 100 ans, afin de mesurer l’urbanisation, phénomène fondamental structurant l’organisation du territoire. Sa fonction principale est de permettre une comparaison spatiale entre des espaces urbains inégalement délimités sur le plan institutionnel. Une version ancienne est appliquée pour la première fois en 1930, puis révisée en 1984 et 1990, toujours sur la base des recensements de la population. La version actuelle classe les 2896 communes de Suisse (état 2000) selon leur appartenance ou pas à une agglomération ou ville isolée en fonction de critères statistiques (Etat et évolution de la population, lien de continuité de la zone bâtie, rapport entre population active occupée et population résidante, structure économique et flux de pendulaires). Les agglomérations et les villes isolées forment l`espace urbain, les territoires restant l`espace rural. La définition des agglomérations de l’OFS n’a pas valeur d’obligation légale.</ows:Abstract>
|
||||
<ows:WGS84BoundingBox>
|
||||
<ows:LowerCorner>5.140242 45.398181</ows:LowerCorner>
|
||||
<ows:UpperCorner>11.47757 48.230651</ows:UpperCorner>
|
||||
</ows:WGS84BoundingBox>
|
||||
<ows:Identifier>ch.are.agglomerationen_isolierte_staedte-2000</ows:Identifier>
|
||||
<ows:Metadata xlink:href="http://www.swisstopo.admin.ch/SITiled/world/AdminBoundaries/metadata.htm"/>
|
||||
<Style>
|
||||
<ows:Title>Agglomérations et villes isolées</ows:Title>
|
||||
<ows:Identifier>ch.are.agglomerationen_isolierte_staedte-2000</ows:Identifier>
|
||||
<LegendURL format="image/png" xlink:href="http://api.geo.admin.ch/legend/ch.are.agglomerationen_isolierte_staedte-2000_fr.png" />
|
||||
</Style>
|
||||
<Format>image/png</Format>
|
||||
<Dimension>
|
||||
<ows:Identifier>Time</ows:Identifier>
|
||||
<Default>20090101</Default>
|
||||
<Value>20090101</Value>
|
||||
</Dimension>
|
||||
<TileMatrixSetLink>
|
||||
<TileMatrixSet>21781</TileMatrixSet>
|
||||
</TileMatrixSetLink>
|
||||
<ResourceURL format="image/png" resourceType="tile" template="http://wmts.geo.admin.ch/1.0.0/ch.are.agglomerationen_isolierte_staedte-2000/default/{Time}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png"/>
|
||||
</Layer>
|
||||
<TileMatrixSet>
|
||||
<ows:Identifier>21781</ows:Identifier>
|
||||
<ows:SupportedCRS>urn:ogc:def:crs:EPSG:1.0:21781</ows:SupportedCRS>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>0</ows:Identifier>
|
||||
<ScaleDenominator>14285750.5715</ScaleDenominator>
|
||||
<TopLeftCorner>420000.0 350000.0</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>1</MatrixWidth>
|
||||
<MatrixHeight>1</MatrixHeight>
|
||||
</TileMatrix>
|
||||
</TileMatrixSet>
|
||||
</Contents>
|
||||
<ServiceMetadataURL xlink:href="http://www.opengis.uab.es/SITiled/world/1.0.0/WMTSCapabilities.xml"/>
|
||||
</Capabilities>
|
||||
@@ -1,126 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd" version="1.0.0">
|
||||
<ows:ServiceIdentification>
|
||||
<ows:Title>Federal Geodata Infrastructure of Switzerland</ows:Title>
|
||||
<ows:Abstract>Some Geodata are subject to license and fees</ows:Abstract>
|
||||
<ows:Keywords>
|
||||
<ows:Keyword>FGDI</ows:Keyword>
|
||||
<ows:Keyword>Pixelkarte</ows:Keyword>
|
||||
<ows:Keyword>Switzerland</ows:Keyword>
|
||||
</ows:Keywords>
|
||||
<ows:ServiceType>OGC WMTS</ows:ServiceType>
|
||||
<ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
|
||||
<ows:Fees>yes</ows:Fees>
|
||||
<ows:AccessConstraints>license</ows:AccessConstraints>
|
||||
</ows:ServiceIdentification>
|
||||
<ows:ServiceProvider>
|
||||
<ows:ProviderName>swisstopo</ows:ProviderName>
|
||||
<ows:ProviderSite xlink:href="http://www.swisstopo.admin.ch"/>
|
||||
<ows:ServiceContact>
|
||||
<ows:IndividualName>David Oesch</ows:IndividualName>
|
||||
<ows:PositionName></ows:PositionName>
|
||||
<ows:ContactInfo>
|
||||
<ows:Phone>
|
||||
<ows:Voice>+41 (0)31 / 963 21 11</ows:Voice>
|
||||
<ows:Facsimile>+41 (0)31 / 963 24 59</ows:Facsimile>
|
||||
</ows:Phone>
|
||||
<ows:Address>
|
||||
<ows:DeliveryPoint>swisstopo</ows:DeliveryPoint>
|
||||
<ows:City>Bern</ows:City>
|
||||
<ows:AdministrativeArea>BE</ows:AdministrativeArea>
|
||||
<ows:PostalCode>3084</ows:PostalCode>
|
||||
<ows:Country>Switzerland</ows:Country>
|
||||
<ows:ElectronicMailAddress/>
|
||||
</ows:Address>
|
||||
</ows:ContactInfo>
|
||||
</ows:ServiceContact>
|
||||
</ows:ServiceProvider>
|
||||
<ows:OperationsMetadata>
|
||||
<ows:Operation name="GetCapabilities">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://wmts.geo.admin.ch/1.0.0/WMTSCapabilities.xml">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>REST</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
<ows:Operation name="GetTile">
|
||||
<ows:DCP>
|
||||
<ows:HTTP>
|
||||
<ows:Get xlink:href="http://wmts.geo.admin.ch/">
|
||||
<ows:Constraint name="GetEncoding">
|
||||
<ows:AllowedValues>
|
||||
<ows:Value>REST</ows:Value>
|
||||
</ows:AllowedValues>
|
||||
</ows:Constraint>
|
||||
</ows:Get>
|
||||
</ows:HTTP>
|
||||
</ows:DCP>
|
||||
</ows:Operation>
|
||||
</ows:OperationsMetadata>
|
||||
<Contents>
|
||||
<Layer>
|
||||
<ows:Title>Agglomérations et villes isolées</ows:Title>
|
||||
<ows:Abstract>Les agglomérations et villes isolées (communes non rattachées à une agglomération et comptant au moins 10`000 habitants) font partie des régions d’analyse de la statistique suisse. Ce niveau géographique est défini depuis plus de 100 ans, afin de mesurer l’urbanisation, phénomène fondamental structurant l’organisation du territoire. Sa fonction principale est de permettre une comparaison spatiale entre des espaces urbains inégalement délimités sur le plan institutionnel. Une version ancienne est appliquée pour la première fois en 1930, puis révisée en 1984 et 1990, toujours sur la base des recensements de la population. La version actuelle classe les 2896 communes de Suisse (état 2000) selon leur appartenance ou pas à une agglomération ou ville isolée en fonction de critères statistiques (Etat et évolution de la population, lien de continuité de la zone bâtie, rapport entre population active occupée et population résidante, structure économique et flux de pendulaires). Les agglomérations et les villes isolées forment l`espace urbain, les territoires restant l`espace rural. La définition des agglomérations de l’OFS n’a pas valeur d’obligation légale.</ows:Abstract>
|
||||
<ows:WGS84BoundingBox>
|
||||
<ows:LowerCorner>5.140242 45.398181</ows:LowerCorner>
|
||||
<ows:UpperCorner>11.47757 48.230651</ows:UpperCorner>
|
||||
</ows:WGS84BoundingBox>
|
||||
<ows:Identifier>ch.are.agglomerationen_isolierte_staedte-2000</ows:Identifier>
|
||||
<ows:Metadata xlink:href="http://www.swisstopo.admin.ch/SITiled/world/AdminBoundaries/metadata.htm"/>
|
||||
<Style>
|
||||
<ows:Title>Agglomérations et villes isolées</ows:Title>
|
||||
<ows:Identifier>ch.are.agglomerationen_isolierte_staedte-2000</ows:Identifier>
|
||||
<LegendURL format="image/png" xlink:href="http://api.geo.admin.ch/legend/ch.are.agglomerationen_isolierte_staedte-2000_fr.png" />
|
||||
</Style>
|
||||
<Format>image/png</Format>
|
||||
<Dimension>
|
||||
<ows:Identifier>Time</ows:Identifier>
|
||||
<Default>20090101</Default>
|
||||
<Value>20090101</Value>
|
||||
</Dimension>
|
||||
<TileMatrixSetLink>
|
||||
<TileMatrixSet>21781</TileMatrixSet>
|
||||
</TileMatrixSetLink>
|
||||
<ResourceURL format="image/png" resourceType="tile" template="http://wmts.geo.admin.ch/1.0.0/ch.are.agglomerationen_isolierte_staedte-2000/default/{Time}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png"/>
|
||||
<ResourceURL format="image/png" resourceType="tile" template="http://wmts1.geo.admin.ch/1.0.0/ch.are.agglomerationen_isolierte_staedte-2000/default/{Time}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png"/>
|
||||
</Layer>
|
||||
<TileMatrixSet>
|
||||
<ows:Identifier>21781</ows:Identifier>
|
||||
<ows:SupportedCRS>urn:ogc:def:crs:EPSG::21781</ows:SupportedCRS>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>0</ows:Identifier>
|
||||
<ScaleDenominator>14285750.5715</ScaleDenominator>
|
||||
<TopLeftCorner>420000.0 350000.0</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>1</MatrixWidth>
|
||||
<MatrixHeight>1</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>8</ows:Identifier>
|
||||
<ScaleDenominator>7142875.28575</ScaleDenominator>
|
||||
<TopLeftCorner>420000.0 350000.0</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>1</MatrixWidth>
|
||||
<MatrixHeight>1</MatrixHeight>
|
||||
</TileMatrix>
|
||||
<TileMatrix>
|
||||
<ows:Identifier>12</ows:Identifier>
|
||||
<ScaleDenominator>3571437.64288</ScaleDenominator>
|
||||
<TopLeftCorner>420000.0 350000.0</TopLeftCorner>
|
||||
<TileWidth>256</TileWidth>
|
||||
<TileHeight>256</TileHeight>
|
||||
<MatrixWidth>2</MatrixWidth>
|
||||
<MatrixHeight>2</MatrixHeight>
|
||||
</TileMatrix>
|
||||
</TileMatrixSet>
|
||||
</Contents>
|
||||
<ServiceMetadataURL xlink:href="http://www.opengis.uab.es/SITiled/world/1.0.0/WMTSCapabilities.xml"/>
|
||||
</Capabilities>
|
||||
@@ -1,246 +0,0 @@
|
||||
goog.provide('ol.test.style.Fill');
|
||||
|
||||
describe('ol.style.Fill', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts literal values', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#BADA55'
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Fill);
|
||||
});
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
opacity: ol.expr.parse('value / 100'),
|
||||
color: ol.expr.parse('fillAttr')
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Fill);
|
||||
});
|
||||
|
||||
it('accepts zIndex', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
opacity: ol.expr.parse('value / 100'),
|
||||
color: ol.expr.parse('fillAttr'),
|
||||
zIndex: 3
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Fill);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#createLiteral()', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
opacity: ol.expr.parse('value / 100'),
|
||||
color: ol.expr.parse('fillAttr')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
value: 42,
|
||||
fillAttr: '#ff0000',
|
||||
geometry: new ol.geom.Polygon(
|
||||
[[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillOpacity).to.be(42 / 100);
|
||||
expect(literal.fillColor).to.be('#ff0000');
|
||||
expect(literal.zIndex).to.be(0);
|
||||
});
|
||||
|
||||
it('applies default opacity', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POLYGON);
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillColor).to.be('#ff0000');
|
||||
expect(literal.fillOpacity).to.be(0.4);
|
||||
});
|
||||
|
||||
it('applies default color', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
opacity: 0.8
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POLYGON);
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillColor).to.be('#ffffff');
|
||||
expect(literal.fillOpacity).to.be(0.8);
|
||||
});
|
||||
|
||||
it('casts opacity to number', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
opacity: ol.expr.parse('opacity'),
|
||||
color: '#ff00ff'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
opacity: '0.55',
|
||||
geometry: new ol.geom.Polygon(
|
||||
[[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillOpacity).to.be(0.55);
|
||||
});
|
||||
|
||||
it('handles zIndex', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
opacity: 0.8,
|
||||
zIndex: 2
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POLYGON);
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.fillColor).to.be('#ffffff');
|
||||
expect(literal.fillOpacity).to.be(0.8);
|
||||
expect(literal.zIndex).to.be(2);
|
||||
});
|
||||
|
||||
it('applies default zIndex', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
opacity: 0.8
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POLYGON);
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.zIndex).to.be(0);
|
||||
});
|
||||
|
||||
it('casts zIndex to number', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
zIndex: ol.expr.parse('zIndex'),
|
||||
color: '#ff00ff'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
zIndex: '11',
|
||||
geometry: new ol.geom.Polygon(
|
||||
[[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.PolygonLiteral);
|
||||
expect(literal.zIndex).to.be(11);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getColor()', function() {
|
||||
|
||||
it('returns the fill color', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
var color = symbolizer.getColor();
|
||||
expect(color).to.be.a(ol.expr.Literal);
|
||||
expect(color.getValue()).to.be('#ff0000');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getOpacity()', function() {
|
||||
|
||||
it('returns the fill opacity', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ffffff',
|
||||
opacity: 0.123
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.123);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getZIndex()', function() {
|
||||
|
||||
it('returns the zIndex', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ffffff',
|
||||
zIndex: 11
|
||||
});
|
||||
|
||||
var zIndex = symbolizer.getZIndex();
|
||||
expect(zIndex).to.be.a(ol.expr.Literal);
|
||||
expect(zIndex.getValue()).to.be(11);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setColor()', function() {
|
||||
|
||||
it('sets the fill color', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
symbolizer.setColor(new ol.expr.Literal('#0000ff'));
|
||||
|
||||
var color = symbolizer.getColor();
|
||||
expect(color).to.be.a(ol.expr.Literal);
|
||||
expect(color.getValue()).to.be('#0000ff');
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setColor('#0000ff');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setOpacity()', function() {
|
||||
|
||||
it('sets the fill opacity', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
symbolizer.setOpacity(new ol.expr.Literal(0.321));
|
||||
|
||||
var opacity = symbolizer.getOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.321);
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Fill({
|
||||
color: '#ff0000'
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setOpacity(0.123);
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('goog.asserts.AssertionError');
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.Polygon');
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.PolygonLiteral');
|
||||
@@ -1,87 +0,0 @@
|
||||
goog.provide('ol.test.style.IconLiteral');
|
||||
|
||||
describe('ol.style.IconLiteral', function() {
|
||||
|
||||
describe('#equals()', function() {
|
||||
|
||||
it('identifies equal literals', function() {
|
||||
var literal = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png',
|
||||
zIndex: 0
|
||||
});
|
||||
var equalLiteral = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png',
|
||||
zIndex: 0
|
||||
});
|
||||
var differentHeight = new ol.style.IconLiteral({
|
||||
height: 11,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png',
|
||||
zIndex: 0
|
||||
});
|
||||
var differentWidth = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 2,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png',
|
||||
zIndex: 0
|
||||
});
|
||||
var differentOpacity = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 0.5,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png',
|
||||
zIndex: 0
|
||||
});
|
||||
var differentRotation = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.2,
|
||||
url: 'http://example.com/1.png',
|
||||
zIndex: 0
|
||||
});
|
||||
var differentUrl = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/2.png',
|
||||
zIndex: 0
|
||||
});
|
||||
var differentZIndex = new ol.style.IconLiteral({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png',
|
||||
zIndex: 20
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).to.be(true);
|
||||
expect(literal.equals(differentHeight)).to.be(false);
|
||||
expect(literal.equals(differentWidth)).to.be(false);
|
||||
expect(literal.equals(differentOpacity)).to.be(false);
|
||||
expect(literal.equals(differentRotation)).to.be(false);
|
||||
expect(literal.equals(differentUrl)).to.be(false);
|
||||
expect(literal.equals(differentZIndex)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
goog.require('ol.style.IconLiteral');
|
||||
@@ -1,531 +0,0 @@
|
||||
goog.provide('ol.test.style.Icon');
|
||||
|
||||
describe('ol.style.Icon', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts literal values', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: 10,
|
||||
width: 20,
|
||||
opacity: 1,
|
||||
rotation: 0.1,
|
||||
url: 'http://example.com/1.png',
|
||||
xOffset: 10,
|
||||
yOffset: 15
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Icon);
|
||||
expect(symbolizer).to.be.a(ol.style.Point);
|
||||
});
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: ol.expr.parse('10'),
|
||||
width: ol.expr.parse('20'),
|
||||
opacity: ol.expr.parse('1'),
|
||||
rotation: ol.expr.parse('0.1'),
|
||||
url: ol.expr.parse('"http://example.com/1.png"'),
|
||||
xOffset: ol.expr.parse('xOffset'),
|
||||
yOffset: ol.expr.parse('yOffset')
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Icon);
|
||||
});
|
||||
|
||||
it('accepts zIndex', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: ol.expr.parse('10'),
|
||||
width: ol.expr.parse('20'),
|
||||
opacity: ol.expr.parse('1'),
|
||||
rotation: ol.expr.parse('0.1'),
|
||||
url: ol.expr.parse('"http://example.com/1.png"'),
|
||||
zIndex: 3
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Icon);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#createLiteral()', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: ol.expr.parse('heightAttr'),
|
||||
width: ol.expr.parse('widthAttr'),
|
||||
opacity: ol.expr.parse('opacityAttr'),
|
||||
rotation: ol.expr.parse('rotationAttr'),
|
||||
url: ol.expr.parse('urlAttr'),
|
||||
xOffset: ol.expr.parse('xOffset'),
|
||||
yOffset: ol.expr.parse('yOffset')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
heightAttr: 42,
|
||||
widthAttr: 0.42,
|
||||
opacityAttr: 0.5,
|
||||
rotationAttr: 123,
|
||||
urlAttr: 'http://example.com/1.png',
|
||||
xOffset: 20,
|
||||
yOffset: 30,
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.height).to.be(42);
|
||||
expect(literal.width).to.be(.42);
|
||||
expect(literal.opacity).to.be(0.5);
|
||||
expect(literal.rotation).to.be(123);
|
||||
expect(literal.xOffset).to.be(20);
|
||||
expect(literal.yOffset).to.be(30);
|
||||
expect(literal.url).to.be('http://example.com/1.png');
|
||||
expect(literal.zIndex).to.be(0);
|
||||
});
|
||||
|
||||
it('can be called without a feature', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: ol.expr.parse('10'),
|
||||
width: ol.expr.parse('20'),
|
||||
opacity: ol.expr.parse('1'),
|
||||
rotation: ol.expr.parse('0.1'),
|
||||
xOffset: ol.expr.parse('10'),
|
||||
yOffset: ol.expr.parse('20'),
|
||||
url: ol.expr.parse('"http://example.com/1.png"')
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.height).to.be(10);
|
||||
expect(literal.width).to.be(20);
|
||||
expect(literal.opacity).to.be(1);
|
||||
expect(literal.rotation).to.be(0.1);
|
||||
expect(literal.xOffset).to.be(10);
|
||||
expect(literal.yOffset).to.be(20);
|
||||
expect(literal.url).to.be('http://example.com/1.png');
|
||||
});
|
||||
|
||||
it('applies default opacity if none provided', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: 10,
|
||||
width: 20,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.opacity).to.be(1);
|
||||
});
|
||||
|
||||
it('applies default rotation if none provided', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: 10,
|
||||
width: 20,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.rotation).to.be(0);
|
||||
});
|
||||
|
||||
it('casts opacity to number', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
opacity: ol.expr.parse('opacity'),
|
||||
height: 10,
|
||||
width: 20,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
opacity: '0.53',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.opacity).to.be(0.53);
|
||||
});
|
||||
|
||||
it('casts width to number', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
width: ol.expr.parse('width'),
|
||||
height: 10,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
width: '42',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.width).to.be(42);
|
||||
});
|
||||
|
||||
it('casts height to number', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: ol.expr.parse('height'),
|
||||
width: 10,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
height: '42',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.height).to.be(42);
|
||||
});
|
||||
|
||||
it('applies default xOffset if none', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: 10,
|
||||
width: 20,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.xOffset).to.be(0);
|
||||
});
|
||||
|
||||
it('casts xOffset to number', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
xOffset: ol.expr.parse('xOffset'),
|
||||
width: 10,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
xOffset: '42',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.xOffset).to.be(42);
|
||||
});
|
||||
|
||||
it('applies default yOffset if none', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: 10,
|
||||
width: 20,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.yOffset).to.be(0);
|
||||
});
|
||||
|
||||
it('casts yOffset to number', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
yOffset: ol.expr.parse('yOffset'),
|
||||
width: 10,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
yOffset: '42',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.yOffset).to.be(42);
|
||||
});
|
||||
|
||||
it('handles zIndex', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: ol.expr.parse('10'),
|
||||
width: ol.expr.parse('20'),
|
||||
url: ol.expr.parse('"http://example.com/1.png"'),
|
||||
zIndex: 4
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.xOffset).to.be(0);
|
||||
expect(literal.zIndex).to.be(4);
|
||||
});
|
||||
|
||||
it('applies default zIndex if none', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
height: 10,
|
||||
width: 20,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(ol.geom.GeometryType.POINT);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.zIndex).to.be(0);
|
||||
});
|
||||
|
||||
it('casts zIndex to number', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
zIndex: ol.expr.parse('zIndex'),
|
||||
width: 10,
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
zIndex: '42',
|
||||
geometry: new ol.geom.Point([1, 2])
|
||||
});
|
||||
|
||||
var literal = symbolizer.createLiteral(feature);
|
||||
expect(literal).to.be.a(ol.style.IconLiteral);
|
||||
expect(literal.zIndex).to.be(42);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getHeight()', function() {
|
||||
|
||||
it('returns the icon height', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
height: 20
|
||||
});
|
||||
|
||||
var height = symbolizer.getHeight();
|
||||
expect(height).to.be.a(ol.expr.Literal);
|
||||
expect(height.getValue()).to.be(20);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getOpacity()', function() {
|
||||
|
||||
it('returns the icon opacity', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
opacity: 0.123
|
||||
});
|
||||
|
||||
var opacity = symbolizer.getOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.123);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getRotation()', function() {
|
||||
|
||||
it('returns the icon rotation', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
rotation: 0.123
|
||||
});
|
||||
|
||||
var rotation = symbolizer.getRotation();
|
||||
expect(rotation).to.be.a(ol.expr.Literal);
|
||||
expect(rotation.getValue()).to.be(0.123);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getUrl()', function() {
|
||||
|
||||
it('returns the url', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
var url = symbolizer.getUrl();
|
||||
expect(url).to.be.a(ol.expr.Literal);
|
||||
expect(url.getValue()).to.be('http://example.com/1.png');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('#getWidth()', function() {
|
||||
|
||||
it('returns the icon width', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10
|
||||
});
|
||||
|
||||
var width = symbolizer.getWidth();
|
||||
expect(width).to.be.a(ol.expr.Literal);
|
||||
expect(width.getValue()).to.be(10);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('#setHeight()', function() {
|
||||
|
||||
it('sets the icon height', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
height: 20
|
||||
});
|
||||
symbolizer.setHeight(new ol.expr.Literal(30));
|
||||
|
||||
var height = symbolizer.getHeight();
|
||||
expect(height).to.be.a(ol.expr.Literal);
|
||||
expect(height.getValue()).to.be(30);
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
height: 20
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setHeight(30);
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setOpacity()', function() {
|
||||
|
||||
it('sets the icon opacity', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
height: 20,
|
||||
opacity: 0.123
|
||||
});
|
||||
symbolizer.setOpacity(new ol.expr.Literal(0.321));
|
||||
|
||||
var opacity = symbolizer.getOpacity();
|
||||
expect(opacity).to.be.a(ol.expr.Literal);
|
||||
expect(opacity.getValue()).to.be(0.321);
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
height: 20,
|
||||
opacity: 0.123
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setOpacity(0.5);
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setRotation()', function() {
|
||||
|
||||
it('sets the icon rotation', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
height: 20,
|
||||
rotation: 0.123
|
||||
});
|
||||
symbolizer.setRotation(new ol.expr.Literal(0.321));
|
||||
|
||||
var rotation = symbolizer.getRotation();
|
||||
expect(rotation).to.be.a(ol.expr.Literal);
|
||||
expect(rotation.getValue()).to.be(0.321);
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10,
|
||||
height: 20,
|
||||
rotation: 0.123
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setRotation(0.5);
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setUrl()', function() {
|
||||
|
||||
it('sets the url', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
symbolizer.setUrl(new ol.expr.Literal('http://example.com/2.png'));
|
||||
|
||||
var url = symbolizer.getUrl();
|
||||
expect(url).to.be.a(ol.expr.Literal);
|
||||
expect(url.getValue()).to.be('http://example.com/2.png');
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png'
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setUrl('http://example.com/2.png');
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setWidth()', function() {
|
||||
|
||||
it('sets the icon width', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10
|
||||
});
|
||||
|
||||
symbolizer.setWidth(new ol.expr.Literal(20));
|
||||
|
||||
var width = symbolizer.getWidth();
|
||||
expect(width).to.be.a(ol.expr.Literal);
|
||||
expect(width.getValue()).to.be(20);
|
||||
});
|
||||
|
||||
it('throws when not provided an expression', function() {
|
||||
var symbolizer = new ol.style.Icon({
|
||||
url: 'http://example.com/1.png',
|
||||
width: 10
|
||||
});
|
||||
|
||||
expect(function() {
|
||||
symbolizer.setWidth(40);
|
||||
}).throwException(function(err) {
|
||||
expect(err).to.be.a(goog.asserts.AssertionError);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('goog.asserts.AssertionError');
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.style.Icon');
|
||||
goog.require('ol.style.IconLiteral');
|
||||
goog.require('ol.style.Point');
|
||||
@@ -1,55 +0,0 @@
|
||||
goog.provide('ol.test.style.LineLiteral');
|
||||
|
||||
describe('ol.style.LineLiteral', function() {
|
||||
|
||||
describe('#equals()', function() {
|
||||
|
||||
it('identifies equal literals', function() {
|
||||
var literal = new ol.style.LineLiteral({
|
||||
width: 3,
|
||||
color: '#BADA55',
|
||||
opacity: 1,
|
||||
zIndex: 0
|
||||
});
|
||||
var equalLiteral = new ol.style.LineLiteral({
|
||||
color: '#BADA55',
|
||||
width: 3,
|
||||
opacity: 1,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentColor = new ol.style.LineLiteral({
|
||||
width: 3,
|
||||
color: '#ff0000',
|
||||
opacity: 1,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentWidth = new ol.style.LineLiteral({
|
||||
width: 3.5,
|
||||
color: '#BADA55',
|
||||
opacity: 1,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentOpacity = new ol.style.LineLiteral({
|
||||
width: 3,
|
||||
color: '#BADA55',
|
||||
opacity: 0.5,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentZIndex = new ol.style.LineLiteral({
|
||||
width: 3,
|
||||
color: '#BADA55',
|
||||
opacity: 1,
|
||||
zIndex: 3
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).to.be(true);
|
||||
expect(literal.equals(differentColor)).to.be(false);
|
||||
expect(literal.equals(differentWidth)).to.be(false);
|
||||
expect(literal.equals(differentOpacity)).to.be(false);
|
||||
expect(literal.equals(differentZIndex)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.style.LineLiteral');
|
||||
@@ -1,86 +0,0 @@
|
||||
goog.provide('ol.test.style.PolygonLiteral');
|
||||
|
||||
describe('ol.style.PolygonLiteral', function() {
|
||||
|
||||
describe('#equals()', function() {
|
||||
|
||||
it('identifies equal literals', function() {
|
||||
var literal = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3,
|
||||
zIndex: 0
|
||||
});
|
||||
var equalLiteral = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentStrokeWidth = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 5,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentStrokeColor = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#ffff00',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentStrokeOpacity = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.41,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentFillColor = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#00ffff',
|
||||
fillOpacity: 0.3,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentFillOpacity = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.31,
|
||||
zIndex: 0
|
||||
});
|
||||
var differentZIndex = new ol.style.PolygonLiteral({
|
||||
strokeWidth: 3,
|
||||
strokeColor: '#013',
|
||||
strokeOpacity: 0.4,
|
||||
fillColor: '#BADA55',
|
||||
fillOpacity: 0.3,
|
||||
zIndex: 2
|
||||
});
|
||||
expect(literal.equals(equalLiteral)).to.be(true);
|
||||
expect(literal.equals(differentStrokeWidth)).to.be(false);
|
||||
expect(literal.equals(differentStrokeColor)).to.be(false);
|
||||
expect(literal.equals(differentStrokeOpacity)).to.be(false);
|
||||
expect(literal.equals(differentFillColor)).to.be(false);
|
||||
expect(literal.equals(differentFillOpacity)).to.be(false);
|
||||
expect(literal.equals(differentZIndex)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.style.PolygonLiteral');
|
||||
@@ -1,157 +0,0 @@
|
||||
goog.provide('ol.test.style.Rule');
|
||||
|
||||
describe('ol.style.Rule', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('accepts a filter option', function() {
|
||||
var rule = new ol.style.Rule({
|
||||
filter: 'foo == "bar"'
|
||||
});
|
||||
expect(rule).to.be.a(ol.style.Rule);
|
||||
});
|
||||
|
||||
it('accepts a minResolution option', function() {
|
||||
var rule = new ol.style.Rule({
|
||||
minResolution: 10
|
||||
});
|
||||
expect(rule).to.be.a(ol.style.Rule);
|
||||
});
|
||||
|
||||
it('accepts a maxResolution option', function() {
|
||||
var rule = new ol.style.Rule({
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule).to.be.a(ol.style.Rule);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#applies()', function() {
|
||||
var feature = new ol.Feature(),
|
||||
rule;
|
||||
|
||||
it('returns true for a rule without filter', function() {
|
||||
rule = new ol.style.Rule({});
|
||||
expect(rule.applies(feature, 1)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false when the filter evaluates to false', function() {
|
||||
rule = new ol.style.Rule({
|
||||
filter: new ol.expr.Literal(false)
|
||||
});
|
||||
expect(rule.applies(feature, 1)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns true when the filter evaluates to true', function() {
|
||||
rule = new ol.style.Rule({
|
||||
filter: new ol.expr.Literal(true)
|
||||
});
|
||||
expect(rule.applies(feature, 1)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false when the resolution is less than min', function() {
|
||||
rule = new ol.style.Rule({
|
||||
minResolution: 10
|
||||
});
|
||||
expect(rule.applies(feature, 9)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns true when the resolution is greater than min', function() {
|
||||
rule = new ol.style.Rule({
|
||||
minResolution: 10
|
||||
});
|
||||
expect(rule.applies(feature, 11)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns true when the resolution is equal to min', function() {
|
||||
rule = new ol.style.Rule({
|
||||
minResolution: 10
|
||||
});
|
||||
expect(rule.applies(feature, 10)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false if filter evaluates to false (with min res)', function() {
|
||||
rule = new ol.style.Rule({
|
||||
filter: new ol.expr.Literal(false),
|
||||
minResolution: 10
|
||||
});
|
||||
expect(rule.applies(feature, 11)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns true if filter evaluates to true (with min res)', function() {
|
||||
rule = new ol.style.Rule({
|
||||
filter: new ol.expr.Literal(true),
|
||||
minResolution: 10
|
||||
});
|
||||
expect(rule.applies(feature, 11)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false when the resolution is greater than max', function() {
|
||||
rule = new ol.style.Rule({
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 101)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns true when the resolution is less than max', function() {
|
||||
rule = new ol.style.Rule({
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 99)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false when the resolution is equal to max', function() {
|
||||
rule = new ol.style.Rule({
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 100)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns false if filter evaluates to false (with max res)', function() {
|
||||
rule = new ol.style.Rule({
|
||||
filter: new ol.expr.Literal(false),
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 99)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns true if filter evaluates to true (with max res)', function() {
|
||||
rule = new ol.style.Rule({
|
||||
filter: new ol.expr.Literal(true),
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 99)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns true if resolution is between min and max', function() {
|
||||
rule = new ol.style.Rule({
|
||||
minResolution: 10,
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 55)).to.be(true);
|
||||
});
|
||||
|
||||
it('returns false if resolution is greater than min and max', function() {
|
||||
rule = new ol.style.Rule({
|
||||
minResolution: 10,
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 1000)).to.be(false);
|
||||
});
|
||||
|
||||
it('returns false if resolution is less than min and max', function() {
|
||||
rule = new ol.style.Rule({
|
||||
minResolution: 10,
|
||||
maxResolution: 100
|
||||
});
|
||||
expect(rule.applies(feature, 5)).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expr.Literal');
|
||||
goog.require('ol.style.Rule');
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user