{"record":{"id":"7539737ffe803b3b","repo":"angular/components","slug":"cannot-interact-with-a-google-map-bicycling-layer","errorCode":null,"errorMessage":"Cannot interact with a Google Map Bicycling Layer before it has been initialized. Please wait for the Transit Layer to load before trying to interact with it.","messagePattern":"Cannot interact with a Google Map Bicycling Layer before it has been initialized\\. Please wait for the Transit Layer to load before trying to interact with it\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/google-maps/map-bicycling-layer/map-bicycling-layer.ts","lineNumber":68,"sourceCode":"    }\n  }\n\n  private _initialize(map: google.maps.Map, layerConstructor: typeof google.maps.BicyclingLayer) {\n    this._zone.runOutsideAngular(() => {\n      this.bicyclingLayer = new layerConstructor();\n      this.bicyclingLayerInitialized.emit(this.bicyclingLayer);\n      this._assertLayerInitialized();\n      this.bicyclingLayer.setMap(map);\n    });\n  }\n\n  ngOnDestroy() {\n    this.bicyclingLayer?.setMap(null);\n  }\n\n  private _assertLayerInitialized(): asserts this is {bicyclingLayer: google.maps.BicyclingLayer} {\n    if (!this.bicyclingLayer) {\n      throw Error(\n        'Cannot interact with a Google Map Bicycling Layer before it has been initialized. ' +\n          'Please wait for the Transit Layer to load before trying to interact with it.',\n      );\n    }\n  }\n}\n","sourceCodeStart":50,"sourceCodeEnd":75,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/google-maps/map-bicycling-layer/map-bicycling-layer.ts#L50-L75","documentation":"MapBicyclingLayer creates its google.maps.BicyclingLayer asynchronously after the map is ready. _assertLayerInitialized (used by _initialize and accessors) throws if bicyclingLayer is still unset. The message mistakenly mentions the Transit Layer, but it guards the bicycling layer object.","triggerScenarios":"Calling bicycling-layer getters/setters or _initialize paths before the BicyclingLayer instance was constructed post-map resolution.","commonSituations":"Toggling layer properties in ngOnInit of a parent; unit tests asserting layer state before async init; API script slowness delaying map/layer creation.","solutions":["Wait for map initialization before mutating layer properties.","Use the component's async signals/events to know when the layer is ready.","In tests, await initialization promises or fixture stability.","Bind inputs declaratively and let the component apply them when ready, instead of imperative calls."],"exampleFix":"// before\nngAfterViewInit() { this.layer.setMap(this.map.googleMap); }\n// after\nthis.map._resolveMap().then(() => {\n  this.layer.setMap(this.map.googleMap);\n});","handlingStrategy":"validation","validationCode":"if (!bicyclingLayerComponent['bicyclingLayer']) {\n  throw new Error('BicyclingLayer not ready; wait for the parent map to initialize.');\n}","typeGuard":"function isBicyclingLayerReady(c: any): c is {bicyclingLayer: google.maps.BicyclingLayer} {\n  return c?.bicyclingLayer != null;\n}","tryCatchPattern":"try {\n  this.layer._initialize();\n} catch (e) {\n  if (String((e as Error).message).includes('before it has been initialized')) {\n    await this.map._resolveMap();\n  }\n}","preventionTips":["Bind layer inputs declaratively instead of calling setters imperatively.","Gate layer interactions on map initialization events.","In tests, await the initialization promise before asserting layer state.","Don't rely on the message text mentioning 'Transit Layer' — it guards the bicycling layer."],"tags":["angular","google-maps","async-initialization","layer","dev-mode"],"backgroundTag":"not-initialized-yet","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}