当前位置:网站首页>Vectortilelayer replacement style
Vectortilelayer replacement style
2022-07-26 09:53:00 【Zhou Xiaotiao】
Problem description :
Base map ( Vector slice layer url) unchanged , But you need to add different style Form the effect of animation rotation .
It's not difficult to change the style of the layer , Find the corresponding feature
, Use feature.setStyle
That's all right. . But the problem I encountered in the project was that I couldn't get feature, Or get feature
Unavailable ( As soon as my colleague came across the use of feature.setStyle
Not in effect , Finally, the reason was not found , Finally, add layers of different styles each time you change the style , Then add a pile of layers
, Resulting in a very large map ).
This article is about no feature
How to change the style when ——layer.setStyle
Code details :
// prop: Used for splicing url Of
// layerId: Layers id, Unique identification
// geom: Used to change different style
loadRainForcastLayer(prop, layerId,geom) {
let levelJson = JSON.parse(geom);
// style and setStyle Methods will appear this Point to different problems , So first put it forward
let that = this
// Find all in the map layer, Judge whether the layer to be added already exists
this.getLayers().forEach((layer) => {
if (layer.getProperties().id&&layer.getProperties().id == layerId) {
this.rainForcastLayer = layer;
}
});
// If the layer exists , Change the style directly
if (this.rainForcastLayer) {
this.rainForcastLayer.setVisible(true);
this.rainForcastLayer.setStyle(function(feature,res){
let id = feature.get("id");
// Down here adopt id Get the style of the layer Color ↓
let number=levelJson[id]?levelJson[id]:0
let level=that.getLevel(number)
let text=String(number)==0?"":String(number)
let color=conf.mapViewer.Predicforeca[level]
// From here up adopt id Get the style of the layer Color ↑
let vectorTileStyle = new Style({
stroke: new Stroke({
color: "rgba(255,255,255,0)",
width: 2,
}),
fill: new Fill({
color: color
}),
text: new Text({
// Text style
font: '12px Calibri,sans-serif',
fill: new Fill({
color: '#000'
}),
stroke: new Stroke({
color: '#000',
width: 1,
}),
// Pay attention to this text Can only be string Format , So the previous conversion
text:text
}),
});
return vectorTileStyle
})
return;
}
let style = "";
// Start splicing here url, If there is a complete available url You can skip this paragraph ↓
var gridsetName = "EPSG:4326";
var gridNames = [
"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",
];
let format = "application/vnd.mapbox-vector-tile";
var 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 vectorTileParams = {
REQUEST: "GetTile",
SERVICE: "WMTS",
VERSION: "1.0.0",
LAYER: prop.layer,
STYLE: style,
TILEMATRIX: gridsetName + ":{z}",
TILEMATRIXSET: gridsetName,
FORMAT: format,
TILECOL: "{x}",
TILEROW: "{y}",
};
var projection = new Projection({
code: "EPSG:4326",
units: "degrees",
axisOrientation: "neu",
});
let baseUrl = ipConfig.geoServer + "/gwc/service/wmts";
let url = baseUrl + "?";
for (var param in vectorTileParams) {
url = url + param + "=" + vectorTileParams[param] + "&";
}
// End the splicing here url, If there is a complete available url You can skip this paragraph ↑
// Add this layer for the first time
this.rainForcastLayer = new VectorTileLayer({
style: function(feature){
let id = feature.get("id");
let number=levelJson[id]?levelJson[id]:0;
let level=that.getLevel(number)
let text=String(number)==0?"":String(number)
let color=conf.mapViewer.Predicforeca[level]
let styles=new Style({
stroke: new Stroke({
color: "rgba(255,255,255,0)",
width: 2,
}),
fill: new Fill({
color: color
}),
text: new Text({
// Text style
font: '12px Calibri,sans-serif',
stroke: new Stroke({
color: '#000',
width: 1,
}),
fill: new Fill({
color: '#000'
}),
text:text
})
})
return styles;
},
zIndex: ZINDEXCONSTANT.NINECLASSLAYER,
id: layerId,
projection: projection,
maxResolution: 350,
source: new VectorTileSource({
projection: projection,
tileGrid: new WMTSTileGrid({
tileSize: [256, 256],
origin: [-180.0, 90.0],
resolutions: resolutions,
matrixIds: gridNames,
}),
format: new MVT(),
url: url,
wrapX: true,
tilePixelRatio: 1,
}),
});
this.addLayer(this.rainForcastLayer);
}
The method of map operation is written , Then set a timer directly when animating :
play(){
this.timeInterval = setInterval(() => {
if (this.currentRowIndex < this.forecastList.length - 1) {
this.currentRowIndex++;
} else {
this.currentRowIndex = 0;
}
this.levelJson=JSON.parse(this.forecastList[this.currentRowIndex].predicProduct)
this.loadRainForcastLayer(
{
key: 'layer-rainForcast',
layer:"meteo_qpf:QPF",
title: ' Rainfall forecast ',
},
"layer-rainForcast",
this.forecastList[this.currentRowIndex].predicProduct
);
}, 3000);}
Then when it stops :
stop(){
// Hide the corresponding layer
this.rainForcastLayer && this.rainForcastLayer.setVisible(false);
// Clear timer
clearInterval(this.timeInterval)
}
Then the function can be completed !
边栏推荐
- POJ 1012 Joseph
- 小白搞一波深拷贝 浅拷贝
- [datawhale] [machine learning] Diabetes genetic risk detection challenge
- Redis sentinel mode setup under Windows
- QT handy notes (III) use qtcharts to draw a line chart in VS
- Node 内存溢出及V8垃圾回收机制
- (1) Hand eye calibration of face scanner and manipulator (eye on hand)
- Show default image when wechat applet image cannot be displayed
- Antd treeselect gets the value of the parent node
- Flutter event distribution
猜你喜欢
Sqoop [environment setup 01] CentOS Linux release 7.5 installation configuration sqoop-1.4.7 resolve warnings and verify (attach sqoop 1 + sqoop 2 Latest installation package +mysql driver package res
Solve NPM -v sudden failure and no response
【荧光字效果】
高斯消元求解矩阵的逆(gauss)
2021年山东省中职组“网络空间安全”B模块windows渗透(解析)
[MySQL database] a collection of basic MySQL operations - the basis of seeing (adding, deleting, modifying, and querying)
asp. Net using redis cache
2022 zhongkepan cloud - server internal information acquisition and analysis flag
Leetcode 504. 七进制数
解决npm -v突然失效 无反应
随机推荐
高斯消元求解异或线性方程组
RMQ学习笔记
Logical architecture of MySQL
PHP one-time request lifecycle
Interpretation of the standard of software programming level examination for teenagers_ second level
挡不住了,纯国产PC已就位,美国的软硬件体系垄断正式被破
js 表格自动循环滚动,鼠标移入暂停
论文笔记(SESSION-BASED RECOMMENDATIONS WITHRECURRENT NEURAL NETWORKS)
Use of selectors
莫队学习笔记(一)
R语言ggpubr包ggsummarystats函数可视化分组箱图(自定义分组颜色)并在X轴标签下方添加分组对应的统计值(样本数N、中位数median、四分位数的间距iqr、统计值的色彩和分组图色匹配
[MySQL database] a collection of basic MySQL operations - the basis of seeing (adding, deleting, modifying, and querying)
Development to testing: a six-year road to automation starting from 0
Sqoop [put it into practice 02] sqoop latest version full database import + data filtering + field type support description and example code (query parameter and field type forced conversion)
Sublime install plug-ins
copyTo
【Datawhale】【机器学习】糖尿病遗传风险检测挑战赛
I finished watching this video on my knees at station B
苹果独占鳌头,三星大举复兴,国产手机在高端市场颗粒无收
[fluorescent character effect]