使用 WebGLVectorTileLayer 渲染 valvesLayer
This commit is contained in:
@@ -29,7 +29,6 @@ import VectorLayer from "ol/layer/Vector";
|
|||||||
import { Icon, Style } from "ol/style.js";
|
import { Icon, Style } from "ol/style.js";
|
||||||
import { FeatureLike } from "ol/Feature";
|
import { FeatureLike } from "ol/Feature";
|
||||||
import { Point } from "ol/geom";
|
import { Point } from "ol/geom";
|
||||||
import VectorTileLayer from "ol/layer/VectorTile";
|
|
||||||
|
|
||||||
interface MapComponentProps {
|
interface MapComponentProps {
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
@@ -216,15 +215,19 @@ const MapComponent: React.FC<MapComponentProps> = ({ children }) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
// 定义 valves 图层的样式函数,使用固定图标
|
// 定义 valves 图层的样式函数,使用固定图标
|
||||||
const valveStyle = () => {
|
// const valveStyle = () => {
|
||||||
const valveIcon = "/icons/valve.svg";
|
// const valveIcon = "/icons/valve.svg";
|
||||||
return new Style({
|
// return new Style({
|
||||||
image: new Icon({
|
// image: new Icon({
|
||||||
src: valveIcon,
|
// src: valveIcon,
|
||||||
scale: 0.1, // 根据需要调整图标大小
|
// scale: 0.1, // 根据需要调整图标大小
|
||||||
anchor: [0.5, 0.5], // 图标锚点居中
|
// anchor: [0.5, 0.5], // 图标锚点居中
|
||||||
}),
|
// }),
|
||||||
});
|
// });
|
||||||
|
// };
|
||||||
|
const valveStyle = {
|
||||||
|
"icon-src": "/icons/valve.svg",
|
||||||
|
"icon-scale": 0.1,
|
||||||
};
|
};
|
||||||
// 定义 pumps 图层的样式函数,使用固定图标
|
// 定义 pumps 图层的样式函数,使用固定图标
|
||||||
const pumpStyle = function (feature: FeatureLike) {
|
const pumpStyle = function (feature: FeatureLike) {
|
||||||
@@ -340,8 +343,8 @@ const MapComponent: React.FC<MapComponentProps> = ({ children }) => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const valvesLayer = new VectorTileLayer({
|
const valvesLayer = new WebGLVectorTileLayer({
|
||||||
source: valveSource,
|
source: valveSource as any,
|
||||||
style: valveStyle,
|
style: valveStyle,
|
||||||
extent: MAP_EXTENT, // 设置图层范围
|
extent: MAP_EXTENT, // 设置图层范围
|
||||||
maxZoom: 24,
|
maxZoom: 24,
|
||||||
|
|||||||
Reference in New Issue
Block a user