//dgXY:經緯度
//10:大小
map.zoomToXY(new dgXY(120.8, 24.2), 10);
            
//啟用旋轉
//Shift + 左鍵
map.openDragRotate();
            
//關閉旋轉
map.closeDragRotate();
            
//工具列增添
//只能添加一次
map.addMapControl([0, 0]);
            
//工具列開關
//需先填加工具
// f_swcontrol_sw: true 或 false
map.setMapControlV(f_swcontrol_sw);
            
//開關ScaleLine
// f_swcontrol_sw: true 或 false
map.setScaleLineVisible(f_sw_scaleline_sw);
            
//啟用BBOX
map.enableDragBox(function (extent) {
    var points = [];
    points.push(new dgXY(extent[0], extent[1]));
    points.push(new dgXY(extent[0], extent[3]));
    points.push(new dgXY(extent[2], extent[3]));
    points.push(new dgXY(extent[2], extent[1]));
    
    let ppt = new dgPolygon(points, "rgba(0,0,200,0.6)", "rgba(211,211,211,0.6)", 2); map.addItem(ppt);
    map.addItem(ppt);
            });
            
//關閉BBOX
map.disableDragBox();
            
var BaseMap01 = {};
BaseMap01.bg = true;
BaseMap01.name = "EMAP5";
BaseMap01.url = "http://wmts.nlsc.gov.tw/wmts";
BaseMap01.layer = "EMAP";
BaseMap01.matrixSet = "EPSG:3857";
BaseMap01.format = "image/png";
BaseMap01.zoomOffset = 0;
BaseMap01.serverResolutions = null;
map.addItem(new dgSource("WMTS", BaseMap01));

var BaseMap02 = {};
BaseMap02.bg = true;
BaseMap02.name = "PHOTO2";
BaseMap02.chname = "臺灣通用電子地圖正射影像";
BaseMap02.url = "http://wmts.nlsc.gov.tw/wmts";
BaseMap02.layer = "PHOTO2";
BaseMap02.matrixSet = "EPSG:3857";
BaseMap02.format = "image/png";
BaseMap02.serverResolutions = null;
map.addItem(new dgSource("WMTS", BaseMap02));

var _op1 = {};
_op1.bg = true;
_op1.name = "OpenStreetMap";
_op1.url = "https://b.tile.openstreetmap.org/${z}/${x}/${y}.png";
_op1.tileOptions = { crossOriginKeyword: null };
//add a layer
map.addItem(new dgSource("webTiles", _op1));

//Vector Tile
var _op2 = {};
_op2.bg = true;
_op2.name = "VectorTile";
_op2.chname = "向量圖專";
_op2.url = 'https://maps.tilehosting.com/data/v3/{z}/{x}/{y}.pbf?key=NKc1L4DU8rAW16aWI7Pa';
_op2.styleUrl = 'https://maps.tilehosting.com/c/a1fc149e-d7c2-41f0-9dcf-2b08a1ecb3f9/styles/darkmatter/style.json?key=NKc1L4DU8rAW16aWI7Pa';
map.addItem(new dgSource("VectorTile", _op2));


map.switchMap(xxx); //xxx:底圖的name
            
//方式一
var layers = [];
var icon = new dgIcon("../../css/imgs/balloon.png", 16, 16);
var xy_1 = new dgXY(120.1, 22.5);
var Marker_1 = new dgMarker(xy_1, icon, true);
//點擊事件
Marker_1.onclick = function (dgxy, dgmarker) { alert(dgxy.x + ',' + dgxy.y) }

var xy_2 = new dgXY(120.5, 22.5);
var Marker_2 = new dgMarker(xy_2, icon, true);
//拖曳事件
Marker_2.ondragend = function (dgxy, dgmarker) { alert(dgxy.x + ',' + dgxy.y) }

layers.push(Marker_1);
layers.push(Marker_2);
//可同時加入
map.addItem(layers);


//方式二:不知援拖曳
var xy_Div = new dgXY(121, 23);
var Marker_Div = new dgMarker(xy_Div, '', true);
Marker_Div.setContent("

i am popup content

"); map.addItem(Marker_Div);
//_tempLayer:為dgMarker陣列
_tempLayer.forEach(function (layer) {
    map.removeItem(layer);
});
            
var LL = [];
var points = [];
//參數設定
points.push(new dgXY(120.64681 + Math.random(), 24.180936 + Math.random()));
points.push(new dgXY(120.64681 + Math.random(), 24.180936 + Math.random()));
points.push(new dgXY(120.64681 + Math.random(), 24.180936 + Math.random()));
points.push(new dgXY(120.64681 + Math.random(), 24.180936 + Math.random()));
points.push(new dgXY(120.64681 + Math.random(), 24.180936 + Math.random()));
var ll = new dgPolyline(points, "rgba(200,0,0,0.8)", 2);

LL.push(ll);//可放置多組polyline
map.addItem(LL);
            
var PP = [];
var points = [];
points.push(new dgXY(120.64681 + Math.random(), 24.180936 + Math.random()));
points.push(new dgXY(120.64681 + Math.random(), 24.180936 + Math.random()));
points.push(new dgXY(120.64681 + Math.random(), 24.180936 + Math.random()));
points.push(new dgXY(120.64681 + Math.random(), 24.180936 + Math.random()));
points.push(new dgXY(120.64681 + Math.random(), 24.180936 + Math.random()));

var pp1 = new dgPolygon(points, "rgba(0,0,200,0.6)", "rgba(200,0,200,0.6)", 8);
PP.push(pp1);//可放置多組polygon

map.addItem(PP);
            
var point = new dgXY(120.64681, 24.180936);
var stroke_rgba = "rgba(200,0,0,0.8)";//邊線的RGBA
var fill_rgba = "rgba(200,0,0,0.2)";//填滿的RGBA
var distance = 100000;//距離:公尺
var stroke_width = 3;//邊線寬
var arcAngle1 = Math.random() * 60;//起使角度
var arcAngle2 = 60 + (Math.random() * 60);//結束角度
var clockwise = true;//順時針true/ 逆時針flase
curve = new dgCurve(point, stroke_rgba, fill_rgba, distance, stroke_width, arcAngle1, arcAngle2, true);

map.addItem(curve);
            
//需先操作 dgCurve 
//curve為dgCurve 物件
map.removeItem(curve);
            
//需先操作 dgCurve 
//curve為dgCurve 物件
map.removeItem(curve);
            
map.clearDraw();
            
var url = "http://easymap.gis.tw/easymap/uploadfile/kml/原住民部落點位.kml";
_kml = new dgKml(url, function (dgkml) {
    //載入完成後的事件
});
//Zoom In
_kml.setUpperZoomByBoundary(true);
//顯示Label
_kml.setLabelVisible(false);

map.addItem(_kml);
            
var url = "http://easymap.gis.tw/easymap/uploadfile/kml/原住民部落點位.kml";
_kml = new dgKml(url, function (dgkml) {
    //載入完成後的事件
});
//Set Cluster
_kml.setClusterEnable(50, 5, new dgGStyle());

map.addItem(_kml);
            
var url = "http://easymap.gis.tw/easymap/uploadfile/kml/polyline.kml"
kml_polyline = new dgKml(url, function (dgkml) {
    //載入完成後的事件
});
kml_polyline.setUpperZoomByBoundary(true);
kml_polyline.setLabelVisible(true);
kml_polyline.setOpacity(1);

map.addItem(kml_polyline);
            
var url = "http://easymap.gis.tw/easymap/uploadfile/kml/polygon.kml"
kml_polygon = new dgKml(url, function (dgkml) {
    //載入完成後的事件
});
kml_polygon.setUpperZoomByBoundary(true);
kml_polygon.setLabelVisible(true);
kml_polygon.setOpacity(0.5);

map.addItem(kml_polygon);
            
var url = "http://easymap.gis.tw/easymap/uploadfile/kml/NetworkLink_image.kml"
kml_n_image = new dgKml(url, function (dgkml) {
    //載入完成後的事件
});
kml_n_image.setOpacity(0.5);
map.addItem(kml_n_image);