map & scale

TW bug

https://antv.alipay.com/zh-cn/g2/3.x/demo/map/drill-down.html


import React, { useEffect } from 'react';
import PropTypes from 'prop-types'; import { bindActionCreators } from 'redux';
import { connect } from 'dva'; import G2 from '@antv/g2';
import DataSet from '@antv/data-set'; import numeral from 'numeral'; import {
// Spin,
Tooltip,
Button,
// message,
} from 'antd'; import { formatAdcode, isSpecialArea, getAreaNode } from '@/utils/regionUtils'; import dashboardRegionActions from '../actions/dashboard.region.action'; let chart; const mapStateToProps = ({ dashboard }) => ({
regionData: dashboard.regionData,
// mapLoading: dashboard?.mapLoading,
}); const mapDispatchToProps = dispatch => ({
actions: bindActionCreators(dashboardRegionActions, dispatch),
}); // export default connect(
// mapStateToProps,
// mapDispatchToProps,
// )(RegionChart);
// @connect(mapStateToProps, mapDispatchToProps,) const RegionChart = ({
regionData,
actions: {
changeRegion,
}
}) => {
let _drawChart;
const { adcode, regions = [] } = regionData;
let scaleHeight = 520;
let scaleWidth = 700;
let paddingLeft = 100;
useEffect(() => {
getAreaNode(adcode).then(_drawChart);
}, [_drawChart, adcode, regionData]); const _dataSource = geoJSON => {
const data = [];
for (let i = 0; i < geoJSON.length; i++) {
// if (i === 0) {
// console.log(`geoJSON[i]`, geoJSON[i]);
// }
const { name, adcode } = geoJSON[i].properties;
// 可以与后端沟通改数据格式
const target = regions.find(({ code }) => formatAdcode(code) === adcode) || {};
const { code, totalUv } = target;
data.push({
adcode,
code,
name,
totalUv,
});
}
return data;
}; _drawChart = areaNode => {
if (!areaNode) return; const geoJSON = isSpecialArea(adcode)
? [areaNode.getParentFeature()]
: areaNode.getSubFeatures(); chart && chart.destroy(); const ds = new DataSet();
const geoDataView = ds.createView().source(
{
type: 'FeatureCollection',
features: geoJSON,
},
{
type: 'GeoJSON',
},
);
const dvData = ds.createView().source(_dataSource(geoJSON));
// 构造 mock 数据
if (adcode === "71") {
dvData.origin.push({
adcode: 710000,
code: undefined,
name: "台湾省",
totalUv: undefined,
});
dvData.rows.push({
adcode: 710000,
code: undefined,
name: "台湾省",
totalUv: undefined,
lat: [0],
lng: [0],
});
} dvData.transform({
type: 'geo.region',
field: 'name',
geoDataView,
as: ['lng', 'lat'],
});
window.$$ = (uid = ``) => document.querySelector(uid);
if (adcode === "71") {
// skip 台湾 bug
scaleHeight = 0;
scaleWidth = 0;
setTimeout(() => {
let TW = window.$$(".region-map-chart-tw");
if (TW) {
TW.style.display = "block";
}
}, 0);
} else {
setTimeout(() => {
let TW = window.$$(".region-map-chart-tw");
if (TW) {
TW.style.display = "none";
}
}, 0);
// start: 计算地图的最佳宽高
let longitudeRange = dvData.range('lng');
let lantitudeRange = dvData.range('lat');
let chartBox = window.$$(".region-container");
let ratio = (longitudeRange[1] - longitudeRange[0]) / (lantitudeRange[1] - lantitudeRange[0]);
if (ratio > chartBox.clientWidth / chartBox.clientHeight) {
scaleWidth = chartBox.clientWidth;
scaleHeight = scaleWidth / ratio;
} else {
scaleWidth = chartBox.clientHeight * ratio;
scaleHeight = chartBox.clientHeight;
} // if (scaleWidth > scaleHeight) {
// paddingLeft = (scaleWidth - scaleHeight) * ratio;
// } else {
// paddingLeft = (scaleHeight - scaleWidth);
// }
// end: 计算地图的最佳宽高
} chart = new G2.Chart({
container: 'region_chart',
height: scaleHeight,
width: scaleWidth,
// padding: 0,
padding: {
left: paddingLeft,
top: 0,
},
// padding: {
// left: 100,
// top: 0,
// },
}); chart.source(dvData); chart.tooltip({
title: 'name',
}); // chart.scale([0, 0.5]);
// chart.scale([0, 1]); chart
.legend(false)
.axis(false)
.polygon()
.position('lng*lat')
.label('name', {
type: 'map',
textStyle: {
fill: '#333',
fontSize: 12,
},
})
.style({
stroke: '#fff',
lineWidth: 1,
})
// 渐变色, 颜色串(start -> end)
.color('totalUv', '#6882FFFF-#898bf2FF-#c3c4f8FF')
// .color('totalUv', '#BAE7FF-#1890FF-#0050B3')
.tooltip('name*totalUv', (name, totalUv) => ({
name: '累计用户数',
value: totalUv ? numeral(totalUv).format('0,0') + '人' : '- -',
})); // 文字
if (adcode === "71") {
// 不好使???
chart
.guide()
.text({
// position: ['min', 'max'],
position: [0, 0],
offsetX: 100 - paddingLeft,
offsetY: 100,
content: "台湾省",
style: {
fontSize: 14,
fontWeight: 'bold',
},
});
} else {
chart
.guide()
.text({
position: ['min', 'max'],
offsetX: 30 - paddingLeft,
offsetY: 20,
content: areaNode.getName(),
// content: "台湾省",
style: {
fontSize: 14,
fontWeight: 'bold',
},
});
} chart.render();
// if (adcode === 'all') {
// chart.on('click', ev => {
// if (ev?.data?._origin) {
// if (ev.data._origin.code) {
// changeRegion(ev.data._origin.code);
// } else {
// message.warning('暂无数据');
// }
// }
// });
// }
}; return (
<>
{adcode !== 'all' && (
<Tooltip title="点击返回全国">
<Button
size="small"
className="region-map-tooltip"
icon="left"
onClick={() => changeRegion('all')}
/>
</Tooltip>
)}
<div id="region_chart" className="region-map-chart" />
<div className="region-map-chart-legend"></div>
<div className="region-map-chart-tw">
台湾省
</div>
</>
);
}; RegionChart.propTypes = {
regionData: PropTypes.object,
}; export default connect(
mapStateToProps,
mapDispatchToProps,
)(RegionChart); // export {
// RegionChart,
// };
// export default RegionChart;

https://www.yuque.com/antv/g2-docs/api-scale

https://www.yuque.com/antv/g2-docs/tutorial-scale



[
{
"name": "全国数据",
"key": "all",
"alias": 10,
"group": "Q"
},
{
"name": "北京市",
"key": 11,
"group": "B"
},
{
"name": "天津市",
"key": 12,
"group": "T"
},
{
"name": "河北省",
"key": 13,
"group": "H"
},
{
"name": "山西省",
"key": 14,
"group": "S"
},
{
"name": "内蒙古自治区",
"key": 15,
"group": "N"
},
{
"name": "辽宁省",
"key": 21,
"group": "L"
},
{
"name": "吉林省",
"key": 22,
"group": "J"
},
{
"name": "黑龙江省",
"key": 23,
"group": "H"
},
{
"name": "上海市",
"key": 31,
"group": "S"
},
{
"name": "江苏省",
"key": 32,
"group": "J"
},
{
"name": "浙江省",
"key": 33,
"group": "Z"
},
{
"name": "安徽省",
"key": 34,
"group": "A"
},
{
"name": "福建省",
"key": 35,
"group": "F"
},
{
"name": "江西省",
"key": 36,
"group": "J"
},
{
"name": "山东省",
"key": 37,
"group": "S"
},
{
"name": "河南省",
"key": 41,
"group": "H"
},
{
"name": "湖北省",
"key": 42,
"group": "H"
},
{
"name": "湖南省",
"key": 43,
"group": "H"
},
{
"name": "广东省",
"key": 44,
"group": "G"
},
{
"name": "广西壮族自治区",
"key": 45,
"group": "G"
},
{
"name": "海南省",
"key": 46,
"group": "H"
},
{
"name": "重庆市",
"key": 50,
"group": "C"
},
{
"name": "四川省",
"key": 51,
"group": "S"
},
{
"name": "贵州省",
"key": 52,
"group": "G"
},
{
"name": "云南省",
"key": 53,
"group": "Y"
},
{
"name": "西藏自治区",
"key": 54,
"group": "X"
},
{
"name": "陕西省",
"key": 61,
"group": "S"
},
{
"name": "甘肃省",
"key": 62,
"group": "G"
},
{
"name": "青海省",
"key": 63,
"group": "Q"
},
{
"name": "宁夏回族自治区",
"key": 64,
"group": "N"
},
{
"name": "新疆维吾尔自治区",
"key": 65,
"group": "X"
},
{
"name": "台湾省",
"key": 71,
"group": "T"
},
{
"name": "香港特别行政区",
"key": 81,
"group": "X"
},
{
"name": "澳门特别行政区",
"key": 82,
"group": "A"
}
]

城市编码表

https://lbs.amap.com/api/webservice/download

cdn

https://a.amap.com/lbs/static/file/AMap_adcode_citycode.xlsx.zip



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


map & scale bug的更多相关文章

  1. RAD C++Builder xe7 std::map xtree BUG

    c++Builder 6 下的std::map还能用,有代码提示. 换到xe7,代码提示出来就一个tt.operator [](),代码没法往下写了. 最后把Target Platforms切换到64 ...

  2. 在mpvue中使用map如何避坑

    最近在做一个需求,当用户放大地图到某个级别时,自动显示marker的callout标签,当小于这个缩放级别时,则隐藏callout.然而在我实现的过程中,却发现一个严重的问题:当我操作marker数据 ...

  3. ArcGIS Google Map 增加虚拟图层(MapImageLayer)(转载)

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  4. 微信小程序 - 多地点标识(map)

    演示如下: wxml <map id="map" scale="{{scale}}" controls="{{controls}}" ...

  5. 小程序map地图多点定位

    最近需求有一个类似共享单车查看附近单车的功能,看了看小程序map api对多点定位显示描述的不怎么清晰.显示定位数组添加多个时就不显示了.踩了几个坑写了几个方法.最终弄出来了.有问题建议欢迎留言. h ...

  6. CartO

    Carto documentation The following is a list of properties provided in CartoCSS that you can apply to ...

  7. arcmap Command

    The information in this document is useful if you are trying to programmatically find a built-in com ...

  8. GIS理论(墨卡托投影、地理坐标系、地面分辨率、地图比例尺、Bing Maps Tile System)

    [注]原文 http://www.cnblogs.com/beniao/archive/2010/04/18/1714544.html 墨卡托投影(Mercator Projection),又名&qu ...

  9. ArcGIS API for JavaScript 4.0(一)

    原文:ArcGIS API for JavaScript 4.0(一) 最近ArcGIS推出了ArcGIS API for JavaScript 4.0,支持无插件3D显示,而且比较Unity和Sky ...

随机推荐

  1. vscode远程开发安装

    https://www.cnblogs.com/xiaoqi/p/vs-code-remote.html ============================= https://blog.csdn ...

  2. python中贪婪与非贪婪

    Python里数量词默认是贪婪的(在少数语言里也可能是默认非贪婪),总是尝试匹配尽可能多的字符: 非贪婪则相反,总是尝试匹配尽可能少的字符. 在"*","?", ...

  3. Jsp数字格式化

    日期格式(2008年5月5日22点00分23秒) <fmt:formatDate value="<%=new Date() %>" pattern="y ...

  4. samba 、 FTP 、 lrzsz工具

    samba Samba是一个实现不同操作系统(Windows.Linux.UNIX)之间文件共享和打印机共享的一种SMB协议的免费软件:linux与linux之间共享用NFS:samba基于cs架构: ...

  5. Nginx图文详解

    想必大家一定听说过 Nginx,若没听说过它,那么一定听过它的"同行"Apache 吧! Nginx 的产生 Nginx 同 Apache 一样都是一种 Web 服务器.基于 RE ...

  6. cassandra权威指南读书笔记--客户端

    DataStax驱动最成熟.默认,驱动程序会使用第一个连接的节点作为支持的版本协议.如果集群存在高低版本的节点(比如升级场景),如果驱动先连接不同不同版本的节点,可能会出现不兼容.驱动支持压缩客户端和 ...

  7. MapReduce统计每个用户的使用总流量

    1.原始数据 2.使用java程序 1)新建项目 2)导包 hadoop-2.7.3\share\hadoop\mapreduce +hsfs的那些包 +common 3.写项目 1)实体类 注:属性 ...

  8. Codeforces Round #667 (Div. 3)

    比赛链接:https://codeforces.com/contest/1409 A. Yet Another Two Integers Problem 题意 给出两个数 $a$ 和 $b$,有以下两 ...

  9. 【poj 2891】Strange Way to Express Integers(数论--拓展欧几里德 求解同余方程组 模版题)

    题意:Elina看一本刘汝佳的书(O_O*),里面介绍了一种奇怪的方法表示一个非负整数 m .也就是有 k 对 ( ai , ri ) 可以这样表示--m%ai=ri.问 m 的最小值. 解法:拓展欧 ...

  10. zjnuSAVEZ (字符串hash)

    Description There are eight planets and one planetoid in the Solar system. It is not a well known fa ...