/**
 * 水上客运地图功能组件，通过调用封装好的基础地图组件实现特定业务功能
 */
import { fullExtent, clearMap, calculation, changeMap, setCamera,
    layerControl, layerQuery, addGraphic, draw, getDrawGeometry,
    addBoats, addBoatHistory
} from '@/utils/map/ArcgisUtil'

import {GetPjylLinePaths, GetWaterFlightPoints} from "@/apis/ssky";

// 浦江游览航线
export function pjylLine(){
    GetPjylLinePaths().then(res=>{
        for (let i=0;i<res.data.length;i++){
            let lineData = res.data[i]
            let linePoints = lineData.linePoints
            let points = []
            let first = []
            for(let j=0;j<linePoints.length;j++){
                let point = [Number(linePoints[j].x),Number(linePoints[j].y)]
                if(j==0){
                    first = [Number(linePoints[j].x),Number(linePoints[j].y)]
                }
                points.push(point)
            }
            points.push(first)

            let params = {
                // title: res.data[i].get('lineName'),
                type: 'polygon',
                data: points,
                edit: false,
                temp: true,
                clear: false,
                goto: true,
                attributes: null,
                symbol: {
                    type: "simple-fill",
                    color: [50, 205, 50, 0.5],
                    //style: "cross",
                    outline: {
                        color: [255, 0, 0],
                        width: 2
                    }
                }
            }
            // 绘制到地图上
            addGraphic(params)
        }
    })
}

// 浦江游览码头定位
export function onePjylPortLocation(data){
    // 码头定位
    let param = {
        title: data.portName,
        type: 'point',
        data:[data.mapx,data.mapy,20],
        edit: false,
        temp: true,
        clear: false,
        goto: true,
        attributes: null,
        symbol:{
            "type": "picture-marker",
            "url": "images/ssky/bgImgPort.png",
            "width":"300px",
            "height":"10px"
        }
    }
    addGraphic(param)
    // 绘制陆域围栏
    layerQuery({
        title: "waterPassenger",
        layerId: "4",
        where: "码头名称='" + data.portName +"'",
        symbol: null,
        is_draw: true,
        is_clear: false,
        callback: "pjylPortHandle"
    })
}
// 浦江游览码头查询回调
export function pjylPortHandle(res) {
    let data = res.data[0].geometry.rings[0]
    let params = {
        type: 'line-3d',
        data: data,
        edit: false,
        temp: true,
        clear: false,
        goto: true,
        attributes: null,
        title: null
    }
    addGraphic(params)
}

// 对江轮渡码头定位
export function oneDjldPortLocation(data){
    // 码头定位
    let param = {
        title: data.portName,
        type: 'point',
        data:[data.mapx,data.mapy,20],
        edit: false,
        temp: true,
        clear: false,
        goto: true,
        attributes: null,
        symbol:{
            "type": "picture-marker",
            "url": "images/ssky/bgImgPort.png",
            "width":"300px",
            "height":"10px"
        }
    }
    addGraphic(param)
    // 绘制陆域围栏
    layerQuery({
        title: "waterPassenger",
        layerId: "1",
        where: "码头名称='" + data.portName +"'",
        symbol: null,
        is_draw: true,
        is_clear: false,
        callback: "djldPortHandle"
    })
}

// 浦江游览码头查询回调
export function djldPortHandle(res) {
    let data = res.data[0].geometry.rings[0]
    let params = {
        type: 'line-3d',
        data: data,
        edit: false,
        temp: true,
        clear: false,
        goto: true,
        attributes: null,
        title: null
    }
    addGraphic(params)
}

// 对江轮渡航线
export function djldLine(lineName){
    GetWaterFlightPoints({lineName:lineName}).then(res=>{
        let rows = res.data.Rows;
        for (let i=0;i<rows.length;i++){
            let lineData = rows[i]
            let linePoints = lineData.linePoint[0]
            let points = []
            for(let j=0;j<linePoints.length;j++){
                let point = [Number(linePoints[j].x),Number(linePoints[j].y)]
                points.push(point)
            }
            let params = {
                title: lineName,
                type: 'polyline',
                data: points,
                edit: false,
                temp: true,
                clear: false,
                goto: true,
                attributes: null,
                symbol: {
                    type: "simple-line",
                    color: [255, 0, 0],
                    width: 2
                }
            }
            // 绘制到地图上
            addGraphic(params)
        }
    })
}