将url中localhost端口改为当前host端口

This commit is contained in:
zh
2025-07-11 09:19:20 +08:00
parent 399725ed06
commit 579b76dc0e
8 changed files with 99 additions and 23 deletions

View File

@ -14,6 +14,7 @@ import { getTheme, setTheme } from "../Obj/Element/theme";
import { setActiveViewer as setMultiViewportActiveViewer } from './MultiViewportMode'
import { setActiveViewer as setSplitActiveViewer, getSdk } from './SplitScreen'
import { updateCluster } from './cluster/cluster'
import { getHost } from "../on";
let coordinateSystem = 'EPSG:4326'
let _cartesian
@ -244,6 +245,16 @@ function setBillboardDefaultUrl(url, name) {
else {
name = 'billboard_default_url'
}
let host = getHost()
if (!url.startsWith("http")) {
//说明是本地的json在磁盘中存在的
if (!url.includes(":")) {
if (host) {
let o = new URL(url, host)
url = o.href
}
}
}
localStorage.setItem(name, url);
}
/*获取广告牌默认图标*/

View File

@ -145,15 +145,7 @@ class Model extends BaseModel {
if (!this.sdk || !this.sdk.viewer || !this.sdk.viewer.scene) {
return
}
if (!url.startsWith("http")) {
//说明是本地的json在磁盘中存在的
if (!url.includes(":")) {
if (this.options.host) {
let o = new URL(url, this.options.host)
url = o.href
}
}
}
url = this.replaceHost(url, this.options.host)
// this.handler = new Cesium.ScreenSpaceEventHandler(
// this.sdk.viewer.canvas
// )
@ -1336,7 +1328,9 @@ class Model extends BaseModel {
this.name = this.options.name || '未命名对象'
this.originalOptions = this.deepCopyObj(this.options)
this._DialogObject.close()
this.Dialog.confirmCallBack && this.Dialog.confirmCallBack(this.originalOptions)
let cdoptions = this.deepCopyObj(this.options)
cdoptions.host = ''
this.Dialog.confirmCallBack && this.Dialog.confirmCallBack(cdoptions)
syncData(this.sdk, this.options.id)
syncSplitData(this.sdk, this.options.id)
},

View File

@ -247,7 +247,9 @@ class BaseTerrain extends BaseSource {
}
this.originalOptions = this.deepCopyObj(this.options)
this._DialogObject.close()
this.Dialog.confirmCallBack && this.Dialog.confirmCallBack(this.originalOptions)
let cdoptions = this.deepCopyObj(this.options)
cdoptions.host = ''
this.Dialog.confirmCallBack && this.Dialog.confirmCallBack(cdoptions)
},
// resetCallBack: () => {
// this.name = this.originalOptions.name

View File

@ -211,8 +211,9 @@ class BillboardObject extends Base {
let index = 0
let font = getFontFamily(that.labelFontFamily) || 'Helvetica'
let url = that.replaceHost(that.options.billboard.image, that.options.host)
that._frameImages = []
if (that.options.billboard.image && that.options.billboard.image.endsWith('gif')) {
if (url && url.endsWith('gif')) {
isGlf = true
switch (that.options.heightMode) {
case 2:
@ -222,7 +223,7 @@ class BillboardObject extends Base {
}
let gifImg = document.createElement('img')
gifImg.setAttribute('rel:animated_src', that.options.billboard.image)
gifImg.setAttribute('rel:animated_src', url)
gifImg.setAttribute('rel:auto_play', '1')
const imgDiv = document.createElement('div')
imgDiv.appendChild(gifImg)
@ -272,7 +273,7 @@ class BillboardObject extends Base {
else {
let image = new Image()
image.src =
that.options.billboard.image ||
url ||
that.getSourceRootPath() + '/img/A-ablu-blank.png'
switch (that.options.heightMode) {
case 2:
@ -720,11 +721,21 @@ class BillboardObject extends Base {
}
get billboardImage() {
return this.options.billboard.image
let url = this.options.billboard.image
if (url && !url.startsWith("http")) {
//说明是本地的json在磁盘中存在的
if (!url.includes(":")) {
if (this.options.host) {
let o = new URL(url, this.options.host)
url = o.href
}
}
}
return url
}
set billboardImage(v) {
let _this = this
this.options.billboard.image = v
this.options.billboard.image = this.replaceHost(v, this.options.host)
let url =
this.options.billboard.image ||
getBillboardDefaultUrl(this.options.billboard.defaultImage) ||
@ -1497,10 +1508,11 @@ class BillboardObject extends Base {
}
set billboardDefaultImage(v) {
setBillboardDefaultUrl(v, this.options.billboard.defaultImage)
let url = this.replaceHost(v, this.options.host)
setBillboardDefaultUrl(url, this.options.billboard.defaultImage)
this._elms.billboardDefaultImage &&
this._elms.billboardDefaultImage.forEach(item => {
item.src = v
item.src = url
})
}
@ -1575,8 +1587,10 @@ class BillboardObject extends Base {
}
this.originalOptions = this.deepCopyObj(this.options)
this._DialogObject.close()
let cdoptions = this.deepCopyObj(this.options)
cdoptions.host = ''
this.Dialog.confirmCallBack &&
this.Dialog.confirmCallBack(this.originalOptions)
this.Dialog.confirmCallBack(cdoptions)
syncData(this.sdk, this.options.id)
syncSplitData(this.sdk, this.options.id)
},

View File

@ -594,12 +594,13 @@ class GroundSvg extends Base {
}
init() {
let url = this.replaceHost(this.options.url, this.options.host)
syncData(this.sdk, this.options.id)
this.hierarchys = []
this.originalOptions = this.deepCopyObj(this.options)
let geometryArray = []
const loader = new SVGLoader();
loader.load(this.options.url, (data) => {
loader.load(url, (data) => {
if (!this.sdk || !this.sdk.viewer || !this.sdk.viewer.entities) {
return
}
@ -923,7 +924,9 @@ class GroundSvg extends Base {
this.text && (this.options.text.position = { lng: this.text.position[0], lat: this.text.position[1], alt: this.text.position[2] })
this.originalOptions = this.deepCopyObj(this.options)
this._DialogObject.close()
this.Dialog.confirmCallBack && this.Dialog.confirmCallBack(this.originalOptions)
let cdoptions = this.deepCopyObj(this.options)
cdoptions.host = ''
this.Dialog.confirmCallBack && this.Dialog.confirmCallBack(cdoptions)
syncData(this.sdk, this.options.id)
syncSplitData(this.sdk, this.options.id)
},

View File

@ -1305,9 +1305,10 @@ class TrajectoryMotion extends Base {
}
// 创建模型
static async addModel(that) {
let url = that.replaceHost(that.options.model.url, that.options.host)
let options = {
id: that.options.id,
url: that.options.model.url,
url: url,
show: that.options.show ? that.options.model.show : false,
scale: that.options.model.scale,
// minimumPixelSize: that.options.model.pixelSize,
@ -2285,7 +2286,7 @@ class TrajectoryMotion extends Base {
async changeModelUrl(url) {
this.sdk.viewer.scene.primitives.remove(this.model)
this.options.model.url = url
this.options.model.url = this.replaceHost(url, this.options.host)
let matrix = this.model.modelMatrix
let position = this.model.position
let options = {

View File

@ -6,6 +6,7 @@
* @update: 2023-12-01 12:12
*/
import Tools from "../../Tools";
import { getHost, getToken } from "../../on";
import { regLeftClickCallback, regRightClickCallback, regMoveCallback } from "../../Global/ClickCallback";
import { regLeftClickCallback as regLeftClickCallback2, regRightClickCallback as regRightClickCallback2, regMoveCallback as regMoveCallback2 } from "../../Global/SplitScreen/ClickCallback";
import { setSplitDirection, syncSplitData, getSdk } from "../../Global/SplitScreen";
@ -27,6 +28,7 @@ class Base extends Tools {
this.clickCallBack = null
this.rightClickCallBack = null
this.picking = true
this.options.host = this.options.host || getHost()
this.setDefaultValue()
// this.sdk.addIncetance(this.options.id, this)

View File

@ -1195,6 +1195,55 @@ class Tools {
return `${year}${month}${day}${hours}${minutes}${seconds}${milliseconds}`;
}
replaceHost(url, host) {
let newUrl = url
if(!url || !host) {
return url
}
try {
if (!url.startsWith("http")) {
//说明是本地的json在磁盘中存在的
if (!url.includes(":")) {
if (this.options.host) {
let o = new URL(url, this.options.host)
newUrl = o.href
}
}
return newUrl
}
else {
// 移除可能的用户名:密码前缀
const authRegex = /^[^@]+@/;
if (authRegex.test(url)) {
url = url.replace(authRegex, '');
}
// 添加协议前缀(如果没有)
if (!/^[a-z]+:\/\//i.test(url)) {
url = 'http://' + url;
}
const parsedUrl = new URL(url);
const parsedUrl2 = new URL(host);
let hostname = parsedUrl.hostname;
let port = parsedUrl.port;
// 处理IPv6地址如果有括号
if (hostname.startsWith('[') && hostname.endsWith(']')) {
hostname = hostname.slice(1, -1);
}
if ((hostname === 'localhost' || hostname === '127.0.0.1') && parseInt(port, 10) !== 55110) {
parsedUrl.port = parsedUrl2.port
parsedUrl.protocol = parsedUrl2.protocol
newUrl = parsedUrl.toString()
}
return newUrl
}
} catch (error) {
return newUrl
}
}
}