summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-08 20:28:52 +0200
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 10:05:59 +0200
commit8db9161553ece681a0c9a6f50b710ce6cbd3c8dc (patch)
tree141eabb4c519929e69c1714251ff87b4025eb604 /src/components
parentc9e70ec95f733caa253b362e154b47cd5a26cbfe (diff)
Implement canvas image element caching
Diffstat (limited to 'src/components')
-rw-r--r--src/components/map/elements/ImageComponent.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/components/map/elements/ImageComponent.js b/src/components/map/elements/ImageComponent.js
index 00766496..486296ea 100644
--- a/src/components/map/elements/ImageComponent.js
+++ b/src/components/map/elements/ImageComponent.js
@@ -3,6 +3,7 @@ import React from "react";
import {Image} from "react-konva";
class ImageComponent extends React.Component {
+ static imageCaches = {};
static propTypes = {
src: PropTypes.string.isRequired,
x: PropTypes.number.isRequired,
@@ -17,9 +18,17 @@ class ImageComponent extends React.Component {
};
componentDidMount() {
+ if (ImageComponent.imageCaches[this.props.src]) {
+ this.setState({image: ImageComponent.imageCaches[this.props.src]});
+ return;
+ }
+
const image = new window.Image();
image.src = this.props.src;
- image.onload = () => this.setState({image});
+ image.onload = () => {
+ this.setState({image});
+ ImageComponent.imageCaches[this.props.src] = image;
+ }
}
render() {