Commit 383e1322 by 李伟康

commit 提交

1 parent d9a2eca3
{ {
"name": "glsk-map-sdk", "name": "glsk-mapapi-sdk",
"version": "0.1.0", "version": "0.1.3",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "glsk-map-sdk", "name": "glsk-mapapi-sdk",
"version": "0.1.0", "version": "0.1.3",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"@babel/preset-env": "^7.26.0", "@babel/preset-env": "^7.26.0",
......
{ {
"name": "glsk-map-sdk", "name": "glsk-mapapi-sdk",
"version": "0.1.0", "version": "0.1.4",
"type": "module", "type": "module",
"description": "glsk-map-sdk", "description": "glsk-mapapi-sdk",
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
......
...@@ -7,7 +7,7 @@ export default { ...@@ -7,7 +7,7 @@ export default {
input: 'src/index.js', input: 'src/index.js',
output: [ output: [
{ {
file: 'dist/glsk-map-sdk.js', file: 'dist/glsk-mapapi-sdk.js',
format: 'umd', format: 'umd',
name: 'GlMap', name: 'GlMap',
globals: { globals: {
......
const env = { const envObject = {
1: 'develop', 1: 'develop',
2: 'test', 2: 'test',
3: 'production', 3: 'production',
...@@ -6,24 +6,35 @@ const env = { ...@@ -6,24 +6,35 @@ const env = {
} }
class GlMapSdk { class GlMapSdk {
constructor() { constructor() {
let envNumber = 1, let mapConfig = {
env: 3,
version: 3
},
_callBack = arguments[0] _callBack = arguments[0]
if (arguments.length > 1) { if (arguments.length > 1) {
envNumber = arguments[0] mapConfig = typeof arguments[0] == 'object' ? arguments[0] : mapConfig
_callBack = arguments[1] _callBack = arguments[1]
if (!mapConfig?.env) mapConfig.env = 3
if (!mapConfig?.version) mapConfig.version = 3
} }
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
const fetchConfig = async () => { const fetchConfig = async () => {
try { try {
console.log(envNumber) const response = await fetch(`https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=map-api-js&env=${envObject[mapConfig.env]}`);
const response = await fetch(`https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=map-api-js&env=${env[envNumber]}`); const res = await response.json(),
const res = await response.json(); scriptExists = Array.from(document.head.getElementsByTagName('script')).some(script => script.src === res.apiUrl);
if (!scriptExists) {
const script = document.createElement('script'); const script = document.createElement('script');
script.src = res.apiUrl; script.src = res.apiUrl;
document.head.appendChild(script) document.head.appendChild(script)
script.onload = () => { script.onload = () => {
this.GLMap = new window.$GlMapApi(() => { this.GLMap = new window.$GlMapApi(mapConfig, () => {
_callBack(this) if (_callBack && typeof _callBack == 'function') _callBack(this)
})
}
} else if (_callBack && typeof _callBack == 'function') {
this.GLMap = new window.$GlMapApi(mapConfig, () => {
if (_callBack && typeof _callBack == 'function') _callBack(this)
}) })
} }
} catch (error) { } catch (error) {
...@@ -37,5 +48,11 @@ class GlMapSdk { ...@@ -37,5 +48,11 @@ class GlMapSdk {
let params = Array.prototype.slice.call(arguments, 1) let params = Array.prototype.slice.call(arguments, 1)
return this.GLMap[target](...params) return this.GLMap[target](...params)
} }
get map () {
return this.GLMap._BMAP
}
get mapGL () {
return this.GLMap._BMapGL
}
} }
export default GlMapSdk export default GlMapSdk
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!