raintee-maputils 1.0.38 → 1.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6095,11 +6095,190 @@ function sortDataFromCNToEN(data) {
6095
6095
  return a.text.localeCompare(b.text);
6096
6096
  });
6097
6097
  return sortedData
6098
- }
6098
+ }
6099
+
6100
+ function canvasToBase64(canvas, mimeType = 'image/png', quality = 0.92) {
6101
+ if (!canvas || !(canvas instanceof HTMLCanvasElement)) {
6102
+ throw new Error('无效的Canvas元素');
6103
+ }
6104
+
6105
+ try {
6106
+ // 方法1:使用toDataURL(最常用)
6107
+ if (mimeType === 'image/jpeg' || mimeType === 'image/webp') {
6108
+ return canvas.toDataURL(mimeType, quality);
6109
+ } else {
6110
+ return canvas.toDataURL(mimeType);
6111
+ }
6112
+ } catch (error) {
6113
+ console.error('Canvas转Base64失败:', error);
6114
+ throw error;
6115
+ }
6116
+ }
6117
+
6118
+ function createElementById(id, callback, options = {}) {
6119
+ // 参数验证
6120
+ if (typeof id !== 'string' || typeof callback !== 'function') {
6121
+ console.error('参数错误:id必须是字符串,callback必须是函数');
6122
+ return null;
6123
+ }
6124
+
6125
+ // 查找现有元素
6126
+ let element = document.getElementById(id);
6127
+
6128
+ if (element) {
6129
+ try {
6130
+ callback(id);
6131
+ } catch (error) {
6132
+ console.error(`执行回调函数时出错:`, error);
6133
+ }
6134
+ return element;
6135
+ } else {
6136
+
6137
+ try {
6138
+ // 创建元素
6139
+ element = document.createElement('div');
6140
+ element.id = id;
6141
+
6142
+ // 设置默认配置
6143
+ const config = {
6144
+ width: 1753,
6145
+ height: 1240,
6146
+ zIndex: -1,
6147
+ styles: {}
6148
+ };
6149
+
6150
+ // 合并用户配置
6151
+ Object.assign(config, options);
6152
+
6153
+ // 基础样式
6154
+ const baseStyles = {
6155
+ width: config.width + 'px',
6156
+ height: config.height + 'px',
6157
+ position: 'absolute',
6158
+ zIndex: config.zIndex.toString(),
6159
+ left: '50%',
6160
+ top: '50%',
6161
+ transform: 'translate(-50%, -50%)',
6162
+ ...config.styles
6163
+ };
6164
+
6165
+ // 应用样式
6166
+ Object.assign(element.style, baseStyles);
6167
+
6168
+ // 添加到页面
6169
+ document.body.appendChild(element);
6170
+
6171
+ // 等待DOM更新后执行回调
6172
+ requestAnimationFrame(() => {
6173
+ try {
6174
+ callback(id);
6175
+ } catch (error) {
6176
+ console.error(`执行回调函数时出错:`, error);
6177
+ }
6178
+ });
6179
+
6180
+ return element;
6181
+
6182
+ } catch (error) {
6183
+ console.error(`创建元素 #${id} 时出错:`, error);
6184
+ return null;
6185
+ }
6186
+ }
6187
+ }
6188
+ const Sttqp = (initVal, taskList, processor) => {
6189
+ return new Promise((resolve, reject) => {
6190
+
6191
+ let result = Array.isArray(initVal) ? [...initVal] : [initVal];
6192
+ let processi = 0;
6193
+
6194
+ const processNext = async () => {
6195
+ if (processi >= taskList.length) {
6196
+ resolve(result);
6197
+ return
6198
+ }
6199
+ try {
6200
+ let current = taskList[processi];
6201
+ let res_cu = await processor(current, processi, result);
6202
+
6203
+
6204
+ if (res_cu !== undefined) {
6205
+ result.push(res_cu);
6206
+ }
6207
+
6208
+ processi++;
6209
+ await processNext();
6210
+
6211
+ } catch (error) {
6212
+ console.error(`任务 ${processi} 处理失败:`, error);
6213
+ reject(error);
6214
+ }
6215
+ };
6216
+
6217
+ // 开始处理
6218
+ processNext();
6219
+ })
6220
+ };
6221
+ const CSnapt = async (fts, lys, style) => {
6222
+ return new Promise((resolve, reject) => {
6223
+ createElementById('tem123', async (id) => {
6224
+ const map = sourcemapgl.CreateMapboxMap({
6225
+ container: id,
6226
+ style: style,
6227
+ zoom: 12,
6228
+ center: [104.27, 30.6],
6229
+ pitch: 0,
6230
+ antialias: false,
6231
+ preserveDrawingBuffer: true
6232
+ });
6233
+ map.on('load', () => {
6234
+ map.getSource('userReport') && map.getSource('userReport').setData(fts);
6235
+ RT_FitBoundsMapboxNative(map, fts);
6236
+ const proccessor = (task) => {
6237
+ return new Promise((resolve, reject) => {
6238
+ try {
6239
+ let s = task;
6240
+ let mlys = map.getStyle().layers.filter(i => i.source === s);
6241
+ let nlys = map.getStyle().layers.filter(i => undefined != i['source-layer'] && i['source-layer'] == 'polygon' && i.source != s);
6242
+ nlys.forEach(i => {
6243
+ map.setLayoutProperty(i.id, 'visibility', 'none');
6244
+ });
6245
+ mlys.forEach(i => {
6246
+ map.setLayoutProperty(i.id, 'visibility', i.type != 'symbol' ? 'visible' : 'none');
6247
+ });
6248
+ map.once('idle', () => {
6249
+ setTimeout(() => {
6250
+ let b = canvasToBase64(map.getCanvas(), 'image/jpeg', 0.8);
6251
+ resolve({
6252
+ id: task,
6253
+ data: b
6254
+ });
6255
+ }, 300);
6256
+ });
6257
+ } catch (error) {
6258
+ reject(error);
6259
+ }
6260
+
6261
+ })
6262
+
6263
+ };
6264
+ Sttqp([], lys, proccessor).then(res => {
6265
+ map.remove();
6266
+ resolve(res);
6267
+ });
6268
+
6269
+ });
6270
+
6271
+ });
6272
+ })
6273
+ };
6099
6274
 
6100
6275
  var RainteeSourceMapTool = /*#__PURE__*/Object.freeze({
6101
6276
  __proto__: null,
6277
+ CSnapt: CSnapt,
6102
6278
  GenerateUniqueId: GenerateUniqueId,
6279
+ Sttqp: Sttqp,
6280
+ canvasToBase64: canvasToBase64,
6281
+ createElementById: createElementById,
6103
6282
  downloadByUrl: downloadByUrl,
6104
6283
  generateKeyValueTableHTML: generateKeyValueTableHTML,
6105
6284
  getLayerIdField: getLayerIdField,