Merge pull request #7871 from fredj/optim

Memory optimization
This commit is contained in:
Frédéric Junod
2018-02-21 16:35:27 +01:00
committed by GitHub
3 changed files with 19 additions and 18 deletions
+8 -5
View File
@@ -1208,15 +1208,18 @@ PluggableMap.prototype.renderFrame_ = function(time) {
layerStates[getUid(layerStatesArray[i].layer)] = layerStatesArray[i]; layerStates[getUid(layerStatesArray[i].layer)] = layerStatesArray[i];
} }
viewState = view.getState(); viewState = view.getState();
const center = viewState.center; let focus = this.focus_;
const pixelResolution = viewState.resolution / this.pixelRatio_; if (!focus) {
center[0] = Math.round(center[0] / pixelResolution) * pixelResolution; focus = viewState.center;
center[1] = Math.round(center[1] / pixelResolution) * pixelResolution; const pixelResolution = viewState.resolution / this.pixelRatio_;
focus[0] = Math.round(focus[0] / pixelResolution) * pixelResolution;
focus[1] = Math.round(focus[1] / pixelResolution) * pixelResolution;
}
frameState = /** @type {olx.FrameState} */ ({ frameState = /** @type {olx.FrameState} */ ({
animate: false, animate: false,
coordinateToPixelTransform: this.coordinateToPixelTransform_, coordinateToPixelTransform: this.coordinateToPixelTransform_,
extent: extent, extent: extent,
focus: !this.focus_ ? center : this.focus_, focus: focus,
index: this.frameIndex_++, index: this.frameIndex_++,
layerStates: layerStates, layerStates: layerStates,
layerStatesArray: layerStatesArray, layerStatesArray: layerStatesArray,
+3 -4
View File
@@ -77,11 +77,10 @@ function handleDragEvent(mapBrowserEvent) {
const deltaY = centroid[1] - this.lastCentroid[1]; const deltaY = centroid[1] - this.lastCentroid[1];
const map = mapBrowserEvent.map; const map = mapBrowserEvent.map;
const view = map.getView(); const view = map.getView();
const viewState = view.getState();
let center = [deltaX, deltaY]; let center = [deltaX, deltaY];
scaleCoordinate(center, viewState.resolution); scaleCoordinate(center, view.getResolution());
rotateCoordinate(center, viewState.rotation); rotateCoordinate(center, view.getRotation());
addCoordinate(center, viewState.center); addCoordinate(center, view.getCenter());
center = view.constrainCenter(center); center = view.constrainCenter(center);
view.setCenter(center); view.setCenter(center);
} }
+8 -9
View File
@@ -73,15 +73,15 @@ const RenderFeature = function(type, flatCoordinates, ends, properties, id) {
*/ */
this.properties_ = properties; this.properties_ = properties;
/**
* @private
* @type {ol.Transform}
*/
this.tmpTransform_ = createTransform();
}; };
/**
* @type {ol.Transform}
*/
const tmpTransform = createTransform();
/** /**
* Get a feature property by its key. * Get a feature property by its key.
* @param {string} key Key * @param {string} key Key
@@ -267,12 +267,11 @@ RenderFeature.prototype.transform = function(source, destination) {
const pixelExtent = source.getExtent(); const pixelExtent = source.getExtent();
const projectedExtent = source.getWorldExtent(); const projectedExtent = source.getWorldExtent();
const scale = getHeight(projectedExtent) / getHeight(pixelExtent); const scale = getHeight(projectedExtent) / getHeight(pixelExtent);
const transform = this.tmpTransform_; composeTransform(tmpTransform,
composeTransform(transform,
projectedExtent[0], projectedExtent[3], projectedExtent[0], projectedExtent[3],
scale, -scale, 0, scale, -scale, 0,
0, 0); 0, 0);
transform2D(this.flatCoordinates_, 0, this.flatCoordinates_.length, 2, transform2D(this.flatCoordinates_, 0, this.flatCoordinates_.length, 2,
transform, this.flatCoordinates_); tmpTransform, this.flatCoordinates_);
}; };
export default RenderFeature; export default RenderFeature;