Merge branch 'exp'

This commit is contained in:
Tom Payne
2012-08-30 17:05:32 +02:00
164 changed files with 11679 additions and 6992 deletions

19
.gitignore vendored
View File

@@ -1,9 +1,18 @@
/build/OpenLayers.js
/tools/closure-compiler.jar
/tools/*.pyc
/apidoc_config/Data/
/bin/plovr*.jar
/build/OpenLayers.js
/build/ol.js
/build/ol3.js
/build/ol3-compiled.js
/build/webgl-debug.js
/demos/*/advanced-optimizations.*
/demos/*/build.html
/demos/*/debug.html
/demos/*/simple-optimizations.*
/doc/apidocs/
/examples/example-list.js
/examples/example-list.xml
/bin/plovr.jar
/jsdoc/
/jsdoc/
/proj4js-combined.js
/tools/*.pyc
/tools/closure-compiler.jar

142
Makefile Normal file
View File

@@ -0,0 +1,142 @@
PLOVR_JAR=bin/plovr-4b3caf2b7d84.jar
SRC_OL = $(shell find src/ol -name \*.js)
SRC_OL3 = $(shell find externs src/ol3 -name \*.js)
TARGETS = $(shell find demos -name advanced-optimizations.js -o -name simple-optimizations.js)
comma := ,
empty :=
space := $(empty) $(empty)
.PHONY: all
all: build demos
.PHONY: build
build: build/ol.js build/ol3-compiled.js build/webgl-debug.js
build/ol.js: $(PLOVR_JAR) $(SRC_OL3) base.json \
build/ol.json src/ol/ol.js
java -jar $(PLOVR_JAR) build build/ol.json >$@
@echo $@ "uncompressed:" $$(wc -c <$@) bytes
@echo $@ " compressed:" $$(gzip -9 -c <$@ | wc -c) bytes
build/ol3-compiled.js: $(PLOVR_JAR) $(SRC_OL3) base.json \
build/ol3.json build/ol3.js
java -jar $(PLOVR_JAR) build build/ol3.json >$@
@echo $@ "uncompressed:" $$(wc -c <$@) bytes
@echo $@ " compressed:" $$(gzip -9 -c <$@ | wc -c) bytes
build/ol3.js: $(SRC_OL3)
( echo "goog.require('goog.dom');" ; find src/ol3 -name \*.js | xargs grep -rh ^goog.provide | sort | uniq | sed -e 's/provide/require/g' ) > $@
.PHONY: demos
demos: demos/api1 demos/proj4js demos/side-by-side demos/two-layers
.PHONY: demos/api1
demos/api1: \
build/ol.js \
demos/api1/build.html \
demos/api1/debug.html
demos/api1/build.html: demos/api1/index.html.in
sed -e 's|@SRC@|../../build/ol.js|' $< > $@
demos/api1/debug.html: demos/api1/index.html.in
sed -e 's|@SRC@|http://localhost:9810/compile?id=ol|' $< > $@
.PHONY: demos/proj4js
demos/proj4js: \
build/ol.js \
demos/proj4js/build.html \
demos/proj4js/debug.html
demos/proj4js/build.html: demos/proj4js/index.html.in
sed -e 's|@SRC@|../../build/ol.js|' $< > $@
demos/proj4js/debug.html: demos/proj4js/index.html.in
sed -e 's|@SRC@|http://localhost:9810/compile?id=ol|' $< > $@
.PHONY: demos/side-by-side
demos/side-by-side: \
demos/side-by-side/advanced-optimizations.html \
demos/side-by-side/advanced-optimizations.js \
demos/side-by-side/debug.html \
demos/side-by-side/simple-optimizations.html \
demos/side-by-side/simple-optimizations.js
demos/side-by-side/advanced-optimizations.html: demos/side-by-side/index.html.in
sed -e 's|@SRC@|advanced-optimizations.js|' $< > $@
demos/side-by-side/advanced-optimizations.js: $(PLOVR_JAR) $(SRC_OL3) base.json \
demos/side-by-side/side-by-side.json demos/side-by-side/side-by-side.js
java -jar $(PLOVR_JAR) build demos/side-by-side/side-by-side.json >$@
@echo $@ "uncompressed:" $$(wc -c <$@) bytes
@echo $@ " compressed:" $$(gzip -9 -c <$@ | wc -c) bytes
demos/side-by-side/debug.html: demos/side-by-side/index.html.in
sed -e 's|@SRC@|http://localhost:9810/compile?id=demo-side-by-side|' $< > $@
demos/side-by-side/simple-optimizations.html: demos/side-by-side/index.html.in
sed -e 's|@SRC@|simple-optimizations.js|' $< > $@
# FIXME invoke plovr directly, rather than assuming that the server is running
demos/side-by-side/simple-optimizations.js: $(PLOVR_JAR) $(SRC_OL3) base.json \
demos/side-by-side/side-by-side.json demos/side-by-side/side-by-side.js
curl 'http://localhost:9810/compile?id=demo-side-by-side&mode=SIMPLE' > $@
@echo $@ "uncompressed:" $$(wc -c <$@) bytes
@echo $@ " compressed:" $$(gzip -9 -c <$@ | wc -c) bytes
.PHONY: demos/two-layers
demos/two-layers: \
demos/two-layers/advanced-optimizations.html \
demos/two-layers/advanced-optimizations.js \
demos/two-layers/debug.html \
demos/two-layers/simple-optimizations.html \
demos/two-layers/simple-optimizations.js
demos/two-layers/advanced-optimizations.html: demos/two-layers/index.html.in
sed -e 's|@SRC@|advanced-optimizations.js|' $< > $@
demos/two-layers/advanced-optimizations.js: $(PLOVR_JAR) $(SRC_OL3) base.json \
demos/two-layers/two-layers.json demos/two-layers/two-layers.js
java -jar $(PLOVR_JAR) build demos/two-layers/two-layers.json >$@
@echo $@ "uncompressed:" $$(wc -c <$@) bytes
@echo $@ " compressed:" $$(gzip -9 -c <$@ | wc -c) bytes
demos/two-layers/debug.html: demos/two-layers/index.html.in
sed -e 's|@SRC@|http://localhost:9810/compile?id=demo-two-layers|' $< > $@
demos/two-layers/simple-optimizations.html: demos/two-layers/index.html.in
sed -e 's|@SRC@|simple-optimizations.js|' $< > $@
# FIXME invoke plovr directly, rather than assuming that the server is running
demos/two-layers/simple-optimizations.js: $(PLOVR_JAR) $(SRC_OL3) base.json \
demos/two-layers/two-layers.json demos/two-layers/two-layers.js
curl 'http://localhost:9810/compile?id=demo-two-layers&mode=SIMPLE' > $@
@echo $@ "uncompressed:" $$(wc -c <$@) bytes
@echo $@ " compressed:" $$(gzip -9 -c <$@ | wc -c) bytes
.PHONY: serve
serve: $(PLOVR_JAR)
java -jar $(PLOVR_JAR) serve build/ol.json build/ol3.json demos/*/*.json
.PHONY: lint
lint:
gjslint --strict --limited_doc_files=$(subst $(space),$(comma),$(shell find externs -name \*.js)) $(SRC_OL3) $(SRC_OL) $(filter-out $(TARGETS),$(shell find demos -name \*.js))
build/webgl-debug.js:
curl https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/sdk/debug/webgl-debug.js > $@
$(PLOVR_JAR):
curl http://plovr.googlecode.com/files/$(notdir $@) > $@
clean:
rm -f build/all.js
rm -f build/ol.js
rm -f build/ol3.js
rm -f build/ol3-compiled.js
rm -f demos/*/*.html
rm -f demos/*/advanced-optimizations.*
rm -f demos/*/simple-optimizations.*
reallyclean: clean
rm -f $(PLOVR_JAR)
rm -f build/webgl-debug.js

View File

@@ -1,49 +0,0 @@
{
"id": "api",
"output-file": "api.js",
"output-wrapper": [
"// Copyright 2012 ...\n",
"(function(){%output%})();"
],
"inputs": "src/ol.export.js",
"paths": [
"src"
],
"define": {
// "goog.dom.ASSUME_STANDARDS_MODE": true,
// "goog.userAgent.ASSUME_MOBILE_WEBKIT": true,
"goog.DEBUG": false,
"ol.API" : true
},
"mode": "ADVANCED",
"level": "VERBOSE",
// "pretty-print": true,
// "debug": true,
// "experimental-compiler-options": {
// "generateExports": true
// },
"checks": {
// acceptable values are "ERROR", "WARNING", and "OFF"
"accessControls": "WARNING",
"visibility": "WARNING",
"checkTypes": "WARNING",
"checkRegExp": "WARNING",
"checkVars": "WARNING",
"deprecated": "WARNING",
"fileoverviewTags": "WARNING",
"invalidCasts": "WARNING",
"missingProperties": "WARNING",
"nonStandardJsDocs": "WARNING",
"undefinedVars": "WARNING"
},
"jsdoc-html-output-path": "jsdoc"
}

37
base.json Normal file
View File

@@ -0,0 +1,37 @@
{
"checks": {
"accessControls": "ERROR",
"visibility": "ERROR",
"checkTypes": "ERROR",
"checkRegExp": "ERROR",
"checkVars": "ERROR",
"deprecated": "ERROR",
"fileoverviewTags": "ERROR",
"invalidCasts": "ERROR",
"missingProperties": "ERROR",
"nonStandardJsDocs": "ERROR",
"undefinedVars": "ERROR"
},
"define": {
"goog.dom.ASSUME_STANDARDS_MODE": true,
"goog.DEBUG": false
},
"externs": [
"externs/bingmaps.js",
"externs/proj4js.js",
"externs/tilejson.js",
"externs/webgl-debug.js"
],
"level": "VERBOSE",
"mode": "ADVANCED",
"paths": "src",
"treat-warnings-as-errors": true
}

View File

@@ -6,7 +6,8 @@
</description>
<property name="ol.home" location=".."/>
<property name="plovr.jar" location="${ol.home}/bin/plovr.jar"/>
<property name="plovr.version" value="4b3caf2b7d84"/>
<property name="plovr.jar" location="${ol.home}/bin/plovr-${plovr.version}.jar"/>
<property name="main.json" location="${ol.home}/main.json"/>
<property name="build.json" location="${ol.home}/api.json"/>
@@ -25,7 +26,7 @@
</condition>
<target name="deps" unless="plovr.exists">
<get src="http://plovr.googlecode.com/files/plovr-4b3caf2b7d84.jar"
<get src="http://plovr.googlecode.com/files/plovr-${plovr.version}.jar"
dest="${plovr.jar}"/>
</target>

9
build/ol.json Normal file
View File

@@ -0,0 +1,9 @@
{
"id": "ol",
"inherits": "../base.json",
"inputs": "src/ol/ol.js"
}

9
build/ol3.json Normal file
View File

@@ -0,0 +1,9 @@
{
"id": "ol3",
"inherits": "../base.json",
"inputs": "build/ol3.js"
}

View File

@@ -1,26 +0,0 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>OL3 Hello World</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
<link rel="stylesheet" href="../css/ol.css" type="text/css">
<script src="../api.js"></script>
<style type="text/css" media="screen">
html, body, #map { width: 100%; height: 100%; border: 0; margin:0; }
</style>
<script type="text/javascript" charset="utf-8">
var map;
function init() {
map = ol.map()
.renderTo('map')
.layers([ol.layer.osm()])
.center([45, 5])
.zoom(10);
}
</script>
</head>
<body onload="init()">
<div id="map"></div>
</body>
</html>

View File

@@ -1,15 +0,0 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>OL3 Hello World</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
<script src="hello-compiled.js"></script>
<style type="text/css" media="screen">
html, body, #map { width: 100%; height: 100%; border: 0; margin:0; }
</style>
</head>
<body onload="init()">
<div id="map"></div>
</body>
</html>

View File

@@ -1,42 +0,0 @@
{
"id": "hello",
"output-file": "hello-compiled.js",
"inputs": [
"hello.js",
"../src/ol.js"
],
"paths": [
"../src"
],
"define": {
// "goog.dom.ASSUME_STANDARDS_MODE": true,
"goog.DEBUG": false
},
"mode": "ADVANCED",
"level": "VERBOSE",
// "pretty-print": true,
// "debug": true,
// "experimental-compiler-options": {
// "generateExports": true
// },
"checks": {
// acceptable values are "ERROR", "WARNING", and "OFF"
"accessControls": "WARNING",
"visibility": "WARNING",
"checkTypes": "WARNING",
"checkRegExp": "WARNING",
"checkVars": "WARNING",
"deprecated": "WARNING",
"fileoverviewTags": "WARNING",
"invalidCasts": "WARNING",
"missingProperties": "WARNING",
"nonStandardJsDocs": "WARNING",
"undefinedVars": "WARNING"
}
}

View File

@@ -1,42 +0,0 @@
{
"id": "hello-epi",
"output-file": "hello-epi-compiled.js",
"inputs": [
"hello-epi.js"
],
"paths": [
"../src"
],
"define": {
// "goog.dom.ASSUME_STANDARDS_MODE": true,
"goog.DEBUG": false
},
"mode": "ADVANCED",
"level": "VERBOSE",
// "pretty-print": true,
// "debug": true,
// "experimental-compiler-options": {
// "generateExports": true
// },
"checks": {
// acceptable values are "ERROR", "WARNING", and "OFF"
"accessControls": "WARNING",
"visibility": "WARNING",
"checkTypes": "WARNING",
"checkRegExp": "WARNING",
"checkVars": "WARNING",
"deprecated": "WARNING",
"fileoverviewTags": "WARNING",
"invalidCasts": "WARNING",
"missingProperties": "WARNING",
"nonStandardJsDocs": "WARNING",
"undefinedVars": "WARNING"
}
}

View File

@@ -1,16 +0,0 @@
/* This is a code which is going to be compiled together with the library */
goog.require('ol.Map');
goog.require('ol.layer.OSM');
goog.require('ol.Loc');
goog.require('goog.dom');
function init() {
var map = new ol.Map();
map.setContainer(goog.dom.getElement('map'));
map.setLayers( [ new ol.layer.OSM() ] );
map.setCenter( new ol.Loc(45, 5));
map.setZoom(10);
}
window['init'] = init;

View File

@@ -1,10 +0,0 @@
/* This is a code which is going to be compiled together with the library */
function init() {
var map = ol.map()
.renderTo('map')
.layers([ol.layer.osm()])
.center([45, 5])
.zoom(10);
}
window['init'] = init;

View File

@@ -1,7 +0,0 @@
/**
Adds the plovr generated script to the document.
*/
(function() {
var url = "http://" + window.location.hostname + ":9810/compile?id=ol";
document.write("<script type='text/javascript' src='" + url + "'></script>");
})();

View File

@@ -1,17 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>OL3 Map</title>
<script type="text/javascript" src="loader.js"></script>
<link rel="stylesheet" href="../css/ol.css" type="text/css">
<style type="text/css">
#map {
width: 512px; height: 350px;
}
</style>
</head>
<body>
</body>
<div id="map"></div>
<script type="text/javascript" src="map.js"></script>
</html>

View File

@@ -1,6 +0,0 @@
var map = ol.map({
renderTo: 'map',
layers: [ol.layer.osm()],
center: [0, 0],
zoom: 1
});

View File

@@ -1,39 +0,0 @@
/**
* Build configuration for the map.js example. Use following syntax:
*
* ol build map.json
*
* The output will be named map-compiled.js.
*/
{
"id": "hello",
"output-file": "map-compiled.js",
"inputs": ["../src/ol.js", "map.js"],
"paths": ["../src"],
"define": {
"goog.DEBUG": false
},
"mode": "ADVANCED",
"level": "VERBOSE",
// acceptable values are "ERROR", "WARNING", and "OFF"
"checks": {
"accessControls": "WARNING",
"visibility": "WARNING",
"checkTypes": "WARNING",
"checkRegExp": "WARNING",
"checkVars": "WARNING",
"deprecated": "WARNING",
"fileoverviewTags": "WARNING",
"invalidCasts": "WARNING",
"missingProperties": "WARNING",
"nonStandardJsDocs": "WARNING",
"undefinedVars": "WARNING"
}
}

6
demos/api1/api1.js Normal file
View File

@@ -0,0 +1,6 @@
var map = ol.map({
renderTo: 'map',
layers: [ol.layer.osm()],
center: [45, 5],
zoom: 10
});

19
demos/api1/index.html.in Normal file
View File

@@ -0,0 +1,19 @@
<!doctype html>
<html>
<head>
<style type="text/css">
.map {
width: 400px;
height: 400px;
border: thin solid;
}
</style>
<script src="@SRC@" type="text/javascript"></script>
<title>ol3 api1 demo</title>
</head>
<body>
<h1>ol3 api1 demo</h1>
<div class="map" id="map"></div>
<script src="api1.js" type="text/javascript"></script>
</body>
</html>

View File

@@ -0,0 +1,13 @@
<!doctype html>
<html>
<head>
<script src="../../proj4js-combined.js" type="text/javascript"></script>
<script src="@SRC@" type="text/javascript"></script>
<title>ol3 proj4js demo</title>
</head>
<body>
<h1>ol3 proj4js demo</h1>
<div id="output"></div>
<script src="proj4js.js" type="text/javascript"></script>
</body>
</html>

23
demos/proj4js/proj4js.js Normal file
View File

@@ -0,0 +1,23 @@
goog.require('goog.dom');
goog.require('ol3.Coordinate');
goog.require('ol3.Projection');
var outputElement = document.getElementById('output');
var point, transformedPoint;
point = new ol3.Coordinate(-626172.13571216376, 6887893.4928337997);
transformedPoint = ol3.Projection.transformWithCodes(
point, 'GOOGLE', 'WGS84');
outputElement.appendChild(goog.dom.createTextNode(transformedPoint.toString()));
Proj4js.defs['EPSG:21781'] =
'+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 ' +
'+x_0=600000 +y_0=200000 +ellps=bessel ' +
'+towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs';
point = new ol3.Coordinate(7.439583333333333, 46.95240555555556);
transformedPoint = ol3.Projection.transformWithCodes(
point, 'EPSG:4326', 'EPSG:21781');
outputElement.appendChild(goog.dom.createTextNode(transformedPoint.toString()));

View File

@@ -0,0 +1,72 @@
<!doctype html>
<html>
<head>
<style type="text/css">
.map {
width: 400px;
height: 400px;
border: thin solid;
}
</style>
<title>ol3 side-by-side demo</title>
</head>
<body>
<h1>ol3 side-by-side demo</h1>
<table>
<tr>
<th>DOM</th>
<th>WebGL</th>
</tr>
<tr>
<td><div id="domMap" class="map"></div></td>
<td><div id="webglMap" class="map"></div></td>
</tr>
<tr>
<td><div id="domMousePosition" class="mouseposition"></div></td>
<td><div id="webglMousePosition" class="mouseposition"></div></td>
</tr>
<tr>
<td colspan="2">
<div id="attribution" class="attribution"></div>
</td>
</tr>
</table>
<table>
<tr>
<td>Pan:</td>
<td>drag, arrow keys</td>
</tr>
<tr>
<td>Zoom:</td>
<td>double-click, <code>Shift</code>+double-click, mouse wheel, <code>+</code>/<code>-</code> keys; <code>Shift</code>+drag</td>
</tr>
<tr>
<td>Rotate:</td>
<td><code>Alt</code>+drag, <code>r</code> to reset (WebGL only)</td>
</tr>
<tr>
<td>Brightness/contrast:</td>
<td><code>b</code>/<code>B</code>/<code>c</code>/<code>C</code> keys (WebGL only)</td>
</tr>
<tr>
<td>Hue/saturation:</td>
<td><code>h</code>/<code>H</code>/<code>s</code>/<code>S</code> keys (WebGL only)</td>
</tr>
<tr>
<td>Opacity:</td>
<td><code>o</code>/<code>O</code> keys</td>
</tr>
<tr>
<td>Visibility:</td>
<td><code>v</code>/<code>V</code> keys</td>
</tr>
<tr>
<td>Reset</td>
<td><code>0</code> key</td>
</tr>
</table>
<p><b>Notes:</b> The two maps share the same center, resolution, rotation and layers. Currently the DOM map does not support rotation.</p>
<p><b>Console tips:</b> If you want to play around with the API in the console, first make sure that you're using the <a href="simple-optimizations.html">simple optimizations version</a> of this demo, then open a console and experiment with the <code>domMap</code>, <code>webglMap</code> and <code>layer</code> variables in the console. The source code is in <a href="side-by-side.js">side-by-side.js</a>.</p>
<script src="@SRC@" type="text/javascript"></script>
</body>
</html>

View File

@@ -0,0 +1,109 @@
goog.require('goog.debug.Console');
goog.require('goog.debug.Logger');
goog.require('goog.debug.Logger.Level');
goog.require('ol3.CoordinateFormat');
goog.require('ol3.RendererHint');
goog.require('ol3.control.Attribution');
goog.require('ol3.control.MousePosition');
goog.require('ol3.createMap');
goog.require('ol3.interaction.Keyboard');
goog.require('ol3.layer.MapQuestOpenAerial');
if (goog.DEBUG) {
goog.debug.Console.autoInstall();
goog.debug.Logger.getLogger('ol').setLevel(goog.debug.Logger.Level.INFO);
}
var layer = new ol3.layer.MapQuestOpenAerial();
var layers = new ol3.Collection();
layers.push(layer);
var domMap = ol3.createMap(
document.getElementById('domMap'),
{'layers': layers},
ol3.RendererHint.DOM);
domMap.setCenter(new ol3.Coordinate(0, 0));
domMap.setResolution(layer.getStore().getResolutions()[0]);
var webglMap = ol3.createMap(
document.getElementById('webglMap'),
{},
ol3.RendererHint.WEBGL);
if (!goog.isNull(webglMap)) {
webglMap.bindTo('center', domMap);
webglMap.bindTo('layers', domMap);
webglMap.bindTo('resolution', domMap);
webglMap.bindTo('rotation', domMap);
}
var attributionControl = new ol3.control.Attribution(domMap);
document.getElementById('attribution').appendChild(
attributionControl.getElement());
var domMousePositionControl = new ol3.control.MousePosition(domMap,
ol3.Projection.getFromCode('EPSG:4326'), ol3.CoordinateFormat.hdms,
'&nbsp;');
document.getElementById('domMousePosition').appendChild(
domMousePositionControl.getElement());
var webglMousePositionControl = new ol3.control.MousePosition(webglMap,
ol3.Projection.getFromCode('EPSG:4326'), ol3.CoordinateFormat.hdms,
'&nbsp;');
document.getElementById('webglMousePosition').appendChild(
webglMousePositionControl.getElement());
var keyboardInteraction = new ol3.interaction.Keyboard();
keyboardInteraction.addCallback('0', function() {
layer.setBrightness(0);
layer.setContrast(0);
layer.setHue(0);
layer.setSaturation(0);
layer.setOpacity(1);
layer.setVisible(true);
});
keyboardInteraction.addCallback('b', function() {
layer.setBrightness(layer.getBrightness() - 0.1);
});
keyboardInteraction.addCallback('B', function() {
layer.setBrightness(layer.getBrightness() + 0.1);
});
keyboardInteraction.addCallback('c', function() {
layer.setContrast(layer.getContrast() - 0.1);
});
keyboardInteraction.addCallback('C', function() {
layer.setContrast(layer.getContrast() + 0.1);
});
keyboardInteraction.addCallback('h', function() {
layer.setHue(layer.getHue() - 0.1);
});
keyboardInteraction.addCallback('H', function() {
layer.setHue(layer.getHue() + 0.1);
});
keyboardInteraction.addCallback('o', function() {
layer.setOpacity(layer.getOpacity() - 0.1);
});
keyboardInteraction.addCallback('O', function() {
layer.setOpacity(layer.getOpacity() + 0.1);
});
keyboardInteraction.addCallback('r', function() {
webglMap.setRotation(0);
});
keyboardInteraction.addCallback('s', function() {
layer.setSaturation(layer.getSaturation() - 0.1);
});
keyboardInteraction.addCallback('S', function() {
layer.setSaturation(layer.getSaturation() + 0.1);
});
keyboardInteraction.addCallback('vV', function() {
layer.setVisible(!layer.getVisible());
});
domMap.getInteractions().push(keyboardInteraction);
goog.exportSymbol('layer', layer);
goog.exportSymbol('layers', layers);
goog.exportSymbol('domMap', domMap);
goog.exportSymbol('webglMap', webglMap);

View File

@@ -0,0 +1,9 @@
{
"id": "demo-side-by-side",
"inherits": "../../base.json",
"inputs": "demos/side-by-side/side-by-side.js"
}

View File

@@ -0,0 +1,32 @@
<!doctype html>
<html>
<head>
<style type="text/css">
.map {
width: 400px;
height: 400px;
border: thin solid;
}
</style>
<title>ol3 two-layers demo</title>
</head>
<body>
<h1>ol3 two-layers demo</h1>
<table>
<tr>
<th>DOM</th>
<th>WebGL</th>
</tr>
<tr>
<td><div id="domMap" class="map"></div></td>
<td><div id="webglMap" class="map"></div></td>
</tr>
<tr>
<td colspan="2">
<div id="attribution" class="attribution"></div>
</td>
</tr>
</table>
<script src="@SRC@" type="text/javascript"></script>
</body>
</html>

View File

@@ -0,0 +1,44 @@
goog.require('ol3.Coordinate');
goog.require('ol3.RendererHint');
goog.require('ol3.control.Attribution');
goog.require('ol3.createMap');
goog.require('ol3.layer.BingMaps');
goog.require('ol3.layer.TileJSON');
var layer1 = new ol3.layer.BingMaps(
ol3.BingMapsStyle.AERIAL,
'AheP841R-MsLErKQChaTba_xDoOCl40-EeTubD9uNhNAyQTePwFY9iVD1_pyqqlE');
var layer2 = new ol3.layer.TileJSON(
'http://api.tiles.mapbox.com/v3/mapbox.va-quake-aug.jsonp');
var layers = new ol3.Collection([layer1, layer2]);
var webglMap = ol3.createMap(
document.getElementById('webglMap'),
{'layers': new ol3.Collection([layer1, layer2])},
ol3.RendererHint.WEBGL);
goog.events.listen(layer2, goog.events.EventType.LOAD, function() {
webglMap.setUserCenter(new ol3.Coordinate(-77.93254999999999, 37.9555));
webglMap.setResolution(layer2.getStore().getResolutions()[5]);
});
var domMap = ol3.createMap(
document.getElementById('domMap'),
{},
ol3.RendererHint.DOM);
domMap.bindTo('center', webglMap);
domMap.bindTo('layers', webglMap);
domMap.bindTo('resolution', webglMap);
domMap.bindTo('rotation', webglMap);
var attributionControl = new ol3.control.Attribution(webglMap);
document.getElementById('attribution').appendChild(
attributionControl.getElement());
goog.exportSymbol('layer1', layer1);
goog.exportSymbol('layer2', layer2);
goog.exportSymbol('layers', layers);
goog.exportSymbol('domMap', domMap);
goog.exportSymbol('webglMap', webglMap);

View File

@@ -0,0 +1,9 @@
{
"id": "demo-two-layers",
"inherits": "../../base.json",
"inputs": "demos/two-layers/two-layers.js"
}

274
doc/ol3.md Normal file
View File

@@ -0,0 +1,274 @@
CLASS HIERARCHY
===============
```
goog.math.Coordinate // Simple 2D point
|
+- TileCoord
goog.math.Box
|
+- Extent // The extent of a single object in two dimensions, projection not stored
|
+- TileBounds // A range of tiles in two dimensions, integer coordinates, z not stored
Projection
goog.events.EventTarget
|
+- MVCObject
| |
| +- Camera
| |
| +- Control
| | |
| | +- ?
| |
| +- Layer
| | |
| | +- TileLayer
| | | |
| | | +- TMSTileLayer
| | | |
| | | +- WMTSTileLayer
| | | |
| | | +- XYZTileLayer / OSMTileLayer
| | |
| | +- VectorLayer
| | |
| | +- ImageLayer
| |
| +- LayerRenderer
| |
| +- LayerRendererOptions
| |
| +- Map
| |
| +- MapRenderer
| | |
| | +- HTMLMapRenderer
| | |
| | +- WebGLMapRenderer
| |
| +- MVCArray
| | |
| | +- ControlArray
| | |
| | +- LayerViewArray
|
| +- TileQueue
|
+- Tile
```
Layer renderer hierarchy
------------------------
```
goog.events.EventTarget
|
+- MVCObject
|
+- LayerRenderer
|
+- SingleTileLayerRenderer
| |
| +- HTMLSingleTileLayerRenderer
| |
| +- WebGLSingleTileLayerRenderer
|
+- TileLayerRenderer
| |
| +- HTMLTileLayerRenderer
| |
| +- WebGLTileLayerRenderer
|
+- VectorLayerRenderer
| |
| +- HTMLVectorLayerRenderer
| | |
| | +- SVGHTMLVectorLayerRenderer
| | |
| | +- Canvas2DHTMLVectorLayerRenderer
| | |
| | +- VMLHTMLVectorLayerRenderer
| |
| +- WebGLVectorLayerRenderer
```
OBJECT PROPERTIES AND METHODS
=============================
Notation:
- `property type` property with type, trailing ? indicates unsure, getters and setters are assumed to exist.
- `f(args) -> type` function taking args returning type.
- `f(args) -> type = something` f is a trivial wrapper around something.
- `fires 'x'` fires events of type 'x'.
Principles:
- All non-trivial objects inherit from `MVCObject`.
- All non-trivial collections are either `MVCArrays` or a child class thereof.
- Resolutions are `Array.<number>`, infinitely scalable resources (e.g. vectore layers) have resolutions == null.
```
MVCObject
as Google Maps MVCObject
freeze()
unfreeze()
TileCoord
clone() -> TileCoord
getHash() -> number
TileBounds
forEachTileCoord(z, function(tileCoord))
Tile
tileCoord TileCoord
url string
state UNLOADED | LOADING | LOADED
fires 'loaded' // when loaded
fires 'aborted' // when loading is aborted
Camera
position goog.math.Coordinate
resolution number
rotation number
Layer
projections Array.<Projection>
extent Extent
getResolutions() -> Array.<number>|null
fires 'change' // when data changes
LayerArray
getResolutions() -> Array.<number>|null
getMaxResolution() = this.getResolutions()[0] | null
LayerRendererOptions
layer Layer
visible boolean
opacity number
brightness number
color number
hue number
saturation number
Map
projection Projection
renderer Renderer
layers LayerArray
addLayer(layer) = layers.push(layer)
getExtent() -> Extent
getMaxResolution() = layers.getMaxResolution()
TileGrid
resolutions Array.<number>
extent ol.Extent
xEast boolean
ySouth boolean
origin(s) Coord|Array.<Coord>
tileSize goog.math.Size
forEachTileCoordChild(tileCoord, function(z, TileBounds))
forEachTileCoordParent(tileCoord, function(z, TileBounds))
getExtentTileBounds(z, extent) -> TileBounds
getTileCoord(coordinate) -> TileCoord
getTileCoordCenter(tileCoord) -> goog.math.Coordinate
getTileCoordExtent(tileCoord) -> ol.Extent
getTileCoordResolution(tileCoord) -> number
getZForResolution(resolution) -> number
TileLayer
tileGrid TileGrid
tileUrl function(tileCoord) -> string
getTileCoordUrl(tileCoord) -> string = this.tileUrl(tileCoord)
TileQueue
camera Camera // or maybe MVCArray.<Camera> ?
getTileCoordPriority(tileCoord) -> number // private
enqueueTile(Tile)
VectorLayer
forEachFeature(resolution, extent, projection, function(Feature))
Renderer
target HTMLDivElement
map Map
camera Camera
getCapabilities() -> Array.<string> // maybe ?
```
Questions:
- Store tile layer extent in TileLayer or in TileGrid? (not clear)
Two concepts: tile coordinate system range and and available data extent.
TileGrid extent is range (or validity extent) of the tile coordinate system.
TileLayer extent is the available data extent. A particular TileGrid may range
from 0,0 to 10,10. My cache may conform to that grid but I may only have tiles
ranging from 2,2 to 8,8. When you need to wrap multiple worlds, you pay
attention to the TileGrid extent. When you need to decide whether or not to
bother requesting a tile, you pay attention to the TileLayer extent.
- Who determines "best" resolution? (static function?)
Todo: if tile layer extent stored in TileLayer rather than TileGrid then extent
will occasionally need to be passed to TileGrid functions for cropping.
DESIGN ASSERTIONS
=================
Map
- A map has a renderer (the map renderer).
- A map has a camera.
- Multiple maps can share the same camera.
- A map has a layer list.
Layer
- A layer can have multiple projections (the supported projections).
- A layer advertizes the projections it supports.
- A layer returns no data if asked data for an unsupported projection.
LayerRendererOptions
- A layer renderer options object stores view-related states for a layer.
- Options include visibility, opacity, saturation, hue, etc.
- A layer renderer options object has a layer.
- Multiple layer renderer options can share the same layer.
- In other words a layer can be viewed in different manners.
Renderer
- The map renderer responds to events.
- The map renderer receives events from the camera.
- The map renderer creates layer renderers.
Control
- A control may listen to map events.
- A control may listen to camera events.
- A map navigation control acts on the camera.
MVC
- Types can be described in MVC terms.
- Models don't know what rendering means.
- Maps are models.
- Layers are models.
- Layer views are models (sorry!).
- Cameras are models.
- Layer lists are collections.
- Renderers are views.
- Controls are views or controllers or both.
- An attribution control is a view.
- A map navigation control is a controller.
- A zoom slider control is both a view and a controller.

176
externs/bingmaps.js Normal file
View File

@@ -0,0 +1,176 @@
/**
* @externs
*/
/**
* @constructor
*/
var BingMapsCoverageArea = function() {};
/**
* @type {Array.<number>}
*/
BingMapsCoverageArea.prototype.bbox;
/**
* @type {number}
*/
BingMapsCoverageArea.prototype.zoomMax;
/**
* @type {number}
*/
BingMapsCoverageArea.prototype.zoomMin;
/**
* @constructor
*/
var BingMapsImageryProvider = function() {};
/**
* @type {string}
*/
BingMapsImageryProvider.prototype.attribution;
/**
* @type {Array.<BingMapsCoverageArea>}
*/
BingMapsImageryProvider.prototype.coverageAreas;
/**
* @constructor
*/
var BingMapsImageryMetadataResponse = function() {};
/**
* @type {string}
*/
BingMapsImageryMetadataResponse.prototype.authenticationResultCode;
/**
* @type {string}
*/
BingMapsImageryMetadataResponse.prototype.brandLogoUri;
/**
* @type {string}
*/
BingMapsImageryMetadataResponse.prototype.copyright;
/**
* @type {Array.<BingMapsResourceSet>}
*/
BingMapsImageryMetadataResponse.prototype.resourceSets;
/**
* @type {number}
*/
BingMapsImageryMetadataResponse.prototype.statusCode;
/**
* @type {string}
*/
BingMapsImageryMetadataResponse.prototype.statusDescription;
/**
* @type {string}
*/
BingMapsImageryMetadataResponse.prototype.traceId;
/**
* @constructor
*/
var BingMapsResource = function() {};
/**
* @type {number}
*/
BingMapsResource.prototype.imageHeight;
/**
* @type {string}
*/
BingMapsResource.prototype.imageUrl;
/**
* @type {Array.<string>}
*/
BingMapsResource.prototype.imageUrlSubdomains;
/**
* @type {number}
*/
BingMapsResource.prototype.imageWidth;
/**
* @type {Array.<BingMapsImageryProvider>}
*/
BingMapsResource.prototype.imageryProviders;
/**
* @type {Object}
*/
BingMapsResource.prototype.vintageEnd;
/**
* @type {Object}
*/
BingMapsResource.prototype.vintageStart;
/**
* @type {number}
*/
BingMapsResource.prototype.zoomMax;
/**
* @type {number}
*/
BingMapsResource.prototype.zoomMin;
/**
* @constructor
*/
var BingMapsResourceSet = function() {};
/**
* @type {number}
*/
BingMapsResourceSet.prototype.estimatedTotal;
/**
* @type {Array.<BingMapsResource>}
*/
BingMapsResourceSet.prototype.resources;

View File

@@ -1,3 +1,4 @@
/**
* @fileoverview Externs for GeoJSON.
* @see http://geojson.org/geojson-spec.html

74
externs/proj4js.js Normal file
View File

@@ -0,0 +1,74 @@
/**
* @externs
* @see http://trac.osgeo.org/proj4js/
*/
/**
* @type {Object}
*/
var Proj4js = {};
/**
* @type {Object.<string, string>}
*/
Proj4js.defs;
/**
* @type {function(string)}
*/
Proj4js.reportError;
/**
* @constructor
* @param {number} x
* @param {number} y
*/
Proj4js.Point = function(x, y) {};
/**
* @type {number}
*/
Proj4js.Point.prototype.x;
/**
* @type {number}
*/
Proj4js.Point.prototype.y;
/**
* @constructor
* @param {string} srsCode
* @param {Function=} opt_callback
*/
Proj4js.Proj = function(srsCode, opt_callback) {};
/**
* @type {string}
*/
Proj4js.Proj.prototype.title;
/**
* @type {string}
*/
Proj4js.Proj.prototype.units;
/**
* @nosideeffects
* @param {Proj4js.Proj} source
* @param {Proj4js.Proj} dest
* @param {Proj4js.Point|{x:number, y:number}} point
* @return {Proj4js.Point}
*/
Proj4js.transform = function(source, dest, point) {};

95
externs/tilejson.js Normal file
View File

@@ -0,0 +1,95 @@
/**
* @externs
* @see https://github.com/mapbox/tilejson-spec
*/
/**
* @constructor
*/
var TileJSON = function() {};
/**
* @type {string}
*/
TileJSON.prototype.tilejson;
/**
* @type {string|undefined}
*/
TileJSON.prototype.name;
/**
* @type {string|undefined}
*/
TileJSON.prototype.description;
/**
* @type {string|undefined}
*/
TileJSON.prototype.version;
/**
* @type {string|undefined}
*/
TileJSON.prototype.attribution;
/**
* @type {string|undefined}
*/
TileJSON.prototype.template;
/**
* @type {string|undefined}
*/
TileJSON.prototype.legend;
/**
* @type {string|undefined}
*/
TileJSON.prototype.scheme;
/**
* @type {!Array.<string>}
*/
TileJSON.prototype.tiles;
/**
* @type {!Array.<string>}
*/
TileJSON.prototype.grids;
/**
* @type {number|undefined}
*/
TileJSON.prototype.minzoom;
/**
* @type {number|undefined}
*/
TileJSON.prototype.maxzoom;
/**
* @type {!Array.<number>|undefined}
*/
TileJSON.prototype.bounds;
/**
* @type {!Array.<number>|undefined}
*/
TileJSON.prototype.center;

98
externs/webgl-debug.js Normal file
View File

@@ -0,0 +1,98 @@
/**
* @externs
* @see http://www.khronos.org/webgl/wiki/Debugging
* @see http://www.khronos.org/webgl/wiki/HandlingContextLost
*/
/**
* @constructor
* @extends {WebGLRenderingContext}
*/
var WebGLDebugRenderingContext = function() {};
/**
* @constructor
* @extends {HTMLCanvasElement}
*/
var WebGLDebugLostContextSimulatingCanvas = function() {};
/**
* @nosideeffects
* @return {number}
*/
WebGLDebugLostContextSimulatingCanvas.prototype.getNumCalls = function() {};
/**
*/
WebGLDebugLostContextSimulatingCanvas.prototype.loseContext = function() {};
/**
* @param {number} numCalls
*/
WebGLDebugLostContextSimulatingCanvas.prototype.loseContextInNCalls =
function(numCalls) {};
/**
*/
WebGLDebugLostContextSimulatingCanvas.prototype.restoreContext = function() {};
/**
* @param {number} timeout
*/
WebGLDebugLostContextSimulatingCanvas.prototype.setRestoreTimeout =
function(timeout) {};
/**
* @type {Object}
*/
var WebGLDebugUtils = {};
/**
* @nosideeffects
* @param {number} value
* @return {string}
*/
WebGLDebugUtils.glEnumToString = function(value) {};
/**
* @nosideeffects
* @param {string} functionName
* @param {Array} args Args.
* @return {string} String.
*/
WebGLDebugUtils.glFunctionArgsToString = function(functionName, args) {};
/**
* @param {WebGLRenderingContext} ctx
*/
WebGLDebugUtils.init = function(ctx) {};
/**
* @param {HTMLCanvasElement} canvas
* @return {WebGLDebugLostContextSimulatingCanvas}
*/
WebGLDebugUtils.makeLostContextSimulatingCanvas = function(canvas) {};
/**
* @param {WebGLRenderingContext} context
* @param {Function=} opt_onErrorFunc
* @param {Function=} opt_onFunc
* @return {WebGLDebugRenderingContext}
*/
WebGLDebugUtils.makeDebugContext =
function(context, opt_onErrorFunc, opt_onFunc) {};

View File

@@ -1,46 +0,0 @@
{
"id": "ol",
"inputs": [
"src/ol.js",
"src/ol.export.js"
],
"paths": [
"src"
],
"define": {
// "goog.dom.ASSUME_STANDARDS_MODE": true,
"goog.DEBUG": false
},
"externs": [
"externs/geojson.js"
],
"mode": "ADVANCED",
"level": "VERBOSE",
"pretty-print": true,
"debug": true,
// "experimental-compiler-options": {
// "generateExports": true
// },
"checks": {
// acceptable values are "ERROR", "WARNING", and "OFF"
"accessControls": "WARNING",
"visibility": "WARNING",
"checkTypes": "WARNING",
"checkRegExp": "WARNING",
"checkVars": "WARNING",
"deprecated": "WARNING",
"fileoverviewTags": "WARNING",
"invalidCasts": "WARNING",
"missingProperties": "WARNING",
"nonStandardJsDocs": "WARNING",
"undefinedVars": "WARNING"
},
"jsdoc-html-output-path": "jsdoc"
}

View File

@@ -1,79 +1,35 @@
# OpenLayers
# OpenLayers 3
Copyright (c) 2005-2012 OpenLayers Contributors. See authors.txt for
more details.
## Build it
OpenLayers is a JavaScript library for building map applications
on the web. OpenLayers is made available under a BSD-license.
Please see license.txt in this distribution for more details.
Run make:
## Getting OpenLayers
$ make
OpenLayers lives at http://www.openlayers.org/. Find details on downloading stable releases or the development version the [development site](http://trac.osgeo.org/openlayers/wiki/HowToDownload).
## Run the examples
## Installing OpenLayers
Run make (as above), then explore the `demos/` directory with your web browser.
You can use OpenLayers as-is by copying build/OpenLayers.js and the
entire theme/ and img/ directories up to your webserver and putting them
in the same directory. The files can be in subdirectories on your website,
or right in the root of the site, as in these examples.
To include the OpenLayers library in your web page from the root of the site, use:
## Run the examples in debug mode
<script type="text/javascript" src="/OpenLayers.js" />
Run the [Plovr](http://plovr.com/) web server with:
As an example, using bash (with the release files in ~/openlayers):
$ make serve
$ cd /var/www/html
$ cp ~/openlayers/OpenLayers.js ./
$ cp -R ~/openlayers/theme ./
$ cp -R ~/openlayers/img ./
Then, start a simple webserver, for example:
If you want to use the multiple-file version of OpenLayers (for, say,
debugging or development purposes), copy the lib/ directory up to your
webserver in the same directory you put the img/ folder. Then add
the following to your web page instead:
$ python -mSimpleHTTPServer
<script type="text/javascript" src="/lib/OpenLayers.js" />
Explore the `demos/` directory through this server, for example <http://localhost:8000/demos/side-by-side/debug.html>. You can turn off compilation by appending `?mode=RAW` to the URL, for example <http://localhost:8000/demos/side-by-side/debug.html?mode=RAW>.
As an example, using bash (with the release files in ~/openlayers):
Note that appending `?mode=RAW` doesn't work with `file://` URLs, which is why you need to access the `demos/` directory though a web server.
$ cd /var/www/html
$ cp -R ~/openlayers/lib ./
$ cp -R ~/openlayers/theme ./
$ cp -R ~/openlayers/img ./
## Run tests
## Alternate OpenLayers Versions in this Release
Run the plovr web server (see above), then open <http://localhost:9810/> in your browser and select *List of tests* or *Test runner*.
The following versions of OpenLayers single file builds are included in this release
and can be used in place of OpenLayers.js in any of the above instructions:
## Run the linter
1. OpenLayers.js - full build --> Includes everything except the alternate language
translations and deprecated classes.
2. OpenLayers.mobile.js - a mobile focused build --> Includes a subset of the OpenLayers
library to serve common mobile web app use cases. This build provides access to
OpenStreetMap, Bing, WMS, WFS and vector layers; touch optimized controls; geolocation;
vector editing and interaction tools. The examples tagged ``mobile`` can use this build.
3. OpenLayers.light.js - a simple use case focused build --> Includes a subset of the
OpenLayers library to serve the basic use case of displaying points and polygons
on a map. This build provides access to OpenStreetMap, Bing, Google, WMS, and
vector layers; basic map controls; and vector interaction tools. The examples
tagged ``light`` can use this build.
## Using OpenLayers in Your Own Website
The [examples directory](http://openlayers.org/dev/examples/) is full of useful examples.
Documentation is available at http://trac.osgeo.org/openlayers/wiki/Documentation.
You can generate the API documentation with http://www.naturaldocs.org/
As an example, using bash (with the release files in ~/openlayers):
$ cd ~/openlayers/
$ /path/to/NaturalDocs -i lib/ -o HTML doc/ -p doc_config/ -s Default OL
Information on changes in the API is available in release notes found in the notes folder.
## Contributing to OpenLayers
Please join the email lists at http://openlayers.org/mailman/listinfo
Patches are welcome!
First, install the [Closure Linter](https://developers.google.com/closure/utilities/docs/linter_howto). Then:
$ make lint

View File

@@ -1,149 +0,0 @@
goog.provide('ol.bounds');
goog.require('ol.Bounds');
goog.require('ol.projection');
/**
* @typedef {ol.Bounds|Array.<number>|Object} bounds Location.
*/
ol.LocLike;
/**
* @export
* @param {ol.LocLike} opt_arg Location.
* @return {ol.Bounds} Location.
*/
ol.bounds = function(opt_arg){
if (opt_arg instanceof ol.Bounds) {
return opt_arg;
}
var minX = 0;
var minY = 0;
var maxX = 0;
var maxY = 0;
var projection;
var x = 0;
var y = 0;
var z;
if (goog.isArray(opt_arg)) {
minX = opt_arg[0];
minY = opt_arg[1];
maxX = opt_arg[2];
maxY = opt_arg[3];
} else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['minX', 'minY', 'maxX', 'maxY', 'projection']);
minX = ol.API ? opt_arg['minX'] : opt_arg.minX;
minY = ol.API ? opt_arg['minY'] : opt_arg.minY;
maxX = ol.API ? opt_arg['maxX'] : opt_arg.maxX;
maxY = ol.API ? opt_arg['maxY'] : opt_arg.maxY;
projection = ol.projection(ol.API ? opt_arg['projection'] : opt_arg.projection);
}
else {
throw new Error('ol.bounds');
}
var bounds = new ol.Bounds(minX, minY, maxX, maxY, projection);
return bounds;
};
/**
* @export
* @param {ol.Projection=} opt_arg Projection.
* @return {ol.Bounds|ol.Projection|undefined} Result.
*/
ol.Bounds.prototype.projection = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setProjection(opt_arg);
return this;
}
else {
return this.getProjection();
}
};
/**
* @export
* @param {number=} opt_arg Minimum X.
* @return {!ol.Bounds|number} Result.
*/
ol.Bounds.prototype.minX = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setMinX(opt_arg);
return this;
}
else {
return this.getMinX();
}
};
/**
* @export
* @param {number=} opt_arg Minimum Y.
* @return {ol.Bounds|number} Result.
*/
ol.Bounds.prototype.minY = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setMinY(opt_arg);
return this;
}
else {
return this.getMinY();
}
};
/**
* @export
* @param {number=} opt_arg Maximum X.
* @return {ol.Bounds|number} Result.
*/
ol.Bounds.prototype.maxX = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setMaxX(opt_arg);
return this;
}
else {
return this.getMaxX();
}
};
/**
* @export
* @param {number=} opt_arg Maximum Y.
* @return {ol.Bounds|number} Result.
*/
ol.Bounds.prototype.maxY = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setMaxY(opt_arg);
return this;
}
else {
return this.getMaxY();
}
};
/**
* Transform this node into another coordinate reference system. Returns a new
* bounds instead of modifying this bounds.
*
* @param {ol.Projection|string} proj Target projection (or string identifier).
* @return {ol.Bounds} A new bounds in the target projection.
*/
ol.Bounds.prototype.transform = function(proj) {
if (goog.isString(proj)) {
proj = new ol.Projection(proj);
}
return this.doTransform(proj);
};

View File

@@ -1,92 +0,0 @@
goog.provide('ol.feature');
goog.require('ol.base');
goog.require('ol.Feature');
goog.require('ol.geom.Geometry');
/**
* @typedef {ol.Feature|Object|string}
*/
ol.FeatureLike;
/**
* @export
* @param {ol.FeatureLike=} opt_arg Argument.
* @return {ol.Feature} Feature.
*/
ol.feature = function(opt_arg){
/** @type {Object|undefined} */
var properties;
/** @type {ol.geom.Geometry|undefined} */
var geometry;
/** @type {string|undefined} */
var type;
if (arguments.length == 1) {
if (opt_arg instanceof ol.Feature) {
return opt_arg;
}
else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['geometry', 'properties', 'type']);
properties = ol.API ? opt_arg['properties'] : opt_arg.properties;
geometry = ol.API ? opt_arg['geometry'] : opt_arg.geometry;
type = ol.API ? opt_arg['type'] : opt_arg.type;
}
else {
throw new Error('ol.feature');
}
}
var feature = new ol.Feature();
if (goog.isDef(type) && type == 'Feature') {
//this means it is a GeoJSON object
//format.read(opt_arg);
} else {
if (goog.isDef(properties)) {
feature.setAttributes(properties);
}
if (goog.isDef(geometry)) {
feature.setGeometry(geometry);
}
}
return feature;
};
/**
* @export
* @param {!string} attr The name of the attribute to be set.
* @param {string|number|boolean} value The value of the attribute to be set.
* @returns {ol.Feature} The feature so calls can be chained
*/
ol.Feature.prototype.set = function(attr, value) {
this.setAttribute(attr, value);
return this;
};
/**
* @export
* @param {!string} attr The name of the attribute to be set.
* @returns {string|number|boolean|undefined} The attribute value requested.
*/
ol.Feature.prototype.get = function(attr) {
return this.getAttribute(attr);
};
/**
* @export
* @param {ol.geom.Geometry=} opt_arg
* @returns {ol.Feature|ol.geom.Geometry|undefined} get or set the geometry on a feature
*/
ol.Feature.prototype.geometry = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setGeometry(opt_arg);
return this;
} else {
return this.getGeometry();
}
};

View File

@@ -1,133 +0,0 @@
goog.provide('ol.geom.collection');
goog.require('ol.geom.Collection');
goog.require('ol.geom.point');
goog.require('ol.projection');
/**
* @export
* @param {Array.<ol.geom.Geometry>} opt_arg Components.
* @return {ol.geom.Collection} Collection.
*/
ol.geom.collection = function(opt_arg){
if (opt_arg instanceof ol.geom.Collection) {
return opt_arg;
}
var components = [];
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isArray(opt_arg)) {
var allValid = goog.array.every(opt_arg, function(geom){
if (geom instanceof ol.geom.Geometry) {
components.push(geom);
return true;
} else {
return false;
}
});
if (!allValid) {
var msg = 'ol.geom.collection: at least one component '
+ 'definition was no geometry.';
throw new Error(msg);
}
} else {
throw new Error('ol.geom.collection');
}
}
var c = new ol.geom.Collection(components);
return c;
};
goog.inherits(ol.geom.collection, ol.geom.geometry);
/**
* @export
* @param {Array.<ol.geom.Geometry>=} opt_arg An array of point specifications.
* @return {Array.<ol.geom.Geometry>|ol.geom.Collection|undefined} Result.
*/
ol.geom.Collection.prototype.components = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
var components = [],
allValid = false;
allValid = goog.array.every(opt_arg, function(geom){
if (geom instanceof ol.geom.Geometry) {
components.push(geom);
return true;
} else {
return false;
}
});
if (!allValid) {
components = [];
}
this.setComponents(components);
return this;
}
else {
return this.getComponents();
}
};
/**
* @export
* @param {ol.geom.Geometry} geom A geometry.
* @param {number=} opt_index An optional index to add the point(s) at. If not
* provided, the point(s) will be added to the end of the list of components.
* @return {ol.geom.Collection} The Collection instance.
*/
ol.geom.Collection.prototype.add = function(geom, opt_index){
var index = this.components_.length;
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
this.addComponent(geom, index);
return this;
};
/**
* @export
* @param {Array.<ol.geom.Geometry>} components Some point specifications.
* @param {number=} opt_index An optional index to add the components at. If not
* provided, the components will be added to the end of the list of
* components.
* @return {ol.geom.Collection} The Collection instance.
*/
ol.geom.Collection.prototype.addAll = function(components, opt_index){
var index = this.components_.length;
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
goog.array.every(components, function(c){
this.addComponent(c, index);
index++;
return true;
}, this);
return this;
};
/**
* @export
* @param {(ol.geom.Geometry|Array.<ol.geom.Geometry>)} components A point specification or
* an array of point specifications.
* @return {ol.geom.Collection} The Collection instance.
*/
ol.geom.Collection.prototype.remove = function(components){
var compArr = [];
if (!goog.isArray(components)) {
compArr.push(components);
} else {
compArr = components;
}
goog.array.every(compArr, function(c){
this.removeComponent(c);
return true;
}, this);
return this;
};

View File

@@ -1,35 +0,0 @@
goog.provide('ol.geom.geometry');
goog.require('ol.geom.Geometry');
/**
* @export
* @return {ol.geom.Geometry} Geometry..
*/
ol.geom.geometry = function(){
var g = new ol.geom.Geometry();
return g;
};
/**
* @export
* @param {ol.Bounds=} opt_arg new Bounds.
* @return {ol.geom.Geometry|ol.Bounds|undefined} either a Geometry (when used as
* setter) or a Bounds/undefined (if used as getter).
*/
ol.geom.Geometry.prototype.bounds = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setBounds(opt_arg);
} else {
return this.getBounds();
}
};
/**
* Returns the centroid of the geometry.
*
* @returns {ol.geom.Point} The centroid of the geometry.
*/
ol.geom.Geometry.prototype.centroid = function() {
return this.getCentroid();
};

View File

@@ -1,142 +0,0 @@
goog.provide('ol.geom.linestring');
goog.require('ol.geom.LineString');
goog.require('ol.geom.point');
goog.require('ol.projection');
/**
* @typedef {Array.<ol.PointLike>} linestring LineString.
*/
ol.LineStringLike;
/**
* @export
* @param {ol.LineStringLike} opt_arg Points.
* @return {ol.geom.LineString} LineString.
*/
ol.geom.linestring = function(opt_arg){
if (opt_arg instanceof ol.geom.LineString) {
return opt_arg;
}
var vertices = [];
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isArray(opt_arg)) {
var allValid = goog.array.every(opt_arg, function(spec){
var v = ol.geom.point(spec);
if (v instanceof ol.geom.Point) {
vertices.push(v);
return true;
} else {
return false;
}
});
if (!allValid) {
var msg = 'ol.geom.linestring: at least one point '
+ 'definition was erroneous.';
throw new Error(msg);
}
} else {
throw new Error('ol.geom.linestring');
}
}
var ls = new ol.geom.LineString(vertices);
return ls;
};
goog.inherits(ol.geom.linestring, ol.geom.geometry);
/**
* @export
* @param {Array.<ol.PointLike>=} opt_arg An array of vertex specifications.
* @return {Array.<ol.geom.Point>|ol.geom.LineString|undefined} Result.
*/
ol.geom.LineString.prototype.vertices = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
var vertices = [],
allValid = false;
goog.array.every(opt_arg, function(spec){
var v = ol.geom.point(spec);
if (v instanceof ol.geom.Point) {
vertices.push(v);
return true;
} else {
return false;
}
});
if (!allValid) {
vertices = [];
}
this.setVertices(vertices);
return this;
}
else {
return this.getVertices();
}
};
/**
* @export
* @param {ol.PointLike} vertex A point specification.
* @param {number=} opt_index An optional index to add the vertices at. If not
* provided, the vertex will be added to the end of the list of vertices.
* @return {ol.geom.LineString} The LineString instance.
*/
ol.geom.LineString.prototype.add = function(vertex, opt_index){
var index = this.vertices_.length,
allValid = false,
v = ol.geom.point(vertex);
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
this.addVertex(v, index);
return this;
};
/**
* @export
* @param {Array.<ol.PointLike>} vertices Some vertex specifications.
* @param {number=} opt_index An optional index to add the vertices at. If not
* provided, the points will be added to the end of the list of vertices.
* @return {ol.geom.LineString} The LineString instance.
*/
ol.geom.LineString.prototype.addAll = function(vertices, opt_index){
var index = this.vertices_.length,
v;
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
goog.array.every(vertices, function(vertexSpec){
v = ol.geom.point(vertexSpec);
this.addVertex(v, index);
index++;
return true;
}, this);
return this;
};
/**
* @export
* @param {(ol.geom.Point|Array.<ol.geom.Point>)} vertices A point specification or
* an array of point specifications.
* @return {ol.geom.LineString} The MultiPoint instance.
*/
ol.geom.LineString.prototype.remove = function(vertices){
var vertexArr = [];
if (!goog.isArray(vertices)) {
vertexArr.push(vertices);
} else {
vertexArr = vertices;
}
goog.array.every(vertexArr, function(v){
this.removeVertex(v);
return true;
}, this);
return this;
};

View File

@@ -1,138 +0,0 @@
goog.provide('ol.geom.multilinestring');
goog.require('ol.geom.MultiLineString');
goog.require('ol.geom.point');
goog.require('ol.geom.collection');
goog.require('ol.projection');
/**
* @export
* @param {Array.<ol.LineStringLike>} opt_arg Point.
* @return {ol.geom.MultiLineString} MultiLineString.
*/
ol.geom.multilinestring = function(opt_arg){
if (opt_arg instanceof ol.geom.MultiLineString) {
return opt_arg;
}
var ls = [];
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isArray(opt_arg)) {
var allValid = goog.array.every(opt_arg, function(spec){
var l = ol.geom.linestring(spec);
if (l instanceof ol.geom.LineString) {
ls.push(l);
return true;
} else {
return false;
}
});
if (!allValid) {
var msg = 'ol.geom.linestring: at least one linestring '
+ 'definition was erroneous.';
throw new Error(msg);
}
} else {
throw new Error('ol.geom.multilinestring');
}
}
var mls = new ol.geom.MultiLineString(ls);
return mls;
};
goog.inherits(ol.geom.multilinestring, ol.geom.collection);
/**
* @export
* @param {Array.<ol.LineStringLike>=} opt_arg An array of point specifications.
* @return {Array.<ol.geom.LineString>|ol.geom.MultiLineString|undefined} Result.
*/
ol.geom.MultiLineString.prototype.linestrings = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
var ls = [],
allValid = false;
allValid = goog.array.every(opt_arg, function(spec){
var l = ol.geom.linestring(spec);
if (l instanceof ol.geom.LineString) {
ls.push(l);
return true;
} else {
return false;
}
});
if (!allValid) {
ls = [];
}
this.setComponents(ls);
return this;
}
else {
return this.getComponents();
}
};
/**
* @export
* @param {ol.LineStringLike} line A linestring specification.
* @param {number=} opt_index An optional index to add the point(s) at. If not
* provided, the point(s) will be added to the end of the list of points.
* @return {ol.geom.MultiLineString} The MultiPoint instance.
*/
ol.geom.MultiLineString.prototype.add = function(line, opt_index){
var index = this.getLineStrings().length,
l = ol.geom.linestring(line);
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
this.addLineString(l, index);
return this;
};
/**
* @export
* @param {Array.<ol.LineStringLike>} lines Some linestring specifications.
* @param {number=} opt_index An optional index to add the points at. If not
* provided, the linestrings will be added to the end of the list of
* linestrings.
* @return {ol.geom.MultiLineString} The MultiLineString instance.
*/
ol.geom.MultiLineString.prototype.addAll = function(lines, opt_index){
var index = this.getLineStrings().length,
l;
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
goog.array.every(lines, function(pointSpec){
l = ol.geom.linestring(pointSpec);
this.addLineString(l, index);
index++;
return true;
}, this);
return this;
};
/**
* @export
* @param {(ol.geom.LineString|Array.<ol.geom.LineString>)} lines A linestring
* specification or an array of linestring specifications.
* @return {ol.geom.MultiLineString} The MultiLineString instance.
*/
ol.geom.MultiLineString.prototype.remove = function(lines){
var lineArr = [];
if (!goog.isArray(lines)) {
lineArr.push(lines);
} else {
lineArr = lines;
}
goog.array.every(lineArr, function(l){
this.removeLineString(l);
return true;
}, this);
return this;
};

View File

@@ -1,137 +0,0 @@
goog.provide('ol.geom.multipoint');
goog.require('ol.geom.MultiPoint');
goog.require('ol.geom.point');
goog.require('ol.geom.collection');
goog.require('ol.projection');
/**
* @export
* @param {Array.<ol.PointLike>} opt_arg Point.
* @return {ol.geom.MultiPoint} MultiPoint.
*/
ol.geom.multipoint = function(opt_arg){
if (opt_arg instanceof ol.geom.MultiPoint) {
return opt_arg;
}
var points = [];
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isArray(opt_arg)) {
var allValid = goog.array.every(opt_arg, function(spec){
var p = ol.geom.point(spec);
if (p instanceof ol.geom.Point) {
points.push(p);
return true;
} else {
return false;
}
});
if (!allValid) {
var msg = 'ol.geom.multipoint: at least one point '
+ 'definition was erroneous.';
throw new Error(msg);
}
} else {
throw new Error('ol.geom.multipoint');
}
}
var mp = new ol.geom.MultiPoint(points);
return mp;
};
goog.inherits(ol.geom.multipoint, ol.geom.collection);
/**
* @export
* @param {Array.<ol.PointLike>=} opt_arg An array of point specifications.
* @return {Array.<ol.geom.Point>|ol.geom.MultiPoint|undefined} Result.
*/
ol.geom.MultiPoint.prototype.points = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
var points = [],
allValid = false;
allValid = goog.array.every(opt_arg, function(spec){
var p = ol.geom.point(spec);
if (p instanceof ol.geom.Point) {
points.push(p);
return true;
} else {
return false;
}
});
if (!allValid) {
points = [];
}
this.setComponents(points);
return this;
}
else {
return this.getComponents();
}
};
/**
* @export
* @param {ol.PointLike} point A point specification.
* @param {number=} opt_index An optional index to add the point(s) at. If not
* provided, the point(s) will be added to the end of the list of points.
* @return {ol.geom.MultiPoint} The MultiPoint instance.
*/
ol.geom.MultiPoint.prototype.add = function(point, opt_index){
var index = this.getPoints().length,
p = ol.geom.point(point);
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
this.addPoint(p, index);
return this;
};
/**
* @export
* @param {Array.<ol.PointLike>} points Some point specifications.
* @param {number=} opt_index An optional index to add the points at. If not
* provided, the points will be added to the end of the list of points.
* @return {ol.geom.MultiPoint} The MultiPoint instance.
*/
ol.geom.MultiPoint.prototype.addAll = function(points, opt_index){
var index = this.getPoints().length,
p;
if (arguments.length == 2 && goog.isDef(opt_index)) {
index = opt_index;
}
goog.array.every(points, function(pointSpec){
p = ol.geom.point(pointSpec);
this.addPoint(p, index);
index++;
return true;
}, this);
return this;
};
/**
* @export
* @param {(ol.geom.Point|Array.<ol.geom.Point>)} points A point specification or
* an array of point specifications.
* @return {ol.geom.MultiPoint} The MultiPoint instance.
*/
ol.geom.MultiPoint.prototype.remove = function(points){
var pointArr = [];
if (!goog.isArray(points)) {
pointArr.push(points);
} else {
pointArr = points;
}
goog.array.every(pointArr, function(p){
this.removePoint(p);
return true;
}, this);
return this;
};

View File

@@ -1,122 +0,0 @@
goog.provide('ol.geom.point');
goog.require('ol.geom.Point');
goog.require('ol.projection');
/**
* @typedef {Array.<number>|Object} point Point.
*/
ol.PointLike;
/**
* @export
* @param {ol.PointLike} opt_arg Point.
* @return {ol.geom.Point} Point.
*/
ol.geom.point = function(opt_arg){
if (opt_arg instanceof ol.geom.Point) {
return opt_arg;
}
var x = 0;
var y = 0;
var z;
var projection;
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isArray(opt_arg)) {
x = opt_arg[0];
y = opt_arg[1];
z = opt_arg[2];
projection = opt_arg[3];
} else if (goog.isObject(opt_arg)) {
x = ol.API ? opt_arg['x'] : opt_arg.x;
y = ol.API ? opt_arg['y'] : opt_arg.y;
z = ol.API ? opt_arg['z'] : opt_arg.z;
projection = ol.API ? opt_arg['projection'] : opt_arg.projection;
} else {
throw new Error('ol.geom.point');
}
}
if (goog.isDef(projection)) {
projection = ol.projection(projection);
}
var p = new ol.geom.Point(x,y,z,projection);
return p;
};
goog.inherits(ol.geom.point, ol.geom.geometry);
/**
* @export
* @param {number=} opt_arg X.
* @return {ol.geom.Point|number} Result.
*/
ol.geom.Point.prototype.x = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setX(opt_arg);
return this;
}
else {
return this.getX();
}
};
/**
* @export
* @param {number=} opt_arg Y.
* @return {ol.geom.Point|number} Result.
*/
ol.geom.Point.prototype.y = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setY(opt_arg);
return this;
}
else {
return this.getY();
}
};
/**
* @export
* @param {number=} opt_arg Z.
* @return {ol.geom.Point|number|undefined} Result.
*/
ol.geom.Point.prototype.z = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setZ(opt_arg);
return this;
}
else {
return this.getZ();
}
};
/**
* @export
* @param {ol.Projection=} opt_arg Projection.
* @return {ol.geom.Point|ol.Projection|undefined} Result.
*/
ol.geom.Point.prototype.projection = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setProjection(ol.projection(opt_arg));
return this;
}
else {
return this.getProjection();
}
};
/**
* Returns the centroid of this point; which is a clone of the point itself.
*
* @return {ol.geom.Point} The centroid.
*/
ol.geom.Point.prototype.centroid = function() {
return this.getCentroid();
};

View File

@@ -1,11 +0,0 @@
goog.provide('ol.layer.osm');
goog.require('ol.layer.OSM');
/**
* @export
* @return {ol.layer.OSM}
*/
ol.layer.osm = function() {
return new ol.layer.OSM();
};

View File

@@ -1,41 +0,0 @@
goog.provide('ol.layer.wms');
goog.require('ol.layer.WMS');
/**
* @export
* @param {Object} opt_arg Config object.
* @return {ol.layer.WMS}
*/
ol.layer.wms = function(opt_arg) {
if (opt_arg instanceof ol.layer.WMS) {
return opt_arg;
}
/** @type {string} */
var url;
/** @type {Array.<string>} */
var layers;
/** @type {string} */
var format;
if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['url', 'layers', 'format']);
url = ol.API ? opt_arg['url'] : opt_arg.url;
layers = ol.API ? opt_arg['layers'] : opt_arg.layers;
format = ol.API ? opt_arg['format'] : opt_arg.format;
}
var msg;
if (!goog.isDef(url)) {
msg = 'Cannot create WMS layer; option "url" is missing';
ol.error(msg);
}
if (!goog.isArray(layers)) {
msg = 'Cannot create WMS layer; option "layers" is missing, ' +
'or is not an array';
ol.error(msg);
}
return new ol.layer.WMS(url, layers, format);
};

View File

@@ -1,31 +0,0 @@
goog.provide('ol.layer.xyz');
goog.require('ol.layer.XYZ');
/**
* @export
* @param {Object} opt_arg Config object.
* @return {ol.layer.XYZ}
*/
ol.layer.xyz = function(opt_arg) {
if (opt_arg instanceof ol.layer.XYZ) {
return opt_arg;
}
/** @type {string} */
var url;
var usage = 'ol.layer.xyz accepts an object with a "url" property';
if (goog.isObject(opt_arg)) {
url = ol.API ? opt_arg['url'] : opt_arg.url;
} else {
throw new Error(usage);
}
if (!goog.isDef(url)) {
throw new Error(usage);
}
return new ol.layer.XYZ(url);
};

View File

@@ -1,146 +0,0 @@
goog.provide('ol.loc');
goog.require('ol.Loc');
goog.require('ol.projection');
/**
* @typedef {ol.Loc|Array.<number>|Object} loc Location.
*/
ol.LocLike;
/**
* @export
* @param {ol.LocLike} opt_arg Location.
* @return {ol.Loc} Location.
*/
ol.loc = function(opt_arg){
if (opt_arg instanceof ol.Loc) {
return opt_arg;
}
/** @type {number|undefined} */
var x;
/** @type {number|undefined} */
var y;
/** @type {number|undefined} */
var z;
/** @type {Object|undefined} */
var projection;
var usage = 'ol.loc accepts a coordinate array or an object with x, y, and (optional) z properties';
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isArray(opt_arg)) {
x = opt_arg[0];
y = opt_arg[1];
z = opt_arg[2];
projection = opt_arg[3];
} else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['projection', 'x', 'y', 'z']);
x = ol.API ? opt_arg['x'] : opt_arg.x;
y = ol.API ? opt_arg['y'] : opt_arg.y;
z = ol.API ? opt_arg['z'] : opt_arg.z;
projection = ol.API ? opt_arg['projection'] : opt_arg.projection;
} else {
throw new Error(usage);
}
}
if (!goog.isNumber(x) || !goog.isNumber(y)) {
throw new Error(usage);
}
if (goog.isDef(projection)) {
projection = ol.projection(projection);
}
var loc = new ol.Loc(x, y, z, projection);
return loc;
};
/**
* Transform this location to another coordinate reference system. This
* requires that this location has a projection set already (if not, an error
* will be thrown). Returns a new location object and does not modify this
* location.
*
* @export
* @param {string|ol.Projection} proj The destination projection. Can be
* supplied as a projection instance of a string identifier.
* @returns {ol.Loc} A new location.
*/
ol.Loc.prototype.transform = function(proj) {
if (goog.isString(proj)) {
proj = new ol.Projection(proj);
}
return this.doTransform(proj);
};
/**
* @export
* @param {ol.Projection=} opt_arg Projection.
* @return {ol.Loc|ol.Projection|undefined} Result.
*/
ol.Loc.prototype.projection = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setProjection(ol.projection(opt_arg));
}
else {
return this.getProjection();
}
};
/**
* @export
* @param {number=} opt_arg X.
* @return {ol.Loc|number} Result.
*/
ol.Loc.prototype.x = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setX(opt_arg);
return this;
}
else {
return this.getX();
}
};
/**
* @export
* @param {number=} opt_arg Y.
* @return {ol.Loc|number} Result.
*/
ol.Loc.prototype.y = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setY(opt_arg);
return this;
}
else {
return this.getY();
}
};
/**
* @export
* @param {number=} opt_arg Z.
* @return {ol.Loc|number|undefined} Result.
*/
ol.Loc.prototype.z = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
return this.setZ(opt_arg);
}
else {
return this.getZ();
}
};

View File

@@ -1,256 +0,0 @@
goog.provide('ol.map');
goog.require('ol.Loc');
goog.require('ol.Map');
goog.require('ol.Projection');
goog.require('ol.loc');
goog.require('ol.projection');
goog.require('ol.error');
goog.require('goog.dispose');
/**
* @typedef {ol.Map|{center, zoom, numZoomLevels, projection, userProjection, maxExtent, maxResolution, resolutions, renderTo, layers, controls}|string}
*/
ol.MapLike;
/**
* @export
* @param {ol.MapLike=} opt_arg Argument.
* @return {ol.Map} Map.
*/
ol.map = function(opt_arg) {
/** @type {ol.Loc|undefined} */
var center;
/** @type {number|undefined} */
var zoom;
/** @type {number|undefined} */
var numZoomLevels;
/** @type {ol.Projection|undefined} */
var projection;
/** @type {ol.Projection|undefined} */
var userProjection;
/** @type {ol.Bounds|undefined} */
var maxExtent;
/** @type {number|undefined} */
var maxResolution;
/** @type {Array.<number>|undefined} */
var resolutions;
/** @type {Element|string|undefined} */
var renderTo;
/** @type {Array|undefined} */
var layers;
/** @type {Array|undefined} */
var controls;
if (arguments.length == 1) {
if (opt_arg instanceof ol.Map) {
return opt_arg;
}
else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['center', 'zoom', 'numZoomLevels', 'projection', 'userProjection', 'maxExtent', 'maxResolution', 'resolutions', 'renderTo', 'layers', 'controls']);
center = ol.API ? opt_arg['center'] : opt_arg.center;
zoom = ol.API ? opt_arg['zoom'] : opt_arg.zoom;
numZoomLevels = ol.API ? opt_arg['numZoomLevels'] : opt_arg.numZoomLevels;
projection = ol.API ? opt_arg['projection'] : opt_arg.projection;
userProjection = ol.API ? opt_arg['userProjection'] : opt_arg.userProjection;
maxExtent = ol.API ? opt_arg['maxExtent'] : opt_arg.maxExtent;
maxResolution = ol.API ? opt_arg['maxResolution'] : opt_arg.maxResolution;
resolutions = ol.API ? opt_arg['resolutions'] : opt_arg.resolutions;
renderTo = ol.API ? opt_arg['renderTo'] : opt_arg.renderTo;
layers = ol.API ? opt_arg['layers'] : opt_arg.layers;
controls = ol.API ? opt_arg['controls'] : opt_arg.controls;
}
else {
throw new Error('ol.map');
}
}
var map = new ol.Map();
if (goog.isDef(center)) {
map.center(center);
}
if (goog.isDef(zoom)) {
map.setZoom(zoom);
}
if (goog.isDef(numZoomLevels)) {
map.setNumZoomLevels(numZoomLevels);
}
if (goog.isDef(projection)) {
map.setProjection(ol.projection(projection));
}
if (goog.isDef(userProjection)) {
map.setUserProjection(ol.projection(userProjection));
}
if (goog.isDef(maxExtent)) {
map.setMaxExtent(ol.bounds(maxExtent));
}
if (goog.isDef(maxResolution)) {
map.setMaxResolution(maxResolution);
}
if (goog.isDef(resolutions)) {
map.setResolutions(resolutions);
}
if (goog.isDef(layers)) {
map.setLayers(layers);
}
if (goog.isDef(controls)) {
map.setControls(controls);
}
if (goog.isDef(renderTo)) {
map.renderTo(renderTo);
}
return map;
};
/**
* @export
* @param {ol.LocLike=} opt_arg
* @returns {ol.Map|ol.Loc|undefined} Map center.
*/
ol.Map.prototype.center = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
var loc = ol.loc(opt_arg);
var proj = loc.getProjection();
if (goog.isNull(proj)) {
proj = this.getUserProjection();
loc.setProjection(proj);
}
this.setCenter(loc);
return this;
} else {
var proj = this.getUserProjection();
return this.getCenter().doTransform(proj);
}
};
/**
* @export
* @param {ol.ProjectionLike=} opt_arg
* @returns {ol.Map|ol.Projection|undefined}
*/
ol.Map.prototype.projection = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setProjection(ol.projection(opt_arg));
return this;
} else {
return this.getProjection();
}
};
/**
* @export
* @param {ol.ProjectionLike=} opt_arg
* @returns {ol.Map|ol.Projection|undefined}
*/
ol.Map.prototype.userProjection = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setUserProjection(ol.projection(opt_arg));
return this;
} else {
return this.getUserProjection();
}
};
/**
* @export
* @param {number=} opt_arg
* @returns {ol.Map|number|undefined} Map center.
*/
ol.Map.prototype.zoom = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setZoom(opt_arg);
return this;
} else {
return this.getZoom();
}
};
/**
* @export
* @param {number=} opt_arg
* @returns {ol.Map|number|undefined} Map center.
*/
ol.Map.prototype.numZoomLevels = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setNumZoomLevels(opt_arg);
return this;
} else {
return this.getNumZoomLevels();
}
};
/**
* @export
* @param {Array=} opt_arg
* @returns {ol.Map|Array|undefined} Map center.
*/
ol.Map.prototype.resolutions = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setResolutions(opt_arg);
return this;
} else {
return this.getResolutions();
}
};
/**
* @export
* @param {Array=} opt_arg
* @returns {ol.Map|Array|undefined} Map center.
*/
ol.Map.prototype.layers = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setLayers(opt_arg);
return this;
} else {
return this.getLayers();
}
};
/**
* @export
* @param {Array=} opt_arg
* @returns {ol.Map|Array|undefined} Map center.
*/
ol.Map.prototype.controls = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setControls(opt_arg);
return this;
} else {
return this.getControls();
}
};
/**
* @export
* @param {Array=} opt_arg
* @returns {ol.Map|ol.Bounds|undefined} Map max extent.
*/
ol.Map.prototype.maxExtent = function(opt_arg) {
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setMaxExtent(ol.bounds(opt_arg));
return this;
} else {
return this.getMaxExtent();
}
};
/**
* @param {string|Element} arg Render the map to a container
* @returns {ol.Map}
*/
ol.Map.prototype.renderTo = function(arg) {
this.setContainer(goog.dom.getElement(arg));
return this;
};
/**
*/
ol.Map.prototype.destroy = function() {
goog.dispose(this);
};

View File

@@ -1,139 +0,0 @@
goog.provide('ol.popup');
goog.require('ol.Popup');
goog.require('ol.map');
/**
* @typedef {ol.Popup|{map, anchor, placement, content, template}} popup
*/
ol.PopupLike;
/**
* @export
* @param {ol.PopupLike} opt_arg popup object literal.
* @return {ol.Popup} the popup.
*/
ol.popup = function(opt_arg){
if (opt_arg instanceof ol.Popup) {
return opt_arg;
}
/** @type {ol.Map} */
var map;
/** @type {ol.Loc|ol.Feature|undefined} */
var anchor;
/** @type {string|undefined} */
var placement;
/** @type {string|undefined} */
var content;
/** @type {string|undefined} */
var template;
if (arguments.length == 1 && goog.isDef(opt_arg)) {
if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['map', 'anchor', 'placement', 'content', 'template']);
map = ol.API ? opt_arg['map'] : opt_arg.map;
anchor = ol.API ? opt_arg['anchor'] : opt_arg.anchor;
placement = ol.API ? opt_arg['placement'] : opt_arg.placement;
content = ol.API ? opt_arg['content'] : opt_arg.content;
template = ol.API ? opt_arg['template'] : opt_arg.template;
}
}
var popup = new ol.Popup(map, anchor);
if (goog.isDef(anchor)) {
popup.setAnchor(anchor);
}
if (goog.isDef(placement)) {
popup.setPlacement(placement);
}
if (goog.isDef(content)) {
popup.setContent(content);
}
if (goog.isDef(template)) {
popup.setTemplate(template);
}
return popup;
};
/**
* @export
* @param {ol.Loc|ol.Feature=} opt_arg a feature or a location.
* @return {ol.Popup|ol.Feature|ol.Loc|undefined} Result.
*/
ol.Popup.prototype.anchor = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setAnchor(opt_arg);
return this;
}
else {
return this.getAnchor();
}
};
/**
* @export
* @param {ol.Map=} opt_arg the map .
* @return {ol.Popup|ol.Map|undefined} the map or the popup.
*/
ol.Popup.prototype.map = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setMap(opt_arg);
return this;
}
else {
return this.getMap();
}
};
/**
* @export
* @param {string=} opt_arg the content for the map (HTML makrkup)
* @return {ol.Popup|string|undefined} the content or the popup.
*/
ol.Popup.prototype.content = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setContent(opt_arg);
return this;
}
else {
return this.getContent();
}
};
/**
* @export
* @param {string=} opt_arg the template to be used to generate the content
* @return {ol.Popup|string|undefined} the template or the popup.
*/
ol.Popup.prototype.template = function(opt_arg){
if (arguments.length == 1 && goog.isDef(opt_arg)) {
this.setTemplate(opt_arg);
return this;
}
else {
return this.getTemplate();
}
};
/**
* Open the popup.
* @export
* @param {ol.Feature|ol.Loc} opt_arg feature or location for the anchor
*/
ol.Popup.prototype.open = function(opt_arg) {
this.doOpen(opt_arg);
};

View File

@@ -1,88 +0,0 @@
goog.provide('ol.projection');
goog.require('ol.base');
goog.require('ol.Projection');
/**
* @typedef {ol.Projection|Object|string}
*/
ol.ProjectionLike;
/**
* @export
* @param {ol.ProjectionLike=} opt_arg Argument.
* @return {ol.Projection} Projection.
*/
ol.projection = function(opt_arg){
/** @type {string} */
var code;
/** @type {undefined|number} */
var units;
/** @type {undefined|Array|ol.UnreferencedBounds} */
var extent;
if (arguments.length == 1 && goog.isDefAndNotNull(opt_arg)) {
if (opt_arg instanceof ol.Projection) {
return opt_arg;
}
else if (goog.isString(opt_arg)) {
code = opt_arg;
}
else if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['code', 'maxExtent', 'units']);
if (goog.isString(ol.API ? opt_arg['code'] : opt_arg.code)) {
code = ol.API ? opt_arg['code'] : opt_arg.code;
} else {
throw new Error('Projection requires a string code.');
}
units = ol.API ? opt_arg['units'] : opt_arg.units;
extent = ol.API ? opt_arg['maxExtent'] : opt_arg.maxExtent;
}
else {
throw new Error('ol.projection');
}
}
var proj = new ol.Projection(code);
if (goog.isDef(units)) {
proj.setUnits(units);
}
if (goog.isDef(extent)) {
proj.setExtent(
new ol.UnreferencedBounds(extent[0],extent[1],extent[2],extent[3])
);
}
return proj;
};
/**
* @export
* @param {string=} opt_code Code.
* @return {!ol.Projection|string} Result.
*/
ol.Projection.prototype.code = function(opt_code){
if (arguments.length == 1 && goog.isDef(opt_code)) {
this.setCode(opt_code);
return this;
}
else {
return this.getCode();
}
};
/**
* @export
* @param {string=} opt_units Units abbreviation.
* @return {undefined|!ol.Projection|string} Result.
*/
ol.Projection.prototype.units = function(opt_units){
if (goog.isDef(opt_units)) {
return this.setUnits(opt_units);
}
else {
return this.getUnits();
}
};

View File

@@ -1,132 +0,0 @@
goog.require("ol");
// ol.map
goog.exportSymbol('ol.map', ol.map );
goog.exportSymbol('ol.Map', ol.Map );
goog.exportProperty( ol.Map.prototype, 'renderTo', ol.Map.prototype.renderTo );
goog.exportProperty( ol.Map.prototype, 'center', ol.Map.prototype.center );
goog.exportProperty( ol.Map.prototype, 'projection', ol.Map.prototype.projection );
goog.exportProperty( ol.Map.prototype, 'userProjection', ol.Map.prototype.userProjection );
goog.exportProperty( ol.Map.prototype, 'zoom', ol.Map.prototype.zoom );
goog.exportProperty( ol.Map.prototype, 'numZoomLevels', ol.Map.prototype.numZoomLevels );
goog.exportProperty( ol.Map.prototype, 'resolutions', ol.Map.prototype.resolutions );
goog.exportProperty( ol.Map.prototype, 'layers', ol.Map.prototype.layers );
goog.exportProperty( ol.Map.prototype, 'controls', ol.Map.prototype.controls );
goog.exportProperty( ol.Map.prototype, 'maxExtent', ol.Map.prototype.maxExtent );
goog.exportProperty( ol.Map.prototype, 'destroy', ol.Map.prototype.destroy );
// ol.loc
goog.exportSymbol('ol.loc', ol.loc );
goog.exportSymbol('ol.Loc', ol.Loc ); // This is not required only for the tests with isInstanceOf
goog.exportProperty( ol.Loc.prototype, 'projection', ol.Loc.prototype.projection );
goog.exportProperty( ol.Loc.prototype, 'x', ol.Loc.prototype.x );
goog.exportProperty( ol.Loc.prototype, 'y', ol.Loc.prototype.y );
goog.exportProperty( ol.Loc.prototype, 'z', ol.Loc.prototype.z );
goog.exportProperty( ol.Loc.prototype, 'transform', ol.Loc.prototype.transform );
goog.exportProperty( ol.Loc.prototype, 'destroy', ol.Loc.prototype.destroy );
// ol.projection
goog.exportSymbol('ol.projection', ol.projection );
goog.exportSymbol('ol.Projection', ol.Projection );
goog.exportProperty( ol.Projection.prototype, 'code', ol.Projection.prototype.code );
goog.exportProperty( ol.Projection.prototype, 'units', ol.Projection.prototype.units );
// ol.bounds
goog.exportSymbol('ol.bounds', ol.bounds );
goog.exportSymbol('ol.Bounds', ol.Bounds );
goog.exportProperty( ol.Bounds.prototype, 'projection', ol.Bounds.prototype.projection );
goog.exportProperty( ol.Bounds.prototype, 'minX', ol.Bounds.prototype.minX );
goog.exportProperty( ol.Bounds.prototype, 'minY', ol.Bounds.prototype.minY );
goog.exportProperty( ol.Bounds.prototype, 'maxX', ol.Bounds.prototype.maxX );
goog.exportProperty( ol.Bounds.prototype, 'maxY', ol.Bounds.prototype.maxY );
// ol.layer.xyz
goog.exportSymbol('ol.layer.xyz', ol.layer.xyz);
goog.exportSymbol('ol.layer.XYZ', ol.layer.XYZ);
// ol.layer.osm
goog.exportSymbol('ol.layer.osm', ol.layer.osm);
goog.exportSymbol('ol.layer.OSM', ol.layer.OSM);
// ol.layer.wms
goog.exportSymbol('ol.layer.wms', ol.layer.wms);
goog.exportSymbol('ol.layer.WMS', ol.layer.WMS);
// ol.feature
goog.exportSymbol('ol.feature', ol.feature);
goog.exportSymbol('ol.Feature', ol.Feature);
goog.exportProperty(ol.Feature.prototype, 'set', ol.Feature.prototype.set);
goog.exportProperty(ol.Feature.prototype, 'get', ol.Feature.prototype.get);
goog.exportProperty(ol.Feature.prototype, 'geometry', ol.Feature.prototype.geometry);
// ol.geometry
goog.exportSymbol('ol.geom.geometry', ol.geom.geometry);
goog.exportSymbol('ol.geom.Geometry', ol.geom.Geometry);
goog.exportProperty(ol.geom.Geometry.prototype, 'bounds', ol.geom.Geometry.prototype.bounds);
goog.exportProperty(ol.geom.Geometry.prototype, 'centroid', ol.geom.Geometry.prototype.centroid);
// ol.geom.collection
goog.exportSymbol('ol.geom.collection', ol.geom.collection);
goog.exportSymbol('ol.geom.Collection', ol.geom.Collection);
goog.exportProperty(ol.geom.Collection.prototype, 'components', ol.geom.Collection.prototype.components);
goog.exportProperty(ol.geom.Collection.prototype, 'add', ol.geom.Collection.prototype.add);
goog.exportProperty(ol.geom.Collection.prototype, 'addAll', ol.geom.Collection.prototype.addAll);
goog.exportProperty(ol.geom.Collection.prototype, 'remove', ol.geom.Collection.prototype.remove);
goog.exportProperty(ol.geom.Collection.prototype, 'centroid', ol.geom.Collection.prototype.centroid);
// ol.geom.point
goog.exportSymbol('ol.geom.point', ol.geom.point);
goog.exportSymbol('ol.geom.Point', ol.geom.Point);
goog.exportProperty(ol.geom.Point.prototype, 'x', ol.geom.Point.prototype.x);
goog.exportProperty(ol.geom.Point.prototype, 'y', ol.geom.Point.prototype.y);
goog.exportProperty(ol.geom.Point.prototype, 'z', ol.geom.Point.prototype.z);
goog.exportProperty(ol.geom.Point.prototype, 'projection', ol.geom.Point.prototype.projection);
goog.exportProperty(ol.geom.Point.prototype, 'centroid', ol.geom.Point.prototype.centroid);
// ol.geom.linestring
goog.exportSymbol('ol.geom.linestring', ol.geom.linestring);
goog.exportSymbol('ol.geom.LineString', ol.geom.LineString);
goog.exportProperty(ol.geom.LineString.prototype, 'vertices', ol.geom.LineString.prototype.vertices);
goog.exportProperty(ol.geom.LineString.prototype, 'add', ol.geom.LineString.prototype.add);
goog.exportProperty(ol.geom.LineString.prototype, 'addAll', ol.geom.LineString.prototype.addAll);
goog.exportProperty(ol.geom.LineString.prototype, 'remove', ol.geom.LineString.prototype.remove);
goog.exportProperty(ol.geom.LineString.prototype, 'centroid', ol.geom.LineString.prototype.centroid);
// ol.geom.multipoint
goog.exportSymbol('ol.geom.multipoint', ol.geom.multipoint);
goog.exportSymbol('ol.geom.MultiPoint', ol.geom.MultiPoint);
goog.exportProperty(ol.geom.MultiPoint.prototype, 'points', ol.geom.MultiPoint.prototype.points);
goog.exportProperty(ol.geom.MultiPoint.prototype, 'add', ol.geom.MultiPoint.prototype.add);
goog.exportProperty(ol.geom.MultiPoint.prototype, 'addAll', ol.geom.MultiPoint.prototype.addAll);
goog.exportProperty(ol.geom.MultiPoint.prototype, 'remove', ol.geom.MultiPoint.prototype.remove);
goog.exportProperty(ol.geom.MultiPoint.prototype, 'centroid', ol.geom.MultiPoint.prototype.centroid);
// ol.geom.multilinestring
goog.exportSymbol('ol.geom.multilinestring', ol.geom.multilinestring);
goog.exportSymbol('ol.geom.MultiLineString', ol.geom.MultiLineString);
goog.exportProperty(ol.geom.MultiLineString.prototype, 'linestrings', ol.geom.MultiLineString.prototype.linestrings);
goog.exportProperty(ol.geom.MultiLineString.prototype, 'add', ol.geom.MultiLineString.prototype.add);
goog.exportProperty(ol.geom.MultiLineString.prototype, 'addAll', ol.geom.MultiLineString.prototype.addAll);
goog.exportProperty(ol.geom.MultiLineString.prototype, 'remove', ol.geom.MultiLineString.prototype.remove);
goog.exportProperty(ol.geom.MultiLineString.prototype, 'centroid', ol.geom.MultiLineString.prototype.centroid);
// ol.popup
goog.exportSymbol('ol.popup', ol.popup);
goog.exportSymbol('ol.Popup', ol.Popup);
goog.exportProperty(ol.Popup.prototype, 'anchor', ol.Popup.prototype.anchor);
goog.exportProperty(ol.Popup.prototype, 'map', ol.Popup.prototype.map);
goog.exportProperty(ol.Popup.prototype, 'content', ol.Popup.prototype.content);
goog.exportProperty(ol.Popup.prototype, 'template', ol.Popup.prototype.template);
goog.exportProperty(ol.Popup.prototype, 'open', ol.Popup.prototype.open);
/**
* Lookup for dynamically registered controls and renderers does not work in
* advanced compiled mode. For now, we duplicate the registration calls here.
*
* TODO: determine a good way for plugins to register
*/
goog.exportProperty(ol.renderer.Composite, 'isSupported', ol.renderer.Composite.isSupported);
goog.exportProperty(ol.renderer.TileLayerRenderer, 'isSupported', ol.renderer.TileLayerRenderer.isSupported);
goog.exportProperty(ol.renderer.TileLayerRenderer, 'canRender', ol.renderer.TileLayerRenderer.canRender);
goog.exportProperty(ol.renderer.TileLayerRenderer, 'getType', ol.renderer.TileLayerRenderer.getType);

View File

@@ -1,32 +0,0 @@
goog.provide("ol");
goog.require('ol.base');
goog.require('ol.bounds');
goog.require('ol.control.Attribution');
goog.require('ol.control.Zoom');
goog.require('ol.handler.Drag');
goog.require('ol.handler.MouseWheel');
goog.require('ol.handler.Click');
goog.require("ol.map");
goog.require("ol.loc");
goog.require("ol.feature");
goog.require("ol.projection");
goog.require("ol.layer.xyz");
goog.require("ol.layer.osm");
goog.require("ol.layer.wms");
goog.require("ol.popup");
goog.require("ol.Tile");
goog.require("ol.TileSet");
goog.require("ol.TileCache");
goog.require("ol.geom.geometry");
goog.require("ol.geom.point");
goog.require("ol.geom.multipoint");
goog.require("ol.geom.linestring");
goog.require("ol.geom.multilinestring");
goog.require("ol.geom.collection");
goog.require('ol.layer.XYZ');
goog.require('ol.layer.OSM');
goog.require('ol.layer.WMS');
goog.require('ol.renderer.Composite');
goog.require('ol.renderer.TileLayerRenderer');
goog.require('ol.renderer.WebGL');

View File

@@ -1,105 +0,0 @@
goog.provide('ol.Bounds');
goog.require('ol.UnreferencedBounds');
goog.require('ol.Loc');
goog.require('ol.Projection');
goog.require('goog.string.format');
/**
* @export
* @constructor
* @param {number} minX Minimum X.
* @param {number} minY Minimum Y.
* @param {number} maxX Maximum X.
* @param {number} maxY Maximum Y.
* @param {ol.Projection=} opt_projection Projection.
* @extends {ol.UnreferencedBounds}
*/
ol.Bounds = function(minX, minY, maxX, maxY, opt_projection) {
goog.base(this, minX, minY, maxX, maxY);
/**
* @protected
* @type {ol.Projection}
*/
this.projection_ = goog.isDef(opt_projection) ? opt_projection : null;
};
goog.inherits(ol.Bounds, ol.UnreferencedBounds);
/**
* @return {ol.Projection} Projection.
*/
ol.Bounds.prototype.getProjection = function() {
return this.projection_;
};
/**
* @param {ol.Projection} projection Projection.
*/
ol.Bounds.prototype.setProjection = function(projection) {
this.projection_ = projection;
};
/**
* Determine if this bounds intersects the target bounds (bounds that only
* touch are considered intersecting).
*
* @param {ol.Bounds} bounds Target bounds.
* @return {boolean} The provided bounds intersects this bounds.
*/
ol.Bounds.prototype.intersects = function(bounds) {
var otherProj = bounds.getProjection();
if (!goog.isNull(otherProj) && !goog.isNull(this.projection_)) {
bounds = bounds.doTransform(this.projection_);
}
return goog.base(this, "intersects", bounds.toUnreferencedBounds());
};
/**
* Transform this node into another coordinate reference system. Returns a new
* bounds instead of modifying this bounds.
*
* @param {ol.Projection} proj Target projection.
* @return {ol.Bounds} A new bounds in the target projection.
*/
ol.Bounds.prototype.doTransform = function(proj) {
if (goog.isNull(this.projection_)) {
throw new Error("Bounds must have a projection before transforming.");
}
var tl = new ol.Loc(
this.minX_, this.maxY_, undefined, this.projection_).doTransform(proj);
var tr = new ol.Loc(
this.maxX_, this.maxY_, undefined, this.projection_).doTransform(proj);
var bl = new ol.Loc(
this.minX_, this.minY_, undefined, this.projection_).doTransform(proj);
var br = new ol.Loc(
this.maxX_, this.minY_, undefined, this.projection_).doTransform(proj);
var x = [tl.getX(), tr.getX(), bl.getX(), br.getX()].sort();
var y = [tl.getY(), tr.getY(), bl.getY(), br.getY()].sort();
return new ol.Bounds(x[0], y[0], x[3], y[3], proj);
};
/**
* Return a bbox string for this bounds.
*
* @return {string} The "minx,miny,maxx,maxy" representation of this bounds.
*/
ol.Bounds.prototype.toBBOX = function() {
return goog.string.format(
'%f,%f,%f,%f', this.minX_, this.minY_, this.maxX_, this.maxY_);
};
/**
* Cast this bounds into an unreferenced bounds.
*
* @returns {ol.UnreferencedBounds}
*/
ol.Bounds.prototype.toUnreferencedBounds = function() {
return new ol.UnreferencedBounds(
this.getMinX(), this.getMinY(), this.getMaxX(), this.getMaxY());
};

View File

@@ -1,77 +0,0 @@
goog.provide('ol.Feature');
goog.require('ol.geom.Geometry');
/**
* @export
* @constructor
*/
ol.Feature = function() {
/**
* @private
* @type {ol.geom.Geometry}
*/
this.geometry_ = null;
/**
* @private
* @type {Object}
*/
this.attributes_ = {};
};
/**
* @return {ol.geom.Geometry} The geometry associated with the feature.
*/
ol.Feature.prototype.getGeometry = function() {
return this.geometry_;
};
/**
* @param {ol.geom.Geometry} geom the geometry for the feature.
*/
ol.Feature.prototype.setGeometry = function(geom) {
this.geometry_ = geom;
};
/**
* @param {!string} name the attribute value to retrieve.
@return {string|number|boolean} the attribute value.
*/
ol.Feature.prototype.getAttribute = function(name) {
return this.attributes_[name];
};
/**
* @param {!string} name of the attribute to set.
* @param {string|number|boolean} value the attribute value to set.
*/
ol.Feature.prototype.setAttribute = function(name, value) {
this.attributes_[name] = value;
};
/**
* @param {Object} attrs An json structure containing key/value pairs.
*/
ol.Feature.prototype.setAttributes = function(attrs) {
for (var key in attrs) {
this.setAttribute(key, attrs[key]);
}
};
/**
*/
ol.Feature.prototype.destroy = function() {
//remove attributes and geometry, etc.
for (var key in this) {
delete this[key];
}
};

View File

@@ -1,147 +0,0 @@
goog.provide('ol.Loc');
goog.require('ol.Projection');
/**
* @export
* @constructor
* @param {number} x X.
* @param {number} y Y.
* @param {number=} opt_z Z.
* @param {ol.Projection=} opt_projection Projection.
*/
ol.Loc = function(x, y, opt_z, opt_projection) {
/**
* @private
* @type {number}
*/
this.x_ = x;
/**
* @private
* @type {number}
*/
this.y_ = y;
/**
* @private
* @type {number|undefined}
*/
this.z_ = opt_z;
/**
* @private
* @type {ol.Projection}
*/
this.projection_ = goog.isDef(opt_projection) ? opt_projection : null;
};
/**
* @return {ol.Projection|undefined} Projection.
*/
ol.Loc.prototype.getProjection = function() {
return this.projection_;
};
/**
* @return {number} X.
*/
ol.Loc.prototype.getX = function() {
return this.x_;
};
/**
* @return {number} Y.
*/
ol.Loc.prototype.getY = function() {
return this.y_;
};
/**
* @return {number|undefined} Z.
*/
ol.Loc.prototype.getZ = function() {
return this.z_;
};
/**
* @param {ol.Projection} projection Projection.
*/
ol.Loc.prototype.setProjection = function(projection) {
this.projection_ = projection;
};
/**
* @param {number} x X.
*/
ol.Loc.prototype.setX = function(x) {
this.x_ = x;
};
/**
* @param {number} y Y.
*/
ol.Loc.prototype.setY = function(y) {
this.y_ = y;
};
/**
* @param {number|undefined} z Z.
*/
ol.Loc.prototype.setZ = function(z) {
this.z_ = z;
};
/**
* Transform this location to a new location given a projection object.
*
* @param {ol.Projection} proj The destination projection.
* @returns {ol.Loc}
*/
ol.Loc.prototype.doTransform = function(proj) {
var point = {'x': this.x_, 'y': this.y_};
var sourceProj = this.projection_;
if (!goog.isDefAndNotNull(sourceProj)) {
throw new Error("Cannot transform a location without a source projection.");
}
ol.Projection.transform(point, sourceProj, proj);
return new ol.Loc(point['x'], point['y'], this.z_, proj);
};
/**
* Adds the passed x, y(, z) delta to a new location.
*
* @param {number} x
* @param {number} y
* @param {number=} opt_z
* @returns {ol.Loc}
*/
ol.Loc.prototype.add = function(x, y, opt_z) {
var newZ;
if (goog.isDef(this.z_)) {
newZ = (opt_z || 0) + this.z_;
}
return new ol.Loc(this.x_ + x, this.y_ + y, newZ, this.projection_);
};
/**
* Clean up.
* @export
*/
ol.Loc.prototype.destroy = function() {
for (var key in this) {
delete this[key];
}
};

View File

@@ -1,625 +0,0 @@
goog.provide('ol.Map');
goog.require('ol.Loc');
goog.require('ol.Bounds');
goog.require('ol.Projection');
goog.require('ol.control.Control');
goog.require('ol.renderer.MapRenderer');
goog.require('ol.handler.Drag');
goog.require('ol.handler.MouseWheel');
goog.require('ol.handler.Click');
goog.require('goog.dom');
goog.require('goog.math');
goog.require('goog.asserts');
goog.require('goog.events.EventTarget');
/**
* @define {boolean} Whether to enable the drag handler.
*/
ol.ENABLE_DRAG_HANDLER = true;
/**
* @define {boolean} Whether to enable the mousewheel handler.
*/
ol.ENABLE_MOUSEWHEEL_HANDLER = true;
/**
* @define {boolean} Whether to enable the click handler.
*/
ol.ENABLE_CLICK_HANDLER = true;
/**
* @export
* @constructor
* @extends {goog.events.EventTarget}
*
* @event layeradd Fires when a layer is added to the map. The event object
* contains a 'layer' property referencing the added layer.
*/
ol.Map = function() {
goog.base(this);
/**
* @private
* @type {ol.Projection}
*/
this.projection_ = null;
/**
* @private
* @type {ol.Projection}
*/
this.userProjection_ = null;
/**
* @private
* @type {ol.Loc}
*/
this.center_ = null;
/**
* @private
* @type {number|undefined}
*/
this.zoom_ = undefined;
/**
* @private
* @type {number}
*/
this.numZoomLevels_ = 22;
/**
* @private
* @type {Array}
*/
this.resolutions_ = null;
/**
* @private
* @type {Array}
*/
this.layers_ = null;
/**
* @private
* @type {Array}
*/
this.controls_ = null;
/**
* @private
* @type {ol.Bounds}
*/
this.maxExtent_ = null;
/**
* @private
* @type {number|undefined}
*/
this.maxResolution_ = undefined;
/**
* @private
* @type {Element}
*/
this.viewport_ = null;
/**
* @private
* @type {goog.math.Size}
*/
this.viewportSize_ = null;
/**
* @private
* @type {Node}
*/
this.mapOverlay_ = null;
/**
* @private
* @type {Node}
*/
this.staticOverlay_ = null;
/**
* @private
* @type {Element}
*/
this.container_ = null;
};
goog.inherits(ol.Map, goog.events.EventTarget);
/**
@const
@type {string}
*/
ol.Map.prototype.DEFAULT_PROJECTION = "EPSG:3857";
/**
@const
@type {string}
*/
ol.Map.prototype.DEFAULT_USER_PROJECTION = "EPSG:4326";
/**
@const
@type {number}
*/
ol.Map.ZOOM_FACTOR = 2;
/**
@const
@type {number}
*/
ol.Map.DEFAULT_TILE_SIZE = 256;
/**
@const
@type {Array.<string>}
*/
ol.Map.DEFAULT_CONTROLS = ["attribution", "zoom"];
/**
* @return {ol.Loc} Map center in map projection.
*/
ol.Map.prototype.getCenter = function() {
return this.center_;
};
/**
* @return {!ol.Projection} Projection.
*/
ol.Map.prototype.getProjection = function() {
if (goog.isNull(this.projection_)) {
this.projection_ = new ol.Projection(this.DEFAULT_PROJECTION);
}
return this.projection_;
};
/**
* @return {!ol.Projection} User projection.
*/
ol.Map.prototype.getUserProjection = function() {
if (goog.isNull(this.userProjection_)) {
this.userProjection_ = new ol.Projection(this.DEFAULT_USER_PROJECTION);
}
return this.userProjection_;
};
/**
* @return {number|undefined} Zoom.
*/
ol.Map.prototype.getZoom = function() {
return this.zoom_;
};
/**
* @return {number} number of zoom levels.
*/
ol.Map.prototype.getNumZoomLevels = function() {
return this.numZoomLevels_;
};
/**
* @return {Array|undefined} array of resolutions available for this map
*/
ol.Map.prototype.getResolutions = function() {
return this.resolutions_;
};
/**
* @return {Array|undefined} array of layers available for this map
*/
ol.Map.prototype.getLayers = function() {
return this.layers_;
};
/**
* @return {Array.<ol.control.Control>}
*/
ol.Map.prototype.getControls = function() {
return this.controls_;
};
/**
* @return {ol.Bounds} the maxExtent for the map
*/
ol.Map.prototype.getMaxExtent = function() {
if (goog.isDefAndNotNull(this.maxExtent_)) {
return this.maxExtent_;
} else {
var projection = this.getProjection();
var extent = projection.getExtent();
if (goog.isDefAndNotNull(extent)) {
extent = new ol.Bounds(
extent.getMinX(), extent.getMinY(),
extent.getMaxX(), extent.getMaxY());
extent.setProjection(projection);
return extent;
} else {
throw('maxExtent must be defined either in the map or the projection');
}
}
};
/**
* @return {number} the max resolution for the map
*/
ol.Map.prototype.getMaxResolution = function() {
if (goog.isDefAndNotNull(this.maxResolution_)) {
return this.maxResolution_;
} else {
var extent = this.getMaxExtent();
var dim = Math.max(
(extent.getMaxX()-extent.getMinX()),
(extent.getMaxY()-extent.getMinY())
);
return dim/ol.Map.DEFAULT_TILE_SIZE;
}
};
/**
* @param {number} zoom the zoom level being requested
* @return {number} the resolution for the map at the given zoom level
*/
ol.Map.prototype.getResolutionForZoom = function(zoom) {
if (goog.isDefAndNotNull(this.resolutions_)) {
return this.resolutions_[zoom];
} else {
var maxResolution = this.getMaxResolution();
return maxResolution/Math.pow(ol.Map.ZOOM_FACTOR, zoom);
}
};
/**
* @return {number} the resolution for the map at the given zoom level
*/
ol.Map.prototype.getResolution = function() {
goog.asserts.assert(goog.isDef(this.renderer_));
return this.renderer_.getResolution();
};
/**
* TODO: We'll have to ask the map overlay renderer for this. This method will
* not work once map space is not aligned with pixel space.
*
* @param {goog.math.Coordinate|{x: number, y: number}} pixel
* @return {ol.Loc}
*/
ol.Map.prototype.getLocForViewportPixel = function(pixel) {
var size = this.getViewportSize();
var center = this.center_;
var resolution = this.getResolution();
var x = center.getX() + (resolution * (pixel.x - (size.width / 2)));
var y = center.getY() - (resolution * (pixel.y - (size.height / 2)));
return new ol.Loc(x, y, undefined, this.getProjection());
};
/**
* TODO: We'll have to ask the map overlay renderer for this. This method will
* not work once map space is not aligned with pixel space.
*
* @param {ol.Loc} loc
* @return {{x: number, y: number}}
*/
ol.Map.prototype.getViewportPixelForLoc = function(loc) {
var size = this.getViewportSize();
var center = this.center_;
var resolution = this.getResolution();
return {
x: ((loc.getX() - center.getX()) / resolution) + (size.width / 2),
y: ((center.getY() - loc.getY()) / resolution) + (size.height / 2)
};
};
/**
* @return {goog.math.Size}
*/
ol.Map.prototype.getViewportSize = function() {
// TODO: listen for resize and set this.viewportSize_ null
// https://github.com/openlayers/ol3/issues/2
if (goog.isNull(this.viewportSize_)) {
this.viewportSize_ = goog.style.getSize(this.viewport_);
}
return this.viewportSize_;
};
/**
* @param {ol.Loc} center Center in map projection.
*/
ol.Map.prototype.setCenter = function(center) {
goog.asserts.assert(!goog.isNull(center.getProjection()));
this.center_ = center.doTransform(this.getProjection());
this.conditionallyRender();
};
/**
* @param {ol.Loc} center
* @param {number} zoom
*/
ol.Map.prototype.setCenterAndZoom = function(center, zoom) {
goog.asserts.assert(!goog.isNull(center.getProjection()));
this.center_ = center.doTransform(this.getProjection());
this.zoom_ = this.limitZoom(zoom);
this.conditionallyRender();
};
/**
* @param {number} zoom The zoom level to zoom to
* @param {goog.math.Coordinate|{x: number, y: number}=} opt_anchor
* Optional anchor pixel for the zoom origin.
*/
ol.Map.prototype.setZoom = function(zoom, opt_anchor) {
var currentZoom = this.zoom_,
newZoom = this.limitZoom(zoom),
newCenter;
if (newZoom === currentZoom) {
return;
}
if (goog.isDef(opt_anchor)) {
var size = this.getViewportSize(),
anchorLoc = this.getLocForViewportPixel(opt_anchor),
newRes = this.getResolutionForZoom(newZoom);
newCenter = anchorLoc.add(
(size.width/2 - opt_anchor.x) * newRes,
(opt_anchor.y - size.height/2) * newRes
);
} else {
newCenter = this.center_;
}
this.setCenterAndZoom(newCenter, newZoom);
};
/**
* @param {ol.Projection} projection Projection.
*/
ol.Map.prototype.setProjection = function(projection) {
this.projection_ = projection;
};
/**
* @param {ol.Projection} userProjection set the user projection.
*/
ol.Map.prototype.setUserProjection = function(userProjection) {
this.userProjection_ = userProjection;
};
/**
* @param {number} zoom
* @return {number} zoom clamped to the range of available zoom levels.
*/
ol.Map.prototype.limitZoom = function(zoom) {
return goog.math.clamp(zoom, 0, this.getNumZoomLevels()-1);
};
/**
* @param {number} nZoom Zoom.
*/
ol.Map.prototype.setNumZoomLevels = function(nZoom) {
this.numZoomLevels_ = nZoom;
};
/**
* @param {Array} resolutions the map resolutions if set on the map
*/
ol.Map.prototype.setResolutions = function(resolutions) {
this.resolutions_ = resolutions;
};
/**
* @param {Array} layers the layers set on the map
*/
ol.Map.prototype.setLayers = function(layers) {
//TODO remove layers properly if there are layers already
this.layers_ = [];
this.addLayers(layers);
};
ol.Map.prototype.addLayers = function(layers) {
var layer;
for (var i=0, ii=layers.length; i<ii; ++i) {
layer = layers[i];
this.layers_.push(layer);
goog.events.dispatchEvent(this, {type: 'layeradd', 'layer': layer});
}
this.conditionallyRender();
};
/**
* @param {Array.<ol.control.Control>|undefined} opt_controls
*/
ol.Map.prototype.setControls = function(opt_controls) {
if (!this.controls_) {
var control;
for (var i=0, ii=opt_controls.length; i<ii; ++i) {
control = opt_controls[i];
if (!(control instanceof ol.control.Control)) {
control = new ol.control.CONTROL_MAP[control]();
}
control.setMap(this);
}
this.controls_ = opt_controls;
}
};
/**
* @param {ol.Bounds} extent the maxExtent for the map
*/
ol.Map.prototype.setMaxExtent = function(extent) {
this.maxExtent_ = extent;
};
/**
* @param {number} maxResolution the max resolution for the map
*/
ol.Map.prototype.setMaxResolution = function(maxResolution) {
this.maxResolution_ = maxResolution;
};
/**
* @param {Element} container the container to render the map to
*/
ol.Map.prototype.setContainer = function(container) {
this.container_ = container;
this.setViewport();
this.createRenderer();
//TODO Controls could be set earlier, but we need to deal with content that
// controls place on overlays.
this.setControls(ol.Map.DEFAULT_CONTROLS);
// conditionally render
this.conditionallyRender();
};
/**
* Check if everything is ready. Render if so.
*/
ol.Map.prototype.conditionallyRender = function() {
if (goog.isDef(this.renderer_) && !goog.isNull(this.layers_) &&
goog.isDef(this.zoom_) && !goog.isNull(this.center_)) {
this.renderer_.draw(this.layers_, this.center_,
this.getResolutionForZoom(this.zoom_)
);
}
};
/**
* @return {Element}
*/
ol.Map.prototype.getViewport = function() {
return this.viewport_;
};
ol.Map.prototype.setViewport = function() {
if (!this.viewport_) {
this.viewport_ = /** @type {Element} */ (goog.dom.createDom('div', {
'class': 'ol-viewport',
'style': 'width:100%;height:100%;top:0;left:0;position:relative;overflow:hidden'
}));
this.initHandlers();
}
goog.dom.appendChild(this.container_, this.viewport_);
};
/**
* Init the map event handlers.
*/
ol.Map.prototype.initHandlers = function() {
goog.asserts.assert(!goog.isNull(this.viewport_));
var handler,
states = /** @type {ol.handler.states} */ ({});
if (ol.ENABLE_DRAG_HANDLER) {
handler = new ol.handler.Drag(this, states);
this.registerDisposable(handler);
}
if (ol.ENABLE_MOUSEWHEEL_HANDLER) {
handler = new ol.handler.MouseWheel(this, states);
this.registerDisposable(handler);
}
if (ol.ENABLE_CLICK_HANDLER) {
handler = new ol.handler.Click(this, states);
this.registerDisposable(handler);
}
};
ol.Map.prototype.createRenderer = function() {
var Renderer = ol.renderer.MapRenderer.pickRendererType(
ol.Map.preferredRenderers);
this.renderer_ = new Renderer(this.viewport_);
//TODO Consider making a renderer responsible for managing the overlays
var viewport = this.viewport_;
if (!this.mapOverlay_ && !this.staticOverlay_) {
var staticCls = 'ol-overlay-static';
this.mapOverlay_ = goog.dom.createDom('div', 'ol-overlay-map');
this.staticOverlay_ = goog.dom.createDom('div', {
'class': staticCls,
'style': 'width:100%;height:100%;top:0;left:0;position:absolute;z-index:1'
});
}
if (!goog.isNull(viewport)) {
goog.dom.append(viewport, this.mapOverlay_, this.staticOverlay_);
}
};
/**
* TODO: This method will need to be reworked/revisited when renderers can
* display a map that is rotated or otherwise not aligned with pixel space.
*
* @param {number} dx pixels to move in x direction
* @param {number} dy pixels to move in x direction
*/
ol.Map.prototype.moveByViewportPx = function(dx, dy) {
if (!goog.isNull(this.center_) && goog.isDef(this.zoom_)) {
var resolution = this.getResolutionForZoom(this.zoom_),
center = new ol.Loc(
this.center_.getX() - dx * resolution,
this.center_.getY() + dy * resolution
);
center.setProjection(this.getProjection());
this.setCenter(center);
}
};
ol.Map.prototype.zoomIn = function() {
this.setZoom(this.zoom_+1);
};
ol.Map.prototype.zoomOut = function() {
this.setZoom(this.zoom_-1);
};
/**
* @returns {Node} the map overlay element
*/
ol.Map.prototype.getMapOverlay = function() {
return this.mapOverlay_;
};
/**
* @returns {Node} the static overlay element
*/
ol.Map.prototype.getStaticOverlay = function() {
return this.staticOverlay_;
};
/**
* @inheritDoc
*/
ol.Map.prototype.disposeInternal = function() {
goog.base(this, 'disposeInternal');
//remove layers, etc.
for (var key in this) {
delete this[key];
}
};
/**
* List of preferred renderer types. Map renderers have a getType method
* that returns a string describing their type. This list determines the
* preferences for picking a layer renderer.
*
* @type {Array.<string>}
*/
ol.Map.preferredRenderers = ["webgl", "canvas"];

View File

@@ -1,343 +0,0 @@
goog.provide('ol.Popup');
goog.require('ol.Map');
goog.require('ol.Loc');
goog.require('ol.Feature');
/**
* @export
* @constructor
* @param {ol.Map} map the map on which the popup is placed.
* @param {ol.Loc|ol.Feature=} opt_anchor the anchor object for the popup.
* @param {string=} opt_placement the placement of the arrow on the popup.
* @param {boolean=} opt_close include a close button on the popup
*/
ol.Popup = function(map, opt_anchor, opt_placement, opt_close) {
/**
* @private
* @type {ol.Map}
*/
this.map_ = map;
/**
* @private
* @type {ol.Loc|ol.Feature|undefined}
*/
this.anchor_ = opt_anchor;
/**
* can be 'top','bottom','right','left','auto'
* TODO: 'auto' not yet implemented
* @private
* @type {!string}
*/
this.placement_ = goog.isDefAndNotNull(opt_placement)?opt_placement:'top';
/**
* include a close button on the popup - defaults to true.
* @private
* @type {boolean|undefined}
*/
this.closeButton_ = goog.isDefAndNotNull(opt_close) ? opt_close : true;
/**
* @private
* @type {string|undefined}
*/
this.content_ = undefined;
/**
* @private
* @type {string|undefined}
*/
this.template_ = undefined;
/**
* @private
* @type {Element}
*/
this.container_ = null;
/**
* @private
* @type {number}
*/
this.arrowOffset_ = 30; //FIXME: set this from CSS dynamically somehow?
/**
* if the CSS sets either width or height assume the app is specifying the
* size of the popup, if not auto size the popup.
* @private
* @type {boolean}
*/
this.autoSize_ = true;
};
/**
* @const
*/
ol.Popup.CLASS_NAME = 'ol-popup';
/**
* @return {ol.Map} Projection.
*/
ol.Popup.prototype.getMap = function() {
return this.map_;
};
/**
* @param {ol.Map} map the map object to hold this popup.
*/
ol.Popup.prototype.setMap = function(map) {
this.map_ = map;
};
/**
* @return {ol.Feature|ol.Loc|undefined} the anchor .
*/
ol.Popup.prototype.getAnchor = function() {
return this.anchor_;
};
/**
* @param {ol.Feature|ol.Loc} anchor the anchor location to place this popup.
*/
ol.Popup.prototype.setAnchor = function(anchor) {
this.anchor_ = anchor;
};
/**
* @return {string|undefined} the placement value relative to the anchor.
*/
ol.Popup.prototype.getPlacement = function() {
return this.placement_;
};
/**
* @param {string} placement where to place this popup relative to the anchor.
*/
ol.Popup.prototype.setPlacement = function(placement) {
if (!goog.isNull(this.container_)) {
goog.dom.classes.remove(this.container_,
ol.Popup.CLASS_NAME+'-'+this.placement_);
goog.dom.classes.add(this.container_,ol.Popup.CLASS_NAME+'-'+placement);
}
this.placement_ = placement;
};
/**
* @return {string|undefined} static content to be displayed in the popup (HTML)
*/
ol.Popup.prototype.getContent = function() {
return this.content_;
};
/**
* @param {string} content the content to be displayed this popup.
*/
ol.Popup.prototype.setContent = function(content) {
this.content_ = content;
};
/**
* @private
* @returns {string} generates the content
*/
ol.Popup.prototype.generateContent_ = function() {
//set the content
if ( goog.isDefAndNotNull(this.content_) ) {
return this.content_;
} else {
if ( goog.isDefAndNotNull(this.template_) &&
goog.isDefAndNotNull(this.anchor_) &&
(this.anchor_ instanceof ol.Feature)) {
//set content from feature attributes on the template
//TODO: this.setContent(template.apply(this.anchor_.getAttributes()));
return this.template_; //stub to return something
} else {
ol.error('ol.Popup unabale to generate any content');
return '<p>no content</p>';
}
}
};
/**
* @return {string|undefined} the anchor .
*/
ol.Popup.prototype.getTemplate = function() {
return this.template_;
};
/**
* @param {string} template the map object to hold this popup.
*/
ol.Popup.prototype.setTemplate = function(template) {
this.template_ = template;
};
/**
* Open the popup.
* @param {ol.Feature|ol.Loc} opt_arg feature or location for the anchor
*/
ol.Popup.prototype.doOpen = function(opt_arg) {
if (goog.isDef(opt_arg)) {
this.setAnchor(opt_arg);
}
//create popup container if it's not created already
if (goog.isNull(this.container_)) {
this.container_ = goog.dom.createElement('div');
goog.dom.classes.add(this.container_,
ol.Popup.CLASS_NAME, ol.Popup.CLASS_NAME+'-'+this.placement_);
//see if the style class sets width or height
if (goog.style.getStyle(this.container_, 'width').length>0 ||
goog.style.getStyle(this.container_, 'height').length>0 ) {
this.autoSize_ = false;
}
if (this.closeButton_) {
var closeButton = goog.dom.createElement('div');
goog.dom.appendChild(this.container_, closeButton);
goog.dom.classes.add(closeButton, ol.Popup.CLASS_NAME+'-close');
}
goog.events.listen(this.map_, 'click', this.clickHandler,
undefined, this);
goog.dom.appendChild(this.map_.getMapOverlay(), this.container_);
}
this.childContent_=goog.dom.htmlToDocumentFragment(this.generateContent_());
goog.dom.appendChild(this.container_, this.childContent_);
if (this.autoSize_) {
this.registerImageListeners();
}
this.setAnchorOffset_();
};
ol.Popup.prototype.setAnchorOffset_ = function() {
if (goog.isNull(this.container_.parentNode)) {
//this means the popup has already been closed, nothing to do here
//which might happen while waiting for images to load
return;
}
if (!goog.isDefAndNotNull(this.anchor_)) {
//must have an anchor when trying to set the position
ol.error("ol.Popup must have an anchor to set the position");
return;
}
//position the element
if (this.anchor_ instanceof ol.Feature) {
this.pos_ = this.anchor_.getGeometry().getCentroid();
} else {
this.pos_ = new ol.geom.Point(this.anchor_.getX(), this.anchor_.getY());
}
var pos = /** @type {ol.Loc} */ (this.pos_);
var popupPosPx = this.map_.getViewportPixelForLoc(pos);
var popupSize = goog.style.getSize(this.container_);
switch(this.placement_) {
default:
case 'auto':
//TODO: switch based on map quadrant
break;
case 'top':
case 'bottom':
popupPosPx[0] -= popupSize.width / 2.0;
if (this.placement_ == "bottom") {
popupPosPx[1] -= popupSize.height + this.arrowOffset_;
} else {
popupPosPx[1] += this.arrowOffset_;
}
break;
case 'left':
case 'right':
popupPosPx[1] -= popupSize.height / 2.0;
if (this.placement_ == "right") {
popupPosPx[0] -= popupSize.width + this.arrowOffset_;
} else {
popupPosPx[0] += this.arrowOffset_;
}
break;
}
this.moveTo_(popupPosPx);
};
/**
* registerImageListeners
* Called when an image contained by the popup loaded. this function
* updates the popup size, then unregisters the image load listener.
*/
ol.Popup.prototype.registerImageListeners = function() {
// As the images load, this function will call setAnchorOffset_() to
// resize the popup to fit the content div (which presumably is now
// bigger than when the image was not loaded).
//
//cycle through the images and if their size is 0x0, that means that
// they haven't been loaded yet, so we attach the listener, which
// will fire when the images finish loading and will resize the
// popup accordingly to its new size.
var images = this.container_.getElementsByTagName("img");
for (var i = 0, len = images.length; i < len; i++) {
var img = images[i];
if (img.width == 0 || img.height == 0) {
goog.events.listenOnce(img, 'load',
goog.bind(this.setAnchorOffset_, this));
}
}
};
/**
* @param px - {goog.} the top and left position of the popup div.
*/
ol.Popup.prototype.moveTo_ = function(px) {
if (goog.isDefAndNotNull(px)) {
goog.style.setPosition(this.container_, px[0], px[1]);
}
};
/**
* Click handler
* @param {Event} evt the event generated by a click
*/
ol.Popup.prototype.clickHandler = function(evt) {
var target = /** @type {Node} */ evt.target;
if (goog.dom.classes.has(target,ol.Popup.CLASS_NAME+'-close')) {
this.close();
}
};
/**
* Clean up.
* @export
*/
ol.Popup.prototype.close = function() {
goog.dom.removeChildren(this.container_);
goog.dom.removeNode(this.container_);
};
/**
* Clean up.
* @export
*/
ol.Popup.prototype.destroy = function() {
for (var key in this) {
delete this[key];
}
};

View File

@@ -1,257 +0,0 @@
goog.provide('ol.Projection');
goog.require('ol.UnreferencedBounds');
/**
* @export
* @constructor
* @param {string} code Projection identifier.
*/
ol.Projection = function(code) {
/**
* @private
* @type {string}
*/
this.code_ = code;
/**
* @private
* @type {string|undefined}
*/
this.units_ = undefined;
/**
* @private
* @type {Object}
*/
this.proj_ = null;
/**
* @private
* @type {ol.UnreferencedBounds}
*/
this.extent_ = null;
};
/**
* @return {string} Code.
*/
ol.Projection.prototype.getCode = function() {
return this.code_;
};
/**
* @param {string} code Code.
*/
ol.Projection.prototype.setCode = function(code) {
this.code_ = code;
};
/**
* @return {string|undefined} Units abbreviation.
*/
ol.Projection.prototype.getUnits = function() {
return this.units_;
};
/**
* @param {string} units Units abbreviation.
*/
ol.Projection.prototype.setUnits = function(units) {
this.units_ = units;
};
/**
* Get the validity extent of the coordinate reference system.
*
* @return {ol.UnreferencedBounds} The valididty extent.
*/
ol.Projection.prototype.getExtent = function() {
if (goog.isNull(this.extent_)) {
var defs = ol.Projection.defaults[this.code_];
if (goog.isDef(defs)) {
var ext = defs.maxExtent;
if (goog.isDef(ext)) {
this.setExtent(new ol.UnreferencedBounds(ext[0],ext[1],ext[2],ext[3]));
}
}
}
return this.extent_;
};
/**
* @param {!ol.UnreferencedBounds} extent Validity extent.
*/
ol.Projection.prototype.setExtent = function(extent) {
this.extent_ = extent;
};
/**
* Transforms is an object, with from properties, each of which may
* have a to property. This allows you to define projections without
* requiring support for proj4js to be included.
*
* This object has keys which correspond to a 'source' projection object. The
* keys should be strings, corresponding to the projection.getCode() value.
* Each source projection object should have a set of destination projection
* keys included in the object.
*
* Each value in the destination object should be a transformation function,
* where the function is expected to be passed an object with a .x and a .y
* property. The function should return the object, with the .x and .y
* transformed according to the transformation function.
*
* Note - Properties on this object should not be set directly. To add a
* transform method to this object, use the <addTransform> method. For an
* example of usage, see the OpenLayers.Layer.SphericalMercator file.
*
* @type {Object}
*/
ol.Projection.transforms = {};
/**
* Defaults for the SRS codes known to OpenLayers (currently EPSG:4326, CRS:84,
* urn:ogc:def:crs:EPSG:6.6:4326, EPSG:900913, EPSG:3857, EPSG:102113 and
* EPSG:102100). Keys are the SRS code, values are units, maxExtent (the
* validity extent for the SRS) and yx (true if this SRS is known to have a
* reverse axis order).
*
* @type {Object}
*/
ol.Projection.defaults = {
"EPSG:4326": {
units: "degrees",
maxExtent: [-180, -90, 180, 90],
yx: true
},
"CRS:84": {
units: "degrees",
maxExtent: [-180, -90, 180, 90]
},
"EPSG:900913": {
units: "m",
maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34]
}
};
/**
* Set a custom transform method between two projections. Use this method in
* cases where the proj4js lib is not available or where custom projections
* need to be handled.
*
* @param {string} from The code for the source projection.
* @param {string} to The code for the destination projection.
* @param {function(Object)} method A function that takes an object with x and
* y properties as an argument and transforms that point from the source to
* the destination projection in place. The original point should be
* modified.
*/
ol.Projection.addTransform = function(from, to, method) {
if (method === ol.Projection.nullTransform) {
var defaults = ol.Projection.defaults[from];
if (defaults && !ol.Projection.defaults[to]) {
ol.Projection.defaults[to] = defaults;
}
}
if(!ol.Projection.transforms[from]) {
ol.Projection.transforms[from] = {};
}
ol.Projection.transforms[from][to] = method;
};
/**
* Transform a point coordinate from one projection to another.
*
* @param {Object} point Object with x and y properties.
* @param {ol.Projection} source Source projection.
* @param {ol.Projection} dest Destination projection.
*/
ol.Projection.transform = function(point, source, dest) {
goog.asserts.assertObject(point);
goog.asserts.assertObject(source);
goog.asserts.assertObject(dest);
if (source.proj_ && dest.proj_) {
// TODO: implement Proj4js handling
// point = Proj4js.transform(source.proj_, dest.proj_, point);
} else {
var sourceCode = source.getCode();
var destCode = dest.getCode();
var transforms = ol.Projection.transforms;
if (transforms[sourceCode] && transforms[sourceCode][destCode]) {
transforms[sourceCode][destCode](point);
}
}
};
/**
* A null transformation - useful for defining projection aliases when
* proj4js is not available:
*
* ol.Projection.addTransform("EPSG:3857", "EPSG:900913",
* ol.Projection.nullTransform);
* ol.Projection.addTransform("EPSG:900913", "EPSG:3857",
* ol.Projection.nullTransform);
*
* @type {function(Object)}
*/
ol.Projection.nullTransform = function(point) {
return point;
};
/**
* Note: Transforms for web mercator <-> geographic
* OpenLayers recognizes EPSG:3857, EPSG:900913, EPSG:102113 and EPSG:102100.
* OpenLayers originally started referring to EPSG:900913 as web mercator.
* The EPSG has declared EPSG:3857 to be web mercator.
* ArcGIS 10 recognizes the EPSG:3857, EPSG:102113, and EPSG:102100 as
* equivalent. See http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2009/11/20/ArcGIS-Online-moving-to-Google-_2F00_-Bing-tiling-scheme_3A00_-What-does-this-mean-for-you_3F00_.aspx#12084.
* For geographic, OpenLayers recognizes EPSG:4326, CRS:84 and
* urn:ogc:def:crs:EPSG:6.6:4326. OpenLayers also knows about the reverse axis
* order for EPSG:4326.
*/
(function() {
var pole = 20037508.34;
function inverseMercator(xy) {
xy.x = 180 * xy.x / pole;
xy.y = 180 / Math.PI * (2 * Math.atan(Math.exp((xy.y / pole) * Math.PI)) - Math.PI / 2);
return xy;
}
function forwardMercator(xy) {
xy.x = xy.x * pole / 180;
xy.y = Math.log(Math.tan((90 + xy.y) * Math.PI / 360)) / Math.PI * pole;
return xy;
}
function map(base, codes) {
var add = ol.Projection.addTransform;
var same = ol.Projection.nullTransform;
var i, len, code, other, j;
for (i=0, len=codes.length; i<len; ++i) {
code = codes[i];
add(base, code, forwardMercator);
add(code, base, inverseMercator);
for (j=i+1; j<len; ++j) {
other = codes[j];
add(code, other, same);
add(other, code, same);
}
}
}
// list of equivalent codes for web mercator
var mercator = ["EPSG:900913", "EPSG:3857", "EPSG:102113", "EPSG:102100"],
geographic = ["CRS:84", "urn:ogc:def:crs:EPSG:6.6:4326", "EPSG:4326"],
i;
for (i=mercator.length-1; i>=0; --i) {
map(mercator[i], geographic);
}
for (i=geographic.length-1; i>=0; --i) {
map(geographic[i], mercator);
}
})();

View File

@@ -1,169 +0,0 @@
goog.provide('ol.Tile');
goog.require('ol.Bounds');
goog.require('goog.events.EventTarget');
goog.require('goog.events');
goog.require('goog.asserts');
/**
* The Tile class.
* @constructor
* @extends {goog.events.EventTarget}
* @param {string} url
* @param {ol.Bounds|undefined} opt_bounds
*/
ol.Tile = function(url, opt_bounds) {
/**
* @private
* @type {string}
*/
this.url_ = url;
/**
* @private
* @type {ol.Bounds|undefined}
*/
this.bounds_ = opt_bounds;
/**
* @private
* @type {boolean}
*/
this.loaded_ = false;
/**
* @private
* @type {boolean}
*/
this.loading_ = false;
/**
* @private
* @type {HTMLImageElement}
*/
this.img_ = this.createImage();
goog.events.listenOnce(this.img_, goog.events.EventType.LOAD,
this.handleImageLoad, false, this);
goog.events.listenOnce(this.img_, goog.events.EventType.ERROR,
this.handleImageError, false, this);
};
goog.inherits(ol.Tile, goog.events.EventTarget);
/**
* @protected
* @return {HTMLImageElement}
*/
ol.Tile.prototype.createImage = function() {
// overriden by subclasses
};
/**
* Load the tile. A tile should loaded only once.
*/
ol.Tile.prototype.load = function() {
goog.asserts.assert(!this.loaded_ && !this.loading_);
this.loading_ = true;
this.img_.src = this.url_;
};
/**
* Get the tile url.
* @return {string}
*/
ol.Tile.prototype.getUrl = function() {
return this.url_;
};
/**
* Get the tile bounds.
* @return {ol.Bounds|undefined}
*/
ol.Tile.prototype.getBounds = function() {
return this.bounds_;
};
/**
* Get the tile image.
* @return {HTMLImageElement}
*/
ol.Tile.prototype.getImg = function() {
return this.img_;
};
/**
* Handle load event on the image.
* @param {goog.events.BrowserEvent} evt Event.
*/
ol.Tile.prototype.handleImageLoad = function(evt) {
this.loading_ = false;
this.loaded_ = true;
this.img_.style.visibility = "inherit";
this.img_.style.opacity = 1; // TODO: allow for layer opacity
goog.events.dispatchEvent(this, 'load');
};
/**
* Handle load error event on the image.
* @param {goog.events.BrowserEvent} evt Event.
*/
ol.Tile.prototype.handleImageError = function(evt) {
this.loading_ = false;
goog.events.dispatchEvent(this, 'error');
};
/**
* Is the tile loaded already?
* @return {boolean}
*/
ol.Tile.prototype.isLoaded = function() {
return this.loaded_;
};
/**
* Is the tile being loaded?
* @return {boolean}
*/
ol.Tile.prototype.isLoading = function() {
return this.loading_;
};
/**
*
*/
ol.Tile.prototype.destroy = function() {
goog.events.dispatchEvent(this, 'destroy');
};
/**
* Create a tile constructor, for specific width and height values
* for the tiles.
* @param {number} width
* @param {number} height
* @return {function(new:ol.Tile, string, ol.Bounds=)}
*/
ol.Tile.createConstructor = function(width, height) {
/**
* @constructor
* @extends {ol.Tile}
*/
var Tile = function(url, opt_bounds) {
goog.base(this, url, opt_bounds);
};
goog.inherits(Tile, ol.Tile);
/** @inheritDoc */
Tile.prototype.createImage = (function() {
var img = document.createElement("img");
img.className = "olTile";
img.style.position = "absolute";
img.style.width = width + "px";
img.style.height = height + "px";
img.style.opacity = 0;
img.src = "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";
return function() {
return img.cloneNode(false);
};
})();
return Tile;
};

View File

@@ -1,23 +0,0 @@
goog.provide('ol.TileCache');
goog.require('goog.structs.LinkedMap');
/**
* A cache of ol.Tile objects.
* @constructor
* @extends {goog.structs.LinkedMap}
* @param {number=} opt_size
*/
ol.TileCache = function(opt_size) {
goog.base(this, opt_size || 100, true /* cache mode */);
};
goog.inherits(ol.TileCache, goog.structs.LinkedMap);
/**
* @inheritDoc
*/
ol.TileCache.prototype.removeNode = function(node) {
goog.base(this, 'removeNode', node);
node.value.destroy();
};

View File

@@ -1,66 +0,0 @@
goog.provide('ol.TileSet');
/**
* The TileSet class. A TileSet instance represents a collection of
* tiles. Tiles of a TileSet have the same resolution, width and
* height.
* @constructor
* @param {Array.<Array.<ol.Tile>>} tiles
* @param {number} tileWidth
* @param {number} tileHeight
* @param {number} resolution
*/
ol.TileSet = function(tiles, tileWidth, tileHeight, resolution) {
/**
* @private
* @type {Array.<Array.<ol.Tile>>}
*/
this.tiles_ = tiles;
/**
* @private
* @type {number}
*/
this.tileWidth_ = tileWidth;
/**
* @private
* @type {number}
*/
this.tileHeight_ = tileHeight;
/**
* @private
* @type {number}
*/
this.resolution_ = resolution;
};
/**
* @return {Array.<Array.<ol.Tile>>}
*/
ol.TileSet.prototype.getTiles = function() {
return this.tiles_;
};
/**
* @return {number}
*/
ol.TileSet.prototype.getResolution = function() {
return this.resolution_;
};
/**
* @return {number}
*/
ol.TileSet.prototype.getTileHeight = function() {
return this.tileHeight_;
};
/**
* @return {number}
*/
ol.TileSet.prototype.getTileWidth = function() {
return this.tileWidth_;
};

View File

@@ -1,130 +0,0 @@
goog.provide('ol.UnreferencedBounds');
/**
* @constructor
* @param {number} minX Minimum X.
* @param {number} minY Minimum Y.
* @param {number} maxX Maximum X.
* @param {number} maxY Maximum Y.
*/
ol.UnreferencedBounds = function(minX, minY, maxX, maxY) {
/**
* @protected
* @type {number}
*/
this.minX_ = minX;
/**
* @protected
* @type {number}
*/
this.minY_ = minY;
/**
* @protected
* @type {number}
*/
this.maxX_ = maxX;
/**
* @protected
* @type {number}
*/
this.maxY_ = maxY;
};
/**
* @return {number} Minimun X.
*/
ol.UnreferencedBounds.prototype.getMinX = function() {
return this.minX_;
};
/**
* @param {number} minX Minimum X.
*/
ol.UnreferencedBounds.prototype.setMinX = function(minX) {
this.minX_ = minX;
};
/**
* @return {number} Minimun Y.
*/
ol.UnreferencedBounds.prototype.getMinY = function() {
return this.minY_;
};
/**
* @param {number} minY Minimum Y.
*/
ol.UnreferencedBounds.prototype.setMinY = function(minY) {
this.minY_ = minY;
};
/**
* @return {number} Maximun X.
*/
ol.UnreferencedBounds.prototype.getMaxX = function() {
return this.maxX_;
};
/**
* @param {number} maxX Maximum X.
*/
ol.UnreferencedBounds.prototype.setMaxX = function(maxX) {
this.maxX_ = maxX;
};
/**
* @return {number} Maximun Y.
*/
ol.UnreferencedBounds.prototype.getMaxY = function() {
return this.maxY_;
};
/**
* @param {number} maxY Maximum Y.
*/
ol.UnreferencedBounds.prototype.setMaxY = function(maxY) {
this.maxY_ = maxY;
};
/**
* @return {number} Bounds width.
*/
ol.UnreferencedBounds.prototype.getWidth = function() {
return this.maxX_ - this.minX_;
};
/**
* @return {number} Bounds height.
*/
ol.UnreferencedBounds.prototype.getHeight = function() {
return this.maxY_ - this.minY_;
};
/**
* Determine if this bounds intersects the target bounds (bounds that only
* touch are considered intersecting).
*
* @param {ol.UnreferencedBounds} bounds Target bounds.
* @return {boolean} The provided bounds intersects this bounds.
*/
ol.UnreferencedBounds.prototype.intersects = function(bounds) {
return !(
// this is left
(this.minX_ > bounds.getMaxX()) ||
// this is right
(this.maxX_ < bounds.getMinX()) ||
// this is above
(this.minY_ > bounds.getMaxY()) ||
// this is below
(this.maxY_ < bounds.getMinY())
);
};

View File

@@ -1,46 +0,0 @@
goog.provide('ol.base');
goog.provide('ol.error');
/**
* @param {string} message Message.
*/
ol.error = function(message) {
if (ol.error.VERBOSE_ERRORS) {
throw new Error(message);
} else {
throw null;
}
};
/**
* Compilation with public API, let's accept options from external world
* @define {boolean}
*/
ol.API = true;
/**
* @define {boolean}
*/
ol.error.VERBOSE_ERRORS = true;
/**
* Options passed in the API from external world are checked for wrong keys
* @define {boolean}
*/
ol.CHECK_KEYS = true;
/**
* @param {Object} obj Object.
* @param {!Array.<string>} allowedKeys Allowed keys.
*/
ol.base.checkKeys = function(obj, allowedKeys) {
if (ol.CHECK_KEYS) {
var keys = goog.object.getKeys(obj);
goog.array.forEach(allowedKeys, function(allowedKey) {
goog.array.remove(keys, allowedKey);
});
if (!goog.array.isEmpty(keys)) {
ol.error('object contains invalid keys: ' + keys.join(', '));
}
}
};

22
src/ol/collection_test.js Normal file
View File

@@ -0,0 +1,22 @@
goog.require('goog.testing.jsunit');
goog.require('ol');
goog.require('ol3.Collection');
function testCreateFromArray() {
var array = [0, 1, 2];
var collection = ol.collection(array);
assertTrue(collection instanceof ol3.Collection);
assertEquals(3, collection.getLength());
assertEquals(0, collection.getAt(0));
assertEquals(1, collection.getAt(1));
assertEquals(2, collection.getAt(2));
}
function testCreateFromCollection() {
var collection1 = new ol3.Collection();
var collection2 = ol.collection(collection1);
assertTrue(collection1 === collection2);
}

View File

@@ -1,95 +0,0 @@
goog.provide('ol.control.Attribution');
goog.require('ol.control.Control');
goog.require('goog.dom');
goog.require('goog.events');
goog.require('goog.events.Event');
/**
* @constructor
* @extends {ol.control.Control}
* @param {boolean|undefined} opt_autoActivate
*/
ol.control.Attribution = function(opt_autoActivate) {
goog.base(this, opt_autoActivate);
/**
* @type {Node}
*/
this.container_ = null;
/**
* Activate this control when it is added to a map. Default is true.
*
* @type {boolean} autoActivate
*/
this.autoActivate_ =
goog.isDef(opt_autoActivate) ? opt_autoActivate : true;
};
goog.inherits(ol.control.Attribution, ol.control.Control);
/**
* @const {string}
*/
ol.control.Attribution.prototype.CLS = 'ol-control-attribution';
/**
* @param {ol.Map} map
*/
ol.control.Attribution.prototype.setMap = function(map) {
var staticOverlay = map.getStaticOverlay();
if (goog.isNull(this.container_)) {
this.container_ = goog.dom.createDom('div', this.CLS);
goog.events.listen(this.container_, 'click',
goog.events.Event.stopPropagation);
}
if (!goog.isNull(staticOverlay)) {
goog.dom.append(staticOverlay, this.container_);
}
goog.base(this, 'setMap', map);
};
/** @inheritDoc */
ol.control.Attribution.prototype.activate = function() {
var active = goog.base(this, 'activate');
if (active) {
goog.events.listen(this.map_, 'layeradd', this.update, false, this);
this.update();
}
return active;
};
/** @inheritDoc */
ol.control.Attribution.prototype.deactivate = function() {
var inactive = goog.base(this, 'deactivate');
if (inactive) {
goog.events.unlisten(this.map_, 'layeradd', this.update, false, this);
}
return inactive;
};
ol.control.Attribution.prototype.update = function() {
var attribution = [],
layers = this.map_.getLayers(), layerAttribution;
for (var i=0, ii=layers.length; i<ii; ++i) {
layerAttribution = layers[i].getAttribution();
if (layerAttribution &&
!~goog.array.indexOf(attribution, layerAttribution)) {
attribution.push(layerAttribution);
}
}
this.container_.innerHTML = attribution.join(', ');
};
ol.control.Attribution.prototype.destroy = function() {
goog.events.unlisten(this.container_, 'click',
goog.events.Event.stopPropagation);
goog.dom.removeNode(this.container_);
goog.base(this, 'destroy');
};
ol.control.addControl('attribution', ol.control.Attribution);

View File

@@ -1,85 +0,0 @@
goog.provide('ol.control');
goog.provide('ol.control.Control');
goog.require('goog.object');
/**
* @enum {Object}
*/
ol.control.CONTROL_MAP = {};
/**
* @param {string} name
* @param {Function} Control
*/
ol.control.addControl = function(name, Control) {
ol.control.CONTROL_MAP[name] = Control;
};
/**
* @constructor
* @param {boolean|undefined} opt_autoActivate
*/
ol.control.Control = function(opt_autoActivate) {
/**
* @type {ol.Map} map
* @protected
*/
this.map_ = null;
/**
* @type {boolean} active
* @private
*/
this.active_ = false;
/**
* Activate this control when it is added to a map. Default is false.
*
* @type {boolean} autoActivate
*/
this.autoActivate_ =
goog.isDef(opt_autoActivate) ? opt_autoActivate : false;
};
/**
* @return {ol.Map} getMap
*/
ol.control.Control.prototype.getMap = function() {
return this.map_;
};
/**
* @param {ol.Map} map
*/
ol.control.Control.prototype.setMap = function(map) {
this.map_ = map;
if (this.autoActivate_) {
this.activate();
}
};
/**
* @return {boolean}
*/
ol.control.Control.prototype.activate = function() {
var returnValue = !this.active_;
this.active_ = true;
return returnValue;
};
/**
* @return {boolean}
*/
ol.control.Control.prototype.deactivate = function() {
var returnValue = this.active_;
this.active_ = false;
return returnValue;
};
ol.control.Control.prototype.destroy = function() {
this.deactivate();
goog.object.clear(this);
};

View File

@@ -1,122 +0,0 @@
goog.provide('ol.control.Zoom');
goog.require('ol.control.Control');
goog.require('goog.dom');
/**
* @constructor
* @extends {ol.control.Control}
* @param {boolean|undefined} opt_autoActivate
*/
ol.control.Zoom = function(opt_autoActivate) {
goog.base(this, opt_autoActivate);
/**
* @type {Node}
*/
this.inButton_ = null;
/**
* @type {Node}
*/
this.outButton_ = null;
/**
* Activate this control when it is added to a map. Default is true.
*
* @type {boolean}
*/
this.autoActivate_ =
goog.isDef(opt_autoActivate) ? opt_autoActivate : true;
};
goog.inherits(ol.control.Zoom, ol.control.Control);
/**
* @param {ol.Map} map
*/
ol.control.Zoom.prototype.setMap = function(map) {
var container = goog.dom.createDom('div', ol.control.Zoom.RES.CLS);
this.inButton_ = goog.dom.createDom(
'div', ol.control.Zoom.RES.IN_CLS,
goog.dom.createDom('a', {'href': '#zoomIn'})
);
goog.dom.setTextContent(
/** @type {Element} */ (this.inButton_.firstChild),
ol.control.Zoom.RES.IN_TEXT
);
this.outButton_ = goog.dom.createDom(
'div', ol.control.Zoom.RES.OUT_CLS,
goog.dom.createDom('a', {'href': '#zoomOut'})
);
goog.dom.setTextContent(
/** @type {Element} */ (this.outButton_.firstChild),
ol.control.Zoom.RES.OUT_TEXT
);
goog.dom.append(container, this.inButton_, this.outButton_);
var overlay = map.getStaticOverlay();
if (goog.isDefAndNotNull(overlay)) {
goog.dom.append(overlay, container);
}
goog.base(this, 'setMap', map);
};
/** @inheritDoc */
ol.control.Zoom.prototype.activate = function() {
var active = goog.base(this, 'activate');
if (active) {
goog.events.listen(this.inButton_, 'click', this.handleIn, false, this);
goog.events.listen(this.outButton_, 'click', this.handleOut, false, this);
}
return active;
};
/** @inheritDoc */
ol.control.Zoom.prototype.deactivate = function() {
var inactive = goog.base(this, 'deactivate');
if (inactive) {
goog.events.unlisten(this.inButton_, 'click', this.handleIn, false, this);
goog.events.unlisten(this.outButton_, 'click', this.handleOut, false, this);
}
return inactive;
};
/**
* @param {Event} evt
*/
ol.control.Zoom.prototype.handleIn = function(evt) {
this.map_.zoomIn();
evt.preventDefault();
evt.stopPropagation();
};
/**
* @param {Event} evt
*/
ol.control.Zoom.prototype.handleOut = function(evt) {
this.map_.zoomOut();
evt.preventDefault();
evt.stopPropagation();
};
ol.control.Zoom.prototype.destroy = function() {
goog.dom.removeNode(goog.dom.getElementByClass(
ol.control.Zoom.RES.CLS,
/** @type {Element} */ (this.map_.getStaticOverlay())
));
goog.base(this, 'destroy');
};
ol.control.addControl('zoom', ol.control.Zoom);
ol.control.Zoom.RES = {
CLS: 'ol-control-zoom',
IN_CLS: 'ol-control-zoom-in',
OUT_CLS: 'ol-control-zoom-out',
IN_TEXT: '+',
OUT_TEXT: '\u2212'
};

View File

@@ -1,58 +0,0 @@
goog.provide('ol.coord.AccessorInterface');
goog.require('ol.Projection');
/**
* The AccessorInterface in coord package
*
* @interface
*
* @param {number} x X.
* @param {number} y Y.
* @param {number=} opt_z Z.
* @param {ol.Projection=} opt_projection Projection.
*/
ol.coord.AccessorInterface = function(x, y, opt_z, opt_projection){
};
/**
* @return {number} X.
*/
ol.coord.AccessorInterface.prototype.getX = function(){};
/**
* @return {number} Y.
*/
ol.coord.AccessorInterface.prototype.getY = function(){};
/**
* @return {number|undefined} Z.
*/
ol.coord.AccessorInterface.prototype.getZ = function(){};
/**
* @return {ol.Projection|undefined} Projection.
*/
ol.coord.AccessorInterface.prototype.getProjection = function() {};
/**
* @param {number} x X.
*/
ol.coord.AccessorInterface.prototype.setX = function(x){};
/**
* @param {number} y Y.
*/
ol.coord.AccessorInterface.prototype.setY = function(y){};
/**
* @param {number|undefined} z Z.
*/
ol.coord.AccessorInterface.prototype.setZ = function(z){};
/**
* @param {ol.Projection} projection Projection.
*/
ol.coord.AccessorInterface.prototype.setProjection = function(projection) {};

View File

@@ -1,198 +0,0 @@
goog.provide('ol.geom.Collection');
goog.require('goog.array');
goog.require('ol.geom.Geometry');
goog.require('ol.Projection');
goog.require('ol.base');
/**
* Creates ol.geom.Collection objects.
*
* @export
* @extends {ol.geom.Geometry}
* @param {Array.<ol.geom.Geometry>} components An array of components.
*
* @constructor
*/
ol.geom.Collection = function(components) {
/**
* @private
* @type {Array.<Function>}
*/
this.typeBlacklist_ = [
ol.geom.Collection
];
/**
* @private
* @type {Array.<Function>}
*/
this.typeWhitelist_ = [
ol.geom.MultiPoint,
ol.geom.MultiLineString
// TODO uncomment when implemented
// ,ol.geom.MultiPolygon
];
/**
* @private
* @type {Array.<ol.geom.Geometry>}
*/
this.components_ = [];
if (arguments.length === 1 && goog.isDef(components)) {
this.setComponents(components);
}
};
goog.inherits(ol.geom.Collection, ol.geom.Geometry);
/**
* Sets the list of disallowed types for the collection.
* @param {Array.<Function>} typeBlacklist Array of constructors to disallow.
*/
ol.geom.Collection.prototype.setTypeBlacklist = function(typeBlacklist){
this.typeBlacklist_ = typeBlacklist;
};
/**
* Gets the list of disallowed types for the collection.
* @return {Array.<Function>} Array of constructors to disallow.
*/
ol.geom.Collection.prototype.getTypeBlacklist = function(){
return this.typeBlacklist_;
};
/**
* Sets the list of always allowed types for the collection.
* @param {Array.<Function>} typeWhitelist Array of constructors to allow.
*/
ol.geom.Collection.prototype.setTypeWhitelist = function(typeWhitelist){
this.typeWhitelist_ = typeWhitelist;
};
/**
* Gets the list of always allowed types for the collection.
* @return {Array.<Function>} Array of constructors to allow.
*/
ol.geom.Collection.prototype.getTypeWhitelist = function(){
return this.typeWhitelist_;
};
/**
* Sets the Collection's components.
*
* @return {Array.<ol.geom.Geometry>} An array of components.
*/
ol.geom.Collection.prototype.getComponents = function() {
return this.components_;
};
/**
* Gets the Collection's components.
*
* @param {Array.<ol.geom.Geometry>} components An array of components.
*/
ol.geom.Collection.prototype.setComponents = function(components) {
var allValidTypes = goog.array.every(
components,
this.isAllowedComponent,
this
);
if (allValidTypes) {
this.components_ = components;
} else {
var msg = 'ol.geom.Collection: at least one component passed to '
+ 'setComponents is not allowed.';
ol.error(msg);
}
};
/**
* Adds the given component to the list of components at the specified index.
*
* @param {ol.geom.Geometry} component A component to be added.
* @param {number} index The index where to add.
*/
ol.geom.Collection.prototype.addComponent = function(component, index) {
if (this.isAllowedComponent(component)) {
goog.array.insertAt(this.components_, component, index);
} else {
var msg = 'ol.geom.Collection: component is not allowed to be added.';
ol.error(msg);
}
};
/**
* Checks whether the passed component is an instance of any of the constructors
* listed in the passed list.
*
* @param {ol.geom.Geometry} component The component to check.
* @param {Array.<Function>} list The List of constructors to check the
* component against.
*
* @return {boolean} Whether the passed component is an instance of any of the
* constructors listed in the passed list.
*
* @private
*/
ol.geom.Collection.prototype.isOnList = function(component, list) {
var isOnList = !goog.array.every(list, function(listedConstr){
if (component instanceof listedConstr) {
return false;
} else {
return true;
}
});
return isOnList;
};
/**
* Checks whether the passed component is allowed according to the black and
* whitelists.
*
* @param {ol.geom.Geometry} component The component to check.
* @return {boolean} Whether the passed component is allowed as part of this
* collection according to black- and whitelist.
*/
ol.geom.Collection.prototype.isAllowedComponent = function(component){
var whitelist = this.getTypeWhitelist(),
blacklist = this.getTypeBlacklist(),
isOnWhitelist = this.isOnList(component, whitelist),
isOnBlacklist = this.isOnList(component, blacklist);
return (isOnWhitelist || !isOnBlacklist);
};
/**
* Removes the given component from the list of components.
*
* @param {ol.geom.Geometry} component A component to be removed.
*/
ol.geom.Collection.prototype.removeComponent = function(component) {
goog.array.remove(this.components_, component);
};
/**
* Compute the centroid for this geometry collection.
*
* @returns {ol.geom.Point} The centroid of the collection.
*/
ol.geom.Collection.prototype.getCentroid = function() {
var components = this.getComponents(),
len = components.length,
sum_x = 0, sum_y = 0,
centroid = null;
if (len > 0) {
goog.array.forEach(components, function(component){
var singleCentroid = component.getCentroid();
if (goog.isDefAndNotNull(singleCentroid)) {
sum_x += singleCentroid.getX();
sum_y += singleCentroid.getX();
} else {
len--;
}
});
centroid = new ol.geom.Point(sum_x / len, sum_y / len);
}
return centroid;
};

View File

@@ -1,58 +0,0 @@
goog.provide('ol.geom.Geometry');
goog.require('ol.geom.IGeometry');
goog.require('ol.Bounds');
/**
* Creates ol.Geometry objects.
*
* @export
* @implements {ol.geom.IGeometry}
* @constructor
*/
ol.geom.Geometry = function() {
/**
* @private
* @type {ol.Bounds|undefined}
*/
this.bounds_ = undefined;
};
/**
* @return {ol.Bounds|undefined} The ol.Bounds.
*/
ol.geom.Geometry.prototype.getBounds = function() {
return this.bounds_;
};
/**
* @param {ol.Bounds} bounds The new ol.Bounds.
* @return {ol.geom.Geometry} This.
*/
ol.geom.Geometry.prototype.setBounds = function(bounds) {
this.bounds_ = bounds;
return this;
};
/**
* Returns the centroid of the geometry.
*
* @returns {ol.geom.Point} The centroid of the geometry.
*/
ol.geom.Geometry.prototype.getCentroid = function() {
// throw an error to enforce subclasses to implement it properly
ol.error('ol.geom.Geometry: getCentroid must be implemented by subclasses');
return null;
};
/**
* Returns the area of the geometry.
*
* @returns {number} The area of the geometry.
*/
ol.geom.Geometry.prototype.getArea = function() {
// throw an error to enforce subclasses to implement it properly
ol.error('ol.geom.Geometry: getArea must be implemented by subclasses');
return 0;
};

View File

@@ -1,27 +0,0 @@
goog.provide('ol.geom.IGeometry');
//goog.require('ol.geom.Point');
//goog.require('ol.Bounds');
/**
* Interface for geometry classes forcing ol.geom.* classes to implement
* expected functionality.
*
* @interface
*/
ol.geom.IGeometry = function(){};
/**
* @return {ol.geom.Point} The centroid of the geometry.
*/
ol.geom.IGeometry.prototype.getCentroid = function(){};
/**
* @return {ol.Bounds|undefined} The centroid of the geometry.
*/
ol.geom.IGeometry.prototype.getBounds = function(){};
/**
* @return {number} The area of the geometry.
*/
ol.geom.IGeometry.prototype.getArea = function(){};

View File

@@ -1,76 +0,0 @@
goog.provide('ol.geom.LineString');
goog.require('goog.array');
goog.require('ol.geom.Geometry');
goog.require('ol.geom.Collection');
goog.require('ol.geom.Point');
goog.require('ol.Projection');
/**
* Creates ol.geom.LineString objects.
*
* @export
* @extends {ol.geom.Geometry}
* @param {Array.<ol.geom.Point>} vertices An array of points building the
* linestrings vertices.
*
* @constructor
*/
ol.geom.LineString = function(vertices) {
/**
* @private
* @type {Array.<ol.geom.Point>}
*/
this.vertices_ = vertices;
};
goog.inherits(ol.geom.LineString, ol.geom.Geometry);
/**
* Sets the LineString's points.
*
* @return {Array.<ol.geom.Point>} An array of points.
*/
ol.geom.LineString.prototype.getVertices = function() {
return this.vertices_;
};
/**
* Gets the LineString's points.
*
* @param {Array.<ol.geom.Point>} vertices An array of points.
*/
ol.geom.LineString.prototype.setVertices = function(vertices) {
this.vertices_ = vertices;
};
/**
* Adds the given vertex to the list of vertices at the specified index.
*
* @param {ol.geom.Point} vertex A point to be added.
* @param {number} index The index where to add.
*/
ol.geom.LineString.prototype.addVertex = function(vertex, index) {
goog.array.insertAt(this.vertices_,vertex,index);
};
/**
* Removes the given vertex from the list of vertices.
*
* @param {ol.geom.Point} vertex A point to be removed.
*/
ol.geom.LineString.prototype.removeVertex = function(vertex) {
goog.array.remove(this.vertices_, vertex);
};
/**
* Compute the centroid for this linestring.
*
* @returns {ol.geom.Point} The centroid of the linestring.
*/
ol.geom.LineString.prototype.getCentroid = function() {
var vertices = this.getVertices(),
collection = new ol.geom.Collection(vertices);
return collection.getCentroid();
};

View File

@@ -1,61 +0,0 @@
goog.provide('ol.geom.MultiLineString');
goog.require('goog.array');
goog.require('ol.geom.Collection');
/**
* Creates ol.geom.MultiLineString objects.
*
* @export
* @extends {ol.geom.Collection}
* @param {Array.<ol.geom.LineString>} linestrings An array of linestrings.
*
* @constructor
*/
ol.geom.MultiLineString = function(linestrings) {
this.setTypeWhitelist([ol.geom.LineString]);
this.setTypeBlacklist([ol.geom.Geometry]);
if (arguments.length === 1 && goog.isDef(linestrings)) {
this.setLineStrings(linestrings);
}
};
goog.inherits(ol.geom.MultiLineString, ol.geom.Collection);
/**
* Gets the MultiLineString's linestrings.
*
* @return {Array.<ol.geom.LineString>} An array of linestrings.
*/
ol.geom.MultiLineString.prototype.getLineStrings = function() {
return this.getComponents();
};
/**
* Sets the MultiLineString's linestrings.
*
* @param {Array.<ol.geom.LineString>} linestrings An array of linestrings.
*/
ol.geom.MultiLineString.prototype.setLineStrings = function(linestrings) {
this.setComponents(linestrings);
};
/**
* Adds the given linestring to the list of linestrings at the specified index.
*
* @param {ol.geom.LineString} linestring A linestring to be added.
* @param {number} index The index where to add.
*/
ol.geom.MultiLineString.prototype.addLineString = function(linestring, index) {
this.addComponent(linestring, index);
};
/**
* Removes the given linestring from the list of linestrings.
*
* @param {ol.geom.LineString} linestring A linestring to be removed.
*/
ol.geom.MultiLineString.prototype.removeLineString = function(linestring) {
this.removeComponent(linestring);
};

View File

@@ -1,61 +0,0 @@
goog.provide('ol.geom.MultiPoint');
goog.require('goog.array');
goog.require('ol.geom.Collection');
/**
* Creates ol.geom.MultiPoint objects.
*
* @export
* @extends {ol.geom.Collection}
* @param {Array.<ol.geom.Point>} points An array of points.
*
* @constructor
*/
ol.geom.MultiPoint = function(points) {
this.setTypeWhitelist([ol.geom.Point]);
this.setTypeBlacklist([ol.geom.Geometry]);
if (arguments.length === 1 && goog.isDef(points)) {
this.setPoints(points);
}
};
goog.inherits(ol.geom.MultiPoint, ol.geom.Collection);
/**
* Sets the MultiPoint's points.
*
* @return {Array.<ol.geom.Point>} An array of points.
*/
ol.geom.MultiPoint.prototype.getPoints = function() {
return this.getComponents();
};
/**
* Gets the MultiPoint's points.
*
* @param {Array.<ol.geom.Point>} points An array of points.
*/
ol.geom.MultiPoint.prototype.setPoints = function(points) {
this.setComponents(points);
};
/**
* Adds the given point to the list of points at the specified index.
*
* @param {ol.geom.Point} point A point to be added.
* @param {number} index The index where to add.
*/
ol.geom.MultiPoint.prototype.addPoint = function(point, index) {
this.addComponent(point, index);
};
/**
* Removes the given point from the list of points.
*
* @param {ol.geom.Point} point A point to be removed.
*/
ol.geom.MultiPoint.prototype.removePoint = function(point) {
this.removeComponent(point);
};

View File

@@ -1,163 +0,0 @@
goog.provide('ol.geom.Point');
goog.require('ol.geom.Geometry');
goog.require('ol.Projection');
goog.require('ol.coord.AccessorInterface');
goog.require('ol.base');
/**
* Creates ol.geom.Point objects.
*
* @export
* @extends {ol.geom.Geometry}
* @param {number} x X.
* @param {number} y Y.
* @param {number=} opt_z Z.
* @param {ol.Projection=} opt_projection Projection.
*
* @implements {ol.coord.AccessorInterface}
*
* @constructor
*/
ol.geom.Point = function(x, y, opt_z, opt_projection) {
/**
* @private
* @type {number}
*/
this.x_ = x;
/**
* @private
* @type {number}
*/
this.y_ = y;
/**
* @private
* @type {number|undefined}
*/
this.z_ = opt_z;
/**
* @private
* @type {ol.Projection}
*/
this.projection_ = goog.isDef(opt_projection) ? opt_projection : null;
};
goog.inherits(ol.geom.Point, ol.geom.Geometry);
/**
* @return {number} X.
*/
ol.geom.Point.prototype.getX = function() {
return this.x_;
};
/**
* @return {number} Y.
*/
ol.geom.Point.prototype.getY = function() {
return this.y_;
};
/**
* @return {number|undefined} Z.
*/
ol.geom.Point.prototype.getZ = function() {
return this.z_;
};
/**
* @return {ol.Projection|undefined} Projection.
*/
ol.geom.Point.prototype.getProjection = function() {
return this.projection_;
};
/**
* @param {ol.Projection} projection Projection.
*/
ol.geom.Point.prototype.setProjection = function(projection) {
this.projection_ = projection;
};
/**
* @param {number} x X.
*/
ol.geom.Point.prototype.setX = function(x) {
this.x_ = x;
};
/**
* @param {number} y Y.
*/
ol.geom.Point.prototype.setY = function(y) {
this.y_ = y;
};
/**
* @param {number|undefined} z Z.
*/
ol.geom.Point.prototype.setZ = function(z) {
this.z_ = z;
};
/**
* Transform this point to another coordinate reference system. This
* requires that this point has a projection set already (if not, an error
* will be thrown). Returns a new point object and does not modify this
* point.
*
* @param {string|!ol.Projection} proj The destination projection. Can be
* supplied as a projection instance of a string identifier.
* @returns {!ol.geom.Point} A new location.
*/
ol.geom.Point.prototype.transform = function(proj) {
if (goog.isString(proj)) {
proj = new ol.Projection(proj);
}
return this._transform(proj);
};
/**
* Transform this point to a new location given a projection object.
*
* @param {!ol.Projection} proj The destination projection.
* @returns {!ol.geom.Point}
* @private
*/
ol.geom.Point.prototype._transform = function(proj) {
var point = {'x': this.x_, 'y': this.y_};
var sourceProj = this.projection_;
if (!goog.isDefAndNotNull(sourceProj)) {
var msg = 'Cannot transform a point without a source projection.';
ol.error(msg);
}
ol.Projection.transform(point, sourceProj, proj);
return new ol.geom.Point(point['x'], point['y'], this.z_, proj);
};
/**
* Returns the centroid of the point.
*
* @returns {ol.geom.Point} The centroid of the point.
*/
ol.geom.Point.prototype.getCentroid = function() {
return new ol.geom.Point(this.x_, this.y_, this.z_, this.projection_);
};
/**
* Returns the area of the geometry whcih is always 0.
*
* @returns {number} The area of the point (always 0).
*/
ol.geom.Point.prototype.getArea = function() {
return 0;
};

View File

@@ -1,22 +0,0 @@
goog.provide('ol.layer.Layer');
/**
* @constructor
* @export
*/
ol.layer.Layer = function() {
/**
* @type {string}
* @protected
*/
this.attribution_;
};
/**
* @return {string}
*/
ol.layer.Layer.prototype.getAttribution = function() {
return this.attribution_;
};

View File

@@ -1,21 +0,0 @@
goog.provide('ol.layer.OSM');
goog.require('ol.layer.XYZ');
/**
* Class for OSM layers.
*
* @export
* @constructor
* @extends {ol.layer.XYZ}
*/
ol.layer.OSM = function() {
//TODO Is this attribution still correct?
/** @inheritDoc */
this.attribution_ = "Data CC-By-SA by <a target='_blank' href='http://openstreetmap.org/'>OpenStreetMap</a>";
goog.base(this, 'http://a.tile.openstreetmap.org/{z}/{x}/{y}.png');
};
goog.inherits(ol.layer.OSM, ol.layer.XYZ);

View File

@@ -1,490 +0,0 @@
goog.provide('ol.layer.TileLayer');
goog.require('ol.error');
goog.require('ol.layer.Layer');
goog.require('ol.Tile');
goog.require('ol.TileCache');
/**
* @constructor
* @extends {ol.layer.Layer}
*/
ol.layer.TileLayer = function() {
/**
* @private
* @type {string|undefined}
*/
this.url_ = undefined;
/**
* @protected
* @type {ol.Projection}
*/
this.projection_ = null;
/**
* @private
* @type {ol.Bounds}
*/
this.extent_ = null;
/**
* @protected
* @type {number}
*/
this.tileWidth_ = 256;
/**
* @protected
* @type {number}
*/
this.tileHeight_ = 256;
/**
* @protected
* @type {function(new:ol.Tile, string, ol.Bounds=)}
*/
this.Tile = ol.Tile.createConstructor(this.tileWidth_, this.tileHeight_);
/**
* @protected
* @type {number|undefined}
*/
this.tileOriginX_ = undefined;
/**
* @protected
* @type {number|undefined}
*/
this.tileOriginY_ = undefined;
/**
* @private
* @type {string}
*/
this.tileOriginCorner_ = 'tl';
/**
* @private
* @type {number|undefined}
*/
this.maxResolution_ = undefined;
/**
* @private
* @type {boolean}
*/
this.xRight_ = true;
/**
* @private
* @type {boolean}
*/
this.yDown_ = true;
/**
* @private
* @type {number|undefined}
*/
this.numZoomLevels_ = undefined;
/**
* @protected
* @type {Array.<number>}
*/
this.resolutions_ = null;
/**
* @private
* @type {ol.TileCache}
*/
this.cache_ = new ol.TileCache();
};
goog.inherits(ol.layer.TileLayer, ol.layer.Layer);
/**
* @protected
* @param {number} x
* @param {number} y
* @param {number} z
* @return {string}
*/
ol.layer.TileLayer.prototype.getTileUrl = function(x, y, z) {
// overridden by subclasses
};
/**
* @return {string|undefined} The layer URL.
*/
ol.layer.TileLayer.prototype.getUrl = function() {
return this.url_;
};
/**
* @return {boolean} The tile index increases from left to right.
*/
ol.layer.TileLayer.prototype.getXRight = function() {
return this.xRight_;
};
/**
* @return {boolean} The tile index increases from top to bottom.
*/
ol.layer.TileLayer.prototype.getYDown = function() {
return this.yDown_;
};
/**
* @param {boolean} right The tile index increases from left to right.
*/
ol.layer.TileLayer.prototype.setXRight = function(right) {
this.xRight_ = right;
};
/**
* @param {boolean} down The tile index increases from top to bottom.
*/
ol.layer.TileLayer.prototype.setYDown = function(down) {
this.yDown_ = down;
};
/**
* Get layer extent. Return null if the layer has no extent
* and no projection.
* @return {ol.UnreferencedBounds}
*/
ol.layer.TileLayer.prototype.getExtent = function() {
if (!goog.isNull(this.extent_)) {
return this.extent_;
}
if (!goog.isNull(this.projection_)) {
return this.projection_.getExtent();
}
return null;
};
/**
* Get tile size.
* @return {Array.<number>}
*/
ol.layer.TileLayer.prototype.getTileSize = function() {
return [this.tileWidth_, this.tileHeight_];
};
/**
* Get tile origin.
* @return {Array.<number>}
*/
ol.layer.TileLayer.prototype.getTileOrigin = function() {
if (goog.isDef(this.tileOriginX_) &&
goog.isDef(this.tileOriginY_)) {
return [this.tileOriginX_, this.tileOriginY_];
}
var errmsg = 'Cannot calculate tile origin; ';
if (goog.isDef(this.tileOriginCorner_)) {
var extent = this.getExtent();
if (!goog.isNull(extent)) {
var tileOriginX, tileOriginY;
switch (this.tileOriginCorner_) {
case "tl":
tileOriginX = extent.getMinX();
tileOriginY = extent.getMaxY();
break;
case "tr":
tileOriginX = extent.getMaxX();
tileOriginY = extent.getMaxY();
break;
case "bl":
tileOriginX = extent.getMinX();
tileOriginY = extent.getMinY();
break;
case "br":
tileOriginX = extent.getMaxX();
tileOriginY = extent.getMinY();
break;
default:
errmsg += 'tileOriginCorner value is incorrect.';
ol.error(errmsg);
}
return [tileOriginX, tileOriginY];
}
errmsg += 'layer has no extent.';
ol.error(errmsg);
}
errmsg += 'layer has no tileOriginCorner.';
ol.error(errmsg);
return null;
};
/**
* Get max resolution. Return undefined if the layer has no maxResolution,
* and no extent from which maxResolution could be derived.
* @return {number|undefined}
*/
ol.layer.TileLayer.prototype.getMaxResolution = function() {
if (!goog.isDef(this.maxResolution_)) {
var extent = this.getExtent();
if (!goog.isNull(extent)) {
this.maxResolution_ = Math.max(
(extent.getMaxX() - extent.getMinX()) / this.tileWidth_,
(extent.getMaxY() - extent.getMinY()) / this.tileHeight_);
}
}
return this.maxResolution_;
};
/**
* Get the number of the zoom levels.
* @return {number|undefined}
*/
ol.layer.TileLayer.prototype.getNumZoomLevels = function() {
return this.numZoomLevels_;
};
/**
* Get layer resolutions. Return null if the layer has no resolutions.
* @return {Array.<number>}
*/
ol.layer.TileLayer.prototype.getResolutions = function() {
if (goog.isNull(this.resolutions_)) {
var maxResolution = this.getMaxResolution(),
numZoomLevels = this.getNumZoomLevels();
if (goog.isDef(maxResolution) && goog.isDef(numZoomLevels)) {
this.resolutions_ = [];
for (var i = 0; i < numZoomLevels; i++) {
this.resolutions_[i] = maxResolution / Math.pow(2, i);
}
}
}
return this.resolutions_;
};
/**
* Set the layer URL.
* @param {string} url
*/
ol.layer.TileLayer.prototype.setUrl = function(url) {
this.url_ = url;
};
/**
* Set layer projection.
* @param {ol.Projection} projection
*/
ol.layer.TileLayer.prototype.setProjection = function(projection) {
this.projection_ = projection;
};
/**
* Set layer extent.
* @param {ol.Bounds} extent
*/
ol.layer.TileLayer.prototype.setExtent = function(extent) {
this.extent_ = extent;
};
/**
* Set tile origin.
* @param {number} tileOriginX
* @param {number} tileOriginY
*/
ol.layer.TileLayer.prototype.setTileOrigin = function(tileOriginX, tileOriginY) {
this.tileOriginX_ = tileOriginX;
this.tileOriginY_ = tileOriginY;
};
/**
* Set tile origin corner.
* @param {string} tileOriginCorner
*/
ol.layer.TileLayer.prototype.setTileOriginCorner = function(tileOriginCorner) {
this.tileOriginCorner_ = tileOriginCorner;
};
/**
* Set maximum resolution.
* @param {number} maxResolution
*/
ol.layer.TileLayer.prototype.setMaxResolution = function(maxResolution) {
this.maxResolution_ = maxResolution;
};
/**
* Set the number of zoom levels.
* @param {number} numZoomLevels
*/
ol.layer.TileLayer.prototype.setNumZoomLevels = function(numZoomLevels) {
this.numZoomLevels_ = numZoomLevels;
};
/**
* Set resolutions for the layer.
* @param {Array.<number>} resolutions
*/
ol.layer.TileLayer.prototype.setResolutions = function(resolutions) {
this.resolutions_ = resolutions;
};
/**
* Get a tile from the cache, or create a tile and add to
* the cache.
* @param url {string}
* @param bounds {ol.Bounds}
*/
ol.layer.TileLayer.prototype.getTile = function(url, bounds) {
var tile = this.cache_.get(url);
if (!goog.isDef(tile)) {
tile = new this.Tile(url, bounds);
this.cache_.set(tile.getUrl(), tile);
}
return tile;
};
/**
* Get a tile from the cache, or create a tile and add to
* the cache.
* @param {number} x
* @param {number} y
* @param {number} z
*/
ol.layer.TileLayer.prototype.getTileForXYZ = function(x, y, z) {
if (!this.validXY(x, y, z)) {
return null;
}
var tileUrl = this.getTileUrl(x, y, z);
var tile = this.cache_.get(tileUrl);
if (!goog.isDef(tile)) {
tile = new this.Tile(tileUrl);
this.cache_.set(tileUrl, tile);
}
return tile;
};
/**
* Determine if the tile x/y/z intersects the layer extent. Always
* return true if the layer has no extent.
* @param {number} x
* @param {number} y
* @param {number} z
* @return {boolean}
*/
ol.layer.TileLayer.prototype.validXY = function(x, y, z) {
var extent = this.getExtent();
if (goog.isNull(extent)) {
return true;
}
var extentMinX = extent.getMinX(),
extentMinY = extent.getMinY(),
extentMaxX = extent.getMaxX(),
extentMaxY = extent.getMaxY();
var tileOrigin = this.getTileOrigin(),
tileOriginX = tileOrigin[0],
tileOriginY = tileOrigin[1];
var resolution = this.getResolutions()[z];
var tileWidth = this.tileWidth_ * resolution,
tileHeight = this.tileHeight_ * resolution;
var minX, maxX;
if (this.xRight_) {
minX = Math.floor((extentMinX - tileOriginX) / tileWidth);
maxX = Math.ceil((extentMaxX - tileOriginX) / tileWidth) - 1;
} else {
minX = Math.floor((tileOriginX - extentMaxX) / tileWidth);
maxX = Math.ceil((tileOriginX - extentMinX) / tileWidth) - 1;
}
var minY, maxY;
if (this.yDown_) {
minY = Math.floor((tileOriginY - extentMaxY) / tileHeight);
maxY = Math.ceil((tileOriginY - extentMinY) / tileHeight) - 1;
} else {
minY = Math.floor((extentMinY - tileOriginY) / tileHeight);
maxY = Math.ceil((extentMaxY - tileOriginY) / tileHeight) - 1;
}
return x >= minX && x <= maxX && y >= minY && y <= maxY;
};
/**
* Get data from the layer. This is the layer's main API function.
* @param {ol.Bounds} bounds
* @param {number} resolution
*/
ol.layer.TileLayer.prototype.getData = function(bounds, resolution) {
var me = this,
zoomAndRes = me.getZoomAndRes(resolution),
zoom = zoomAndRes[0];
resolution = zoomAndRes[1];
// define some values used for the actual tiling
var boundsMinX = bounds.getMinX(),
boundsMaxX = bounds.getMaxX(),
boundsMinY = bounds.getMinY(),
boundsMaxY = bounds.getMaxY(),
tileWidth = me.tileWidth_,
tileHeight = me.tileHeight_,
tileOrigin = me.getTileOrigin(),
tileOriginX = tileOrigin[0],
tileOriginY = tileOrigin[1],
tileWidthGeo = tileWidth * resolution,
tileHeightGeo = tileHeight * resolution;
// make sure we don't create tiles outside the layer extent
var extent = this.getExtent();
if (extent) {
boundsMinX = Math.max(boundsMinX, extent.getMinX());
boundsMaxX = Math.min(boundsMaxX, extent.getMaxX());
boundsMinY = Math.max(boundsMinY, extent.getMinY());
boundsMaxY = Math.min(boundsMaxY, extent.getMaxY());
}
var offsetX = Math.floor(
(boundsMinX - tileOriginX) / tileWidthGeo),
offsetY = Math.floor(
(tileOriginY - boundsMaxY) / tileHeightGeo),
gridLeft = tileOriginX + tileWidthGeo * offsetX,
gridTop = tileOriginY - tileHeightGeo * offsetY;
// now tile
var tiles = [],
tile,
url,
tileBottom, tileRight, tileBounds;
for (var y=0, tileTop=gridTop; tileTop > boundsMinY;
++y, tileTop-=tileHeightGeo) {
tiles[y] = [];
tileBottom = tileTop - tileHeightGeo;
for (var x=0, tileLeft=gridLeft; tileLeft < boundsMaxX;
++x, tileLeft+=tileWidthGeo) {
tileRight = tileLeft + tileWidthGeo;
tileBounds = new ol.Bounds(tileLeft, tileBottom,
tileRight, tileTop, this.projection_);
url = this.getTileUrl(offsetX + x, offsetY + y, zoom);
tile = this.getTile(url, tileBounds);
tiles[y][x] = tile;
}
}
return new ol.TileSet(tiles, tileWidth, tileHeight, resolution);
};
/**
* Get the zoom level (z) and layer resolution for the given resolution.
* @param {number} resolution
* @return {Array.<number>}
*/
ol.layer.TileLayer.prototype.getZoomAndRes = function(resolution) {
var delta = Number.POSITIVE_INFINITY,
currentDelta,
resolutions = this.getResolutions(),
zoom;
for (var i=resolutions.length-1; i>=0; --i) {
currentDelta = Math.abs(resolutions[i] - resolution);
if (currentDelta > delta) {
break;
}
delta = currentDelta;
}
zoom = i + 1;
return [zoom, resolutions[zoom]];
};

View File

@@ -1,74 +0,0 @@
goog.provide('ol.layer.WMS');
goog.require('goog.Uri');
goog.require('ol.layer.TileLayer');
/**
* Class for WMS layers.
*
* @export
* @constructor
* @extends {ol.layer.TileLayer}
* @param {string} url The WMS URL.
* @param {Array.<string>} layers List of layers.
* @param {string|undefined} format Image format (e.g. "image/jpeg")
*/
ol.layer.WMS = function(url, layers, format) {
goog.base(this);
this.setUrl(url);
/**
* @private
* @type {Array.<string>}
*/
this.layers_ = layers;
/**
* @private
* @type {string|undefined}
*/
this.format_ = format;
};
goog.inherits(ol.layer.WMS, ol.layer.TileLayer);
/**
* @const
* @type {Object}
*/
ol.layer.WMS.prototype.DEFAULT_PARAMS = {
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetMap",
"STYLES": "",
"FORMAT": "image/png"
};
/**
* @inheritDoc
*/
ol.layer.WMS.prototype.getTileUrl = function(x, y, z) {
var tileOrigin = this.getTileOrigin(),
tileOriginX = tileOrigin[0],
tileOriginY = tileOrigin[1];
var resolution = this.getResolutions()[z];
var tileWidth = this.tileWidth_ * resolution,
tileHeight = this.tileHeight_ * resolution;
var minX = tileOriginX + (x * tileWidth),
maxY = tileOriginY - (y * tileHeight),
maxX = minX + tileWidth,
minY = maxY - tileHeight;
var qd = new goog.Uri.QueryData();
qd.extend(this.DEFAULT_PARAMS);
qd.set('WIDTH', this.tileWidth_);
qd.set('HEIGHT', this.tileHeight_);
qd.set('BBOX', [minX, minY, maxX, maxY].join(','));
qd.set('LAYERS', [this.layers_].join(','));
// FIXME this requires a projection in the layer, which should
// not be required
qd.set('SRS', this.projection_.getCode());
var uri = new goog.Uri(this.getUrl());
uri.setQueryData(qd);
return uri.toString();
};

View File

@@ -1,35 +0,0 @@
goog.provide('ol.layer.XYZ');
goog.require('ol.layer.TileLayer');
goog.require('ol.Projection');
goog.require('ol.TileSet');
/**
* Class for XYZ layers.
*
* @export
* @constructor
* @extends {ol.layer.TileLayer}
* @param {string} url URL template. E.g.
* http://a.tile.openstreetmap.org/{z}/{x}/{y}.png.
*/
ol.layer.XYZ = function(url) {
goog.base(this);
this.setUrl(url);
this.setProjection(new ol.Projection("EPSG:3857"));
this.setNumZoomLevels(22);
};
goog.inherits(ol.layer.XYZ, ol.layer.TileLayer);
/**
* @inheritDoc
*/
ol.layer.XYZ.prototype.getTileUrl = function(x, y, z) {
var base = this.getUrl();
return base.replace('{x}', x + '')
.replace('{y}', y + '')
.replace('{z}', z + '');
};

19
src/ol/object_test.js Normal file
View File

@@ -0,0 +1,19 @@
goog.require('goog.testing.jsunit');
goog.require('ol');
goog.require('ol3.Object');
function testObject1() {
var obj = {k: 1};
obj = ol.object(obj);
assertTrue(obj instanceof ol3.Object);
assertEquals(1, obj.get('k'));
}
function testObject2() {
var obj1 = new ol3.Object();
var obj2 = ol.object(obj1);
assertTrue(obj2 === obj1);
}

168
src/ol/ol.js Normal file
View File

@@ -0,0 +1,168 @@
goog.provide('ol');
goog.provide('ol.layer');
goog.require('goog.dom');
goog.require('ol3.Collection');
goog.require('ol3.Coordinate');
goog.require('ol3.Layer');
goog.require('ol3.Map');
goog.require('ol3.Object');
goog.require('ol3.Projection');
goog.require('ol3.createMap');
goog.require('ol3.layer.OpenStreetMap');
goog.exportSymbol('ol', ol);
/**
* @typedef {Array|ol3.Collection}
*/
ol.Collection;
/**
* @typedef {Array.<number>|ol3.Coordinate|{x: number, y: number}}
*/
ol.Coordinate;
/**
* @typedef {{center: (ol.Coordinate|undefined),
* layers: (ol.Collection|undefined),
* renderTo: (Element|string|undefined),
* resolution: (number|undefined),
* zoom: (number|undefined)}}
*/
ol.MapOptions;
/**
* @typedef {Object|ol3.Object}
*/
ol.Object;
/**
* @typedef {ol3.Projection|string}
*/
ol.Projection;
/**
* @param {ol.Collection} collection Collection.
* @return {ol3.Collection} Collection.
*/
ol.collection = function(collection) {
if (collection instanceof ol3.Collection) {
return collection;
} else if (goog.isArray(collection)) {
var array = /** @type {Array} */ collection;
return new ol3.Collection(collection);
} else {
return null;
}
};
goog.exportProperty(ol, 'collection', ol.collection);
/**
* @param {ol.Coordinate} coordinate Coordinate.
* @return {ol3.Coordinate} Coordinate.
*/
ol.coordinate = function(coordinate) {
if (coordinate instanceof ol3.Coordinate) {
return coordinate;
} else if (goog.isArray(coordinate)) {
var array = /** @type {Array.<number>} */ coordinate;
return new ol3.Coordinate(array[1], array[0]);
} else if (goog.isObject(coordinate)) {
var object = /** @type {{x: number, y: number}} */ coordinate;
return new ol3.Coordinate(object.x, object.y);
} else {
return null;
}
};
goog.exportProperty(ol, 'coordinate', ol.coordinate);
goog.exportProperty(ol, 'layer', ol.layer);
/**
* @return {ol3.Layer} Layer.
*/
ol.layer.osm = function() {
return new ol3.layer.OpenStreetMap();
};
goog.exportProperty(ol.layer, 'osm', ol.layer.osm);
/**
* @param {ol.MapOptions=} opt_mapOptions Options.
* @return {ol3.Map} Map.
*/
ol.map = function(opt_mapOptions) {
var options = opt_mapOptions || {};
var center = ol.coordinate(/** @type {ol.Coordinate} */
(goog.object.get(options, 'center', null)));
var layers = ol.collection(/** @type {ol.Collection} */
(goog.object.get(options, 'layers', null)));
var projection = ol.projection(/** @type {ol.Projection} */
(goog.object.get(options, 'projection', 'EPSG:3857')));
var resolution = /** @type {number|undefined} */
goog.object.get(options, 'resolution');
if (!goog.isDef(resolution) && goog.object.containsKey(options, 'zoom')) {
var zoom = /** @type {number} */ goog.object.get(options, 'zoom');
resolution = ol3.Projection.EPSG_3857_HALF_SIZE / (128 << zoom);
}
var target = goog.dom.getElement(/** @type {Element|string} */
(goog.object.get(options, 'renderTo', 'map')));
var userProjection = ol.projection(/** @type {ol.Projection} */
(goog.object.get(options, 'userProjection', 'EPSG:4326')));
var map = ol3.createMap(target, {
'layers': layers,
'projection': projection,
'resolution': resolution,
'userProjection': userProjection
});
if (!goog.isNull(center)) {
map.setUserCenter(center);
}
return map;
};
goog.exportProperty(ol, 'map', ol.map);
/**
* @param {ol.Object} object Object.
* @return {ol3.Object} Object.
*/
ol.object = function(object) {
if (object instanceof ol3.Object) {
return object;
} else if (goog.isObject(object)) {
var values = /** @type {Object} */ object;
return new ol3.Object(values);
} else {
return null;
}
};
goog.exportProperty(ol, 'object', ol.object);
/**
* @param {ol.Projection} projection Projection.
* @return {ol3.Projection} Projection.
*/
ol.projection = function(projection) {
if (projection instanceof ol3.Projection) {
return projection;
} else if (goog.isString(projection)) {
var code = /** @type {string} */ projection;
return ol3.Projection.getFromCode(code);
} else {
return null;
}
};
goog.exportProperty(ol, 'projection', ol.projection);

View File

@@ -1,314 +0,0 @@
goog.provide('ol.renderer.Composite');
goog.require('ol.renderer.MapRenderer');
goog.require('ol.renderer.LayerRenderer');
goog.require('ol.layer.Layer');
goog.require('ol.Loc');
goog.require('goog.array');
goog.require('goog.dom');
goog.require('goog.style');
goog.require('goog.math.Coordinate');
/**
* @constructor
* @param {!Element} container
* @extends {ol.renderer.MapRenderer}
*/
ol.renderer.Composite = function(container) {
goog.base(this, container);
/**
* @type {Array.<ol.renderer.LayerRenderer>}
* @private
*/
this.renderers_ = [];
/**
* Pixel buffer for renderer container.
*
* @type {number}
* @private
*/
this.buffer_ = 128;
/**
* @type {Element}
* @private
*/
this.target_ = null;
/**
* The current top left corner location of the target element (map coords).
*
* @type {ol.Loc}
* @private
*/
this.targetOrigin_ = null;
/**
* The pixel offset of the target element with respect to its container.
*
* @type {goog.math.Coordinate}
* @private
*/
this.targetOffset_ = null;
/**
* @type {Object}
* @private
*/
this.layerContainers_ = {};
};
goog.inherits(ol.renderer.Composite, ol.renderer.MapRenderer);
/**
* @param {Array.<ol.layer.Layer>} layers
* @param {ol.Loc} center
* @param {number} resolution
* @param {boolean} animate
*/
ol.renderer.Composite.prototype.draw = function(layers, center, resolution, animate) {
if (goog.isNull(this.target_)) {
// first rendering
this.createTarget_(center, resolution);
}
// TODO: deal with layer order and removal
if (this.renderedResolution_) {
if (resolution !== this.renderedResolution_) {
// TODO: apply transition to old target
this.resetTarget_(center, resolution);
}
}
this.renderedResolution_ = resolution;
// shift target element to account for center change
if (this.renderedCenter_) {
this.shiftTarget_(center, resolution);
}
this.renderedCenter_ = center;
// update each layer renderer
var renderer;
for (var i=0, ii=layers.length; i<ii; ++i) {
renderer = this.getOrCreateRenderer_(layers[i], i);
renderer.draw(center, resolution);
}
};
/**
* Create a new target element for layer renderer containers.
*
* @param {ol.Loc} center
* @param {number} resolution
*/
ol.renderer.Composite.prototype.createTarget_ = function(center, resolution) {
this.targetOrigin_ = this.getOriginForCenterAndRes_(center, resolution);
var containerSize = this.getContainerSize();
var containerWidth = containerSize.width;
var containerHeight = containerSize.height;
var buffer = this.buffer_;
var targetWidth = containerWidth + (2 * buffer);
var targetHeight = containerHeight + (2 * buffer);
var offset = new goog.math.Coordinate(-buffer, -buffer);
var target = goog.dom.createDom('div', {
'class': 'ol-renderer-composite',
'style': 'width:' + targetWidth + 'px;height:' + targetHeight + 'px;' +
'top:' + offset.y + 'px;left:' + offset.x + 'px;' +
'position:absolute'
});
this.target_ = target;
this.targetOffset_ = offset;
this.renderedCenter_ = center;
goog.dom.appendChild(this.container_, target);
};
/**
* @param {ol.Loc} center
* @param {number} resolution
* @return {ol.Loc}
*/
ol.renderer.Composite.prototype.getOriginForCenterAndRes_ = function(center, resolution) {
var containerSize = this.getContainerSize();
var containerWidth = containerSize.width;
var containerHeight = containerSize.height;
var buffer = this.buffer_;
var targetWidth = containerWidth + (2 * buffer);
var targetHeight = containerHeight + (2 * buffer);
return new ol.Loc(
center.getX() - (resolution * targetWidth / 2),
center.getY() + (resolution * targetHeight / 2)
);
};
/**
* Adjust the position of the renderer target given the new center.
*
* @param {ol.Loc} center
* @param {number} resolution
*/
ol.renderer.Composite.prototype.shiftTarget_ = function(center, resolution) {
var oldCenter = this.renderedCenter_;
var dx = Math.round((oldCenter.getX() - center.getX()) / resolution);
var dy = Math.round((center.getY() - oldCenter.getY()) / resolution);
if (!(dx == 0 && dy == 0)) {
var offset = this.targetOffset_;
offset.x += Math.round((oldCenter.getX() - center.getX()) / resolution);
offset.y += Math.round((center.getY() - oldCenter.getY()) / resolution);
goog.style.setPosition(this.target_, offset);
}
};
/**
* Reposition the target element back to the original offset.
*
* @param {ol.Loc} center
* @param {number} resolution
*/
ol.renderer.Composite.prototype.resetTarget_ = function(center, resolution) {
this.targetOrigin_ = this.getOriginForCenterAndRes_(center, resolution);
for (var i=0, ii=this.renderers_.length; i<ii; ++i) {
this.renderers_[i].setContainerOrigin(this.targetOrigin_);
}
var offset = new goog.math.Coordinate(-this.buffer_, -this.buffer_);
this.targetOffset_ = offset;
this.renderedCenter_ = center;
goog.style.setPosition(this.target_, offset);
};
/**
* @param {ol.layer.Layer} layer
* @param {number} index
*/
ol.renderer.Composite.prototype.getOrCreateRenderer_ = function(layer, index) {
var renderer = this.getRenderer_(layer);
if (goog.isNull(renderer)) {
renderer = this.createRenderer_(layer);
goog.array.insertAt(this.renderers_, renderer, index);
}
return renderer;
};
/**
* @param {ol.layer.Layer} layer
* @return {ol.renderer.LayerRenderer}
*/
ol.renderer.Composite.prototype.getRenderer_ = function(layer) {
function finder(candidate) {
return candidate.getLayer() === layer;
}
var renderer = goog.array.find(this.renderers_, finder);
return /** @type {ol.renderer.LayerRenderer} */ renderer;
};
/**
* @param {ol.layer.Layer} layer
*/
ol.renderer.Composite.prototype.createRenderer_ = function(layer) {
var Renderer = this.pickRendererType(layer);
goog.asserts.assert(Renderer, "No supported renderer for layer: " + layer);
var container = goog.dom.createDom('div', {
'class': 'ol-renderer-composite-layer',
'style': 'width:100%;height:100%;top:0;left:0;position:absolute'
});
goog.dom.appendChild(this.target_, container);
var renderer = new Renderer(container, layer);
renderer.setContainerOrigin(this.targetOrigin_);
this.layerContainers_[goog.getUid(renderer)] = container;
return renderer;
};
/**
* @param {ol.renderer.LayerRenderer} renderer
* @return {Element}
*/
ol.renderer.Composite.prototype.getRendererContainer_ = function(renderer) {
var container = this.layerContainers_[goog.getUid(renderer)];
goog.asserts.assert(goog.isDef(container));
return container;
};
/**
* List of preferred renderer types. Layer renderers have a getType method
* that returns a string describing their type. This list determines the
* preferences for picking a layer renderer.
*
* @type {Array.<string>}
*/
ol.renderer.Composite.preferredRenderers = ["svg", "canvas", "vml"];
/**
* @param {ol.layer.Layer} layer
* @returns {Function}
*/
ol.renderer.Composite.prototype.pickRendererType = function(layer) {
// maps candidate renderer types to candidate renderers
var types = {};
function picker(Candidate) {
var supports = Candidate['isSupported']() && Candidate['canRender'](layer);
if (supports) {
types[Candidate['getType']()] = Candidate;
}
return supports;
}
var Candidates = goog.array.filter(ol.renderer.Composite.registry_, picker);
// check to see if any preferred renderers are available
var preferences = ol.renderer.Composite.preferredRenderers;
var Renderer;
for (var i=0, ii=preferences.length; i<ii; ++i) {
Renderer = types[preferences[i]];
if (Renderer) {
break;
}
}
// if we didn't find any of the preferred renderers, use the first
return Renderer || Candidates[0] || null;
};
/**
* @type {Array.<Function>}
* @private
*/
ol.renderer.Composite.registry_ = [];
/**
* @param {Function} Renderer
*/
ol.renderer.Composite.register = function(Renderer) {
ol.renderer.Composite.registry_.push(Renderer);
};
/**
* return {string}
*/
ol.renderer.Composite.getType = function() {
// TODO: revisit
return "composite";
};
/**
* TODO: determine if there is a better way to register these renderers
*
* @export
* @return {boolean}
*/
ol.renderer.Composite.isSupported = function() {
return true;
};
ol.renderer.MapRenderer.register(ol.renderer.Composite);

View File

@@ -1,98 +0,0 @@
goog.provide('ol.renderer.LayerRenderer');
goog.require('goog.math.Coordinate');
goog.require('goog.math.Size');
/**
* A single layer renderer that will be created by the composite map renderer.
*
* @constructor
* @param {!Element} container
* @param {!ol.layer.Layer} layer
*/
ol.renderer.LayerRenderer = function(container, layer) {
/**
* @type {!Element}
* @protected
*/
this.container_ = container;
/**
* @type {goog.math.Size}
* @private
*/
this.containerSize_ = null;
/**
* Location of the top-left corner of the renderer container in map coords.
*
* @type {ol.Loc}
* @protected
*/
this.containerOrigin_ = null;
/**
* @type {!ol.layer.Layer}
* @protected
*/
this.layer_ = layer;
};
/**
* @return {goog.math.Size}
* @protected
*/
ol.renderer.LayerRenderer.prototype.getContainerSize = function() {
// TODO: listen for resize and set this.constainerSize_ null
// https://github.com/openlayers/ol3/issues/2
if (goog.isNull(this.containerSize_)) {
this.containerSize_ = goog.style.getSize(this.container_);
}
return this.containerSize_;
};
/**
* Set the location of the top-left corner of the renderer container.
*
* @param {ol.Loc} origin The container origin.
*/
ol.renderer.LayerRenderer.prototype.setContainerOrigin = function(origin) {
this.containerOrigin_ = origin;
};
/**
* Get layer being rendered.
*
* @returns {!ol.layer.Layer}
*/
ol.renderer.LayerRenderer.prototype.getLayer = function() {
return this.layer_;
};
/**
* Get an identifying string for this renderer.
*
* @returns {string|undefined}
*/
ol.renderer.LayerRenderer.prototype.getType = function() {};
/**
* Determine if this renderer is supported in the given environment.
*
* @returns {boolean}
*/
ol.renderer.LayerRenderer.isSupported = function() {
return false;
};
/**
* Determine if this renderer is capable of renderering the given layer.
*
* @param {ol.layer.Layer} layer
* @returns {boolean}
*/
ol.renderer.LayerRenderer.canRender = function(layer) {
return false;
};

View File

@@ -1,110 +0,0 @@
goog.provide('ol.renderer.MapRenderer');
goog.require('goog.style');
goog.require('goog.math.Size');
/**
* @constructor
* @param {!Element} container
*/
ol.renderer.MapRenderer = function(container) {
/**
* @type !Element
* @protected
*/
this.container_ = container;
/**
* @type {goog.math.Size}
* @private
*/
this.containerSize_ = null;
/**
* @type {ol.Loc}
* @protected
*/
this.renderedCenter_;
/**
* @type {number}
* @protected
*/
this.renderedResolution_;
};
/**
* @return {goog.math.Size}
* @protected
*/
ol.renderer.MapRenderer.prototype.getContainerSize = function() {
// TODO: listen for resize and set this.constainerSize_ null
// https://github.com/openlayers/ol3/issues/2
if (goog.isNull(this.containerSize_)) {
this.containerSize_ = goog.style.getSize(this.container_);
}
return this.containerSize_;
};
/**
* @param {Array.<ol.layer.Layer>} layers
* @param {ol.Loc} center
* @param {number} resolution
* @param {boolean} animate
*/
ol.renderer.MapRenderer.prototype.draw = function(layers, center, resolution, animate) {
};
/**
* @return {number} The rendered resolution.
*/
ol.renderer.MapRenderer.prototype.getResolution = function() {
return this.renderedResolution_;
};
/**
* TODO: determine a closure friendly way to register map renderers.
* @type {Array}
* @private
*/
ol.renderer.MapRenderer.registry_ = [];
/**
* @param {Function} Renderer
*/
ol.renderer.MapRenderer.register = function(Renderer) {
ol.renderer.MapRenderer.registry_.push(Renderer);
};
/**
* @param {Array.<string>} preferences List of preferred renderer types.
* @returns {Function} A renderer constructor.
*/
ol.renderer.MapRenderer.pickRendererType = function(preferences) {
// map of candidate renderer types to candidate renderers
var types = {};
function picker(Candidate) {
var supports = Candidate.isSupported();
if (supports) {
types[Candidate.getType()] = Candidate;
}
return supports;
}
var Candidates = goog.array.filter(ol.renderer.MapRenderer.registry_, picker);
// check to see if any preferred renderers are available
var Renderer;
for (var i=0, ii=preferences.length; i<ii; ++i) {
Renderer = types[preferences[i]];
if (Renderer) {
break;
}
}
// if we didn't find any of the preferred renderers, use the first
return Renderer || Candidates[0] || null;
};

View File

@@ -1,352 +0,0 @@
goog.provide('ol.renderer.TileLayerRenderer');
goog.require('ol.renderer.LayerRenderer');
goog.require('ol.layer.TileLayer');
goog.require('ol.renderer.Composite');
goog.require('ol.TileSet');
goog.require('ol.Bounds');
goog.require('goog.style');
goog.require('goog.math.Box');
/**
* A single layer renderer that will be created by the composite map renderer.
*
* @constructor
* @param {!Element} container
* @param {!ol.layer.Layer} layer
* @extends {ol.renderer.LayerRenderer}
*/
ol.renderer.TileLayerRenderer = function(container, layer) {
goog.base(this, container, layer);
/**
* @type {Array.<number>}
*/
this.layerResolutions_ = layer.getResolutions();
/**
* @type {Array.<number>}
*/
this.tileOrigin_ = layer.getTileOrigin();
/**
* @type {Array.<number>}
*/
this.tileSize_ = layer.getTileSize();
/**
* @type {boolean}
*/
this.xRight_ = layer.getXRight();
/**
* @type {boolean}
*/
this.yDown_ = layer.getYDown();
/**
* @type {number|undefined}
* @private
*/
this.renderedResolution_ = undefined;
/**
* @type {number|undefined}
* @private
*/
this.renderedZ_ = undefined;
};
goog.inherits(ol.renderer.TileLayerRenderer, ol.renderer.LayerRenderer);
/**
* Render the layer.
*
* @param {!ol.Loc} center
* @param {number} resolution
*/
ol.renderer.TileLayerRenderer.prototype.draw = function(center, resolution) {
if (resolution !== this.renderedResolution_) {
this.changeResolution_(resolution);
}
var z = this.renderedZ_;
var tileOrigin = this.tileOrigin_;
var offset = this.getTileOffset_();
var tileBox = this.getTileBox_(center, resolution);
var fragment = document.createDocumentFragment();
var ijz, key, tile, xyz, box, img, newTiles = false;
for (var i=tileBox.left; i<tileBox.right; ++i) {
for (var j=tileBox.top; j<tileBox.bottom; ++j) {
ijz = [i, j, z];
key = ijz.join(",");
tile = this.renderedTiles_[key];
if (!tile) {
xyz = this.getTileCoordsFromNormalizedCoords_(ijz);
tile = this.layer_.getTileForXYZ(xyz[0], xyz[1], xyz[2]);
if (tile) {
if (!tile.isLoaded() && !tile.isLoading()) {
tile.load();
}
this.renderedTiles_[key] = tile;
box = this.getTilePixelBox_(ijz, resolution);
img = tile.getImg();
img.style.top = (box.top - offset.y) + "px";
img.style.left = (box.left - offset.x) + "px";
/**
* We need to set the size here even if the scale is 1
* because the image may have been scaled previously. If
* we want to avoid setting size unnecessarily, the tile
* should keep track of the scale.
*/
img.style.height = (box.bottom - box.top) + "px";
img.style.width = (box.right - box.left) + "px";
goog.dom.appendChild(fragment, img);
newTiles = true;
}
}
}
}
if (newTiles) {
this.container_.appendChild(fragment);
}
this.renderedTileBox_ = tileBox;
this.removeInvisibleTiles_();
};
/**
* Get the pixel offset between the tile origin and the container origin.
* TODO: cache this and invalidate it with changes to the container origin.
*
* @return {goog.math.Coordinate}
*/
ol.renderer.TileLayerRenderer.prototype.getTileOffset_ = function() {
var resolution = this.renderedResolution_;
return new goog.math.Coordinate(
Math.round((this.containerOrigin_.getX() - this.tileOrigin_[0]) / resolution),
Math.round((this.tileOrigin_[1] - this.containerOrigin_.getY()) / resolution)
);
};
/**
* @param {Array.<number>} ijz
* @param {number} resolution
* @return {goog.math.Box}
*/
ol.renderer.TileLayerRenderer.prototype.getTilePixelBox_ = function(ijz, resolution) {
var tileResolution = this.layerResolutions_[ijz[2]];
var scale = resolution / tileResolution;
var tileSize = this.tileSize_;
// desired tile size (in fractional pixels)
var fpxTileWidth = tileSize[0] / scale;
var fpxTileHeight = tileSize[1] / scale;
var col = ijz[0];
var left = Math.round(col * fpxTileWidth); // inclusive
var right = Math.round((col + 1) * fpxTileWidth); // exclusive
var row = ijz[1];
var top = Math.round(row * fpxTileHeight); // inclusive
var bottom = Math.round((row + 1) * fpxTileWidth); // exclusive
return new goog.math.Box(top, right, bottom, left);
};
/**
* @param {ol.Loc} loc
* @param {number} resolution
* @return {goog.math.Coordinate}
*/
ol.renderer.TileLayerRenderer.prototype.getNormalizedTileCoord_ = function(loc, resolution) {
var tileOrigin = this.tileOrigin_;
var tileSize = this.tileSize_;
var pair = this.getPreferredResAndZ_(resolution);
var tileResolution = pair[0];
var z = pair[1];
var scale = resolution / tileResolution;
// offset from tile origin in pixel space
var dx = Math.floor((loc.getX() - tileOrigin[0]) / resolution);
var dy = Math.floor((tileOrigin[1] - loc.getY()) / resolution);
// desired tile size (in fractional pixels)
var fpxTileWidth = tileSize[0] / scale;
var fpxTileHeight = tileSize[1] / scale;
// determine normalized col number (0 based, ascending right)
var col = Math.floor(dx / fpxTileWidth);
// determine normalized row number (0 based, ascending down)
var row = Math.floor(dy / fpxTileHeight);
var box = this.getTilePixelBox_([col, row, z], resolution);
// adjust col to allow for stretched tiles
if (dx < box.left) {
col -= 1;
} else if (dx >= box.right) {
col += 1;
}
// adjust row to allow for stretched tiles
if (dy < box.top) {
row -= 1;
} else if (dy >= box.bottom) {
row += 1;
}
return new goog.math.Coordinate(col, row);
};
/**
* @param {number} resolution
* @return {Array.<number>}
*/
ol.renderer.TileLayerRenderer.prototype.getPreferredResAndZ_ = (function() {
var cache = {};
return function(resolution) {
if (resolution in cache) {
return cache[resolution];
}
var minDiff = Number.POSITIVE_INFINITY;
var candidate, diff, z, r;
for (var i=0, ii=this.layerResolutions_.length; i<ii; ++i) {
// assumes sorted resolutions
candidate = this.layerResolutions_[i];
diff = Math.abs(resolution - candidate);
if (diff < minDiff) {
z = i;
r = candidate;
minDiff = diff;
} else {
break;
}
}
var pair = cache[resolution] = [r, z];
return pair;
};
})();
/**
* Tiles rendered at the current resolution;
* @type {Object}
*/
ol.renderer.TileLayerRenderer.prototype.renderedTiles_ = {};
/**
* @param {Array.<number>} ijz
* @return {Array.<number>}
*/
ol.renderer.TileLayerRenderer.prototype.getTileCoordsFromNormalizedCoords_ = function(ijz) {
return [
this.xRight_ ? ijz[0] : -ijz[0] - 1,
this.yDown_ ? ijz[1] : -ijz[1] - 1,
ijz[2]
];
};
/**
* @param {ol.Loc} center
* @param {number} resolution
* @return {goog.math.Box}
*/
ol.renderer.TileLayerRenderer.prototype.getTileBox_ = function(center, resolution) {
var size = this.getContainerSize();
var halfWidth = size.width / 2;
var halfHeight = size.height / 2;
var leftTop = new ol.Loc(
center.getX() - (resolution * halfWidth),
center.getY() + (resolution * halfHeight));
var rightBottom = new ol.Loc(
center.getX() + (resolution * halfWidth),
center.getY() - (resolution * halfHeight));
var ltCoord = this.getNormalizedTileCoord_(leftTop, resolution);
var rbCoord = this.getNormalizedTileCoord_(rightBottom, resolution);
// right and bottom are treated as excluded, so we increment for the box
rbCoord.x += 1;
rbCoord.y += 1;
return goog.math.Box.boundingBox(ltCoord, rbCoord);
};
/**
* Get rid of tiles outside the rendered extent.
*/
ol.renderer.TileLayerRenderer.prototype.removeInvisibleTiles_ = function() {
var index, prune, i, j, z, tile;
var box = this.renderedTileBox_;
for (var ijz in this.renderedTiles_) {
index = ijz.split(",");
i = +index[0];
j = +index[1];
z = +index[2];
prune = this.renderedZ_ !== z ||
i < box.left || // beyond on the left side
i >= box.right || // beyond on the right side
j < box.top || // above
j >= box.bottom; // below
if (prune) {
tile = this.renderedTiles_[ijz];
delete this.renderedTiles_[ijz];
this.container_.removeChild(tile.getImg());
}
}
};
/**
* Deal with changes in resolution.
* TODO: implement the animation
*
* @param {number} resolution New resolution.
*/
ol.renderer.TileLayerRenderer.prototype.changeResolution_ = function(resolution) {
var pair = this.getPreferredResAndZ_(resolution);
this.renderedZ_ = pair[1];
this.renderedResolution_ = resolution;
this.renderedTiles_ = {};
goog.dom.removeChildren(this.container_);
};
/**
* Get an identifying string for this renderer.
*
* @export
* @returns {string}
*/
ol.renderer.TileLayerRenderer.getType = function() {
// TODO: revisit
return "tile";
};
/**
* Determine if this renderer type is supported in this environment.
*
* @export
* @return {boolean} This renderer is supported.
*/
ol.renderer.TileLayerRenderer.isSupported = function() {
return true;
};
/**
* Determine if this renderer can render the given layer.
*
* @export
* @param {ol.layer.Layer} layer The candidate layer.
* @return {boolean} This renderer is capable of rendering the layer.
*/
ol.renderer.TileLayerRenderer.canRender = function(layer) {
return layer instanceof ol.layer.TileLayer;
};
ol.renderer.Composite.register(ol.renderer.TileLayerRenderer);

View File

@@ -1,276 +0,0 @@
/**
* @fileoverview WebGL based MapRenderer drawing all the supplied layers in OpenGL
*/
goog.provide('ol.renderer.WebGL');
goog.require('ol.renderer.MapRenderer');
goog.require('ol.layer.Layer');
goog.require('ol.Loc');
goog.require('goog.events');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.vec.Mat4');
goog.require('goog.webgl');
/**
* Initialization of the native WebGL renderer (canvas, context, layers)
* @constructor
* @param {!Element} container
* @extends {ol.renderer.MapRenderer}
*/
ol.renderer.WebGL = function(container) {
/**
* @private
* @type {!Element}
*/
this.canvas_ = goog.dom.createDom('canvas', 'ol-renderer-webgl-canvas'); // Suppose to have: style: 'width:100%;height:100%;'
/**
* @private
* @type {WebGLRenderingContext}
*/
this.gl_ = (this.canvas_.getContext('experimental-webgl', {
'alpha': false,
'depth': false,
'antialias': true,
'stencil': false,
'preserveDrawingBuffer': false
}));
goog.asserts.assert(!goog.isNull(this.gl_), "The WebGL is not supported on your browser. Check http://get.webgl.org/");
goog.dom.append(container, this.canvas_);
goog.base(this, container);
/**
* @private
* @type {Object.<string, WebGLTexture>}
*/
this.textureCache_ = {};
var gl = this.gl_;
var clearColor = [0, 0, 0]; // hardcoded background color
gl.clearColor(clearColor[0], clearColor[1], clearColor[2], 1);
gl.disable(goog.webgl.DEPTH_TEST);
gl.disable(goog.webgl.SCISSOR_TEST);
gl.disable(goog.webgl.CULL_FACE);
var fragmentShader = gl.createShader(goog.webgl.FRAGMENT_SHADER);
gl.shaderSource(fragmentShader, [
'precision mediump float;',
'',
'uniform sampler2D uTexture;',
'',
'varying vec2 vTexCoord;',
'',
'void main(void) {',
' gl_FragColor = vec4(vec3(texture2D(uTexture, vTexCoord)), 1.);',
'}'
].join('\n'));
gl.compileShader(fragmentShader);
if (!gl.getShaderParameter(fragmentShader, goog.webgl.COMPILE_STATUS)) {
window.console.log(gl.getShaderInfoLog(fragmentShader));
goog.asserts.assert(gl.getShaderParameter(fragmentShader, goog.webgl.COMPILE_STATUS));
}
var vertexShader = gl.createShader(goog.webgl.VERTEX_SHADER);
gl.shaderSource(vertexShader, [
'attribute vec2 aPosition;',
'attribute vec2 aTexCoord;',
'',
'uniform mat4 uMVPMatrix;',
'',
'varying vec2 vTexCoord;',
'',
'void main(void) {',
' gl_Position = uMVPMatrix * vec4(aPosition, 0.0, 1.0);',
' vTexCoord = aTexCoord;',
'}'
].join('\n'));
if (!gl.getShaderParameter(vertexShader, goog.webgl.COMPILE_STATUS)) {
window.console.log(gl.getShaderInfoLog(vertexShader));
goog.asserts.assert(gl.getShaderParameter(vertexShader, goog.webgl.COMPILE_STATUS));
}
var program = gl.createProgram();
gl.attachShader(program, fragmentShader);
gl.attachShader(program, vertexShader);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, goog.webgl.LINK_STATUS)) {
window.console.log(gl.getProgramInfoLog(program));
goog.asserts.assert(gl.getProgramParameter(program, goog.webgl.LINK_STATUS));
}
this.mvpMatrixLocation_ = gl.getUniformLocation(program, 'uMVPMatrix');
this.textureLocation_ = gl.getUniformLocation(program, 'uTexture');
var texCoordBuffer = gl.createBuffer();
gl.bindBuffer(goog.webgl.ARRAY_BUFFER, texCoordBuffer);
gl.bufferData(goog.webgl.ARRAY_BUFFER, new Float32Array([0, 1, 1, 1, 0, 0, 1, 0]), goog.webgl.STATIC_DRAW);
var texCoordLocation = gl.getAttributeLocation(program, 'aTexCoord');
gl.enableVertexAttribArray(texCoordLocation);
gl.vertexAttribPointer(texCoordLocation, 2, goog.webgl.FLOAT, false, 0, 0);
gl.bindBuffer(goog.webgl.ARRAY_BUFFER, null);
this.positionLocation_ = gl.getAttributeLocation(program, 'aPosition');
gl.enableVertexAttribArray(this.positionLocation_);
this.positionBuffer_ = gl.createBuffer();
};
goog.inherits(ol.renderer.WebGL, ol.renderer.MapRenderer);
/**
* Determine if this renderer type is supported in this environment.
* A static method.
* @returns {boolean} This renderer is supported.
*/
ol.renderer.WebGL.isSupported = function() {
return !goog.isNull( goog.dom.createDom('canvas').getContext('experimental-webgl') );
};
/**
* @param {ol.Tile} tile Tile.
* @protected
*/
ol.renderer.WebGL.prototype.bindTexture = function(tile) {
var gl = this.gl_;
var url = tile.getUrl();
if (url in this.textureCache_) {
gl.bindTexture(gl.TEXTURE_2D, this.textureCache_[url]);
} else {
var texture = gl.createTexture();
gl.bindTexture(goog.webgl.TEXTURE_2D, texture);
gl.texImage2D(goog.webgl.TEXTURE_2D, 0, goog.webgl.RGBA, goog.webgl.RGBA, goog.webgl.UNSIGNED_BYTE, tile.getImg());
gl.texParameteri(goog.webgl.TEXTURE_2D, goog.webgl.TEXTURE_MAG_FILTER, goog.webgl.LINEAR);
gl.texParameteri(goog.webgl.TEXTURE_2D, goog.webgl.TEXTURE_MIN_FILTER, goog.webgl.LINEAR);
this.textureCache_[url] = texture;
}
};
/**
* @param {ol.Tile} tile Tile.
* @protected
*/
ol.renderer.WebGL.prototype.handleTileLoad = function(tile) {
this.redraw();
};
/**
* @param {ol.Tile} tile Tile.
* @protected
*/
ol.renderer.WebGL.prototype.handleTileDestroy = function(tile) {
var gl = this.gl_;
var url = tile.getUrl();
if (url in this.textureCache_) {
gl.deleteTexture(this.textureCache_[url]);
delete this.textureCache_[url];
}
};
/**
* @inheritDoc
*/
ol.renderer.WebGL.prototype.draw = function(layers, center, resolution, animate) {
var gl = this.gl_;
var width = this.canvas_.width;
var height = this.canvas_.height;
var bounds = new ol.Bounds(
center.getX() - width * resolution / 2,
center.getY() - height * resolution / 2,
center.getX() + width * resolution / 2,
center.getY() + height * resolution / 2,
center.getProjection());
/** @type {goog.vec.Mat4.Type} */
var cameraMatrix;
goog.vec.Mat4.makeIdentity(cameraMatrix);
goog.vec.Mat4.scale(cameraMatrix, resolution, resolution, 1);
goog.vec.Mat4.translate(cameraMatrix, -center.getX(), -center.getY(), 0);
/** @type {goog.vec.Mat4.Type} */
var positionToViewportMatrix;
goog.vec.Mat4.makeIdentity(positionToViewportMatrix);
goog.vec.Mat4.scale(positionToViewportMatrix, 1 / width, 1 / height, 1);
goog.vec.Mat4.multMat(positionToViewportMatrix, cameraMatrix, positionToViewportMatrix);
/** @type {goog.vec.Mat4.Type} */
var viewportToPositionMatrix;
var inverted = goog.vec.Mat4.invert(positionToViewportMatrix, viewportToPositionMatrix);
goog.asserts.assert(inverted);
/** @type {goog.vec.Mat4.Type} */
var targetPixelToPositionMatrix;
goog.vec.Mat4.makeIdentity(targetPixelToPositionMatrix);
goog.vec.Mat4.translate(targetPixelToPositionMatrix, -1, 1, 0);
goog.vec.Mat4.scale(targetPixelToPositionMatrix, 2 / width, -2 / height, 1);
goog.vec.Mat4.multMat(viewportToPositionMatrix, targetPixelToPositionMatrix, targetPixelToPositionMatrix);
gl.clear(goog.webgl.COLOR_BUFFER_BIT);
gl.bindBuffer(goog.webgl.ARRAY_BUFFER, this.positionBuffer_);
gl.uniform1i(this.textureLocation_, 0);
gl.uniformMatrix4fv(this.positionLocation_, false, positionToViewportMatrix);
goog.array.forEach(layers, function(layer) {
if (!(layer instanceof ol.layer.TileLayer)) {
return;
}
var tileLayer = /** @type {ol.layer.TileLayer} */ (layer);
var tileSet = layer.getData(bounds, resolution);
var tiles = tileSet.getTiles();
var i, j, row, tile, tileBounds, positions, texture;
for (i = 0; i < tiles.length; ++i) {
row = tiles[i];
for (j = 0; j < row.length; ++j) {
tile = row[j];
if (!tile.isLoaded()) {
if (!tile.isLoading()) {
goog.events.listen(tile, 'load', this.handleTileLoad,
undefined, this);
goog.events.listen(tile, 'destroy', this.handleTileDestroy,
undefined, this);
tile.load();
}
continue;
}
tileBounds = tile.getBounds();
positions = [
tileBounds.getMinX(), tileBounds.getMinY(),
tileBounds.getMaxX(), tileBounds.getMinY(),
tileBounds.getMinX(), tileBounds.getMaxY(),
tileBounds.getMaxX(), tileBounds.getMaxY()
];
gl.bufferData(goog.webgl.ARRAY_BUFFER, new Float32Array(positions), goog.webgl.DYNAMIC_DRAW);
gl.vertexAttribPointer(this.positionLocation_, 2, goog.webgl.FLOAT, false, 0, 0);
this.bindTexture(tile);
gl.drawArrays(goog.webgl.TRIANGLES, 0, 4);
}
}
}, this);
this.renderedLayers_ = layers;
this.renderedCenter_ = center;
this.renderedResolution_ = resolution;
this.renderedAnimate_ = animate;
};
/**
*/
ol.renderer.WebGL.prototype.redraw = function() {
this.draw(this.renderedLayers_, this.renderedCenter_, this.renderedResolution_, this.renderedAnimate_);
};

59
src/ol3/base/array.js Normal file
View File

@@ -0,0 +1,59 @@
goog.provide('ol3.array');
goog.require('goog.array');
/**
* @param {Array.<number>} arr Array.
* @param {number} target Target.
* @return {number} Index.
*/
ol3.array.binaryFindNearest = function(arr, target) {
var index = goog.array.binarySearch(arr, target, function(a, b) {
return b - a;
});
if (index >= 0) {
return index;
} else if (index == -1) {
return 0;
} else if (index == -arr.length - 1) {
return arr.length - 1;
} else {
var left = -index - 2;
var right = -index - 1;
if (arr[left] - target < target - arr[right]) {
return left;
} else {
return right;
}
}
};
/**
* @param {Array.<number>} arr Array.
* @param {number} target Target.
* @return {number} Index.
*/
ol3.array.linearFindNearest = function(arr, target) {
var n = arr.length;
if (arr[0] <= target) {
return 0;
} else if (target <= arr[n - 1]) {
return n - 1;
} else {
var i;
for (i = 1; i < n; ++i) {
if (arr[i] == target) {
return i;
} else if (arr[i] < target) {
if (arr[i - 1] - target < target - arr[i]) {
return i - 1;
} else {
return i;
}
}
}
return n - 1;
}
};

View File

@@ -0,0 +1,46 @@
goog.require('goog.testing.jsunit');
goog.require('ol3.array');
function testBinaryFindNearest() {
var arr = [1000, 500, 100];
assertEquals(0, ol3.array.binaryFindNearest(arr, 10000));
assertEquals(0, ol3.array.binaryFindNearest(arr, 1000));
assertEquals(0, ol3.array.binaryFindNearest(arr, 900));
assertEquals(1, ol3.array.binaryFindNearest(arr, 750));
assertEquals(1, ol3.array.binaryFindNearest(arr, 550));
assertEquals(1, ol3.array.binaryFindNearest(arr, 500));
assertEquals(1, ol3.array.binaryFindNearest(arr, 450));
assertEquals(2, ol3.array.binaryFindNearest(arr, 300));
assertEquals(2, ol3.array.binaryFindNearest(arr, 200));
assertEquals(2, ol3.array.binaryFindNearest(arr, 100));
assertEquals(2, ol3.array.binaryFindNearest(arr, 50));
}
function testLinearFindNearest() {
var arr = [1000, 500, 100];
assertEquals(0, ol3.array.linearFindNearest(arr, 10000));
assertEquals(0, ol3.array.linearFindNearest(arr, 1000));
assertEquals(0, ol3.array.linearFindNearest(arr, 900));
assertEquals(1, ol3.array.linearFindNearest(arr, 750));
assertEquals(1, ol3.array.linearFindNearest(arr, 550));
assertEquals(1, ol3.array.linearFindNearest(arr, 500));
assertEquals(1, ol3.array.linearFindNearest(arr, 450));
assertEquals(2, ol3.array.linearFindNearest(arr, 300));
assertEquals(2, ol3.array.linearFindNearest(arr, 200));
assertEquals(2, ol3.array.linearFindNearest(arr, 100));
assertEquals(2, ol3.array.linearFindNearest(arr, 50));
}

View File

@@ -0,0 +1,58 @@
goog.provide('ol3.Attribution');
goog.require('ol3.CoverageArea');
goog.require('ol3.Projection');
/**
* @constructor
* @param {string} html HTML.
* @param {Array.<ol3.CoverageArea>=} opt_coverageAreas Coverage areas.
* @param {ol3.Projection=} opt_projection Projection.
*/
ol3.Attribution = function(html, opt_coverageAreas, opt_projection) {
/**
* @private
* @type {string}
*/
this.html_ = html;
/**
* @private
* @type {Array.<ol3.CoverageArea>}
*/
this.coverageAreas_ = opt_coverageAreas || null;
/**
* @private
* @type {ol3.Projection}
*/
this.projection_ = opt_projection || null;
};
/**
* @return {Array.<ol3.CoverageArea>} Coverage areas.
*/
ol3.Attribution.prototype.getCoverageAreas = function() {
return this.coverageAreas_;
};
/**
* @return {string} HTML.
*/
ol3.Attribution.prototype.getHtml = function() {
return this.html_;
};
/**
* @return {ol3.Projection} Projection.
*/
ol3.Attribution.prototype.getProjection = function() {
return this.projection_;
};

215
src/ol3/base/collection.js Normal file
View File

@@ -0,0 +1,215 @@
/**
* @fileoverview An implementation of Google Maps' MVCArray.
* @see https://developers.google.com/maps/documentation/javascript/reference
*/
goog.provide('ol3.Collection');
goog.provide('ol3.CollectionEvent');
goog.provide('ol3.CollectionEventType');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.events.Event');
goog.require('ol3.Object');
/**
* @enum {string}
*/
ol3.CollectionEventType = {
ADD: 'add',
INSERT_AT: 'insert_at',
REMOVE: 'remove',
REMOVE_AT: 'remove_at',
SET_AT: 'set_at'
};
/**
* @constructor
* @extends {goog.events.Event}
* @param {ol3.CollectionEventType} type Type.
* @param {*=} opt_elem Element.
* @param {number=} opt_index Index.
* @param {*=} opt_prev Value.
* @param {Object=} opt_target Target.
*/
ol3.CollectionEvent =
function(type, opt_elem, opt_index, opt_prev, opt_target) {
goog.base(this, type, opt_target);
/**
* @type {*}
*/
this.elem = opt_elem;
/**
* @type {number|undefined}
*/
this.index = opt_index;
/**
* @type {*}
*/
this.prev = opt_prev;
};
goog.inherits(ol3.CollectionEvent, goog.events.Event);
/**
* @enum {string}
*/
ol3.CollectionProperty = {
LENGTH: 'length'
};
/**
* @constructor
* @extends {ol3.Object}
* @param {Array=} opt_array Array.
*/
ol3.Collection = function(opt_array) {
goog.base(this);
/**
* @private
* @type {Array}
*/
this.array_ = opt_array || [];
this.updateLength_();
};
goog.inherits(ol3.Collection, ol3.Object);
/**
*/
ol3.Collection.prototype.clear = function() {
while (this[ol3.CollectionProperty.LENGTH]) {
this.pop();
}
};
/**
* @param {Function} f Function.
* @param {Object=} opt_obj Object.
*/
ol3.Collection.prototype.forEach = function(f, opt_obj) {
goog.array.forEach(this.array_, f, opt_obj);
};
/**
* @return {Array} Array.
*/
ol3.Collection.prototype.getArray = function() {
return this.array_;
};
/**
* @param {number} index Index.
* @return {*} Element.
*/
ol3.Collection.prototype.getAt = function(index) {
return this.array_[index];
};
/**
* @return {number} Length.
*/
ol3.Collection.prototype.getLength = function() {
return /** @type {number} */ this.get(ol3.CollectionProperty.LENGTH);
};
/**
* @param {number} index Index.
* @param {*} elem Element.
*/
ol3.Collection.prototype.insertAt = function(index, elem) {
goog.array.insertAt(this.array_, elem, index);
this.updateLength_();
this.dispatchEvent(new ol3.CollectionEvent(
ol3.CollectionEventType.ADD, elem, undefined, undefined, this));
this.dispatchEvent(new ol3.CollectionEvent(
ol3.CollectionEventType.INSERT_AT, elem, index, undefined, this));
};
/**
* @return {*} Element.
*/
ol3.Collection.prototype.pop = function() {
return this.removeAt(this.getLength() - 1);
};
/**
* @param {*} elem Element.
* @return {number} Length.
*/
ol3.Collection.prototype.push = function(elem) {
var n = this.array_.length;
this.insertAt(n, elem);
return n;
};
/**
* @param {number} index Index.
* @return {*} Value.
*/
ol3.Collection.prototype.removeAt = function(index) {
var prev = this.array_[index];
goog.array.removeAt(this.array_, index);
this.updateLength_();
this.dispatchEvent(new ol3.CollectionEvent(
ol3.CollectionEventType.REMOVE, prev, undefined, undefined, this));
this.dispatchEvent(new ol3.CollectionEvent(ol3.CollectionEventType.REMOVE_AT,
undefined, index, prev, this));
return prev;
};
/**
* @param {number} index Index.
* @param {*} elem Element.
*/
ol3.Collection.prototype.setAt = function(index, elem) {
var n = this[ol3.CollectionProperty.LENGTH];
if (index < n) {
var prev = this.array_[index];
this.array_[index] = elem;
this.dispatchEvent(new ol3.CollectionEvent(ol3.CollectionEventType.SET_AT,
elem, index, prev, this));
this.dispatchEvent(new ol3.CollectionEvent(ol3.CollectionEventType.REMOVE,
prev, undefined, undefined, this));
this.dispatchEvent(new ol3.CollectionEvent(ol3.CollectionEventType.ADD,
elem, undefined, undefined, this));
} else {
var j;
for (j = n; j < index; ++j) {
this.insertAt(j, undefined);
}
this.insertAt(index, elem);
}
};
/**
* @private
*/
ol3.Collection.prototype.updateLength_ = function() {
this.set(ol3.CollectionProperty.LENGTH, this.array_.length);
};

View File

@@ -0,0 +1,238 @@
goog.require('goog.array');
goog.require('goog.testing.jsunit');
goog.require('ol3.Collection');
goog.require('ol3.CollectionEventType');
function testEmpty() {
var collection = new ol3.Collection();
assertEquals(0, collection.getLength());
assertTrue(goog.array.equals(collection.getArray(), []));
assertUndefined(collection.getAt(0));
}
function testConstruct() {
var array = [0, 1, 2];
var collection = new ol3.Collection(array);
assertEquals(0, collection.getAt(0));
assertEquals(1, collection.getAt(1));
assertEquals(2, collection.getAt(2));
}
function testPush() {
var collection = new ol3.Collection();
collection.push(1);
assertEquals(1, collection.getLength());
assertTrue(goog.array.equals(collection.getArray(), [1]));
assertEquals(1, collection.getAt(0));
}
function testPushPop() {
var collection = new ol3.Collection();
collection.push(1);
collection.pop();
assertEquals(0, collection.getLength());
assertTrue(goog.array.equals(collection.getArray(), []));
assertUndefined(collection.getAt(0));
}
function testInsertAt() {
var collection = new ol3.Collection([0, 2]);
collection.insertAt(1, 1);
assertEquals(0, collection.getAt(0));
assertEquals(1, collection.getAt(1));
assertEquals(2, collection.getAt(2));
}
function testSetAt() {
var collection = new ol3.Collection();
collection.setAt(1, 1);
assertEquals(2, collection.getLength());
assertUndefined(collection.getAt(0));
assertEquals(1, collection.getAt(1));
}
function testRemoveAt() {
var collection = new ol3.Collection([0, 1, 2]);
collection.removeAt(1);
assertEquals(0, collection.getAt(0));
assertEquals(2, collection.getAt(1));
}
function testForEachEmpty() {
var collection = new ol3.Collection();
var forEachCalled = false;
collection.forEach(function() {
forEachCalled = true;
});
assertFalse(forEachCalled);
}
function testForEachPopulated() {
var collection = new ol3.Collection();
collection.push(1);
collection.push(2);
var forEachCount = 0;
collection.forEach(function() {
++forEachCount;
});
assertEquals(2, forEachCount);
}
function testSetAtEvent() {
var collection = new ol3.Collection(['a', 'b']);
var index, prev;
goog.events.listen(collection, ol3.CollectionEventType.SET_AT, function(e) {
index = e.index;
prev = e.prev;
});
collection.setAt(1, 1);
assertEquals(1, index);
assertEquals('b', prev);
}
function testRemoveAtEvent() {
var collection = new ol3.Collection(['a']);
var index, prev;
goog.events.listen(
collection, ol3.CollectionEventType.REMOVE_AT, function(e) {
index = e.index;
prev = e.prev;
});
collection.pop();
assertEquals(0, index);
assertEquals('a', prev);
}
function testInsertAtEvent() {
var collection = new ol3.Collection([0, 2]);
var index;
goog.events.listen(
collection, ol3.CollectionEventType.INSERT_AT, function(e) {
index = e.index;
});
collection.insertAt(1, 1);
assertEquals(1, index);
}
function testSetAtBeyondEnd() {
var collection = new ol3.Collection();
var inserts = [];
goog.events.listen(
collection, ol3.CollectionEventType.INSERT_AT, function(e) {
inserts.push(e.index);
});
collection.setAt(2, 0);
assertEquals(3, collection.getLength());
assertUndefined(collection.getAt(0));
assertUndefined(collection.getAt(1));
assertEquals(0, collection.getAt(2));
assertEquals(3, inserts.length);
assertEquals(0, inserts[0]);
assertEquals(1, inserts[1]);
assertEquals(2, inserts[2]);
}
function testLengthChangeInsertAt() {
var collection = new ol3.Collection([0, 1, 2]);
var lengthEventDispatched;
goog.events.listen(collection, 'length_changed', function() {
lengthEventDispatched = true;
});
collection.insertAt(2, 3);
assertTrue(lengthEventDispatched);
}
function testLengthChangeRemoveAt() {
var collection = new ol3.Collection([0, 1, 2]);
var lengthEventDispatched;
goog.events.listen(collection, 'length_changed', function() {
lengthEventDispatched = true;
});
collection.removeAt(0);
assertTrue(lengthEventDispatched);
}
function testLengthChangeSetAt() {
var collection = new ol3.Collection([0, 1, 2]);
var lengthEventDispatched;
goog.events.listen(collection, 'length_changed', function() {
lengthEventDispatched = true;
});
collection.setAt(1, 1);
assertUndefined(lengthEventDispatched);
}
function testForEach() {
var collection = new ol3.Collection([1, 2, 4]);
var sum = 0;
collection.forEach(function(elem) {
sum += elem;
});
assertEquals(7, sum);
}
function testForEachScope() {
var collection = new ol3.Collection([0]);
var that;
var uniqueObj = {};
collection.forEach(function(elem) {
that = this;
}, uniqueObj);
assertTrue(that === uniqueObj);
}
function testAddEvent() {
var collection = new ol3.Collection();
var elem;
goog.events.listen(collection, ol3.CollectionEventType.ADD, function(e) {
elem = e.elem;
});
collection.push(1);
assertEquals(1, elem);
}
function testAddRemoveEvent() {
var collection = new ol3.Collection([1]);
var addedElem;
goog.events.listen(collection, ol3.CollectionEventType.ADD, function(e) {
addedElem = e.elem;
});
var removedElem;
goog.events.listen(collection, ol3.CollectionEventType.REMOVE, function(e) {
removedElem = e.elem;
});
collection.setAt(0, 2);
assertEquals(1, removedElem);
assertEquals(2, addedElem);
}
function testRemove() {
var collection = new ol3.Collection([1]);
var elem;
goog.events.listen(collection, ol3.CollectionEventType.REMOVE, function(e) {
elem = e.elem;
});
collection.pop();
assertEquals(1, elem);
}

56
src/ol3/base/color.js Normal file
View File

@@ -0,0 +1,56 @@
goog.provide('ol3.Color');
goog.require('goog.color');
/**
* @constructor
* @param {number} r Red.
* @param {number} g Green.
* @param {number} b Blue.
* @param {number} a Alpha.
*/
ol3.Color = function(r, g, b, a) {
/**
* @type {number}
*/
this.r = r;
/**
* @type {number}
*/
this.g = g;
/**
* @type {number}
*/
this.b = b;
/**
* @type {number}
*/
this.a = a;
};
/**
* @param {string} str String.
* @param {number=} opt_a Alpha.
* @return {ol3.Color} Color.
*/
ol3.Color.createFromString = function(str, opt_a) {
var rgb = goog.color.hexToRgb(goog.color.parse(str).hex);
var a = opt_a || 255;
return new ol3.Color(rgb[0], rgb[1], rgb[2], a);
};
/**
* @return {ol3.Color} Clone.
*/
ol3.Color.prototype.clone = function() {
return new ol3.Color(this.r, this.g, this.b, this.a);
};

View File

@@ -0,0 +1,31 @@
goog.provide('ol3.Coordinate');
goog.require('goog.math.Vec2');
/**
* @constructor
* @extends {goog.math.Vec2}
* @param {number} x X.
* @param {number} y Y.
*/
ol3.Coordinate = function(x, y) {
goog.base(this, x, y);
};
goog.inherits(ol3.Coordinate, goog.math.Vec2);
/**
* @const
* @type {ol3.Coordinate}
*/
ol3.Coordinate.ZERO = new ol3.Coordinate(0, 0);
/**
* @return {ol3.Coordinate} Clone.
*/
ol3.Coordinate.prototype.clone = function() {
return new ol3.Coordinate(this.x, this.y);
};

View File

@@ -0,0 +1,57 @@
goog.provide('ol3.CoordinateFormat');
goog.provide('ol3.CoordinateFormatType');
goog.require('goog.math');
goog.require('ol3.Coordinate');
/**
* @typedef {function((ol3.Coordinate|undefined)): string}
*/
ol3.CoordinateFormatType;
/**
* @param {number} precision Precision.
* @return {ol3.CoordinateFormatType} Coordinate format.
*/
ol3.CoordinateFormat.createXY = function(precision) {
return function(coordinate) {
if (goog.isDef(coordinate)) {
return coordinate.x.toFixed(precision) + ', ' +
coordinate.y.toFixed(precision);
} else {
return '';
}
};
};
/**
* @private
* @param {number} degrees Degrees.
* @param {string} hemispheres Hemispheres.
* @return {string} String.
*/
ol3.CoordinateFormat.degreesToHDMS_ = function(degrees, hemispheres) {
var normalizedDegrees = goog.math.modulo(degrees + 180, 360) - 180;
var x = Math.abs(Math.round(3600 * normalizedDegrees));
return Math.floor(x / 3600) + '\u00b0 ' +
Math.floor((x / 60) % 60) + '\u2032 ' +
Math.floor(x % 60) + '\u2033 ' +
hemispheres.charAt(normalizedDegrees < 0 ? 1 : 0);
};
/**
* @param {ol3.Coordinate|undefined} coordinate Coordinate.
* @return {string} Coordinate format.
*/
ol3.CoordinateFormat.hdms = function(coordinate) {
if (goog.isDef(coordinate)) {
return ol3.CoordinateFormat.degreesToHDMS_(coordinate.y, 'NS') + ' ' +
ol3.CoordinateFormat.degreesToHDMS_(coordinate.x, 'EW');
} else {
return '';
}
};

View File

@@ -0,0 +1,45 @@
goog.provide('ol3.CoverageArea');
goog.require('ol3.Extent');
/**
* @constructor
* @param {ol3.Extent} extent Extent.
*/
ol3.CoverageArea = function(extent) {
/**
* @type {ol3.Extent}
*/
this.extent = extent;
};
/**
* @param {ol3.Extent} extent Extent.
* @return {boolean} Intersects.
*/
ol3.CoverageArea.prototype.intersectsExtent = function(extent) {
return this.extent.intersects(extent);
};
/**
* @param {ol3.Extent} extent Extent.
* @param {number} resolution Resolution.
* @return {boolean} Intersects.
*/
ol3.CoverageArea.prototype.intersectsExtentAndResolution = goog.abstractMethod;
/**
* @param {ol3.TransformFunction} transformFn Transform.
* @return {ol3.CoverageArea} Transformed coverage area.
*/
ol3.CoverageArea.prototype.transform = function(transformFn) {
var extent = this.extent.transform(transformFn);
return new ol3.CoverageArea(extent);
};

153
src/ol3/base/createmap.js Normal file
View File

@@ -0,0 +1,153 @@
goog.provide('ol3.RendererHint');
goog.provide('ol3.createMap');
goog.require('goog.object');
goog.require('ol3.Collection');
goog.require('ol3.Map');
goog.require('ol3.MapProperty');
goog.require('ol3.Projection');
goog.require('ol3.dom');
goog.require('ol3.dom.MapRenderer');
goog.require('ol3.interaction.AltDragRotate');
goog.require('ol3.interaction.CenterConstraint');
goog.require('ol3.interaction.Constraints');
goog.require('ol3.interaction.DblClickZoom');
goog.require('ol3.interaction.DragPan');
goog.require('ol3.interaction.KeyboardPan');
goog.require('ol3.interaction.KeyboardZoom');
goog.require('ol3.interaction.MouseWheelZoom');
goog.require('ol3.interaction.ResolutionConstraint');
goog.require('ol3.interaction.RotationConstraint');
goog.require('ol3.interaction.ShiftDragZoom');
goog.require('ol3.webgl');
goog.require('ol3.webgl.MapRenderer');
/**
* @define {string} Default projection code.
*/
ol3.DEFAULT_PROJECTION_CODE = 'EPSG:3857';
/**
* @define {string} Default user projection code.
*/
ol3.DEFAULT_USER_PROJECTION_CODE = 'EPSG:4326';
/**
* @define {boolean} Whether to enable DOM.
*/
ol3.ENABLE_DOM = true;
/**
* @define {boolean} Whether to enable WebGL.
*/
ol3.ENABLE_WEBGL = true;
/**
* @enum {string}
*/
ol3.RendererHint = {
DOM: 'dom',
WEBGL: 'webgl'
};
/**
* @type {Array.<ol3.RendererHint>}
*/
ol3.DEFAULT_RENDERER_HINT = [
ol3.RendererHint.WEBGL,
ol3.RendererHint.DOM
];
/**
* @param {Element} target Target.
* @param {Object.<string, *>=} opt_values Values.
* @param {ol3.RendererHint|Array.<ol3.RendererHint>=} opt_rendererHints
* Renderer hints.
* @return {ol3.Map} Map.
*/
ol3.createMap = function(target, opt_values, opt_rendererHints) {
var values = {};
if (goog.isDef(opt_values)) {
goog.object.extend(values, opt_values);
}
// FIXME this should be a configuration option
var centerConstraint = ol3.interaction.CenterConstraint.snapToPixel;
var resolutionConstraint =
ol3.interaction.ResolutionConstraint.createSnapToPower(
Math.exp(Math.log(2) / 8), ol3.Projection.EPSG_3857_HALF_SIZE / 128);
var rotationConstraint = ol3.interaction.RotationConstraint.none;
var constraints = new ol3.interaction.Constraints(
centerConstraint, resolutionConstraint, rotationConstraint);
if (!goog.object.containsKey(values, ol3.MapProperty.INTERACTIONS)) {
var interactions = new ol3.Collection();
interactions.push(new ol3.interaction.AltDragRotate(constraints));
interactions.push(new ol3.interaction.DblClickZoom(constraints));
interactions.push(new ol3.interaction.DragPan(constraints));
interactions.push(new ol3.interaction.KeyboardPan(constraints, 16));
interactions.push(new ol3.interaction.KeyboardZoom(constraints));
interactions.push(new ol3.interaction.MouseWheelZoom(constraints));
interactions.push(new ol3.interaction.ShiftDragZoom(constraints));
values[ol3.MapProperty.INTERACTIONS] = interactions;
}
if (!goog.object.containsKey(values, ol3.MapProperty.LAYERS)) {
values[ol3.MapProperty.LAYERS] = new ol3.Collection();
}
if (!goog.object.containsKey(values, ol3.MapProperty.PROJECTION)) {
values[ol3.MapProperty.PROJECTION] =
ol3.Projection.getFromCode(ol3.DEFAULT_PROJECTION_CODE);
}
if (!goog.object.containsKey(values, ol3.MapProperty.USER_PROJECTION)) {
values[ol3.MapProperty.USER_PROJECTION] =
ol3.Projection.getFromCode(ol3.DEFAULT_USER_PROJECTION_CODE);
}
/**
* @type {Array.<ol3.RendererHint>}
*/
var rendererHints;
if (goog.isDef(opt_rendererHints)) {
if (goog.isArray(opt_rendererHints)) {
rendererHints = opt_rendererHints;
} else {
rendererHints = [opt_rendererHints];
}
} else {
rendererHints = ol3.DEFAULT_RENDERER_HINT;
}
var i, rendererHint, rendererConstructor;
for (i = 0; i < rendererHints.length; ++i) {
rendererHint = rendererHints[i];
if (rendererHint == ol3.RendererHint.DOM) {
if (ol3.ENABLE_DOM && ol3.dom.isSupported()) {
rendererConstructor = ol3.dom.MapRenderer;
break;
}
} else if (rendererHint == ol3.RendererHint.WEBGL) {
if (ol3.ENABLE_WEBGL && ol3.webgl.isSupported()) {
rendererConstructor = ol3.webgl.MapRenderer;
break;
}
}
}
if (goog.isDef(rendererConstructor)) {
return new ol3.Map(target, rendererConstructor, values);
} else {
return null;
}
};

59
src/ol3/base/extent.js Normal file
View File

@@ -0,0 +1,59 @@
goog.provide('ol3.Extent');
goog.require('ol3.Coordinate');
goog.require('ol3.Rectangle');
goog.require('ol3.TransformFunction');
/**
* @constructor
* @extends {ol3.Rectangle}
* @param {number} minX Minimum X.
* @param {number} minY Minimum Y.
* @param {number} maxX Maximum X.
* @param {number} maxY Maximum Y.
*/
ol3.Extent = function(minX, minY, maxX, maxY) {
goog.base(this, minX, minY, maxX, maxY);
};
goog.inherits(ol3.Extent, ol3.Rectangle);
/**
* @param {...ol3.Coordinate} var_args Coordinates.
* @return {!ol3.Extent} Bounding extent.
*/
ol3.Extent.boundingExtent = function(var_args) {
var coordinate0 = arguments[0];
var extent = new ol3.Extent(coordinate0.x, coordinate0.y,
coordinate0.x, coordinate0.y);
var i;
for (i = 1; i < arguments.length; ++i) {
var coordinate = arguments[i];
extent.minX = Math.min(extent.minX, coordinate.x);
extent.minY = Math.min(extent.minY, coordinate.y);
extent.maxX = Math.max(extent.maxX, coordinate.x);
extent.maxY = Math.max(extent.maxY, coordinate.y);
}
return extent;
};
/**
* @return {ol3.Extent} Extent.
*/
ol3.Extent.prototype.clone = function() {
return new ol3.Extent(this.minX, this.minY, this.maxX, this.maxY);
};
/**
* @param {ol3.TransformFunction} transformFn Transform function.
* @return {ol3.Extent} Extent.
*/
ol3.Extent.prototype.transform = function(transformFn) {
var min = transformFn(new ol3.Coordinate(this.minX, this.minY));
var max = transformFn(new ol3.Coordinate(this.maxX, this.maxY));
return new ol3.Extent(min.x, min.y, max.x, max.y);
};

View File

@@ -0,0 +1,29 @@
goog.require('goog.testing.jsunit');
goog.require('ol3.Extent');
goog.require('ol3.Projection');
function testClone() {
var extent = new ol3.Extent(1, 2, 3, 4);
var clonedExtent = extent.clone();
assertTrue(clonedExtent instanceof ol3.Extent);
assertFalse(clonedExtent === extent);
assertEquals(extent.minX, clonedExtent.minX);
assertEquals(extent.minY, clonedExtent.minY);
assertEquals(extent.maxX, clonedExtent.maxX);
assertEquals(extent.maxY, clonedExtent.maxY);
}
function testTransform() {
var transformFn =
ol3.Projection.getTransformFromCodes('EPSG:4326', 'EPSG:3857');
var sourceExtent = new ol3.Extent(-15, -30, 45, 60);
var destinationExtent = sourceExtent.transform(transformFn);
assertNotNullNorUndefined(destinationExtent);
// FIXME check values with third-party tool
assertRoughlyEquals(-1669792.3618991037, destinationExtent.minX, 1e-9);
assertRoughlyEquals(-3503549.843504376, destinationExtent.minY, 1e-9);
assertRoughlyEquals(5009377.085697311, destinationExtent.maxX, 1e-9);
assertRoughlyEquals(8399737.889818361, destinationExtent.maxY, 1e-9);
}

228
src/ol3/base/layer.js Normal file
View File

@@ -0,0 +1,228 @@
goog.provide('ol3.Layer');
goog.provide('ol3.LayerProperty');
goog.require('goog.math');
goog.require('ol3.Object');
goog.require('ol3.Store');
/**
* @enum {string}
*/
ol3.LayerProperty = {
BRIGHTNESS: 'brightness',
CONTRAST: 'contrast',
HUE: 'hue',
OPACITY: 'opacity',
SATURATION: 'saturation',
VISIBLE: 'visible'
};
/**
* @constructor
* @extends {ol3.Object}
* @param {ol3.Store} store Store.
* @param {Object.<string, *>=} opt_values Values.
*/
ol3.Layer = function(store, opt_values) {
goog.base(this);
/**
* @private
* @type {ol3.Store}
*/
this.store_ = store;
this.setBrightness(0);
this.setContrast(0);
this.setHue(0);
this.setOpacity(1);
this.setSaturation(0);
this.setVisible(true);
if (goog.isDef(opt_values)) {
this.setValues(opt_values);
}
};
goog.inherits(ol3.Layer, ol3.Object);
/**
* @return {number} Brightness.
*/
ol3.Layer.prototype.getBrightness = function() {
return /** @type {number} */ this.get(ol3.LayerProperty.BRIGHTNESS);
};
goog.exportProperty(
ol3.Layer.prototype,
'getBrightness',
ol3.Layer.prototype.getBrightness);
/**
* @return {number} Contrast.
*/
ol3.Layer.prototype.getContrast = function() {
return /** @type {number} */ this.get(ol3.LayerProperty.CONTRAST);
};
goog.exportProperty(
ol3.Layer.prototype,
'getContrast',
ol3.Layer.prototype.getContrast);
/**
* @return {number} Hue.
*/
ol3.Layer.prototype.getHue = function() {
return /** @type {number} */ this.get(ol3.LayerProperty.HUE);
};
goog.exportProperty(
ol3.Layer.prototype,
'getHue',
ol3.Layer.prototype.getHue);
/**
* @return {number} Opacity.
*/
ol3.Layer.prototype.getOpacity = function() {
return /** @type {number} */ this.get(ol3.LayerProperty.OPACITY);
};
goog.exportProperty(
ol3.Layer.prototype,
'getOpacity',
ol3.Layer.prototype.getOpacity);
/**
* @return {number} Saturation.
*/
ol3.Layer.prototype.getSaturation = function() {
return /** @type {number} */ this.get(ol3.LayerProperty.SATURATION);
};
goog.exportProperty(
ol3.Layer.prototype,
'getSaturation',
ol3.Layer.prototype.getSaturation);
/**
* @return {ol3.Store} Store.
*/
ol3.Layer.prototype.getStore = function() {
return this.store_;
};
/**
* @return {boolean} Visible.
*/
ol3.Layer.prototype.getVisible = function() {
return /** @type {boolean} */ this.get(ol3.LayerProperty.VISIBLE);
};
goog.exportProperty(
ol3.Layer.prototype,
'getVisible',
ol3.Layer.prototype.getVisible);
/**
* @return {boolean} Is ready.
*/
ol3.Layer.prototype.isReady = function() {
return this.getStore().isReady();
};
/**
* @param {number} brightness Brightness.
*/
ol3.Layer.prototype.setBrightness = function(brightness) {
brightness = goog.math.clamp(brightness, -1, 1);
if (brightness != this.getBrightness()) {
this.set(ol3.LayerProperty.BRIGHTNESS, brightness);
}
};
goog.exportProperty(
ol3.Layer.prototype,
'setBrightness',
ol3.Layer.prototype.setBrightness);
/**
* @param {number} contrast Contrast.
*/
ol3.Layer.prototype.setContrast = function(contrast) {
contrast = goog.math.clamp(contrast, -1, 1);
if (contrast != this.getContrast()) {
this.set(ol3.LayerProperty.CONTRAST, contrast);
}
};
goog.exportProperty(
ol3.Layer.prototype,
'setContrast',
ol3.Layer.prototype.setContrast);
/**
* @param {number} hue Hue.
*/
ol3.Layer.prototype.setHue = function(hue) {
if (hue != this.getHue()) {
this.set(ol3.LayerProperty.HUE, hue);
}
};
goog.exportProperty(
ol3.Layer.prototype,
'setHue',
ol3.Layer.prototype.setHue);
/**
* @param {number} opacity Opacity.
*/
ol3.Layer.prototype.setOpacity = function(opacity) {
opacity = goog.math.clamp(opacity, 0, 1);
if (opacity != this.getOpacity()) {
this.set(ol3.LayerProperty.OPACITY, opacity);
}
};
goog.exportProperty(
ol3.Layer.prototype,
'setOpacity',
ol3.Layer.prototype.setOpacity);
/**
* @param {number} saturation Saturation.
*/
ol3.Layer.prototype.setSaturation = function(saturation) {
saturation = goog.math.clamp(saturation, -1, 1);
if (saturation != this.getSaturation()) {
this.set(ol3.LayerProperty.SATURATION, saturation);
}
};
goog.exportProperty(
ol3.Layer.prototype,
'setSaturation',
ol3.Layer.prototype.setSaturation);
/**
* @param {boolean} visible Visible.
*/
ol3.Layer.prototype.setVisible = function(visible) {
visible = !!visible;
if (visible != this.getVisible()) {
this.set(ol3.LayerProperty.VISIBLE, visible);
}
};
goog.exportProperty(
ol3.Layer.prototype,
'setVisible',
ol3.Layer.prototype.setVisible);

Some files were not shown because too many files have changed in this diff Show More