当前位置: 首页 > news >正文

APP嵌入WebView实现中国地图分布图

要在 React Native 中实现一个中国地区分布图

使用 WebView + ECharts 实现

效果实现图:
在这里插入图片描述

import React from 'react';
import {View} from 'react-native';
import {WebView} from 'react-native-webview';
/*** * 中国分布地图组件* 效果图地址:https://oss.leixiaoan.com/lxz-icon/home/chinaMap.jpg*/
const ChinaMap = () => {const html = `<!DOCTYPE html><html><head><meta charset="UTF-8" /><script src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script><style>html, body, #main {height: 100%;margin: 0;padding: 0;}</style></head><body><div id="main"></div><script>// 动态加载中国地图 GeoJSON 数据fetch('https://geo.datav.aliyun.com/areas/bound/100000_full.json').then(res => res.json()).then(geoJson => {echarts.registerMap('china', geoJson);var chart = echarts.init(document.getElementById('main'));var option = {tooltip: {trigger: 'item',formatter: '{b}: {c}'},visualMap: {min: 0,max: 100,left: 'left',top: 'bottom',text: ['高', '低'],calculable: true,inRange: {color: ['#d0f0ff', '#409EFF'] // 从浅到深的蓝色},outOfRange: {color: '#e6f7ff'  // 空值背景色(浅蓝)}},series: [{name: '地区数值',type: 'map',map: 'china',label: {show: true},data: [{ name: '北京市', value: Math.floor(Math.random() * 101) },{ name: '天津市', value: Math.floor(Math.random() * 101) },{ name: '上海市', value: Math.floor(Math.random() * 101) },{ name: '重庆市', value: Math.floor(Math.random() * 101) },{ name: '河北省', value: Math.floor(Math.random() * 101) },{ name: '山西省', value: Math.floor(Math.random() * 101) },{ name: '辽宁省', value: Math.floor(Math.random() * 101) },{ name: '吉林省', value: Math.floor(Math.random() * 101) },{ name: '黑龙江省', value: Math.floor(Math.random() * 101) },{ name: '江苏省', value: Math.floor(Math.random() * 101) },{ name: '浙江省', value: Math.floor(Math.random() * 101) },{ name: '安徽省', value: Math.floor(Math.random() * 101) },{ name: '福建省', value: Math.floor(Math.random() * 101) },{ name: '江西省', value: Math.floor(Math.random() * 101) },{ name: '山东省', value: Math.floor(Math.random() * 101) },{ name: '河南省', value: Math.floor(Math.random() * 101) },{ name: '湖北省', value: Math.floor(Math.random() * 101) },{ name: '湖南省', value: Math.floor(Math.random() * 101) },{ name: '广东省', value: Math.floor(Math.random() * 101) },{ name: '海南省', value: Math.floor(Math.random() * 101) },{ name: '四川省', value: Math.floor(Math.random() * 101) },{ name: '贵州省', value: Math.floor(Math.random() * 101) },{ name: '云南省', value: Math.floor(Math.random() * 101) },{ name: '陕西省', value: Math.floor(Math.random() * 101) },{ name: '甘肃省', value: Math.floor(Math.random() * 101) },{ name: '青海省', value: Math.floor(Math.random() * 101) },{ name: '台湾省', value: Math.floor(Math.random() * 101) },{ name: '内蒙古自治区', value: Math.floor(Math.random() * 101) },{ name: '广西壮族自治区', value: Math.floor(Math.random() * 101) },{ name: '西藏自治区', value: Math.floor(Math.random() * 101) },{ name: '宁夏回族自治区', value: Math.floor(Math.random() * 101) },{ name: '新疆维吾尔自治区', value: Math.floor(Math.random() * 101) },{ name: '香港特别行政区', value: Math.floor(Math.random() * 101) },{ name: '澳门特别行政区', value: Math.floor(Math.random() * 101) },]}]};chart.setOption(option);});</script></body></html>`;return (<View style={{flex: 1, backgroundColor: 'red', width: '100%', height: 300}}><WebView originWhitelist={['*']} source={{html}} /></View>);
};export default ChinaMap;

相关文章:

  • Mediatek Android13 设置Launcher
  • UML概览
  • Spark-Streaming简介 核心编程
  • 在线视频转 AVI 的便捷之选,便捷操作,无需下载软件,在线使用
  • 信息系统项目管理师_第十二章 项目风险管理
  • 复盘20250422
  • 3d打印机设备厂家|casaim打印建筑楼盘模型
  • 探索 Linux 路由表及 route 命令的奥秘
  • 每日OJ_牛客_AOE还是单体?_贪心_C++_Java
  • Spring事件机制,如何使用Spring事件监听器
  • ROS 2开发中的目录哲学:源码与产物的共生关系
  • RockChip Android14 修改LCD背光最大值
  • 云账号安全事件应急响应指南:应对来自中国IP的异常访问
  • STM32 外部中断
  • iPaaS+AI:企业数智化转型的“智能基座”与创新引擎
  • Unity 脚本使用(二)——UnityEngine.AI——NavMesh
  • Flink介绍——实时计算核心论文之Dataflow论文详解
  • 进阶篇 第 3 篇:经典永不落幕 - ARIMA 模型详解与实践
  • 路由交换网络专题 | 第六章 | OSPF | BGP | BGP属性 | 防环机制
  • 3674B矢量网络分析仪
  • 金地集团:保交楼为经营的首要任务,将根据融资性现金流恢复程度等进行投资决策
  • 神二十具备执行发射任务的各项条件
  • 5旬辅警30余年前被人顶替上中专?河南沁阳:基本属实,将依法处理
  • 上海消保委调查二次元消费:手办与卡牌受欢迎,悦己和社交是动力
  • 外汇局:将持续强化外汇形势监测,保持汇率弹性,坚决对市场顺周期行为进行纠偏
  • 广西通报桂林、贵港、玉林三市应对不力:管不住山火和露天焚烧