mapControl.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /**
  2. * map操作类
  3. * Created by Administrator on 2017/11/8.
  4. */
  5. define([], function () {
  6. var map = {
  7. /**
  8. * 创建图层组
  9. */
  10. createLayer: function (clustering) {
  11. if (!clustering) clustering = false;
  12. return map23DControl.group({
  13. action: 'add',
  14. clustering: clustering //是否开启聚合
  15. })
  16. },
  17. /**
  18. * 清空图层组
  19. */
  20. clearLayer: function (Guid) {
  21. map23DControl.group({
  22. action: 'clearAll',
  23. guid: Guid
  24. })
  25. },
  26. /**
  27. * 移除图层组
  28. */
  29. removeLayer: function (Guid) {
  30. if (!Guid) return;
  31. map23DControl.group({
  32. action: 'remove',
  33. guid: Guid
  34. })
  35. },
  36. /**
  37. * 添加一个marker
  38. */
  39. addMarker: function (title, iconurl, iconSize, iconRorate, popupContent, lat, lng, groupId) {
  40. var markerOp = {
  41. action: 'add',//添加 //'delete'删除//'update'修改
  42. groupId: groupId, //所加载图层id
  43. visible2D: true,
  44. visible3D: true,
  45. geojson: {
  46. "type": "Feature",
  47. "properties": {
  48. title: title,//标题
  49. iconUrl: iconurl,//图标地址
  50. iconSize: [iconSize, iconSize],//图标大小
  51. iconAnchor: [iconSize / 2, iconSize / 2],//图标中心点偏移值
  52. popupAnchor: [0, 0],//冒泡窗与中心点的偏移值
  53. altitude: 0,//高度
  54. popupContent: popupContent,//冒泡窗内容
  55. iconRorate: iconRorate,//图标旋转角度
  56. },
  57. "geometry": {
  58. "type": "Point",
  59. "coordinates": [lng, lat]//经纬度
  60. }
  61. }
  62. }
  63. return map23DControl.marker(markerOp);
  64. },
  65. /**
  66. * 添加一个marker在2D地图
  67. */
  68. addMarkerTo2D: function (title, iconurl, iconSize, iconRorate, popupContent, lat, lng, groupId) {
  69. var markerOp = {
  70. action: 'add',//添加 //'delete'删除//'update'修改
  71. groupId: groupId, //所加载图层id
  72. visible2D: true,
  73. visible3D: false,
  74. geojson: {
  75. "type": "Feature",
  76. "properties": {
  77. title: title,//标题
  78. iconUrl: iconurl,//图标地址
  79. iconSize: [iconSize, iconSize],//图标大小
  80. iconAnchor: [iconSize / 2, iconSize / 2],//图标中心点偏移值
  81. popupAnchor: [0, 0],//冒泡窗与中心点的偏移值
  82. altitude: 0,//高度
  83. popupContent: popupContent,//冒泡窗内容
  84. iconRorate: iconRorate,//图标旋转角度
  85. },
  86. "geometry": {
  87. "type": "Point",
  88. "coordinates": [lng, lat]//经纬度
  89. }
  90. }
  91. }
  92. return map23DControl.marker(markerOp);
  93. },
  94. /**
  95. * 添加一个文字marker
  96. */
  97. addText: function (title, test, size, color, fontWeight, lat, lng, groupId, add3D, anchorX, anchorY) {
  98. if (anchorX != 0 && !anchorX) anchorX = size / 2;
  99. if (anchorY != 0 && !anchorY) anchorY = size / 2;
  100. var markerOp = {
  101. action: 'add',//添加 //'delete'删除//'update'修改
  102. groupId: groupId,
  103. visible2D: true,
  104. visible3D: true,
  105. geojson: {
  106. "type": "Feature",
  107. "properties": {
  108. title: title,//标题
  109. iconUrl: '/dist/images/marker.svg',
  110. iconSize: [size, size],//图标大小
  111. iconAnchor: [anchorX, anchorY],//图标中心点偏移值
  112. popupAnchor: [0, -14],//冒泡窗与中心点的偏移值
  113. altitude: 0,//高度
  114. fontIcon: test,//字体图标
  115. fontSize: size,//字体图标大小
  116. fontColor: color,//字体图标颜色
  117. fontWeight: fontWeight, //字体粗细
  118. popupContent: '',
  119. altitudeMode: 0
  120. },
  121. "geometry": {
  122. "type": "Point",
  123. "coordinates": [lng, lat]//经纬度
  124. }
  125. }
  126. }
  127. return map23DControl.marker(markerOp);
  128. },
  129. /**
  130. * 添加一条线
  131. * @param title 标题
  132. * @param color 颜色
  133. * @param weight 宽度
  134. * @param dash 虚线宽度 false未非虚线
  135. * @param points 点的集合(点为先lng后lat)
  136. * @param groupId 要添加的图层ID
  137. * @param addTo3D 是否添加到3D地图
  138. */
  139. addPolyline: function (title, color, weight, dash, points, groupId, addTo3D) {
  140. var alts = [];
  141. var type;
  142. if (dash) { //虚线
  143. type = 3;
  144. }
  145. for (var i = 0; i < points.length; i++) { //给定高度,防止3维遮挡
  146. alts.push(5000);
  147. }
  148. return map23DControl.polyline({
  149. action: 'add',
  150. groupId: groupId,
  151. visible2D: true,
  152. visible3D: addTo3D,
  153. geojson: {
  154. "type": "Feature",
  155. "properties": {
  156. title: title,
  157. color: color,
  158. weight: weight,
  159. opacity: 1,
  160. popupContent: '',
  161. altitude: alts,//高度
  162. // altitude: [10, 10, 10, 10, 10, 10, 10],
  163. lineJoin: 'miter',
  164. lineCap: 'butt',
  165. dashArray: dash,
  166. lineType: type
  167. },
  168. "geometry": {
  169. "type": "LineString",
  170. "coordinates": points //[lng, lat]
  171. }
  172. }
  173. })
  174. },
  175. /**
  176. * 添加一个圆
  177. */
  178. addCircle: function (title, radius, color, fillColor, lat, lng, layer) {
  179. return map23DControl.circle({
  180. action: 'add',
  181. groupId: layer,
  182. geojson: {
  183. "type": "Feature",
  184. "properties": {
  185. title: title,
  186. color: color,
  187. weight: 1,
  188. fillColor: fillColor,
  189. opacity: 1,
  190. fillOpacity: 0.5,
  191. // popupContent: '',
  192. // extrude: 18000, //拉伸高度
  193. // altitude: 11000, //点海拔高度
  194. // altitudeMode: 1, //海拔模式
  195. radius: radius
  196. },
  197. "geometry": {
  198. "type": "Circle",
  199. "coordinates": [lng, lat]
  200. }
  201. }
  202. });
  203. },
  204. /**
  205. * 添加填充区域
  206. */
  207. addPolygon: function (title, color, fillColor, lnglats, lnglats2, layer) {
  208. var alts = [];
  209. for (var i = 0; i < lnglats.length; i++) {
  210. alts.push(5000);
  211. }
  212. return map23DControl.polygon({
  213. action: 'add',
  214. groupId: layer,
  215. geojson: {
  216. "type": "Feature",
  217. "properties": {
  218. title: title,
  219. color: color,
  220. weight: 3,
  221. fillColor: fillColor,
  222. opacity: 1,
  223. fillOpacity: 0.5,
  224. popupContent: '',
  225. altitude: alts
  226. },
  227. "geometry": {
  228. "type": "Polygon",
  229. "coordinates": [lnglats, lnglats2]
  230. }
  231. }
  232. });
  233. },
  234. /**
  235. * 23D地图添加图片覆盖物
  236. */
  237. addImage: function (url, slat, slng, elat, elng, opacity) {
  238. if (!opacity && opacity != 0) opacity = 1;
  239. var guid = map23DControl.imageOverlay({
  240. action: 'add',
  241. from: '23D',
  242. type: 'imageOverlay',
  243. layers: {
  244. opacity: opacity,//2D透明度
  245. layerBounds: [[slng, slat], [elng, elat]],//左上角 右下角
  246. imageUrl2D: url,//2D图片地址
  247. imageUrl3D: url//3D图片服务地址
  248. }
  249. })
  250. return guid;
  251. },
  252. /**
  253. * 23D地图删除图片覆盖物
  254. */
  255. removeImage: function (guid) {
  256. map23DControl.imageOverlay({
  257. action: 'remove',
  258. from: '23D',
  259. guid: guid
  260. })
  261. },
  262. /**
  263. * 23D地图更新图片覆盖物(更改透明度)
  264. * @param guid
  265. * @param opacity
  266. */
  267. upDateImage: function (guid, opacity) {
  268. map23DControl.imageOverlay({
  269. action: 'update',
  270. from: '23D',
  271. guid: guid,
  272. type: 'imageOverlay',
  273. layers: {
  274. opacity: opacity,//2D透明度
  275. // layerBounds: [[100, 39], [120, -49]],//左上角 右下角
  276. // imageUrl2D: map23DConfig.map23DAssetsUrl + '/data/weixing/sdt_marker.png',//2D图片地址
  277. // imageUrl3D: map23DConfig.map23DAssetsUrl + '/data/weixing/sdt_marker.png'//3D图片服务地址
  278. }
  279. })
  280. },
  281. //-------------------------------地图状态工具方法----------------------------------------
  282. getBounds: function () { //获取当前显示范围
  283. if (map.mapType == '2d') {
  284. var se = [];
  285. se.push(map2DViewer.map.getBounds().getSouthWest().lat);
  286. se.push(map2DViewer.map.getBounds().getSouthWest().lng);
  287. se.push(map2DViewer.map.getBounds().getNorthEast().lat);
  288. se.push(map2DViewer.map.getBounds().getNorthEast().lng);
  289. return se;
  290. } else {
  291. var topLeft = map23DUtil.get3DPixToLnglat('topleft');
  292. var bottomRight = map23DUtil.get3DPixToLnglat('bottomright');
  293. var slat = topLeft.lat < bottomRight.lat ? topLeft.lat : bottomRight.lat;
  294. var slng = topLeft.lng < bottomRight.lng ? topLeft.lng : bottomRight.lng;
  295. var elat = topLeft.lat < bottomRight.lat ? bottomRight.lat : topLeft.lat;
  296. var elng = topLeft.lng < bottomRight.lng ? bottomRight.lng : topLeft.lng;
  297. var se = [];
  298. se.push(slat);
  299. se.push(slng);
  300. se.push(elat);
  301. se.push(elng);
  302. return se;
  303. }
  304. },
  305. getZoom: function () { //获取缩放层级
  306. if (map.mapType == '2d') {
  307. return map2DViewer.map._zoom;
  308. } else {
  309. return map.zoom3d;
  310. }
  311. },
  312. init: function () {
  313. //2D地图移动监听
  314. map2DViewer.map.on('moveend', function () {
  315. if (map.mapType != '2d') return;
  316. for (var key in meteo.f) {
  317. if (meteo.f[key].onMove) meteo.f[key].onMove();
  318. }
  319. });
  320. //23D地图切换监听
  321. ONEMAP.C.publisher.subscribe(function (type) {
  322. map.mapType = type;
  323. //修改时间轴2/3D地图背景样式
  324. $('.meteo-time-boxone').toggleClass('meteo-time-boxbg');
  325. }, 'change23D');
  326. //3D地图移动监听
  327. ONEMAP.C.publisher.subscribe(function (zoom) {
  328. if (map.mapType == '2d') return;
  329. map.zoom3d = zoom;
  330. var topLeft = map23DUtil.get3DPixToLnglat('topleft');
  331. var bottomRight = map23DUtil.get3DPixToLnglat('bottomright');
  332. if (!topLeft.lat || !topLeft.lng || !bottomRight.lat || !bottomRight.lng) {
  333. //只要当前有一个点没有数据,就不触发marker重绘
  334. return;
  335. }
  336. for (var key in meteo.f) {
  337. if (meteo.f[key].onMove) meteo.f[key].onMove();
  338. }
  339. }, 'mapChange23D');
  340. },
  341. mapType: '2d',
  342. zoom3d: null,
  343. }
  344. map.init();
  345. return map;
  346. })