MCPcopy Index your code
hub / github.com/plotly/plotly.js / getProjection

Function getProjection

src/plots/geo/geo.js:710–768  ·  view source on GitHub ↗
(geoLayout)

Source from the content-addressed store, hash-verified

708//
709// This wrapper alleviates subsequent code of (many) annoying if-statements.
710function getProjection(geoLayout) {
711 var projLayout = geoLayout.projection;
712 var projType = projLayout.type;
713
714 var projName = constants.projNames[projType];
715 // uppercase the first letter and add geo to the start of method name
716 projName = 'geo' + Lib.titleCase(projName);
717 var projFn = geo[projName] || geoProjection[projName];
718 var projection = projFn();
719
720 var clipAngle =
721 geoLayout._isSatellite ? Math.acos(1 / projLayout.distance) * 180 / Math.PI :
722 geoLayout._isClipped ? constants.lonaxisSpan[projType] / 2 : null;
723
724 var methods = ['center', 'rotate', 'parallels', 'clipExtent'];
725 var dummyFn = function(_) { return _ ? projection : []; };
726
727 for(var i = 0; i < methods.length; i++) {
728 var m = methods[i];
729 if(typeof projection[m] !== 'function') {
730 projection[m] = dummyFn;
731 }
732 }
733
734 projection.isLonLatOverEdges = function(lonlat) {
735 if(projection(lonlat) === null) {
736 return true;
737 }
738
739 if(clipAngle) {
740 var r = projection.rotate();
741 var angle = geoDistance(lonlat, [-r[0], -r[1]]);
742 var maxAngle = clipAngle * Math.PI / 180;
743 return angle > maxAngle;
744 } else {
745 return false;
746 }
747 };
748
749 projection.getPath = function() {
750 return geoPath().projection(projection);
751 };
752
753 projection.getBounds = function(object) {
754 return projection.getPath().bounds(object);
755 };
756
757 projection.precision(constants.precision);
758
759 if(geoLayout._isSatellite) {
760 projection.tilt(projLayout.tilt).distance(projLayout.distance);
761 }
762
763 if(clipAngle) {
764 projection.clipAngle(clipAngle - constants.clipPad);
765 }
766
767 return projection;

Callers 1

geo.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…