高德地图 编辑(单独一个或多个中单独编辑一个) 删除 新增
前台
<style> .form-control{ display:inline-block; } .tiaozheng { padding-top:5px; } </style> <script type="text/javascript"> $(document).ready(function () { var map = new AMap.Map('container', { resizeEnable: true, zoom: 12, showIndoorMap: false, center: [123.418707, 41.80209] }); map.plugin(["AMap.Scale"], function () { //加载比例尺插件 scale = new AMap.Scale(); map.addControl(scale); scale.show(); }); map.plugin(["AMap.OverView"], function () { //在地图中添加鹰眼插件 //加载鹰眼 overView = new AMap.OverView({ visible: true //初始化显示鹰眼 }); map.addControl(overView); overView.open(); //展开鹰眼 }); map.plugin(["AMap.ToolBar"], function () { //在地图中添加ToolBar插件 toolBar = new AMap.ToolBar(); map.addControl(toolBar); }); var getpath = []; var PortalId = $("#PortalId").val(); $.ajax({ type: "post", url: '/DesktopModules/AMD_AREASET/test1.ashx', data: { PortalId: PortalId, Polygon: "getpath" }, dataType: "html", success: function (data) { document.getElementById("closeEditPolygon1").disabled = "disabled"; document.getElementById("deletePolygon").disabled = "disabled"; var newstr = data.replace("[", "[ "); var obj = eval('(' + newstr + ')'); document.getElementById('get_path').innerHTML = ""; var html = "<table id=" + "tb_path" + " style=" + "width:100%;height:auto;display:none;" + ">"; html += "<tr><th>id</th><th>cname</th><th>path</th></tr>"; for (var i in obj) { for (var j in obj[i]) { html += "<tr id=" + obj[i][j].id + "" + "><td>" + obj[i][j].id + "</td><td>" + obj[i][j].SalesName + "</td><td>" + obj[i][j].SalesPaths + "</td></tr>"; }; }; html += "</table>"; document.getElementById('get_path').innerHTML = html; show_path(map); }, error: function () { alert("连接出错!!"); } }); var beginPoints; var beginMarks; //地图上面的click事件对象 var clickListener; //当前绘制的点个数,用来控制前面3个点 var beginNum = 0; var polygonEditor; // 撤销编辑 var cexiaobianji; var resPolygon = []; var resNum = 0; init(); //初始化 function init() { beginPoints = []; beginMarks = []; beginNum = 0; polygonEditor = ''; clickListener = AMap.event.addListener(map, "click", mapOnClick); } //地图上面绑定的点击事件 function mapOnClick(e) { beginMarks.push(addMarker(e.lnglat)); beginPoints.push(e.lnglat); beginNum++; if (beginNum == 3) { //处理有了3个点以后,转化为多边形的逻辑 AMap.event.removeListener(clickListener); var polygon = createPolygon(beginPoints); polygonEditor = createEditor(polygon); clearMarks(); } }; // 实例化点标记 function addMarker(lnglat) { var marker = new AMap.Marker({ icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png", position: lnglat }); marker.setMap(map); marker //获取当前点标记坐标 //alert(marker.getPosition()); return marker; } //清除前面的3个点标记 function clearMarks() { map.remove(beginMarks); } var _polygonEditor; var _polygonEditor1; var _polygonEditor2; var _polygonEditor3; var _polygonEditor4; var _polygonEditor5; var _polygonEditor6; var _polygonEditor7; var _polygonEditor8; var _polygonEditor9; var _polygonEditor10; var _polygonEditor11; var _polygonEditor12; var _polygonEditor13; var _polygonEditor14; var _polygonEditor15; var _polygonEditor16; var _polygonEditor17; var _polygonEditor18; var _polygonEditor19; var _polygonEditor20; var _polygonEditor21; var _polygonEditor22; var _polygonEditor23; var _polygonEditor24; var _polygonEditor25; var _polygonEditor26; var _polygonEditor27; var _polygonEditor28; var _polygonEditor29; var _polygonEditor30; var Editor1; var Editor2; var Editor3; var Editor4; var Editor5; var Editor6; var Editor7; var Editor8; var Editor9; var Editor10; var Editor11; var Editor12; var Editor13; var Editor14; var Editor15; var Editor16; var Editor17; var Editor18; var Editor19; var Editor20; var Editor21; var Editor22; var Editor23; var Editor24; var Editor25; var Editor26; var Editor27; var Editor28; var Editor29; var Editor30; var polygon; var path_id1; var path_id2; var path_id3; var path_id4; var path_id5; var path_id6; var path_id7; var path_id8; var path_id9; var path_id10; var path_id11; var path_id12; var path_id13; var path_id14; var path_id15; var path_id16; var path_id17; var path_id18; var path_id19; var path_id20; var path_id21; var path_id22; var path_id23; var path_id24; var path_id25; var path_id26; var path_id27; var path_id28; var path_id29; var path_id30; var polygon_pathQ1; var polygon_pathQ2; var polygon_pathQ3; var polygon_pathQ4; var polygon_pathQ5; var polygon_pathQ6; var polygon_pathQ7; var polygon_pathQ8; var polygon_pathQ9; var polygon_pathQ10; var polygon_pathQ11; var polygon_pathQ12; var polygon_pathQ13; var polygon_pathQ14; var polygon_pathQ15; var polygon_pathQ16; var polygon_pathQ17; var polygon_pathQ18; var polygon_pathQ19; var polygon_pathQ20; var polygon_pathQ21; var polygon_pathQ22; var polygon_pathQ23; var polygon_pathQ24; var polygon_pathQ25; var polygon_pathQ26; var polygon_pathQ27; var polygon_pathQ28; var polygon_pathQ29; var polygon_pathQ30; function show_path(map) { var strokeColor = []; strokeColor.push("#0000FF"); strokeColor.push("#008B00"); strokeColor.push("#00B2EE"); strokeColor.push("#00CD66"); strokeColor.push("#030303"); strokeColor.push("#0D0D0D"); strokeColor.push("#836FFF"); strokeColor.push("#7D26CD"); strokeColor.push("#8B1A1A"); strokeColor.push("#CD00CD"); strokeColor.push("#CD69C9"); strokeColor.push("#B03060"); strokeColor.push("#E0FFFF"); strokeColor.push("#FF4040"); strokeColor.push("#FFB6C1"); strokeColor.push("#FFD700"); strokeColor.push("#FFB90F"); strokeColor.push("#FFA07A"); strokeColor.push("#FF6347"); strokeColor.push("#FFFF00"); strokeColor.push("#FFFFCC"); strokeColor.push("#CCFFFF"); strokeColor.push("#FFCCCC"); strokeColor.push("#99CCCC"); strokeColor.push("#FFCC99"); strokeColor.push("#FFCCCC"); strokeColor.push("#FF9999"); strokeColor.push("#996699"); strokeColor.push("#FFCCCC"); strokeColor.push("#CC9999"); strokeColor.push("#FFFFCC"); strokeColor.push("#CCCC99"); strokeColor.push("#FFFF99"); strokeColor.push("#CCCCFF"); strokeColor.push("#0099CC"); strokeColor.push("#CCCCCC"); strokeColor.push("#FF6666"); strokeColor.push("#FF9966"); strokeColor.push("#CC9966"); strokeColor.push("#99CC66"); var table = document.getElementById("tb_path"); for (var i = 1; i < table.rows.length; i++) { var polygon_pathQ = table.rows[i].cells[2].innerText; var polygon_name = table.rows[i].cells[1].innerText; var path = json2arr(polygon_pathQ); //创建一个多边形对象 polygon = new AMap.Polygon({ map: map, path: path, strokeColor: strokeColor[i], strokeOpacity: 1, strokeWeight: 3, fillColor: "#f5deb3", fillOpacity: 0.35 }); map.setFitView(); if (i == 0) { Editor1 = polygon_name; _polygonEditor1 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor1, 'end', polygonEnd); path_id1 = table.rows[i].cells[0].innerText; polygon_pathQ1 = table.rows[i].cells[2].innerText; } if (i == 1) { Editor2 = polygon_name; _polygonEditor2 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor2, 'end', polygonEnd); path_id2 = table.rows[i].cells[0].innerText; polygon_pathQ2 = table.rows[i].cells[2].innerText; } if (i == 2) { Editor3 = polygon_name; _polygonEditor3 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor3, 'end', polygonEnd); path_id3 = table.rows[i].cells[0].innerText; polygon_pathQ3 = table.rows[i].cells[2].innerText; } if (i == 3) { Editor4 = polygon_name; _polygonEditor4 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor4, 'end', polygonEnd); path_id4 = table.rows[i].cells[0].innerText; polygon_pathQ4 = table.rows[i].cells[2].innerText; } if (i == 4) { Editor5 = polygon_name; _polygonEditor5 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor5, 'end', polygonEnd); path_id5 = table.rows[i].cells[0].innerText; polygon_pathQ5 = table.rows[i].cells[2].innerText; } if (i == 5) { Editor6 = polygon_name; _polygonEditor6 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor6, 'end', polygonEnd); path_id6 = table.rows[i].cells[0].innerText; polygon_pathQ6 = table.rows[i].cells[2].innerText; } if (i == 6) { Editor7 = polygon_name; _polygonEditor7 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor7, 'end', polygonEnd); path_id7 = table.rows[i].cells[0].innerText; polygon_pathQ7 = table.rows[i].cells[2].innerText; } if (i == 7) { Editor8 = polygon_name; _polygonEditor8 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor8, 'end', polygonEnd); path_id8 = table.rows[i].cells[0].innerText; polygon_pathQ8 = table.rows[i].cells[2].innerText; } if (i == 8) { Editor9 = polygon_name; _polygonEditor9 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor9, 'end', polygonEnd); path_id9 = table.rows[i].cells[0].innerText; polygon_pathQ9 = table.rows[i].cells[2].innerText; } if (i == 9) { Editor10 = polygon_name; _polygonEditor10 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor10, 'end', polygonEnd); path_id10 = table.rows[i].cells[0].innerText; polygon_pathQ10 = table.rows[i].cells[2].innerText; } if (i == 10) { Editor11 = polygon_name; _polygonEditor11 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor11, 'end', polygonEnd); path_id11 = table.rows[i].cells[0].innerText; polygon_pathQ11 = table.rows[i].cells[2].innerText; } if (i == 11) { Editor12 = polygon_name; _polygonEditor12 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor12, 'end', polygonEnd); path_id12 = table.rows[i].cells[0].innerText; polygon_pathQ12 = table.rows[i].cells[2].innerText; } if (i == 12) { Editor13 = polygon_name; _polygonEditor13 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor13, 'end', polygonEnd); path_id13 = table.rows[i].cells[0].innerText; polygon_pathQ13 = table.rows[i].cells[2].innerText; } if (i == 13) { Editor14 = polygon_name; _polygonEditor14 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor14, 'end', polygonEnd); path_id14 = table.rows[i].cells[0].innerText; polygon_pathQ14 = table.rows[i].cells[2].innerText; } if (i == 14) { Editor15 = polygon_name; _polygonEditor15 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor15, 'end', polygonEnd); path_id15 = table.rows[i].cells[0].innerText; polygon_pathQ15 = table.rows[i].cells[2].innerText; } if (i == 15) { Editor16 = polygon_name; _polygonEditor16 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor16, 'end', polygonEnd); path_id16 = table.rows[i].cells[0].innerText; polygon_pathQ16 = table.rows[i].cells[2].innerText; } if (i == 16) { Editor17 = polygon_name; _polygonEditor17 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor17, 'end', polygonEnd); path_id17 = table.rows[i].cells[0].innerText; polygon_pathQ17 = table.rows[i].cells[2].innerText; } if (i == 17) { Editor18 = polygon_name; _polygonEditor18 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor18, 'end', polygonEnd); path_id18 = table.rows[i].cells[0].innerText; polygon_pathQ18 = table.rows[i].cells[2].innerText; } if (i == 18) { Editor19 = polygon_name; _polygonEditor19 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor19, 'end', polygonEnd); path_id19 = table.rows[i].cells[0].innerText; polygon_pathQ19 = table.rows[i].cells[2].innerText; } if (i == 19) { Editor20 = polygon_name; _polygonEditor20 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor20, 'end', polygonEnd); path_id20 = table.rows[i].cells[0].innerText; polygon_pathQ20 = table.rows[i].cells[2].innerText; } if (i == 20) { Editor21 = polygon_name; _polygonEditor21 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor21, 'end', polygonEnd); path_id21 = table.rows[i].cells[0].innerText; polygon_pathQ21 = table.rows[i].cells[2].innerText; } if (i == 21) { Editor22 = polygon_name; _polygonEditor22 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor22, 'end', polygonEnd); path_id22 = table.rows[i].cells[0].innerText; polygon_pathQ22 = table.rows[i].cells[2].innerText; } if (i == 22) { Editor23 = polygon_name; _polygonEditor23 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor23, 'end', polygonEnd); path_id23 = table.rows[i].cells[0].innerText; polygon_pathQ23 = table.rows[i].cells[2].innerText; } if (i == 23) { Editor24 = polygon_name; _polygonEditor24 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor24, 'end', polygonEnd); path_id24 = table.rows[i].cells[0].innerText; polygon_pathQ24 = table.rows[i].cells[2].innerText; } if (i == 24) { Editor25 = polygon_name; _polygonEditor25 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor25, 'end', polygonEnd); path_id25 = table.rows[i].cells[0].innerText; polygon_pathQ25 = table.rows[i].cells[2].innerText; } if (i == 25) { Editor26 = polygon_name; _polygonEditor26 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor26, 'end', polygonEnd); path_id26 = table.rows[i].cells[0].innerText; polygon_pathQ26 = table.rows[i].cells[2].innerText; } if (i == 26) { Editor27 = polygon_name; _polygonEditor27 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor27, 'end', polygonEnd); path_id27 = table.rows[i].cells[0].innerText; polygon_pathQ27 = table.rows[i].cells[2].innerText; } if (i == 27) { Editor28 = polygon_name; _polygonEditor28 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor28, 'end', polygonEnd); path_id28 = table.rows[i].cells[0].innerText; polygon_pathQ28 = table.rows[i].cells[2].innerText; } if (i == 28) { Editor29 = polygon_name; _polygonEditor29 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor29, 'end', polygonEnd); path_id29 = table.rows[i].cells[0].innerText; polygon_pathQ29 = table.rows[i].cells[2].innerText; } if (i == 29) { Editor30 = polygon_name; _polygonEditor30 = new AMap.PolyEditor(map, polygon); AMap.event.addListener(_polygonEditor30, 'end', polygonEnd); path_id30 = table.rows[i].cells[0].innerText; polygon_pathQ30 = table.rows[i].cells[2].innerText; } }; }; var path_id; var polygon_pa; //function startEditPolygon() { $("#startEditPolygon").click(function () { //2-27 修改 map.clearMap(); var name = document.getElementById("<%=this.DropDownListSalesP.ClientID %>").value; $.ajax({ type: "post", url: '/DesktopModules/AMD_AREASET/test1.ashx', data: { PortalId: PortalId, Polygon: "getpathone", name:name }, dataType: "html", success: function (data) { document.getElementById("closeEditPolygon1").disabled = ""; document.getElementById("deletePolygon").disabled = ""; duobianxing = data; var arr = json2arr(duobianxing); var polygon = createPolygon(arr); polygonEditor = createEditor(polygon); //var newstr = data.replace("[", "[ "); //var obj = eval('(' + newstr + ')'); //document.getElementById('get_path').innerHTML = ""; //var html = "<table id=" + "tb_path" + " style=" + "width:100%;height:auto;display:none;" + ">"; //html += "<tr><th>id</th><th>cname</th><th>path</th></tr>"; //for (var i in obj) { // for (var j in obj[i]) { // html += "<tr id=" + obj[i][j].id + "" + "><td>" + obj[i][j].id + "</td><td>" + obj[i][j].SalesName + "</td><td>" + obj[i][j].SalesPaths + "</td></tr>"; // }; //}; //html += "</table>"; //document.getElementById('get_path').innerHTML = html; //show_path(map); }, error: function () { alert("连接出错!!"); } }); // //原来 //var name = document.getElementById("").value;<% %>=this.DropDownListSalesP.ClientID //if (name == Editor1) { // _polygonEditor1.open(); // AMap.event.addListener(_polygonEditor1, 'end', polygonEnd); // path_id = path_id1; // polygon_pa = _polygonEditor1; //} //if (name == Editor2) { // _polygonEditor2.open(); // AMap.event.addListener(_polygonEditor2, 'end', polygonEnd); // path_id = path_id2; // polygon_pa = _polygonEditor2; //} //if (name == Editor3) { // _polygonEditor3.open(); // AMap.event.addListener(_polygonEditor3, 'end', polygonEnd); // path_id = path_id3; // polygon_pa = _polygonEditor3; //} //if (name == Editor4) { // _polygonEditor4.open(); // AMap.event.addListener(_polygonEditor4, 'end', polygonEnd); // path_id = path_id4; // polygon_pa = _polygonEditor4; //} //if (name == Editor5) { // _polygonEditor5.open(); // AMap.event.addListener(_polygonEditor5, 'end', polygonEnd); // path_id = path_id5; // polygon_pa = _polygonEditor5; //} //if (name == Editor6) { // _polygonEditor6.open(); // AMap.event.addListener(_polygonEditor6, 'end', polygonEnd); // path_id = path_id6; // polygon_pa = _polygonEditor6; //} //if (name == Editor7) { // _polygonEditor7.open(); // AMap.event.addListener(_polygonEditor7, 'end', polygonEnd); // path_id = path_id7; // polygon_pa = _polygonEditor7; //} //if (name == Editor8) { // _polygonEditor8.open(); // AMap.event.addListener(_polygonEditor8, 'end', polygonEnd); // path_id = path_id8; // polygon_pa = _polygonEditor8; //} //if (name == Editor9) { // _polygonEditor9.open(); // AMap.event.addListener(_polygonEditor9, 'end', polygonEnd); // path_id = path_id9; // polygon_pa = _polygonEditor9; //} //if (name == Editor10) { // _polygonEditor10.open(); // AMap.event.addListener(_polygonEditor10, 'end', polygonEnd); // path_id = path_id10; // polygon_pa = _polygonEditor10; //} //if (name == Editor11) { // _polygonEditor11.open(); // AMap.event.addListener(_polygonEditor11, 'end', polygonEnd); // path_id = path_id11; // polygon_pa = _polygonEditor11; //} //if (name == Editor12) { // _polygonEditor12.open(); // AMap.event.addListener(_polygonEditor12, 'end', polygonEnd); // path_id = path_id12; // polygon_pa = _polygonEditor12; //} //if (name == Editor13) { // _polygonEditor13.open(); // AMap.event.addListener(_polygonEditor13, 'end', polygonEnd); // path_id = path_id13; // polygon_pa = _polygonEditor13; //} //if (name == Editor14) { // _polygonEditor14.open(); // AMap.event.addListener(_polygonEditor14, 'end', polygonEnd); // path_id = path_id14; // polygon_pa = _polygonEditor14; //} //if (name == Editor15) { // _polygonEditor15.open(); // AMap.event.addListener(_polygonEditor15, 'end', polygonEnd); // path_id = path_id15; // polygon_pa = _polygonEditor15; //} //if (name == Editor16) { // _polygonEditor16.open(); // AMap.event.addListener(_polygonEditor16, 'end', polygonEnd); // path_id = path_id16; // polygon_pa = _polygonEditor16; //} //if (name == Editor17) { // _polygonEditor17.open(); // AMap.event.addListener(_polygonEditor17, 'end', polygonEnd); // path_id = path_id17; // polygon_pa = _polygonEditor17; //} //if (name == Editor18) { // _polygonEditor18.open(); // AMap.event.addListener(_polygonEditor18, 'end', polygonEnd); // path_id = path_id18; // polygon_pa = _polygonEditor18; //} //if (name == Editor19) { // _polygonEditor19.open(); // AMap.event.addListener(_polygonEditor19, 'end', polygonEnd); // path_id = path_id19; // polygon_pa = _polygonEditor19; //} //if (name == Editor20) { // _polygonEditor20.open(); // AMap.event.addListener(_polygonEditor20, 'end', polygonEnd); // path_id = path_id20; // polygon_pa = _polygonEditor20; //} //if (name == Editor21) { // _polygonEditor21.open(); // AMap.event.addListener(_polygonEditor21, 'end', polygonEnd); // path_id = path_id21; // polygon_pa = _polygonEditor21; //} //if (name == Editor22) { // _polygonEditor22.open(); // AMap.event.addListener(_polygonEditor22, 'end', polygonEnd); // path_id = path_id22; // polygon_pa = _polygonEditor22; //} //if (name == Editor23) { // _polygonEditor23.open(); // AMap.event.addListener(_polygonEditor23, 'end', polygonEnd); // path_id = path_id23; // polygon_pa = _polygonEditor23; //} //if (name == Editor24) { // _polygonEditor24.open(); // AMap.event.addListener(_polygonEditor24, 'end', polygonEnd); // path_id = path_id24; // polygon_pa = _polygonEditor24; //} //if (name == Editor25) { // _polygonEditor25.open(); // AMap.event.addListener(_polygonEditor25, 'end', polygonEnd); // path_id = path_id25; // polygon_pa = _polygonEditor25; //} //if (name == Editor26) { // _polygonEditor26.open(); // AMap.event.addListener(_polygonEditor26, 'end', polygonEnd); // path_id = path_id26; // polygon_pa = _polygonEditor26; //} //if (name == Editor27) { // _polygonEditor27.open(); // AMap.event.addListener(_polygonEditor27, 'end', polygonEnd); // path_id = path_id27; // polygon_pa = _polygonEditor27; //} //if (name == Editor28) { // _polygonEditor28.open(); // AMap.event.addListener(_polygonEditor28, 'end', polygonEnd); // path_id = path_id28; // polygon_pa = _polygonEditor28; //} //if (name == Editor29) { // _polygonEditor29.open(); // AMap.event.addListener(_polygonEditor29, 'end', polygonEnd); // path_id = path_id29; // polygon_pa = _polygonEditor29; //} //if (name == Editor30) { // _polygonEditor30.open(); // AMap.event.addListener(_polygonEditor30, 'end', polygonEnd); // path_id = path_id30; // polygon_pa = _polygonEditor30; //} //原来 }); function json2arr(json) { var arr = JSON.parse(json); var res = []; for (var i = 0; i < arr.length; i++) { var line = []; line.push(arr[i].lng); line.push(arr[i].lat); res.push(line); }; return res; } //创建一个多边形对象 function createPolygon(arr) { var polygon = new AMap.Polygon({ map: map, path: arr, strokeColor: "#0000ff", strokeOpacity: 1, strokeWeight: 3, fillColor: "#f5deb3", fillOpacity: 0.35 }); return polygon; } function createEditor(polygon) { var polygonEditor = new AMap.PolyEditor(map, polygon); polygonEditor.open(); AMap.event.addListener(polygonEditor, 'end', polygonEnd); return polygonEditor; } //编辑结束事件 resPolygon显示多边形每个点的坐标,累加的 function polygonEnd(res) { resPolygon.push(res.target); //alert(resPolygon[resNum].contains([116.386328, 39.913818]));// 是不是包含的 那一点 appendHideHtml(resNum, res.target.getPath()); resNum++; init(); } var strify; function appendHideHtml(index, arr) { strify = JSON.stringify(arr); var html = '<input type="hidden" id="index+' + index + '" name="paths[]" value="' + strify + '">'; $('body').append(html); } //function closeEditPolygon() { $("#closeEditPolygon").click(function () { resPolygon = []; var changdu = polygon_pa.sa[0].length; for (var i = 0 ; i < changdu; i++) { var de = polygon_pa.sa[0][i]; resPolygon.push(de.B4); } var PortalId = $("#PortalId").val(); var path = JSON.stringify(resPolygon);//undefined id = path_id; $.ajax({ type: "post", url: '/DesktopModules/AMD_AREASET/test1.ashx', data: { PortalId: PortalId, path: path, path_id: id.toString(), Polygon: "Update_path" }, dataType: "html", success: function (path) { alert("修改成功"); window.location.href = window.location.href; }, error: function () { alert("连接出错!!"); } }); }); $("#closeEditPolygon1").click(function () { polygonEditor.close(); var PortalId = $("#PortalId").val(); var path = strify; var name = document.getElementById("<%=this.DropDownListSalesP.ClientID %>").value; $.ajax({ type: "post", url: '/DesktopModules/AMD_AREASET/test1.ashx', data: { PortalId: PortalId, path: path.toString(), name: name.toString(), Polygon: "Update_path" }, dataType: "html", success: function (data) { alert("成功"); window.location.href = window.location.href; }, error: function () { alert("连接出错!!+1"); } }) }) $("#deletePolygon").click(function () { var name = document.getElementById("<%=this.DropDownListSalesP.ClientID %>").value; $.ajax({ type: "post", url: '/DesktopModules/AMD_AREASET/test1.ashx', data: { PortalId: PortalId, name: name.toString(), Polygon: "delete_path" }, dataType: "html", success: function (data) { alert("删除成功"); window.location.href = window.location.href; }, error: function () { alert("连接出错!!+1"); } }) }); //清空地图 function clearMap() { mapObj.clearMap(); cloudDataLayer.setMap(null); } }); function FinishEditPolygon() { polygonEditor.close(); var PortalId = $("#PortalId").val(); var path = strify; var name = document.getElementById("<%=this.DropDownListSalesP.ClientID %>").value; $.ajax({ type: "post", url: '/DesktopModules/AMD_AREASET/test1.ashx', data: { PortalId: PortalId, path: path.toString(), name: name.toString(), Polygon: "Insert_path" }, dataType: "html", success: function (data) { alert("成功"); //location.replace("http://localhost/平台管理/基础数据维护/销售区域维护") }, error: function () { alert("连接出错!!+1"); } }) }; </script> <div id="container" style="width: 100%; height: 600px;"></div> <div> <div style="display:inline-block;top:5px;position:relative;"> <asp:DropDownList runat="server" ID="DropDownListSalesP" Width="200px" class="form-control" DataSourceID="SqlDataSourceDropSalesP" DataTextField="FullName" DataValueField="FullName" AutoPostBack="false"> </asp:DropDownList> </div> <asp:SqlDataSource ID="SqlDataSourceDropSalesP" runat="server" ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>" SelectCommand="Select FullName from SalesPerson Where Portal_id = @portal_id"> <SelectParameters> <asp:Parameter Name="portal_id" Type="String"/> </SelectParameters> </asp:SqlDataSource> <a href="javascript:void(0)" class="widget widget-hover-effect2 themed-background-muted-light" style="display:inline-block;"> <div > <input type="button" value="开始编辑多边形" id="startEditPolygon" class="widget widget-hover-effect2 themed-background-muted-light" style="border:0px;color:black"/> </div> </a> <a href="javascript:void(0)" class="widget widget-hover-effect2 themed-background-muted-light" style="display:inline-block;"> <div > <input type="button" value="结束编辑多边形" id="closeEditPolygon1" class="widget widget-hover-effect2 themed-background-muted-light" style="border:0px;color:black"/> </div> </a> <a href="javascript:void(0)" class="widget widget-hover-effect2 themed-background-muted-light" style="display:inline-block;"> <div > <input type="button" value="删除多边形" id="deletePolygon" class="widget widget-hover-effect2 themed-background-muted-light" style="border:0px;color:black"/> </div> </a> <a href="javascript:void(0)" class="widget widget-hover-effect2 themed-background-muted-light" style="display:inline-block;"> <div > <button class="widget widget-hover-effect2 themed-background-muted-light" style="border:0px;color:black" onclick="javascript:clearMap();return false;">清除操作 </button> </div> </a> <%--onClick="startEditPolygon()"--%><%--style="width:31%;display:block;float:left;margin-left: 15px;"--%> <%-- <input type="hidden" value="结束编辑多边形" id="closeEditPolygon" class="widget widget-hover-effect2 themed-background-muted-light"/><%--onClick="closeEditPolygon()"--%> <%--<input id="closeEditPolygon1" type="button" value="结束编辑多边形" class="widget widget-hover-effect2 themed-background-muted-light"/>--%> <%--<input type="button" value="删除多边形" id="deletePolygon" class="widget widget-hover-effect2 themed-background-muted-light"/>--%> <%--<input type="button" onClick="FinishEditPolygon()" value="地图编辑完成" />--%> <%--<button class="widget widget-hover-effect2 themed-background-muted-light" onclick="javascript:clearMap();">清除操作 </button>--%> </div> <input type="hidden" id="PortalId" name="" class="" value="<%=PortalIds%>" /> <div id="get_path"></div>
一般处理程序
using DbHelper; using System; using System.Data; using System.Web; namespace AMD_AREASET { /// <summary> /// GetCustomer_paths 的摘要说明 /// </summary> public class test1 : IHttpHandler { DbHelperSQLP dbHelper = new DbHelperSQLP(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string Polygon_val = context.Request.Form["Polygon"]; if (Polygon_val.Equals("getpath")) { string PortalId = context.Request.Form["PortalId"]; string Selectsql = "select * from PolygonCustomer_paths where portal_id=" + PortalId + ";"; DataSet dalist = dbHelper.Query(Selectsql); string jsonname = GetJsonByDataset(dalist); context.Response.Write(jsonname); } else if (Polygon_val.Equals("Update_path")) { string PortalId = context.Request.Form["PortalId"]; string path = context.Request.Form["path"]; string name = context.Request.Form["Name"]; string str = "select SalesPaths from PolygonCustomer_paths where portal_id=" + PortalId + " and SalesName = '" + name + "'"; DataTable dt = DbHelper.DAL.DataTable(str); if (dt.Rows.Count > 0) { string Updatesql = "update PolygonCustomer_paths set SalesPaths='" + path + "' where portal_id=" + PortalId + " and SalesName='" + name + "'"; dbHelper.ExecuteSql(Updatesql); } else { string Insertsql = "insert into PolygonCustomer_paths ([portal_id],[SalesName],[SalesPaths]) values (" + PortalId + ",'" + name + "','" + path + "')"; dbHelper.ExecuteSql(Insertsql); } //string path_id = context.Request.Form["path_id"]; context.Response.Write("编辑成功"); } else if (Polygon_val.Equals("Insert_path")) { string PortalId = context.Request.Form["PortalId"]; string path = context.Request.Form["Path"]; string name = context.Request.Form["Name"]; string Insertsql = "insert into PolygonCustomer_paths ([portal_id],[SalesName],[SalesPaths]) values (" + PortalId + ",'" + name + "','" + path + "')"; dbHelper.ExecuteSql(Insertsql); context.Response.Write("编辑成功"); } //2-27 else if (Polygon_val.Equals("getpathone")) { string name = context.Request.Form["name"]; string PortalId = context.Request.Form["PortalId"]; string Selectsql = "select SalesPaths from PolygonCustomer_paths where portal_id=" + PortalId + " and SalesName = '" + name + "'"; DataSet dalist = dbHelper.Query(Selectsql); string jsonname = Getstring(dalist); context.Response.Write(jsonname); } else if (Polygon_val.Equals("delete_path")) { string name = context.Request.Form["name"]; string PortalId = context.Request.Form["PortalId"]; string Selectsql = "delete from PolygonCustomer_paths where portal_id=" + PortalId + " and SalesName = '" + name + "'"; dbHelper.ExecuteSql(Selectsql); context.Response.Write("删除成功"); } } private string Getstring(DataSet ds) { string str = ""; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { for (int j = 0; j < ds.Tables[0].Columns.Count; j++) { str += "" + ds.Tables[0].Rows[i][j].ToString(); } } return str.ToString(); } /// 把dataset数据转换成json的格式 private string GetJsonByDataset(DataSet ds) { System.Text.StringBuilder str = new System.Text.StringBuilder(); for (int o = 0; o < ds.Tables.Count; o++) { str.Append("{"); str.Append(string.Format("\"{0}\":[", ds.Tables[o].TableName)); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { str.Append("{"); for (int j = 0; j < ds.Tables[0].Columns.Count; j++) { str.Append(string.Format("\"{0}\":\"{1}\",", ds.Tables[0].Columns[j].ColumnName.Replace("\"", "\\\"").Replace("\'", "\\\'"), ds.Tables[0].Rows[i][j].ToString().Replace("\"", "\\\"").Replace("\'", "\\\'")).Replace(Convert.ToString((char)13), "\\r\\n").Replace(Convert.ToString((char)10), "\\r\\n")); } str.Remove(str.Length - 1, 1); str.Append("},"); } str.Remove(str.Length - 1, 1); str.Append("]},"); } str.Remove(str.Length - 1, 1); return str.ToString(); } public bool IsReusable { get { return false; } } private string GetstringL(DataSet ds) { string str = ""; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { for (int j = 0; j < ds.Tables[0].Columns.Count; j++) { if (j == 0) { str += "" + ds.Tables[0].Rows[i][j].ToString() + ","; } else { str += "" + ds.Tables[0].Rows[i][j].ToString() + "?"; } } } return str.ToString(); } } }
再三须慎意,第一莫欺心