[D3JS] Add more map layer and color

import React, {Component} from 'react';
import * as d3 from 'd3';
import 'd3-geo';
import * as topojson from 'topojson';
import * as colorbrewer from 'colorbrewer';
const us = require('./us.json');
const width = 960;
const height = 600;
class Map extends Component {
componentDidMount() {
const svg = d3.select(this.refs.mountSvg)
.append('svg')
.attr('height', height)
.attr('width', width);
const path = d3.geoPath();
// define color
var color = d3.scaleLinear()
.domain([-100000, 500000])
.range(colorbrewer.Greens[6]);
// Add nation layer
svg.append('path')
.datum(topojson.feature(us, us.objects.nation))
.attr('class', 'land')
.attr('d', path);
// add state layer
svg.append('path')
.datum(topojson.mesh(us, us.objects.states), (a,b) => a!==b)
.attr('class', 'border state')
.attr('d', path);
// add counties and county layer
svg.append("g")
.attr("class", "counties")
.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features)
.enter().append("path")
.attr("class", "county")
.attr("d", path)
//add color
.attr("fill", function(d) {
const profit = d.properties.profit;
if(profit) {
return color(d.properties.profit);
}
})
}
render() {
const style = {
width,
height,
border: '1px solid black',
margin: '10px auto'
};
return (
<div style={style} ref="mountSvg"></div>
);
}
}
export default Map;
[D3JS] Add more map layer and color的更多相关文章
- Add baidu map in your website (wordpress)
手动挡 访问应用(AK)Key http://lbsyun.baidu.com/apiconsole/key Basic Map Generator http://api.map.baidu.com/ ...
- HEC-ResSim原文档
HEC-ResSim Reservoir System Simulation User's Manual Version 3.1 May 201 ...
- PS网页设计教程XXX——在PS中创建一个漫画书主题网页布局
作为编码者,美工基础是偏弱的.我们可以参考一些成熟的网页PS教程,提高自身的设计能力.套用一句话,“熟读唐诗三百首,不会作诗也会吟”. 本系列的教程来源于网上的PS教程,都是国外的,全英文的.本人尝试 ...
- MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.1 A map with single layer
MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.1 A map with single layer 一.前言 开始MapServer用 ...
- ROS_Kinetic_x ROS栅格地图庫 Grid Map Library
源自:https://github.com/ethz-asl/grid_map Grid Map Overview This is a C++ library with ROS interface t ...
- MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.7 Adding a wms layer
MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.7 Adding a wms layer 前言 Add OGC WMS Layers( ...
- MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.5 Adding a raster layer
MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.5 Adding a raster layer 一.前言 MapServer不仅支持 ...
- MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example 1.4 Labeling the Map
MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example 1.4 Labeling the Map 一.前言 MapServer拥有非常灵活的标签 ...
- MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.3 Displaying Classes in a Layer
MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.3 Displaying Classes in a Layer 一.前言 关于第一节的 ...
随机推荐
- Java基本数据类型及字节
1.基本类型可以分为三类,字符类型char,布尔类型boolean以及数值类型byte.short.int.long.float.double.数值类型又可以分为整数类型byte.short.int. ...
- poj--1637--Sightseeing tour(网络流,最大流判断混合图是否存在欧拉图)
Sightseeing tour Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u Sub ...
- Linux企业应用--RHAS 2.1 下安装中文 Lotus Domino R 6.5 图解
原文请到ftp.jms165.com下载,是用上传用户 (RHAS3+ksnapshot+OperOff ...
- jquery easyui 输入框 禁止输入负数 设置属性data-options="min:0,required:true"
jquery easyui 输入框 禁止输入负数 设置属性data-options="min:0,required:true" <input id="days& ...
- Aspose.Cells相应操作及下载
Aspose.Cells相应操作 1,上传 1.1 Workbook Workbook workBook = new Workbook(); 属性: 名称 值类型 说明 Colors Color[] ...
- Redis 数据持久化的方案的实现
原文:Redis 数据持久化的方案的实现 版权声明:m_nanle_xiaobudiu https://blog.csdn.net/m_nanle_xiaobudiu/article/details/ ...
- RQNOJ PID496/[IOI1999]花店橱窗布置
PID496 / [IOI1999]花店橱窗布置 ☆ 题目描述 某花店现有F束花,每一束花的品种都不一样,同时至少有同样数量的花瓶,被按顺序摆成一行,花瓶的位置是固定的,从左到右按1到V顺序 编号 ...
- mongodb适用和不适用的应用场景
近期考虑把订单历史数据从Oracle数据库迁移到Nosql数据库做历史数据查询和分析,一天千万级数据.打算使用mongodb数据库.使用nodejs做查询和统计API,对并发请求量要求低,不知道有没有 ...
- 在oracle存储过程中创建暂时表
在oracle的存储过程中,不能直接使用DDL语句,比方create.alter.drop.truncate等. 那假设我们想在存储过程中建立一张暂时表就仅仅能使用动态sql语句了: create o ...
- 一些安全的DNS提供商
检测当前使用的DNS服务器 https://dnsleaktest.com 一些安全的DNS提供商 DNS提供商名称 主DNS服务器 次要DNS服务器 Google 8.8.8.8 8.8.4. ...