Commit 44178018 authored by 吕超's avatar 吕超

merge合并,第二模块添加颜色绘制

parents 21f78201 0cd7699c
...@@ -22,25 +22,37 @@ ...@@ -22,25 +22,37 @@
<script> <script>
export default { export default {
props: {
range: {
type: Array
}
},
data() { data() {
return { return {
curTime: '2009', curTime: '2009',
play: false, play: false,
range: ['2008', '2013'],
pickerOptions: { pickerOptions: {
disabledDate(time) { disabledDate: time => {
return ( return (
new Date('2008').getTime() > time.getTime() || new Date(this.ranges[0]).getTime() > time.getTime() ||
new Date('2015').getTime() < time.getTime() new Date(this.ranges[1]).getTime() < time.getTime()
) )
} }
} }
} }
}, },
computed: {
ranges() {
return this.range
}
},
watch: {
curTime(val) {
this.$emit('dateChange', val)
}
},
methods: { methods: {
showDatePicker() { showDatePicker() {
console.log('asdfsadf')
console.log(this.$refs.datePicker.focus) console.log(this.$refs.datePicker.focus)
this.$refs.datePicker.focus() this.$refs.datePicker.focus()
}, },
...@@ -59,11 +71,16 @@ export default { ...@@ -59,11 +71,16 @@ export default {
} else { } else {
this.clearPlay() this.clearPlay()
} }
}, 1000) }, 2000)
} else { } else {
this.clearPlay() this.clearPlay()
} }
} }
},
mounted() {
setTimeout(() => {
this.curTime = this.ranges[0]
}, 1000)
} }
} }
</script> </script>
......
...@@ -58,6 +58,7 @@ export default { ...@@ -58,6 +58,7 @@ export default {
// 扩大echarts点击面的大小,即点击灰色面也可以触发 // 扩大echarts点击面的大小,即点击灰色面也可以触发
that.chart.getZr().on("click", function (params) { that.chart.getZr().on("click", function (params) {
console.log(params)
const pointInPixel = [params.offsetX, params.offsetY]; const pointInPixel = [params.offsetX, params.offsetY];
if (that.chart.containPixel("grid", pointInPixel)) { if (that.chart.containPixel("grid", pointInPixel)) {
/*此处添加具体执行代码*/ /*此处添加具体执行代码*/
...@@ -66,7 +67,8 @@ export default { ...@@ -66,7 +67,8 @@ export default {
pointInPixel pointInPixel
); );
//X轴序号 //X轴序号
const xIndex = pointInGrid[0]; console.log(pointInGrid)
const xIndex = pointInGrid[1];
//获取当前图表的option //获取当前图表的option
const op = that.chart.getOption(); const op = that.chart.getOption();
...@@ -75,6 +77,7 @@ export default { ...@@ -75,6 +77,7 @@ export default {
if (op.xAxis[0].type === "category") { if (op.xAxis[0].type === "category") {
name = op.xAxis[0].data[xIndex]; name = op.xAxis[0].data[xIndex];
} else { } else {
console.log(xIndex)
name = op.yAxis[0].data[xIndex]; name = op.yAxis[0].data[xIndex];
} }
......
<template>
<div class="legend">
<div class="title">{{ title }}</div>
<div class="main">
<template v-for="(item, index) in colors">
<div :key="index">
<div class="item" v-if="index == 0">
<div class="circle" :style="{ 'background-color': item }"></div>
<label>- {{ range[index] }}</label>
</div>
<div class="item" v-else>
<div class="circle" :style="{ 'background-color': item }"></div>
<label>{{ range[index - 1] }} - {{ range[index] }}</label>
</div>
</div>
</template>
</div>
</div>
</template>
<script>
export default {
data() {
return {}
},
props: {
title: {
type: String
},
colors: {
type: Array
},
range: {
type: Array
}
}
}
</script>
<style lang="less" scoped>
.legend {
position: absolute;
right: 1vh;
bottom: 1vh;
display: flex;
flex-direction: column;
justify-content: flex-start;
.title {
width: 100%;
text-align: left;
padding-left: 0;
margin-bottom: 5px;
color: @main-color;
font-size: 1.3vh;
}
.item {
display: flex;
align-items: center;
.circle {
border-radius: 2px;
width: 17px;
height: 10px;
margin-right: 0.5vh;
}
label {
color: @main-color;
font-size: 1.2vh;
}
}
.item + .item {
margin-top: 0.3vh;
}
}
</style>
\ No newline at end of file
...@@ -54,7 +54,7 @@ export default { ...@@ -54,7 +54,7 @@ export default {
renderWorldCopies: false, // 地图不重复 renderWorldCopies: false, // 地图不重复
// style // style
}); });
this.map.on("load", () => { this.map.on("load", async () => {
let map = this.map; let map = this.map;
window.map = this.map; window.map = this.map;
...@@ -75,12 +75,13 @@ export default { ...@@ -75,12 +75,13 @@ export default {
style.layers.forEach((item) => { style.layers.forEach((item) => {
map.addLayer(item); map.addLayer(item);
}); });
this.addProvinceLayer(); await this.addProvinceLayer();
this.$emit("onload", map); this.$emit("onload", map);
}); });
}, },
addProvinceLayer() { async addProvinceLayer() {
this.$api.data.getProvinceData().then((res) => { const res = await this.$api.data.getProvinceData();
if (res) {
this.map.addSource("province", { this.map.addSource("province", {
type: "geojson", type: "geojson",
data: res.data, data: res.data,
...@@ -91,11 +92,11 @@ export default { ...@@ -91,11 +92,11 @@ export default {
type: "fill", type: "fill",
layout: {}, layout: {},
paint: { paint: {
"fill-outline-color": "#fff",
"fill-color": "rgba(0, 0, 0, 0)", "fill-color": "rgba(0, 0, 0, 0)",
}, },
}); });
console.log(res); }
});
}, },
}, },
}; };
...@@ -103,7 +104,7 @@ export default { ...@@ -103,7 +104,7 @@ export default {
<style lang="less" scoped> <style lang="less" scoped>
.__map { .__map {
position: absolute; // position: absolute;
width: 100%; width: 100%;
height: 100%; height: 100%;
overflow: hidden; overflow: hidden;
......
export default{
province:[
{ code:'10', name:'全国',},
{ code:'11', name:'北京',},
{ code:'12', name:'天津',},
{ code:'13', name:'河北',},
{ code:'14', name:'山西',},
{ code:'15', name:'内蒙',},
{ code:'21', name:'辽宁',},
{ code:'22', name:'吉林',},
{ code:'23', name:'黑龙江',},
{ code:'31', name:'上海',},
{ code:'32', name:'江苏',},
{ code:'33', name:'浙江',},
{ code:'34', name:'安徽',},
{ code:'35', name:'福建',},
{ code:'36', name:'江西',},
{ code:'37', name:'山东',},
{ code:'41', name:'河南',},
{ code:'42', name:'湖北',},
{ code:'43', name:'湖南',},
{ code:'44', name:'广东',},
{ code:'45', name:'广西',},
{ code:'46', name:'海南',},
{ code:'50', name:'重庆',},
{ code:'51', name:'四川',},
{ code:'52', name:'贵州',},
{ code:'53', name:'云南',},
{ code:'54', name:'西藏',},
{ code:'61', name:'陕西',},
{ code:'62', name:'甘肃',},
{ code:'63', name:'青海',},
{ code:'64', name:'宁夏',},
{ code:'65', name:'新疆',},
]
}
\ No newline at end of file
<template> <template>
<div class="biogasManure"> <div class="biogasManure">
<Map mapId="methane" @onload="onload"></Map> <Map mapId="methane" @onload="onload"></Map>
{{ getFilterColor }}
</div> </div>
</template> </template>
<script> <script>
import Map from "@/components/Map/Map.vue"; import Map from "@/components/Map/Map.vue";
import { BiomassData } from "../config/biomass.config.js";
import { color, colorLabel } from "../config/legend.config";
export default { export default {
name: "biogasManure", name: "biogasManure",
props: {
type: {
type: String,
default: "",
},
data: {
type: Array,
default: () => [],
},
},
data() { data() {
return {}; return {
map: null,
};
}, },
components: { components: {
Map, Map,
}, },
computed: {}, computed: {
getFilterColor() {
const obj = BiomassData[this.type].find(
(item) => item.type === "aggregation"
);
const filterCon = ["match", ["get", "province_c"]];
this.data.forEach((item) => {
const currentColor = this.getCurrentColor(item.properties[obj.key]);
filterCon.push(Number(item.properties.pcode), currentColor);
});
filterCon.push("#f00");
return filterCon;
},
},
methods: { methods: {
onload() { onload(map) {
this.map = map;
console.log(this.map.getStyle());
this.setPaintColor();
console.log("地图加载完成"); console.log("地图加载完成");
}, },
getCurrentColor(val) {
if (val > colorLabel[colorLabel.length - 1]) {
return color[color.length - 1];
} else {
let idx = -1;
colorLabel.find((item, index) => {
idx = index;
return item >= val;
});
if (idx !== -1) {
return color[idx];
}
}
},
setPaintColor() {
if (this.map) {
this.map.getLayer("province") &&
this.map.setPaintProperty(
"province",
"fill-color",
this.getFilterColor
);
}
},
},
watch: {
type() {
this.setPaintColor();
},
data() {
this.setPaintColor();
},
}, },
}; };
</script> </script>
......
export const BiomassData = { export const BiomassData = {
gn: [ gn: [
{ key: "gn_local", value: "数量(处)" }, { key: "gn_local", value: "数量(处)", type: "aggregation" },
{ key: "gn_family", value: "供暖户数(万户)" }, { key: "gn_family", value: "供暖户数(万户)" },
{ key: "gn_area", value: "供暖面积(万平米)" }, { key: "gn_area", value: "供暖面积(万平米)" },
], ],
ghcx: [ ghcx: [
{ key: "ghcx_local", value: "数量(处)" }, { key: "ghcx_local", value: "数量(处)", type: "aggregation" },
{ key: "ghcx_output", value: "年产量(万吨)" }, { key: "ghcx_output", value: "年产量(万吨)" },
], ],
rj: [ rj: [
{ key: "rj_num", value: "数量(处)" }, { key: "rj_num", value: "数量(处)", type: "aggregation" },
{ key: "rj_local", value: "运行数量(处)" }, { key: "rj_local", value: "运行数量(处)" },
{ key: "rj_family", value: "供气户数(万户)" }, { key: "rj_family", value: "供气户数(万户)" },
], ],
th: [ th: [
{ key: "th_local", value: "数量(处)" }, { key: "th_local", value: "数量(处)", type: "aggregation" },
{ key: "th_output", value: "年产量(万吨)" }, { key: "th_output", value: "年产量(万吨)" },
], ],
}; };
export const color = [
"#7e82d0",
"#818bd4",
"#8492d7",
"#869adb",
"#89a1de",
"#8dabe2",
"#95c1e2",
"#9bcfe2",
"#a3e4e3",
];
export const colorLabel = [1, 3, 5, 10, 30, 50, 100, 500];
<template> <template>
<div class="BiomassEnergyWarm"> <div class="BiomassEnergyWarm">
<LeftPart :type="statusValue.key"></LeftPart> <LeftPart :type="statusValue.key"></LeftPart>
<BiogasManureMap></BiogasManureMap> <BiogasManureMap :type="statusValue.key" :data="data"></BiogasManureMap>
<StatusControl <StatusControl
:statusStyle="{ position: 'absolute', right: '600px', top: '100px' }" :statusStyle="{ position: 'absolute', right: '600px', top: '100px' }"
:list="statusControlList" :list="statusControlList"
......
...@@ -5,22 +5,39 @@ ...@@ -5,22 +5,39 @@
</template> </template>
<script> <script>
import Map from "@/components/Map/Map.vue"; import Map from '@/components/Map/Map.vue'
export default { export default {
name: "methane", name: 'methane',
data() { data() {
return {}; return {
map: ''
}
}, },
components: { components: {
Map, Map
}, },
computed: {}, computed: {},
methods: { methods: {
onload() { async onload(map) {
console.log("地图加载完成"); this.map = map
this.map.addLayer({
id: 'province',
source: 'province',
type: 'fill',
layout: {},
paint: {
'fill-outline-color': '#fff',
'fill-color': 'rgba(0, 0, 0, 0)'
}
})
await this.$emit('onload', map)
}, },
}, async setBackground(data) {
}; console.log(this.map.getStyle())
await this.map.setPaintProperty('province', 'fill-color', data)
}
}
}
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment