Skip to content

Commit

Permalink
feat(Polyline): component with example
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchentw committed Oct 27, 2014
1 parent 61a9688 commit d0b802b
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
15 changes: 14 additions & 1 deletion client/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require("../styles/index.scss");
var React = require("react/addons");
var {update} = React.addons;

var {GoogleMapsMixin, Map, Marker, Polygon} = require("../../src");
var {GoogleMapsMixin, Map, Marker, Polygon, Polyline} = require("../../src");

var Body = React.createClass({

Expand All @@ -27,6 +27,18 @@ var Body = React.createClass({
fillColor: '#FF0000',
fillOpacity: 0.35,
},
flightPath: {
path: [
{lat: 37.772323, lng: -122.214897},
{lat: 21.291982, lng: -157.821856},
{lat: -18.142599, lng: 178.431},
{lat: -27.46758, lng: 153.027892},
],
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2,
},
};
},

Expand Down Expand Up @@ -86,6 +98,7 @@ var Body = React.createClass({
onRightclick: this._handle_polygon_rightclick
}}))
}
{ Polyline(props.flightPath) }
</div>;
}
});
Expand Down
1 change: 0 additions & 1 deletion src/Marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = React.createClass({

componentDidMount () {
var marker = this._init_marker();
console.log("componentDidMount", marker);
if (!marker) return;
this.add_listeners(marker);
},
Expand Down
72 changes: 72 additions & 0 deletions src/Polyline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/** @jsx React.DOM */
"use strict";
var React = require("react/addons");

var ChildMixin = require("./mixins/ChildMixin");
var EventBindingMixin = require("./mixins/EventBindingMixin");

module.exports = React.createClass({
displayName: "Polyline",

mixins: [ChildMixin, EventBindingMixin],

getInitialState () {
return {
polyline: null
};
},

componentDidMount () {
var polyline = this._init_polyline();
if (!polyline) return;
this.add_listeners(polyline);
},

componentWillUpdate () {
var {polyline} = this.state;
if (!polyline) return;
this.clear_listeners(polyline);
},

componentDidUpdate () {
var polyline = this._init_polyline();
if (!polyline) return;
this.add_listeners(polyline);
polyline.setOptions(this.props);
},

componentWillUnmount () {
var {polyline} = this.state;
if (!polyline) return;
this.clear_listeners(polyline);
polyline.setMap(null);
this.setState({ polyline: null });
},

render () {
return this._render(this.props, this.state);
},

get_event_names () {
return "click dblclick drag dragend dragstart mousedown mousemove mouseout mouseover mouseup rightclick";
},

_init_polyline () {
var {context} = this;
var {polyline} = this.state;
if (polyline || !context.hasMap() || !context.getApi()) {
return polyline;
}
var {Polyline} = context.getApi();
polyline = new Polyline(this.props);
polyline.setMap(context.getMap());

this.expose_getters_from(Polyline.prototype, polyline);
this.setState({ polyline });
return polyline;
},

_render (props, state) {
return null;
}
});
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ exports.GoogleMapsMixin = require("./GoogleMapsMixin");
exports.Map = require("./Map");
exports.Marker = require("./Marker");
exports.Polygon = require("./Polygon");
exports.Polyline = require("./Polyline");

0 comments on commit d0b802b

Please sign in to comment.