-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(default-extent): introduce new component
closes #46
- Loading branch information
Showing
7 changed files
with
174 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# @ugrc/default-extent | ||
|
||
[![NPM version](https://badgen.net/npm/v/@ugrc/default-extent)](https://www.npmjs.com/package/@ugrc/default-extent) | ||
|
||
A React component for zooming to a default extent in a map. | ||
|
||
Install with [npm](https://www.npmjs.com/) | ||
|
||
```bash | ||
npm install @ugrc/default-extent | ||
``` | ||
|
||
## Example | ||
|
||
```js | ||
import HomeButton from '@ugrc/default-extent'; | ||
import Extent from '@arcgis/core/geometry/Extent'; | ||
|
||
const defaultExtent = new Extent({ | ||
xmax: -12612006, | ||
xmin: -12246370, | ||
ymax: 5125456, | ||
ymin: 4473357, | ||
spatialReference: 3857, | ||
}); | ||
|
||
return ( | ||
<HomeButton view={view.current} position="top-left" extent={defaultExtent} /> | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "@ugrc/default-extent", | ||
"version": "1.0.0", | ||
"private": false, | ||
"description": "A react component that creates and places a button in an esri map to set the default map view", | ||
"keywords": [ | ||
"ugrc", | ||
"component", | ||
"arcgis", | ||
"esri", | ||
"react", | ||
"map", | ||
"extent", | ||
"home" | ||
], | ||
"homepage": "https://github.com/agrc/kitchen-sink/tree/main/packages/default-extent", | ||
"bugs": { | ||
"url": "https://github.com/agrc/kitchen-sink/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/agrc/kitchen-sink.git" | ||
}, | ||
"license": "MIT", | ||
"author": "ugrc developers", | ||
"maintainers": [ | ||
{ | ||
"name": "Steve Gourley", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Scott Davis", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"type": "module", | ||
"exports": { | ||
".": "./src/index" | ||
}, | ||
"scripts": { | ||
"test": "vitest --config ../../vite.config.js" | ||
}, | ||
"dependencies": { | ||
"@ugrc/utilities": "^2.1.1" | ||
}, | ||
"peerDependencies": { | ||
"@arcgis/core": "^4.20.0", | ||
"prop-types": "^15.8.1", | ||
"react": ">=16.8.0", | ||
"react-dom": ">=16.8.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import HomeButton from './'; | ||
|
||
/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */ | ||
export default { | ||
title: 'DefaultExtent', | ||
component: HomeButton, | ||
decorators: [ | ||
(Story) => <div className="esri-ui-top-left esri-ui-corner">{Story()}</div>, | ||
], | ||
argTypes: { | ||
goTo: { action: 'goTo' }, | ||
}, | ||
}; | ||
|
||
export const Normal = (args) => ( | ||
<HomeButton | ||
view={{ goTo: args.goTo, ui: { add: () => {} } }} | ||
extent={{}} | ||
></HomeButton> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import PropTypes from 'prop-types'; | ||
import { faGlobeAmericas } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { useViewUiPosition } from '@ugrc/utilities/hooks'; | ||
|
||
const goHome = (view, extent) => { | ||
return view.goTo(extent); | ||
}; | ||
|
||
export default function DefaultExtent({ view, position, extent }) { | ||
const me = useViewUiPosition(view, position); | ||
|
||
return ( | ||
<button | ||
ref={me} | ||
className="esri-home esri-widget--button esri-widget" | ||
aria-label="Default map view" | ||
title="Default map view" | ||
onClick={() => goHome(view, extent)} | ||
> | ||
<FontAwesomeIcon | ||
icon={faGlobeAmericas} | ||
className="esri-icon esri-icon-home" | ||
/> | ||
</button> | ||
); | ||
} | ||
|
||
DefaultExtent.propTypes = { | ||
view: PropTypes.object.isRequired, | ||
position: PropTypes.oneOf([ | ||
'bottom-leading', | ||
'bottom-left', | ||
'bottom-right', | ||
'bottom-trailing', | ||
'top-leading', | ||
'top-left', | ||
'top-right', | ||
'top-trailing', | ||
'manual', | ||
]).isRequired, | ||
extent: PropTypes.object.isRequired, | ||
}; |