import {Component} from '@angular/core';

import * as  AMapLoader from '@amap/amap-jsapi-loader';


(window as any)._AMapSecurityConfig = {
  securityJsCode: '32aa3f4ab0fa0061de03edd4eafdd50a',
}

@Component({
  selector: 'app-page-plan-route',
  templateUrl: './page-plan-route.component.html',
  styleUrls: ['./page-plan-route.component.scss']
})
export class PagePlanRouteComponent {

  AMap: any;
  map: any;

  constructor() {
    this.createMap()
  }

  async createMap() {
    try {
      this.AMap = await AMapLoader.load({
        "key": "473b52010df7d3a32db0a2f5db245c8e",              // 申请好的Web端开发者Key，首次调用 load 时必填
        "version": "2.0",   // 指定要加载的 JS API 的版本，缺省时默认为 1.4.15
        "plugins": [],           // 需要使用的的插件列表，如比例尺'AMap.Scale'等
      });
      this.map = new this.AMap.Map('container', {
        resizeEnable: true,
        viewMode: "3D", // 是否为3D地图模式
        zoom: 13, // 初始化地图级别
        zooms: [4, 18],
        center: [116.397428, 39.90923], // 初始化地图中心点位置
        layers: [//使用多个图层
          // new AMap.TileLayer.Satellite(),
          // new AMap.TileLayer.RoadNet(),
          // new AMap.TileLayer.Traffic({
          //   zIndex: 10
          // })
        ],
      });
      this.AMap.plugin(['AMap.ToolBar', 'AMap.Driving'], () => {
        var toolbar = new this.AMap.ToolBar();
        this.map.addControl(toolbar);
        var driving = new this.AMap.Driving({
          map: this.map,
          panel: "panel",
        });
        driving.search([
          {keyword: '江西脑控科技有限公司', city: '南昌'},
          {keyword: '江西财经大学(枫林园)', city: '南昌'}
        ], (status: string, result: any) => {
          // result 即是对应的驾车导航信息，相关数据结构文档请参考  http://lbs.amap.com/api/javascript-api/reference/route-search#m_DrivingResult
          if (status === 'complete') {
            console.log(1)
          } else {
            console.log(result)
          }
        });
      });
    } catch (error) {
      console.log(error);
    }
  }
}

