11.newLayer系列-VectorTileLayer

该代码段展示了如何在OpenLayers中创建一个WMTSVectorTileLayer,使用GeoJSON格式来获取数据。它定义了请求参数、分辨率、矩阵ID,并设置了投影信息。
摘要由CSDN通过智能技术生成
import "ol/ol.css";
import WMTSTileGrid from 'ol/tilegrid/WMTS'
import {Projection} from 'ol/proj'
import VectorTileLayer from 'ol/layer/VectorTile';
import VectorTileSource from "ol/source/VectorTile";
import {GeoJSON} from 'ol/format'

let xysGetVectorTileLayer = () => {

  let layer = 'one:base-old'
  let baseUrl = 'http://43.143.xxx.xxx:8083/geoserver/gwc/service/wmts'


  let urlConstruct = () => {
    let url = baseUrl + '?';
    for (let param in params) {
      url = url + param + '=' + params[param] + '&';
    }
    url = url.slice(0, -1);
    return url;
  }

  let gridsetName = 'EPSG:4326';

  let params = {
    'REQUEST': 'GetTile',
    'SERVICE': 'WMTS',
    'VERSION': '1.0.0',
    'LAYER': layer,
    'STYLE': '',
    'TILEMATRIX': gridsetName + ':{z}',
    'TILEMATRIXSET': gridsetName,
    'FORMAT': 'application/json;type=geojson',
    'TILECOL': '{x}',
    'TILEROW': '{y}'
  };

  //切片名
  let matrixIds = ['EPSG:4326:0', 'EPSG:4326:1', 'EPSG:4326:2', 'EPSG:4326:3',
    'EPSG:4326:4', 'EPSG:4326:5', 'EPSG:4326:6', 'EPSG:4326:7', 'EPSG:4326:8',
    'EPSG:4326:9', 'EPSG:4326:10', 'EPSG:4326:11', 'EPSG:4326:12', 'EPSG:4326:13',
    'EPSG:4326:14', 'EPSG:4326:15', 'EPSG:4326:16', 'EPSG:4326:17', 'EPSG:4326:18',
    'EPSG:4326:19', 'EPSG:4326:20', 'EPSG:4326:21'];

  //分辨率
  let resolutions = [0.703125, 0.3515625, 0.17578125, 0.087890625, 0.0439453125,
    0.02197265625, 0.010986328125, 0.0054931640625, 0.00274658203125, 0.001373291015625,
    6.866455078125E-4, 3.4332275390625E-4, 1.71661376953125E-4, 8.58306884765625E-5,
    4.291534423828125E-5, 2.1457672119140625E-5, 1.0728836059570312E-5, 5.364418029785156E-6,
    2.682209014892578E-6, 1.341104507446289E-6, 6.705522537231445E-7, 3.3527612686157227E-7];

  //设置地图投影
  let projection = new Projection({
    code: 'EPSG:4326',
    units: 'degrees',
    axisOrientation: 'neu'
  });

  return new VectorTileLayer({
    source: new VectorTileSource({
      url: urlConstruct(),
      format: new GeoJSON({}),    //切片格式
      projection: projection,
      tileGrid: new WMTSTileGrid({
        tileSize: [256, 256],
        extent: [-180.0, -90.0, 180.0, 90.0],  //范围
        origin: [-180.0, 90.0],   //切片原点
        resolutions: resolutions,   //分辨率
        matrixIds: matrixIds    //层级标识列表,与地图级数保持一致
      })
    }),
    wrapX: false,
  });
// let views = new View({
//   center: [117.28, 31.86],
//   projection: projection,
//   zoom: 6,
//   resolutions: resolutions,
//   extent: [-180.0, -90.0, 180.0, 90.0]
// });

}

export default xysGetVectorTileLayer
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值