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

Method _initialize

modules/react-mapbox/src/mapbox/mapbox.ts:288–381  ·  view source on GitHub ↗
(container: HTMLDivElement)

Source from the content-addressed store, hash-verified

286
287 /* eslint-disable complexity,max-statements */
288 _initialize(container: HTMLDivElement) {
289 const {props} = this;
290 const {mapStyle = DEFAULT_STYLE} = props;
291 const mapOptions = {
292 ...props,
293 ...props.initialViewState,
294 accessToken: props.mapboxAccessToken || getAccessTokenFromEnv() || null,
295 container,
296 style: normalizeStyle(mapStyle)
297 };
298
299 const viewState = mapOptions.initialViewState || mapOptions.viewState || mapOptions;
300 Object.assign(mapOptions, {
301 center: [viewState.longitude || 0, viewState.latitude || 0],
302 zoom: viewState.zoom || 0,
303 pitch: viewState.pitch || 0,
304 bearing: viewState.bearing || 0
305 });
306
307 if (props.gl) {
308 // eslint-disable-next-line
309 const getContext = HTMLCanvasElement.prototype.getContext;
310 // Hijack canvas.getContext to return our own WebGLContext
311 // This will be called inside the mapboxgl.Map constructor
312 // @ts-expect-error
313 HTMLCanvasElement.prototype.getContext = () => {
314 // Unhijack immediately
315 HTMLCanvasElement.prototype.getContext = getContext;
316 return props.gl;
317 };
318 }
319
320 const map = new this._MapClass(mapOptions);
321 // Props that are not part of constructor options
322 if (viewState.padding) {
323 map.setPadding(viewState.padding);
324 }
325 if (props.cursor) {
326 map.getCanvas().style.cursor = props.cursor;
327 }
328 this._createProxyTransform(map);
329
330 // Hack
331 // Insert code into map's render cycle
332 // eslint-disable-next-line @typescript-eslint/unbound-method
333 const renderMap = map._render;
334 map._render = (arg: number) => {
335 // Hijacked to set this state flag
336 this._inRender = true;
337 renderMap.call(map, arg);
338 this._inRender = false;
339 };
340 // eslint-disable-next-line @typescript-eslint/unbound-method
341 const runRenderTaskQueue = map._renderTaskQueue.run;
342 map._renderTaskQueue.run = (arg: number) => {
343 // This is where camera updates from input handler/animation happens
344 // And where all view state change events are fired
345 this._proxyTransform.$internalUpdate = true;

Callers 1

constructorMethod · 0.95

Calls 5

_createProxyTransformMethod · 0.95
_fireDefferedEventsMethod · 0.95
normalizeStyleFunction · 0.90
getAccessTokenFromEnvFunction · 0.70

Tested by

no test coverage detected