11
11
/* global PlotlyGeoAssets:false */
12
12
13
13
var d3 = require ( 'd3' ) ;
14
+ var geo = require ( 'd3-geo' ) ;
15
+ var geoPath = require ( 'd3-geo' ) . geoPath ;
16
+ var geoDistance = require ( 'd3-geo' ) . geoDistance ;
17
+ var geoProjection = require ( 'd3-geo-projection' ) ;
14
18
15
19
var Registry = require ( '../../registry' ) ;
16
20
var Lib = require ( '../../lib' ) ;
@@ -32,8 +36,6 @@ var geoUtils = require('../../lib/geo_location_utils');
32
36
var topojsonUtils = require ( '../../lib/topojson_utils' ) ;
33
37
var topojsonFeature = require ( 'topojson-client' ) . feature ;
34
38
35
- require ( './projections' ) ( d3 ) ;
36
-
37
39
function Geo ( opts ) {
38
40
this . id = opts . id ;
39
41
this . graphDiv = opts . graphDiv ;
@@ -655,7 +657,7 @@ proto.render = function() {
655
657
}
656
658
} ;
657
659
658
- // Helper that wraps d3.geo[ /* projection name /*]() which:
660
+ // Helper that wraps d3[geo + /* Projection name /*]() which:
659
661
//
660
662
// - adds 'fitExtent' (available in d3 v4)
661
663
// - adds 'getPath', 'getBounds' convenience methods
@@ -670,7 +672,11 @@ function getProjection(geoLayout) {
670
672
var projLayout = geoLayout . projection ;
671
673
var projType = projLayout . type ;
672
674
673
- var projection = d3 . geo [ constants . projNames [ projType ] ] ( ) ;
675
+ var projName = constants . projNames [ projType ] ;
676
+ // uppercase the first letter and add geo to the start of method name
677
+ projName = 'geo' + projName . charAt ( 0 ) . toUpperCase ( ) + projName . slice ( 1 ) ;
678
+ var projFn = geo [ projName ] || geoProjection [ projName ] ;
679
+ var projection = projFn ( ) ;
674
680
675
681
var clipAngle = geoLayout . _isClipped ?
676
682
constants . lonaxisSpan [ projType ] / 2 :
@@ -693,7 +699,7 @@ function getProjection(geoLayout) {
693
699
694
700
if ( clipAngle ) {
695
701
var r = projection . rotate ( ) ;
696
- var angle = d3 . geo . distance ( lonlat , [ - r [ 0 ] , - r [ 1 ] ] ) ;
702
+ var angle = geoDistance ( lonlat , [ - r [ 0 ] , - r [ 1 ] ] ) ;
697
703
var maxAngle = clipAngle * Math . PI / 180 ;
698
704
return angle > maxAngle ;
699
705
} else {
@@ -702,7 +708,7 @@ function getProjection(geoLayout) {
702
708
} ;
703
709
704
710
projection . getPath = function ( ) {
705
- return d3 . geo . path ( ) . projection ( projection ) ;
711
+ return geoPath ( ) . projection ( projection ) ;
706
712
} ;
707
713
708
714
projection . getBounds = function ( object ) {
0 commit comments