Skip to content

Commit

Permalink
Add toggle radius button to movable circle map example
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-ES committed Sep 12, 2016
1 parent 7d5a6d3 commit f4206e7
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions demo/examples/MovableCircleMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ interface MovableCircleMapProps {

interface MovableCircleMapState {
center: H.geo.IPoint;
radius: number;
}

export default class MovableCircleMap extends React.Component<MovableCircleMapProps, MovableCircleMapState> {
public static subtitle = "This example shows you how to create an interactive map" +
" centred in London, England, with a circle of radius 1km displayed over the top of it." +
" The circle's position can be toggled between two possible locations by clicking a " +
"provided button.";
"provided button, and toggled between two possible radii with another.";

public static title = "Movable Circle Map";
public static title = "Movable and Resizable Circle Map";

public static code = "import React, { Component } from \"react\";\n" +
"import HEREMap from \"react-here-maps\";\n" +
Expand Down Expand Up @@ -49,6 +50,10 @@ export default class MovableCircleMap extends React.Component<MovableCircleMapPr
" <button>\n" +
" Change Position\n" +
" </button>\n" +
" \n" +
" <button>\n" +
" Change Radius\n" +
" </button>\n" +
" </div>\n" +
" )\n" +
" }\n" +
Expand All @@ -58,18 +63,22 @@ export default class MovableCircleMap extends React.Component<MovableCircleMapPr
center: {
lat: 51.5,
lng: 0,
}
},

radius: 10000,
}

constructor(props: any, context: any) {
super(props, context);
this.togglePosition = this.togglePosition.bind(this);
this.toggleRadius = this.toggleRadius.bind(this);
}

public render() {
// center the map somewhere in London
const {
center,
radius,
} = this.state;

return (
Expand All @@ -87,13 +96,17 @@ export default class MovableCircleMap extends React.Component<MovableCircleMapPr
strokeColor="#1275E8"
fillColor="rgba(18, 117, 232, 0.2)"
lineWidth={2}
radius={10000}
radius={radius}
/>
</HEREMap>

<button onClick={this.togglePosition}>
Change Position
</button>

<button onClick={this.toggleRadius}>
Change Radius
</button>
</div>
);
}
Expand All @@ -109,4 +122,16 @@ export default class MovableCircleMap extends React.Component<MovableCircleMapPr
center,
} as MovableCircleMapState);
}

private toggleRadius() {
let {
radius,
} = this.state;

radius = radius === 10000 ? 5000 : 10000;

this.setState({
radius,
} as MovableCircleMapState);
}
}

0 comments on commit f4206e7

Please sign in to comment.