@@ -13,7 +13,6 @@ export default function useCurrentLocationLayer(map: Map, locationState: Current
1313 const accuracyFeatureRef = useRef < Feature | null > ( null )
1414 const headingFeatureRef = useRef < Feature | null > ( null )
1515
16- // Create layer once when enabled
1716 useEffect ( ( ) => {
1817 if ( ! locationState . enabled ) {
1918 if ( layerRef . current ) {
@@ -65,12 +64,13 @@ export default function useCurrentLocationLayer(map: Map, locationState: Current
6564 positionFeatureRef . current . setGeometry ( new Point ( coord ) )
6665 accuracyFeatureRef . current . setGeometry ( new Circle ( coord , locationState . accuracy ) )
6766
68- // Set heading feature position (style will handle the triangle and rotation)
67+ // set heading feature position (style will handle the triangle and rotation)
6968 if ( locationState . heading != null ) {
7069 headingFeatureRef . current . setGeometry ( new Point ( coord ) )
7170 headingFeatureRef . current . set ( 'heading' , locationState . heading )
7271 } else {
7372 headingFeatureRef . current . setGeometry ( undefined )
73+ headingFeatureRef . current . unset ( 'heading' ) // not strictly necessary
7474 }
7575
7676 if ( locationState . syncView ) {
@@ -99,23 +99,22 @@ function createLocationLayer(): VectorLayer<VectorSource> {
9999 style : feature => {
100100 const geometry = feature . getGeometry ( )
101101 if ( geometry instanceof Point ) {
102- // Check if this is the heading feature
103102 const heading = feature . get ( 'heading' )
104103 if ( heading !== undefined ) {
105- // Triangle style for heading direction
104+ // triangle style for heading direction
106105 return new Style ( {
107106 image : new RegularShape ( {
108107 points : 3 ,
109108 radius : 8 ,
110109 displacement : [ 0 , 9 ] ,
111- rotation : ( heading * Math . PI ) / 180 , // Convert degrees to radians
110+ rotation : ( heading * Math . PI ) / 180 , // convert degrees to radians
112111 fill : new Fill ( { color : '#368fe8' } ) ,
113112 stroke : new Stroke ( { color : '#FFFFFF' , width : 1 } ) ,
114113 } ) ,
115114 zIndex : 1 ,
116115 } )
117116 } else {
118- // Blue dot style for position
117+ // blue dot style for position
119118 return new Style ( {
120119 image : new CircleStyle ( {
121120 radius : 8 ,
@@ -126,7 +125,7 @@ function createLocationLayer(): VectorLayer<VectorSource> {
126125 } )
127126 }
128127 } else if ( geometry instanceof CircleGeom ) {
129- // Accuracy circle style
128+ // accuracy circle style
130129 return new Style ( {
131130 fill : new Fill ( { color : 'rgba(66, 133, 244, 0.1)' } ) ,
132131 stroke : new Stroke ( { color : 'rgba(66, 133, 244, 0.3)' , width : 1 } ) ,
@@ -135,6 +134,6 @@ function createLocationLayer(): VectorLayer<VectorSource> {
135134 }
136135 return [ ]
137136 } ,
138- zIndex : 4 , // Above paths and query points
137+ zIndex : 4 , // layer itself should be above paths and query points
139138 } )
140139}
0 commit comments