Merge pull request #7550 from fredj/d3_example_v4
Update examples to d3.js v4
This commit is contained in:
@@ -6,7 +6,7 @@ docs: >
|
|||||||
<p>The example loads TopoJSON geometries and uses d3 (<code>d3.geo.path</code>) to render these geometries to a canvas element that is then used as the image of an OpenLayers image layer.</p>
|
<p>The example loads TopoJSON geometries and uses d3 (<code>d3.geo.path</code>) to render these geometries to a canvas element that is then used as the image of an OpenLayers image layer.</p>
|
||||||
tags: "d3"
|
tags: "d3"
|
||||||
resources:
|
resources:
|
||||||
- https://d3js.org/d3.v3.min.js
|
- https://unpkg.com/d3@4.12.0/build/d3.js
|
||||||
- https://d3js.org/topojson.v1.min.js
|
- https://unpkg.com/topojson@3.0.2/dist/topojson.js
|
||||||
---
|
---
|
||||||
<div id="map" class="map"></div>
|
<div id="map" class="map"></div>
|
||||||
|
|||||||
11
examples/d3.js
vendored
11
examples/d3.js
vendored
@@ -40,8 +40,7 @@ d3.json('data/topojson/us.json', function(error, us) {
|
|||||||
* @param {ol.proj.Projection} projection Projection.
|
* @param {ol.proj.Projection} projection Projection.
|
||||||
* @return {HTMLCanvasElement} A canvas element.
|
* @return {HTMLCanvasElement} A canvas element.
|
||||||
*/
|
*/
|
||||||
var canvasFunction = function(extent, resolution, pixelRatio,
|
var canvasFunction = function(extent, resolution, pixelRatio, size, projection) {
|
||||||
size, projection) {
|
|
||||||
var canvasWidth = size[0];
|
var canvasWidth = size[0];
|
||||||
var canvasHeight = size[1];
|
var canvasHeight = size[1];
|
||||||
|
|
||||||
@@ -50,14 +49,14 @@ d3.json('data/topojson/us.json', function(error, us) {
|
|||||||
|
|
||||||
var context = canvas.node().getContext('2d');
|
var context = canvas.node().getContext('2d');
|
||||||
|
|
||||||
var d3Projection = d3.geo.mercator().scale(1).translate([0, 0]);
|
var d3Projection = d3.geoMercator().scale(1).translate([0, 0]);
|
||||||
var d3Path = d3.geo.path().projection(d3Projection);
|
var d3Path = d3.geoPath().projection(d3Projection);
|
||||||
|
|
||||||
var pixelBounds = d3Path.bounds(features);
|
var pixelBounds = d3Path.bounds(features);
|
||||||
var pixelBoundsWidth = pixelBounds[1][0] - pixelBounds[0][0];
|
var pixelBoundsWidth = pixelBounds[1][0] - pixelBounds[0][0];
|
||||||
var pixelBoundsHeight = pixelBounds[1][1] - pixelBounds[0][1];
|
var pixelBoundsHeight = pixelBounds[1][1] - pixelBounds[0][1];
|
||||||
|
|
||||||
var geoBounds = d3.geo.bounds(features);
|
var geoBounds = d3.geoBounds(features);
|
||||||
var geoBoundsLeftBottom = ol.proj.transform(
|
var geoBoundsLeftBottom = ol.proj.transform(
|
||||||
geoBounds[0], 'EPSG:4326', projection);
|
geoBounds[0], 'EPSG:4326', projection);
|
||||||
var geoBoundsRightTop = ol.proj.transform(
|
var geoBoundsRightTop = ol.proj.transform(
|
||||||
@@ -81,7 +80,7 @@ d3.json('data/topojson/us.json', function(error, us) {
|
|||||||
d3Path(features);
|
d3Path(features);
|
||||||
context.stroke();
|
context.stroke();
|
||||||
|
|
||||||
return canvas[0][0];
|
return canvas.node();
|
||||||
};
|
};
|
||||||
|
|
||||||
var layer = new ol.layer.Image({
|
var layer = new ol.layer.Image({
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ docs: >
|
|||||||
</p>
|
</p>
|
||||||
tags: "raster, pixel"
|
tags: "raster, pixel"
|
||||||
resources:
|
resources:
|
||||||
- https://d3js.org/d3.v3.min.js
|
- https://unpkg.com/d3@4.12.0/build/d3.js
|
||||||
cloak:
|
cloak:
|
||||||
As1HiMj1PvLPlqc_gtM7AqZfBL8ZL3VrjaS3zIb22Uvb9WKhuJObROC-qUpa81U5: Your Bing Maps Key from http://www.bingmapsportal.com/ here
|
As1HiMj1PvLPlqc_gtM7AqZfBL8ZL3VrjaS3zIb22Uvb9WKhuJObROC-qUpa81U5: Your Bing Maps Key from http://www.bingmapsportal.com/ here
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -144,13 +144,13 @@ var chart = d3.select('#plot').append('svg')
|
|||||||
.attr('width', barWidth * bins)
|
.attr('width', barWidth * bins)
|
||||||
.attr('height', plotHeight);
|
.attr('height', plotHeight);
|
||||||
|
|
||||||
var chartRect = chart[0][0].getBoundingClientRect();
|
var chartRect = chart.node().getBoundingClientRect();
|
||||||
|
|
||||||
var tip = d3.select(document.body).append('div')
|
var tip = d3.select(document.body).append('div')
|
||||||
.attr('class', 'tip');
|
.attr('class', 'tip');
|
||||||
|
|
||||||
function plot(resolution, counts, threshold) {
|
function plot(resolution, counts, threshold) {
|
||||||
var yScale = d3.scale.linear()
|
var yScale = d3.scaleLinear()
|
||||||
.domain([0, d3.max(counts.values)])
|
.domain([0, d3.max(counts.values)])
|
||||||
.range([0, plotHeight]);
|
.range([0, plotHeight]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user