Skip to content

Commit 5106b56

Browse files
更新 maplibregl overlay 版本 修复mapv heat 示例
1 parent b895969 commit 5106b56

File tree

7 files changed

+85
-101
lines changed

7 files changed

+85
-101
lines changed

src/maplibregl/overlay/DeckglLayer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { DeckglLayerBase } from '@supermap/iclient-common/overlay/deckgl/DeckglL
88
* @category Visualization DeckGL
99
* @classdesc Deckgl 高效率图层,该图图层为综合图层,通过该图层可创建 高效率点图层、路径图层(线图层)、高效率面图层、曲线图层、
1010
* 正六边形图层(蜂巢图层)、网格图层,只需给定相依配置,因此,在创建图层之前,请仔细阅读参数配置。
11+
* @version 11.1.0
1112
* @param {string} layerTypeID - 高效率图层类型 ID,包括 "scatter-plot" 高效率点图层、"path-layer" 路径图层(线图层)、
1213
* "polygon-layer" 高效率面图层、"arc-layer" 曲线图层、"hexagon-layer" 正六边形图层(蜂巢图层)、"screen-grid-layer" 网格图层。
1314
*

src/maplibregl/overlay/GraphicLayer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* @class GraphicLayer
2424
* @category Visualization Graphic
2525
* @classdesc 高效率点图层。
26+
* @version 11.1.0
2627
* @param {string} [id] - 图层id。默认使用 CommonUtil.createUniqueID("graphicLayer_") 创建专题图层 ID。
2728
* @param {Object} options - 参数。
2829
* @param {Array.<Graphic>} options.graphics - 点要素对象数组 。

src/maplibregl/overlay/GraticuleLayer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import maplibregl from 'maplibre-gl';
1616
* @class GraticuleLayer
1717
* @category Visualization GraticuleLayer
1818
* @classdesc 经纬网。
19-
* @version 10.1.1
19+
* @version 11.1.0
2020
* @param {Object} options - 参数。
2121
* @param {string} [options.layerID] - 图层 ID。默认使用 CommonUtil.createUniqueID("graticuleLayer_") 创建图层 ID。
2222
* @param {boolean} [options.visible=true] - 是否显示经纬网。

src/maplibregl/overlay/HeatMapLayer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { HeatMapLayerRenderer } from '@supermap/iclient-common/overlay/heatmap/H
99
* @class HeatMapLayer
1010
* @classdesc 热力图层类。
1111
* @category Visualization HeatMap
12+
* @version 11.1.0
1213
* @param {string} name - 图层名称。
1314
* @param {Object} options - 构造参数。
1415
* @param {mapboxgl.Map} options.map - MapBoxGL Map 对象。
@@ -91,6 +92,8 @@ export class HeatMapLayer extends mapboxgl.Evented {
9192
onRemove() {
9293
this.removeAllFeatures();
9394
this.renderer.removeFromMap();
95+
this.features = {};
96+
this.renderer = null;
9497
}
9598

9699
render() {

src/maplibregl/overlay/MapvLayer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
* @class MapvLayer
1212
* @category Visualization MapV
1313
* @classdesc Mapv 图层。
14+
* @version 11.1.0
1415
* @param {mapboxgl.Map} map - MapBoxGL Map 对象,将在下个版本弃用,请用 map.addLayer() 方法添加图层。
1516
* @param {Mapv.DataSet} dataSet - MapV 图层数据集。
1617
* @param {Object} options - Mapv 参数。
@@ -31,6 +32,7 @@ export class MapvLayer {
3132
this.pitchStartEvent = this.pitchStart.bind(this);
3233
this.pitchEndEvent = this.pitchEnd.bind(this);
3334
this.renderingMode = '3d';
35+
this.context = this.options.context || '2d';
3436
}
3537

3638
onAdd(map) {
@@ -69,7 +71,7 @@ export class MapvLayer {
6971
var zoomUnit = getMeterPerMapUnit('DEGREE') * resolutionX;
7072
var center = map.getCenter();
7173
var centerPx = map.project(center);
72-
74+
var self = this;
7375
function transferCoordinate(coordinate) {
7476
if (map.transform.rotationMatrix || self.context === '2d') {
7577
var worldPoint = map.project(new maplibregl.LngLat(coordinate[0], coordinate[1]));

src/maplibregl/overlay/ThreeLayer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ThreeLayerRenderer } from "@supermap/iclient-common/overlay/threejs/Thr
1515
* @class ThreeLayer
1616
* @category Visualization Three
1717
* @classdesc Three 图层。
18+
* @version 11.1.0
1819
* @param {string} id - 图层 ID。
1920
* @param {string} [renderer="gl"] - 图层渲染方式( canvas 或 WebGL )。取值:"gl","canvas"。
2021
* @param {Object} options - 初始化参数。

src/openlayers/overlay/FGB.js

Lines changed: 75 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,78 @@
11
/* Copyright© 2000 - 2023 SuperMap Software Co.Ltd. All rights reserved.
22
* This program are made available under the terms of the Apache License, Version 2.0
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
4-
import VectorSource from 'ol/source/Vector';
5-
import { deserialize } from 'flatgeobuf/lib/mjs/geojson';
6-
import { buildFeature } from 'flatgeobuf/lib/mjs/generic/feature';
7-
import { parseGeometry } from 'flatgeobuf/lib/mjs/generic/geometry';
8-
import { FetchRequest } from '@supermap/iclient-common/util/FetchRequest';
9-
import { all, bbox } from 'ol/loadingstrategy';
10-
import { getIntersection } from '@supermap/iclient-common/util/MapCalculateUtil';
11-
import GeoJSON from 'ol/format/GeoJSON';
12-
import clonedeep from 'lodash.clonedeep';
13-
import { v4 as uuidv4 } from 'uuid';
14-
/**
15-
* @class FGB
16-
* @browsernamespace ol.source
17-
* @category Visualization FGB
18-
* @classdesc FGB 图层源,该图层源把 {@link FlatGeobuf} 格式解析为点线面要素。
19-
* @version 11.1.0
20-
* @param {Object} opt_options - 参数。
21-
* @param {string} opt_options.url - FGB 服务地址,例如:http://localhost:8090/iserver/services/xxx/rest/data/featureResults/newResourceId.fgb。
22-
* @param {ol.loadingstrategy} [opt_options.strategy='bbox'] - 指定加载策略,可选值为 ol.loadingstrategy.all,ol/loadingstrategy.bbox。all为全部加载, bbox为当前可见范围加载
23-
* @param {Array} [opt_options.extent] - 加载范围, 参数规范为: [minX, minY, maxX, maxY], 传递此参数后, 图层将使用局部加载。
24-
* @param {function} [opt_options.featureLoader] - 要素加载回调函数
25-
* @param {boolean} [opt_options.overlaps] - 是否优化重叠要素的填充与描边操作
26-
* @param {boolean} [opt_options.useSpatialIndex] - 是否启用要素空间索引
27-
* @param {boolean} [opt_options.wrapX] - 是否平铺地图
28-
* @extends {ol.source.Vector}
29-
* @usage
30-
*/
31-
export class FGB extends VectorSource {
32-
constructor(options) {
33-
const baseOptions = Object.assign({ strategy: bbox }, options);
34-
delete baseOptions.url;
35-
delete baseOptions.extent;
36-
super(baseOptions);
37-
this.options = options || {};
38-
this.strategy = baseOptions.strategy;
39-
this.url = this.options.url;
40-
this.extent = this.options.extent;
41-
this.setLoader(async function (extent) {
42-
if (this.extent && this.strategy === bbox) {
43-
const intersectExtent = getIntersection(this.extent, extent);
44-
extent = intersectExtent && intersectExtent.length ? intersectExtent : this.extent;
45-
}
46-
if (!this.extent && (this.strategy === all || !isFinite(extent[0]))) {
47-
extent = [];
48-
}
49-
let fgbStream;
50-
if (!Object.keys(extent).length) {
51-
fgbStream = await this._getStream(this.url);
52-
}
53-
this._handleFeatures((fgbStream && fgbStream.body) || this.url, extent);
54-
});
55-
}
56-
57-
async _handleFeatures(url, extent) {
58-
let rect = {};
59-
if (extent && extent.length) {
60-
rect = {
61-
minX: extent[0],
62-
minY: extent[1],
63-
maxX: extent[2],
64-
maxY: extent[3]
65-
};
66-
}
67-
let headerMeta = {};
68-
const fgb = deserialize(url, rect, function (metaInfo) {
69-
headerMeta = clonedeep(metaInfo);
70-
console.log('meta', headerMeta);
71-
});
72-
for await (let feature of fgb) {
73-
feature = new GeoJSON().readFeature(feature);
74-
let properties = feature.getProperties();
75-
let columns = [];
76-
headerMeta.columns.forEach((column) => {
77-
if (properties[column.name]) {
78-
columns.push(column);
79-
}
80-
});
81-
headerMeta.columns = columns;
82-
let res = buildFeature(
83-
parseGeometry(feature.getGeometry(), headerMeta.geometryType),
84-
properties,
85-
headerMeta
86-
);
87-
console.log('res', res);
88-
let xxx = uuidv4({}, Array.from(res));
89-
console.log('xxx', xxx);
90-
if (this.options.featureLoader && typeof this.options.featureLoader === 'function') {
91-
feature = this.options.featureLoader(feature);
92-
}
93-
this.addFeature(feature);
94-
}
95-
}
96-
97-
async _getStream(url) {
98-
return await FetchRequest.get(url, {}, { withoutFormatSuffix: true }).then(function (response) {
99-
return response;
100-
});
101-
}
102-
}
4+
import VectorSource from 'ol/source/Vector';
5+
import { deserialize } from 'flatgeobuf/lib/mjs/geojson';
6+
import { FetchRequest } from '@supermap/iclient-common/util/FetchRequest';
7+
import { all, bbox } from 'ol/loadingstrategy';
8+
import { getIntersection } from '@supermap/iclient-common/util/MapCalculateUtil';
9+
import GeoJSON from 'ol/format/GeoJSON';
10+
/**
11+
* @class FGB
12+
* @browsernamespace ol.source
13+
* @category Visualization FGB
14+
* @classdesc FGB 图层源,该图层源把 {@link FlatGeobuf} 格式解析为点线面要素。
15+
* @version 11.1.0
16+
* @param {Object} opt_options - 参数。
17+
* @param {string} opt_options.url - FGB 服务地址,例如:http://localhost:8090/iserver/services/xxx/rest/data/featureResults/newResourceId.fgb。
18+
* @param {ol.loadingstrategy} [opt_options.strategy='bbox'] - 指定加载策略,可选值为 ol.loadingstrategy.all,ol/loadingstrategy.bbox。all为全部加载, bbox为当前可见范围加载
19+
* @param {Array} [opt_options.extent] - 加载范围, 参数规范为: [minX, minY, maxX, maxY], 传递此参数后, 图层将使用局部加载。
20+
* @param {function} [opt_options.featureLoader] - 要素加载回调函数
21+
* @param {boolean} [opt_options.overlaps] - 是否优化重叠要素的填充与描边操作
22+
* @param {boolean} [opt_options.useSpatialIndex] - 是否启用要素空间索引
23+
* @param {boolean} [opt_options.wrapX] - 是否平铺地图
24+
* @extends {ol.source.Vector}
25+
* @usage
26+
*/
27+
export class FGB extends VectorSource {
28+
constructor(options) {
29+
const baseOptions = Object.assign({ strategy: bbox }, options);
30+
delete baseOptions.url;
31+
delete baseOptions.extent;
32+
super(baseOptions);
33+
this.options = options || {};
34+
this.strategy = baseOptions.strategy;
35+
this.url = this.options.url;
36+
this.extent = this.options.extent;
37+
this.setLoader(async function (extent) {
38+
if (this.extent && this.strategy === bbox) {
39+
const intersectExtent = getIntersection(this.extent, extent);
40+
extent = (intersectExtent && intersectExtent.length) ? intersectExtent : this.extent;
41+
}
42+
if (!this.extent && (this.strategy === all || !isFinite(extent[0]))) {
43+
extent = [];
44+
}
45+
let fgbStream;
46+
if (!Object.keys(extent).length) {
47+
fgbStream = await this._getStream(this.url);
48+
}
49+
this._handleFeatures((fgbStream && fgbStream.body) || this.url, extent);
50+
});
51+
}
52+
53+
async _handleFeatures(url, extent) {
54+
let rect = {};
55+
if (extent && extent.length) {
56+
rect = {
57+
minX: extent[0],
58+
minY: extent[1],
59+
maxX: extent[2],
60+
maxY: extent[3]
61+
};
62+
}
63+
const fgb = deserialize(url, rect);
64+
for await (let feature of fgb) {
65+
feature = new GeoJSON().readFeature(feature);
66+
if (this.options.featureLoader && typeof this.options.featureLoader === 'function') {
67+
feature = this.options.featureLoader(feature);
68+
}
69+
this.addFeature(feature);
70+
}
71+
}
72+
73+
async _getStream(url) {
74+
return await FetchRequest.get(url, {}, { withoutFormatSuffix: true }).then(function (response) {
75+
return response;
76+
});
77+
}
78+
}

0 commit comments

Comments
 (0)