How to use the d3-geo.geoTransform 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
// ----------------------------------------------------------------------
const context: 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; }
};

// ----------------------------------------------------------------------
// Projection Streams
// ----------------------------------------------------------------------

// geoTransform(...) ====================================================

const transformFunction: { stream: (s: d3Geo.GeoStream) => {} } = d3Geo.geoTransform({});

interface CustomTranformProto extends d3Geo.GeoTransformPrototype {
    a: number;
}

let customTransformProto: CustomTranformProto;

customTransformProto = {
    point(x, y) {
        return this.stream.point(x + this.a, -y);
    },
    a: 10
};

const t: { stream: (s: d3Geo.GeoStream) => (CustomTranformProto & d3Geo.GeoStream) } = d3Geo.geoTransform(customTransformProto);
github DefinitelyTyped / DefinitelyTyped / d3-geo / d3-geo-tests.ts View on Github external
const transformFunction: { stream: (s: d3Geo.GeoStream) => {} } = d3Geo.geoTransform({});

interface CustomTranformProto extends d3Geo.GeoTransformPrototype {
    a: number;
}

let customTransformProto: CustomTranformProto;

customTransformProto = {
    point(x, y) {
        return this.stream.point(x + this.a, -y);
    },
    a: 10
};

const t: { stream: (s: d3Geo.GeoStream) => (CustomTranformProto & d3Geo.GeoStream) } = d3Geo.geoTransform(customTransformProto);

// geoIdentity() ========================================================

let identityTransform: d3Geo.GeoIdentityTranform;

identityTransform = d3Geo.geoIdentity();

scale = identityTransform.scale();
identityTransform = identityTransform.scale(2);

translate = identityTransform.translate();
identityTransform = identityTransform.translate([10, 10]);

clipExtent = identityTransform.clipExtent();
identityTransform = identityTransform.clipExtent(null);
identityTransform = identityTransform.clipExtent([[0, 0], [100, 100]]);
github DefinitelyTyped / DefinitelyTyped / types / d3-geo / d3-geo-tests.ts View on Github external
// ----------------------------------------------------------------------
const context: 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; }
};

// ----------------------------------------------------------------------
// Projection Streams
// ----------------------------------------------------------------------

// geoTransform(...) ====================================================

const transformFunction: { stream(s: d3Geo.GeoStream): {} } = d3Geo.geoTransform({});

interface CustomTranformProto extends d3Geo.GeoTransformPrototype {
    a: number;
}

let customTransformProto: CustomTranformProto;

customTransformProto = {
    point(x, y) {
        return this.stream.point(x + this.a, -y);
    },
    a: 10
};

const t: { stream(s: d3Geo.GeoStream): CustomTranformProto & d3Geo.GeoStream } = d3Geo.geoTransform(customTransformProto);
github DefinitelyTyped / DefinitelyTyped / types / d3-geo / d3-geo-tests.ts View on Github external
const transformFunction: { stream(s: d3Geo.GeoStream): {} } = d3Geo.geoTransform({});

interface CustomTranformProto extends d3Geo.GeoTransformPrototype {
    a: number;
}

let customTransformProto: CustomTranformProto;

customTransformProto = {
    point(x, y) {
        return this.stream.point(x + this.a, -y);
    },
    a: 10
};

const t: { stream(s: d3Geo.GeoStream): CustomTranformProto & d3Geo.GeoStream } = d3Geo.geoTransform(customTransformProto);

// geoIdentity() ========================================================

let identityTransform: d3Geo.GeoIdentityTranform;

identityTransform = d3Geo.geoIdentity();

scale = identityTransform.scale();
identityTransform = identityTransform.scale(2);

translate = identityTransform.translate();
identityTransform = identityTransform.translate([10, 10]);

clipExtent = identityTransform.clipExtent();
identityTransform = identityTransform.clipExtent(null);
identityTransform = identityTransform.clipExtent([[0, 0], [100, 100]]);
github uber / react-map-gl / examples / additional-overlays / src / choropleth-overlay.js View on Github external
_redraw = ({width, height, ctx, isDragging, project, unproject}) => {
    ctx.clearRect(0, 0, width, height);

    function projectPoint(lon, lat) {
      const point = project([lon, lat]);
      /* eslint-disable no-invalid-this */
      this.stream.point(point[0], point[1]);
      /* eslint-enable no-invalid-this */
    }

    if (this.props.renderWhileDragging || !isDragging) {
      const transform = geoTransform({point: projectPoint});
      const path = geoPath()
        .projection(transform)
        .context(ctx);
      this._drawFeatures(ctx, path);
    }
  };
github openstreetmap / iD / modules / geo / raw_mercator.js View on Github external
if (!arguments.length) return clipExtent;
        clipExtent = _;
        return projection;
    };


    projection.transform = function(_) {
        if (!arguments.length) return d3_zoomIdentity.translate(x, y).scale(k);
        x = +_.x;
        y = +_.y;
        k = +_.k;
        return projection;
    };


    projection.stream = d3_geoTransform({
        point: function(x, y) {
            x = projection([x, y]);
            this.stream.point(x[0], x[1]);
        }
    }).stream;


    return projection;
}
github mapseed / platform / src / base / static / utils / geo.ts View on Github external
export const redraw = ({ project, ctx, featureCollection, width, height }) => {
  function projectPoint(this: GeoTransformWrapper, lon, lat) {
    const point = project([lon, lat]);
    this.stream.point(point[0], point[1]);
  }

  const transform = geoTransform({ point: projectPoint });
  const path = geoPath()
    .projection(transform)
    .context(ctx);

  ctx.clearRect(0, 0, width, height);

  const { features } = featureCollection;
  if (!features) {
    return;
  }

  for (const feature of features) {
    const geometry = feature.geometry;

    ctx.beginPath();
    geometry.type !== "Point" && ctx.setLineDash([2, 2]);
github developmentseed / dirty-reprojectors / index.js View on Github external
function flipY () {
  return d3.geoTransform({
    point: function (x, y) {
      this.stream.point(x, -y)
    }
  }).stream
}
github newsappsio / spam / src / zoomable-canvas-map.js View on Github external
constructor(parameters) {
    const simplify = geoTransform({
      point: function(x, y, z) {
        if (!z || z >= area) this.stream.point(x, y);
      }
    });

    this.map = new CanvasMap(parameters);
    this.area = 0;
    this.canvas = null;
    this.context = null;

    this.settings = this.map.settings;
    this.dataPath = geoPath().projection({
      stream: s => {
        if (this.settings.projection)
          return simplify.stream(this.settings.projection.stream(s));
        return simplify.stream(s);
github ideditor / id-sdk / packages / math / projection / built / projection.js View on Github external
Projection.prototype.getStream = function() {
    var thiz = this;
    return d3_geo_1
      .geoTransform({
        point: function(x, y) {
          var p = thiz.project([x, y]);
          this.stream.point(p[0], p[1]);
        }
      })
      .stream();
  };
  return Projection;