Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add geom.Point, geom.MultiPoint and geom.Circle geometries #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/geom/circle.js
Original file line number Diff line number Diff line change
@@ -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);
}
}

Circle.propTypes = {
children: React.PropTypes.arrayOf(PropTypes.number).isRequired,
radius: React.PropTypes.number.isRequired
}

Circle.contextTypes = {
feature: React.PropTypes.instanceOf(ol.Feature)
}
3 changes: 3 additions & 0 deletions src/geom/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
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';
export {default as Point} from './point';
export {default as MultiPoint} from './multi-point';
4 changes: 4 additions & 0 deletions src/geom/line-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export default class LineString extends OLComponent {
componentWillReceiveProps(newProps) {
this.updateFromProps(newProps);
}

componentWillUnmount() {
this.context.feature.setGeometry(undefined);
}
}

LineString.propTypes = {
Expand Down
37 changes: 37 additions & 0 deletions src/geom/multi-point.js
Original file line number Diff line number Diff line change
@@ -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)
}
35 changes: 35 additions & 0 deletions src/geom/point.js
Original file line number Diff line number Diff line change
@@ -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)
}
4 changes: 2 additions & 2 deletions src/geom/polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default class Polygon extends OLComponent {
this.updateFromProps(newProps);
}

render() {
return false;
componentWillUnmount() {
this.context.feature.setGeometry(undefined);
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
}

Expand Down