import React from "react" import { default as LocationEditorComponent } from "../LocationEditorComponent" import LocationFinder from "../LocationFinder" import { LocationAnswerValue } from "../response" import { InnerFormContext } from "../formContext" export interface LocationAnswerComponentProps { value?: any onValueChange: (value: LocationAnswerValue | null) => void disableSetByMap?: boolean disableManualLatLng?: boolean formCtx: InnerFormContext } export default class LocationAnswerComponent extends React.Component { focus() { // Nothing to focus return null } handleUseMap = () => { if (this.props.formCtx.displayMap != null) { return this.props.formCtx.displayMap(this.props.value, (newLoc: LocationAnswerValue | null) => { if (!newLoc) { this.props.onValueChange(null) } else { // Wrap to -180, 180 while (newLoc.longitude < -180) { newLoc.longitude += 360 } while (newLoc.longitude > 180) { newLoc.longitude -= 360 } // Clip to -85, 85 (for Webmercator) if (newLoc.latitude > 85) { newLoc.latitude = 85 } if (newLoc.latitude < -85) { newLoc.latitude = -85 } // Record that done via map newLoc.method = "map" this.props.onValueChange(newLoc) } }) } } render() { return ( ) } }