<template>
  <view>
    <web-view :src="mapUrl"/>
  </view>
</template>

<script>
import {
  getChecklistInspectionStatusRecordViewOtherHiddenDangerList
} from "@/api";
import gcoord from '@/common/gcoord.js'
import imgH from "@/static/h.png";

export default {
  data() {
    return {
      id: '',
      mapUrl: '',
    }
  },
  onLoad(event) {
    this.id = event.id;
    this.getData()
  },
  methods: {
    async getData() {
      let { data } = await getChecklistInspectionStatusRecordViewOtherHiddenDangerList({
        checkrecordId: this.id,
      });
      const covers = []
      for (let i = 0; i < data.length; i++) {
        if (
            !this.isEmpty(data[i].longitude) &&
            !this.isEmpty(data[i].latitude)
        ) {
          covers.push({
            latitude: data[i].latitude,
            longitude: data[i].longitude,
            iconPath: imgH,
          });
        }
      }
      uni.getLocation({
        type: "GCJ02",
        success: (res) => {
          const result = gcoord.transform(
              [res.longitude, res.latitude],
              gcoord.GCJ02,
              gcoord.BD09
          );
          this.mapUrl =
              "https://skqhdg.porthebei.com:9004/map/map.html?point=" +
              encodeURIComponent(JSON.stringify(covers)) +
              "&longitude=" +
              result[0] +
              "&latitude=" +
              result[1];
        },
        fail: () => {
          uni.showToast({
            title: "获取位置失败",
            icon: "none",
          });
        },
      });
    },
    isEmpty(value) {
      return (
          value === undefined ||
          value === null ||
          value === "undefined" ||
          value === "null" ||
          (typeof value === "object" && Object.keys(value).length === 0) ||
          (typeof value === "string" && value.trim().length === 0)
      );
    }
  }
}
</script>

<style scoped lang="scss"></style>
