Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
M
mars3d
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
frontend
mars3d
Commits
2ed3ef11
Commit
2ed3ef11
authored
Oct 30, 2023
by
wanghao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加popup示例
parent
4a19b66c
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
73 行增加
和
25 行删除
+73
-25
src/widgets/basic/SearchPoi/QueryPopup.tsx
+48
-0
src/widgets/basic/SearchPoi/index.module.less
+5
-0
src/widgets/basic/SearchPoi/index.tsx
+19
-0
src/widgets/basic/SearchPoi/map.ts
+1
-25
没有找到文件。
src/widgets/basic/SearchPoi/QueryPopup.tsx
0 → 100644
查看文件 @
2ed3ef11
import
{
useRef
}
from
"react"
import
styles
from
"./index.module.less"
export
default
function
(
props
)
{
const
attr
=
useRef
<
any
>
({
...
props
.
attr
})
return
(
<
div
className=
{
"mars3d-popup-content-wrapper mars3d-popup-background"
}
>
<
span
className=
"mars3d-popup-close-button mars3d-popup-color closeButton"
>
×
</
span
>
<
div
className=
"mars3d-popup-content-wrapper mars3d-popup-background"
>
<
div
className=
"mars3d-template-titile"
>
<
a
href=
{
"https://www.amap.com/detail/"
+
attr
.
current
.
id
}
target=
"_black"
>
{
attr
.
current
.
name
}
</
a
>
</
div
>
<
div
className=
{
`mars3d-template-content ${styles["mars3d-template-content"]}`
}
>
{
attr
.
current
.
tel
&&
attr
.
current
.
tel
.
length
?
(
<
div
>
<
label
>
电话:
</
label
>
{
attr
.
current
.
tel
}
</
div
>
)
:
(
""
)
}
<
div
>
{
attr
.
current
.
address
?
(
<
div
>
<
label
>
地址:
</
label
>
{
attr
.
current
.
address
}
</
div
>
)
:
(
""
)
}
</
div
>
<
div
>
{
attr
.
current
.
type
?
(
<
div
>
<
label
>
类别:
</
label
>
{
attr
.
current
.
type
}
</
div
>
)
:
(
""
)
}
</
div
>
</
div
>
</
div
>
</
div
>
)
}
src/widgets/basic/SearchPoi/index.module.less
查看文件 @
2ed3ef11
...
@@ -139,3 +139,8 @@
...
@@ -139,3 +139,8 @@
}
}
}
}
}
}
.mars3d-template-content {
padding: 12px;
padding-top: 0;
}
src/widgets/basic/SearchPoi/index.tsx
查看文件 @
2ed3ef11
...
@@ -5,6 +5,9 @@ import * as mapWork from "./map"
...
@@ -5,6 +5,9 @@ import * as mapWork from "./map"
import
{
useLifecycle
}
from
"@mars/widgets/common/uses/useLifecycle"
import
{
useLifecycle
}
from
"@mars/widgets/common/uses/useLifecycle"
import
styles
from
"./index.module.less"
import
styles
from
"./index.module.less"
import
{
renderToString
}
from
"react-dom/server"
import
QueryPopup
from
"./QueryPopup"
const
storageName
=
"mars3d_queryGaodePOI"
const
storageName
=
"mars3d_queryGaodePOI"
const
url
=
"//www.amap.com/detail/"
const
url
=
"//www.amap.com/detail/"
...
@@ -22,6 +25,22 @@ export default function (props) {
...
@@ -22,6 +25,22 @@ export default function (props) {
if
(
searchTxt
===
""
)
{
if
(
searchTxt
===
""
)
{
setSearchListShow
(
false
)
setSearchListShow
(
false
)
}
}
// 绑定popup
mapWork
.
graphicLayer
.
bindPopup
(
(
event
)
=>
{
const
attr
=
event
.
graphic
.
attr
||
{}
if
(
!
attr
)
{
return
}
// 示例比较特殊,使用 renderToString 返回一个html元素;
// 也可使用 createPortal ,具体用法参考react文档 或 mars3d基础项目
const
html
=
renderToString
(<
QueryPopup
attr=
{
attr
}
/>)
return
html
},
{
template
:
false
}
)
})
})
let
timer
=
useRef
<
any
>
()
let
timer
=
useRef
<
any
>
()
...
...
src/widgets/basic/SearchPoi/map.ts
查看文件 @
2ed3ef11
...
@@ -7,7 +7,7 @@ import * as mars3d from "mars3d"
...
@@ -7,7 +7,7 @@ import * as mars3d from "mars3d"
const
Cesium
=
mars3d
.
Cesium
const
Cesium
=
mars3d
.
Cesium
let
map
:
mars3d
.
Map
// 地图对象
let
map
:
mars3d
.
Map
// 地图对象
let
graphicLayer
:
mars3d
.
layer
.
GraphicLayer
export
let
graphicLayer
:
mars3d
.
layer
.
GraphicLayer
let
queryPoi
:
mars3d
.
query
.
GaodePOI
// GaodePOI查询
let
queryPoi
:
mars3d
.
query
.
GaodePOI
// GaodePOI查询
let
address
:
any
=
null
let
address
:
any
=
null
...
@@ -24,30 +24,6 @@ export function onMounted(mapInstance: mars3d.Map): void {
...
@@ -24,30 +24,6 @@ export function onMounted(mapInstance: mars3d.Map): void {
pid
:
99
// 图层管理 中使用,父节点id
pid
:
99
// 图层管理 中使用,父节点id
})
})
graphicLayer
.
bindPopup
(
function
(
event
:
any
)
{
const
item
=
event
.
graphic
?.
attr
if
(
!
item
)
{
return
}
let
inHtml
=
`<div class="mars3d-template-titile"><a href="https://www.amap.com/detail/
${
item
.
id
}
" target="_black" style="color: #ffffff; ">
${
item
.
name
}
</a></div><div class="mars3d-template-content" >`
if
(
item
.
tel
!==
""
)
{
inHtml
+=
"<div><label>电话:</label>"
+
item
.
tel
+
"</div>"
}
if
(
item
.
address
)
{
inHtml
+=
"<div><label>地址:</label>"
+
item
.
address
+
"</div>"
}
if
(
item
.
type
)
{
const
fl
=
item
.
type
if
(
fl
!==
""
)
{
inHtml
+=
"<div><label>类别:</label>"
+
fl
+
"</div>"
}
}
inHtml
+=
"</div>"
return
inHtml
})
map
.
addLayer
(
graphicLayer
)
map
.
addLayer
(
graphicLayer
)
map
.
on
(
mars3d
.
EventType
.
cameraChanged
,
cameraChanged
)
map
.
on
(
mars3d
.
EventType
.
cameraChanged
,
cameraChanged
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论