[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 一.前言 关于第一节的 ...
随机推荐
- NetFlow是一种数据交换方式,提供网络流量的会话级视图,记录下每个TCP/IP事务的信息
NetFlow是一种数据交换方式,提供网络流量的会话级视图,记录下每个TCP/IP事务的信息.也许它不能象tcpdump那样提供网络流量的完整记录,但是当汇集起来时,它更加易于管理和易读.Netflo ...
- HIToj--1076--Ordered Fractions(水题)
Ordered Fractions Source : Unknown Time limit : 3 sec Memory limit : 32 M Submitted : 1510, Ac ...
- Spring MVC 返回视图时添加的模型数据------POJO
POJO(Plain Old Java Objects)简单的Java对象,实际就是普通JavaBeans,是为了避免和EJB混淆所创造的简称. 使用POJO名称是为了避免和 EJB混淆起来, 而且简 ...
- node.js 中 events emitter 的实现(发布、订阅模式)
const EventEmitter = require('events'); const myEmitter = new EventEmitter(); myEmitter.on('event', ...
- UVC和V4L2的关系(转载)
UVC是一种usb视频设备驱动.用来支持usb视频设备,凡是usb接口的摄像头都能够支持 V4L2是Linux下的视频采集框架.用来统一接口,向应用层提供API UVC: USB video clas ...
- Windows IP 设置脚本
前言: 有时候,总要在不同地方工作,就会总要切换 IP,内网比较严重,内网大多数都是静态 IP 所以呢,老是手动去设置 IP.子网掩码.网关等甚是繁琐,同时还得记住 IP,所以呢,用脚本来记录 IP, ...
- 开启mysql远程服务
1.在开始里输入远程,选择允许从这台机器访问 2.选择第二个开启 3. 打开cmd, 进入mysql中更改mysql数据库下的user表,中的root用户的Host 为 ‘%’use mysql:up ...
- php获取csv数据无乱码
<?php //获取csv数据 function csvencode($file){ if(!is_file($file['tmp_name'])){ ...
- 一招制胜---详解分布式系统里session同步
一招制胜---详解分布式系统里session同步 几周前,有个盆友问老王,说现在有多台服务器,怎么样来解决这些服务器间的session同步问题?老王一下就来精神了,因为在n年以前,老王还在学校和几个同 ...
- [Python] Manage Dependencies with Python Virtual Environments
Virtual Environments ensure that dependencies from one Python application don’t overwrite the depend ...