@@ -437,46 +437,56 @@ export abstract class RendererBase {
437437 * @param name - The unique name of the pattern
438438 * @param canvas - The container into which to add the pattern
439439 */
440- protected loadPattern ( name : string , canvas ?: Svg ) : void {
440+ protected loadPattern ( name : string , opts : { canvas ?: Svg , fg ?: string , bg ?: string } = { } ) : void {
441+ let canvas : Svg | undefined = this . rootSvg ;
442+ if ( opts . canvas !== undefined ) {
443+ canvas = opts . canvas ;
444+ }
441445 if ( canvas === undefined ) {
442- if ( this . rootSvg === undefined ) {
443- throw new Error ( "Object in an invalid state!" ) ;
444- }
445- canvas = this . rootSvg ;
446+ throw new Error ( "Object in an invalid state." ) ;
447+ }
448+
449+ let fg = this . options . colourContext . strokes ;
450+ if ( opts . fg !== undefined ) {
451+ fg = opts . fg ;
446452 }
453+ let bg = this . options . colourContext . background ;
454+ if ( opts . bg !== undefined ) {
455+ bg = opts . bg ;
456+ }
457+
447458 // Keep in alphabetical order.
448459 // If you change any `id`s, you need to change them in the constructor, too.
449-
450460 switch ( name ) {
451461 case "chevrons" :
452- canvas . defs ( ) . svg ( " <pattern id=' chevrons' patternUnits=' userSpaceOnUse' width='30' height='15' viewbox=' 0 0 60 30' ><svg xmlns=' http://www.w3.org/2000/svg' xmlns:xlink=' http://www.w3.org/1999/xlink' width='60' height='30' ><defs><rect id='_r' width='30' height='15' fill='#fff' stroke-width=' 2.5' stroke='#000' /><g id='_p' ><use xlink:href=' #_r' /><use y='15' xlink:href=' #_r' /><use y='30' xlink:href=' #_r' /><use y='45' xlink:href=' #_r' /></g></defs><use xlink:href=' #_p' transform=' translate(0 -25) skewY(40)' /><use xlink:href=' #_p' transform=' translate(30 0) skewY(-40)' /></svg></pattern>" ) ;
462+ canvas . defs ( ) . svg ( ` <pattern id=" chevrons" patternUnits=" userSpaceOnUse" width="30" height="15" viewbox=" 0 0 60 30" ><svg xmlns=" http://www.w3.org/2000/svg" xmlns:xlink=" http://www.w3.org/1999/xlink" width="60" height="30" ><defs><rect id="_r" width="30" height="15" fill=" ${ bg } " stroke-width=" 2.5" stroke=" ${ fg } " /><g id="_p" ><use xlink:href=" #_r" /><use y="15" xlink:href=" #_r" /><use y="30" xlink:href=" #_r" /><use y="45" xlink:href=" #_r" /></g></defs><use xlink:href=" #_p" transform=" translate(0 -25) skewY(40)" /><use xlink:href=" #_p" transform=" translate(30 0) skewY(-40)" /></svg></pattern>` ) ;
453463 break ;
454464 case "cross" :
455- canvas . defs ( ) . svg ( " <pattern id=' cross' patternUnits=' userSpaceOnUse' width='8' height='8' ><svg xmlns=' http://www.w3.org/2000/svg' width='8' height='8' ><rect width='8' height='8' fill='#fff' /><path d=' M0 0L8 8ZM8 0L0 8Z' stroke-width=' 0.5' stroke='#000' /></svg></pattern>" ) ;
465+ canvas . defs ( ) . svg ( ` <pattern id=" cross" patternUnits=" userSpaceOnUse" width="8" height="8" ><svg xmlns=" http://www.w3.org/2000/svg" width="8" height="8" ><rect width="8" height="8" fill=" ${ bg } " /><path d=" M0 0L8 8ZM8 0L0 8Z" stroke-width=" 0.5" stroke=" ${ fg } " /></svg></pattern>` ) ;
456466 break ;
457467 case "dots" :
458- canvas . defs ( ) . svg ( " <pattern id=' dots' patternUnits=' userSpaceOnUse' width='10' height='10' ><svg xmlns=' http://www.w3.org/2000/svg' width='10' height='10' ><rect width='10' height='10' fill='#fff' /><circle cx=' 2.5' cy=' 2.5' r=' 2.5' fill='#000' /></svg></pattern>" ) ;
468+ canvas . defs ( ) . svg ( ` <pattern id=" dots" patternUnits=" userSpaceOnUse" width="10" height="10" ><svg xmlns=" http://www.w3.org/2000/svg" width="10" height="10" ><rect width="10" height="10" fill=" ${ bg } " /><circle cx=" 2.5" cy=" 2.5" r=" 2.5" fill=" ${ fg } " /></svg></pattern>` ) ;
459469 break ;
460470 case "honeycomb" :
461- canvas . defs ( ) . svg ( " <pattern id=' honeycomb' patternUnits=' userSpaceOnUse' width=' 22.4' height='40' viewbox=' 0 0 56 100' ><svg xmlns=' http://www.w3.org/2000/svg' width='56' height=' 100' ><rect width='56' height=' 100' fill='#fff' /><path d=' M28 66L0 50L0 16L28 0L56 16L56 50L28 66L28 100' fill=' none' stroke='#000' stroke-width='2' /><path d=' M28 0L28 34L0 50L0 84L28 100L56 84L56 50L28 34' fill=' none' stroke='#000' stroke-width='2' /></svg></pattern>" ) ;
471+ canvas . defs ( ) . svg ( ` <pattern id=" honeycomb" patternUnits=" userSpaceOnUse" width=" 22.4" height="40" viewbox=" 0 0 56 100" ><svg xmlns=" http://www.w3.org/2000/svg" width="56" height=" 100" ><rect width="56" height=" 100" fill=" ${ bg } " /><path d=" M28 66L0 50L0 16L28 0L56 16L56 50L28 66L28 100" fill=" none" stroke=" ${ fg } " stroke-width="2" /><path d=" M28 0L28 34L0 50L0 84L28 100L56 84L56 50L28 34" fill=" none" stroke=" ${ fg } " stroke-width="2" /></svg></pattern>` ) ;
462472 break ;
463473 case "houndstooth" :
464- canvas . defs ( ) . svg ( " <pattern id=' houndstooth' patternUnits=' userSpaceOnUse' width='24' height='24' viewbox=' 0 0 24 24' ><svg width='24' height='24' viewBox=' 0 0 24 24' xmlns=' http://www.w3.org/2000/svg' ><title>houndstooth</title><g fill='#000' fill-opacity='1' fill-rule=' evenodd' ><path d=' M0 18h6l6-6v6h6l-6 6H0M24 18v6h-6M24 0l-6 6h-6l6-6M12 0v6L0 18v-6l6-6H0V0' /></g></svg></pattern>" ) ;
474+ canvas . defs ( ) . svg ( ` <pattern id=" houndstooth" patternUnits=" userSpaceOnUse" width="24" height="24" viewbox=" 0 0 24 24" ><svg width="24" height="24" viewBox=" 0 0 24 24" xmlns=" http://www.w3.org/2000/svg" ><title>houndstooth</title><g fill=" ${ fg } " fill-opacity="1" fill-rule=" evenodd" ><path d=" M0 18h6l6-6v6h6l-6 6H0M24 18v6h-6M24 0l-6 6h-6l6-6M12 0v6L0 18v-6l6-6H0V0" /></g></svg></pattern>` ) ;
465475 break ;
466476 case "microbial" :
467- canvas . defs ( ) . svg ( " <pattern id=' microbial' patternUnits=' userSpaceOnUse' width='20' height=20><svg xmlns=' http://www.w3.org/2000/svg' width='20' height='20' ><rect width='40' height='40' fill='#fff' /><circle r=' 9.2' stroke-width='1' stroke='#000' fill=' none' /><circle cy=' 18.4' r=' 9.2' stroke-width=' 1px' stroke='#000' fill=' none' /><circle cx=' 18.4' cy=' 18.4' r=' 9.2' stroke-width='1' stroke='#000' fill=' none' /></svg></pattern>" ) ;
477+ canvas . defs ( ) . svg ( ` <pattern id=" microbial" patternUnits=" userSpaceOnUse" width="20" height=20><svg xmlns=" http://www.w3.org/2000/svg" width="20" height="20" ><rect width="40" height="40" fill=" ${ bg } " /><circle r=" 9.2" stroke-width="1" stroke=" ${ fg } " fill=" none" /><circle cy=" 18.4" r=" 9.2" stroke-width=" 1px" stroke=" ${ fg } " fill=" none" /><circle cx=" 18.4" cy=" 18.4" r=" 9.2" stroke-width="1" stroke=" ${ fg } " fill=" none" /></svg></pattern>` ) ;
468478 break ;
469479 case "slant" :
470- canvas . defs ( ) . svg ( " <pattern id=' slant' patternUnits=' userSpaceOnUse' width='10' height='10' ><svg xmlns=' http://www.w3.org/2000/svg' width='10' height='10' ><rect width='10' height='10' fill='#fff' /><path d=' M-1,1 l2,-2 M0,10 l10,-10 M9,11 l2,-2' stroke='#000' stroke-width='1' /></svg></pattern>" ) ;
480+ canvas . defs ( ) . svg ( ` <pattern id=" slant" patternUnits=" userSpaceOnUse" width="10" height="10" ><svg xmlns=" http://www.w3.org/2000/svg" width="10" height="10" ><rect width="10" height="10" fill=" ${ bg } " /><path d=" M-1,1 l2,-2 M0,10 l10,-10 M9,11 l2,-2" stroke=" ${ fg } " stroke-width="1" /></svg></pattern>` ) ;
471481 break ;
472482 case "starsWhite" :
473- canvas . defs ( ) . svg ( " <pattern id=' starsWhite' patternUnits=' userSpaceOnUse' width='40' height='40' viewbox=' 0 0 80 80' ><svg xmlns=' http://www.w3.org/2000/svg' width='80' height='80' ><rect width='80' height='80' fill='#fff' /><circle cx='40' cy='40' r='40' fill='#000' /><path d=' M0 40 A40 40 45 0 0 40 0 A40 40 315 0 0 80 40 A40 40 45 0 0 40 80 A40 40 270 0 0 0 40Z' fill='#fff' /></svg></pattern>" ) ;
483+ canvas . defs ( ) . svg ( ` <pattern id=" starsWhite" patternUnits=" userSpaceOnUse" width="40" height="40" viewbox=" 0 0 80 80" ><svg xmlns=" http://www.w3.org/2000/svg" width="80" height="80" ><rect width="80" height="80" fill=" ${ bg } " /><circle cx="40" cy="40" r="40" fill=" ${ fg } " /><path d=" M0 40 A40 40 45 0 0 40 0 A40 40 315 0 0 80 40 A40 40 45 0 0 40 80 A40 40 270 0 0 0 40Z" fill=" ${ bg } " /></svg></pattern>` ) ;
474484 break ;
475485 case "triangles" :
476- canvas . defs ( ) . svg ( " <pattern id=' triangles' patternUnits=' userSpaceOnUse' width='15' height='15' ><svg xmlns=' http://www.w3.org/2000/svg' width='15' height='15' ><rect width='15' height='15' fill='#fff' /><path d=' M0 15L7.5 0L15 15Z' fill='#000' /></svg></pattern>" ) ;
486+ canvas . defs ( ) . svg ( ` <pattern id=" triangles" patternUnits=" userSpaceOnUse" width="15" height="15" ><svg xmlns=" http://www.w3.org/2000/svg" width="15" height="15" ><rect width="15" height="15" fill=" ${ bg } " /><path d=" M0 15L7.5 0L15 15Z" fill=" ${ fg } " /></svg></pattern>` ) ;
477487 break ;
478488 case "wavy" :
479- canvas . defs ( ) . svg ( " <pattern id=' wavy' patternUnits=' userSpaceOnUse' width='15' height='20' viewbox=' 0 0 75 100' ><svg xmlns=' http://www.w3.org/2000/svg' width='75' height=' 100' ><rect width='75' height=' 100' fill='#fff' /><circle cx='75' cy='50' r=' 28.3%' stroke-width='12' stroke='#000' fill=' none' /><circle cx='0' r=' 28.3%' stroke-width='12' stroke='#000' fill=' none' /><circle cy=' 100' r=' 28.3%' stroke-width='12' stroke='#000' fill=' none' /></svg></pattern>" ) ;
489+ canvas . defs ( ) . svg ( ` <pattern id=" wavy" patternUnits=" userSpaceOnUse" width="15" height="20" viewbox=" 0 0 75 100" ><svg xmlns=" http://www.w3.org/2000/svg" width="75" height=" 100" ><rect width="75" height=" 100" fill=" ${ bg } " /><circle cx="75" cy="50" r=" 28.3%" stroke-width="12" stroke=" ${ fg } " fill=" none" /><circle cx="0" r=" 28.3%" stroke-width="12" stroke=" ${ fg } " fill=" none" /><circle cy=" 100" r=" 28.3%" stroke-width="12" stroke=" ${ fg } " fill=" none" /></svg></pattern>` ) ;
480490 break ;
481491 default :
482492 throw new Error ( `The pattern name you requested (${ name } ) is not known.` ) ;
@@ -6699,15 +6709,29 @@ export abstract class RendererBase {
66996709 if ( typeof marker . colour === "object" ) {
67006710 isGradient = true ;
67016711 }
6702- colour = this . resolveColour ( marker . colour ) ;
6712+ colour = this . resolveColour ( marker . colour ) ;
67036713 }
67046714 let opacity = 0.25 ;
67056715 if ( ( "opacity" in marker ) && ( marker . opacity !== undefined ) ) {
67066716 opacity = marker . opacity ;
67076717 }
6708- let fill : FillData | SVGGradient ;
6718+ let pattern : string | undefined ;
6719+ if ( ( "pattern" in marker ) && ( marker . pattern !== undefined ) && ( marker . pattern . length > 0 ) ) {
6720+ pattern = marker . pattern ;
6721+ }
6722+ if ( pattern !== undefined ) {
6723+ this . loadPattern ( pattern , { bg : "none" , fg : typeof colour === "string" ? colour : undefined } ) ;
6724+ }
6725+ let fill : FillData | SVGGradient | SVGElement ;
67096726 if ( isGradient ) {
67106727 fill = colour as SVGGradient ;
6728+ } else if ( pattern !== undefined ) {
6729+ if ( pattern !== undefined ) {
6730+ fill = this . rootSvg . findOne ( `#${ pattern } ` ) as SVGElement ;
6731+ if ( fill === undefined ) {
6732+ throw new Error ( "Could not load the requested pattern." ) ;
6733+ }
6734+ }
67116735 } else {
67126736 fill = { color : colour as string , opacity} ;
67136737 }
0 commit comments