@@ -116,7 +116,7 @@ <h3>{name}</h3>
116116 } else {
117117 // Show photo details
118118 const details = features . map ( f => photoDetails ( f ) ) ;
119- document . getElementById ( 'photo-details' ) . innerHTML = details . join ( ) ;
119+ document . getElementById ( 'photo-details' ) . innerHTML = details . join ( "" ) ;
120120 }
121121 } ) ;
122122} ) ;
@@ -125,7 +125,7 @@ <h3>{name}</h3>
125125 const transform = ol . proj . getTransform ( 'EPSG:4326' , 'EPSG:3857' ) ;
126126 items . forEach ( item => {
127127 const feature = new ol . Feature ( item ) ;
128- feature . set ( 'url' , item . thumb ) ;
128+ feature . set ( 'url' , item . thumb ? item . thumb : thumbnail ( item . name ) ) ;
129129 const coordinate = transform ( [ parseFloat ( item . lon ) , parseFloat ( item . lat ) ] ) ;
130130 feature . setGeometry ( new ol . geom . Point ( coordinate ) ) ;
131131 photosSource . addFeature ( feature ) ;
@@ -187,6 +187,24 @@ <h3>{name}</h3>
187187 return [ photoStyle ( feature , clamp ( 0.2 , 0.1 / resolution , 1 ) ) ] ;
188188}
189189
190+ function thumbnail ( str ) {
191+ const hue = hueColor ( str ) ;
192+ const svg = `
193+ <svg width="160" height="120" xmlns="http://www.w3.org/2000/svg">
194+ <rect width="100%" height="100%" fill="hsl(${ hue } , 60%, 50%)" stroke="hsl(${ hue } , 55%, 30%)" stroke-width="2"/>
195+ </svg>
196+ ` . trim ( ) ;
197+ return `data:image/svg+xml;base64,${ btoa ( svg ) } ` ;
198+ }
199+
200+ function hueColor ( str ) {
201+ let hash = 0 ;
202+ for ( let i = 0 ; i < str . length ; i ++ ) {
203+ hash = str . charCodeAt ( i ) + ( ( hash << 5 ) - hash ) ;
204+ }
205+ return hash % 360 ;
206+ }
207+
190208function clamp ( min , value , max ) {
191209 if ( value < min ) return min ;
192210 if ( value > max ) return max ;
0 commit comments