|
116 | 116 | var dataUrl = 'http://172.16.14.44:8090/iserver/services/data-video/rest/data'; |
117 | 117 | var datasourceName = 'VideoData'; |
118 | 118 | 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 | + }; |
119 | 125 | var REAL_MAP_DRAW_SOURCE_ID = 'real-map-draw-sync'; |
120 | 126 | var videoMap; |
121 | 127 | var map; |
122 | 128 | var mapDraw; |
123 | 129 | var measurementMarkers = {}; |
| 130 | + var uploadedDatasetFeatures = {}; |
124 | 131 | var mapFitted = false; |
125 | | - var mapBearing = 90; |
| 132 | + var mapBearing = 270; |
126 | 133 | var videoExtents = []; |
127 | 134 | var lastVideoExtentTime; |
128 | 135 | var tk = '1d109683f4d84198e37a38c442d68311'; |
|
336 | 343 | syncVideoMapDraw(); |
337 | 344 | syncVideoFootprint(); |
338 | 345 | fitVideoBounds(); |
339 | | - videoMap.on('vectorupdate', function () { |
| 346 | + videoMap.on('videoparameterupdate', function () { |
340 | 347 | syncVideoFootprint(videoMap.currentTime); |
341 | 348 | }); |
342 | 349 | videoMap.on('drawupdate', function (e) { |
|
345 | 352 | videoMap.on('drawcreate', function (e) { |
346 | 353 | updateDrawHint(e.data.features.length); |
347 | 354 | fitRealMap(e.data); |
| 355 | + uploadDrawFeature(e.feature); |
348 | 356 | }); |
349 | 357 | videoMap.on('drawdelete', function (e) { |
350 | 358 | updateDrawHint(e.data.features.length); |
|
353 | 361 | updateDrawHint(0); |
354 | 362 | mapFitted = false; |
355 | 363 | }); |
| 364 | + ['NewPoint', 'NewLine', 'NewRegion'].forEach(addUploadedDataset); |
356 | 365 | resizeMaps(); |
357 | 366 | }); |
358 | 367 | }); |
|
464 | 473 | }); |
465 | 474 | } |
466 | 475 |
|
| 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 | + |
467 | 599 | function getFeatureMeasurement(feature) { |
468 | 600 | if (!feature.geometry) { |
469 | 601 | return null; |
|
509 | 641 | map.fitBounds([[bounds[0], bounds[1]], [bounds[2], bounds[3]]], { |
510 | 642 | padding: 48, |
511 | 643 | maxZoom: 17, |
| 644 | + bearing: mapBearing, |
512 | 645 | duration: 600 |
513 | 646 | }); |
514 | 647 | } |
|
0 commit comments