Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// ----------------------------------------------------------------------
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);
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]]);
// ----------------------------------------------------------------------
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);
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]]);
_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);
}
};
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;
}
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]);
function flipY () {
return d3.geoTransform({
point: function (x, y) {
this.stream.point(x, -y)
}
}).stream
}
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);
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;