|
@@ -6,7 +6,8 @@
|
|
|
|
|
|
<script>
|
|
|
import AMapLoader from '@amap/amap-jsapi-loader';
|
|
|
-import { smallClassMap } from "@/service/index.js";
|
|
|
+import { smallClassMap } from '@/service/index.js';
|
|
|
+import { mapMutations, mapState, mapGetters } from 'vuex';
|
|
|
export default {
|
|
|
name: 'amap',
|
|
|
data() {
|
|
@@ -22,7 +23,9 @@ export default {
|
|
|
districtExplorer: null,
|
|
|
tipMarker: null,
|
|
|
$tipMarkerContent: null,
|
|
|
- currentAreaNode: null
|
|
|
+ currentAreaNode: null,
|
|
|
+ smallClassMapArr: [],
|
|
|
+ smallMarker: null
|
|
|
};
|
|
|
},
|
|
|
|
|
@@ -32,17 +35,28 @@ export default {
|
|
|
},
|
|
|
watch: {
|
|
|
'$store.state.addr.parentId'(val) {
|
|
|
- console.log(val);
|
|
|
if (this.map) {
|
|
|
this.switch2AreaNode(val);
|
|
|
- this.getDistrict(this.$store.state.addr.parentName, this.$store.state.addr.mapLevel);
|
|
|
+ this.getDistrict(
|
|
|
+ this.$store.state.addr.parentName,
|
|
|
+ this.$store.state.addr.mapLevel
|
|
|
+ );
|
|
|
this.map.clearMap();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
},
|
|
|
- created() {},
|
|
|
+ computed: {
|
|
|
+ ...mapGetters(['vuexSelectCity', 'vuexSelectDistrict', 'vuexSelectStreet'])
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.getSmallClass();
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ ...mapMutations([
|
|
|
+ 'changeSelectCity',
|
|
|
+ 'changeSelectDistrict',
|
|
|
+ 'changeSelectStreet'
|
|
|
+ ]),
|
|
|
initAMap() {
|
|
|
let _this = this;
|
|
|
window._AMapSecurityConfig = {
|
|
@@ -78,6 +92,7 @@ export default {
|
|
|
_this.loadMapData(DistrictExplorer, $);
|
|
|
}
|
|
|
);
|
|
|
+
|
|
|
// this.$nextTick(() => {
|
|
|
// // this.getDistrict()
|
|
|
// });
|
|
@@ -173,16 +188,26 @@ export default {
|
|
|
var adcode = '520000';
|
|
|
//feature被点击
|
|
|
this.districtExplorer.on('featureClick', (e, feature) => {
|
|
|
- that.map.clearMap();
|
|
|
+ // that.map.clearMap();
|
|
|
const props = feature.properties;
|
|
|
- console.log(props);
|
|
|
mapLevel = props.level;
|
|
|
adName = props.name;
|
|
|
+
|
|
|
// that.getDistrict(adName, mapLevel);
|
|
|
- // this.switch2AreaNode(props.adcode);
|
|
|
- this.$store.dispatch('searchArea', { parentId: props.adcode ,name:props.name,mapLevel:props.level});
|
|
|
+ // this.switch2AreaNode(props.adcode);
|
|
|
+ this.$store.dispatch('searchArea', {
|
|
|
+ parentId: props.adcode,
|
|
|
+ name: props.name,
|
|
|
+ mapLevel: props.level
|
|
|
+ });
|
|
|
+ let valCode = props.adcode + '000000';
|
|
|
+ if (props.level == 'city') {
|
|
|
+ this.changeSelectCity({ value: valCode, label: props.name });
|
|
|
+ } else if (props.level == 'district') {
|
|
|
+ this.changeSelectDistrict({ value: valCode, label: props.name });
|
|
|
+ }
|
|
|
// this.$store.commit('changeSelectCity', {value:props.adcode,label:props.name})
|
|
|
- console.log( this.$store.state.addr);
|
|
|
+ console.log(this.$store.state.addr);
|
|
|
});
|
|
|
console.log(this.$store.state.addr);
|
|
|
this.switch2AreaNode(adcode);
|
|
@@ -252,7 +277,6 @@ export default {
|
|
|
},
|
|
|
//切换区域
|
|
|
switch2AreaNode(adcode, callback) {
|
|
|
- console.log(adcode);
|
|
|
if (
|
|
|
this.currentAreaNode &&
|
|
|
'' + this.currentAreaNode.getAdcode() === '' + adcode
|
|
@@ -266,7 +290,9 @@ export default {
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
this.currentAreaNode = areaNode;
|
|
|
+ this.addPolygon();
|
|
|
//设置当前使用的定位用节点
|
|
|
this.districtExplorer.setAreaNodesForLocating([this.currentAreaNode]);
|
|
|
this.refreshAreaNode(areaNode);
|
|
@@ -291,9 +317,86 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- // getSmallClass() {
|
|
|
- // smallClassMap
|
|
|
- // }
|
|
|
+ getSmallClass() {
|
|
|
+ let that = this;
|
|
|
+ smallClassMap().then((res) => {
|
|
|
+ // console.log(res.rows);
|
|
|
+ this.smallClassMapArr = res.rows;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ addPolygon() {
|
|
|
+ this.smallClassMapArr.forEach((item) => {
|
|
|
+ let polyData = JSON.parse(item.mapInfo);
|
|
|
+ let polygon = new AMap.Polygon({
|
|
|
+ map: this.map,
|
|
|
+ path: polyData.features[0].geometry.coordinates,
|
|
|
+ // fillColor: 'red',
|
|
|
+ strokeOpacity: 1,
|
|
|
+ fillOpacity: 0,
|
|
|
+ strokeColor: 'red',
|
|
|
+ strokeWeight: 2,
|
|
|
+ zIndex: 999,
|
|
|
+ cursor: 'pointer'
|
|
|
+ // strokeStyle: 'dashed',
|
|
|
+ // strokeDasharray: [5, 5]
|
|
|
+ });
|
|
|
+ var lanLatArr = [];
|
|
|
+
|
|
|
+ polygon.on('mouseover', (e) => {
|
|
|
+ lanLatArr = [e.lnglat.lng, e.lnglat.lat];
|
|
|
+ let smallLabel =
|
|
|
+ "<div class='info-small'>" +
|
|
|
+ "<h5 class='marker-title'>" +
|
|
|
+ item.countyName +
|
|
|
+ '-' +
|
|
|
+ item.smallNumber +
|
|
|
+ '</h5>' +
|
|
|
+ "<div class='marker-content'>" +
|
|
|
+ '<p>小班号:' +
|
|
|
+ item.smallNumber +
|
|
|
+ '</p>' +
|
|
|
+ '<p>样地数:' +
|
|
|
+ item.sampleCount +
|
|
|
+ '</p>' +
|
|
|
+ '<p>村(林班):' +
|
|
|
+ polyData.features[0].properties.CUN +
|
|
|
+ '</p>' +
|
|
|
+ '<p>乡镇(林场):' +
|
|
|
+ item.townName +
|
|
|
+ '</p>' +
|
|
|
+ '</div>' +
|
|
|
+ '</div>';
|
|
|
+ this.smallMarker = new AMap.Marker({
|
|
|
+ position: lanLatArr,
|
|
|
+ icon: require('@/assets/img/small-marker.png'),
|
|
|
+ anchor: 'bottom-center',
|
|
|
+ offset: new AMap.Pixel(0, 0)
|
|
|
+ });
|
|
|
+ this.smallMarker.setLabel({
|
|
|
+ direction: 'right',
|
|
|
+ offset: new AMap.Pixel(-150, -90), //设置文本标注偏移量
|
|
|
+ content: smallLabel //设置文本标注内容
|
|
|
+ });
|
|
|
+ this.smallMarker.setMap(this.map);
|
|
|
+ polygon.setOptions({
|
|
|
+ fillOpacity: 0.7,
|
|
|
+ fillColor: 'yellow'
|
|
|
+ });
|
|
|
+ });
|
|
|
+ polygon.on('mouseout', () => {
|
|
|
+ if (this.smallMarker) {
|
|
|
+ this.smallMarker.setMap(null);
|
|
|
+ this.smallMarker = null;
|
|
|
+ }
|
|
|
+ polygon.setOptions({
|
|
|
+ fillOpacity: 0,
|
|
|
+ fillColor: '#ccebc5'
|
|
|
+ });
|
|
|
+ });
|
|
|
+ this.map.add(polygon);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ setMarker() {}
|
|
|
}
|
|
|
};
|
|
|
</script>
|
|
@@ -347,4 +450,33 @@ export default {
|
|
|
display: block !important;
|
|
|
visibility: inherit !important;
|
|
|
}
|
|
|
+/deep/ .amap-icon img {
|
|
|
+ max-width: 2rem !important;
|
|
|
+ max-height: 2rem !important;
|
|
|
+}
|
|
|
+/deep/ .info-small {
|
|
|
+ background-image: url('../assets/img/small-label.png');
|
|
|
+ background-repeat: no-repeat;
|
|
|
+ background-size: 100% 100%;
|
|
|
+ width: 16rem;
|
|
|
+ height: 10rem;
|
|
|
+ color: #fff;
|
|
|
+ .marker-title {
|
|
|
+ margin: 0 auto;
|
|
|
+ line-height: 30px;
|
|
|
+ }
|
|
|
+ .marker-content {
|
|
|
+ padding: 0 20px 10px 20px;
|
|
|
+ p {
|
|
|
+ text-align: left;
|
|
|
+ font-size: 12px;
|
|
|
+ margin: 0;
|
|
|
+ line-height: 28px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+/deep/ .amap-marker-label {
|
|
|
+ border: 0;
|
|
|
+ background-color: transparent;
|
|
|
+}
|
|
|
</style>
|