Skip to content

Commit

Permalink
feat: can receive selected tree from iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
dadiorchen committed May 6, 2023
1 parent bc268d4 commit 1a80d5e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/pages/demo.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import React from 'react';
// import { Map } from 'treetracker-web-map-core';

const label = 'DEMO:';
function Demo() {
const iframeRef = React.useRef();

React.useEffect(() => {
// jjiframeRef.current.contentWindow.alert("OK");
setTimeout(() => {
const {map} = iframeRef.current.contentDocument.querySelector('#map-canvas');
console.log('map:', map);
const { map } =
iframeRef.current.contentDocument.querySelector('#map-canvas');
console.log(label, 'map:', map);
map.on('move-end', (data) => {
console.log(label, 'onMoveEnd:', data);
});
map.on('tree-selected', (data) => {
console.log(label, 'select tree:', data);
});
map.onClickTree((data) => {
console.log('onClickTree:', data);
console.log(label, 'onClickTree:', data);
});
}, 5000);
}, 10000);
}, []);

return (
Expand All @@ -24,7 +33,7 @@ function Demo() {
src="http://localhost:3000/"
width="800px"
height="600px"
/>
/>
</div>
);
}
Expand Down

0 comments on commit 1a80d5e

Please sign in to comment.