|
| 1 | +import { |
| 2 | + default as React, |
| 3 | + PropTypes, |
| 4 | + Component, |
| 5 | + Children, |
| 6 | +} from "react"; |
| 7 | + |
| 8 | +import {default as RectangleEventList} from "../eventLists/RectangleEventList"; |
| 9 | +import {default as eventHandlerCreator} from "../utils/eventHandlerCreator"; |
| 10 | +import {default as defaultPropsCreator} from "../utils/defaultPropsCreator"; |
| 11 | +import {default as composeOptions} from "../utils/composeOptions"; |
| 12 | +import {default as componentLifecycleDecorator} from "../utils/componentLifecycleDecorator"; |
| 13 | + |
| 14 | +import {default as GoogleMapHolder} from "./GoogleMapHolder"; |
| 15 | + |
| 16 | +export const rectangleControlledPropTypes = { |
| 17 | +// [].map.call($0.querySelectorAll("tr>td>code"), function(it){ return it.textContent; }).filter(function(it){ return it.match(/^set/) && !it.match(/^setMap/); }) |
| 18 | +// https://developers.google.com/maps/documentation/javascript/3.exp/reference#Rectangle |
| 19 | + bounds: PropTypes.any, |
| 20 | + draggable: PropTypes.bool, |
| 21 | + editable: PropTypes.bool, |
| 22 | + options: PropTypes.object, |
| 23 | + visible: PropTypes.bool, |
| 24 | +}; |
| 25 | + |
| 26 | +export const rectangleDefaultPropTypes = defaultPropsCreator(rectangleControlledPropTypes); |
| 27 | + |
| 28 | +const rectangleUpdaters = { |
| 29 | + bounds (bounds, component) { component.getRectangle().setBounds(bounds); }, |
| 30 | + draggable (draggable, component) { component.getRectangle().setDraggable(draggable); }, |
| 31 | + editable (editable, component) { component.getRectangle().setEditable(editable); }, |
| 32 | + options (options, component) { component.getRectangle().setOptions(options); }, |
| 33 | + visible (visible, component) { component.getRectangle().setVisible(visible); }, |
| 34 | +}; |
| 35 | + |
| 36 | +const {eventPropTypes, registerEvents} = eventHandlerCreator(RectangleEventList); |
| 37 | + |
| 38 | +export const rectangleEventPropTypes = eventPropTypes; |
| 39 | + |
| 40 | +@componentLifecycleDecorator({ |
| 41 | + registerEvents, |
| 42 | + instanceMethodName: "getRectangle", |
| 43 | + updaters: rectangleUpdaters, |
| 44 | +}) |
| 45 | +export default class RectangleCreator extends Component { |
| 46 | + |
| 47 | + static propTypes = { |
| 48 | + mapHolderRef: PropTypes.instanceOf(GoogleMapHolder).isRequired, |
| 49 | + rectangle: PropTypes.object.isRequired, |
| 50 | + } |
| 51 | + |
| 52 | + static _createRectangle (mapHolderRef, rectangleProps) { |
| 53 | + // https://developers.google.com/maps/documentation/javascript/3.exp/reference#Rectangle |
| 54 | + const rectangle = new google.maps.Rectangle(composeOptions(rectangleProps, [ |
| 55 | + // https://developers.google.com/maps/documentation/javascript/3.exp/reference#RectangleOptions |
| 56 | + "bounds", |
| 57 | + "draggable", |
| 58 | + "editable", |
| 59 | + "visible", |
| 60 | + ])); |
| 61 | + |
| 62 | + rectangle.setMap(mapHolderRef.getMap()); |
| 63 | + |
| 64 | + return rectangle; |
| 65 | + } |
| 66 | + |
| 67 | + getRectangle () { |
| 68 | + return this.props.rectangle; |
| 69 | + } |
| 70 | + |
| 71 | + render () { |
| 72 | + return (<noscript />); |
| 73 | + } |
| 74 | +} |
0 commit comments