eaeb29cb创建于 2025年2月7日历史提交
import Feature from '../../../../src/ol/Feature.js';
import Map from '../../../../src/ol/Map.js';
import View from '../../../../src/ol/View.js';
import Point from '../../../../src/ol/geom/Point.js';
import VectorTileLayer from '../../../../src/ol/layer/VectorTile.js';
import VectorTileSource from '../../../../src/ol/source/VectorTile.js';
import Circle from '../../../../src/ol/style/Circle.js';
import Fill from '../../../../src/ol/style/Fill.js';
import Stroke from '../../../../src/ol/style/Stroke.js';
import Style from '../../../../src/ol/style/Style.js';
import {createXYZ} from '../../../../src/ol/tilegrid.js';

const points = [
  [0, 0],
  [0, 1000000],
  [1000000, 0],
  [1000000, 1000000],
];

const vectorTileSource = new VectorTileSource({
  tileGrid: createXYZ({
    extent: [-20000000, -10000000, 10000000, 20000000],
    tileSize: 512,
  }),
  tileUrlFunction: (tileCoord) => tileCoord,
  tileLoadFunction(tile, tileCoord) {
    const features = points.map(
      (corner) =>
        new Feature({
          geometry: new Point(corner),
          tileCoord,
        }),
    );
    tile.setFeatures(features);
  },
});

const vectorTileLayer = new VectorTileLayer({
  source: vectorTileSource,
  style: new Style({
    image: new Circle({
      radius: 100,
      fill: new Fill({
        color: 'rgba(255, 0, 0, 0.5)',
      }),
      stroke: new Stroke({
        width: 1,
        color: 'black',
      }),
    }),
  }),
});

const map = new Map({
  target: 'map',
  layers: [vectorTileLayer],
  view: new View({
    center: [0, 0],
    zoom: 4,
  }),
});

map.renderSync();
vectorTileLayer.setDeclutter(true);

render();