Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Feat] Introduce MapPopoverContent (for tooltip charts) (#2119)
Igor Dykhta1f20ef715735
diff --git a/src/components/src/map/map-popover-content.tsx b/src/components/src/map/map-popover-content.tsxnew file mode 100644index 000000000..316463de7--- /dev/null+++ b/src/components/src/map/map-popover-content.tsx@@ -0,0 +1,56 @@+// Copyright (c) 2023 Uber Technologies, Inc.+//+// Permission is hereby granted, free of charge, to any person obtaining a copy+// of this software and associated documentation files (the "Software"), to deal+// in the Software without restriction, including without limitation the rights+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+// copies of the Software, and to permit persons to whom the Software is+// furnished to do so, subject to the following conditions:+//+// The above copyright notice and this permission notice shall be included in+// all copies or substantial portions of the Software.+//+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+// THE SOFTWARE.++import React from 'react';+import {injectIntl, IntlShape} from 'react-intl';+import {LayerHoverProp} from '@kepler.gl/reducers';+import LayerHoverInfoFactory from './layer-hover-info';+import CoordinateInfoFactory from './coordinate-info';++MapPopoverContentFactory.deps = [LayerHoverInfoFactory, CoordinateInfoFactory];++type MapPopoverContentProps = {+ coordinate: [number, number] | boolean;+ layerHoverProp: LayerHoverProp | null;+ zoom: number;+};++type IntlProps = {+ intl: IntlShape;+};++export default function MapPopoverContentFactory(+ LayerHoverInfo: ReturnType<typeof LayerHoverInfoFactory>,+ CoordinateInfo: ReturnType<typeof CoordinateInfoFactory>+) {+ const MapPopoverContent: React.FC<MapPopoverContentProps & IntlProps> = ({+ coordinate,+ layerHoverProp,+ zoom+ }) => {+ return (+ <>+ {Array.isArray(coordinate) && <CoordinateInfo coordinate={coordinate} zoom={zoom} />}+ {layerHoverProp && <LayerHoverInfo {...layerHoverProp} />}+ </>+ );+ };+ return injectIntl(MapPopoverContent);+}diff --git a/src/components/src/map/map-popover.tsx b/src/components/src/map/map-popover.tsxindex cd553729b..1630e0754 100644--- a/src/components/src/map/map-popover.tsx+++ b/src/components/src/map/map-popover.tsx@@ -22,6 +22,7 @@ import React, {useState} from 'react';import styled from 'styled-components';import LayerHoverInfoFactory from './layer-hover-info';import CoordinateInfoFactory from './coordinate-info';+import MapPopoverContentFactory from './map-popover-content';import {Pin, ArrowLeft, ArrowRight} from '../common/icons';import {injectIntl, IntlShape} from 'react-intl';import {FormattedMessage} from '@kepler.gl/localization';@@ -126,7 +127,7 @@ const StyledIcon = styled.div`}`;-MapPopoverFactory.deps = [LayerHoverInfoFactory, CoordinateInfoFactory];+MapPopoverFactory.deps = [LayerHoverInfoFactory, CoordinateInfoFactory, MapPopoverContentFactory];function createVirtualReference(container, x, y, size = 0) {const bounds =@@ -193,7 +194,8 @@ type IntlProps = {export default function MapPopoverFactory(LayerHoverInfo: ReturnType<typeof LayerHoverInfoFactory>,- CoordinateInfo: ReturnType<typeof CoordinateInfoFactory>+ CoordinateInfo: ReturnType<typeof CoordinateInfoFactory>,+ MapPopoverContent: ReturnType<typeof MapPopoverContentFactory>) {/** @type {typeof import('./map-popover').MapPopover} */const MapPopover: React.FC<MapPopoverProps & IntlProps> = ({@@ -250,10 +252,11 @@ export default function MapPopoverFactory(</PinnedButtons>) : null}<PopoverContent>- {Array.isArray(coordinate) && (- <CoordinateInfo coordinate={coordinate} zoom={zoom} />- )}- {layerHoverProp && <LayerHoverInfo {...layerHoverProp} />}+ <MapPopoverContent+ coordinate={coordinate}+ zoom={zoom}+ layerHoverProp={layerHoverProp}+ /></PopoverContent></StyledMapPopover>)}