-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Polyline): component with example
- Loading branch information
Showing
4 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters