ol3 is now internal, ol is now external

As discussed with @ahocevar, @elemoine and @tschaub.
This commit is contained in:
Tom Payne
2012-08-29 19:53:46 +02:00
parent 1eddf91996
commit 4aff22e980
116 changed files with 3953 additions and 3939 deletions
-395
View File
@@ -1,395 +0,0 @@
// FIXME handle rotation
// FIXME handle date line wrap
// FIXME handle layer order
// FIXME check clean-up code
goog.provide('ol.control.Attribution');
goog.require('goog.dom');
goog.require('goog.dom.TagName');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('goog.object');
goog.require('goog.style');
goog.require('ol.Collection');
goog.require('ol.Control');
goog.require('ol.CoverageArea');
goog.require('ol.Layer');
goog.require('ol.MapProperty');
goog.require('ol.TileCoverageArea');
/**
* @constructor
* @extends {ol.Control}
* @param {ol.Map} map Map.
*/
ol.control.Attribution = function(map) {
goog.base(this, map);
/**
* @private
* @type {Element}
*/
this.ulElement_ = goog.dom.createElement(goog.dom.TagName.UL);
/**
* @private
* @type {Array.<number>}
*/
this.layersListenerKeys_ = null;
/**
* @private
* @type {Object.<number, ?number>}
*/
this.layerVisibleChangeListenerKeys_ = {};
/**
* @private
* @type {Object.<number, Element>}
*/
this.attributionElements_ = {};
/**
* @private
* @type {Object.<number, Array.<ol.CoverageArea>>}
*/
this.coverageAreass_ = {};
goog.events.listen(map, ol.Object.getChangedEventType(ol.MapProperty.CENTER),
this.handleMapChanged, false, this);
goog.events.listen(map, ol.Object.getChangedEventType(ol.MapProperty.LAYERS),
this.handleMapLayersChanged, false, this);
goog.events.listen(map,
ol.Object.getChangedEventType(ol.MapProperty.RESOLUTION),
this.handleMapChanged, false, this);
goog.events.listen(map, ol.Object.getChangedEventType(ol.MapProperty.SIZE),
this.handleMapChanged, false, this);
this.handleMapLayersChanged();
};
goog.inherits(ol.control.Attribution, ol.Control);
/**
* @param {ol.Layer} layer Layer.
* @protected
*/
ol.control.Attribution.prototype.addLayer = function(layer) {
var layerKey = goog.getUid(layer);
this.layerVisibleChangeListenerKeys_[layerKey] = goog.events.listen(
layer, ol.Object.getChangedEventType(ol.LayerProperty.VISIBLE),
this.handleLayerVisibleChanged, false, this);
if (layer.getStore().isReady()) {
this.createAttributionElementsForLayer_(layer);
} else {
goog.events.listenOnce(layer, goog.events.EventType.LOAD,
this.handleLayerLoad, false, this);
}
};
/**
* @param {ol.Layer} layer Layer.
* @private
*/
ol.control.Attribution.prototype.createAttributionElementsForLayer_ =
function(layer) {
var store = layer.getStore();
var attributions = store.getAttributions();
if (goog.isNull(attributions)) {
return;
}
var map = this.getMap();
var mapIsDef = map.isDef();
var mapExtent = /** @type {ol.Extent} */ map.getExtent();
var mapProjection = /** @type {ol.Projection} */ map.getProjection();
var mapResolution = /** @type {number} */ map.getResolution();
var layerVisible = layer.getVisible();
var attributionVisibilities;
if (mapIsDef && layerVisible) {
attributionVisibilities = this.getLayerAttributionVisiblities_(
layer, mapExtent, mapResolution, mapProjection);
} else {
attributionVisibilities = null;
}
goog.array.forEach(attributions, function(attribution) {
var attributionKey = goog.getUid(attribution);
var attributionElement = goog.dom.createElement(goog.dom.TagName.LI);
attributionElement.innerHTML = attribution.getHtml();
if (!map.isDef ||
!layerVisible ||
goog.isNull(attributionVisibilities) ||
!attributionVisibilities[attributionKey]) {
goog.style.showElement(attributionElement, false);
}
goog.dom.appendChild(this.ulElement_, attributionElement);
this.attributionElements_[attributionKey] = attributionElement;
}, this);
};
/**
* @inheritDoc
*/
ol.control.Attribution.prototype.getElement = function() {
return this.ulElement_;
};
/**
* @param {ol.Layer} layer Layer.
* @param {ol.Extent} mapExtent Map extent.
* @param {number} mapResolution Map resolution.
* @param {ol.Projection} mapProjection Map projection.
* @return {Object.<number, boolean>} Attribution visibilities.
* @private
*/
ol.control.Attribution.prototype.getLayerAttributionVisiblities_ =
function(layer, mapExtent, mapResolution, mapProjection) {
var store = layer.getStore();
var attributions = store.getAttributions();
if (goog.isNull(attributions)) {
return null;
}
var mapZ;
if (store instanceof ol.TileStore) {
var tileStore = /** @type {ol.TileStore} */ store;
var tileGrid = tileStore.getTileGrid();
mapZ = tileGrid.getZForResolution(mapResolution);
}
var attributionVisibilities = {};
goog.array.forEach(attributions, function(attribution) {
var attributionKey = goog.getUid(attribution);
var attributionVisible = true;
var coverageAreas;
if (attributionKey in this.coverageAreass_) {
coverageAreas = this.coverageAreass_[attributionKey];
} else {
var attributionProjection = attribution.getProjection();
coverageAreas = attribution.getCoverageAreas();
if (!goog.isNull(coverageAreas) &&
!ol.Projection.equivalent(attributionProjection, mapProjection)) {
var transformFn = ol.Projection.getTransform(
attributionProjection, mapProjection);
if (transformFn !== ol.Projection.cloneTransform) {
coverageAreas = goog.array.map(coverageAreas, function(coverageArea) {
return coverageArea.transform(transformFn);
});
}
}
this.coverageAreass_[attributionKey] = coverageAreas;
}
if (!goog.isNull(coverageAreas)) {
if (store instanceof ol.TileStore) {
attributionVisible = goog.array.some(
coverageAreas,
/**
* @param {ol.TileCoverageArea} tileCoverageArea Tile coverage area.
*/
function(tileCoverageArea) {
goog.asserts.assert(
tileCoverageArea instanceof ol.TileCoverageArea);
return tileCoverageArea.intersectsExtentAndZ(mapExtent, mapZ);
});
} else {
attributionVisible = goog.array.some(
coverageAreas,
function(coverageArea) {
return coverageArea.intersectsExtentAndResolution(
mapExtent, mapResolution);
});
}
}
attributionVisibilities[attributionKey] = attributionVisible;
}, this);
return attributionVisibilities;
};
/**
* @param {goog.events.Event} event Event.
*/
ol.control.Attribution.prototype.handleLayerLoad = function(event) {
var layer = /** @type {ol.Layer} */ event.target;
this.createAttributionElementsForLayer_(layer);
};
/**
* @param {goog.events.Event} event Event.
* @protected
*/
ol.control.Attribution.prototype.handleLayerVisibleChanged = function(event) {
var map = this.getMap();
var mapIsDef = map.isDef();
var mapExtent = /** @type {ol.Extent} */ map.getExtent();
var mapProjection = /** @type {ol.Projection} */ map.getProjection();
var mapResolution = /** @type {number} */ map.getResolution();
var layer = /** @type {ol.Layer} */ event.target;
this.updateLayerAttributionsVisibility_(
layer, mapIsDef, mapExtent, mapResolution, mapProjection);
};
/**
* @param {ol.CollectionEvent} collectionEvent Collection event.
* @protected
*/
ol.control.Attribution.prototype.handleLayersAdd = function(collectionEvent) {
var layer = /** @type {ol.Layer} */ collectionEvent.elem;
this.addLayer(layer);
};
/**
* @param {ol.CollectionEvent} collectionEvent Collection event.
* @protected
*/
ol.control.Attribution.prototype.handleLayersRemove =
function(collectionEvent) {
var layer = /** @type {ol.Layer} */ collectionEvent.elem;
this.removeLayer(layer);
};
/**
* @protected
*/
ol.control.Attribution.prototype.handleMapChanged = function() {
var map = this.getMap();
var mapIsDef = map.isDef();
var mapExtent = /** @type {ol.Extent} */ map.getExtent();
var mapProjection = /** @type {ol.Projection} */ map.getProjection();
var mapResolution = map.getResolution();
var layers = map.getLayers();
layers.forEach(function(layer) {
this.updateLayerAttributionsVisibility_(
layer, mapIsDef, mapExtent, mapResolution, mapProjection);
}, this);
};
/**
* @protected
*/
ol.control.Attribution.prototype.handleMapLayersChanged = function() {
if (!goog.isNull(this.layersListenerKeys_)) {
goog.array.forEach(this.layersListenerKeys_, goog.events.unlistenByKey);
this.layersListenerKeys_ = null;
}
goog.object.forEach(this.attributionElements_, function(attributionElement) {
goog.dom.removeNode(attributionElement);
}, this);
this.attributionElements_ = {};
this.coverageAreass_ = {};
var map = this.getMap();
var layers = map.getLayers();
if (goog.isDefAndNotNull(layers)) {
layers.forEach(this.addLayer, this);
this.layersListenerKeys_ = [
goog.events.listen(layers, ol.CollectionEventType.ADD,
this.handleLayersAdd, false, this),
goog.events.listen(layers, ol.CollectionEventType.REMOVE,
this.handleLayersRemove, false, this)
];
}
};
/**
* @param {ol.Layer} layer Layer.
* @protected
*/
ol.control.Attribution.prototype.removeLayer = function(layer) {
var layerKey = goog.getUid(layer);
goog.events.unlistenByKey(this.layerVisibleChangeListenerKeys_[layerKey]);
delete this.layerVisibleChangeListenerKeys_[layerKey];
goog.array.forEach(layer.getStore().getAttributions(), function(attribution) {
var attributionKey = goog.getUid(attribution);
delete this.coverageAreass_[attributionKey];
var attributionElement = this.attributionElements_[attributionKey];
goog.dom.removeNode(attributionElement);
delete this.attributionElements_[attributionKey];
}, this);
};
/**
* @param {ol.Layer} layer Layer.
* @param {boolean} mapIsDef Map is defined.
* @param {ol.Extent} mapExtent Map extent.
* @param {number} mapResolution Map resolution.
* @param {ol.Projection} mapProjection Map projection.
* @private
*/
ol.control.Attribution.prototype.updateLayerAttributionsVisibility_ =
function(layer, mapIsDef, mapExtent, mapResolution, mapProjection) {
if (mapIsDef && layer.getVisible()) {
var attributionVisibilities = this.getLayerAttributionVisiblities_(
layer, mapExtent, mapResolution, mapProjection);
goog.object.forEach(
attributionVisibilities,
function(attributionVisible, attributionKey) {
var attributionElement = this.attributionElements_[attributionKey];
goog.style.showElement(attributionElement, attributionVisible);
},
this);
} else {
var store = layer.getStore();
var attributions = store.getAttributions();
if (!goog.isNull(attributions)) {
goog.array.forEach(attributions, function(attribution) {
var attributionKey = goog.getUid(attribution);
var attributionElement = this.attributionElements_[attributionKey];
goog.style.showElement(attributionElement, false);
}, this);
}
}
};
-33
View File
@@ -1,33 +0,0 @@
goog.provide('ol.Control');
goog.require('ol.Map');
/**
* @constructor
* @param {ol.Map} map Map.
*/
ol.Control = function(map) {
/**
* @private
* @type {ol.Map}
*/
this.map_ = map;
};
/**
* @return {Element} Element.
*/
ol.Control.prototype.getElement = goog.abstractMethod;
/**
* @return {ol.Map} Map.
*/
ol.Control.prototype.getMap = function() {
return this.map_;
};
-128
View File
@@ -1,128 +0,0 @@
// FIXME should listen on appropriate pane, once it is defined
goog.provide('ol.control.MousePosition');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('ol.Control');
goog.require('ol.MapProperty');
goog.require('ol.Object');
goog.require('ol.Projection');
goog.require('ol.TransformFunction');
/**
* @constructor
* @extends {ol.Control}
* @param {ol.Map} map Map.
* @param {ol.Projection=} opt_projection Projection.
* @param {ol.CoordinateFormatType=} opt_coordinateFormat Coordinate format.
* @param {string=} opt_undefinedHTML Undefined HTML.
*/
ol.control.MousePosition =
function(map, opt_projection, opt_coordinateFormat, opt_undefinedHTML) {
goog.base(this, map);
/**
* @private
* @type {Element}
*/
this.divElement_ = goog.dom.createElement(goog.dom.TagName.DIV);
/**
* @private
* @type {ol.Projection}
*/
this.projection_ = opt_projection || null;
/**
* @private
* @type {ol.CoordinateFormatType|undefined}
*/
this.coordinateFormat_ = opt_coordinateFormat;
/**
* @private
* @type {string}
*/
this.undefinedHTML_ = opt_undefinedHTML || '';
/**
* @private
* @type {ol.TransformFunction}
*/
this.transform_ = ol.Projection.identityTransform;
goog.events.listen(map,
ol.Object.getChangedEventType(ol.MapProperty.PROJECTION),
this.handleMapProjectionChanged, false, this);
goog.events.listen(map.getViewport(), goog.events.EventType.MOUSEMOVE,
this.handleMouseMove, false, this);
goog.events.listen(map.getViewport(), goog.events.EventType.MOUSEOUT,
this.handleMouseOut, false, this);
this.handleMapProjectionChanged();
};
goog.inherits(ol.control.MousePosition, ol.Control);
/**
* @inheritDoc
*/
ol.control.MousePosition.prototype.getElement = function() {
return this.divElement_;
};
/**
* @protected
*/
ol.control.MousePosition.prototype.handleMapProjectionChanged = function() {
var map = this.getMap();
var mapProjection = map.getProjection();
if (!goog.isDef(mapProjection) || goog.isNull(this.projection_)) {
this.transform_ = ol.Projection.identityTransform;
} else {
this.transform_ =
ol.Projection.getTransform(mapProjection, this.projection_);
}
// FIXME should we instead re-calculate using the last known mouse position?
this.divElement_.innerHTML = this.undefinedHTML_;
};
/**
* @param {goog.events.BrowserEvent} browserEvent Browser event.
* @protected
*/
ol.control.MousePosition.prototype.handleMouseMove = function(browserEvent) {
var map = this.getMap();
var pixel = new ol.Pixel(browserEvent.offsetX, browserEvent.offsetY);
var coordinate = map.getCoordinateFromPixel(pixel);
var html;
if (goog.isDef(coordinate)) {
coordinate = this.transform_(coordinate);
if (goog.isDef(this.coordinateFormat_)) {
html = this.coordinateFormat_(coordinate);
} else {
html = coordinate.toString();
}
} else {
html = this.undefinedHTML_;
}
this.divElement_.innerHTML = html;
};
/**
* @param {goog.events.BrowserEvent} browserEvent Browser event.
* @protected
*/
ol.control.MousePosition.prototype.handleMouseOut = function(browserEvent) {
this.divElement_.innerHTML = this.undefinedHTML_;
};