Heat3DScreen.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { StatusBar } from 'expo-status-bar';
  4. import { Div, Button } from 'react-native-magnus';
  5. import { Appbar } from 'react-native-paper';
  6. import { WebView } from 'react-native-webview';
  7. import { useTranslation } from 'react-i18next';
  8. import useModel from 'flooks';
  9. import { useRequest } from 'ahooks';
  10. import MapModel from './model';
  11. import {
  12. toastShow,
  13. toastHide,
  14. toastInfo,
  15. toastSuccess,
  16. } from '../utils/SystemUtils';
  17. export default function SearchMapScreen() {
  18. const { t } = useTranslation();
  19. const webRef = React.useRef();
  20. const { getNowLocation } = useModel(MapModel);
  21. const { run } = useRequest(
  22. (location) =>
  23. `/merchant/heatMap?longitude=${location.lng}&latitude=${location.lat}`,
  24. {
  25. manual: true,
  26. }
  27. );
  28. return (
  29. <>
  30. <WebView
  31. ref={webRef}
  32. source={{
  33. uri: `http://dingdong.izouma.com/map/heat3D`,
  34. }}
  35. style={{ flexGrow: 1, width: '100%' }}
  36. onMessage={({ nativeEvent }) => {
  37. console.log(nativeEvent);
  38. }}
  39. onLoadEnd={() => {
  40. getNowLocation().then((res) => {
  41. const { location } = res;
  42. run(location).then((res) => {
  43. var list = res.map((item) => {
  44. return {
  45. count: item.count,
  46. lng: item.longitude,
  47. lat: item.latitude,
  48. };
  49. });
  50. webRef.current.injectJavaScript(
  51. `window.draw(${JSON.stringify(list)},'${JSON.stringify(
  52. location
  53. )}')`
  54. );
  55. });
  56. });
  57. }}
  58. />
  59. </>
  60. );
  61. }