SuperMap iClient for MapLibreGL 根据SQL条件过滤显示动态图层

devtools/2024/10/18 2:25:20/

查阅发现iClient 有子图层控制类 LayerStatus
可实现:子图层显示参数类。此类存储了各个子图层的名称、是否可见的状态、SQL 过滤条件等参数。
API详情:http://support.supermap.com.cn:8090/iserver/iClient/forJavaScript/docs/maplibregl/LayerStatus.html
在这里插入图片描述

实现思路:

1、构造StatusParameters 参数数组

 let mymyLayerStatusList = [];//构造子图层显示参数myLayerStatusList.push(new maplibregl.supermap.LayerStatus({layerName: "Grids@World",displayFilter: "false", // 设置子图层显影// displayFilter: "smid = 0",}));

2、通过LayerInfoService创建临时图层

 //构造子图层显示控制参数let statusParameters = new maplibregl.supermap.SetLayerStatusParameters({myLayerStatusList: myLayerStatusList,});let layerInfoService = new maplibregl.supermap.LayerInfoService(url);//子图层显示控制服务。负责将子图层显示控制参数传递到服务端,并获取服务端返回的图层显示状态。layerInfoService.setLayerStatus(statusParameters, (res) => {})

3、根据layersID加载临时图层

 sources: {"raster-tiles": {attribution: "",type: "raster",// 拼接临时图层地址tiles: [url + "/zxyTileImage.png?prjCoordSys=" + encodeURIComponent('{"epsgCode":3857}') +"&z={z}&x={x}&y={y}&noWrap=true&transparent=true&cacheEnabled=false&layersID=" +tempMapId,],tileSize: 256,},

完整代码

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>根据SQL条件过滤显示动态图层</title><linkrel="stylesheet"href="https://iclient.supermap.io/web/libs/maplibre-gl-js/4.3.2/maplibre-gl.min.css"/><script src="https://iclient.supermap.io/web/libs/maplibre-gl-js/4.3.2/maplibre-gl.min.js"></script><linkrel="stylesheet"href="https://iclient.supermap.io/web/libs/maplibre-gl-js-enhance/4.3.0-1/maplibre-gl-enhance.css"/><script src="https://iclient.supermap.io/web/libs/maplibre-gl-js-enhance/4.3.0-1/maplibre-gl-enhance.js"></script><script src="https://iclient.supermap.io/dist/maplibregl/iclient-maplibregl-es6.min.js"></script><style>body {margin: 0;padding: 0;}#map {position: absolute;top: 0;bottom: 0;width: 100%;}</style></head><body><div id="map"></div></body><script>let url ="http://support.supermap.com.cn:8090/iserver/services/map-world/rest/maps/%E4%B8%96%E7%95%8C%E5%9C%B0%E5%9B%BE_Day";let mymyLayerStatusList = [];//构造子图层显示参数myLayerStatusList.push(new maplibregl.supermap.LayerStatus({layerName: "Grids@World",displayFilter: "false", // 设置子图层显影// displayFilter: "smid = 0",}));myLayerStatusList.push(new maplibregl.supermap.LayerStatus({layerName: "continent_T@World",displayFilter: "true", // 设置子图层显影displayFilter: "smid = 5",}));myLayerStatusList.push(new maplibregl.supermap.LayerStatus({layerName: "Countries@World",isVisible: "true", // 设置子图层显影displayFilter: "smid > 200",}));myLayerStatusList.push(new maplibregl.supermap.LayerStatus({layerName: "Countries@World#1",isVisible: "true", // 设置子图层显影displayFilter: "smid > 200",}));//构造子图层显示控制参数let statusParameters = new maplibregl.supermap.SetLayerStatusParameters({myLayerStatusList: myLayerStatusList,});let layerInfoService = new maplibregl.supermap.LayerInfoService(url);//子图层显示控制服务。负责将子图层显示控制参数传递到服务端,并获取服务端返回的图层显示状态。layerInfoService.setLayerStatus(statusParameters, (res) => {if (res.result) {//获取临时图层idlet tempMapId = res.result.newResourceID;console.log(tempMapId);let map = new maplibregl.Map({container: "map",style: {version: 8,sources: {"raster-tiles": {attribution: "",type: "raster",// 拼接临时图层地址tiles: [url +"/zxyTileImage.png?prjCoordSys=" +encodeURIComponent('{"epsgCode":3857}') +"&z={z}&x={x}&y={y}&noWrap=true&transparent=true&cacheEnabled=false&layersID=" +tempMapId,],tileSize: 256,},},layers: [{id: "simple-tiles",type: "raster",source: "raster-tiles",minzoom: 0,maxzoom: 22,},],},center: [100, 50],maxZoom: 18,zoom: 2,});map.addControl(new maplibregl.supermap.LogoControl(), "bottom-right");map.addControl(new maplibregl.NavigationControl(), "top-left");}});</script>
</html>

http://www.ppmy.cn/devtools/123043.html

相关文章

一些以前使用的linux及shell命令,gnuplot脚本

tar tar -cvzf xxx.tar.gz * -c&#xff0c;--create 创建新的tar文件 -v&#xff0c;--verbose 列出每一步处理涉及的文件的信息&#xff0c;只用一个“v”时&#xff0c;仅列出文件名 使用两个“v”时&#xff0c;列出权限、所有者、大小、时间、文件名等信息 -z&#xff0c…

3dsMax添加天空盒

点击渲染&#xff0c;环境 &#xff0c; 点击位图 找到要设置的天空HDR&#xff0c;可以使用HDR(EXR)贴图 一个可以下载HDR贴图的网站 https://polyhaven.com/hdris在渲染的时候不要使用使用微软输入法&#xff0c;3dsmax会卡死&#xff0c; 在渲染的时候不要使用使用微软…

在线教育系统开发:SpringBoot框架的实战应用

4系统概要设计 4.1概述 本系统采用B/S结构(Browser/Server,浏览器/服务器结构)和基于Web服务两种模式&#xff0c;是一个适用于Internet环境下的模型结构。只要用户能连上Internet,便可以在任何时间、任何地点使用。系统工作原理图如图4-1所示&#xff1a; 图4-1系统工作原理…

jvm参数解析

JVM(Java Virtual Machine)的参数可以分为几大类,包括标准参数、非标准参数和高级调优参数。这些参数允许你控制JVM的行为、内存管理、垃圾回收策略、性能监控等。以下是一些常见的JVM参数分类和它们的用途: 1. 标准参数 这些是跨平台的基本JVM参数,大多数JVM实现都支持…

【30天玩转python】自动化与脚本编写

自动化与脚本编写 Python 因其简洁的语法和强大的标准库&#xff0c;非常适合用于自动化任务和编写脚本。通过编写 Python 脚本&#xff0c;可以自动执行重复性工作、简化日常任务、批量处理文件和数据&#xff0c;甚至管理服务器等。本篇文章将介绍如何使用 Python 编写自动化…

【视频目标分割-2024CVPR】Putting the Object Back into Video Object Segmentation

Cutie 系列文章目录1 摘要2 引言2.1背景和难点2.2 解决方案2.3 成果 3 相关方法3.1 基于记忆的VOS3.2对象级推理3.3 自动视频分割 4 工作方法4.1 overview4.2 对象变换器4.2.1 overview4.2.2 Foreground-Background Masked Attention4.2.3 Positional Embeddings 4.3 Object Me…

【JavaEE】http/https 超级详解

&#x1f525;个人主页&#xff1a; 中草药 &#x1f525;专栏&#xff1a;【Java】登神长阶 史诗般的Java成神之路 &#x1f98a;一.定义 HTTP&#xff08;HyperText Transfer Protocol&#xff09;即超文本传输协议&#xff0c;他是应用非常广泛的应用层协议&#xff0c;是…

序列化与反序列化基础及反序列化漏洞(附案例)

参考文章&#xff1a; [web安全原理]PHP反序列化漏洞 - 笑花大王 - 博客园 (cnblogs.com) 一、概念 为了能有效的存储数据而不丢失数据的类型和内容&#xff0c;经常需要通过序列化对数据进行处理&#xff0c;将数据进行序列化后&#xff0c;会生成一个字符串&#xff0c;字符…