Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- REACT
- expire_logs_days
- log_bin
- Express
- MySQL
- Regular expression
- Webpack
- 퀵소트
- nodejs
- Effective Java 3/e
- spring
- current_date
- eslint
- regex
- spring cloud
- Spring Batch
- update
- Node
- git
- Effective Java
- 정규표현식
- Chunk
- java
- log4j2
- JavaScript
- mysql 5.5
- npm
- migration
- REACTJS
- upgrade
Archives
- Today
- Total
내 세상
[React] React-leaflet rectangle gradient 적용 방법 본문
728x90
반응형
React-Leafet 사용 시, 동적인 정보를 보여주기 위해 Rectangle을 Customize해서 사용하고 있음.
다만, Rectangle은 SVG 요소이기 때문에, fillColor를 Gradient로 사용이 불가하고 단색으로만 가능함.
하지만, svg defs 선언을 통해서 SVG 요소에도 Gradient를 적용할 수 있는 방안을 발견
MapContainer 내부에 svg-defs를 통해 먼저 linearGradient를 먼저 설정한다.
그리고 Rectangle이나 SVG 요소에서 fillColor를 'url(#grad-RED)' 와 같은 형식으로 사용하면 됨
const MyContainer = memo(
({ onMove, mapCenter, mapZoom, showDialogWithData, mapMarkers }) => {
....
const addGradient = () => {
const colorToGradient = ["RED", "BLUE", "GREY"];
return colorToGradient.map((item) => {
const { start, end } = getGradientColors(item)
return (
<linearGradient
id={`grad-${item}`}
x1="0%"
y1="0%"
x2="100%"
y2="100%"
key={item}
>
<stop offset="0%" stopColor={start} />
<stop offset="100%" stopColor={end} />
</linearGradient>
)
})
}
_.forEach(mapMarkers, (elem) => {
...
})
L.CRS.MyCRS = L.extend({}, L.CRS.Simple, {
transformation: new L.Transformation(1, 0, 1, 0), // ax+b, cy+d
})
return (
<MapContainer
center={mapCenter}
zoom={mapZoom}
zoomControl={false}
attributionControl={false}
maxBounds={boundsMap}
style={{ height: '100%', fontFamily: 'IBM Plex Sans', fontWeight: 500 }}
crs={L.CRS.MyCRS}
maxZoom={10}
id="map"
ref={mapRef}
>
<svg>
<defs>{addGradient()}</defs>
</svg>
<Marker icon={icon} position={{ lat: 0, lng: 0 }}></Marker>
<Marker icon={icon} position={{ lat: 0, lng: 1980 }}></Marker>
<Marker icon={icon} position={{ lat: 360, lng: 0 }}></Marker>
<Rectangle
bounds ={[[100,0],[10,100]]}
pathOptions ={{fillColor: 'url(#grad-RED)'}} />
</MapContainer>
)
}
)
728x90
반응형
'Technical > React' 카테고리의 다른 글
[React] React-Select 메뉴 클릭 시, 드롭다운 메뉴 뒤 클릭 이슈 (0) | 2025.01.07 |
---|---|
[webpack] webpack-dev-server config 설정 (esbuild-loader, babel-loader) (0) | 2024.12.06 |
[React] node-sass error (0) | 2023.01.04 |
[React] MUI ClickAwayListener (0) | 2022.12.23 |
[React] Copy to Clipboard (0) | 2022.11.29 |