Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xplot
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
digit_plot
xplot
Commits
2533a109
Commit
2533a109
authored
Sep 03, 2024
by
dliangx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
使用高德地图作为数据源
parent
70796814
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
9 deletions
+49
-9
src/components/land/Land.tsx
+9
-4
src/components/layers/Layers.tsx
+40
-5
No files found.
src/components/land/Land.tsx
View file @
2533a109
...
@@ -6,22 +6,27 @@ import TileLayer from 'ol/layer/Tile';
...
@@ -6,22 +6,27 @@ import TileLayer from 'ol/layer/Tile';
import
OSM
from
'ol/source/OSM'
;
import
OSM
from
'ol/source/OSM'
;
import
'ol/ol.css'
;
import
'ol/ol.css'
;
import
'./Land.css'
import
'./Land.css'
import
XYZ
from
"ol/source/XYZ"
;
const
Land
=
()
=>
{
const
Land
=
()
=>
{
const
mapRef
=
useRef
(
null
);
const
mapRef
=
useRef
(
null
);
const
gaodeSource
=
new
XYZ
({
url
:
'https://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}'
,
});
const
gaodeLayer
=
new
TileLayer
({
source
:
gaodeSource
,
});
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
mapRef
.
current
)
{
if
(
mapRef
.
current
)
{
const
map
=
new
Map
({
const
map
=
new
Map
({
target
:
mapRef
.
current
,
target
:
mapRef
.
current
,
layers
:
[
layers
:
[
new
TileLayer
({
gaodeLayer
source
:
new
OSM
(),
}),
],
],
view
:
new
View
({
view
:
new
View
({
center
:
[
0
,
0
],
center
:
[
0
,
0
],
zoom
:
2
,
zoom
:
3
,
}),
}),
});
});
...
...
src/components/layers/Layers.tsx
View file @
2533a109
import
Footer
from
"../common/Footer"
import
Footer
from
"../common/Footer"
;
import
{
useEffect
,
useRef
}
from
"react"
;
import
Map
from
"ol/Map"
;
import
View
from
"ol/View"
;
import
TileLayer
from
"ol/layer/Tile"
;
import
"ol/ol.css"
;
import
XYZ
from
"ol/source/XYZ"
;
const
Layers
=
()
=>
{
const
mapRef
=
useRef
(
null
);
const
gaodeSource
=
new
XYZ
({
url
:
"https://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}"
,
});
const
Layers
=
()
=>
{
const
gaodeLayer
=
new
TileLayer
({
return
(<>
source
:
gaodeSource
,
});
useEffect
(()
=>
{
if
(
mapRef
.
current
)
{
const
map
=
new
Map
({
target
:
mapRef
.
current
,
layers
:
[
gaodeLayer
],
view
:
new
View
({
center
:
[
0
,
0
],
zoom
:
3
,
minZoom
:
3
,
// 设置最小缩放等级为 5
maxZoom
:
18
,
// 设置最大缩放等级为 15
}),
});
return
()
=>
{
map
.
setTarget
();
};
}
},
[]);
return
(
<>
<
div
ref=
{
mapRef
}
className=
" bottom-14 top-0 w-full absolute"
></
div
>
<
Footer
></
Footer
>
<
Footer
></
Footer
>
</>)
</>
}
);
};
export
default
Layers
;
export
default
Layers
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment