addMap.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  7. <title>项目标注</title>
  8. <link rel="stylesheet" href="../../../../assets/libs/layui/css/layui.css"/>
  9. <link rel="stylesheet" href="../../../../assets/module/admin.css?v=312"/>
  10. <link rel="stylesheet" href="../../../../assets/css/editormap.css?v=312"/>
  11. <link rel="stylesheet" type="text/css" href="../../../../assets/libs/leaflet/leaflet-draw/leaflet.draw-src.css">
  12. <link rel="stylesheet" type="text/css" href="../../../../assets/libs/leaflet/leaflet.css">
  13. <link rel="stylesheet" href="../../../../assets/module/formSelects/formSelects-v4.css"/>
  14. </head>
  15. <body>
  16. <!-- 页面加载loading -->
  17. <div class="page-loading">
  18. <div class="ball-loader">
  19. <span></span><span></span><span></span><span></span>
  20. </div>
  21. </div>
  22. <!-- 正文开始 -->
  23. <div class="layui-fluid">
  24. <div class="layui-card">
  25. <div class="layui-card-body">
  26. <form id="modelRoleForm" lay-filter="modelRoleForm" class="layui-form">
  27. <input type="hidden" name="entMapId" id="entMapId">
  28. <!--<div class="layui-form-item">
  29. <div class="layui-inline">
  30. <label class="layui-form-label w-auto w-padding">选择背景图:</label>
  31. <div class="layui-input-inline mr0">
  32. <select id="entMapList" name="entMapList" lay-filter="entMapList" lay-verType="tips" class="layui-input-block">
  33. <option value="">选择背景图</option>
  34. </select>
  35. </div>
  36. </div>
  37. </div>-->
  38. <div class="map-container" id="map" style="height: 500px"></div>
  39. <div class="layui-form-item text-right">
  40. <button class="layui-btn" lay-filter="modelSubmitRole" lay-submit>保存</button>
  41. <button class="layui-btn layui-btn-primary" type="button" id="closePageDialog">取消</button>
  42. </div>
  43. </form>
  44. </div>
  45. </div>
  46. </div>
  47. <!-- js部分 -->
  48. <script type="text/javascript" src="../../../../assets/libs/layui/layui.js"></script>
  49. <script type="text/javascript" src="../../../../assets/js/common.js?v=312"></script>
  50. <script type="text/javascript" src="../../../../assets/libs/jquery/jquery-3.2.1.min.js"></script>
  51. <script src="../../../../assets/libs/leaflet/leaflet.js"></script>
  52. <script src="../../../../assets/libs/leaflet/leaflet-draw/leaflet.draw-src.js"></script>
  53. <script src="../../../../assets/libs/leaflet/leaflet-draw/local.js"></script>
  54. <script src="../../../../assets/libs/leaflet/proj4-compressed.js"></script>
  55. <script src="../../../../assets/libs/leaflet/proj4leaflet.js"></script>
  56. <script>
  57. var imgPath;
  58. var map;
  59. var entMapList;
  60. var loadFlag = true;
  61. layui.use(['layer', 'form', 'uParas', 'admin'], function () {
  62. var $ = layui.jquery;
  63. var layer = layui.layer;
  64. var form = layui.form;
  65. var admin = layui.admin;
  66. var uParas = layui.uParas;
  67. var projectId = uParas.getUrlParam("projectId");
  68. // var entMapId = uParas.getUrlParam("entMapId");
  69. // if (entMapId != null && entMapId != undefined) {
  70. // $("#entMapId").val(entMapId);
  71. // }
  72. // debugger
  73. // $.ajaxSetup({async: false});
  74. // $.getJSON(uParas.baseUrl + "/ent/map/getList", {mapType: 2}, function (result) {
  75. // var entMap;
  76. // if (result.data != null) {
  77. // entMapList = result.data;
  78. // if (entMapId != null && entMapId != undefined) {
  79. // $.each(result.data, function (i, field) {
  80. // if (field.mapId.toString() === entMapId) {
  81. // imgPath = uParas.baseUrl + field.mapRasterLayer;
  82. // uParas.initSimpleSelectX("entMapList", "modelRoleForm", result, "mapName", "mapId", entMapId);
  83. // return;
  84. // }
  85. // });
  86. // } else {
  87. // entMap = result.data[0];
  88. // imgPath = uParas.baseUrl + entMap.mapRasterLayer;
  89. // uParas.initSimpleSelectX("entMapList", "modelRoleForm", result, "mapName", "mapId", entMap.mapId);
  90. // $("#entMapId").val(entMap.mapId);
  91. // }
  92. // }
  93. // });
  94. // console.log("entMapList", entMapList);
  95. //监听下拉选择
  96. // form.on('select(entMapList)', function (data) {
  97. // $.each(entMapList, function (i, field) {
  98. // if (field.mapId.toString() === data.value) {
  99. // imgPath = uParas.baseUrl + field.mapRasterLayer;
  100. // return;
  101. // }
  102. // });
  103. // $("#entMapId").val(data.value);
  104. // myBmap.init(projectId);
  105. // });
  106. form.on('submit(modelSubmitRole)', function (data) {
  107. //console.log(data.field);
  108. var layers = plotLayer.getLayers();
  109. var drawIds = '';
  110. if (layers.length > 0) {
  111. layers.forEach(function (v) {
  112. v = v.toGeoJSON();
  113. //console.log(v);
  114. if (v.geometry.type == "Point") {
  115. var data = new Array();
  116. data[0] = v.geometry.coordinates[1];
  117. data[1] = v.geometry.coordinates[0];
  118. drawIds = drawIds += JSON.stringify(data) + ";" + v.geometry.type + "#";
  119. } else {
  120. drawIds = drawIds += JSON.stringify(v.geometry.coordinates) + ";" + v.geometry.type + "#";
  121. }
  122. });
  123. }
  124. data.field.projectId = projectId;
  125. data.field.drawIds = drawIds;
  126. data.field.entMapId = $("#entMapId").val();
  127. $.ajax({
  128. type: "post",
  129. url: "/org/project/saveMapData",
  130. data: data.field,
  131. dataType: "json",
  132. success: function (result) {
  133. //debugger
  134. if (result.code === 1) {
  135. parent.layer.closeAll();
  136. layer.msg(result.msg);
  137. //location.href = "./index.html"
  138. parent.closeReload();
  139. } else {
  140. layer.msg(result.msg);
  141. }
  142. }
  143. });
  144. return false;
  145. });
  146. $('#closePageDialog').click(function () {
  147. parent.layer.closeAll();
  148. });
  149. myBmap.init(projectId);
  150. });
  151. var myBmap = {
  152. mapContainer: "map", //地图容器
  153. mapTile: "http://online{s}.map.bdimg.com/tile/?qt=vtile&x={x}&y={y}&z={z}&styles=pl&scaler=2&udt=20181205", //切片图层
  154. myIcon: null, //保存创建的icon
  155. myMarker: null, //保存自己创建marker
  156. myMarkerType: 0, //marker类型
  157. myMarkerId: null, //markerId
  158. isSave: true, //是否保存标记
  159. checkedIcon: null, //保存选中的icon
  160. deleteMarkerId: null, //保存删除得markerId
  161. data: {},
  162. init: function (projectId) {
  163. var _this = this;
  164. //初始化地图
  165. var map_type = 4;
  166. if (map_type == 4) {
  167. baidu_map();
  168. } else {
  169. image_map();
  170. }
  171. // 增加区域绘制工具栏
  172. plotLayer = new L.FeatureGroup,
  173. map.addLayer(plotLayer);
  174. var e = {
  175. position: "topright",
  176. draw: {
  177. polyline: {shapeOptions: {color: "#0000ff", weight: 3}},
  178. polygon: {allowIntersection: !0, showArea: !0, shapeOptions: {color: "#0000ff", weight: 2}},
  179. rectangle: {shapeOptions: {color: "#0000ff", weight: 2}},
  180. circle: false,
  181. circlemarker: false,
  182. marker: true,
  183. Point: false
  184. },
  185. edit: {
  186. featureGroup: plotLayer,
  187. remove: !0,
  188. edit: true
  189. }
  190. }, n = new L.Control.Draw(e);
  191. if (loadFlag) {
  192. map.addControl(n),
  193. map.on(L.Draw.Event.CREATED, draw_createdHandler);
  194. }
  195. function draw_createdHandler(t) {
  196. t.layerType;
  197. var o = t.layer;
  198. // 逻辑判断
  199. // var layers = plotLayer.getLayers();
  200. // var types;
  201. // if (layers.length > 0) {
  202. // layers.forEach(function (v) {
  203. // types += v.toGeoJSON().geometry.type;
  204. // });
  205. // if (types.indexOf("Point") != -1) {
  206. // Point = 1
  207. // }
  208. // }
  209. // if (o.toGeoJSON().geometry.type == "Point" && Point == 0) {
  210. // plotLayer.addLayer(o);
  211. // } else if (o.toGeoJSON().geometry.type != "Point") {
  212. // plotLayer.addLayer(o);
  213. // }
  214. plotLayer.addLayer(o);
  215. }
  216. //获取数据
  217. $.getJSON("/org/project/findProjectMapData", {"riskPointId": projectId}, function (result) {
  218. if (result.data && result.data.length > 0) {
  219. $.each(result.data, function (index, item) {
  220. //console.log(item);
  221. var markerData = item.mapData;
  222. if (markerData != null) {
  223. var optionsData = {
  224. projectId: item.projectId,
  225. title: item.mapName
  226. };
  227. var layers;
  228. if (item.mapType == 3) {
  229. var data = new Array();
  230. $.each($.parseJSON(markerData), function (index, item) {
  231. data[index] = new Array(item[1], item[0]);
  232. });
  233. layers = L.polygon(data, optionsData);
  234. } else if (item.mapType == 1) {
  235. layers = L.marker($.parseJSON(markerData));
  236. } else if (item.mapType == 2) {
  237. var data = new Array();
  238. $.each($.parseJSON(markerData), function (index, item) {
  239. data[index] = new Array(item[1], item[0]);
  240. });
  241. layers = L.polyline(data, optionsData);
  242. }
  243. plotLayer.addLayer(layers);
  244. }
  245. });
  246. }
  247. });
  248. //底图为图片
  249. function image_map() {
  250. if (map != undefined && map != null) {
  251. map.remove();
  252. }
  253. map = L.map(_this.mapContainer, {
  254. crs: L.CRS.Simple,
  255. center: L.latLng(50.5, 30.5),
  256. minZoom: 0,
  257. zoom: 4,
  258. attributionControl: false
  259. });
  260. var yx = L.latLng;
  261. var xy = function xy(x, y) {
  262. if (L.Util.isArray(x)) {
  263. return yx(x[1], x[0]);
  264. }
  265. return yx(y, x);
  266. };
  267. map.eachLayer(function (layer) {
  268. map.removeLayer(layer);
  269. });
  270. var bounds = [xy(-600, -600), xy(300, 300)];
  271. L.imageOverlay(imgPath, bounds).addTo(map);
  272. map.fitBounds(bounds);
  273. }
  274. //底图为百度地图
  275. function baidu_map() {
  276. var maxZoom = 26;
  277. var crs = new L.Proj.CRS('EPSG:3395',
  278. '+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs', {
  279. resolutions: function () {
  280. level = 19;
  281. var res = [];
  282. res[0] = Math.pow(2, 18);
  283. for (var i = 1; i < level; i++) {
  284. res[i] = Math.pow(2, (18 - i))
  285. }
  286. return res;
  287. }(),
  288. origin: [0, 0],
  289. bounds: L.bounds([20037508.342789244, 0], [0, 20037508.342789244])
  290. });
  291. var image = new L.TileLayer(_this.mapTile, {
  292. maxZoom: maxZoom,
  293. minZoom: 10,
  294. subdomains: [0, 1, 2],
  295. tms: true
  296. });
  297. map = L.map(_this.mapContainer, {
  298. crs: crs,
  299. layers: [image]
  300. });
  301. map.setView([34.277799, 108.953098], 14);
  302. }
  303. }
  304. }
  305. function iconClick(e) {
  306. $(e).toggleClass('icon-active')
  307. }
  308. </script>
  309. </body>
  310. </html>