Skip to content

Commit

Permalink
feat: implement zoom to feature in identify pane
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed Aug 30, 2023
1 parent c2a026b commit 3b6d7ea
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/components/Identify.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PropTypes from 'prop-types';
import { forwardRef } from 'react';
import useMap from '../contexts/useMap';
import Button from '../utah-design-system/Button';
import Icon from '../utah-design-system/Icon';
import Link from '../utah-design-system/Link';
Expand All @@ -12,7 +13,6 @@ const buttonClasses = 'border-none px-2 my-1';
const urlRegex = /^https?:\/\/\S*$/;
function Cell({ value }) {
// if this is a link, return an anchor tag
console.log('value', value);
if (urlRegex.test(value)) {
return (
<Link external href={value}>
Expand All @@ -30,9 +30,11 @@ Cell.propTypes = {
};

const Identify = forwardRef(function Identify(
{ attributes, fields, onBack, links },
{ attributes, fields, geometry, links, onBack },
forwardedRef,
) {
const { zoom } = useMap();

const columns = [
{
accessorKey: 'field',
Expand Down Expand Up @@ -64,7 +66,7 @@ const Identify = forwardRef(function Identify(
<Tabs.Trigger value="attributes">Attributes</Tabs.Trigger>
<Tabs.Trigger value="related">Related Records</Tabs.Trigger>
<Tabs.Trigger value="links">Links</Tabs.Trigger>
<Button className={buttonClasses} onClick={() => {}} disabled>
<Button className={buttonClasses} onClick={() => zoom(geometry)}>
<Icon
name={Icon.Names.search}
className="mr-2"
Expand Down Expand Up @@ -108,13 +110,14 @@ const Identify = forwardRef(function Identify(
Identify.propTypes = {
attributes: PropTypes.object.isRequired,
fields: PropTypes.arrayOf(PropTypes.object).isRequired,
onBack: PropTypes.func.isRequired,
geometry: PropTypes.object.isRequired,
links: PropTypes.arrayOf(
PropTypes.shape({
text: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
}),
).isRequired,
onBack: PropTypes.func.isRequired,
};

export default Identify;
9 changes: 8 additions & 1 deletion src/components/ResultTable.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fromJSON } from '@arcgis/core/geometry/support/jsonUtils';
import * as Collapsible from '@radix-ui/react-collapsible';
import clsx from 'clsx';
import ky from 'ky';
Expand Down Expand Up @@ -28,7 +29,7 @@ export default function ResultTable({
f: 'json',
where: `OBJECTID = ${oid}`,
outFields: '*',
returnGeometry: false,
returnGeometry: true,
},
},
)
Expand All @@ -39,6 +40,11 @@ export default function ResultTable({
setIdentifyResults({
attributes,
fields: result.fields,
geometry: fromJSON({
...result.features[0].geometry,
type: result.geometryType,
spatialReference: result.spatialReference,
}),
});
},
[queryLayerResult],
Expand Down Expand Up @@ -169,6 +175,7 @@ export default function ResultTable({
attributes={identifyResults.attributes}
fields={identifyResults.fields}
links={getLinks()}
geometry={identifyResults.geometry}
/>
) : (
<Table
Expand Down
9 changes: 9 additions & 0 deletions src/contexts/MapProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@ export default function MapProvider({ children }) {
const [mapView, setMapView] = useState(null);
const [selectedGraphicInfo, setSelectedGraphicInfo] = useState(null);

const zoom = (geometry) => {
if (!mapView) {
console.warn('attempting to zoom before the mapView is set');
} else {
mapView.goTo(geometry);
}
};

return (
<MapContext.Provider
value={{
mapView,
setMapView,
selectedGraphicInfo,
setSelectedGraphicInfo,
zoom,
}}
>
{children}
Expand Down

0 comments on commit 3b6d7ea

Please sign in to comment.