MapMarkImg.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import * as WebBrowser from 'expo-web-browser';
  2. import * as React from 'react';
  3. import { Div, Image, Text } from 'react-native-magnus';
  4. import useModel from 'flooks';
  5. import { useRequest, useCreation } from '@umijs/hooks';
  6. import MapModel from './model'; // detail模块通用方法
  7. export default function MapMarkImg({ imgType, info, label }) {
  8. const { personImg, merchatImg, riderImg } = useModel(MapModel, []);
  9. const { merchant, location } = info;
  10. const locations = location ? location.split(',') : [];
  11. const persoMark =
  12. locations.length > 0
  13. ? `markers=icon:${personImg}%7C${locations[1]},${locations[0]}`
  14. : '';
  15. const merchatMark = `markers=icon:${merchatImg}%7C${merchant.latitude},${merchant.longitude}`;
  16. const riderMark = `markers=icon:${riderImg}%7C31.981746,118.734661`;
  17. const markers = useCreation(() => {
  18. const str = '';
  19. let list = [];
  20. switch (imgType) {
  21. case 'rider':
  22. list.push(riderMark);
  23. list.push(merchatMark);
  24. list.push(persoMark);
  25. break;
  26. case 'merchant':
  27. list.push(merchatMark);
  28. list.push(riderMark);
  29. list.push(persoMark);
  30. break;
  31. default:
  32. list.push(persoMark);
  33. list.push(riderMark);
  34. list.push(merchatMark);
  35. break;
  36. }
  37. list = list.filter((item) => {
  38. return !!item;
  39. });
  40. return list.length > 0 ? `&${list.join('&')}` : str;
  41. }, [persoMark, merchatMark, riderMark, info, imgType]);
  42. const center = useCreation(() => {
  43. let str = '';
  44. switch (imgType) {
  45. case 'rider':
  46. str = '31.982155,118.734716';
  47. break;
  48. case 'merchant':
  49. str = `${merchant.latitude},${merchant.longitude}`;
  50. break;
  51. default:
  52. str = `${merchant.latitude},${merchant.longitude}`;
  53. break;
  54. }
  55. return str;
  56. }, [persoMark, merchatMark, riderMark, info, imgType]);
  57. return (
  58. <>
  59. <Div>
  60. {imgType != null && (
  61. <>
  62. <Div
  63. position="absolute"
  64. left={0}
  65. right={0}
  66. top={10}
  67. zIndex={2}
  68. row
  69. justifyContent="center"
  70. >
  71. <Text bg="brand500" color="white" px={10} py={5} rounded="sm">
  72. {label}
  73. </Text>
  74. </Div>
  75. <Image
  76. zIndex={1}
  77. h={200}
  78. source={{
  79. uri: `https://apis.map.qq.com/ws/staticmap/v2/?center=${center}&zoom=18&size=939*600&maptype=roadmap${markers}&key=GLFBZ-ZR2W6-76XSA-MF7CQ-GDJ6Z-6FB5K`,
  80. }}
  81. />
  82. </>
  83. )}
  84. </Div>
  85. </>
  86. );
  87. }