From f5b5937a5b508e522885ac9e9c2e0d0a159fe552 Mon Sep 17 00:00:00 2001 From: Matt Hampel Date: Mon, 29 Aug 2022 21:26:36 -0400 Subject: [PATCH 1/5] Add a background image --- static/images/stripe_ffb4d4.png | Bin 0 -> 239 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 static/images/stripe_ffb4d4.png diff --git a/static/images/stripe_ffb4d4.png b/static/images/stripe_ffb4d4.png new file mode 100644 index 0000000000000000000000000000000000000000..bdf24c045891ca4fd32c223a8bc7c7c58003c50e GIT binary patch literal 239 zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1SFZ~=vx7)ZJsWUArY-dubt*?br4|+sCgUF z_4b$5#j0adJKfyh^QZXx-7wrz>1c6TV%o2Z3;bLQ3Zr-rimsB^3z}On_f?~J zsBz5NTM12B4VJH@eS+l^m)&YVnZ^EWb@>LDy$7_u@^D{eUK3g#v5rY1D!WQ_<@u=r zhP{Cn%awLmtZjS1b(LRyrQZ&}uLqW{l3W*-Yv5>lK;|p&vX%V?!EX literal 0 HcmV?d00001 From a630d9267d804e874469f25edb7a29e871936a33 Mon Sep 17 00:00:00 2001 From: Matt Hampel Date: Mon, 29 Aug 2022 22:54:25 -0400 Subject: [PATCH 2/5] Try to unbork images --- lib/cartoRenderer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cartoRenderer.js b/lib/cartoRenderer.js index e18677d..cda7569 100644 --- a/lib/cartoRenderer.js +++ b/lib/cartoRenderer.js @@ -812,7 +812,7 @@ var cartoImageRenderer = function (ctx, scale, layers, styles, zoom, minX, maxX, // TODO: moving toString() up gives us performance improvements // But breaks background images. Gotta fix this sometime. - // var rawValue = instanceStyle[key], + var rawValue = instanceStyle[key]; // value = rawValue.toString(); var value = instanceStyle[key]; From 6c7c249659bade54eadcd135da0e991ef86445d9 Mon Sep 17 00:00:00 2001 From: Matt Hampel Date: Mon, 29 Aug 2022 23:04:42 -0400 Subject: [PATCH 3/5] Try again --- lib/cartoRenderer.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/cartoRenderer.js b/lib/cartoRenderer.js index cda7569..dd16d8f 100644 --- a/lib/cartoRenderer.js +++ b/lib/cartoRenderer.js @@ -812,7 +812,7 @@ var cartoImageRenderer = function (ctx, scale, layers, styles, zoom, minX, maxX, // TODO: moving toString() up gives us performance improvements // But breaks background images. Gotta fix this sometime. - var rawValue = instanceStyle[key]; + // var rawValue = instanceStyle[key]; // value = rawValue.toString(); var value = instanceStyle[key]; @@ -821,10 +821,9 @@ var cartoImageRenderer = function (ctx, scale, layers, styles, zoom, minX, maxX, shouldFill = true; } else if (key === "background-image" || key === "polygon-pattern-file") { - if (rawValue) { - ctx.fillStyle = ctx.createPattern(rawValue, "repeat"); - shouldFill = true; - } + console.log("Creating pattern with", value) + ctx.fillStyle = ctx.createPattern(value, "repeat"); + shouldFill = true; } else if (key === "line-width") { ctx.lineWidth = value; @@ -857,10 +856,8 @@ var cartoImageRenderer = function (ctx, scale, layers, styles, zoom, minX, maxX, // handled at fill time below } else if (key === "line-pattern-file") { - if (rawValue) { - ctx.strokeStyle = ctx.createPattern(rawValue, "repeat"); - shouldStroke = true; - } + ctx.strokeStyle = ctx.createPattern(value, "repeat"); + shouldStroke = true; } else if (key === "marker-type") { shouldMark = true; From feab89c3f6aa89d3dc9fe210ca141f9efa983fd4 Mon Sep 17 00:00:00 2001 From: Matt Hampel Date: Mon, 29 Aug 2022 23:15:00 -0400 Subject: [PATCH 4/5] Ok last one for today --- lib/cartoRenderer.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/cartoRenderer.js b/lib/cartoRenderer.js index dd16d8f..d1e0438 100644 --- a/lib/cartoRenderer.js +++ b/lib/cartoRenderer.js @@ -821,7 +821,17 @@ var cartoImageRenderer = function (ctx, scale, layers, styles, zoom, minX, maxX, shouldFill = true; } else if (key === "background-image" || key === "polygon-pattern-file") { + + if (!(value instanceof Canvas.Image)) { + var content = value.toString(); + var img = new Canvas.Image(); + var imagePath = path.normalize(__dirname + "/../static/images/" + content); + img.src = fs.readFileSync(imagePath); + value = img; + } + console.log("Creating pattern with", value) + ctx.fillStyle = ctx.createPattern(value, "repeat"); shouldFill = true; } From 18e0ecf2f03444b3eed2e1f8d0cfd19fba1be1e2 Mon Sep 17 00:00:00 2001 From: Matt Hampel Date: Mon, 29 Aug 2022 23:20:13 -0400 Subject: [PATCH 5/5] Whattabout now --- lib/cartoRenderer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/cartoRenderer.js b/lib/cartoRenderer.js index d1e0438..d1c8393 100644 --- a/lib/cartoRenderer.js +++ b/lib/cartoRenderer.js @@ -1,5 +1,5 @@ 'use strict'; -const { createCanvas } = require('canvas') +const { Canvas, createCanvas } = require('canvas') var carto = require("carto"); var UTFGrid = require('./utfgrid'); var fs = require('fs'); @@ -829,7 +829,7 @@ var cartoImageRenderer = function (ctx, scale, layers, styles, zoom, minX, maxX, img.src = fs.readFileSync(imagePath); value = img; } - + console.log("Creating pattern with", value) ctx.fillStyle = ctx.createPattern(value, "repeat");