|
|
@@ -24,191 +24,47 @@ import { alert } from '../../Utils/TotastUtils';
|
|
|
export default function MapScreen({ navigation }) {
|
|
|
const key = 'c4faf80125b298f93bbc1477db10e69c';
|
|
|
const html = `
|
|
|
-<!DOCTYPE html>
|
|
|
-<html lang="en">
|
|
|
-
|
|
|
-<head>
|
|
|
+<head lang="zh-CN">
|
|
|
<meta charset="UTF-8">
|
|
|
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
|
- <title>DOMOverlay</title>
|
|
|
-</head>
|
|
|
-<script charset="utf-8"
|
|
|
- src="https://map.qq.com/api/gljs?libraries=tools&v=1.exp&key=GLFBZ-ZR2W6-76XSA-MF7CQ-GDJ6Z-6FB5K"></script>
|
|
|
-<style type="text/css">
|
|
|
- html,
|
|
|
- body {
|
|
|
- height: 100%;
|
|
|
- margin: 0px;
|
|
|
- padding: 0px;
|
|
|
- }
|
|
|
-
|
|
|
- #container {
|
|
|
- width: 100%;
|
|
|
- height: 100%;
|
|
|
- }
|
|
|
-</style>
|
|
|
-
|
|
|
-<body onload="initMap()">
|
|
|
- <div id="container"></div>
|
|
|
- <script>
|
|
|
- var SVG_NS = 'http://www.w3.org/2000/svg';
|
|
|
- // 自定义环状饼图 - 继承DOMOverlay
|
|
|
- function Donut(options) {
|
|
|
- TMap.DOMOverlay.call(this, options);
|
|
|
+ <meta name="viewport"
|
|
|
+ content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
|
+ <meta name="mobile-web-app-capable" content="yes">
|
|
|
+ <meta name="apple-mobile-web-app-capable" content="yes">
|
|
|
+ <meta name="apple-mobile-web-app-status-bar-style" content="black">
|
|
|
+ <meta name="format-detection" content="address=no">
|
|
|
+ <script type="text/javascript"
|
|
|
+ src="https://3gimg.qq.com/lightmap/components/locationPicker2/js/main-62c2e3b971.js"></script>
|
|
|
+ <title>locationPicker Components Demo - iframe</title>
|
|
|
+ <style>
|
|
|
+ * {
|
|
|
+ margin: 0;
|
|
|
+ padding: 0;
|
|
|
}
|
|
|
|
|
|
- Donut.prototype = new TMap.DOMOverlay();
|
|
|
-
|
|
|
- // 初始化
|
|
|
- Donut.prototype.onInit = function (options) {
|
|
|
- this.position = options.position;
|
|
|
- this.data = options.data;
|
|
|
- this.minRadius = options.minRadius || 0;
|
|
|
- this.maxRadius = options.maxRadius || 50;
|
|
|
- };
|
|
|
-
|
|
|
- // 销毁时需解绑事件监听
|
|
|
- Donut.prototype.onDestroy = function () {
|
|
|
- if (this.onClick) {
|
|
|
- this.dom.removeEventListener(this.onClick);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- // 创建DOM元素,返回一个DOMElement,使用this.dom可以获取到这个元素
|
|
|
- Donut.prototype.createDOM = function () {
|
|
|
- let svg = document.createElementNS(SVG_NS, 'svg');
|
|
|
- svg.setAttribute('version', '1.1');
|
|
|
- svg.setAttribute('baseProfile', 'full');
|
|
|
-
|
|
|
- let r = this.maxRadius;
|
|
|
- svg.setAttribute('viewBox', [-r, -r, r * 2, r * 2].join(' '));
|
|
|
- svg.setAttribute('width', r * 2);
|
|
|
- svg.setAttribute('height', r * 2);
|
|
|
- svg.style.cssText = 'position:absolute;top:0px;left:0px;';
|
|
|
-
|
|
|
- let donut = createDonut(this.data, this.minRadius, this.maxRadius);
|
|
|
- svg.appendChild(donut);
|
|
|
-
|
|
|
- // click事件监听
|
|
|
- this.onClick = () => {
|
|
|
- // DOMOverlay继承自EventEmitter,可以使用emit触发事件
|
|
|
- this.emit('click');
|
|
|
- };
|
|
|
- svg.addEventListener('click', this.onClick);
|
|
|
- return svg;
|
|
|
- };
|
|
|
-
|
|
|
- // 更新DOM元素,在地图移动/缩放后执行
|
|
|
- Donut.prototype.updateDOM = function () {
|
|
|
- if (!this.map) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 经纬度坐标转容器像素坐标
|
|
|
- let pixel = this.map.projectToContainer(this.position);
|
|
|
-
|
|
|
- // 使饼图中心点对齐经纬度坐标点
|
|
|
- let left = pixel.getX() - this.dom.clientWidth / 2 + 'px';
|
|
|
- let top = pixel.getY() - this.dom.clientHeight / 2 + 'px';
|
|
|
- this.dom.style.transform = 'translate('+left+', '+top+')';
|
|
|
- };
|
|
|
-
|
|
|
- // 使用SVG创建环状饼图
|
|
|
- function createDonut(data, minRadius, maxRadius) {
|
|
|
- const colorList = [
|
|
|
- '#7AF4FF',
|
|
|
- '#67D7FF',
|
|
|
- '#52B5FF',
|
|
|
- '#295BFF'
|
|
|
- ];
|
|
|
- let sum = data.reduce((prev, curr) => prev + curr, 0);
|
|
|
- let angle = 0;
|
|
|
-
|
|
|
- let group = document.createElementNS(SVG_NS, "g");
|
|
|
- data.forEach((d, i) => {
|
|
|
- let delta = d / sum * Math.PI * 2;
|
|
|
- color = colorList[i],
|
|
|
- r = maxRadius,
|
|
|
- startAngle = angle,
|
|
|
- endAngle = angle + delta;
|
|
|
- angle += delta;
|
|
|
-
|
|
|
- // 对每个数据创建一个扇形
|
|
|
- let fanShape = document.createElementNS(SVG_NS, 'path');
|
|
|
- fanShape.setAttribute('style', 'fill: '+ color+';');
|
|
|
- fanShape.setAttribute('d', [
|
|
|
- 'M0 0',
|
|
|
- 'L'+(r * Math.sin(startAngle))+(-r * Math.cos(startAngle)),
|
|
|
- 'A'+r+' '+r+' 0 '+(delta > Math.PI ? 1 : 0)+' 1 '+(r * Math.sin(endAngle))+' '+(-r * Math.cos(endAngle)),
|
|
|
- ].join(' ') + ' z');
|
|
|
- group.appendChild(fanShape);
|
|
|
- });
|
|
|
+ body,
|
|
|
+ html {
|
|
|
+ overflow: hidden;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
|
|
|
- // 在中心创建一个圆形
|
|
|
- let circleShape = document.createElementNS(SVG_NS, 'circle');
|
|
|
- circleShape.setAttribute('style', 'fill: #FFFFFF');
|
|
|
- circleShape.setAttribute('cx', 0);
|
|
|
- circleShape.setAttribute('cy', 0);
|
|
|
- circleShape.setAttribute('r', minRadius);
|
|
|
- group.appendChild(circleShape);
|
|
|
+</head>
|
|
|
|
|
|
- // 绘制文字
|
|
|
- let textShape = document.createElementNS(SVG_NS, 'text');
|
|
|
- textShape.setAttribute('x', 0);
|
|
|
- textShape.setAttribute('y', '0.3em');
|
|
|
- textShape.setAttribute('text-anchor', 'middle');
|
|
|
- textShape.innerHTML = sum;
|
|
|
- group.appendChild(textShape);
|
|
|
+<body>
|
|
|
+ <!-- 通过 iframe 嵌入地图选点组件 -->
|
|
|
+ <iframe id="iframe" style="width:100vw;height:100vh" frameborder=0 scrolling="no"
|
|
|
+ src="https://apis.map.qq.com/tools/locpicker?search=1&type=1&key=GLFBZ-ZR2W6-76XSA-MF7CQ-GDJ6Z-6FB5K&referer=Dingdong">
|
|
|
+ </iframe>
|
|
|
|
|
|
- return group;
|
|
|
- }
|
|
|
+ <script>
|
|
|
|
|
|
- window.Donut = Donut;
|
|
|
- </script>
|
|
|
- <script type="text/javascript">
|
|
|
- var map;
|
|
|
- function initMap() {
|
|
|
- // 初始化地图
|
|
|
- map = new TMap.Map("container", {
|
|
|
- zoom: 12, // 设置地图缩放级别
|
|
|
- center: new TMap.LatLng(39.984104, 116.307503) // 设置地图中心点坐标
|
|
|
- });
|
|
|
+ window.addEventListener('message', function (event) {
|
|
|
+ var loc = event.data;
|
|
|
+ window.ReactNativeWebView.postMessage(JSON.stringify(loc))
|
|
|
+ }, false);
|
|
|
|
|
|
- let donutList = [
|
|
|
- new Donut({
|
|
|
- map,
|
|
|
- position: new TMap.LatLng(39.96030543872138, 116.25809083213608),
|
|
|
- data: [12, 24],
|
|
|
- minRadius: 13,
|
|
|
- maxRadius: 20
|
|
|
- }),
|
|
|
- new Donut({
|
|
|
- map,
|
|
|
- position: new TMap.LatLng(39.9986945980902, 116.33598362780685),
|
|
|
- data: [23, 99, 101, 400],
|
|
|
- minRadius: 25,
|
|
|
- maxRadius: 35
|
|
|
- }),
|
|
|
- new Donut({
|
|
|
- map,
|
|
|
- position: new TMap.LatLng(40.02906301748584, 116.25499991104516),
|
|
|
- data: [18, 41, 50],
|
|
|
- minRadius: 20,
|
|
|
- maxRadius: 28
|
|
|
- })
|
|
|
- ];
|
|
|
|
|
|
- donutList.forEach((donut, index) => {
|
|
|
- donut.on('click', () => {
|
|
|
- console.log('第'+index+'个环形图被点击,位置为'+donut.position);
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
</script>
|
|
|
</body>
|
|
|
-
|
|
|
-</html>
|
|
|
`;
|
|
|
return (
|
|
|
<>
|