File tree Expand file tree Collapse file tree 3 files changed +75
-1
lines changed
docs/api-reference/maplibre
modules/react-maplibre/src Expand file tree Collapse file tree 3 files changed +75
-1
lines changed Original file line number Diff line number Diff line change 1+ # GlobeControl
2+
3+ React component that wraps maplibre-gl's [ GlobeControl] ( https://maplibre.org/maplibre-gl-js/docs/API/classes/GlobeControl/ ) class.
4+
5+ ``` tsx
6+ import * as React from ' react' ;
7+ import {Map , GlobeControl } from ' react-map-gl/maplibre' ;
8+ import ' maplibre-gl/dist/maplibre-gl.css' ;
9+
10+ function App() {
11+ return <Map
12+ initialViewState = { {
13+ longitude: - 100 ,
14+ latitude: 40 ,
15+ zoom: 3.5
16+ }}
17+ mapStyle = " https://demotiles.maplibre.org/style.json"
18+ >
19+ <GlobeControl />
20+ </Map >;
21+ }
22+ ```
23+
24+ ## Properties
25+
26+ ### Reactive Properties
27+
28+ #### ` style ` : CSSProperties {#style}
29+
30+ CSS style override that applies to the control's container.
31+
32+ ### Other Properties
33+
34+ The properties in this section are not reactive. They are only used when the component first mounts.
35+
36+ #### ` position ` : 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
37+
38+ Default: ` 'top-right' `
39+
40+ Placement of the control relative to the map.
41+
42+ ## Source
43+
44+ [ globe-control.ts] ( https://github.com/visgl/react-map-gl/tree/9.0-release/modules/react-maplibre/src/components/globe-control.ts )
Original file line number Diff line number Diff line change 1+ import * as React from "react" ;
2+ import { useEffect , memo } from "react" ;
3+ import { applyReactStyle } from "../utils/apply-react-style" ;
4+ import { useControl } from "./use-control" ;
5+ import { ControlPosition } from "../types/lib" ;
6+
7+ export type GlobeControlProps = {
8+ /** Placement of the control relative to the map. */
9+ position ?: ControlPosition ;
10+ /** CSS style override, applied to the control's container */
11+ style ?: React . CSSProperties ;
12+ } ;
13+
14+ function _GlobeControl ( props : GlobeControlProps ) {
15+ const ctrl = useControl ( ( { mapLib } ) => new mapLib . GlobeControl ( props ) , {
16+ position : props . position ,
17+ } ) ;
18+
19+ useEffect ( ( ) => {
20+ applyReactStyle ( ctrl . _container , props . style ) ;
21+ } , [ props . style ] ) ;
22+
23+ return null ;
24+ }
25+
26+ export const GlobeControl = memo ( _GlobeControl ) ;
Original file line number Diff line number Diff line change @@ -18,7 +18,8 @@ import type {
1818 TerrainControl ,
1919 TerrainSpecification ,
2020 LogoControl ,
21- LogoControlOptions
21+ LogoControlOptions ,
22+ GlobeControl ,
2223} from 'maplibre-gl' ;
2324
2425export type {
@@ -43,6 +44,7 @@ export type {
4344 TerrainControl as TerrainControlInstance ,
4445 LogoControl as LogoControlInstance ,
4546 LogoControlOptions ,
47+ GlobeControl as GlobeControlInstance ,
4648 CustomLayerInterface
4749} from 'maplibre-gl' ;
4850
@@ -73,4 +75,6 @@ export interface MapLib {
7375 TerrainControl : { new ( options : TerrainSpecification ) : TerrainControl } ;
7476
7577 LogoControl : { new ( options : LogoControlOptions ) : LogoControl } ;
78+
79+ GlobeControl : { new ( options : any ) : GlobeControl } ;
7680}
You can’t perform that action at this time.
0 commit comments