Skip to content

Commit c389b8d

Browse files
[fix]修复UT Jsdoc 例子修改, e.point, escapeHTML
AI-GEN: 70% Cursor
1 parent a5292a4 commit c389b8d

12 files changed

Lines changed: 253 additions & 101 deletions

‎examples/mapboxgl/config.js‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,13 +1882,6 @@ var exampleConfig = {
18821882
thumbnail: 'videoMap.png',
18831883
fileName: 'videoMap'
18841884
},
1885-
// {
1886-
// name: '视频地图标绘对比',
1887-
// name_en: 'Video Map Draw Compare',
1888-
// version: '12.1.1',
1889-
// thumbnail: 'videoMap.png',
1890-
// fileName: 'videoMapDraw'
1891-
// },
18921885
{
18931886
name: '无人机视频',
18941887
name_en: 'UAV video',
@@ -1909,20 +1902,6 @@ var exampleConfig = {
19091902
version: '12.1.1',
19101903
thumbnail: 'videoMapWithTimeDraw.png',
19111904
fileName: 'videoMapWithTimeDraw'
1912-
},
1913-
{
1914-
name: '动态视频地图 - 淮南',
1915-
name_en: 'Dynamic Video Map - Huainan',
1916-
version: '12.1.1',
1917-
thumbnail: 'videoMap_huainan.png',
1918-
fileName: 'videoMapWithTime_huainan'
1919-
},
1920-
{
1921-
name: '动态视频地图标绘对比 - 淮南',
1922-
name_en: 'Dynamic Video Map Draw Compare - Huainan',
1923-
version: '12.1.1',
1924-
thumbnail: 'videoMap_huainan_draw.png',
1925-
fileName: 'videoMapWithTime_huainanDraw'
19261905
}
19271906
]
19281907
}

‎examples/mapboxgl/videoMapWithTimeDraw.html‎

Lines changed: 135 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,20 @@
116116
var dataUrl = 'http://172.16.14.44:8090/iserver/services/data-video/rest/data';
117117
var datasourceName = 'VideoData';
118118
var datasetName = 'DJI_09304';
119+
var dataSourceUrl = dataUrl + '/datasources/' + datasourceName;
120+
var datasetUrl = {
121+
Point: dataSourceUrl + '/datasets/NewPoint',
122+
LineString: dataSourceUrl + '/datasets/NewLine',
123+
Polygon: dataSourceUrl + '/datasets/NewRegion'
124+
};
119125
var REAL_MAP_DRAW_SOURCE_ID = 'real-map-draw-sync';
120126
var videoMap;
121127
var map;
122128
var mapDraw;
123129
var measurementMarkers = {};
130+
var uploadedDatasetFeatures = {};
124131
var mapFitted = false;
125-
var mapBearing = 90;
132+
var mapBearing = 270;
126133
var videoExtents = [];
127134
var lastVideoExtentTime;
128135
var tk = '1d109683f4d84198e37a38c442d68311';
@@ -336,7 +343,7 @@
336343
syncVideoMapDraw();
337344
syncVideoFootprint();
338345
fitVideoBounds();
339-
videoMap.on('vectorupdate', function () {
346+
videoMap.on('videoparameterupdate', function () {
340347
syncVideoFootprint(videoMap.currentTime);
341348
});
342349
videoMap.on('drawupdate', function (e) {
@@ -345,6 +352,7 @@
345352
videoMap.on('drawcreate', function (e) {
346353
updateDrawHint(e.data.features.length);
347354
fitRealMap(e.data);
355+
uploadDrawFeature(e.feature);
348356
});
349357
videoMap.on('drawdelete', function (e) {
350358
updateDrawHint(e.data.features.length);
@@ -353,6 +361,7 @@
353361
updateDrawHint(0);
354362
mapFitted = false;
355363
});
364+
['NewPoint', 'NewLine', 'NewRegion'].forEach(addUploadedDataset);
356365
resizeMaps();
357366
});
358367
});
@@ -464,6 +473,129 @@
464473
});
465474
}
466475

476+
function uploadDrawFeature(feature) {
477+
if (!feature || !feature.geometry) {
478+
return;
479+
}
480+
var targetUrl = datasetUrl[feature.geometry.type];
481+
if (!targetUrl) {
482+
return;
483+
}
484+
var datasetPath = targetUrl.match(/^(.*)\/datasources\/([^/]+)\/datasets\/([^/?#]+)\/?$/);
485+
if (!datasetPath) {
486+
return;
487+
}
488+
var editFeaturesService = new mapboxgl.supermap.FeatureService(datasetPath[1]);
489+
var editFeaturesParams = new mapboxgl.supermap.EditFeaturesParameters({
490+
features: feature,
491+
dataSourceName: decodeURIComponent(datasetPath[2]),
492+
dataSetName: decodeURIComponent(datasetPath[3]),
493+
editType: 'add',
494+
returnContent: true
495+
});
496+
editFeaturesService.editFeatures(editFeaturesParams).then(function (serviceResult) {
497+
if (!serviceResult || !serviceResult.result || !serviceResult.result.succeed) {
498+
return;
499+
}
500+
addUploadedDataset(decodeURIComponent(datasetPath[3]));
501+
}).catch(function (error) {
502+
console.error('视频标绘上传失败:', error);
503+
});
504+
}
505+
506+
function addUploadedDataset(dataset) {
507+
var sqlParam = new mapboxgl.supermap.GetFeaturesBySQLParameters({
508+
queryParameter: { name: dataset + '@' + datasourceName },
509+
targetEpsgCode: '4326',
510+
datasetNames: [datasourceName + ':' + dataset],
511+
toIndex: 99999
512+
});
513+
new mapboxgl.supermap.FeatureService(dataUrl).getFeaturesBySQL(sqlParam).then(function (serviceResult) {
514+
var featureCollection = serviceResult && serviceResult.result && serviceResult.result.features;
515+
if (!featureCollection || !featureCollection.features) {
516+
return;
517+
}
518+
var featuresByKey = uploadedDatasetFeatures[dataset] || {};
519+
featureCollection.features.forEach(function (item) {
520+
var key = item.id == null ? JSON.stringify(item) : String(item.id);
521+
featuresByKey[key] = item;
522+
});
523+
uploadedDatasetFeatures[dataset] = featuresByKey;
524+
var data = {
525+
type: 'FeatureCollection',
526+
features: Object.keys(featuresByKey).map(function (key) {
527+
return featuresByKey[key];
528+
})
529+
};
530+
var sourceId = 'uploaded-draw-' + dataset;
531+
var source = map.getSource(sourceId);
532+
if (source) {
533+
source.setData(data);
534+
syncUploadedDatasetToVideoMap(dataset, data);
535+
return;
536+
}
537+
map.addSource(sourceId, { type: 'geojson', data: data });
538+
map.addLayer({
539+
id: sourceId + '-fill',
540+
type: 'fill',
541+
source: sourceId,
542+
filter: ['==', '$type', 'Polygon'],
543+
paint: { 'fill-color': '#52c41a', 'fill-opacity': 0.2 }
544+
});
545+
map.addLayer({
546+
id: sourceId + '-line',
547+
type: 'line',
548+
source: sourceId,
549+
filter: ['in', '$type', 'LineString', 'Polygon'],
550+
paint: { 'line-color': '#52c41a', 'line-width': 3 }
551+
});
552+
map.addLayer({
553+
id: sourceId + '-point',
554+
type: 'circle',
555+
source: sourceId,
556+
filter: ['==', '$type', 'Point'],
557+
paint: { 'circle-radius': 5, 'circle-color': '#52c41a', 'circle-stroke-width': 1, 'circle-stroke-color': '#fff' }
558+
});
559+
syncUploadedDatasetToVideoMap(dataset, data);
560+
}).catch(function (error) {
561+
console.error('已上传标绘数据查询失败:', error);
562+
});
563+
}
564+
565+
function syncUploadedDatasetToVideoMap(dataset, data) {
566+
if (!videoMap || !videoMap.map || !data) {
567+
return;
568+
}
569+
var sourceId = 'uploaded-draw-' + dataset;
570+
var source = videoMap.sourceCache && videoMap.sourceCache[sourceId];
571+
if (source) {
572+
source.setData(data);
573+
return;
574+
}
575+
videoMap.addSource(sourceId, { type: 'geojson', data: data });
576+
videoMap.addLayer({
577+
id: sourceId + '-fill',
578+
type: 'fill',
579+
source: sourceId,
580+
filter: ['==', '$type', 'Polygon'],
581+
paint: { 'fill-color': '#52c41a', 'fill-opacity': 0.2 }
582+
});
583+
videoMap.addLayer({
584+
id: sourceId + '-line',
585+
type: 'line',
586+
source: sourceId,
587+
filter: ['in', '$type', 'LineString', 'Polygon'],
588+
paint: { 'line-color': '#52c41a', 'line-width': 3 }
589+
});
590+
videoMap.addLayer({
591+
id: sourceId + '-point',
592+
type: 'circle',
593+
source: sourceId,
594+
filter: ['==', '$type', 'Point'],
595+
paint: { 'circle-radius': 5, 'circle-color': '#52c41a', 'circle-stroke-width': 1, 'circle-stroke-color': '#fff' }
596+
});
597+
}
598+
467599
function getFeatureMeasurement(feature) {
468600
if (!feature.geometry) {
469601
return null;
@@ -509,6 +641,7 @@
509641
map.fitBounds([[bounds[0], bounds[1]], [bounds[2], bounds[3]]], {
510642
padding: 48,
511643
maxZoom: 17,
644+
bearing: mapBearing,
512645
duration: 600
513646
});
514647
}

‎examples/mapboxgl/videoMapWithTime_huainanDraw.html‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
var mapSourceCount = 0;
166166
var dynamicLayerIds = [];
167167
var measurementMarkers = {};
168+
var uploadedDatasetFeatures = {};
168169
var mapBearing = 214;
169170
var tk = '1d109683f4d84198e37a38c442d68311';
170171
var attribution =
@@ -345,10 +346,22 @@
345346

346347
function addUploadedDataset(datasetName) {
347348
queryFeatures(datasetName).then(function (serviceResult) {
348-
var featureCollection = serviceResult && serviceResult.result && serviceResult.result.features;
349-
if (!featureCollection || !featureCollection.features) {
349+
var queriedFeatureCollection = serviceResult && serviceResult.result && serviceResult.result.features;
350+
if (!queriedFeatureCollection || !queriedFeatureCollection.features) {
350351
return;
351352
}
353+
var featuresByKey = uploadedDatasetFeatures[datasetName] || {};
354+
queriedFeatureCollection.features.forEach(function (feature) {
355+
var key = feature.id == null ? JSON.stringify(feature) : String(feature.id);
356+
featuresByKey[key] = feature;
357+
});
358+
uploadedDatasetFeatures[datasetName] = featuresByKey;
359+
var featureCollection = {
360+
type: 'FeatureCollection',
361+
features: Object.keys(featuresByKey).map(function (key) {
362+
return featuresByKey[key];
363+
})
364+
};
352365
var sourceId = 'uploaded-draw-source-' + datasetName;
353366
addOrUpdateRealSource('real-' + sourceId, featureCollection, '#e66b2e');
354367
if (!videoMap) {
@@ -616,7 +629,7 @@
616629
videoMap.on('drawclear', function () {
617630
syncVideoDraw({ type: 'FeatureCollection', features: [] });
618631
});
619-
videoMap.on('vectorupdate', function () {
632+
videoMap.on('videoparameterupdate', function () {
620633
updateMeasurementMarkers('video', videoMap, mapDraw.getAll(), true);
621634
updateVideoFootprint();
622635
});

‎src/mapboxgl/control/VideoMapDrawControl.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function resolveControls(options) {
6262
* @param {VideoMap} [options.videoMap] - 视频地图实例。通过 `videoMap.addControl` 添加时会自动注入。
6363
* @param {Object} [options.controls={point:true, line_string:true, polygon:true, trash:true}] - 按钮显隐,`point` / `line_string` / `polygon` / `trash`。不传时默认全部显示;传入后仅 `true` 对应的按钮显示,未指定项隐藏。
6464
* @param {Object} [options.styles] - 点、线、面的全局样式,使用 Mapbox paint 属性名。`point`:`circle-radius` / `circle-color` / `circle-opacity` / `circle-stroke-width` / `circle-stroke-color`;`line`:`line-color` / `line-width` / `line-opacity` / `line-dasharray`;`polygon`:`fill-color` / `fill-opacity` 及轮廓的 `line-*`。选中要素的颜色由 `selected.color` 指定(默认 `#fbb03b`),绘制完成后要素处于选中状态;绘制中的预览线点沿用对应的点、线、面颜色。可通过 `preview.point` / `preview.line` / `preview.polygon` 单独设置绘制中的样式(属性同上,面预览可用 `fill-*` 与轮廓 `line-*`),未设置的属性沿用主样式或默认值。
65+
* @param {string} [options.position='top-left'] - 未在 `videoMap.addControl` 中指定位置时使用的控件位置。
6566
* @example
6667
* videoMap.addControl(new mapboxgl.supermap.VideoMapDrawControl({
6768
* styles: { point: { 'circle-color': '#f00' }, line: { 'line-width': 4 } }
@@ -74,7 +75,8 @@ export class VideoMapDrawControl {
7475
this.options = {
7576
videoMap: options.videoMap,
7677
controls: resolveControls(options),
77-
styles: options.styles
78+
styles: options.styles,
79+
position: options.position || 'top-left'
7880
};
7981
this.videoMap = options.videoMap || null;
8082
this._buttons = {};
@@ -85,6 +87,7 @@ export class VideoMapDrawControl {
8587
}
8688

8789
/**
90+
* @private
8891
* @function VideoMapDrawControl.prototype.setVideoMap
8992
* @description 绑定视频地图实例。
9093
* @param {VideoMap} videoMap - 视频地图。
@@ -100,6 +103,7 @@ export class VideoMapDrawControl {
100103
}
101104

102105
/**
106+
* @private
103107
* @function VideoMapDrawControl.prototype.onAdd
104108
* @description 添加到地图。
105109
* @param {mapboxgl.Map} map - MapboxGL 地图对象。
@@ -139,6 +143,7 @@ export class VideoMapDrawControl {
139143
}
140144

141145
/**
146+
* @private
142147
* @function VideoMapDrawControl.prototype.onRemove
143148
* @description 从地图移除控件。
144149
*/
@@ -156,12 +161,13 @@ export class VideoMapDrawControl {
156161
}
157162

158163
/**
164+
* @private
159165
* @function VideoMapDrawControl.prototype.getDefaultPosition
160166
* @description 默认位置。
161167
* @returns {string} 控件位置。
162168
*/
163169
getDefaultPosition() {
164-
return 'top-left';
170+
return this.options.position;
165171
}
166172

167173
/**

0 commit comments

Comments
 (0)