|
|
from pyecharts import options as opts
|
|
|
from pyecharts.charts import Geo
|
|
|
from pyecharts.globals import ChartType, SymbolType
|
|
|
import json
|
|
|
|
|
|
|
|
|
def rendOutputGeo(outputFilePath: str):
|
|
|
# 创建Geo对象
|
|
|
c = Geo(init_opts=opts.InitOpts(width="100%", height="100%")).add_schema(
|
|
|
# 添加地理坐标系配置
|
|
|
maptype="world", # 地图类型
|
|
|
itemstyle_opts=opts.ItemStyleOpts(
|
|
|
color="rgba(0, 255, 255, 0.8)" # 地图区域颜色
|
|
|
),
|
|
|
# label_opts=opts.LabelOpts(is_show=True), # 是否显示标签
|
|
|
)
|
|
|
|
|
|
# 读取坐标点添加到地图中
|
|
|
labelList = []
|
|
|
index = 0
|
|
|
with open(outputFilePath, "r") as file:
|
|
|
for line in file:
|
|
|
if index % 3 == 0:
|
|
|
coordinate = [float(x) for x in line.split()]
|
|
|
c.add_coordinate("测试点" + str(index), coordinate[0], coordinate[1])
|
|
|
labelList.append(
|
|
|
["测试点" + str(index), ", ".join(map(str, coordinate))]
|
|
|
)
|
|
|
index += 1
|
|
|
|
|
|
c.add("卫星坐标投影", [(x[0], x[1]) for x in labelList], symbol_size=6)
|
|
|
c.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
|
|
|
c.set_global_opts(
|
|
|
# visualmap_opts=opts.VisualMapOpts(is_piecewise=True, min_=-1, max_=1, range_color=['#FEF888', '#ED7651', 'red']), # 设置比例尺的的范围这里设置最小为-1最大为1, 设置区间颜色([最低,中间,最高])
|
|
|
title_opts=opts.TitleOpts(title="卫星坐标图", subtitle=""),
|
|
|
)
|
|
|
|
|
|
htmlFilePath = outputFilePath.replace(".txt", ".html")
|
|
|
# 渲染地图
|
|
|
c.render(htmlFilePath)
|
|
|
|
|
|
# 修改html,支持全屏和自适应
|
|
|
with open(htmlFilePath, "r") as file:
|
|
|
data = file.read()
|
|
|
# 1、设置全屏大小
|
|
|
# 2、将在线js文件替换为本地js文件
|
|
|
data = data.replace(
|
|
|
"</head>",
|
|
|
"<style>html, body{width: 100%;height: 100%;margin:0px;}</style>\n</head>",
|
|
|
).replace(
|
|
|
"https://assets.pyecharts.org/assets/v5/echarts.min.js", "echarts.min.js").replace(
|
|
|
"https://assets.pyecharts.org/assets/v5/maps/world.js","world.js")
|
|
|
with open(htmlFilePath, "w", encoding="utf-8") as file:
|
|
|
file.write(data)
|
|
|
|