Merge pull request #3472 from tschaub/unbound
Remove the experimental bindTo method from ol.Object.
This commit is contained in:
@@ -2,12 +2,37 @@
|
||||
|
||||
### v3.5.0
|
||||
|
||||
* The following experimental methods have been removed from `ol.Object`: `bindTo`, `unbind`, and `unbindAll`. If you want to get notification about `ol.Object` property changes, you can listen for the `'propertychange'` event (e.g. `object.on('propertychange', listener)`). Two-way binding can be set up at the application level using property change listeners. See [#3472](https://github.com/openlayers/ol3/pull/3472) for details on the change.
|
||||
|
||||
* The experimental `ol.dom.Input` component has been removed. If you need to synchronize the state of a dom Input element with an `ol.Object`, this can be accomplished using listeners for change events. For example, you might bind the state of a checkbox type input with a layer's visibility like this:
|
||||
|
||||
```js
|
||||
var layer = new ol.layer.Tile();
|
||||
var checkbox = document.querySelector('#checkbox');
|
||||
|
||||
checkbox.addEventListener('change', function() {
|
||||
var checked = this.checked;
|
||||
if (checked !== layer.getVisible()) {
|
||||
layer.setVisible(checked);
|
||||
}
|
||||
});
|
||||
|
||||
layer.on('change:visible', function() {
|
||||
var visible = this.getVisible();
|
||||
if (visible !== checkbox.checked) {
|
||||
checkbox.checked = visible;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
* When manually loading an image for `ol.style.Icon`, the image size should now be set
|
||||
with the `imgSize` option and not with `size`. `size` is supposed to be used for the
|
||||
size of a sub-rectangle in an image sprite.
|
||||
|
||||
### v3.4.0
|
||||
|
||||
There should be nothing special required when upgrading from v3.3.0 to v3.4.0.
|
||||
|
||||
### v3.3.0
|
||||
|
||||
* The `ol.events.condition.mouseMove` function was replaced by `ol.events.condition.pointerMove` (see [#3281](https://github.com/openlayers/ol3/pull/3281)). For example, if you use `ol.events.condition.mouseMove` as the condition in a `Select` interaction then you now need to use `ol.events.condition.pointerMove`:
|
||||
|
||||
@@ -29,11 +29,10 @@ Interactions for [vector features](ol.Feature.html)
|
||||
<br>[Vector sources](ol.source.Vector.html) for [ol.layer.Vector](ol.layer.Vector.html)
|
||||
<br>[Formats](ol.format.Feature.html) for reading/writing vector data
|
||||
<br>[ol.format.WMSCapabilities](ol.format.WMSCapabilities.html)</td></tr>
|
||||
<tr><th>Projections</th><th>2-way bindings</th><th>Other components</th></tr>
|
||||
<tr><th>Projections</th><th>Observable objects</th><th>Other components</th></tr>
|
||||
<tr><td><p>All coordinates and extents need to be provided in view projection (default: EPSG:3857). To transform, use [ol.proj.transform()](ol.proj.html#transform) and [ol.proj.transformExtent()](ol.proj.html#transformExtent).</p>
|
||||
[ol.proj](ol.proj.html)</td>
|
||||
<td><p>[Objects](ol.Object.html) can be kept in sync using the [bindTo()](ol.Object.html#bindTo) method.</p>
|
||||
<p>A [DOM Input](ol.dom.Input.html) class is available to bind Object properties to HTML Input elements.</p></td>
|
||||
<td><p>Changes to all [ol.Objects](ol.Object.html) can observed by calling the [object.on('propertychange')](ol.Object.html#on) method. Listeners receive an [ol.ObjectEvent](ol.ObjectEvent.html) with information on the changed property and old value.</p>
|
||||
<td>[ol.DeviceOrientation](ol.DeviceOrientation.html)<br>
|
||||
[ol.Geolocation](ol.Geolocation.html)<br>
|
||||
[ol.Overlay](ol.Overlay.html)<br>
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
---
|
||||
template: example.html
|
||||
title: Bind HTML input example
|
||||
shortdesc: Demonstrates two-way binding of HTML input elements to OpenLayers objects.
|
||||
docs: >
|
||||
<p id="has-webgl" style="display: none">With the <a href="?renderer=webgl">WebGL renderer</a>, <strong>hue</strong>, <strong>saturation</strong>, <strong>contrast</strong> and <strong>brightness</strong> can also be controlled.</p>
|
||||
<div id="no-webgl" class="alert alert-warning" style="display: none">
|
||||
<h4>Warning!</h4>
|
||||
A browser that supports <a href="http://get.webgl.org/">WebGL</a> is required to change the
|
||||
<strong>hue</strong>, <strong>saturation</strong>, <strong>contrast</strong> and <strong>brightness</strong>.
|
||||
</div>
|
||||
tags: "custom, control"
|
||||
---
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<div id="map" class="map"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<form class="">
|
||||
<fieldset>
|
||||
<legend>Layer</legend>
|
||||
<label class="checkbox" for="visible">
|
||||
<input id="visible" type="checkbox"/>visibility
|
||||
</label>
|
||||
<label>opacity</label>
|
||||
<input id="opacity" type="range" min="0" max="1" step="0.01"/>
|
||||
</fieldset>
|
||||
<fieldset id="webgl" style="display: none">
|
||||
<label>hue</label>
|
||||
<input id="hue" type="range" min="-3.141592653589793" max="3.141592653589793" step="0.01"/>
|
||||
<label>saturation</label>
|
||||
<input id="saturation" type="range" min="0" max="5" step="0.01"/>
|
||||
<label>contrast</label>
|
||||
<input id="contrast" type="range" min="0" max="2" step="0.01"/>
|
||||
<label>brightness</label>
|
||||
<input id="brightness" type="range" min="-1" max="1" step="0.01"/>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
<div class="span4">
|
||||
<form class="">
|
||||
<fieldset>
|
||||
<legend>View</legend>
|
||||
<label>rotation</label>
|
||||
<input id="rotation" type="range" min="-3.141592653589793" max="3.141592653589793" step="0.01"/>
|
||||
<label>resolution</label>
|
||||
<input id="resolution" type="number" min="0" step="250"/>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
@@ -1,69 +0,0 @@
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.View');
|
||||
goog.require('ol.control');
|
||||
goog.require('ol.dom.Input');
|
||||
goog.require('ol.has');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.source.OSM');
|
||||
|
||||
|
||||
function checkWebGL(evt) {
|
||||
document.getElementById('no-webgl').style.display =
|
||||
ol.has.WEBGL ? 'none' : '';
|
||||
document.getElementById('has-webgl').style.display =
|
||||
ol.has.WEBGL && !evt.glContext ? '' : 'none';
|
||||
document.getElementById('webgl').style.display =
|
||||
evt.glContext ? '' : 'none';
|
||||
}
|
||||
|
||||
var layer = new ol.layer.Tile({
|
||||
source: new ol.source.OSM()
|
||||
});
|
||||
layer.once('precompose', checkWebGL);
|
||||
|
||||
var view = new ol.View({
|
||||
center: [0, 0],
|
||||
zoom: 2
|
||||
});
|
||||
|
||||
var map = new ol.Map({
|
||||
layers: [layer],
|
||||
renderer: exampleNS.getRendererFromQueryString(),
|
||||
target: 'map',
|
||||
controls: ol.control.defaults({
|
||||
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
|
||||
collapsible: false
|
||||
})
|
||||
}),
|
||||
view: view
|
||||
});
|
||||
|
||||
var visible = new ol.dom.Input(document.getElementById('visible'));
|
||||
visible.bindTo('checked', layer, 'visible');
|
||||
|
||||
var opacity = new ol.dom.Input(document.getElementById('opacity'));
|
||||
opacity.bindTo('value', layer, 'opacity')
|
||||
.transform(parseFloat, String);
|
||||
|
||||
var hue = new ol.dom.Input(document.getElementById('hue'));
|
||||
hue.bindTo('value', layer, 'hue')
|
||||
.transform(parseFloat, String);
|
||||
|
||||
var saturation = new ol.dom.Input(document.getElementById('saturation'));
|
||||
saturation.bindTo('value', layer, 'saturation')
|
||||
.transform(parseFloat, String);
|
||||
|
||||
var contrast = new ol.dom.Input(document.getElementById('contrast'));
|
||||
contrast.bindTo('value', layer, 'contrast')
|
||||
.transform(parseFloat, String);
|
||||
|
||||
var brightness = new ol.dom.Input(document.getElementById('brightness'));
|
||||
brightness.bindTo('value', layer, 'brightness')
|
||||
.transform(parseFloat, String);
|
||||
|
||||
|
||||
var rotation = new ol.dom.Input(document.getElementById('rotation'));
|
||||
rotation.bindTo('value', view, 'rotation').transform(parseFloat, String);
|
||||
|
||||
var resolution = new ol.dom.Input(document.getElementById('resolution'));
|
||||
resolution.bindTo('value', view, 'resolution').transform(parseFloat, String);
|
||||
@@ -2,7 +2,6 @@ goog.require('ol.DeviceOrientation');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.View');
|
||||
goog.require('ol.control');
|
||||
goog.require('ol.dom.Input');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.OSM');
|
||||
@@ -31,8 +30,10 @@ var map = new ol.Map({
|
||||
});
|
||||
|
||||
var deviceOrientation = new ol.DeviceOrientation();
|
||||
var track = new ol.dom.Input(document.getElementById('track'));
|
||||
track.bindTo('checked', deviceOrientation, 'tracking');
|
||||
|
||||
$('#track').on('change', function() {
|
||||
deviceOrientation.setTracking(this.checked);
|
||||
});
|
||||
|
||||
deviceOrientation.on('change', function(event) {
|
||||
$('#alpha').text(deviceOrientation.getAlpha() + ' [rad]');
|
||||
|
||||
@@ -4,7 +4,6 @@ goog.require('ol.Geolocation');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.View');
|
||||
goog.require('ol.control');
|
||||
goog.require('ol.dom.Input');
|
||||
goog.require('ol.geom.Point');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.source.OSM');
|
||||
@@ -37,8 +36,9 @@ var geolocation = new ol.Geolocation({
|
||||
projection: view.getProjection()
|
||||
});
|
||||
|
||||
var track = new ol.dom.Input(document.getElementById('track'));
|
||||
track.bindTo('checked', geolocation, 'tracking');
|
||||
$('#track').on('change', function() {
|
||||
geolocation.setTracking(this.checked);
|
||||
});
|
||||
|
||||
// update the HTML page when the position changes.
|
||||
geolocation.on('change', function() {
|
||||
@@ -57,7 +57,9 @@ geolocation.on('error', function(error) {
|
||||
});
|
||||
|
||||
var accuracyFeature = new ol.Feature();
|
||||
accuracyFeature.bindTo('geometry', geolocation, 'accuracyGeometry');
|
||||
geolocation.on('change:accuracyGeometry', function() {
|
||||
accuracyFeature.setGeometry(geolocation.getAccuracyGeometry());
|
||||
});
|
||||
|
||||
var positionFeature = new ol.Feature();
|
||||
positionFeature.setStyle(new ol.style.Style({
|
||||
@@ -73,10 +75,11 @@ positionFeature.setStyle(new ol.style.Style({
|
||||
})
|
||||
}));
|
||||
|
||||
positionFeature.bindTo('geometry', geolocation, 'position')
|
||||
.transform(function() {}, function(coordinates) {
|
||||
return coordinates ? new ol.geom.Point(coordinates) : null;
|
||||
});
|
||||
geolocation.on('change:position', function() {
|
||||
var coordinates = geolocation.getPosition();
|
||||
positionFeature.setGeometry(coordinates ?
|
||||
new ol.geom.Point(coordinates) : null);
|
||||
});
|
||||
|
||||
var featuresOverlay = new ol.FeatureOverlay({
|
||||
map: map,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.View');
|
||||
goog.require('ol.dom.Input');
|
||||
goog.require('ol.layer.Group');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.proj');
|
||||
@@ -39,13 +38,19 @@ var map = new ol.Map({
|
||||
});
|
||||
|
||||
function bindInputs(layerid, layer) {
|
||||
new ol.dom.Input($(layerid + ' .visible')[0])
|
||||
.bindTo('checked', layer, 'visible');
|
||||
var visibilityInput = $(layerid + ' input.visible');
|
||||
visibilityInput.on('change', function() {
|
||||
layer.setVisible(this.checked);
|
||||
});
|
||||
visibilityInput.prop('checked', layer.getVisible());
|
||||
|
||||
$.each(['opacity', 'hue', 'saturation', 'contrast', 'brightness'],
|
||||
function(i, v) {
|
||||
new ol.dom.Input($(layerid + ' .' + v)[0])
|
||||
.bindTo('value', layer, v)
|
||||
.transform(parseFloat, String);
|
||||
var input = $(layerid + ' input.' + v);
|
||||
input.on('input change', function() {
|
||||
layer.set(v, parseFloat(this.value));
|
||||
});
|
||||
input.val(String(layer.get(v)));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ goog.require('ol.View');
|
||||
goog.require('ol.control');
|
||||
goog.require('ol.control.MousePosition');
|
||||
goog.require('ol.coordinate');
|
||||
goog.require('ol.dom.Input');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.OSM');
|
||||
@@ -37,20 +36,14 @@ var map = new ol.Map({
|
||||
})
|
||||
});
|
||||
|
||||
var projectionSelect = new ol.dom.Input(document.getElementById('projection'));
|
||||
projectionSelect.bindTo('value', mousePositionControl, 'projection')
|
||||
.transform(
|
||||
function(code) {
|
||||
// projectionSelect.value -> mousePositionControl.projection
|
||||
return ol.proj.get(/** @type {string} */ (code));
|
||||
},
|
||||
function(projection) {
|
||||
// mousePositionControl.projection -> projectionSelect.value
|
||||
return projection.getCode();
|
||||
});
|
||||
var projectionSelect = $('#projection');
|
||||
projectionSelect.on('change', function() {
|
||||
mousePositionControl.setProjection(ol.proj.get(this.value));
|
||||
});
|
||||
projectionSelect.val(mousePositionControl.getProjection().getCode());
|
||||
|
||||
var precisionInput = document.getElementById('precision');
|
||||
precisionInput.addEventListener('change', function() {
|
||||
var format = ol.coordinate.createStringXY(precisionInput.valueAsNumber);
|
||||
var precisionInput = $('#precision');
|
||||
precisionInput.on('change', function() {
|
||||
var format = ol.coordinate.createStringXY(this.valueAsNumber);
|
||||
mousePositionControl.setCoordinateFormat(format);
|
||||
}, false);
|
||||
});
|
||||
|
||||
@@ -4,6 +4,11 @@ goog.require('ol.layer.Tile');
|
||||
goog.require('ol.source.BingMaps');
|
||||
|
||||
|
||||
var view = new ol.View({
|
||||
center: [-4808600, -2620936],
|
||||
zoom: 8
|
||||
});
|
||||
|
||||
var map1 = new ol.Map({
|
||||
layers: [
|
||||
new ol.layer.Tile({
|
||||
@@ -16,10 +21,7 @@ var map1 = new ol.Map({
|
||||
],
|
||||
renderer: exampleNS.getRendererFromQueryString(),
|
||||
target: 'map1',
|
||||
view: new ol.View({
|
||||
center: [-4808600, -2620936],
|
||||
zoom: 8
|
||||
})
|
||||
view: view
|
||||
});
|
||||
|
||||
var map2 = new ol.Map({
|
||||
@@ -33,6 +35,6 @@ var map2 = new ol.Map({
|
||||
})
|
||||
],
|
||||
renderer: exampleNS.getRendererFromQueryString(),
|
||||
target: 'map2'
|
||||
target: 'map2',
|
||||
view: view
|
||||
});
|
||||
map2.bindTo('view', map1);
|
||||
|
||||
@@ -2,7 +2,6 @@ goog.require('ol.Map');
|
||||
goog.require('ol.View');
|
||||
goog.require('ol.control');
|
||||
goog.require('ol.control.ScaleLine');
|
||||
goog.require('ol.dom.Input');
|
||||
goog.require('ol.layer.Tile');
|
||||
goog.require('ol.source.OSM');
|
||||
|
||||
@@ -31,5 +30,8 @@ var map = new ol.Map({
|
||||
});
|
||||
|
||||
|
||||
var unitsSelect = new ol.dom.Input(document.getElementById('units'));
|
||||
unitsSelect.bindTo('value', scaleLineControl, 'units');
|
||||
var unitsSelect = $('#units');
|
||||
unitsSelect.on('change', function() {
|
||||
scaleLineControl.setUnits(this.value);
|
||||
});
|
||||
unitsSelect.val(scaleLineControl.getUnits());
|
||||
|
||||
@@ -22,10 +22,10 @@ var domMap = new ol.Map({
|
||||
if (ol.has.WEBGL) {
|
||||
var webglMap = new ol.Map({
|
||||
renderer: 'webgl',
|
||||
target: 'webglMap'
|
||||
target: 'webglMap',
|
||||
layers: domMap.getLayers(),
|
||||
view: domMap.getView()
|
||||
});
|
||||
webglMap.bindTo('layergroup', domMap);
|
||||
webglMap.bindTo('view', domMap);
|
||||
} else {
|
||||
var info = document.getElementById('no-webgl');
|
||||
/**
|
||||
@@ -35,7 +35,7 @@ if (ol.has.WEBGL) {
|
||||
}
|
||||
|
||||
var canvasMap = new ol.Map({
|
||||
target: 'canvasMap'
|
||||
target: 'canvasMap',
|
||||
layers: domMap.getLayers(),
|
||||
view: domMap.getView()
|
||||
});
|
||||
canvasMap.bindTo('layergroup', domMap);
|
||||
canvasMap.bindTo('view', domMap);
|
||||
|
||||
@@ -139,10 +139,6 @@ ol.control.MousePosition.prototype.getCoordinateFormat = function() {
|
||||
return /** @type {ol.CoordinateFormatType|undefined} */ (
|
||||
this.get(ol.control.MousePositionProperty.COORDINATE_FORMAT));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.control.MousePosition.prototype,
|
||||
'getCoordinateFormat',
|
||||
ol.control.MousePosition.prototype.getCoordinateFormat);
|
||||
|
||||
|
||||
/**
|
||||
@@ -155,10 +151,6 @@ ol.control.MousePosition.prototype.getProjection = function() {
|
||||
return /** @type {ol.proj.Projection|undefined} */ (
|
||||
this.get(ol.control.MousePositionProperty.PROJECTION));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.control.MousePosition.prototype,
|
||||
'getProjection',
|
||||
ol.control.MousePosition.prototype.getProjection);
|
||||
|
||||
|
||||
/**
|
||||
@@ -209,10 +201,6 @@ ol.control.MousePosition.prototype.setMap = function(map) {
|
||||
ol.control.MousePosition.prototype.setCoordinateFormat = function(format) {
|
||||
this.set(ol.control.MousePositionProperty.COORDINATE_FORMAT, format);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.control.MousePosition.prototype,
|
||||
'setCoordinateFormat',
|
||||
ol.control.MousePosition.prototype.setCoordinateFormat);
|
||||
|
||||
|
||||
/**
|
||||
@@ -224,10 +212,6 @@ goog.exportProperty(
|
||||
ol.control.MousePosition.prototype.setProjection = function(projection) {
|
||||
this.set(ol.control.MousePositionProperty.PROJECTION, projection);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.control.MousePosition.prototype,
|
||||
'setProjection',
|
||||
ol.control.MousePosition.prototype.setProjection);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,9 +12,11 @@ goog.require('ol.Collection');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.MapEventType');
|
||||
goog.require('ol.Object');
|
||||
goog.require('ol.ObjectEventType');
|
||||
goog.require('ol.Overlay');
|
||||
goog.require('ol.OverlayPositioning');
|
||||
goog.require('ol.View');
|
||||
goog.require('ol.ViewProperty');
|
||||
goog.require('ol.control.Control');
|
||||
goog.require('ol.coordinate');
|
||||
goog.require('ol.css');
|
||||
@@ -155,54 +157,89 @@ goog.inherits(ol.control.OverviewMap, ol.control.Control);
|
||||
* @api
|
||||
*/
|
||||
ol.control.OverviewMap.prototype.setMap = function(map) {
|
||||
var currentMap = this.getMap();
|
||||
|
||||
if (goog.isNull(map) && !goog.isNull(currentMap)) {
|
||||
goog.events.unlisten(
|
||||
currentMap, ol.Object.getChangeEventType(ol.MapProperty.VIEW),
|
||||
this.handleViewChanged_, false, this);
|
||||
var oldMap = this.getMap();
|
||||
if (map === oldMap) {
|
||||
return;
|
||||
}
|
||||
if (oldMap) {
|
||||
var oldView = oldMap.getView();
|
||||
if (oldView) {
|
||||
this.unbindView_(oldView);
|
||||
}
|
||||
}
|
||||
|
||||
goog.base(this, 'setMap', map);
|
||||
|
||||
if (!goog.isNull(map)) {
|
||||
if (map) {
|
||||
this.listenerKeys.push(goog.events.listen(
|
||||
map, ol.ObjectEventType.PROPERTYCHANGE,
|
||||
this.handleMapPropertyChange_, false, this));
|
||||
|
||||
// if no layers were set for the overviewmap map, then bind with
|
||||
// those in the main map
|
||||
// TODO: to really support map switching, this would need to be reworked
|
||||
if (this.ovmap_.getLayers().getLength() === 0) {
|
||||
this.ovmap_.bindTo(ol.MapProperty.LAYERGROUP, map);
|
||||
this.ovmap_.setLayerGroup(map.getLayerGroup());
|
||||
}
|
||||
|
||||
// bind current map view, or any new one
|
||||
this.bindView_();
|
||||
|
||||
goog.events.listen(
|
||||
map, ol.Object.getChangeEventType(ol.MapProperty.VIEW),
|
||||
this.handleViewChanged_, false, this);
|
||||
|
||||
this.ovmap_.updateSize();
|
||||
this.resetExtent_();
|
||||
var view = map.getView();
|
||||
if (view) {
|
||||
this.bindView_(view);
|
||||
if (view.isDef()) {
|
||||
this.ovmap_.updateSize();
|
||||
this.resetExtent_();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Bind some actions to the main map view.
|
||||
* Handle map property changes. This only deals with changes to the map's view.
|
||||
* @param {ol.ObjectEvent} event The propertychange event.
|
||||
* @private
|
||||
*/
|
||||
ol.control.OverviewMap.prototype.bindView_ = function() {
|
||||
var map = this.getMap();
|
||||
var view = map.getView();
|
||||
|
||||
// if the map does not have a view, we can't act upon it
|
||||
if (goog.isNull(view)) {
|
||||
return;
|
||||
ol.control.OverviewMap.prototype.handleMapPropertyChange_ = function(event) {
|
||||
if (event.key === ol.MapProperty.VIEW) {
|
||||
var oldView = /** @type {ol.View} */ (event.oldValue);
|
||||
if (oldView) {
|
||||
this.unbindView_(oldView);
|
||||
}
|
||||
var newView = this.getMap().getView();
|
||||
this.bindView_(newView);
|
||||
}
|
||||
};
|
||||
|
||||
// FIXME - the overviewmap view rotation currently follows the one used
|
||||
// by the main map view. We could support box rotation instead. The choice
|
||||
// between the 2 modes would be made in a single option
|
||||
this.ovmap_.getView().bindTo(ol.ViewProperty.ROTATION, view);
|
||||
|
||||
/**
|
||||
* Register listeners for view property changes.
|
||||
* @param {ol.View} view The view.
|
||||
* @private
|
||||
*/
|
||||
ol.control.OverviewMap.prototype.bindView_ = function(view) {
|
||||
goog.events.listen(view,
|
||||
ol.Object.getChangeEventType(ol.ViewProperty.ROTATION),
|
||||
this.handleRotationChanged_, false, this);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Unregister listeners for view property changes.
|
||||
* @param {ol.View} view The view.
|
||||
* @private
|
||||
*/
|
||||
ol.control.OverviewMap.prototype.unbindView_ = function(view) {
|
||||
goog.events.unlisten(view,
|
||||
ol.Object.getChangeEventType(ol.ViewProperty.ROTATION),
|
||||
this.handleRotationChanged_, false, this);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Handle rotation changes to the main map.
|
||||
* TODO: This should rotate the extent rectrangle instead of the
|
||||
* overview map's view.
|
||||
* @private
|
||||
*/
|
||||
ol.control.OverviewMap.prototype.handleRotationChanged_ = function() {
|
||||
this.ovmap_.getView().setRotation(this.getMap().getView().getRotation());
|
||||
};
|
||||
|
||||
|
||||
@@ -217,16 +254,6 @@ ol.control.OverviewMap.render = function(mapEvent) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Called on main map view changed.
|
||||
* @param {goog.events.Event} event Event.
|
||||
* @private
|
||||
*/
|
||||
ol.control.OverviewMap.prototype.handleViewChanged_ = function(event) {
|
||||
this.bindView_();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Reset the overview map extent if the box size (width or
|
||||
* height) is less than the size of the overview map size times minRatio
|
||||
|
||||
@@ -150,10 +150,6 @@ ol.control.ScaleLine.prototype.getUnits = function() {
|
||||
return /** @type {ol.control.ScaleLineUnits|undefined} */ (
|
||||
this.get(ol.control.ScaleLineProperty.UNITS));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.control.ScaleLine.prototype,
|
||||
'getUnits',
|
||||
ol.control.ScaleLine.prototype.getUnits);
|
||||
|
||||
|
||||
/**
|
||||
@@ -188,10 +184,6 @@ ol.control.ScaleLine.prototype.handleUnitsChanged_ = function() {
|
||||
ol.control.ScaleLine.prototype.setUnits = function(units) {
|
||||
this.set(ol.control.ScaleLineProperty.UNITS, units);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.control.ScaleLine.prototype,
|
||||
'setUnits',
|
||||
ol.control.ScaleLine.prototype.setUnits);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -147,10 +147,6 @@ ol.DeviceOrientation.prototype.getAlpha = function() {
|
||||
return /** @type {number|undefined} */ (
|
||||
this.get(ol.DeviceOrientationProperty.ALPHA));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.DeviceOrientation.prototype,
|
||||
'getAlpha',
|
||||
ol.DeviceOrientation.prototype.getAlpha);
|
||||
|
||||
|
||||
/**
|
||||
@@ -164,10 +160,6 @@ ol.DeviceOrientation.prototype.getBeta = function() {
|
||||
return /** @type {number|undefined} */ (
|
||||
this.get(ol.DeviceOrientationProperty.BETA));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.DeviceOrientation.prototype,
|
||||
'getBeta',
|
||||
ol.DeviceOrientation.prototype.getBeta);
|
||||
|
||||
|
||||
/**
|
||||
@@ -181,10 +173,6 @@ ol.DeviceOrientation.prototype.getGamma = function() {
|
||||
return /** @type {number|undefined} */ (
|
||||
this.get(ol.DeviceOrientationProperty.GAMMA));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.DeviceOrientation.prototype,
|
||||
'getGamma',
|
||||
ol.DeviceOrientation.prototype.getGamma);
|
||||
|
||||
|
||||
/**
|
||||
@@ -198,10 +186,6 @@ ol.DeviceOrientation.prototype.getHeading = function() {
|
||||
return /** @type {number|undefined} */ (
|
||||
this.get(ol.DeviceOrientationProperty.HEADING));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.DeviceOrientation.prototype,
|
||||
'getHeading',
|
||||
ol.DeviceOrientation.prototype.getHeading);
|
||||
|
||||
|
||||
/**
|
||||
@@ -214,10 +198,6 @@ ol.DeviceOrientation.prototype.getTracking = function() {
|
||||
return /** @type {boolean} */ (
|
||||
this.get(ol.DeviceOrientationProperty.TRACKING));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.DeviceOrientation.prototype,
|
||||
'getTracking',
|
||||
ol.DeviceOrientation.prototype.getTracking);
|
||||
|
||||
|
||||
/**
|
||||
@@ -247,7 +227,3 @@ ol.DeviceOrientation.prototype.handleTrackingChanged_ = function() {
|
||||
ol.DeviceOrientation.prototype.setTracking = function(tracking) {
|
||||
this.set(ol.DeviceOrientationProperty.TRACKING, tracking);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.DeviceOrientation.prototype,
|
||||
'setTracking',
|
||||
ol.DeviceOrientation.prototype.setTracking);
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
goog.provide('ol.dom.Input');
|
||||
goog.provide('ol.dom.InputProperty');
|
||||
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('ol.Object');
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.dom.InputProperty = {
|
||||
VALUE: 'value',
|
||||
CHECKED: 'checked'
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Helper class for binding HTML input to an {@link ol.Object}.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* // bind a checkbox with id 'visible' to a layer's visibility
|
||||
* var visible = new ol.dom.Input(document.getElementById('visible'));
|
||||
* visible.bindTo('checked', layer, 'visible');
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.Object}
|
||||
* @param {Element} target Target element.
|
||||
* @api
|
||||
*/
|
||||
ol.dom.Input = function(target) {
|
||||
goog.base(this);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLInputElement}
|
||||
*/
|
||||
this.target_ = /** @type {HTMLInputElement} */ (target);
|
||||
|
||||
goog.events.listen(this.target_,
|
||||
[goog.events.EventType.CHANGE, goog.events.EventType.INPUT],
|
||||
this.handleInputChanged_, false, this);
|
||||
|
||||
goog.events.listen(this,
|
||||
ol.Object.getChangeEventType(ol.dom.InputProperty.VALUE),
|
||||
this.handleValueChanged_, false, this);
|
||||
goog.events.listen(this,
|
||||
ol.Object.getChangeEventType(ol.dom.InputProperty.CHECKED),
|
||||
this.handleCheckedChanged_, false, this);
|
||||
};
|
||||
goog.inherits(ol.dom.Input, ol.Object);
|
||||
|
||||
|
||||
/**
|
||||
* If the input is a checkbox, return whether or not the checkbox is checked.
|
||||
* @return {boolean|undefined} The checked state of the Input.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
ol.dom.Input.prototype.getChecked = function() {
|
||||
return /** @type {boolean} */ (this.get(ol.dom.InputProperty.CHECKED));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.dom.Input.prototype,
|
||||
'getChecked',
|
||||
ol.dom.Input.prototype.getChecked);
|
||||
|
||||
|
||||
/**
|
||||
* Get the value of the input.
|
||||
* @return {string|undefined} The value of the Input.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
ol.dom.Input.prototype.getValue = function() {
|
||||
return /** @type {string} */ (this.get(ol.dom.InputProperty.VALUE));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.dom.Input.prototype,
|
||||
'getValue',
|
||||
ol.dom.Input.prototype.getValue);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the value of the input.
|
||||
* @param {string} value The value of the Input.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
ol.dom.Input.prototype.setValue = function(value) {
|
||||
this.set(ol.dom.InputProperty.VALUE, value);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.dom.Input.prototype,
|
||||
'setValue',
|
||||
ol.dom.Input.prototype.setValue);
|
||||
|
||||
|
||||
/**
|
||||
* Set whether or not a checkbox is checked.
|
||||
* @param {boolean} checked The checked state of the Input.
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
ol.dom.Input.prototype.setChecked = function(checked) {
|
||||
this.set(ol.dom.InputProperty.CHECKED, checked);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.dom.Input.prototype,
|
||||
'setChecked',
|
||||
ol.dom.Input.prototype.setChecked);
|
||||
|
||||
|
||||
/**
|
||||
* @param {goog.events.BrowserEvent} browserEvent Browser event.
|
||||
* @private
|
||||
*/
|
||||
ol.dom.Input.prototype.handleInputChanged_ = function(browserEvent) {
|
||||
goog.asserts.assert(browserEvent.currentTarget == this.target_,
|
||||
'currentTarget should be the same as this.target_');
|
||||
var target = this.target_;
|
||||
if (target.type === 'checkbox' || target.type === 'radio') {
|
||||
this.setChecked(target.checked);
|
||||
} else {
|
||||
this.setValue(target.value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {goog.events.Event} event Change event.
|
||||
* @private
|
||||
*/
|
||||
ol.dom.Input.prototype.handleCheckedChanged_ = function(event) {
|
||||
this.target_.checked = /** @type {boolean} */ (this.getChecked());
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {goog.events.Event} event Change event.
|
||||
* @private
|
||||
*/
|
||||
ol.dom.Input.prototype.handleValueChanged_ = function(event) {
|
||||
this.target_.value = /** @type {string} */ (this.getValue());
|
||||
};
|
||||
@@ -148,10 +148,6 @@ ol.Feature.prototype.getGeometry = function() {
|
||||
return /** @type {ol.geom.Geometry|undefined} */ (
|
||||
this.get(this.geometryName_));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Feature.prototype,
|
||||
'getGeometry',
|
||||
ol.Feature.prototype.getGeometry);
|
||||
|
||||
|
||||
/**
|
||||
@@ -233,10 +229,6 @@ ol.Feature.prototype.handleGeometryChanged_ = function() {
|
||||
ol.Feature.prototype.setGeometry = function(geometry) {
|
||||
this.set(this.geometryName_, geometry);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Feature.prototype,
|
||||
'setGeometry',
|
||||
ol.Feature.prototype.setGeometry);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -199,10 +199,6 @@ ol.Geolocation.prototype.getAccuracy = function() {
|
||||
return /** @type {number|undefined} */ (
|
||||
this.get(ol.GeolocationProperty.ACCURACY));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Geolocation.prototype,
|
||||
'getAccuracy',
|
||||
ol.Geolocation.prototype.getAccuracy);
|
||||
|
||||
|
||||
/**
|
||||
@@ -215,10 +211,6 @@ ol.Geolocation.prototype.getAccuracyGeometry = function() {
|
||||
return /** @type {?ol.geom.Geometry} */ (
|
||||
this.get(ol.GeolocationProperty.ACCURACY_GEOMETRY) || null);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Geolocation.prototype,
|
||||
'getAccuracyGeometry',
|
||||
ol.Geolocation.prototype.getAccuracyGeometry);
|
||||
|
||||
|
||||
/**
|
||||
@@ -232,10 +224,6 @@ ol.Geolocation.prototype.getAltitude = function() {
|
||||
return /** @type {number|undefined} */ (
|
||||
this.get(ol.GeolocationProperty.ALTITUDE));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Geolocation.prototype,
|
||||
'getAltitude',
|
||||
ol.Geolocation.prototype.getAltitude);
|
||||
|
||||
|
||||
/**
|
||||
@@ -249,10 +237,6 @@ ol.Geolocation.prototype.getAltitudeAccuracy = function() {
|
||||
return /** @type {number|undefined} */ (
|
||||
this.get(ol.GeolocationProperty.ALTITUDE_ACCURACY));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Geolocation.prototype,
|
||||
'getAltitudeAccuracy',
|
||||
ol.Geolocation.prototype.getAltitudeAccuracy);
|
||||
|
||||
|
||||
/**
|
||||
@@ -265,10 +249,6 @@ ol.Geolocation.prototype.getHeading = function() {
|
||||
return /** @type {number|undefined} */ (
|
||||
this.get(ol.GeolocationProperty.HEADING));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Geolocation.prototype,
|
||||
'getHeading',
|
||||
ol.Geolocation.prototype.getHeading);
|
||||
|
||||
|
||||
/**
|
||||
@@ -282,10 +262,6 @@ ol.Geolocation.prototype.getPosition = function() {
|
||||
return /** @type {ol.Coordinate|undefined} */ (
|
||||
this.get(ol.GeolocationProperty.POSITION));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Geolocation.prototype,
|
||||
'getPosition',
|
||||
ol.Geolocation.prototype.getPosition);
|
||||
|
||||
|
||||
/**
|
||||
@@ -299,10 +275,6 @@ ol.Geolocation.prototype.getProjection = function() {
|
||||
return /** @type {ol.proj.Projection|undefined} */ (
|
||||
this.get(ol.GeolocationProperty.PROJECTION));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Geolocation.prototype,
|
||||
'getProjection',
|
||||
ol.Geolocation.prototype.getProjection);
|
||||
|
||||
|
||||
/**
|
||||
@@ -316,10 +288,6 @@ ol.Geolocation.prototype.getSpeed = function() {
|
||||
return /** @type {number|undefined} */ (
|
||||
this.get(ol.GeolocationProperty.SPEED));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Geolocation.prototype,
|
||||
'getSpeed',
|
||||
ol.Geolocation.prototype.getSpeed);
|
||||
|
||||
|
||||
/**
|
||||
@@ -332,10 +300,6 @@ ol.Geolocation.prototype.getTracking = function() {
|
||||
return /** @type {boolean} */ (
|
||||
this.get(ol.GeolocationProperty.TRACKING));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Geolocation.prototype,
|
||||
'getTracking',
|
||||
ol.Geolocation.prototype.getTracking);
|
||||
|
||||
|
||||
/**
|
||||
@@ -351,10 +315,6 @@ ol.Geolocation.prototype.getTrackingOptions = function() {
|
||||
return /** @type {GeolocationPositionOptions|undefined} */ (
|
||||
this.get(ol.GeolocationProperty.TRACKING_OPTIONS));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Geolocation.prototype,
|
||||
'getTrackingOptions',
|
||||
ol.Geolocation.prototype.getTrackingOptions);
|
||||
|
||||
|
||||
/**
|
||||
@@ -367,10 +327,6 @@ goog.exportProperty(
|
||||
ol.Geolocation.prototype.setProjection = function(projection) {
|
||||
this.set(ol.GeolocationProperty.PROJECTION, projection);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Geolocation.prototype,
|
||||
'setProjection',
|
||||
ol.Geolocation.prototype.setProjection);
|
||||
|
||||
|
||||
/**
|
||||
@@ -382,10 +338,6 @@ goog.exportProperty(
|
||||
ol.Geolocation.prototype.setTracking = function(tracking) {
|
||||
this.set(ol.GeolocationProperty.TRACKING, tracking);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Geolocation.prototype,
|
||||
'setTracking',
|
||||
ol.Geolocation.prototype.setTracking);
|
||||
|
||||
|
||||
/**
|
||||
@@ -400,7 +352,3 @@ goog.exportProperty(
|
||||
ol.Geolocation.prototype.setTrackingOptions = function(options) {
|
||||
this.set(ol.GeolocationProperty.TRACKING_OPTIONS, options);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Geolocation.prototype,
|
||||
'setTrackingOptions',
|
||||
ol.Geolocation.prototype.setTrackingOptions);
|
||||
|
||||
@@ -65,10 +65,6 @@ ol.interaction.Interaction.prototype.getActive = function() {
|
||||
return /** @type {boolean} */ (
|
||||
this.get(ol.interaction.InteractionProperty.ACTIVE));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.interaction.Interaction.prototype,
|
||||
'getActive',
|
||||
ol.interaction.Interaction.prototype.getActive);
|
||||
|
||||
|
||||
/**
|
||||
@@ -89,10 +85,6 @@ ol.interaction.Interaction.prototype.getMap = function() {
|
||||
ol.interaction.Interaction.prototype.setActive = function(active) {
|
||||
this.set(ol.interaction.InteractionProperty.ACTIVE, active);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.interaction.Interaction.prototype,
|
||||
'setActive',
|
||||
ol.interaction.Interaction.prototype.setActive);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -178,10 +178,6 @@ ol.interaction.Snap.prototype.addFeature = function(feature, opt_listen) {
|
||||
}
|
||||
}
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.interaction.Snap.prototype,
|
||||
'addFeature',
|
||||
ol.interaction.Snap.prototype.addFeature);
|
||||
|
||||
|
||||
/**
|
||||
@@ -311,10 +307,6 @@ ol.interaction.Snap.prototype.removeFeature = function(feature, opt_unlisten) {
|
||||
}
|
||||
}
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.interaction.Snap.prototype,
|
||||
'removeFeature',
|
||||
ol.interaction.Snap.prototype.removeFeature);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -198,10 +198,6 @@ ol.layer.Heatmap.prototype.createCircle_ = function() {
|
||||
ol.layer.Heatmap.prototype.getBlur = function() {
|
||||
return /** @type {number} */ (this.get(ol.layer.HeatmapLayerProperty.BLUR));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Heatmap.prototype,
|
||||
'getBlur',
|
||||
ol.layer.Heatmap.prototype.getBlur);
|
||||
|
||||
|
||||
/**
|
||||
@@ -213,10 +209,6 @@ ol.layer.Heatmap.prototype.getGradient = function() {
|
||||
return /** @type {Array.<string>} */ (
|
||||
this.get(ol.layer.HeatmapLayerProperty.GRADIENT));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Heatmap.prototype,
|
||||
'getGradient',
|
||||
ol.layer.Heatmap.prototype.getGradient);
|
||||
|
||||
|
||||
/**
|
||||
@@ -227,10 +219,6 @@ goog.exportProperty(
|
||||
ol.layer.Heatmap.prototype.getRadius = function() {
|
||||
return /** @type {number} */ (this.get(ol.layer.HeatmapLayerProperty.RADIUS));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Heatmap.prototype,
|
||||
'getRadius',
|
||||
ol.layer.Heatmap.prototype.getRadius);
|
||||
|
||||
|
||||
/**
|
||||
@@ -285,10 +273,6 @@ ol.layer.Heatmap.prototype.handleRender_ = function(event) {
|
||||
ol.layer.Heatmap.prototype.setBlur = function(blur) {
|
||||
this.set(ol.layer.HeatmapLayerProperty.BLUR, blur);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Heatmap.prototype,
|
||||
'setBlur',
|
||||
ol.layer.Heatmap.prototype.setBlur);
|
||||
|
||||
|
||||
/**
|
||||
@@ -299,10 +283,6 @@ goog.exportProperty(
|
||||
ol.layer.Heatmap.prototype.setGradient = function(colors) {
|
||||
this.set(ol.layer.HeatmapLayerProperty.GRADIENT, colors);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Heatmap.prototype,
|
||||
'setGradient',
|
||||
ol.layer.Heatmap.prototype.setGradient);
|
||||
|
||||
|
||||
/**
|
||||
@@ -313,7 +293,3 @@ goog.exportProperty(
|
||||
ol.layer.Heatmap.prototype.setRadius = function(radius) {
|
||||
this.set(ol.layer.HeatmapLayerProperty.RADIUS, radius);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Heatmap.prototype,
|
||||
'setRadius',
|
||||
ol.layer.Heatmap.prototype.setRadius);
|
||||
|
||||
@@ -93,10 +93,6 @@ ol.layer.Layer.prototype.getSource = function() {
|
||||
return goog.isDef(source) ?
|
||||
/** @type {ol.source.Source} */ (source) : null;
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Layer.prototype,
|
||||
'getSource',
|
||||
ol.layer.Layer.prototype.getSource);
|
||||
|
||||
|
||||
/**
|
||||
@@ -142,7 +138,3 @@ ol.layer.Layer.prototype.handleSourcePropertyChange_ = function() {
|
||||
ol.layer.Layer.prototype.setSource = function(source) {
|
||||
this.set(ol.layer.LayerProperty.SOURCE, source);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Layer.prototype,
|
||||
'setSource',
|
||||
ol.layer.Layer.prototype.setSource);
|
||||
|
||||
@@ -94,10 +94,6 @@ goog.inherits(ol.layer.Base, ol.Object);
|
||||
ol.layer.Base.prototype.getBrightness = function() {
|
||||
return /** @type {number} */ (this.get(ol.layer.LayerProperty.BRIGHTNESS));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'getBrightness',
|
||||
ol.layer.Base.prototype.getBrightness);
|
||||
|
||||
|
||||
/**
|
||||
@@ -108,10 +104,6 @@ goog.exportProperty(
|
||||
ol.layer.Base.prototype.getContrast = function() {
|
||||
return /** @type {number} */ (this.get(ol.layer.LayerProperty.CONTRAST));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'getContrast',
|
||||
ol.layer.Base.prototype.getContrast);
|
||||
|
||||
|
||||
/**
|
||||
@@ -122,10 +114,6 @@ goog.exportProperty(
|
||||
ol.layer.Base.prototype.getHue = function() {
|
||||
return /** @type {number} */ (this.get(ol.layer.LayerProperty.HUE));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'getHue',
|
||||
ol.layer.Base.prototype.getHue);
|
||||
|
||||
|
||||
/**
|
||||
@@ -183,10 +171,6 @@ ol.layer.Base.prototype.getExtent = function() {
|
||||
return /** @type {ol.Extent|undefined} */ (
|
||||
this.get(ol.layer.LayerProperty.EXTENT));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'getExtent',
|
||||
ol.layer.Base.prototype.getExtent);
|
||||
|
||||
|
||||
/**
|
||||
@@ -198,10 +182,6 @@ ol.layer.Base.prototype.getMaxResolution = function() {
|
||||
return /** @type {number} */ (
|
||||
this.get(ol.layer.LayerProperty.MAX_RESOLUTION));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'getMaxResolution',
|
||||
ol.layer.Base.prototype.getMaxResolution);
|
||||
|
||||
|
||||
/**
|
||||
@@ -213,10 +193,6 @@ ol.layer.Base.prototype.getMinResolution = function() {
|
||||
return /** @type {number} */ (
|
||||
this.get(ol.layer.LayerProperty.MIN_RESOLUTION));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'getMinResolution',
|
||||
ol.layer.Base.prototype.getMinResolution);
|
||||
|
||||
|
||||
/**
|
||||
@@ -227,10 +203,6 @@ goog.exportProperty(
|
||||
ol.layer.Base.prototype.getOpacity = function() {
|
||||
return /** @type {number} */ (this.get(ol.layer.LayerProperty.OPACITY));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'getOpacity',
|
||||
ol.layer.Base.prototype.getOpacity);
|
||||
|
||||
|
||||
/**
|
||||
@@ -241,10 +213,6 @@ goog.exportProperty(
|
||||
ol.layer.Base.prototype.getSaturation = function() {
|
||||
return /** @type {number} */ (this.get(ol.layer.LayerProperty.SATURATION));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'getSaturation',
|
||||
ol.layer.Base.prototype.getSaturation);
|
||||
|
||||
|
||||
/**
|
||||
@@ -261,10 +229,6 @@ ol.layer.Base.prototype.getSourceState = goog.abstractMethod;
|
||||
ol.layer.Base.prototype.getVisible = function() {
|
||||
return /** @type {boolean} */ (this.get(ol.layer.LayerProperty.VISIBLE));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'getVisible',
|
||||
ol.layer.Base.prototype.getVisible);
|
||||
|
||||
|
||||
/**
|
||||
@@ -292,10 +256,6 @@ goog.exportProperty(
|
||||
ol.layer.Base.prototype.setBrightness = function(brightness) {
|
||||
this.set(ol.layer.LayerProperty.BRIGHTNESS, brightness);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'setBrightness',
|
||||
ol.layer.Base.prototype.setBrightness);
|
||||
|
||||
|
||||
/**
|
||||
@@ -310,10 +270,6 @@ goog.exportProperty(
|
||||
ol.layer.Base.prototype.setContrast = function(contrast) {
|
||||
this.set(ol.layer.LayerProperty.CONTRAST, contrast);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'setContrast',
|
||||
ol.layer.Base.prototype.setContrast);
|
||||
|
||||
|
||||
/**
|
||||
@@ -326,10 +282,6 @@ goog.exportProperty(
|
||||
ol.layer.Base.prototype.setHue = function(hue) {
|
||||
this.set(ol.layer.LayerProperty.HUE, hue);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'setHue',
|
||||
ol.layer.Base.prototype.setHue);
|
||||
|
||||
|
||||
/**
|
||||
@@ -342,10 +294,6 @@ goog.exportProperty(
|
||||
ol.layer.Base.prototype.setExtent = function(extent) {
|
||||
this.set(ol.layer.LayerProperty.EXTENT, extent);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'setExtent',
|
||||
ol.layer.Base.prototype.setExtent);
|
||||
|
||||
|
||||
/**
|
||||
@@ -356,10 +304,6 @@ goog.exportProperty(
|
||||
ol.layer.Base.prototype.setMaxResolution = function(maxResolution) {
|
||||
this.set(ol.layer.LayerProperty.MAX_RESOLUTION, maxResolution);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'setMaxResolution',
|
||||
ol.layer.Base.prototype.setMaxResolution);
|
||||
|
||||
|
||||
/**
|
||||
@@ -370,10 +314,6 @@ goog.exportProperty(
|
||||
ol.layer.Base.prototype.setMinResolution = function(minResolution) {
|
||||
this.set(ol.layer.LayerProperty.MIN_RESOLUTION, minResolution);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'setMinResolution',
|
||||
ol.layer.Base.prototype.setMinResolution);
|
||||
|
||||
|
||||
/**
|
||||
@@ -384,10 +324,6 @@ goog.exportProperty(
|
||||
ol.layer.Base.prototype.setOpacity = function(opacity) {
|
||||
this.set(ol.layer.LayerProperty.OPACITY, opacity);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'setOpacity',
|
||||
ol.layer.Base.prototype.setOpacity);
|
||||
|
||||
|
||||
/**
|
||||
@@ -403,10 +339,6 @@ goog.exportProperty(
|
||||
ol.layer.Base.prototype.setSaturation = function(saturation) {
|
||||
this.set(ol.layer.LayerProperty.SATURATION, saturation);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'setSaturation',
|
||||
ol.layer.Base.prototype.setSaturation);
|
||||
|
||||
|
||||
/**
|
||||
@@ -417,7 +349,3 @@ goog.exportProperty(
|
||||
ol.layer.Base.prototype.setVisible = function(visible) {
|
||||
this.set(ol.layer.LayerProperty.VISIBLE, visible);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Base.prototype,
|
||||
'setVisible',
|
||||
ol.layer.Base.prototype.setVisible);
|
||||
|
||||
@@ -155,10 +155,6 @@ ol.layer.Group.prototype.getLayers = function() {
|
||||
return /** @type {!ol.Collection.<ol.layer.Base>} */ (this.get(
|
||||
ol.layer.GroupProperty.LAYERS));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Group.prototype,
|
||||
'getLayers',
|
||||
ol.layer.Group.prototype.getLayers);
|
||||
|
||||
|
||||
/**
|
||||
@@ -170,10 +166,6 @@ goog.exportProperty(
|
||||
ol.layer.Group.prototype.setLayers = function(layers) {
|
||||
this.set(ol.layer.GroupProperty.LAYERS, layers);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Group.prototype,
|
||||
'setLayers',
|
||||
ol.layer.Group.prototype.setLayers);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -52,10 +52,6 @@ goog.inherits(ol.layer.Tile, ol.layer.Layer);
|
||||
ol.layer.Tile.prototype.getPreload = function() {
|
||||
return /** @type {number} */ (this.get(ol.layer.TileProperty.PRELOAD));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Tile.prototype,
|
||||
'getPreload',
|
||||
ol.layer.Tile.prototype.getPreload);
|
||||
|
||||
|
||||
/**
|
||||
@@ -74,10 +70,6 @@ ol.layer.Tile.prototype.getSource;
|
||||
ol.layer.Tile.prototype.setPreload = function(preload) {
|
||||
this.set(ol.layer.TileProperty.PRELOAD, preload);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Tile.prototype,
|
||||
'setPreload',
|
||||
ol.layer.Tile.prototype.setPreload);
|
||||
|
||||
|
||||
/**
|
||||
@@ -89,10 +81,6 @@ ol.layer.Tile.prototype.getUseInterimTilesOnError = function() {
|
||||
return /** @type {boolean} */ (
|
||||
this.get(ol.layer.TileProperty.USE_INTERIM_TILES_ON_ERROR));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Tile.prototype,
|
||||
'getUseInterimTilesOnError',
|
||||
ol.layer.Tile.prototype.getUseInterimTilesOnError);
|
||||
|
||||
|
||||
/**
|
||||
@@ -105,7 +93,3 @@ ol.layer.Tile.prototype.setUseInterimTilesOnError =
|
||||
this.set(
|
||||
ol.layer.TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.layer.Tile.prototype,
|
||||
'setUseInterimTilesOnError',
|
||||
ol.layer.Tile.prototype.setUseInterimTilesOnError);
|
||||
|
||||
@@ -709,10 +709,6 @@ ol.Map.prototype.getTarget = function() {
|
||||
return /** @type {Element|string|undefined} */ (
|
||||
this.get(ol.MapProperty.TARGET));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Map.prototype,
|
||||
'getTarget',
|
||||
ol.Map.prototype.getTarget);
|
||||
|
||||
|
||||
/**
|
||||
@@ -790,10 +786,6 @@ ol.Map.prototype.getInteractions = function() {
|
||||
ol.Map.prototype.getLayerGroup = function() {
|
||||
return /** @type {ol.layer.Group} */ (this.get(ol.MapProperty.LAYERGROUP));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Map.prototype,
|
||||
'getLayerGroup',
|
||||
ol.Map.prototype.getLayerGroup);
|
||||
|
||||
|
||||
/**
|
||||
@@ -843,10 +835,6 @@ ol.Map.prototype.getRenderer = function() {
|
||||
ol.Map.prototype.getSize = function() {
|
||||
return /** @type {ol.Size|undefined} */ (this.get(ol.MapProperty.SIZE));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Map.prototype,
|
||||
'getSize',
|
||||
ol.Map.prototype.getSize);
|
||||
|
||||
|
||||
/**
|
||||
@@ -859,10 +847,6 @@ goog.exportProperty(
|
||||
ol.Map.prototype.getView = function() {
|
||||
return /** @type {ol.View} */ (this.get(ol.MapProperty.VIEW));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Map.prototype,
|
||||
'getView',
|
||||
ol.Map.prototype.getView);
|
||||
|
||||
|
||||
/**
|
||||
@@ -1385,10 +1369,6 @@ ol.Map.prototype.renderFrame_ = function(time) {
|
||||
ol.Map.prototype.setLayerGroup = function(layerGroup) {
|
||||
this.set(ol.MapProperty.LAYERGROUP, layerGroup);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Map.prototype,
|
||||
'setLayerGroup',
|
||||
ol.Map.prototype.setLayerGroup);
|
||||
|
||||
|
||||
/**
|
||||
@@ -1400,10 +1380,6 @@ goog.exportProperty(
|
||||
ol.Map.prototype.setSize = function(size) {
|
||||
this.set(ol.MapProperty.SIZE, size);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Map.prototype,
|
||||
'setSize',
|
||||
ol.Map.prototype.setSize);
|
||||
|
||||
|
||||
/**
|
||||
@@ -1416,10 +1392,6 @@ goog.exportProperty(
|
||||
ol.Map.prototype.setTarget = function(target) {
|
||||
this.set(ol.MapProperty.TARGET, target);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Map.prototype,
|
||||
'setTarget',
|
||||
ol.Map.prototype.setTarget);
|
||||
|
||||
|
||||
/**
|
||||
@@ -1431,10 +1403,6 @@ goog.exportProperty(
|
||||
ol.Map.prototype.setView = function(view) {
|
||||
this.set(ol.MapProperty.VIEW, view);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Map.prototype,
|
||||
'setView',
|
||||
ol.Map.prototype.setView);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
284
src/ol/object.js
284
src/ol/object.js
@@ -1,18 +1,10 @@
|
||||
/**
|
||||
* An implementation of Google Maps' MVCObject.
|
||||
* @see https://developers.google.com/maps/articles/mvcfun
|
||||
* @see https://developers.google.com/maps/documentation/javascript/reference
|
||||
*/
|
||||
|
||||
goog.provide('ol.Object');
|
||||
goog.provide('ol.ObjectEvent');
|
||||
goog.provide('ol.ObjectEventType');
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.Event');
|
||||
goog.require('goog.functions');
|
||||
goog.require('goog.object');
|
||||
goog.require('goog.string');
|
||||
goog.require('ol.Observable');
|
||||
|
||||
|
||||
@@ -64,63 +56,6 @@ goog.inherits(ol.ObjectEvent, goog.events.Event);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {ol.Object} source Source object.
|
||||
* @param {ol.Object} target Target object.
|
||||
* @param {string} sourceKey Source key.
|
||||
* @param {string} targetKey Target key.
|
||||
*/
|
||||
ol.ObjectAccessor = function(source, target, sourceKey, targetKey) {
|
||||
|
||||
/**
|
||||
* @type {ol.Object}
|
||||
*/
|
||||
this.source = source;
|
||||
|
||||
/**
|
||||
* @type {ol.Object}
|
||||
*/
|
||||
this.target = target;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.sourceKey = sourceKey;
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.targetKey = targetKey;
|
||||
|
||||
/**
|
||||
* @type {function(?): ?}
|
||||
*/
|
||||
this.from = goog.functions.identity;
|
||||
|
||||
/**
|
||||
* @type {function(?): ?}
|
||||
*/
|
||||
this.to = goog.functions.identity;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {function(?): ?} from A function that transforms the source value
|
||||
* before it is set to the target.
|
||||
* @param {function(?): ?} to A function that transforms the target value
|
||||
* before it is set to the source.
|
||||
* @api
|
||||
*/
|
||||
ol.ObjectAccessor.prototype.transform = function(from, to) {
|
||||
var oldValue = ol.Object.getKeyValue_(this.source, this.sourceKey);
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.source.notify(this.sourceKey, oldValue);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Abstract base class; normally only used for creating subclasses and not
|
||||
@@ -157,12 +92,6 @@ ol.ObjectAccessor.prototype.transform = function(from, to) {
|
||||
* first will be a `hasOwnProperty`; the second will appear in
|
||||
* `getProperties()`. Only the second is observable.
|
||||
*
|
||||
* The observable properties also implement a form of Key Value Observing.
|
||||
* Two objects can be bound together such that a change in one will
|
||||
* automatically be reflected in the other. See `bindTo` method for more
|
||||
* details, and see {@link ol.dom.Input} for the specific case of binding an
|
||||
* object with an HTML element.
|
||||
*
|
||||
* Properties can be deleted by using the unset method. E.g.
|
||||
* object.unset('foo').
|
||||
*
|
||||
@@ -187,18 +116,6 @@ ol.Object = function(opt_values) {
|
||||
*/
|
||||
this.values_ = {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string, ol.ObjectAccessor>}
|
||||
*/
|
||||
this.accessors_ = {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string, goog.events.Key>}
|
||||
*/
|
||||
this.listeners_ = {};
|
||||
|
||||
if (goog.isDef(opt_values)) {
|
||||
this.setProperties(opt_values);
|
||||
}
|
||||
@@ -213,20 +130,6 @@ goog.inherits(ol.Object, ol.Observable);
|
||||
ol.Object.changeEventTypeCache_ = {};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string, string>}
|
||||
*/
|
||||
ol.Object.getterNameCache_ = {};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string, string>}
|
||||
*/
|
||||
ol.Object.setterNameCache_ = {};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} key Key name.
|
||||
* @return {string} Change name.
|
||||
@@ -238,116 +141,6 @@ ol.Object.getChangeEventType = function(key) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} key String.
|
||||
* @return {string} Getter name.
|
||||
*/
|
||||
ol.Object.getGetterName = function(key) {
|
||||
return ol.Object.getterNameCache_.hasOwnProperty(key) ?
|
||||
ol.Object.getterNameCache_[key] :
|
||||
(ol.Object.getterNameCache_[key] = 'get' + goog.string.capitalize(key));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} key String.
|
||||
* @return {string} Setter name.
|
||||
*/
|
||||
ol.Object.getSetterName = function(key) {
|
||||
return ol.Object.setterNameCache_.hasOwnProperty(key) ?
|
||||
ol.Object.setterNameCache_[key] :
|
||||
(ol.Object.setterNameCache_[key] = 'set' + goog.string.capitalize(key));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the value for an object and a key. Use the getter (`getX`) if it exists,
|
||||
* otherwise use the generic `get` function.
|
||||
* @param {ol.Object} obj Object.
|
||||
* @param {string} key Key;
|
||||
* @return {*} Value;
|
||||
* @private
|
||||
*/
|
||||
ol.Object.getKeyValue_ = function(obj, key) {
|
||||
var getterName = ol.Object.getGetterName(key);
|
||||
var getter = /** @type {function(): *|undefined} */
|
||||
(/** @type {Object} */ (obj)[getterName]);
|
||||
return goog.isDef(getter) ? getter.call(obj) : obj.get(key);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the value for an object and a key. Use the setter (`setX`) if it exists,
|
||||
* otherwise use the generic `set` function.
|
||||
* @param {ol.Object} obj Object.
|
||||
* @param {string} key Key.
|
||||
* @param {*} value Value.
|
||||
* @private
|
||||
*/
|
||||
ol.Object.setKeyValue_ = function(obj, key, value) {
|
||||
var setterName = ol.Object.getSetterName(key);
|
||||
var setter = /** @type {function(*)|undefined} */
|
||||
(/** @type {Object} */ (obj)[setterName]);
|
||||
if (goog.isDef(setter)) {
|
||||
setter.call(obj, value);
|
||||
} else {
|
||||
obj.set(key, value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The bindTo method allows you to set up a two-way binding between a
|
||||
* `source` and `target` object. The method returns an object with a
|
||||
* `transform` method that you can use to provide `from` and `to`
|
||||
* functions to transform values on the way from the source to the
|
||||
* target and on the way back.
|
||||
*
|
||||
* For example, if you had two map views (sourceView and targetView)
|
||||
* and you wanted the target view to have double the resolution of the
|
||||
* source view, you could transform the resolution on the way to and
|
||||
* from the target with the following:
|
||||
*
|
||||
* sourceView.bindTo('resolution', targetView)
|
||||
* .transform(
|
||||
* function(sourceResolution) {
|
||||
* // from sourceView.resolution to targetView.resolution
|
||||
* return 2 * sourceResolution;
|
||||
* },
|
||||
* function(targetResolution) {
|
||||
* // from targetView.resolution to sourceView.resolution
|
||||
* return targetResolution / 2;
|
||||
* }
|
||||
* );
|
||||
*
|
||||
* @param {string} key Key name.
|
||||
* @param {ol.Object} target Target.
|
||||
* @param {string=} opt_targetKey Target key.
|
||||
* @return {ol.ObjectAccessor}
|
||||
* @api
|
||||
*/
|
||||
ol.Object.prototype.bindTo = function(key, target, opt_targetKey) {
|
||||
var targetKey = opt_targetKey || key;
|
||||
this.unbind(key);
|
||||
|
||||
// listen for change:targetkey events
|
||||
var eventType = ol.Object.getChangeEventType(targetKey);
|
||||
this.listeners_[key] = goog.events.listen(target, eventType,
|
||||
/**
|
||||
* @param {ol.ObjectEvent} e Event.
|
||||
* @this {ol.Object}
|
||||
*/
|
||||
function(e) {
|
||||
this.notify(key, e.oldValue);
|
||||
}, undefined, this);
|
||||
|
||||
var accessor = new ol.ObjectAccessor(this, target, key, targetKey);
|
||||
this.accessors_[key] = accessor;
|
||||
this.notify(key, this.values_[key]);
|
||||
return accessor;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gets a value.
|
||||
* @param {string} key Key name.
|
||||
@@ -356,12 +149,7 @@ ol.Object.prototype.bindTo = function(key, target, opt_targetKey) {
|
||||
*/
|
||||
ol.Object.prototype.get = function(key) {
|
||||
var value;
|
||||
var accessors = this.accessors_;
|
||||
if (accessors.hasOwnProperty(key)) {
|
||||
var accessor = accessors[key];
|
||||
value = ol.Object.getKeyValue_(accessor.target, accessor.targetKey);
|
||||
value = accessor.to(value);
|
||||
} else if (this.values_.hasOwnProperty(key)) {
|
||||
if (this.values_.hasOwnProperty(key)) {
|
||||
value = this.values_[key];
|
||||
}
|
||||
return value;
|
||||
@@ -374,29 +162,7 @@ ol.Object.prototype.get = function(key) {
|
||||
* @api stable
|
||||
*/
|
||||
ol.Object.prototype.getKeys = function() {
|
||||
var accessors = this.accessors_;
|
||||
var keysObject;
|
||||
if (goog.object.isEmpty(this.values_)) {
|
||||
if (goog.object.isEmpty(accessors)) {
|
||||
return [];
|
||||
} else {
|
||||
keysObject = accessors;
|
||||
}
|
||||
} else {
|
||||
if (goog.object.isEmpty(accessors)) {
|
||||
keysObject = this.values_;
|
||||
} else {
|
||||
keysObject = {};
|
||||
var key;
|
||||
for (key in this.values_) {
|
||||
keysObject[key] = true;
|
||||
}
|
||||
for (key in accessors) {
|
||||
keysObject[key] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return goog.object.getKeys(keysObject);
|
||||
return goog.object.getKeys(this.values_);
|
||||
};
|
||||
|
||||
|
||||
@@ -411,9 +177,6 @@ ol.Object.prototype.getProperties = function() {
|
||||
for (key in this.values_) {
|
||||
properties[key] = this.values_[key];
|
||||
}
|
||||
for (key in this.accessors_) {
|
||||
properties[key] = this.get(key);
|
||||
}
|
||||
return properties;
|
||||
};
|
||||
|
||||
@@ -438,16 +201,9 @@ ol.Object.prototype.notify = function(key, oldValue) {
|
||||
* @api stable
|
||||
*/
|
||||
ol.Object.prototype.set = function(key, value) {
|
||||
var accessors = this.accessors_;
|
||||
if (accessors.hasOwnProperty(key)) {
|
||||
var accessor = accessors[key];
|
||||
value = accessor.from(value);
|
||||
ol.Object.setKeyValue_(accessor.target, accessor.targetKey, value);
|
||||
} else {
|
||||
var oldValue = this.values_[key];
|
||||
this.values_[key] = value;
|
||||
this.notify(key, oldValue);
|
||||
}
|
||||
var oldValue = this.values_[key];
|
||||
this.values_[key] = value;
|
||||
this.notify(key, oldValue);
|
||||
};
|
||||
|
||||
|
||||
@@ -465,36 +221,6 @@ ol.Object.prototype.setProperties = function(values) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Removes a binding. Unbinding will set the unbound property to the current
|
||||
* value. The object will not be notified, as the value has not changed.
|
||||
* @param {string} key Key name.
|
||||
* @api
|
||||
*/
|
||||
ol.Object.prototype.unbind = function(key) {
|
||||
var listeners = this.listeners_;
|
||||
var listener = listeners[key];
|
||||
if (listener) {
|
||||
delete listeners[key];
|
||||
goog.events.unlistenByKey(listener);
|
||||
var value = this.get(key);
|
||||
delete this.accessors_[key];
|
||||
this.values_[key] = value;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Removes all bindings.
|
||||
* @api
|
||||
*/
|
||||
ol.Object.prototype.unbindAll = function() {
|
||||
for (var key in this.listeners_) {
|
||||
this.unbind(key);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Unsets a property.
|
||||
* @param {string} key Key name.
|
||||
|
||||
@@ -186,10 +186,6 @@ ol.Overlay.prototype.getElement = function() {
|
||||
return /** @type {Element|undefined} */ (
|
||||
this.get(ol.OverlayProperty.ELEMENT));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Overlay.prototype,
|
||||
'getElement',
|
||||
ol.Overlay.prototype.getElement);
|
||||
|
||||
|
||||
/**
|
||||
@@ -202,10 +198,6 @@ ol.Overlay.prototype.getMap = function() {
|
||||
return /** @type {ol.Map|undefined} */ (
|
||||
this.get(ol.OverlayProperty.MAP));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Overlay.prototype,
|
||||
'getMap',
|
||||
ol.Overlay.prototype.getMap);
|
||||
|
||||
|
||||
/**
|
||||
@@ -218,10 +210,6 @@ ol.Overlay.prototype.getOffset = function() {
|
||||
return /** @type {Array.<number>} */ (
|
||||
this.get(ol.OverlayProperty.OFFSET));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Overlay.prototype,
|
||||
'getOffset',
|
||||
ol.Overlay.prototype.getOffset);
|
||||
|
||||
|
||||
/**
|
||||
@@ -235,10 +223,6 @@ ol.Overlay.prototype.getPosition = function() {
|
||||
return /** @type {ol.Coordinate|undefined} */ (
|
||||
this.get(ol.OverlayProperty.POSITION));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Overlay.prototype,
|
||||
'getPosition',
|
||||
ol.Overlay.prototype.getPosition);
|
||||
|
||||
|
||||
/**
|
||||
@@ -252,10 +236,6 @@ ol.Overlay.prototype.getPositioning = function() {
|
||||
return /** @type {ol.OverlayPositioning} */ (
|
||||
this.get(ol.OverlayProperty.POSITIONING));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Overlay.prototype,
|
||||
'getPositioning',
|
||||
ol.Overlay.prototype.getPositioning);
|
||||
|
||||
|
||||
/**
|
||||
@@ -340,10 +320,6 @@ ol.Overlay.prototype.handlePositioningChanged = function() {
|
||||
ol.Overlay.prototype.setElement = function(element) {
|
||||
this.set(ol.OverlayProperty.ELEMENT, element);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Overlay.prototype,
|
||||
'setElement',
|
||||
ol.Overlay.prototype.setElement);
|
||||
|
||||
|
||||
/**
|
||||
@@ -355,10 +331,6 @@ goog.exportProperty(
|
||||
ol.Overlay.prototype.setMap = function(map) {
|
||||
this.set(ol.OverlayProperty.MAP, map);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Overlay.prototype,
|
||||
'setMap',
|
||||
ol.Overlay.prototype.setMap);
|
||||
|
||||
|
||||
/**
|
||||
@@ -370,10 +342,6 @@ goog.exportProperty(
|
||||
ol.Overlay.prototype.setOffset = function(offset) {
|
||||
this.set(ol.OverlayProperty.OFFSET, offset);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Overlay.prototype,
|
||||
'setOffset',
|
||||
ol.Overlay.prototype.setOffset);
|
||||
|
||||
|
||||
/**
|
||||
@@ -387,10 +355,6 @@ goog.exportProperty(
|
||||
ol.Overlay.prototype.setPosition = function(position) {
|
||||
this.set(ol.OverlayProperty.POSITION, position);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Overlay.prototype,
|
||||
'setPosition',
|
||||
ol.Overlay.prototype.setPosition);
|
||||
|
||||
|
||||
/**
|
||||
@@ -488,10 +452,6 @@ ol.Overlay.prototype.getRect_ = function(element, size) {
|
||||
ol.Overlay.prototype.setPositioning = function(positioning) {
|
||||
this.set(ol.OverlayProperty.POSITIONING, positioning);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.Overlay.prototype,
|
||||
'setPositioning',
|
||||
ol.Overlay.prototype.setPositioning);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
goog.provide('ol.View');
|
||||
goog.provide('ol.ViewHint');
|
||||
goog.provide('ol.ViewProperty');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
@@ -252,10 +253,6 @@ ol.View.prototype.getCenter = function() {
|
||||
return /** @type {ol.Coordinate|undefined} */ (
|
||||
this.get(ol.ViewProperty.CENTER));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.View.prototype,
|
||||
'getCenter',
|
||||
ol.View.prototype.getCenter);
|
||||
|
||||
|
||||
/**
|
||||
@@ -308,10 +305,6 @@ ol.View.prototype.getResolution = function() {
|
||||
return /** @type {number|undefined} */ (
|
||||
this.get(ol.ViewProperty.RESOLUTION));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.View.prototype,
|
||||
'getResolution',
|
||||
ol.View.prototype.getResolution);
|
||||
|
||||
|
||||
/**
|
||||
@@ -364,10 +357,6 @@ ol.View.prototype.getResolutionForValueFunction = function(opt_power) {
|
||||
ol.View.prototype.getRotation = function() {
|
||||
return /** @type {number} */ (this.get(ol.ViewProperty.ROTATION));
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.View.prototype,
|
||||
'getRotation',
|
||||
ol.View.prototype.getRotation);
|
||||
|
||||
|
||||
/**
|
||||
@@ -596,10 +585,6 @@ ol.View.prototype.rotate = function(rotation, opt_anchor) {
|
||||
ol.View.prototype.setCenter = function(center) {
|
||||
this.set(ol.ViewProperty.CENTER, center);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.View.prototype,
|
||||
'setCenter',
|
||||
ol.View.prototype.setCenter);
|
||||
|
||||
|
||||
/**
|
||||
@@ -626,10 +611,6 @@ ol.View.prototype.setHint = function(hint, delta) {
|
||||
ol.View.prototype.setResolution = function(resolution) {
|
||||
this.set(ol.ViewProperty.RESOLUTION, resolution);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.View.prototype,
|
||||
'setResolution',
|
||||
ol.View.prototype.setResolution);
|
||||
|
||||
|
||||
/**
|
||||
@@ -641,10 +622,6 @@ goog.exportProperty(
|
||||
ol.View.prototype.setRotation = function(rotation) {
|
||||
this.set(ol.ViewProperty.ROTATION, rotation);
|
||||
};
|
||||
goog.exportProperty(
|
||||
ol.View.prototype,
|
||||
'setRotation',
|
||||
ol.View.prototype.setRotation);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
92
test/spec/ol/control/overviewmapcontrol.test.js
Normal file
92
test/spec/ol/control/overviewmapcontrol.test.js
Normal file
@@ -0,0 +1,92 @@
|
||||
goog.provide('ol.test.control.OverviewMap');
|
||||
|
||||
describe('ol.control.OverviewMap', function() {
|
||||
var map, target;
|
||||
|
||||
beforeEach(function() {
|
||||
target = document.createElement('div');
|
||||
document.body.appendChild(target);
|
||||
map = new ol.Map({
|
||||
target: target
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
goog.dispose(map);
|
||||
document.body.removeChild(target);
|
||||
map = null;
|
||||
target = null;
|
||||
});
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates an overview map with the default options', function() {
|
||||
var control = new ol.control.OverviewMap();
|
||||
expect(control).to.be.a(ol.control.OverviewMap);
|
||||
expect(control).to.be.a(ol.control.Control);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setMap()', function() {
|
||||
|
||||
it('keeps ovmap view rotation in sync with map view rotation', function() {
|
||||
var view = new ol.View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
rotation: 0
|
||||
});
|
||||
map.setView(view);
|
||||
|
||||
var control = new ol.control.OverviewMap();
|
||||
map.addControl(control);
|
||||
var ovView = control.ovmap_.getView();
|
||||
expect(ovView.getRotation()).to.be(0);
|
||||
|
||||
view.setRotation(Math.PI / 4);
|
||||
expect(ovView.getRotation()).to.be(Math.PI / 4);
|
||||
});
|
||||
|
||||
it('maintains rotation in sync if view added later', function() {
|
||||
var control = new ol.control.OverviewMap();
|
||||
map.addControl(control);
|
||||
var ovView = control.ovmap_.getView();
|
||||
expect(ovView.getRotation()).to.be(0);
|
||||
|
||||
var view = new ol.View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
rotation: 0
|
||||
});
|
||||
map.setView(view);
|
||||
view.setRotation(Math.PI / 4);
|
||||
expect(ovView.getRotation()).to.be(Math.PI / 4);
|
||||
});
|
||||
|
||||
it('stops listening to old maps', function() {
|
||||
var control = new ol.control.OverviewMap();
|
||||
var ovView = control.ovmap_.getView();
|
||||
|
||||
var view = new ol.View({
|
||||
center: [0, 0],
|
||||
zoom: 0,
|
||||
rotation: 0
|
||||
});
|
||||
map.setView(view);
|
||||
map.addControl(control);
|
||||
|
||||
view.setRotation(Math.PI / 8);
|
||||
expect(ovView.getRotation()).to.be(Math.PI / 8);
|
||||
|
||||
map.removeControl(control);
|
||||
|
||||
view.setRotation(Math.PI / 4);
|
||||
expect(ovView.getRotation()).to.be(Math.PI / 8);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.View');
|
||||
goog.require('ol.control.Control');
|
||||
goog.require('ol.control.OverviewMap');
|
||||
@@ -109,7 +109,7 @@ describe('ol.Object', function() {
|
||||
|
||||
describe('notify', function() {
|
||||
|
||||
var listener1, listener2, listener3;
|
||||
var listener1, listener2;
|
||||
|
||||
beforeEach(function() {
|
||||
listener1 = sinon.spy();
|
||||
@@ -117,11 +117,6 @@ describe('ol.Object', function() {
|
||||
|
||||
listener2 = sinon.spy();
|
||||
goog.events.listen(o, ol.ObjectEventType.PROPERTYCHANGE, listener2);
|
||||
|
||||
var o2 = new ol.Object();
|
||||
o2.bindTo('k', o);
|
||||
listener3 = sinon.spy();
|
||||
goog.events.listen(o2, 'change:k', listener3);
|
||||
});
|
||||
|
||||
it('dispatches events', function() {
|
||||
@@ -143,21 +138,11 @@ describe('ol.Object', function() {
|
||||
expect(event.key).to.be('k');
|
||||
expect(event.oldValue).to.be(1);
|
||||
});
|
||||
|
||||
it('dispatches events to bound objects', function() {
|
||||
o.notify('k', 1);
|
||||
expect(listener3.calledOnce).to.be(true);
|
||||
var args = listener3.firstCall.args;
|
||||
expect(args).to.have.length(1);
|
||||
var event = args[0];
|
||||
expect(event.key).to.be('k');
|
||||
expect(event.oldValue).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('set', function() {
|
||||
|
||||
var listener1, o2, listener2, listener3;
|
||||
var listener1, listener2;
|
||||
|
||||
beforeEach(function() {
|
||||
listener1 = sinon.spy();
|
||||
@@ -165,11 +150,6 @@ describe('ol.Object', function() {
|
||||
|
||||
listener2 = sinon.spy();
|
||||
goog.events.listen(o, ol.ObjectEventType.PROPERTYCHANGE, listener2);
|
||||
|
||||
o2 = new ol.Object();
|
||||
o2.bindTo('k', o);
|
||||
listener3 = sinon.spy();
|
||||
goog.events.listen(o2, 'change:k', listener3);
|
||||
});
|
||||
|
||||
it('dispatches events to object', function() {
|
||||
@@ -177,7 +157,6 @@ describe('ol.Object', function() {
|
||||
expect(listener1).to.be.called();
|
||||
|
||||
expect(o.getKeys()).to.eql(['k']);
|
||||
expect(o2.getKeys()).to.eql(['k']);
|
||||
});
|
||||
|
||||
it('dispatches generic change events to object', function() {
|
||||
@@ -189,259 +168,6 @@ describe('ol.Object', function() {
|
||||
expect(event.key).to.be('k');
|
||||
});
|
||||
|
||||
it('dispatches events to bound object', function() {
|
||||
o.set('k', 1);
|
||||
expect(listener3).to.be.called();
|
||||
});
|
||||
|
||||
it('dispatches events to object bound to', function() {
|
||||
o2.set('k', 2);
|
||||
expect(listener1).to.be.called();
|
||||
|
||||
expect(o.getKeys()).to.eql(['k']);
|
||||
expect(o2.getKeys()).to.eql(['k']);
|
||||
});
|
||||
|
||||
it('dispatches generic change events to object bound to', function() {
|
||||
o2.set('k', 2);
|
||||
expect(listener2.calledOnce).to.be(true);
|
||||
var args = listener2.firstCall.args;
|
||||
expect(args).to.have.length(1);
|
||||
var event = args[0];
|
||||
expect(event.key).to.be('k');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('bind', function() {
|
||||
|
||||
var o2;
|
||||
|
||||
beforeEach(function() {
|
||||
o2 = new ol.Object();
|
||||
});
|
||||
|
||||
describe('bindTo after set', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
o.set('k', 1);
|
||||
o2.set('k', 0);
|
||||
});
|
||||
|
||||
it('gets expected value', function() {
|
||||
o2.bindTo('k', o);
|
||||
expect(o.get('k')).to.eql(1);
|
||||
expect(o2.get('k')).to.eql(1);
|
||||
|
||||
expect(o.getKeys()).to.eql(['k']);
|
||||
expect(o2.getKeys()).to.eql(['k']);
|
||||
});
|
||||
|
||||
it('dispatches a change: event', function() {
|
||||
var listener = sinon.spy();
|
||||
o2.on('change:k', listener);
|
||||
o2.bindTo('k', o);
|
||||
expect(listener.calledOnce).to.be(true);
|
||||
var call = listener.firstCall;
|
||||
expect(call.args).to.have.length(1);
|
||||
expect(call.args[0].key).to.be('k');
|
||||
expect(call.args[0].oldValue).to.be(0);
|
||||
expect(o2.get('k')).to.be(1);
|
||||
});
|
||||
|
||||
it('dispatches a propertychange event', function() {
|
||||
var listener = sinon.spy();
|
||||
o2.on('propertychange', listener);
|
||||
o2.bindTo('k', o);
|
||||
expect(listener.calledOnce).to.be(true);
|
||||
var call = listener.firstCall;
|
||||
expect(call.args).to.have.length(1);
|
||||
expect(call.args[0].key).to.be('k');
|
||||
expect(call.args[0].oldValue).to.be(0);
|
||||
expect(o2.get('k')).to.be(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('bindTo before set', function() {
|
||||
|
||||
it('gets expected value', function() {
|
||||
o2.bindTo('k', o);
|
||||
o.set('k', 1);
|
||||
expect(o.get('k')).to.eql(1);
|
||||
expect(o2.get('k')).to.eql(1);
|
||||
|
||||
expect(o.getKeys()).to.eql(['k']);
|
||||
expect(o2.getKeys()).to.eql(['k']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('backwards', function() {
|
||||
describe('bindTo after set', function() {
|
||||
|
||||
it('gets expected value', function() {
|
||||
o2.set('k', 1);
|
||||
o2.bindTo('k', o);
|
||||
expect(o.get('k')).to.be(undefined);
|
||||
expect(o2.get('k')).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('bindTo before set', function() {
|
||||
|
||||
it('gets expected value', function() {
|
||||
o2.bindTo('k', o);
|
||||
o2.set('k', 1);
|
||||
expect(o.get('k')).to.eql(1);
|
||||
expect(o2.get('k')).to.eql(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('unbind', function() {
|
||||
var o2;
|
||||
|
||||
beforeEach(function() {
|
||||
o2 = new ol.Object();
|
||||
o2.bindTo('k', o);
|
||||
o2.set('k', 1);
|
||||
});
|
||||
|
||||
it('makes changes to unbound object invisible to other object', function() {
|
||||
// initial state
|
||||
expect(o.get('k')).to.eql(1);
|
||||
expect(o2.get('k')).to.eql(1);
|
||||
o2.unbind('k');
|
||||
expect(o.get('k')).to.eql(1);
|
||||
expect(o2.get('k')).to.eql(1);
|
||||
o2.set('k', 2);
|
||||
expect(o.get('k')).to.eql(1);
|
||||
expect(o2.get('k')).to.eql(2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('unbindAll', function() {
|
||||
var o2;
|
||||
|
||||
beforeEach(function() {
|
||||
o2 = new ol.Object();
|
||||
o2.bindTo('k', o);
|
||||
o2.set('k', 1);
|
||||
});
|
||||
|
||||
it('makes changes to unbound object invisible to other object', function() {
|
||||
// initial state
|
||||
expect(o.get('k')).to.eql(1);
|
||||
expect(o2.get('k')).to.eql(1);
|
||||
o2.unbindAll();
|
||||
expect(o.get('k')).to.eql(1);
|
||||
expect(o2.get('k')).to.eql(1);
|
||||
o2.set('k', 2);
|
||||
expect(o.get('k')).to.eql(1);
|
||||
expect(o2.get('k')).to.eql(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('bind rename', function() {
|
||||
var listener1, o2, listener2;
|
||||
|
||||
beforeEach(function() {
|
||||
o2 = new ol.Object();
|
||||
o2.bindTo('k2', o, 'k1');
|
||||
|
||||
listener1 = sinon.spy();
|
||||
goog.events.listen(o, 'change:k1', listener1);
|
||||
|
||||
listener2 = sinon.spy();
|
||||
goog.events.listen(o2, 'change:k2', listener2);
|
||||
});
|
||||
|
||||
it('sets the expected properties', function() {
|
||||
o.set('k1', 1);
|
||||
expect(o.get('k1')).to.eql(1);
|
||||
expect(o.get('k2')).to.be(undefined);
|
||||
expect(o2.get('k2')).to.eql(1);
|
||||
expect(o2.get('k1')).to.be(undefined);
|
||||
expect(listener1).to.be.called();
|
||||
expect(listener2).to.be.called();
|
||||
|
||||
expect(o.getKeys()).to.eql(['k1']);
|
||||
expect(o2.getKeys()).to.eql(['k2']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('transitive bind', function() {
|
||||
var o2, o3;
|
||||
|
||||
beforeEach(function() {
|
||||
o2 = new ol.Object();
|
||||
o3 = new ol.Object();
|
||||
o2.bindTo('k2', o, 'k1');
|
||||
o3.bindTo('k3', o2, 'k2');
|
||||
});
|
||||
|
||||
it('sets the expected properties', function() {
|
||||
o.set('k1', 1);
|
||||
expect(o.get('k1')).to.eql(1);
|
||||
expect(o2.get('k2')).to.eql(1);
|
||||
expect(o3.get('k3')).to.eql(1);
|
||||
|
||||
expect(o.getKeys()).to.eql(['k1']);
|
||||
expect(o2.getKeys()).to.eql(['k2']);
|
||||
expect(o3.getKeys()).to.eql(['k3']);
|
||||
});
|
||||
|
||||
describe('backward', function() {
|
||||
|
||||
it('sets the expected properties', function() {
|
||||
o3.set('k3', 1);
|
||||
expect(o.get('k1')).to.eql(1);
|
||||
expect(o2.get('k2')).to.eql(1);
|
||||
expect(o3.get('k3')).to.eql(1);
|
||||
|
||||
expect(o.getKeys()).to.eql(['k1']);
|
||||
expect(o2.getKeys()).to.eql(['k2']);
|
||||
expect(o3.getKeys()).to.eql(['k3']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('circular bind', function() {
|
||||
var o2;
|
||||
|
||||
beforeEach(function() {
|
||||
o2 = new ol.Object();
|
||||
o.bindTo('k', o2);
|
||||
});
|
||||
|
||||
it('throws an error', function() {
|
||||
expect(function() { o2.bindTo('k', o); }).to.throwException();
|
||||
});
|
||||
});
|
||||
|
||||
describe('priority', function() {
|
||||
var o2;
|
||||
|
||||
beforeEach(function() {
|
||||
o2 = new ol.Object();
|
||||
});
|
||||
|
||||
it('respects set order', function() {
|
||||
o.set('k', 1);
|
||||
o2.set('k', 2);
|
||||
o.bindTo('k', o2);
|
||||
expect(o.get('k')).to.eql(2);
|
||||
expect(o2.get('k')).to.eql(2);
|
||||
});
|
||||
|
||||
it('respects set order (undefined)', function() {
|
||||
o.set('k', 1);
|
||||
o.bindTo('k', o2);
|
||||
expect(o.get('k')).to.be(undefined);
|
||||
expect(o2.get('k')).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('setter', function() {
|
||||
@@ -452,27 +178,12 @@ describe('ol.Object', function() {
|
||||
sinon.spy(o, 'setX');
|
||||
});
|
||||
|
||||
describe('without bind', function() {
|
||||
it('does not call the setter', function() {
|
||||
o.set('x', 1);
|
||||
expect(o.get('x')).to.eql(1);
|
||||
expect(o.setX).to.not.be.called();
|
||||
it('does not call the setter', function() {
|
||||
o.set('x', 1);
|
||||
expect(o.get('x')).to.eql(1);
|
||||
expect(o.setX).to.not.be.called();
|
||||
|
||||
expect(o.getKeys()).to.eql(['x']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with bind', function() {
|
||||
it('does call the setter', function() {
|
||||
var o2 = new ol.Object();
|
||||
o2.bindTo('x', o);
|
||||
o2.set('x', 1);
|
||||
expect(o.setX).to.be.called();
|
||||
expect(o.get('x')).to.eql(1);
|
||||
|
||||
expect(o.getKeys()).to.eql(['x']);
|
||||
expect(o2.getKeys()).to.eql(['x']);
|
||||
});
|
||||
expect(o.getKeys()).to.eql(['x']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -484,29 +195,9 @@ describe('ol.Object', function() {
|
||||
sinon.spy(o, 'getX');
|
||||
});
|
||||
|
||||
describe('without bind', function() {
|
||||
it('does not call the getter', function() {
|
||||
expect(o.get('x')).to.be(undefined);
|
||||
expect(o.getX).to.not.be.called();
|
||||
});
|
||||
});
|
||||
|
||||
describe('with bind', function() {
|
||||
it('does call the getter', function() {
|
||||
var o2 = new ol.Object();
|
||||
o2.bindTo('x', o);
|
||||
expect(o2.get('x')).to.eql(1);
|
||||
expect(o.getX).to.be.called();
|
||||
|
||||
expect(o.getKeys()).to.eql([]);
|
||||
expect(o2.getKeys()).to.eql(['x']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('bind self', function() {
|
||||
it('throws an error', function() {
|
||||
expect(function() { o.bindTo('k', o); }).to.throwException();
|
||||
it('does not call the getter', function() {
|
||||
expect(o.get('x')).to.be(undefined);
|
||||
expect(o.getX).to.not.be.called();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -538,130 +229,6 @@ describe('ol.Object', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('transforms', function() {
|
||||
|
||||
describe('original states and events', function() {
|
||||
it('bindTo and transform emit propertychange events', function() {
|
||||
var source = new ol.Object();
|
||||
var target = new ol.Object();
|
||||
source.set('x', 1);
|
||||
target.set('x', 2);
|
||||
var sourceSpy = sinon.spy();
|
||||
var targetSpy = sinon.spy();
|
||||
source.on('propertychange', sourceSpy);
|
||||
target.on('propertychange', targetSpy);
|
||||
var accessor = source.bindTo('x', target);
|
||||
expect(sourceSpy.callCount).to.be(1);
|
||||
expect(targetSpy.callCount).to.be(0);
|
||||
expect(source.get('x')).to.be(2);
|
||||
expect(target.get('x')).to.be(2);
|
||||
accessor.transform(function(v) {
|
||||
return v * 2;
|
||||
}, function(v) {
|
||||
return v / 2;
|
||||
});
|
||||
var call, args;
|
||||
expect(sourceSpy.calledTwice).to.be(true);
|
||||
call = sourceSpy.firstCall;
|
||||
expect(call.args).to.have.length(1);
|
||||
expect(call.args[0].key).to.be('x');
|
||||
expect(call.args[0].oldValue).to.be(1);
|
||||
call = sourceSpy.secondCall;
|
||||
expect(call.args).to.have.length(1);
|
||||
expect(call.args[0].key).to.be('x');
|
||||
expect(call.args[0].oldValue).to.be(2);
|
||||
expect(targetSpy.called).to.be(false);
|
||||
expect(source.get('x')).to.be(1);
|
||||
expect(target.get('x')).to.be(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with multiple binds to a single property', function() {
|
||||
|
||||
var original, plusOne, asString;
|
||||
|
||||
beforeEach(function() {
|
||||
original = new ol.Object();
|
||||
original.set('x', 1);
|
||||
plusOne = new ol.Object();
|
||||
plusOne.bindTo('x', original).transform(
|
||||
function(x) { return x - 1; },
|
||||
function(x) { return x + 1; }
|
||||
);
|
||||
asString = new ol.Object();
|
||||
asString.bindTo('x', original).transform(
|
||||
function(x) { return +x; },
|
||||
function(x) { return x + ''; }
|
||||
);
|
||||
});
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(original.get('x')).to.be(1);
|
||||
expect(plusOne.get('x')).to.be(2);
|
||||
expect(asString.get('x')).to.be('1');
|
||||
});
|
||||
|
||||
it('allows the original value to be set correctly', function() {
|
||||
original.set('x', 2);
|
||||
expect(plusOne.get('x')).to.be(3);
|
||||
expect(asString.get('x')).to.be('2');
|
||||
});
|
||||
|
||||
it('allows the transformed values to be set correctly', function() {
|
||||
plusOne.set('x', 3);
|
||||
expect(original.get('x')).to.be(2);
|
||||
expect(asString.get('x')).to.be('2');
|
||||
asString.set('x', '3');
|
||||
expect(original.get('x')).to.be(3);
|
||||
expect(plusOne.get('x')).to.be(4);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with transitive binds', function() {
|
||||
|
||||
var original, plusOne, plusOneAsString;
|
||||
|
||||
beforeEach(function() {
|
||||
original = new ol.Object();
|
||||
original.set('x', 1);
|
||||
plusOne = new ol.Object();
|
||||
plusOne.bindTo('x', original).transform(
|
||||
function(x) { return x - 1; },
|
||||
function(x) { return x + 1; }
|
||||
);
|
||||
plusOneAsString = new ol.Object();
|
||||
plusOneAsString.bindTo('x', plusOne).transform(
|
||||
parseFloat,
|
||||
function(x) { return x + ''; }
|
||||
);
|
||||
});
|
||||
|
||||
it('returns the expected value', function() {
|
||||
expect(original.get('x')).to.be(1);
|
||||
expect(plusOne.get('x')).to.be(2);
|
||||
expect(plusOneAsString.get('x')).to.be('2');
|
||||
});
|
||||
|
||||
it('allows the original value to be set correctly', function() {
|
||||
original.set('x', 2);
|
||||
expect(plusOne.get('x')).to.be(3);
|
||||
expect(plusOneAsString.get('x')).to.be('3');
|
||||
});
|
||||
|
||||
it('allows the transformed values to be set correctly', function() {
|
||||
plusOne.set('x', 3);
|
||||
expect(original.get('x')).to.be(2);
|
||||
expect(plusOneAsString.get('x')).to.be('3');
|
||||
plusOneAsString.set('x', '4');
|
||||
expect(original.get('x')).to.be(3);
|
||||
expect(plusOne.get('x')).to.be(4);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user