11const photosSource = new ol . source . Vector ( ) ;
22
3+ // Configure map layers: bottom - OpenStreetMap map, top - photo thumbnails
34const layerOSM = new ol . layer . Tile ( {
45 source : new ol . source . OSM ( )
56} ) ;
67const layerThumbs = new ol . layer . Vector ( {
78 source : photosSource ,
89 style : thumbStyle ,
10+ updateWhileAnimating : true ,
11+ updateWhileInteracting : true ,
912} ) ;
1013const map = new ol . Map ( {
1114 target : 'map' ,
@@ -16,6 +19,23 @@ const map = new ol.Map({
1619 } )
1720} ) ;
1821
22+ // Configure thumbnail selector
23+ const thumbSelector = new ol . interaction . Select ( {
24+ layers : [ layerThumbs ] ,
25+ style : selectedStyle
26+ } ) ;
27+ map . addInteraction ( thumbSelector ) ;
28+
29+ const selectedFeatures = thumbSelector . getFeatures ( ) ;
30+ selectedFeatures . on ( 'add' , event => {
31+ const feature = event . target . item ( 0 ) ;
32+ const details = photoDetails ( feature ) ;
33+ document . getElementById ( 'photo-details' ) . innerHTML = details ;
34+ } ) ;
35+ selectedFeatures . on ( 'remove' , ( ) => {
36+ document . getElementById ( 'photo-details' ) . innerHTML = '' ;
37+ } ) ;
38+
1939const handleMapDataLoaded = items => {
2040 const transform = ol . proj . getTransform ( 'EPSG:4326' , 'EPSG:3857' ) ;
2141 items . forEach ( item => {
@@ -27,11 +47,27 @@ const handleMapDataLoaded = items => {
2747 } ) ;
2848} ;
2949handleMapDataLoaded ( [ {
50+ "name" : "dsc_1337_ps_5996.jpg" ,
51+ "path" : "https://annimon.com/albums/files/dsc_1337_ps_5996.jpg" ,
3052 "preview" : "https://annimon.com/albums/screens/dsc_1337_ps_5996.jpg.250.png" ,
3153 "lat" : 47.765957 ,
32- "lon" : 37.255646
54+ "lon" : 37.255646 ,
55+ "make" : "Sony Ericsson" ,
56+ "model" : "MK16i" ,
57+ "date" : "2017-06-02 19:30:08"
3358} ] ) ;
3459
60+ // -- photo details --
61+ function photoDetails ( feature ) {
62+ let content = document . getElementById ( 'photo-template' ) . innerHTML ;
63+ const keys = [ 'name' , 'preview' , 'date' , 'lat' , 'lon' , 'make' , 'model' , 'path' ] ;
64+ keys . forEach ( key => {
65+ const value = feature . get ( key ) ;
66+ content = content . replace ( `{${ key } }` , value ) ;
67+ } ) ;
68+ return content ;
69+ }
70+
3571// -- icon styles --
3672const cache = { } ;
3773
@@ -50,6 +86,10 @@ function thumbStyle(feature, resolution) {
5086 return [ photoStyle ( feature , clamp ( 0.2 , 0.1 / resolution , 1 ) ) ] ;
5187}
5288
89+ function selectedStyle ( feature , resolution ) {
90+ return [ photoStyle ( feature , clamp ( 0.4 , 0.14 / resolution , 1.2 ) ) ] ;
91+ }
92+
5393function clamp ( min , value , max ) {
5494 if ( value < min ) return min ;
5595 if ( value > max ) return max ;
0 commit comments