Use x of the real world in forEachFeatureAtCoordinate

This commit is contained in:
Andreas Hocevar
2015-04-16 14:09:23 +02:00
parent a90a012e5d
commit 45cc660c48
+41 -15
View File
@@ -9,6 +9,7 @@ goog.require('goog.events.EventType');
goog.require('goog.functions'); goog.require('goog.functions');
goog.require('goog.object'); goog.require('goog.object');
goog.require('goog.vec.Mat4'); goog.require('goog.vec.Mat4');
goog.require('ol.extent');
goog.require('ol.layer.Layer'); goog.require('ol.layer.Layer');
goog.require('ol.renderer.Layer'); goog.require('ol.renderer.Layer');
goog.require('ol.style.IconImageCache'); goog.require('ol.style.IconImageCache');
@@ -136,23 +137,44 @@ ol.renderer.Map.prototype.forEachFeatureAtCoordinate =
var viewState = frameState.viewState; var viewState = frameState.viewState;
var viewResolution = viewState.resolution; var viewResolution = viewState.resolution;
var viewRotation = viewState.rotation; var viewRotation = viewState.rotation;
/** @type {Object.<string, boolean>} */
var features = {};
/**
* @param {ol.Feature} feature Feature.
* @return {?} Callback result.
*/
function forEachFeatureAtCoordinate(feature) {
goog.asserts.assert(goog.isDef(feature), 'received a feature');
var key = goog.getUid(feature).toString();
if (!(key in features)) {
features[key] = true;
return callback.call(thisArg, feature, null);
}
}
var projection = viewState.projection;
var translatedX;
if (projection.isGlobal()) {
var projectionExtent = projection.getExtent();
var worldWidth = ol.extent.getWidth(projectionExtent);
var x = coordinate[0];
if (x < projectionExtent[0] || x > projectionExtent[2]) {
var worldsAway = Math.ceil((projectionExtent[0] - x) / worldWidth);
translatedX = x + worldWidth * worldsAway;
}
}
if (!goog.isNull(this.replayGroup)) { if (!goog.isNull(this.replayGroup)) {
/** @type {Object.<string, boolean>} */
var features = {};
result = this.replayGroup.forEachFeatureAtCoordinate(coordinate, result = this.replayGroup.forEachFeatureAtCoordinate(coordinate,
viewResolution, viewRotation, {}, viewResolution, viewRotation, {}, forEachFeatureAtCoordinate);
/** if (!result && goog.isDef(translatedX)) {
* @param {ol.Feature} feature Feature. result = this.replayGroup.forEachFeatureAtCoordinate(
* @return {?} Callback result. [translatedX, coordinate[1]],
*/ viewResolution, viewRotation, {}, forEachFeatureAtCoordinate);
function(feature) { }
goog.asserts.assert(goog.isDef(feature), 'received a feature');
var key = goog.getUid(feature).toString();
if (!(key in features)) {
features[key] = true;
return callback.call(thisArg, feature, null);
}
});
if (result) { if (result) {
return result; return result;
} }
@@ -168,6 +190,10 @@ ol.renderer.Map.prototype.forEachFeatureAtCoordinate =
var layerRenderer = this.getLayerRenderer(layer); var layerRenderer = this.getLayerRenderer(layer);
result = layerRenderer.forEachFeatureAtCoordinate( result = layerRenderer.forEachFeatureAtCoordinate(
coordinate, frameState, callback, thisArg); coordinate, frameState, callback, thisArg);
if (!result && goog.isDef(translatedX)) {
result = layerRenderer.forEachFeatureAtCoordinate(
[translatedX, coordinate[1]], frameState, callback, thisArg);
}
if (result) { if (result) {
return result; return result;
} }