main.js
3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var main = {
map:null,
layer:null,
vectorLayer:null,
dragFeature:null,
pointFeature:null,
init:function () {
//初始化地图
this.map = new SuperMap.Map("map", {
controls: [
new SuperMap.Control.Navigation()
// new SuperMap.Control.Zoom(),
// new SuperMap.Control.LayerSwitcher()
]
});
this.map.events.on({
zoomend: function (evt) {
mapLevel.setLevel(main.map.getZoom());
}
});
this.layer = new SuperMap.Layer.CloudLayer();
//实例化矢量图层 vectorLayer
this.vectorLayer = new SuperMap.Layer.Vector("vectorLayer");
//实例化 DragFeature 控件
this.dragFeature = new SuperMap.Control.DragFeature(this.vectorLayer);
//map上添加控件
this.map.addControl(this.dragFeature);
//加载图层
this.map.addLayers([this.layer,this.vectorLayer]);
this.map.setCenter(new SuperMap.LonLat(11339634.286396, 4588716.5813769), 5);
//加载地图大小缩放控件
mapLevel.loadLevelControl(main.map);
//加载按钮事件
$('#location_cancel').hide();
$('#location_confirm').hide();
$('#location_update').click(function () {
main.updateLocation("location_update");
});
$('#location_cancel').click(function () {
main.updateLocation("location_cancel");
});
$('#location_confirm').click(function () {
main.updateLocation("location_confirm");
});
//获取网点
// this.getInfo();
this.getInfoSuccess(11);
},
getInfo:function () {
var method = "/v1/point/search";
var parameter = {
custom_id:{"fieldName":"","fieldValue":""}
};
saas.saasHttpRequest(method,parameter,this.getInfoSuccess,this.getInfoError);
},
getInfoSuccess:function (data) {
var lonlat = {x:120.42995, y:36.131393};
var po = latLonToMeters(lonlat);
this.addMarker(po.x, po.y,1, "src/image/icon.png");
},
getInfoError:function (error) {
},
updateLocation:function (btn) {
if (btn == "location_update"){
$('#location_update').hide();
$('#location_cancel').show();
$('#location_confirm').show();
//激活控件
main.dragFeature.activate();
}else if (btn == "location_cancel"){
$('#location_update').show();
$('#location_cancel').hide();
$('#location_confirm').hide();
//注销控件
main.dragFeature.deactivate();
}else if (btn == "location_confirm"){
$('#location_update').show();
$('#location_cancel').hide();
$('#location_confirm').hide();
//注销控件
main.dragFeature.deactivate();
var point = this.pointFeature.geometry.getCentroid();
console.log(point.x+","+point.y);
}
},
addMarker: function (pointX,pointY,code,iconPath) {
var lonlat = {
x:pointX,
y:pointY
};
// var lonlat = latLonToMeters(pointX,pointY);
var geometry = new SuperMap.Geometry.Point(lonlat.x,lonlat.y);
console.log(geometry.x+","+geometry.y);
var style = {
// fillColor:iconPath,
// pointRadius:3,
// stroke:true,
// strokeColor:iconPath
externalGraphic:iconPath,
graphicWidth:21,
graphicHeight:30
};
this.pointFeature = new SuperMap.Feature.Vector(geometry,{pointId:code},style);
this.vectorLayer.addFeatures(this.pointFeature);
}
}