{
clearLocation = () => {
this.updateProperty(this.props.propertyName, {
lat: -34.397,
long: 150.644,
title: "",
});
};
onLocationSelection = (ref: any) => {
try {
// For some places, the length is zero
const places = ref.getPlaces();
const location = places[0].geometry.location;
const title = places[0].formatted_address;
const lat = location.lat();
const long = location.lng();
const value = { lat, long, title };
this.updateProperty(this.props.propertyName, value, true);
} catch (e) {
if (ref && ref.getPlaces)
log.debug("Error selecting location:", ref.getPlaces());
else {
log.debug("Error selecting location - searchBox not found");
}
}
};
onSearchBoxMounted = (ref: any) => {
if (window) {
const searchBox = new window.google.maps.places.SearchBox(ref);
searchBox.addListener("places_changed", () => {
this.onLocationSelection(searchBox);
});
}
};
render() {
return (
);
}
static getControlType() {
return "LOCATION_SEARCH";
}
static canDisplayValueInUI(config: ControlData, value: any): boolean {
return !isDynamicValue(value);
}
}
interface MapScriptWrapperProps {
onSearchBoxMounted: (ref: any) => void;
clearLocation: () => void;
propertyValue: any;
}
function MapScriptWrapper(props: MapScriptWrapperProps) {
const [title, setTitle] = useState("");
return (
{
if (value === "") {
props.clearLocation();
}
setTitle(value);
}}
placeholder="Enter location"
ref={props.onSearchBoxMounted}
tabIndex={-1}
/>
);
}
export default LocationSearchControl;