import TileLayer from 'ol/layer/Tile'
import TileArcGISRest from 'ol/source/TileArcGISRest'
import OSM from 'ol/source/OSM'
import XYZ from 'ol/source/XYZ'
import Baidu from '../source/Baidu'
import Group from 'ol/layer/Group'
import { MapType } from '../base/MapType'
var baseMap = function(type) {
    var maplayer = null
    switch (parseInt(type)) {
        case MapType.OSM:
            maplayer = new TileLayer({
                source: new OSM(),
                title: "OSM地图",
                id: "basemap",
                isBaseMap: true
            })
            break
        case MapType.ArcGisOnLine:
            maplayer = new TileLayer({
                source: new TileArcGISRest({
                    url: 'https://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer',
                    crossOrigin: 'anonymous'
                }),
                title: "ArcGis地图",
                id: "basemap",
                isBaseMap: true
            })
            break
        case MapType.BaiDu:
            maplayer = new TileLayer({
                source: new Baidu({
                    origin: [43.88955327932, 12.590178885765],
                    url: 'http://online{0-3}.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl&udt=20170607&scaler=1&p=1'
                }),
                title: "百度地图",
                id: "basemap",
                isBaseMap: true
            })
            break
        case MapType.GaoDe:
            maplayer = new TileLayer({
                source: new XYZ({
                    url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
                    crossOrigin: 'anonymous'
                }),
                title: "高德地图",
                id: "basemap",
                isBaseMap: true
            })
            break
        case MapType.Google:
            maplayer = new TileLayer({
                source: new XYZ({
                    url: 'http://ditu.google.cn/maps/vt/pb=!1m4!1m3!1i{z}!2i{x}!3i{y}!2m3!1e0!2sm!3i345013117!3m8!2szh-CN!3scn!5e1105!12m4!1e68!2m2!1sset!2sRoadmap!4e0',
                    crossOrigin: 'anonymous'
                }),
                title: "谷歌地图",
                id: "basemap",
                isBaseMap: true
            })
            break
        case MapType.TdT:
            maplayer = new Group({
                layers: [new TileLayer({
                        source: new XYZ({
                            url: "http://t0.tianditu.com/DataServer?T=" + "vec_w" + "&X={x}&Y={y}&L={z}"
                        })
                    }),
                    new TileLayer({
                        source: new XYZ({
                            url: "http://t0.tianditu.com/DataServer?T=" + "cva_w" + "&X={x}&Y={y}&L={z}"
                        })
                    })
                ],
                title: "天地图地图",
                id: "basemap",
                isBaseMap: true
            })
            break
    }
    return maplayer
}
var mapconfig = {
    layers: baseMap
}
export default mapconfig