@@ -18,34 +18,22 @@ export default function useCurrentLocationLayer(map: Map, locationState: Current
1818 if ( layerRef . current ) {
1919 map . removeLayer ( layerRef . current )
2020 layerRef . current = null
21- positionFeatureRef . current = null
22- accuracyFeatureRef . current = null
23- headingFeatureRef . current = null
2421 }
2522 return
2623 } else if ( ! layerRef . current ) {
2724 const layer = createLocationLayer ( )
28- const positionFeature = new Feature ( )
29- const accuracyFeature = new Feature ( )
30- const headingFeature = new Feature ( )
31- layer . getSource ( ) ?. addFeature ( positionFeature )
32- layer . getSource ( ) ?. addFeature ( accuracyFeature )
33- layer . getSource ( ) ?. addFeature ( headingFeature )
25+ layer . getSource ( ) ?. addFeature ( ( positionFeatureRef . current = new Feature ( ) ) )
26+ layer . getSource ( ) ?. addFeature ( ( accuracyFeatureRef . current = new Feature ( ) ) )
27+ layer . getSource ( ) ?. addFeature ( ( headingFeatureRef . current = new Feature ( ) ) )
3428 map . addLayer ( layer )
3529
3630 layerRef . current = layer
37- positionFeatureRef . current = positionFeature
38- accuracyFeatureRef . current = accuracyFeature
39- headingFeatureRef . current = headingFeature
4031 }
4132
4233 return ( ) => {
4334 if ( layerRef . current ) {
4435 map . removeLayer ( layerRef . current )
4536 layerRef . current = null
46- positionFeatureRef . current = null
47- accuracyFeatureRef . current = null
48- headingFeatureRef . current = null
4937 }
5038 }
5139 } , [ locationState . enabled ] )
@@ -54,6 +42,8 @@ export default function useCurrentLocationLayer(map: Map, locationState: Current
5442 if (
5543 ! locationState . enabled ||
5644 ! locationState . coordinate ||
45+ ! layerRef . current ||
46+ // typescript complaints without the following
5747 ! positionFeatureRef . current ||
5848 ! accuracyFeatureRef . current ||
5949 ! headingFeatureRef . current
0 commit comments