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的更多相关文章

  1. Add baidu map in your website (wordpress)

    手动挡 访问应用(AK)Key http://lbsyun.baidu.com/apiconsole/key Basic Map Generator http://api.map.baidu.com/ ...

  2. HEC-ResSim原文档

              HEC-ResSim Reservoir System Simulation             User's Manual       Version 3.1 May 201 ...

  3. PS网页设计教程XXX——在PS中创建一个漫画书主题网页布局

    作为编码者,美工基础是偏弱的.我们可以参考一些成熟的网页PS教程,提高自身的设计能力.套用一句话,“熟读唐诗三百首,不会作诗也会吟”. 本系列的教程来源于网上的PS教程,都是国外的,全英文的.本人尝试 ...

  4. 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用 ...

  5. 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 ...

  6. 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( ...

  7. MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.5 Adding a raster layer

    MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.5 Adding a  raster layer 一.前言 MapServer不仅支持 ...

  8. MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example 1.4 Labeling the Map

    MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example 1.4 Labeling the Map 一.前言 MapServer拥有非常灵活的标签 ...

  9. MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.3 Displaying Classes in a Layer

    MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.3 Displaying Classes in a Layer 一.前言 关于第一节的 ...

随机推荐

  1. php实现简单算法1

    php实现简单算法1 <? //-------------------- // 基本数据结构算法 //-------------------- //二分查找(数组里查找某个元素) functio ...

  2. HDU 5371 Hotaru's problem Manacher+尺取法

    题意:给你一个序列,求最长的两段回文子串,要求他们共用中间的一半. 思路:利用Manacher求出p[i]表示的当前位置的最长回文串长度,然后把每一个长度大于等于2的回文串的左区间和右区间分别放到两个 ...

  3. Cisco路由器交换机配置命令详解

    1. 交换机支持的命令: 交换机基本状态:switch: :ROM状态, 路由器是rommon>hostname> :用户模式hostname# :特权模式hostname(config) ...

  4. 解决电信或网通的DNS劫持

    大家有没有碰到访问一些不存在域名或者网站时,浏览器本应显示一个网址不存在之类的信息,但是因为现在很多ISP做了DNS劫持将不存在的域名或网址重定向到ISP的广告页面,烦人的狠.其实tomato可以解决 ...

  5. C/C++(C++返回对象与应用区别,类成员的存储)

    返回对象与应用区别: 拷贝构造器发生的时机: 1.构造新对象 A a, A b = a; 2.传参或返回对象 对于普通变量来说,传引用效果不是很明显,对于类对象而言,传对象效果很高. 传引用等价于扩大 ...

  6. ajax的几个面试题

    一.什么是AJAX(请谈一下你对Ajax的认识)AJAX是“Asynchronous JavaScript and XML”的缩写.他是指一种创建交互式网页应用的网页开发技术.Ajax包含下列技术:基 ...

  7. Linux学习总结(6)——CenterOS7安装mysql5.5的方法

    首先centos7 已经不支持mysql,因为收费了你懂得,所以内部集成了mariadb,而安装mysql的话会和mariadb的文件冲突,所以需要先卸载掉mariadb,以下为卸载mariadb,安 ...

  8. CCF模拟题 相反数

    相反数 时间限制: 1.0s 内存限制: 256.0MB 问题描述 有 N 个非零且各不相同的整数.请你编一个程序求出它们中有多少对相反数(a 和 -a 为一对相反数).   输入格式 第一行包含一个 ...

  9. 洛谷 P2913 [USACO08OCT]车轮旋转Wheel Rotation

    P2913 [USACO08OCT]车轮旋转Wheel Rotation 题目描述 Farmer John has an old-time thresher (wheat harvester) tha ...

  10. Qt Installer Framework的学习(二)

    Qt Installer Framework的学习(二) Qt Installer Framework的一些操作能够使用最常见的Qt项目来表示,也就是说,书写pro文件,使用qmake执行之,除了能够 ...