MCPcopy Create free account
hub / github.com/visgl/react-map-gl / createRef

Function createRef

modules/react-mapbox/src/mapbox/create-ref.ts:34–89  ·  view source on GitHub ↗
(mapInstance: Mapbox)

Source from the content-addressed store, hash-verified

32} & Omit<MapInstance, (typeof skipMethods)[number]>;
33
34export default function createRef(mapInstance: Mapbox): MapRef | null {
35 if (!mapInstance) {
36 return null;
37 }
38
39 const map = mapInstance.map;
40 const ref: any = {
41 getMap: () => map,
42
43 // Overwrite getters to use our shadow transform
44 getCenter: () => mapInstance.transform.center,
45 getZoom: () => mapInstance.transform.zoom,
46 getBearing: () => mapInstance.transform.bearing,
47 getPitch: () => mapInstance.transform.pitch,
48 getPadding: () => mapInstance.transform.padding,
49 getBounds: () => mapInstance.transform.getBounds(),
50 project: (lnglat: LngLatLike) => {
51 const tr = map.transform;
52 map.transform = mapInstance.transform;
53 const result = map.project(lnglat);
54 map.transform = tr;
55 return result;
56 },
57 unproject: (point: PointLike) => {
58 const tr = map.transform;
59 map.transform = mapInstance.transform;
60 const result = map.unproject(point);
61 map.transform = tr;
62 return result;
63 },
64 // options diverge between mapbox and maplibre
65 queryTerrainElevation: (lnglat: LngLatLike, options?: any) => {
66 const tr = map.transform;
67 map.transform = mapInstance.transform;
68 const result = map.queryTerrainElevation(lnglat, options);
69 map.transform = tr;
70 return result;
71 },
72 queryRenderedFeatures: (geometry?: any, options?: any) => {
73 const tr = map.transform;
74 map.transform = mapInstance.transform;
75 const result = map.queryRenderedFeatures(geometry, options);
76 map.transform = tr;
77 return result;
78 }
79 };
80
81 for (const key of getMethodNames(map)) {
82 // @ts-expect-error
83 if (!(key in ref) && !skipMethods.includes(key)) {
84 ref[key] = map[key].bind(map);
85 }
86 }
87
88 return ref;
89}
90
91function getMethodNames(obj: Object) {

Callers 1

_MapFunction · 0.50

Calls 1

getMethodNamesFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…