<template>
	<div id="ThreeJS" class="three_div"></div>
</template>


<script>
	import {
		getStdMapMixin
	} from "@/mixin/workManagement/getStdMapMixin.js"
	import {
		openDriveMixin
	} from "@/mixin/workManagement/openDriveMixin.js"


	export default {
		name: "OpenDrive",
		mixins: [getStdMapMixin, openDriveMixin],
		components: {
			// vueQr,
			// glHome,
		},
		data() {
			return {
				isLoaded: false,
				lineArr:[],
				startPointJson: {},
				endPointJson: {},
				timer: ''
			};
		},
		props: {
			mapId: {
				type: String,
				default: () => ""
			},
			startPoint: {
				type: Object,
				default: () => {}
			},
			endPoint: {
				type: Object,
				default: () => {}
			},
			sections: {
				type: Array,
				default: () =>[]
			}
		},
		methods: {
			changeMap(fileUrl) {
				this.onFileSelect(fileUrl);
			},
			getMapDetails(mapId) {
				
				this.$axios({
					method: "post",
					url: this.$api.workManagement.mapDetails,
					data: {
						mapId
					}
				}).then((res) => {
					if (res.code == 200) {
						if(this.isLoaded == true){
							this.reloadNewMap(res.info.mapPath);
						}else{
							this.loadMap(res.info.mapPath);
							this.isLoaded = true;
						}
						
					}
				})
			},
			reloadMap(){
				this.reloadOdrMap();
				this.initData();
			},
			initData(){
				// this.startPoint = {};
				// this.endPoint = {};
				// this.sections = [];
			}
		},
		mounted() {
		},
		updated() {

		},
		watch: {
			mapId: {
				handler(newVal, oldVal) {
					this.getMapDetails(newVal);
				}
			},
			startPoint: {
				handler(newVal, oldVal) {
					this.drawPoint(newVal);
				}
			},
			endPoint: {
				handler(newVal, oldVal) {
					this.drawPoint(newVal);
				}
			},
			sections: {
				handler(newVal, oldVal) {
					if(this.lineArr && this.lineArr.length > 0){
						this.lineArr.forEach((elem, index) => {
							this.clearColorLine(elem.roadId, elem.laneId);
						})
						//this.clearPoint();
					}
					newVal.forEach((elem, index) => {
						this.fillColorLine(elem.roadId, elem.laneId);
					})
					this.lineArr = newVal;
				}
			}
		}
	};
</script>
<style scoped lang="less">
	.three_div {
		width: 100% !important;
		height: 100% !important;
	}

	/deep/ canvas {
		width: 100% !important;
		height: 100% !important;
	}
</style>