in src/components/geocoder-panel.js [100:184]
export default function GeocoderPanelFactory() {
class GeocoderPanel extends Component {
static propTypes = {
isGeocoderEnabled: PropTypes.bool.isRequired,
mapboxApiAccessToken: PropTypes.string.isRequired,
mapState: PropTypes.object.isRequired,
updateVisData: PropTypes.func.isRequired,
removeDataset: PropTypes.func.isRequired,
updateMap: PropTypes.func.isRequired,
transitionDuration: PropTypes.number,
width: PropTypes.number
};
removeGeocoderDataset() {
this.props.removeDataset(GEOCODER_DATASET_NAME);
}
onSelected = (viewport = null, geoItem) => {
const {
center: [lon, lat],
text,
bbox
} = geoItem;
this.removeGeocoderDataset();
this.props.updateVisData(
[generateGeocoderDataset(lat, lon, text)],
{
keepExistingConfig: true
},
PARSED_CONFIG
);
const bounds = bbox || [
lon - GEOCODER_GEO_OFFSET,
lat - GEOCODER_GEO_OFFSET,
lon + GEOCODER_GEO_OFFSET,
lat + GEOCODER_GEO_OFFSET
];
const {center, zoom} = geoViewport.viewport(bounds, [
this.props.mapState.width,
this.props.mapState.height
]);
this.props.updateMap({
latitude: center[1],
longitude: center[0],
zoom,
pitch: 0,
bearing: 0,
transitionDuration: this.props.transitionDuration,
transitionInterpolator: new FlyToInterpolator()
});
};
removeMarker = () => {
this.removeGeocoderDataset();
};
render() {
const {isGeocoderEnabled, mapboxApiAccessToken, width} = this.props;
return (
<StyledGeocoderPanel
className="geocoder-panel"
width={width}
style={{display: isGeocoderEnabled ? 'block' : 'none'}}
>
{isValid(mapboxApiAccessToken) && (
<Geocoder
mapboxApiAccessToken={mapboxApiAccessToken}
onSelected={this.onSelected}
onDeleteMarker={this.removeMarker}
width={width}
/>
)}
</StyledGeocoderPanel>
);
}
}
GeocoderPanel.defaultProps = {
transitionDuration: 3000
};
return GeocoderPanel;
}