当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


JavaScript ArcGIS BaseLayerView2D用法及代码示例


基本信息

以下是所在类或对象的基本信息。

AMD: require(["esri/views/2d/layers/BaseLayerView2D"], (BaseLayerView2D) => { /* code goes here */ });

ESM: import BaseLayerView2D from "@arcgis/core/views/2d/layers/BaseLayerView2D";

类: esri/views/2d/layers/BaseLayerView2D

继承: BaseLayerView2D > LayerView > Accessor

自从:用于 JavaScript 4.8 的 ArcGIS API

用法说明

表示 LayerLayerView 在被添加到带有 MapViewMap 之后。

可以扩展此类以为层创建自定义LayerView。当将图层添加到其Map的图层列表时,MapView 会根据需要创建 LayerView

子类可以实现LayerView生命周期的多个函数。首先,当LayerView即将开始绘制图层内容时,调用attach()方法。然后,在 LayerView 的生命周期中,render() 方法在 MapView 渲染阶段被调用。 render() 方法可以访问画布 2d 上下文,在其中可以渲染可显示的内容。最后,从Map中删除图层后,将调用 detach() 方法。它释放所有分配的资源并停止on-going请求。

例子:

let TileBorderLayerView2D = BaseLayerView2D.createSubclass({
   // Example of a render implementation that draws tile boundaries
   render(renderParameters) {
     let tileSize = this.layer.tileInfo.size[0];
     let state = renderParameters.state;
     let pixelRatio = state.pixelRatio;
     let width = state.size[0];
     let height = state.size[1];
     let context = renderParameters.context;
     let coords = [0, 0];

     context.fillStyle = "rgba(0,0,0,0.25)";
     context.fillRect(0, 0, width * pixelRatio, height * pixelRatio);

     // apply rotation for everything that will be applied to the canvas
     if (state.rotation !== 0) {
       context.translate(width * pixelRatio * 0.5, height * pixelRatio * 0.5);
       context.rotate((state.rotation * Math.PI) / 180);
       context.translate(- width * pixelRatio * 0.5, -height * pixelRatio * 0.5);
     }

     // Set the style for all the text.
     context.font = "24px monospace";
     context.fillStyle = "black";
     context.shadowBlur = 1;

     for (const tile of this.tiles) {
       let screenScale = tile.resolution / state.resolution * pixelRatio;

       state.toScreenNoRotation(coords, tile.coords);

       // Draw the tile boundaries
       context.strokeRect(coords[0], coords[1], tileSize * screenScale, tileSize * screenScale);

       // Draw the tile information
       context.shadowColor = "white";
       context.fillText(
         tile.level + "/" + tile.row + "/" + tile.col + "/" + tile.world,
         coords[0] + 12,
         coords[1] + 24,
         tileSize * screenScale
       );
       context.shadowColor = "transparent";
     }
   }
 });

 let CustomTileLayer = Layer.createSubclass({
   tileInfo: TileInfo.create({ spatialReference: { wkid: 3857 }}),

   createLayerView(view) {
     if (view.type === "2d") {
       return new TileBorderLayerView2D({
         view: view,
         layer: this
       });
     }
   }
 });

相关用法


注:本文由纯净天空筛选整理自arcgis.com大神的英文原创作品 BaseLayerView2D。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。