Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Aug 19, 2024
1 parent f0a55c0 commit af50deb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Arcgis/Layer/Layer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class $Layer extends EventEmitter {
const data = await this.#layer.queryExtent();
if (!$map.view) return;
$map.view.goTo(data.extent).then(() => {
if (!$map.view) return;
if (!$map.view?.ready) return;
const homeWidget = $map.view.ui.find('Home');
if (!homeWidget) return;
homeWidget.viewpoint = new $map.modules.AgViewpoint({
Expand Down
28 changes: 18 additions & 10 deletions src/Widgets/VisualizationWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,29 @@ function MapEditorModal(props) {
const VisualizationWidget = (props) => {
const $map = useRef();
const controller = useRef({});
const $value = useRef(props.value);
const { id, title, description, value } = props;
const [showMapEditor, setShowMapEditor] = useState(false);

const onConnect = useCallback(() => {
if (controller.current.multiple && !props.block) return;
const onConnect = () => {
if (controller.current.multiple && !props.block && !$map.current) return;
props.onChange(props.id, {
...value,
...$value.current,
preview: 'loading',
});
controller.current.agReactive = $map.current.modules.agReactiveUtils.watch(
() => $map.current.view.updating,
() => $map.current?.view?.updating,
async (updating) => {
if (updating || !$map.current.view) return;
if (updating || !$map.current?.view) return;
debounce(
async () => {
if (!$map.current?.view) return;
const preview = await $map.current.view.takeScreenshot({
format: 'png',
});
console.log('HERE LOADED');
props.onChange(props.id, {
...value,
...$value.current,
preview: preview.dataUrl,
});
},
Expand All @@ -191,15 +194,16 @@ const VisualizationWidget = (props) => {
);
},
);
}, [props, value]);
};

const onDisconnect = useCallback(() => {
const onDisconnect = () => {
if (!controller.current.agReactive) return;
controller.current.agReactive.remove();
}, []);
};

useEffect(() => {
const map = $map.current;

if (!map) return;

const widgets = document.querySelectorAll(
Expand All @@ -218,7 +222,11 @@ const VisualizationWidget = (props) => {
map.off('connected', onConnect);
map.off('disconnected', onDisconnect);
};
}, [onConnect, onDisconnect]);
}, []);

useEffect(() => {
$value.current = value;
}, [value]);

if (__SERVER__ || !value) return null;

Expand Down
11 changes: 10 additions & 1 deletion src/middlewares/preview_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@ export const preview_image = (middlewares) => [
) {
return next(action);
}
if (action?.request?.data?.map_visualization_data?.preview === 'loading') {
const preview = action?.request?.data?.map_visualization_data?.preview;
if (
preview === 'loading' &&
confirm('Do you want to save a preview image?')
) {
return;
} else if (
preview !== 'loading' &&
!confirm('Do you want to save a preview image?')
) {
return next(action);
}
try {
const previewImage = {
Expand Down

0 comments on commit af50deb

Please sign in to comment.