diff --git a/examples/builder/.umirc.ts b/examples/builder/.umirc.ts index 6112e4cb..4e19970f 100644 --- a/examples/builder/.umirc.ts +++ b/examples/builder/.umirc.ts @@ -1,9 +1,11 @@ import { defineConfig } from 'umi'; export default defineConfig({ + mfsu: false, history: { type: 'hash', }, + codeSplitting: {jsStrategy: 'granularChunks'}, routes: [ { path: '/', component: 'Project' }, { path: '/builder/:id', component: 'Builder' }, diff --git a/packages/li-editor/src/constants/base-map.ts b/packages/li-editor/src/constants/base-map.ts new file mode 100644 index 00000000..e926aa3b --- /dev/null +++ b/packages/li-editor/src/constants/base-map.ts @@ -0,0 +1,20 @@ +/** + * https://lbs.amap.com/api/javascript-api/guide/abc/prepare + */ +// @ts-ignore +window._AMapSecurityConfig = { + securityJsCode: '8803c38931b6fddc9bbfeee69df8824d', +}; + +export const AMAP_KEY = 'f0230f884bbd54e2913c890cdf45aa7e'; + +// 可用域名白名单 +// locationinsight.antv.antgroup.com +// li.antv.antgroup.com +// *.antgroup-inc.cn +// *.antgroup-inc.com +// *.antfin-inc.com +// *.alipay.net +// localhost +export const MAPBOX_TOKEN = + 'pk.eyJ1IjoibGl1dmlnb25nenVvc2hpIiwiYSI6ImNsYWx2dHlxOTA5NGYzeW9icGd6aDE2NnoifQ.T3wEAOe8HReAyoeu6d6HJw'; diff --git a/packages/li-editor/src/constants/index.ts b/packages/li-editor/src/constants/index.ts index 8cda44e5..46e0dd7f 100644 --- a/packages/li-editor/src/constants/index.ts +++ b/packages/li-editor/src/constants/index.ts @@ -1,3 +1,4 @@ export * from './application'; +export * from './base-map'; export * from './registry-default'; export * from './widget'; diff --git a/packages/li-editor/src/utils/application.ts b/packages/li-editor/src/utils/application.ts index 894dbc2c..aa54eecc 100644 --- a/packages/li-editor/src/utils/application.ts +++ b/packages/li-editor/src/utils/application.ts @@ -2,7 +2,7 @@ import type { Application } from '@antv/li-sdk'; import { parseVersion } from '@antv/li-sdk'; import { Empty_App_Schema } from '../constants'; import type { EditorContextState } from '../types'; -import { validateDatasets, validateLayers, validateMetadata, validWidgets } from './validator'; +import { validateDatasets, validateLayers, validateMap, validateMetadata, validWidgets } from './validator'; export const creatEmptyApplication = (applicationName: string) => { const config: Application = { @@ -29,7 +29,7 @@ export const validateApplicationSchema = (appSchema: Application) => { metadata: appSchema.metadata, datasets: validateDatasets(appSchema.datasets), spec: { - ...appSchema.spec, + map: validateMap(appSchema.spec.map), layers: validateLayers(appSchema.spec.layers), widgets: validWidgets(appSchema.spec.widgets), }, diff --git a/packages/li-editor/src/utils/validator.ts b/packages/li-editor/src/utils/validator.ts index 6e3ba6d7..9fb039c2 100644 --- a/packages/li-editor/src/utils/validator.ts +++ b/packages/li-editor/src/utils/validator.ts @@ -1,7 +1,14 @@ -import type { Application, DatasetSchema, LayerSchema, LocalDatasetSchema, WidgetSchema } from '@antv/li-sdk'; +import type { + Application, + DatasetSchema, + LayerSchema, + LocalDatasetSchema, + MapSchema, + WidgetSchema, +} from '@antv/li-sdk'; import { getDatasetColumns, isLocalDatasetSchema } from '@antv/li-sdk'; import { isEmpty, isUndefined, omit } from 'lodash-es'; -import { AtomWidgetEmptyContainer } from '../constants'; +import { AMAP_KEY, AtomWidgetEmptyContainer, MAPBOX_TOKEN } from '../constants'; export const validateMetadata = (metadata: Application['metadata']) => { const _metadata = { ...metadata }; @@ -17,6 +24,21 @@ export const validateMetadata = (metadata: Application['metadata']) => { return _metadata; }; +export const validateMap = (mapSchema: MapSchema) => { + if (mapSchema.basemap !== 'Map' && isEmpty(mapSchema.config.token)) { + const _mapSchema: MapSchema = { ...mapSchema }; + if (mapSchema.basemap === 'Mapbox') { + _mapSchema.config = { ..._mapSchema.config, token: MAPBOX_TOKEN }; + } else { + _mapSchema.config = { ..._mapSchema.config, token: AMAP_KEY }; + } + + return _mapSchema; + } + + return mapSchema; +}; + export const validateDataset = (dataset: DatasetSchema) => { if (isLocalDatasetSchema(dataset) && dataset.data) { const _dataset: LocalDatasetSchema = { ...dataset, type: 'local' }; diff --git a/packages/li-editor/src/widgets/MapSetting/MapSetting.tsx b/packages/li-editor/src/widgets/MapSetting/MapSetting.tsx index dbfd3bfa..e5500a02 100644 --- a/packages/li-editor/src/widgets/MapSetting/MapSetting.tsx +++ b/packages/li-editor/src/widgets/MapSetting/MapSetting.tsx @@ -2,16 +2,10 @@ import Icon, { DownOutlined } from '@ant-design/icons'; import type { RadioChangeEvent } from 'antd'; import { Button, ConfigProvider, Dropdown, Form, InputNumber, message, Modal, Radio, Space, Tooltip } from 'antd'; import React, { useState } from 'react'; +import { AMAP_KEY as AMAP__KEY, MAPBOX_TOKEN as MAPBOX__TOKEN } from '../../constants'; import { useEditorService, useEditorState } from '../../hooks'; import type { ImplementEditorWidgetProps } from '../../types'; -import { - AMAP_KEY as AMAP__KEY, - BaseMapSvg, - CLS_PREFIX, - GaodeMapStyleConfig, - MapboxStyleConfig, - MAPBOX_TOKEN as MAPBOX__TOKEN, -} from './constant'; +import { BaseMapSvg, CLS_PREFIX, GaodeMapStyleConfig, MapboxStyleConfig } from './constant'; import { MapCenterModal } from './MapCenterModal'; import './MapSetting.less'; diff --git a/packages/li-editor/src/widgets/MapSetting/constant.tsx b/packages/li-editor/src/widgets/MapSetting/constant.tsx index 36626091..634460db 100644 --- a/packages/li-editor/src/widgets/MapSetting/constant.tsx +++ b/packages/li-editor/src/widgets/MapSetting/constant.tsx @@ -81,21 +81,3 @@ export const MapboxStyleConfig = [ type: 'dark', }, ]; - -/** - * https://lbs.amap.com/api/javascript-api/guide/abc/prepare - */ -// @ts-ignore -window._AMapSecurityConfig = { - securityJsCode: '8803c38931b6fddc9bbfeee69df8824d', -}; -// 可用域名白名单 -// locationinsight.antv.antgroup.com -// li.antv.antgroup.com -// *.antgroup-inc.cn -// *.antgroup-inc.com -// *.antfin-inc.com -// *.alipay.net -export const AMAP_KEY = 'f0230f884bbd54e2913c890cdf45aa7e'; -export const MAPBOX_TOKEN = - 'pk.eyJ1IjoibGl1dmlnb25nenVvc2hpIiwiYSI6ImNsYWx2dHlxOTA5NGYzeW9icGd6aDE2NnoifQ.T3wEAOe8HReAyoeu6d6HJw';