How to use the d3-geo.geoPath function in d3-geo

To help you get started, we’ve selected a few d3-geo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / d3-geo / d3-geo-tests.ts View on Github external
// ----------------------------------------------------------------------
// GeoPath Generator
// ----------------------------------------------------------------------

const minimalRenderingContextMockUp: d3Geo.GeoContext = {
    beginPath: () => { return; },
    moveTo: (x: number, y: number) => { return; },
    lineTo: (x: number, y: number) => { return; },
    arc: (x, y, radius, startAngle, endAngle) => { return; },
    closePath: () => { return; }
};

// Create geoPath Generator =============================================

let geoPathCanvas: d3Geo.GeoPath;
geoPathCanvas = d3Geo.geoPath();
geoPathCanvas = d3Geo.geoPath(null);
geoPathCanvas = d3Geo.geoPath(null, null);
geoPathCanvas = d3Geo.geoPath(d3Geo.geoAzimuthalEqualArea());
geoPathCanvas = d3Geo.geoPath(d3Geo.geoAzimuthalEqualArea(), minimalRenderingContextMockUp);

let geoPathSVG: d3Geo.GeoPath>;
geoPathSVG = d3Geo.geoPath>();
geoPathSVG = d3Geo.geoPath>(d3Geo.geoAzimuthalEqualArea());
geoPathSVG = d3Geo.geoPath>(d3Geo.geoAzimuthalEqualArea(), null);
// Configure geoPath Generator ==========================================

// projection(...) ------------------------------------------------------

geoPathCanvas = geoPathCanvas.projection(azimuthalEqualArea);
const geoPathProjectionMinimal: d3Geo.GeoStreamWrapper = geoPathCanvas.projection();
const geoPathProjectionUnion: d3Geo.GeoProjection | d3Geo.GeoConicProjection | d3Geo.GeoStreamWrapper = geoPathCanvas.projection();
github openstreetmap / iD / modules / svg / data.js View on Github external
function drawLabels(selection, textClass, data) {
            var labelPath = d3_geoPath(projection);
            var labelData = data.filter(function(d) {
                return _showLabels && d.properties && (d.properties.desc || d.properties.name);
            });

            var labels = selection.selectAll('text.' + textClass)
                .data(labelData, featureKey);

            // exit
            labels.exit()
                .remove();

            // enter/update
            labels = labels.enter()
                .append('text')
                .attr('class', function(d) { return textClass + ' ' + featureClasses(d); })
                .merge(labels)
github GlobalFishingWatch / map-client / app / src / miniglobe / components / MiniGlobe.jsx View on Github external
viewBox={`${viewBoxX} ${viewBoxY} ${viewBoxWidth} ${viewBoxHeight}`}
            className={MiniGlobeStyles.globeSvg}
          >
            
          
        
        {/* <div>
          <span>
            Zone
          </span>
        </div> */}
      
    );
  }
}
github yaph / d3-geomap / src / js / geomap.js View on Github external
.attr('class', 'background')
            .attr('width', self.properties.width)
            .attr('height', self.properties.height)
            .on('click', self.clicked.bind(self));

        // Set map projection and path.
        let proj = self.properties.projection()
            .scale(self.properties.scale)
            .translate(self.properties.translate)
            .precision(.1);

        // Not every projection supports rotation, e. g. albersUsa does not.
        if (proj.hasOwnProperty('rotate') && self.properties.rotate)
            proj.rotate(self.properties.rotate);

        self.path = geoPath().projection(proj);

        const drawGeoData = geo => {
            self.geo = geo;
            self.svg.append('g').attr('class', 'units zoom')
                .selectAll('path')
                .data(topoFeature(geo, geo.objects[self.properties.units]).features)
                .enter().append('path')
                    .attr('class', d => 'unit ' + this.properties.unitPrefix + self.unitName(d.properties))
                    .attr('d', self.path)
                    .on('click', self.clicked.bind(self))
                    .append('title')
                        .text(self.properties.unitTitle);
            self.update();
        };

        Promise.resolve()
github antvis / data-set / src / connector / geojson.js View on Github external
const getPointAtLength = require('point-at-length');
const cloneDeep = require('@antv/util/lib/clone');
const {
  geoPath
} = require('d3-geo');
const {
  GEO,
  registerConnector
} = require('../data-set');

const geoPathGenerator = geoPath();

function GeoJSONConnector(data, options, dataView) {
  dataView.dataType = GEO;
  const features = cloneDeep(data.features);

  // pre-process
  features.forEach(feature => {
    feature.name = feature.properties.name;
    feature.longitude = [];
    feature.latitude = [];
    const pathData = feature.pathData = geoPathGenerator(feature);
    const points = getPointAtLength(pathData);
    points._path.forEach(point => {
      feature.longitude.push(point[1]);
      feature.latitude.push(point[2]);
    });
github uber / react-vis / src / plot / series / contour-series.js View on Github external
);
    }

    const x = this._getAttributeFunctor('x');
    const y = this._getAttributeFunctor('y');

    const contouredData = contourDensity()
      .x(d =&gt; x(d))
      .y(d =&gt; y(d))
      .size([innerWidth, innerHeight])
      .bandwidth(bandwidth)(data);

    const geo = geoPath();
    const {min, max} = getDomain(contouredData);
    const colorScale = scaleLinear()
      .domain([min, max])
      .range(colorRange || CONTINUOUS_COLOR_RANGE);
    return (
github PitchInteractiveInc / tilegrams / source / graphics / MapGraphic.js View on Github external
_precomputeBounds() {
    const pathProjection = geoPath()
    this._generalBounds = [[Infinity, Infinity], [-Infinity, -Infinity]]
    this._projectedStates = this._stateFeatures.features.map(feature => {
      const hasMultiplePaths = feature.geometry.type === 'MultiPolygon'
      const bounds = pathProjection.bounds(feature)
      updateBounds(this._generalBounds, bounds)
      const paths = feature.geometry.coordinates
        .filter(path => area(hasMultiplePaths ? path[0] : path) > MIN_PATH_AREA)
        .map(path => [hasMultiplePaths ? path[0] : path])
      return {bounds, paths}
    })
  }
github amcharts / amcharts4 / src / .internal / charts / map / projections / Projection.ts View on Github external
public set d3Projection(projection: d3geo.GeoProjection) {
		this._d3Projection = projection;
		projection.precision(0.1);
		this._d3Path = d3geo.geoPath().projection(projection);

		if (this.chart) {
			this.chart.invalidateProjection();
		}
	}
github newamericafoundation / teddy / packages / maps / src / Projection / index.js View on Github external
...restProps
    } = this.props;

    const currProjection = projectionMapping[projection]();

    if (clipAngle) currProjection.clipAngle(clipAngle);
    if (clipExtent) currProjection.clipExtent(clipExtent);
    if (scale) currProjection.scale(scale);
    if (translate) currProjection.translate(translate);
    if (center) currProjection.center(center);
    if (rotate) currProjection.rotate(rotate);
    if (precision) currProjection.rotate(precision);
    if (fitExtent) currProjection.fitExtent(...fitExtent);
    if (fitSize) currProjection.fitSize(...fitSize);

    const path = geoPath().projection(currProjection);

    const features = data.map((feature, i) =&gt; {
      return {
        feature,
        type: projection,
        projection: currProjection,
        index: i,
        centroid: path.centroid(feature),
        path: path(feature)
      };
    });

    if (children) return children({ path, features });

    return (