From ca1be97a15f9138f5ad93b904f91836934fc6d2d Mon Sep 17 00:00:00 2001 From: Tamas Nepusz Date: Fri, 24 Feb 2017 13:14:08 +0100 Subject: [PATCH 1/5] added updateSize() method to map --- src/map.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/map.js b/src/map.js index e2b6591..b1e960c 100644 --- a/src/map.js +++ b/src/map.js @@ -32,6 +32,12 @@ export default class Map extends React.Component { this.map.setTarget(undefined) } + focus () { + const viewport = this.map.getViewport() + viewport.tabIndex = 0 + viewport.focus() + } + getChildContext () { return { map: this.map @@ -51,10 +57,8 @@ export default class Map extends React.Component { ) } - focus () { - const viewport = this.map.getViewport() - viewport.tabIndex = 0 - viewport.focus() + updateSize () { + this.map.updateSize() } } From 143ed4fbf9b339908c4d1e5b89b7b14336d3c84d Mon Sep 17 00:00:00 2001 From: Tamas Nepusz Date: Sat, 11 Nov 2017 18:47:30 +0100 Subject: [PATCH 2/5] geometries should be unset when they are unmounted --- src/geom/line-string.js | 4 ++++ src/geom/polygon.js | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/geom/line-string.js b/src/geom/line-string.js index 73ecfdc..6e08d90 100644 --- a/src/geom/line-string.js +++ b/src/geom/line-string.js @@ -20,6 +20,10 @@ export default class LineString extends OLComponent { componentWillReceiveProps(newProps) { this.updateFromProps(newProps); } + + componentWillUnmount() { + this.context.feature.setGeometry(undefined); + } } LineString.propTypes = { diff --git a/src/geom/polygon.js b/src/geom/polygon.js index ada66f6..eb8b987 100644 --- a/src/geom/polygon.js +++ b/src/geom/polygon.js @@ -21,8 +21,8 @@ export default class Polygon extends OLComponent { this.updateFromProps(newProps); } - render() { - return false; + componentWillUnmount() { + this.context.feature.setGeometry(undefined); } } From 16121a745569500b8e36086dc75933c3c3bba43c Mon Sep 17 00:00:00 2001 From: Tamas Nepusz Date: Sat, 11 Nov 2017 19:04:17 +0100 Subject: [PATCH 3/5] added Point and MultiPoint geometries --- src/geom/index.js | 2 ++ src/geom/multi-point.js | 37 +++++++++++++++++++++++++++++++++++++ src/geom/point.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 src/geom/multi-point.js create mode 100644 src/geom/point.js diff --git a/src/geom/index.js b/src/geom/index.js index 1b9f5a6..15ecf0f 100644 --- a/src/geom/index.js +++ b/src/geom/index.js @@ -1,3 +1,5 @@ export {default as Polygon} from './polygon'; export {default as LineString} from './line-string'; export {default as RawGeometry} from './raw-geometry'; +export {default as Point} from './point'; +export {default as MultiPoint} from './multi-point'; diff --git a/src/geom/multi-point.js b/src/geom/multi-point.js new file mode 100644 index 0000000..6c988b8 --- /dev/null +++ b/src/geom/multi-point.js @@ -0,0 +1,37 @@ +import React from 'react'; +import ol from 'openlayers'; +import OLComponent from '../ol-component'; + +export default class MultiPoint extends OLComponent { + constructor(props) { + super(props); + this.geometry = new ol.geom.MultiPoint(); + this.updateFromProps(props); + } + + updateFromProps(props) { + this.geometry.setCoordinates(props.children); + } + + componentDidMount() { + this.context.feature.setGeometry(this.geometry); + } + + componentWillReceiveProps(newProps) { + this.updateFromProps(newProps); + } + + componentWillUnmount() { + this.context.feature.setGeometry(undefined); + } +} + +MultiPoint.propTypes = { + children: React.PropTypes.arrayOf( + React.PropTypes.arrayOf(React.PropTypes.number) + ).isRequired, +} + +MultiPoint.contextTypes = { + feature: React.PropTypes.instanceOf(ol.Feature) +} diff --git a/src/geom/point.js b/src/geom/point.js new file mode 100644 index 0000000..093118c --- /dev/null +++ b/src/geom/point.js @@ -0,0 +1,35 @@ +import React from 'react'; +import ol from 'openlayers'; +import OLComponent from '../ol-component'; + +export default class Point extends OLComponent { + constructor(props) { + super(props); + this.geometry = new ol.geom.Point(); + this.updateFromProps(props); + } + + updateFromProps(props) { + this.geometry.setCoordinates(props.children); + } + + componentDidMount() { + this.context.feature.setGeometry(this.geometry); + } + + componentWillReceiveProps(newProps) { + this.updateFromProps(newProps); + } + + componentWillUnmount() { + this.context.feature.setGeometry(undefined); + } +} + +Point.propTypes = { + children: React.PropTypes.arrayOf(React.PropTypes.number).isRequired +} + +Point.contextTypes = { + feature: React.PropTypes.instanceOf(ol.Feature) +} From 78781f52000bec0f1ac810812c22d8c1957112e3 Mon Sep 17 00:00:00 2001 From: Tamas Nepusz Date: Thu, 16 Nov 2017 21:42:29 +0100 Subject: [PATCH 4/5] added Circle feature --- src/geom/circle.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/geom/index.js | 1 + 2 files changed, 45 insertions(+) create mode 100644 src/geom/circle.js diff --git a/src/geom/circle.js b/src/geom/circle.js new file mode 100644 index 0000000..f66ffc9 --- /dev/null +++ b/src/geom/circle.js @@ -0,0 +1,44 @@ +import React from 'react'; +import ol from 'openlayers'; +import OLComponent from '../ol-component'; + +export default class Circle extends OLComponent { + constructor(props) { + super(props); + this.geometry = new ol.geom.Circle(); + this.updateFromProps(props); + } + + updateFromProps(props) { + if (props.children.length == 1) { + // props.children[0] is the center + this.geometry.setCenterAndRadius(props.children[0], props.radius); + } else if (props.children.length > 1) { + // props.children is the center + this.geometry.setCenterAndRadius(props.children, props.radius); + } else { + this.geometry.setCenterAndRadius([0, 0], props.radius); + } + } + + componentDidMount() { + this.context.feature.setGeometry(this.geometry); + } + + componentWillReceiveProps(newProps) { + this.updateFromProps(newProps); + } + + componentWillUnmount() { + this.context.feature.setGeometry(undefined); + } +} + +Point.propTypes = { + children: React.PropTypes.arrayOf(PropTypes.number).isRequired, + radius: React.PropTypes.number.isRequired +} + +Point.contextTypes = { + feature: React.PropTypes.instanceOf(ol.Feature) +} diff --git a/src/geom/index.js b/src/geom/index.js index 15ecf0f..b8dc210 100644 --- a/src/geom/index.js +++ b/src/geom/index.js @@ -1,3 +1,4 @@ +export {default as Circle} from './circle'; export {default as Polygon} from './polygon'; export {default as LineString} from './line-string'; export {default as RawGeometry} from './raw-geometry'; From c313af38b5f881e103b7747ba536235172e77e5d Mon Sep 17 00:00:00 2001 From: Tamas Nepusz Date: Thu, 16 Nov 2017 22:01:16 +0100 Subject: [PATCH 5/5] fixed copy-paste error in geom.Circle --- src/geom/circle.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/geom/circle.js b/src/geom/circle.js index f66ffc9..e992f07 100644 --- a/src/geom/circle.js +++ b/src/geom/circle.js @@ -34,11 +34,11 @@ export default class Circle extends OLComponent { } } -Point.propTypes = { +Circle.propTypes = { children: React.PropTypes.arrayOf(PropTypes.number).isRequired, radius: React.PropTypes.number.isRequired } -Point.contextTypes = { +Circle.contextTypes = { feature: React.PropTypes.instanceOf(ol.Feature) }