Appearance
图层组件生命周期
图层组件的生命周期只要是继承 maplibre-gl 的 CustomLayerInterface。
onAdd
Optional method called when the layer has been added to the Map with Map#addLayer. This gives the layer a chance to initialize gl resources and register event listeners.
Parameters
| Name | Type | Description |
|---|---|---|
| map | Map | The Map this custom layer was just added to. |
| gl | WebGLRenderingContext/WebGL2RenderingContext | The gl context for the map. |
onRemove
Optional method called when the layer has been removed from the Map with Map#removeLayer. This gives the layer a chance to clean up gl resources and event listeners.
Parameters
| Name | Type | Description |
|---|---|---|
| map | Map | The Map this custom layer was just added to. |
| gl | WebGLRenderingContext/WebGL2RenderingContext | The gl context for the map. |
render
Called during a render frame allowing the layer to draw into the GL context.
The layer can assume blending and depth state is set to allow the layer to properly blend and clip other layers. The layer cannot make any other assumptions about the current GL state.
If the layer needs to render to a texture, it should implement the prerender method to do this and only use the render method for drawing directly into the main framebuffer.
The blend function is set to gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA). This expects colors to be provided in premultiplied alpha form where the r, g and b values are already multiplied by the a value. If you are unable to provide colors in premultiplied form you may want to change the blend function to gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA).
对于自定义图层的使用,详情参考 加载自定义图层

