// var extent = ol.extent.boundingExtent(feature.getGeometry().getCoordinates()[0]); //获取一个坐标数组的边界，格式为[minx,miny,maxx,maxy]
// var center = ol.extent.getCenter(extent);   //获取边界区域的中心位置
// map.getView().setCenter(center);  //设置当前地图的显示中心位置



//创建图层(WMTS方式)


function crtLayerWMTS(wmtsData, opacity, projection){
    var projectionExtent = projection.getExtent();
    var size = ol.extent.getWidth(projectionExtent) / 256;
    var resolutions = new Array(19);
    var matrixIds = new Array(19);
    for (var z = 1; z < 19; ++z) {
        // generate resolutions and matrixIds arrays for this WMTS
        resolutions[z] = size / Math.pow(2, z);
        matrixIds[z] = z;
    }

    var source = new ol.source.WMTS({
        url: wmtsData.url,
        layer: wmtsData.layer,
        matrixSet: wmtsData.matrixSet,
        format: 'tiles',
        projection: projection,
        tileGrid: new ol.tilegrid.WMTS({
            origin: ol.extent.getTopLeft(projectionExtent),
            resolutions: resolutions,
            matrixIds: matrixIds
        }),
        style: 'default',
        wrapX: true
    })

    var layer = new ol.layer.Tile({
        opacity: opacity,
        zIndex:wmtsData.zIndex,
        source: source
    });
    layer.id = wmtsData.layer+"_"+wmtsData.matrixSet;
    return layer;
}

function createTile(url,layer,zIndex,style){
    var untiled = new ol.layer.Image({
        zIndex: zIndex,
        source: new ol.source.ImageWMS({
            ratio: 1,
            url: url,
            params: {'FORMAT': 'image/png',
                'VERSION': '1.1.1',
                "STYLES": style,
                "LAYERS": layer,
                "exceptions": 'application/vnd.ogc.se_inimage',
            }
        })
    });
    return untiled;
}


function createGeoJson(url, sf, zIndex){
    return new ol.layer.Vector({
        source: new ol.source.Vector({
            format: new ol.format.GeoJSON(),
            url: url
        }),
        style: sf,
        zIndex: zIndex
    })
}







