@@ -29,9 +29,17 @@ map.on('click', event => {
2929 layerClusters . getFeatures ( event . pixel ) . then ( clickedFeatures => {
3030 if ( ! clickedFeatures . length ) return ;
3131 const features = clickedFeatures [ 0 ] . get ( 'features' ) ;
32- // Show photo details
33- const details = features . map ( f => photoDetails ( f ) ) ;
34- document . getElementById ( 'photo-details' ) . innerHTML = details . join ( ) ;
32+ if ( features . length > 1 && ! isMaximumZoom ( map . getView ( ) ) ) {
33+ // Zoom in
34+ const extent = ol . extent . boundingExtent (
35+ features . map ( r => r . getGeometry ( ) . getCoordinates ( ) ) ,
36+ ) ;
37+ map . getView ( ) . fit ( extent , { duration : 400 , padding : [ 150 , 150 , 150 , 150 ] } ) ;
38+ } else {
39+ // Show photo details
40+ const details = features . map ( f => photoDetails ( f ) ) ;
41+ document . getElementById ( 'photo-details' ) . innerHTML = details . join ( ) ;
42+ }
3543 } ) ;
3644} ) ;
3745
@@ -82,6 +90,8 @@ const cache = {};
8290function clusterStyle ( feature , resolution ) {
8391 const features = feature . get ( 'features' ) ;
8492 const size = features . length ;
93+ if ( size === 1 ) return thumbStyle ( features [ 0 ] , resolution ) ;
94+
8595 const key = `cl-${ size } ` ;
8696 if ( ! cache [ key ] ) {
8797 cache [ key ] = new ol . style . Style ( {
@@ -119,4 +129,10 @@ function clamp(min, value, max) {
119129 if ( value < min ) return min ;
120130 if ( value > max ) return max ;
121131 return value ;
132+ }
133+
134+ function isMaximumZoom ( view ) {
135+ const maxZoom = view . getMaxZoom ( ) ;
136+ const currentZoom = view . getZoom ( ) ;
137+ return currentZoom >= maxZoom ;
122138}
0 commit comments