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