-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GLJS-1144] Fixed user-rendered icons (internal-2091)
- Loading branch information
Showing
7 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const size = 200; | ||
|
||
export const image = { | ||
width: size, | ||
height: size, | ||
data: new Uint8Array(size * size * 4), | ||
|
||
onAdd: function () { | ||
const canvas = document.createElement('canvas'); | ||
canvas.width = this.width; | ||
canvas.height = this.height; | ||
this.context = canvas.getContext('2d'); | ||
}, | ||
|
||
render: function () { | ||
const radius = (size / 2) * 0.3; | ||
const outerRadius = (size / 2) * 0.7 + radius; | ||
const context = this.context; | ||
|
||
// Draw the outer circle. | ||
context.clearRect(0, 0, this.width, this.height); | ||
context.beginPath(); | ||
context.arc( | ||
this.width / 2, | ||
this.height / 2, | ||
outerRadius, | ||
0, | ||
Math.PI * 2 | ||
); | ||
context.fillStyle = `rgba(255, 200, 200, 1)`; | ||
context.fill(); | ||
|
||
// Draw the inner circle. | ||
context.beginPath(); | ||
context.arc( | ||
this.width / 2, | ||
this.height / 2, | ||
radius, | ||
0, | ||
Math.PI * 2 | ||
); | ||
context.fillStyle = 'rgba(255, 100, 100, 1)'; | ||
context.strokeStyle = 'white'; | ||
context.lineWidth = 2 + 4; | ||
context.fill(); | ||
context.stroke(); | ||
|
||
// Update this image's data with data from the canvas. | ||
this.data = context.getImageData( | ||
0, | ||
0, | ||
this.width, | ||
this.height | ||
).data; | ||
|
||
// Return `true` to let the map know that the image was updated. | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions
49
test/integration/render-tests/image/render-callback/style.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"version": 8, | ||
"metadata": { | ||
"test": { | ||
"width": 200, | ||
"height": 200, | ||
"operations": [ | ||
[ | ||
"addImage", | ||
"dot", | ||
"./image/dot.js" | ||
], | ||
[ | ||
"wait" | ||
] | ||
] | ||
} | ||
}, | ||
"sources": { | ||
"dot-point": { | ||
"type": "geojson", | ||
"data": { | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
0, | ||
0 | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"layers": [ | ||
{ | ||
"id": "layer-with-dot", | ||
"type": "symbol", | ||
"source": "dot-point", | ||
"layout": { | ||
"icon-image": "dot" | ||
} | ||
} | ||
] | ||
} |