esrieact 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +309 -0
- package/dist/core/Graphic.d.ts +16 -0
- package/dist/core/Graphic.js +67 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +3 -0
- package/dist/core/renderers/Renderer.d.ts +11 -0
- package/dist/core/renderers/Renderer.js +11 -0
- package/dist/core/renderers/SimpleRenderer.d.ts +11 -0
- package/dist/core/renderers/SimpleRenderer.js +12 -0
- package/dist/core/renderers/UniqueValueRenderer.d.ts +12 -0
- package/dist/core/renderers/UniqueValueRenderer.js +12 -0
- package/dist/core/renderers/createRendererComponent.d.ts +13 -0
- package/dist/core/renderers/createRendererComponent.js +63 -0
- package/dist/core/renderers/index.d.ts +4 -0
- package/dist/core/renderers/index.js +4 -0
- package/dist/core/symbols/PictureMarkerSymbol.d.ts +9 -0
- package/dist/core/symbols/PictureMarkerSymbol.js +43 -0
- package/dist/core/symbols/SimpleFillSymbol.d.ts +9 -0
- package/dist/core/symbols/SimpleFillSymbol.js +34 -0
- package/dist/core/symbols/index.d.ts +2 -0
- package/dist/core/symbols/index.js +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/layers/FeatureLayer.d.ts +27 -0
- package/dist/layers/FeatureLayer.js +13 -0
- package/dist/layers/GraphicsLayer.d.ts +14 -0
- package/dist/layers/GraphicsLayer.js +13 -0
- package/dist/layers/GroupLayer.d.ts +14 -0
- package/dist/layers/GroupLayer.js +30 -0
- package/dist/layers/ImageryLayer.d.ts +14 -0
- package/dist/layers/ImageryLayer.js +13 -0
- package/dist/layers/ImageryTileLayer.d.ts +14 -0
- package/dist/layers/ImageryTileLayer.js +13 -0
- package/dist/layers/KMLLayer.d.ts +14 -0
- package/dist/layers/KMLLayer.js +13 -0
- package/dist/layers/LayerView.d.ts +52 -0
- package/dist/layers/LayerView.js +70 -0
- package/dist/layers/VectorTileLayer.d.ts +14 -0
- package/dist/layers/VectorTileLayer.js +13 -0
- package/dist/layers/WMSLayer.d.ts +14 -0
- package/dist/layers/WMSLayer.js +13 -0
- package/dist/layers/WebTileLayer.d.ts +14 -0
- package/dist/layers/WebTileLayer.js +13 -0
- package/dist/layers/createLayerComponent.d.ts +36 -0
- package/dist/layers/createLayerComponent.js +54 -0
- package/dist/layers/index.d.ts +11 -0
- package/dist/layers/index.js +11 -0
- package/dist/map/MapView.d.ts +144 -0
- package/dist/map/MapView.js +109 -0
- package/dist/map/index.d.ts +1 -0
- package/dist/map/index.js +1 -0
- package/dist/symbols/SymbolPreview.d.ts +16 -0
- package/dist/symbols/SymbolPreview.js +21 -0
- package/dist/symbols/index.d.ts +1 -0
- package/dist/symbols/index.js +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +30 -0
- package/dist/utils/useEsriPropertyUpdates.d.ts +10 -0
- package/dist/utils/useEsriPropertyUpdates.js +26 -0
- package/dist/utils/useEvents.d.ts +20 -0
- package/dist/utils/useEvents.js +38 -0
- package/dist/utils/usePrevious.d.ts +2 -0
- package/dist/utils/usePrevious.js +9 -0
- package/dist/widgets/BasemapGallery.d.ts +14 -0
- package/dist/widgets/BasemapGallery.js +13 -0
- package/dist/widgets/Expand.d.ts +14 -0
- package/dist/widgets/Expand.js +15 -0
- package/dist/widgets/LayerList/ListItem.d.ts +14 -0
- package/dist/widgets/LayerList/ListItem.js +13 -0
- package/dist/widgets/LayerList/index.d.ts +14 -0
- package/dist/widgets/LayerList/index.js +13 -0
- package/dist/widgets/Legend.d.ts +14 -0
- package/dist/widgets/Legend.js +15 -0
- package/dist/widgets/SearchBar.d.ts +14 -0
- package/dist/widgets/SearchBar.js +13 -0
- package/dist/widgets/Sketch.d.ts +24 -0
- package/dist/widgets/Sketch.js +13 -0
- package/dist/widgets/createWidgetComponent.d.ts +29 -0
- package/dist/widgets/createWidgetComponent.js +47 -0
- package/dist/widgets/index.d.ts +7 -0
- package/dist/widgets/index.js +7 -0
- package/package.json +39 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import EsriSketch from "@arcgis/core/widgets/Sketch";
|
|
3
|
+
interface SketchProperties extends __esri.SketchProperties {
|
|
4
|
+
layer: __esri.GraphicsLayer;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* An Sketch Widget component
|
|
8
|
+
*
|
|
9
|
+
* ArcGIS JS API Source Components:
|
|
10
|
+
* - [Sketch](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch.html)
|
|
11
|
+
*/
|
|
12
|
+
export declare const Sketch: React.ForwardRefExoticComponent<SketchProperties & {
|
|
13
|
+
children?: React.ReactNode;
|
|
14
|
+
} & {
|
|
15
|
+
events?: Partial<{
|
|
16
|
+
delete: __esri.SketchDeleteEventHandler;
|
|
17
|
+
create: __esri.SketchCreateEventHandler;
|
|
18
|
+
update: __esri.SketchUpdateEventHandler;
|
|
19
|
+
redo: __esri.SketchRedoEventHandler;
|
|
20
|
+
undo: __esri.SketchUndoEventHandler;
|
|
21
|
+
}> | undefined;
|
|
22
|
+
position?: string | __esri.UIAddPosition | undefined;
|
|
23
|
+
} & React.RefAttributes<EsriSketch>>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import EsriSketch from "@arcgis/core/widgets/Sketch";
|
|
3
|
+
import { createWidgetComponent } from ".";
|
|
4
|
+
const createWidget = (properties) => {
|
|
5
|
+
return new EsriSketch(properties);
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* An Sketch Widget component
|
|
9
|
+
*
|
|
10
|
+
* ArcGIS JS API Source Components:
|
|
11
|
+
* - [Sketch](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch.html)
|
|
12
|
+
*/
|
|
13
|
+
export const Sketch = React.forwardRef((properties, ref) => createWidgetComponent(createWidget, ref, properties));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { Ref } from "react";
|
|
2
|
+
import EsriWidget from "@arcgis/core/widgets/Widget";
|
|
3
|
+
/**
|
|
4
|
+
* Properties that can be applied to any ESRIEACT Widget component. Extends from
|
|
5
|
+
* esri's WidgetProperties to include child components and the widget position
|
|
6
|
+
*/
|
|
7
|
+
export type WidgetComponentProps<T extends __esri.WidgetProperties = __esri.WidgetProperties, E extends Record<string, Function> = {}> = React.PropsWithChildren<T> & {
|
|
8
|
+
events?: E;
|
|
9
|
+
position?: string | __esri.UIAddPosition;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Function that takes in layer properties and returns an esri Layer instance. Properties must be
|
|
13
|
+
* any esri properties that extend esri.LayerProperties, and optional children
|
|
14
|
+
*/
|
|
15
|
+
export type CreateWidgetFunction<T extends WidgetComponentProps = WidgetComponentProps> = (properties: T) => __esri.Widget;
|
|
16
|
+
/**
|
|
17
|
+
* The react context object that any widget component creates when rendered
|
|
18
|
+
* and makes available to its descendants
|
|
19
|
+
*/
|
|
20
|
+
export declare const WidgetContext: React.Context<EsriWidget>;
|
|
21
|
+
/**
|
|
22
|
+
* Factory function to create an esrieact widget component
|
|
23
|
+
* @param createWidget Function that takes in the widget properties (which must extend from __esri.WidgetProperties)
|
|
24
|
+
* and returns the widget instance
|
|
25
|
+
* @param ref The react ref to be passed from the parent
|
|
26
|
+
* @param properties The widget properties
|
|
27
|
+
* @returns A context provider whose context is the instance to be passed to children, or if there are no children, returns null
|
|
28
|
+
*/
|
|
29
|
+
export declare function createWidgetComponent<P extends WidgetComponentProps>(createWidget: CreateWidgetFunction, ref: Ref<EsriWidget>, { children, events, position, ...properties }: P): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useImperativeHandle, useMemo, } from "react";
|
|
3
|
+
import Expand from "@arcgis/core/widgets/Expand";
|
|
4
|
+
import { useMap } from "..";
|
|
5
|
+
import { useEsriPropertyUpdates, useEvents } from "../utils";
|
|
6
|
+
/**
|
|
7
|
+
* The react context object that any widget component creates when rendered
|
|
8
|
+
* and makes available to its descendants
|
|
9
|
+
*/
|
|
10
|
+
export const WidgetContext = createContext({});
|
|
11
|
+
/**
|
|
12
|
+
* Factory function to create an esrieact widget component
|
|
13
|
+
* @param createWidget Function that takes in the widget properties (which must extend from __esri.WidgetProperties)
|
|
14
|
+
* and returns the widget instance
|
|
15
|
+
* @param ref The react ref to be passed from the parent
|
|
16
|
+
* @param properties The widget properties
|
|
17
|
+
* @returns A context provider whose context is the instance to be passed to children, or if there are no children, returns null
|
|
18
|
+
*/
|
|
19
|
+
export function createWidgetComponent(createWidget, ref, { children, events, position, ...properties }) {
|
|
20
|
+
const { view } = useMap();
|
|
21
|
+
const parentWidgetContext = useContext(WidgetContext);
|
|
22
|
+
const instance = useMemo(() => {
|
|
23
|
+
const instance = createWidget({ ...properties, view });
|
|
24
|
+
if (parentWidgetContext instanceof Expand) {
|
|
25
|
+
parentWidgetContext.content = instance;
|
|
26
|
+
return instance;
|
|
27
|
+
}
|
|
28
|
+
if (!properties.container) {
|
|
29
|
+
view.ui.add(instance, position);
|
|
30
|
+
}
|
|
31
|
+
return instance;
|
|
32
|
+
}, []);
|
|
33
|
+
useImperativeHandle(ref, () => instance);
|
|
34
|
+
useEsriPropertyUpdates(instance, properties);
|
|
35
|
+
useEvents(instance, events);
|
|
36
|
+
/**
|
|
37
|
+
* Remove widget on unmount
|
|
38
|
+
*/
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
return () => {
|
|
41
|
+
view.ui.remove(instance);
|
|
42
|
+
};
|
|
43
|
+
}, []);
|
|
44
|
+
if (!children)
|
|
45
|
+
return null;
|
|
46
|
+
return (_jsx(WidgetContext.Provider, { value: instance, children: children }));
|
|
47
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "esrieact",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "rm -rf dist && tsc && cp ../../README.md .",
|
|
13
|
+
"tsc": "tsc --noEmit",
|
|
14
|
+
"tsc:watch": "tsc --noEmit --watch --preserveWatchOutput"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./dist/index.js",
|
|
18
|
+
"./core/*": "./dist/core/*",
|
|
19
|
+
"./layers/*": "./dist/layers/*",
|
|
20
|
+
"./map/*": "./dist/map/*",
|
|
21
|
+
"./symbols/*": "./dist/symbols/*",
|
|
22
|
+
"./utils/*": "./dist/utils/*",
|
|
23
|
+
"./widgets/*": "./dist/widgets/*"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"lodash.isequal": "^4.5.0",
|
|
27
|
+
"usehooks-ts": "^2.9.1"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@arcgis/core": "^4.28.10",
|
|
31
|
+
"react": "^18.2.0",
|
|
32
|
+
"react-dom": "^18.2.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/react": "^18.2.43",
|
|
36
|
+
"@types/react-dom": "^18.2.17",
|
|
37
|
+
"typescript": "^5.2.2"
|
|
38
|
+
}
|
|
39
|
+
}
|