mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
125 lines
3.9 KiB
TypeScript
125 lines
3.9 KiB
TypeScript
import * as React from "react";
|
|
import {
|
|
Viewport,
|
|
StaticMapProps,
|
|
InteractiveMapProps,
|
|
InteractiveMap,
|
|
CanvasOverlay,
|
|
SVGOverlay,
|
|
HTMLOverlay,
|
|
HTMLOverlayProps,
|
|
CanvasRedrawOptions,
|
|
HTMLRedrawOptions,
|
|
SVGOverlayProps,
|
|
SVGRedrawOptions,
|
|
StaticMap
|
|
} from 'react-map-gl';
|
|
import * as MapboxGL from "mapbox-gl";
|
|
|
|
interface MyMapState {
|
|
viewport: Viewport;
|
|
}
|
|
|
|
class MyMap extends React.Component<{}, MyMapState> {
|
|
state: MyMapState = {
|
|
viewport: {
|
|
bearing: 0,
|
|
isDragging: false,
|
|
latitude: 0,
|
|
longitude: 0,
|
|
zoom: 3,
|
|
}
|
|
};
|
|
|
|
private map: MapboxGL.Map;
|
|
|
|
render() {
|
|
return (
|
|
<div>
|
|
<InteractiveMap
|
|
{...this.state.viewport}
|
|
mapboxApiAccessToken="pk.test"
|
|
height={400}
|
|
width={400}
|
|
ref={this.setRefInteractive}
|
|
>
|
|
<CanvasOverlay
|
|
redraw={(opts: CanvasRedrawOptions) => {
|
|
const {
|
|
ctx,
|
|
height,
|
|
project,
|
|
unproject,
|
|
width,
|
|
} = opts;
|
|
const xy: number[] = unproject(project([20, 20]));
|
|
ctx.clearRect(0, 0, width, height);
|
|
}}
|
|
/>
|
|
<CanvasOverlay
|
|
redraw={(opts: CanvasRedrawOptions) => {}}
|
|
captureScroll={true}
|
|
captureDrag={true}
|
|
captureClick={true}
|
|
captureDoubleClick={true}
|
|
/>
|
|
<SVGOverlay
|
|
redraw={() => {}}
|
|
/>
|
|
<SVGOverlay
|
|
redraw={(opts: SVGRedrawOptions) => {
|
|
const {
|
|
height,
|
|
project,
|
|
unproject,
|
|
width,
|
|
} = opts;
|
|
const xy: number[] = unproject(project([20, 20]));
|
|
}}
|
|
captureScroll={true}
|
|
captureDrag={true}
|
|
captureClick={true}
|
|
captureDoubleClick={true}
|
|
/>
|
|
<HTMLOverlay
|
|
redraw={() => {}}
|
|
/>
|
|
<HTMLOverlay
|
|
redraw={(opts: HTMLRedrawOptions) => {
|
|
const {
|
|
height,
|
|
project,
|
|
unproject,
|
|
width,
|
|
} = opts;
|
|
const xy: number[] = unproject(project([20, 20]));
|
|
}}
|
|
style={{
|
|
border: "2px solid black"
|
|
}}
|
|
captureScroll={true}
|
|
captureDrag={true}
|
|
captureClick={true}
|
|
captureDoubleClick={true}
|
|
/>
|
|
</InteractiveMap>
|
|
<StaticMap
|
|
{...this.state.viewport}
|
|
mapboxApiAccessToken="pk.test"
|
|
height={400}
|
|
width={400}
|
|
ref={this.setRefStatic}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
private readonly setRefInteractive = (el: InteractiveMap) => {
|
|
this.map = el.getMap();
|
|
}
|
|
|
|
private readonly setRefStatic = (el: StaticMap) => {
|
|
this.map = el.getMap();
|
|
}
|
|
}
|