Skip to content

Commit

Permalink
fix: 高德底图 token 失效问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Oct 20, 2023
1 parent 19dc4a7 commit 7a6f927
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 30 deletions.
2 changes: 2 additions & 0 deletions examples/builder/.umirc.ts
Original file line number Diff line number Diff line change
@@ -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' },
Expand Down
20 changes: 20 additions & 0 deletions packages/li-editor/src/constants/base-map.ts
Original file line number Diff line number Diff line change
@@ -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';
1 change: 1 addition & 0 deletions packages/li-editor/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './application';
export * from './base-map';
export * from './registry-default';
export * from './widget';
4 changes: 2 additions & 2 deletions packages/li-editor/src/utils/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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),
},
Expand Down
26 changes: 24 additions & 2 deletions packages/li-editor/src/utils/validator.ts
Original file line number Diff line number Diff line change
@@ -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 };
Expand All @@ -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' };
Expand Down
10 changes: 2 additions & 8 deletions packages/li-editor/src/widgets/MapSetting/MapSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
18 changes: 0 additions & 18 deletions packages/li-editor/src/widgets/MapSetting/constant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 7a6f927

Please sign in to comment.