11import React , { memo , useContext , useMemo , useCallback , useEffect } from 'react' ;
22import { useSelector } from 'react-redux' ;
33import { MapContext } from '../App' ;
4+ import { addMapImage } from '../utils/map' ;
45import { API_URL , DEFAULT_SYMBOL_LAYOUT , DEFAULT_SYMBOL_PAINT } from '../constants' ;
56
7+ import MarkerImage from '../common/images/icons/mapbox-blue-marker-icon.png' ;
8+ import RangerStationsImage from '../common/images/icons/ranger-stations.png' ;
9+
610const SPATIAL_FEATURES_SOURCE = 'spatial-features-source' ;
711
812const VECTOR_TILE_URL = `${ API_URL } spatialfeatures/tiles/{z}/{x}/{y}.pbf` ;
@@ -14,6 +18,8 @@ export const LINES_LAYER_ID = 'spatial-features-lines';
1418export const POLYGONS_LAYER_ID = 'spatial-features-polygons' ;
1519// const POLYGONS_LABELS_LAYER_ID = 'spatial-features-polygon-labels';
1620
21+ const BEFORE_LAYER_ID = 'feature-separation-layer' ;
22+
1723const DEFAULT_LINE_PAINT_COLOR = [
1824 'case' ,
1925 [ 'has' , 'stroke' ] , [ 'get' , 'stroke' ] ,
@@ -26,10 +32,11 @@ const DEFAULT_LINE_PAINT_COLOR = [
2632const DEFAULT_POLYGON_FILL_COLOR = [
2733 'case' ,
2834 [ 'has' , 'fill' ] , [ 'get' , 'fill' ] ,
29- [ 'has' , 'color' ] , [ 'get' , 'color' ] ,
35+ [ 'has' , 'fill- color' ] , [ 'get' , 'fill- color' ] ,
3036 [ 'has' , 'fill_color' ] , [ 'get' , 'fill_color' ] ,
37+ [ 'has' , 'color' ] , [ 'get' , 'color' ] ,
3138 [ 'has' , 'stroke' ] , [ 'get' , 'stroke' ] ,
32- '#ff6600 '
39+ 'rgba(255, 102, 0, 0) '
3340] ;
3441
3542
@@ -114,7 +121,7 @@ const SpatialFeaturesLayer = ({ onFeatureClick }) => {
114121 ...DEFAULT_SYMBOL_PAINT
115122 } ,
116123 filter : symbolLayerFilter
117- } ) ;
124+ } , BEFORE_LAYER_ID ) ;
118125 }
119126
120127 if ( ! map . getLayer ( LINES_LAYER_ID ) ) {
@@ -131,7 +138,7 @@ const SpatialFeaturesLayer = ({ onFeatureClick }) => {
131138 [ 'has' , 'width' ] , [ 'get' , 'width' ] ,
132139 [ 'has' , 'line_width' ] , [ 'get' , 'line_width' ] ,
133140 [ 'has' , 'stroke_width' ] , [ 'get' , 'stroke_width' ] ,
134- 3
141+ 1 ,
135142 ] ,
136143 'line-opacity' : [
137144 'case' ,
@@ -143,7 +150,7 @@ const SpatialFeaturesLayer = ({ onFeatureClick }) => {
143150 ]
144151 } ,
145152 filter : lineLayerFilter
146- } ) ;
153+ } , BEFORE_LAYER_ID ) ;
147154 }
148155
149156 if ( ! map . getLayer ( POLYGONS_LAYER_ID ) ) {
@@ -166,11 +173,11 @@ const SpatialFeaturesLayer = ({ onFeatureClick }) => {
166173 [ 'has' , 'stroke' ] , [ 'get' , 'stroke' ] ,
167174 [ 'has' , 'outline_color' ] , [ 'get' , 'outline_color' ] ,
168175 [ 'has' , 'border_color' ] , [ 'get' , 'border_color' ] ,
169- '#ff6600 '
176+ 'rgba(255, 102, 0, 0.25) '
170177 ]
171178 } ,
172179 filter : polygonLayerFilter
173- } ) ;
180+ } , BEFORE_LAYER_ID ) ;
174181 }
175182
176183 /* // Add separate label layers for each geometry type
@@ -361,6 +368,15 @@ const SpatialFeaturesLayer = ({ onFeatureClick }) => {
361368 }
362369 } , [ map , polygonLayerFilter ] ) ;
363370
371+ useEffect ( ( ) => {
372+ if ( ! map ?. hasImage ?. ( 'marker-icon' ) ) {
373+ addMapImage ( { src : MarkerImage , id : 'marker-icon' } ) ;
374+ }
375+ if ( ! map ?. hasImage ?. ( 'ranger-stations' ) ) {
376+ addMapImage ( { src : RangerStationsImage , id : 'ranger-stations' } ) ;
377+ }
378+ } , [ map ] ) ;
379+
364380 return null ;
365381} ;
366382
0 commit comments