Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
C
country-energy-ecological-construction
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
范加坤
country-energy-ecological-construction
Commits
b37f335d
Commit
b37f335d
authored
Jul 29, 2021
by
吕超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 初始化地图样式
parent
bf8dc9a8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
9321 additions
and
691 deletions
+9321
-691
.gitignore
.gitignore
+1
-0
Map.vue
src/components/Map/Map.vue
+51
-28
index.js
src/components/Map/config/index.js
+73
-0
map.js
src/components/Map/config/map.js
+78
-0
map.js
src/components/Map/map.js
+0
-0
methaneMap.vue
src/pages/methaneUpgrade/components/methaneMap.vue
+30
-0
index.vue
src/pages/methaneUpgrade/index.vue
+22
-651
Home.vue
src/views/Home.vue
+13
-12
yarn.lock
yarn.lock
+9053
-0
No files found.
.gitignore
View file @
b37f335d
.DS_Store
.DS_Store
node_modules
node_modules
/dist
/dist
/public/fonts
# local env files
# local env files
...
...
src/components/Map/Map.vue
View file @
b37f335d
...
@@ -3,61 +3,83 @@
...
@@ -3,61 +3,83 @@
</
template
>
</
template
>
<
script
>
<
script
>
import
mapboxgl
from
'mapbox-gl'
import
mapboxgl
from
"mapbox-gl"
;
import
{
register
}
from
'./map'
import
{
register
}
from
"./config/map.js"
;
// import style from '@/config/mapStyle.js'
import
style
from
"./config/index.js"
;
export
default
{
export
default
{
props
:
{
props
:
{
center
:
{
center
:
{
type
:
Array
,
type
:
Array
,
default
:
()
=>
[
110
,
30
]
default
:
()
=>
[
110
,
30
]
,
},
},
zoom
:
{
zoom
:
{
type
:
Number
,
type
:
Number
,
default
:
2
default
:
2
,
},
},
mapId
:
{
mapId
:
{
// 接收图层容器的ID
// 接收图层容器的ID
type
:
String
||
undefined
,
type
:
String
||
undefined
,
default
:
'map'
default
:
"map"
,
}
}
,
},
},
data
()
{
data
()
{
return
{
return
{
map
:
null
map
:
null
,
}
}
;
},
},
mounted
()
{
mounted
()
{
this
.
initMap
()
this
.
initMap
()
;
},
},
methods
:
{
methods
:
{
initMap
()
{
initMap
()
{
this
.
map
=
new
mapboxgl
.
Map
({
this
.
map
=
new
mapboxgl
.
Map
({
container
:
this
.
mapId
,
container
:
this
.
mapId
,
zoom
:
this
.
zoom
,
zoom
:
this
.
zoom
,
center
:
this
.
center
,
center
:
[
110
,
30
],
maxZoom
:
18
,
// style: "mapbox://styles/mapbox/dark-v10",
// style: "mapbox://styles/mapbox/dark-v10",
style
:
`
${
process
.
env
.
VUE_APP_BASE_MAP_URL
}
grey_simple.json`
style
:
{
version
:
8
,
center
:
[
110
,
36
],
zoom
:
3
,
sources
:
{},
layers
:
[],
glyphs
:
"./fonts/{fontstack}/{range}.pbf"
,
},
maxZoom
:
19.9
,
minZoom
:
0.1
,
// dragRotate: false,
trackResize
:
true
,
attributionControl
:
false
,
preserveDrawingBuffer
:
true
,
renderWorldCopies
:
false
,
// 地图不重复
// style
// style
})
});
this
.
map
.
on
(
'load'
,
()
=>
{
this
.
map
.
on
(
"load"
,
()
=>
{
let
map
=
this
.
map
let
map
=
this
.
map
;
window
.
map
=
this
.
map
;
// 添加新的地图实例方法, 初始化相关状态
// 添加新的地图实例方法, 初始化相关状态
register
(
mapboxgl
.
Map
.
prototype
)
register
(
mapboxgl
.
Map
.
prototype
)
;
map
.
_initMapState
({
//
map._initMapState({
center
:
this
.
center
,
//
center: this.center,
zoom
:
this
.
zoom
//
zoom: this.zoom
})
//
})
// console.log()
// console.log()
// map.setBaseMap({ sources: style.sources, layers: style.layers })
map
.
setBaseMap
({
sources
:
style
.
sources
,
layers
:
style
.
layers
});
console
.
log
(
'loadload'
,
map
)
// 添加source
this
.
$emit
(
'onload'
,
map
)
Object
.
entries
(
style
.
sources
).
forEach
((
item
)
=>
{
})
map
.
addSource
(
item
[
0
],
item
[
1
]);
}
});
}
}
// 添加layers
style
.
layers
.
forEach
((
item
)
=>
{
map
.
addLayer
(
item
);
});
this
.
$emit
(
"onload"
,
map
);
});
},
},
};
</
script
>
</
script
>
<
style
lang=
"less"
scoped
>
<
style
lang=
"less"
scoped
>
...
@@ -65,6 +87,7 @@ export default {
...
@@ -65,6 +87,7 @@ export default {
position: absolute;
position: absolute;
width: 100%;
width: 100%;
height: 100%;
height: 100%;
overflow: hidden;
}
}
// .pop-class {
// .pop-class {
...
...
src/components/Map/config/index.js
0 → 100644
View file @
b37f335d
export
default
{
version
:
8
,
// glyphs: "./fonts/{fontstack}/{range}.pbf",
sources
:
{
"gt-basemap-streets-v1"
:
{
type
:
"vector"
,
tiles
:
[
process
.
env
.
VUE_APP_MAP_INIT_STYLE
+
"/gt-basemap-streets-v1/{z}/{x}/{y}.vector.pbf"
,
],
minzoom
:
0
,
maxzoom
:
21
,
},
area
:
{
tiles
:
[
`
${
process
.
env
.
VUE_APP_MAP_INIT_STYLE
}
/gx_area/{z}/{x}/{y}.vector.pbf`
,
],
type
:
"vector"
,
maxzoom
:
12
,
},
area_title
:
{
tiles
:
[
`
${
process
.
env
.
VUE_APP_MAP_INIT_STYLE
}
/area_title/{z}/{x}/{y}.vector.pbf`
,
],
type
:
"vector"
,
maxzoom
:
5
,
},
},
layers
:
[
{
id
:
"china_land"
,
source
:
"gt-basemap-streets-v1"
,
"source-layer"
:
"china_land"
,
minzoom
:
0
,
maxzoom
:
21
,
type
:
"line"
,
paint
:
{
"line-color"
:
"rgba(252, 249, 242, 1)"
,
},
},
{
id
:
"province_title"
,
type
:
"symbol"
,
source
:
"area_title"
,
"source-layer"
:
"province"
,
layout
:
{
"text-font"
:
[
"open-sans"
],
"text-field"
:
"{PXZQMC}"
,
"text-size"
:
17
,
"text-max-width"
:
5
,
},
maxzoom
:
7
,
minzoom
:
1
,
paint
:
{
"text-color"
:
"#fff"
,
"text-halo-color"
:
"#000"
,
"text-halo-width"
:
1
,
},
},
{
id
:
"province_outline"
,
type
:
"line"
,
source
:
"area"
,
"source-layer"
:
"province"
,
layout
:
{},
paint
:
{
"line-color"
:
"#fff"
,
"line-width"
:
2
,
"line-blur"
:
1
,
},
},
],
};
src/components/Map/config/map.js
0 → 100644
View file @
b37f335d
// 在mapboxgl.Map中添加新的方法
const
addedMapUtil
=
{
// base map state
_originalMapState
:
null
,
// 设置初始地图状态
_initMapState
(
state
)
{
const
{
center
,
zoom
}
=
state
;
if
(
!
center
||
!
zoom
)
{
throw
new
Error
(
"missing center or zoom!"
);
}
this
.
_originalMapState
=
{
zoom
,
center
,
};
},
// recover map
recover
()
{
// this.setCenter(this._originalMapState.center)
// this.zoomTo(this._originalMapState.zoom)
this
.
flyTo
({
center
:
this
.
_originalMapState
.
center
,
zoom
:
this
.
_originalMapState
.
zoom
,
});
},
baseMap
:
null
,
/**
* @description 设置基础底图
* @param {Object} [baseMap.sources] 底图的sources, 和mapbox style中source格式一致
* @param {Array} [baseMap.layers] 底图的layers, 和mapbox style中layers格式一致
* @param {Object} options style中其它的选项,例如加载一些图层需要特定的字体和雪碧图。 注意:修改sprites、icon、glyphs会导致强制更新,这种情况下可能会导致某些图层丢失
*/
setBaseMap
(
baseMap
,
options
)
{
const
{
sources
,
layers
}
=
baseMap
;
// init map
if
(
!
this
.
baseMap
)
{
this
.
baseMap
=
baseMap
;
// 缓存地图的source和layer
return
;
}
const
style
=
this
.
getStyle
();
// set sources
Object
.
assign
(
style
.
sources
,
sources
);
// set layers
const
oldLayers
=
style
.
layers
;
const
firstLayer
=
oldLayers
[
0
];
if
(
!
firstLayer
)
{
style
.
layers
.
push
(...
layers
);
}
else
{
// step1. remove old base layers
const
layerIds
=
this
.
baseMap
.
layers
.
map
((
layer
)
=>
layer
.
id
);
layerIds
.
forEach
((
layerId
)
=>
{
const
index
=
oldLayers
.
findIndex
((
l
)
=>
l
.
id
===
layerId
);
if
(
index
>
-
1
)
{
oldLayers
.
splice
(
index
,
1
);
}
});
// step2. add new base layers to the top of old layers
style
.
layers
=
layers
.
concat
(
oldLayers
);
// other mapbox style options. eg. glyphs and sprite
if
(
options
)
{
Object
.
assign
(
style
,
options
);
}
this
.
setStyle
(
style
);
}
this
.
baseMap
=
{
sources
,
layers
};
// 缓存地图的source和layer
},
// 获取底图的配置
getBaseMap
()
{
return
this
.
baseMap
;
},
};
export
function
register
(
proto
)
{
Object
.
assign
(
proto
,
addedMapUtil
);
}
src/components/Map/map.js
deleted
100644 → 0
View file @
bf8dc9a8
src/pages/methaneUpgrade/components/methaneMap.vue
0 → 100644
View file @
b37f335d
<
template
>
<div
class=
"methane"
>
<Map
mapId=
"methane"
@
onload=
"onload"
></Map>
</div>
</
template
>
<
script
>
import
Map
from
"@/components/Map/Map.vue"
;
export
default
{
name
:
"methane"
,
data
()
{
return
{};
},
components
:
{
Map
,
},
computed
:
{},
methods
:
{
onload
()
{
console
.
log
(
"地图加载完成"
);
},
},
};
</
script
>
<
style
scoped
lang=
"less"
>
.methane {
height: inherit;
}
</
style
>
src/pages/methaneUpgrade/index.vue
View file @
b37f335d
This diff is collapsed.
Click to expand it.
src/views/Home.vue
View file @
b37f335d
...
@@ -10,10 +10,7 @@
...
@@ -10,10 +10,7 @@
<div
class=
"a-menu"
@
click=
"$router.push('/methane_upgrade')"
>
<div
class=
"a-menu"
@
click=
"$router.push('/methane_upgrade')"
>
沼气
沼气
</div>
</div>
<div
<div
class=
"a-menu"
@
click=
"$router.push('/biomass_energy_warm')"
>
class=
"a-menu"
@
click=
"$router.push('/biomass_energy_warm')"
>
生物
生物
</div>
</div>
<div
<div
...
@@ -43,20 +40,19 @@
...
@@ -43,20 +40,19 @@
<
script
>
<
script
>
export
default
{
export
default
{
name
:
'Home'
,
name
:
"Home"
,
data
()
{
data
()
{
return
{
return
{
// baseUrl: process.env.BASE_URL
// baseUrl: process.env.BASE_URL
}
}
;
},
},
components
:
{
components
:
{
// HelloWorld,
// HelloWorld,
}
}
,
}
}
;
</
script
>
</
script
>
<
style
scoped
lang=
"less"
>
<
style
scoped
lang=
"less"
>
@import url('../assets/css/public.less');
.body {
.body {
width: 100%;
width: 100%;
height: 100%;
height: 100%;
...
@@ -94,7 +90,7 @@ export default {
...
@@ -94,7 +90,7 @@ export default {
font-weight: 700;
font-weight: 700;
letter-spacing: 0.1vh;
letter-spacing: 0.1vh;
color: @main-color;
color: @main-color;
font-family:
'Segoe UI'
, Tahoma, Geneva, Verdana, sans-serif;
font-family:
"Segoe UI"
, Tahoma, Geneva, Verdana, sans-serif;
}
}
}
}
.menu {
.menu {
...
@@ -102,8 +98,8 @@ export default {
...
@@ -102,8 +98,8 @@ export default {
align-items: center;
align-items: center;
margin-right: 40px;
margin-right: 40px;
.a-menu {
.a-menu {
width:
50px
;
width:
50px
;
height:
50px
;
height:
50px
;
background-color: @main-color;
background-color: @main-color;
margin-right: 20px;
margin-right: 20px;
border-radius: 50%;
border-radius: 50%;
...
@@ -114,5 +110,10 @@ export default {
...
@@ -114,5 +110,10 @@ export default {
}
}
}
}
}
}
.content-cont {
width: 100vw;
height: 100vh;
}
}
}
</
style
>
</
style
>
yarn.lock
0 → 100644
View file @
b37f335d
This diff is collapsed.
Click to expand it.
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