-
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.
Allows a HeatmapLayer to be created. Takes an array of `google.maps.LatLng` objects to the prop `data`.
- Loading branch information
Showing
3 changed files
with
133 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
default as React, | ||
Component, | ||
} from "react"; | ||
|
||
import { | ||
default as canUseDOM, | ||
} from "can-use-dom"; | ||
|
||
import { | ||
default as HeatmapLayerCreator, | ||
heatmapLayerDefaultPropTypes, | ||
heatmapLayerControlledPropTypes, | ||
heatmapLayerEventPropTypes, | ||
} from "./addonsCreators/HeatmapLayerCreator"; | ||
|
||
export default class HeatmapLayer extends Component { | ||
static propTypes = { | ||
// Uncontrolled default[props] - used only in componentDidMount | ||
...heatmapLayerDefaultPropTypes, | ||
// Controlled [props] - used in componentDidMount/componentDidUpdate | ||
...heatmapLayerControlledPropTypes, | ||
// Event [onEventName] | ||
...heatmapLayerEventPropTypes, | ||
} | ||
|
||
// Public APIs | ||
// | ||
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#HeatmapLayer | ||
// | ||
// [].map.call($0.querySelectorAll("tr>td>code"), function(it){ return it.textContent; }).filter(function(it){ return it.match(/^get/) && !it.match(/^getMap/); }) | ||
getData() { return this.state.directionsRenderer.getDirections(); } | ||
|
||
// END - Public APIs | ||
// | ||
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#HeatmapLayer | ||
|
||
state = { | ||
} | ||
|
||
componentWillMount() { | ||
if (!canUseDOM) { | ||
return; | ||
} | ||
const heatmapLayer = HeatmapLayerCreator._createHeatmapLayer(this.props); | ||
|
||
this.setState({ heatmapLayer }); | ||
} | ||
|
||
render() { | ||
if (this.state.heatmapLayer) { | ||
return ( | ||
<HeatmapLayerCreator heatmapLayer={this.state.heatmapLayer} {...this.props}> | ||
{this.props.children} | ||
</HeatmapLayerCreator> | ||
); | ||
} else { | ||
return (<noscript />); | ||
} | ||
} | ||
} |
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,67 @@ | ||
import { | ||
default as React, | ||
PropTypes, | ||
Component, | ||
} from "react"; | ||
|
||
import { default as HeatmapLayerEventList } from "../addonsEventLists/HeatmapLayerEventList"; | ||
import { default as eventHandlerCreator } from "../../utils/eventHandlerCreator"; | ||
import { default as defaultPropsCreator } from "../../utils/defaultPropsCreator"; | ||
import { default as composeOptions } from "../../utils/composeOptions"; | ||
import { default as componentLifecycleDecorator } from "../../utils/componentLifecycleDecorator"; | ||
|
||
import { default as GoogleMapHolder } from "../../creators/GoogleMapHolder"; | ||
|
||
export const heatmapLayerControlledPropTypes = { | ||
// NOTICE!!!!!! | ||
// | ||
// Only expose those with getters & setters in the table as controlled props. | ||
// | ||
// [].map.call($0.querySelectorAll("tr>td>code"), function(it){ return it.textContent; }).filter(function(it){ return it.match(/^set/) && !it.match(/^setMap/); }) | ||
// | ||
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#HeatmapLayer | ||
data: PropTypes.any, | ||
options: PropTypes.object, | ||
}; | ||
|
||
export const heatmapLayerDefaultPropTypes = defaultPropsCreator(heatmapLayerControlledPropTypes); | ||
|
||
const heatmapLayerUpdaters = { | ||
data(data, component) { component.getHeatmapLayer().setData(data); }, | ||
options(options, component) { component.getHeatmapLayer().setOptions(options); }, | ||
}; | ||
|
||
const { eventPropTypes, registerEvents } = eventHandlerCreator(HeatmapLayerEventList); | ||
|
||
export const heatmapLayerEventPropTypes = eventPropTypes; | ||
|
||
@componentLifecycleDecorator({ | ||
registerEvents, | ||
instanceMethodName: `getHeatmapLayer`, | ||
updaters: heatmapLayerUpdaters, | ||
}) | ||
export default class HeatmapLayerCreator extends Component { | ||
|
||
static propTypes = { | ||
mapHolderRef: PropTypes.instanceOf(GoogleMapHolder).isRequired, | ||
heatmapLayer: PropTypes.object.isRequired, | ||
} | ||
|
||
static _createHeatmapLayer(heatmapLayerProps) { | ||
const { mapHolderRef } = heatmapLayerProps; | ||
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#HeatmapLayer | ||
const heatmapLayer = new google.maps.visualization.HeatmapLayer(composeOptions(heatmapLayerProps, heatmapLayerControlledPropTypes)); | ||
|
||
heatmapLayer.setMap(mapHolderRef.getMap()); | ||
|
||
return heatmapLayer; | ||
} | ||
|
||
getHeatmapLayer() { | ||
return this.props.heatmapLayer; | ||
} | ||
|
||
render() { | ||
return (<noscript />); | ||
} | ||
} |
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,5 @@ | ||
// https://developers.google.com/maps/documentation/javascript/3.exp/reference#Polyline | ||
// [].map.call($0.querySelectorAll("tr>td>code"), function(it){ return it.textContent; }) | ||
export default [ | ||
`zoom_changed`, | ||
]; |