openlayers加载arcgis的VectorTileServer服务图层

openlayers加载arcgis的VectorTileServer服务图层

url示例:http://127.0.0.1/arcgis/rest/services/Hosted/JCDLDT_YX_2K/VectorTileServer

js 复制代码
    /**
     * 加载ArcGis矢量瓦片
     * @param options
     */
    public async loadArcGisVectorTileLayer(options: IaddArcgisLayerConfig) {
        const metadata = await fetch(`${options.url}?f=pjson`).then((r) => r.json());

        const tileGrid: any = this.buildTileGridFromArcGIS(metadata);

        console.log('Full metadata:', metadata);
        console.log('Styles:', metadata.styles); // 查看 styles 信息

        const source = new VectorTileSource({
            format: new MVT(),
            url: `${options.url}/tile/{z}/{y}/{x}.pbf`,
            tileGrid,
            // projection: `EPSG:${metadata.fullExtent.spatialReference.wkid}`,
            projection: `EPSG:4490`,
            wrapX: true,
        });

        const layer = new VectorTileLayer({
            source,
            zIndex: options.index,
        });

        layer.setProperties({
            id: options.layerId,
            group: options.group,
            record: options,
        });

        console.log(layer, 'layer');

        this.map.addLayer(layer);

        // 加载并应用样式
        const styleJson = await fetch(`${options.url}/resources/styles/root.json`).then(r => r.json());

        // 修正样式中的资源路径
        if (styleJson.sprite) {
            styleJson.sprite = `${options.url}/resources/sprites/sprite`;
        }

        if (styleJson.glyphs) {
            styleJson.glyphs = `${options.url}/resources/fonts/{fontstack}/{range}.pbf`;
        }
        if (styleJson.sources?.esri) {
            delete styleJson.sources.esri.url;
            styleJson.sources.esri.tiles = [`${options.url}/tile/{z}/{y}/{x}.pbf`];
            styleJson.sources.esri.tileSize = 512;
        }

        // 构建切片网格
        const resolutions = metadata.tileInfo.lods
            .sort((a, b) => a.level - b.level)
            .map(lod => lod.resolution);

        await applyStyle(layer, styleJson, "esri", { resolutions });
    }



   /**
    * 根据 ArcGIS VectorTileServer 的 pjson 构建 OpenLayers TileGrid
    */
    public buildTileGridFromArcGIS(metadata: any): TileGrid {

        if (!metadata?.tileInfo) {
            throw new Error('ArcGIS VectorTileServer 元数据缺少 tileInfo');
        }

        const tileInfo = metadata.tileInfo;
        const fullExtent = metadata.fullExtent;

        // extent
        const extent: [number, number, number, number] = [
            fullExtent.xmin,
            fullExtent.ymin,
            fullExtent.xmax,
            fullExtent.ymax,
        ];

        // origin
        const origin: [number, number] = [
            tileInfo.origin.x,
            tileInfo.origin.y,
        ];

        const tileSize: number = tileInfo.cols;

        // resolutions 直接使用 metadata 中的值
        const resolutions: number[] = tileInfo.lods
            .sort((a: any, b: any) => a.level - b.level)
            .map((lod: any) => lod.resolution);

        return new TileGrid({
            extent,
            origin,
            tileSize,
            resolutions,
        });
    }

创建4490经纬度地图

js 复制代码
const mapDiv: any = document.querySelector('.mapDiv');
    const projection = new Projection({
      code: `EPSG:4490`,
      units: 'degrees',
      global: false, // 是否全局
    });
    this.projection = projection;
    const map = new Map({
      target: mapDiv,
      layers: [],
      view: new View({
        projection,
        minZoom: 6,
        maxZoom: 21,
        center: [102, 25], // 云南中心点附近
        zoom: 8,
        // 关闭无级缩放地图
        smoothResolutionConstraint: true,
        // 设置边界范围
        extent: [98, 20.5, 106, 30],
        // 确保地图中心点不能移动到边界外
        constrainOnlyCenter: true,
      }),
      controls: [],
    });
相关推荐
小飞大王6661 天前
WebSocket技术与心跳检测
前端·javascript·websocket·网络协议·arcgis
( ˶˙⚇˙˶ )୨⚑︎1 天前
如何下载 ArcGIS 官方数据图层
python·arcgis
zhaoyin19946 天前
智能机器人
arcgis
杨超越luckly10 天前
HTML应用指南:利用GET请求获取中国邮政网点位置信息
前端·python·arcgis·html·php·数据可视化
不超限13 天前
ArcGIS JS 异常之:Invalid language tag: RangeError: Invalid language tag:
开发语言·javascript·arcgis
智航GIS14 天前
SHP数据修复
数据库·arcgis
安宝特 3D CAD14 天前
安宝特方案丨AEC行业数字化转型卡在哪?数据断流!
arcgis·空间数据·bim数据·aec行业数字化转型·空间数据集成
杨超越luckly14 天前
HTML应用指南:利用POST请求获取全国交通银行网点位置信息
大数据·前端·arcgis·html·交通银行
中科GIS地理信息培训15 天前
ArcGIS Pro 3.6新增【空间权重矩阵SWM】工具更新:高阶邻接邻域、共享边界长度对邻居加权、距离衰减模型
线性代数·arcgis·矩阵