MapMarkImg.jsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 { merLocation, location, merShowName, riderLocation } = info;
  10. const merLocations = merLocation ? merLocation.split(',') : [];
  11. const locations = location ? location.split(',') : [];
  12. const ridLocations = riderLocation ? riderLocation.split(',') : [];
  13. const persoMark =
  14. locations.length > 0
  15. ? `markers=icon:${personImg}%7C${locations[1]},${locations[0]}`
  16. : '';
  17. const merchatMark =
  18. merLocation.length > 0
  19. ? `markers=icon:${merchatImg}%7C${merLocations[1]},${merLocations[0]}`
  20. : '';
  21. const riderMark =
  22. ridLocations.length > 0
  23. ? `markers=icon:${riderImg}%7C${ridLocations[1]},${ridLocations[0]}`
  24. : '';
  25. const markers = useCreation(() => {
  26. const str = '';
  27. let list = [];
  28. switch (imgType) {
  29. case 'rider':
  30. list.push(riderMark);
  31. list.push(merchatMark);
  32. list.push(persoMark);
  33. break;
  34. case 'merchant':
  35. list.push(merchatMark);
  36. list.push(riderMark);
  37. list.push(persoMark);
  38. break;
  39. default:
  40. list.push(persoMark);
  41. list.push(riderMark);
  42. list.push(merchatMark);
  43. break;
  44. }
  45. list = list.filter((item) => {
  46. return !!item;
  47. });
  48. return list.length > 0 ? `&${list.join('&')}` : str;
  49. }, [persoMark, merchatMark, riderMark, info, imgType]);
  50. const center = useCreation(() => {
  51. let str = '';
  52. switch (imgType) {
  53. case 'rider':
  54. str = '31.982155,118.734716';
  55. break;
  56. case 'merchant':
  57. str = `${merLocations[1]},${merLocations[0]}`;
  58. break;
  59. default:
  60. str = `${merLocations[1]},${merLocations[0]}`;
  61. break;
  62. }
  63. return str;
  64. }, [persoMark, merchatMark, riderMark, info, imgType]);
  65. return (
  66. <>
  67. <Div>
  68. {imgType != null && (
  69. <>
  70. <Div
  71. position="absolute"
  72. left={0}
  73. right={0}
  74. top={10}
  75. zIndex={2}
  76. row
  77. justifyContent="center"
  78. >
  79. <Text bg="brand500" color="white" px={10} py={5} rounded="sm">
  80. {label}
  81. </Text>
  82. </Div>
  83. <Image
  84. zIndex={1}
  85. h={200}
  86. source={{
  87. 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`,
  88. }}
  89. />
  90. </>
  91. )}
  92. </Div>
  93. </>
  94. );
  95. }