|  |  |  | 
|---|
|  |  |  | <script> | 
|---|
|  |  |  | var baiduMap; | 
|---|
|  |  |  | var markerManager = { | 
|---|
|  |  |  | data: {}, | 
|---|
|  |  |  | data: { | 
|---|
|  |  |  | _regionName:null, | 
|---|
|  |  |  | _boundary:[], | 
|---|
|  |  |  | _boundaryState:false | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | bind: {} | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | markerManager.bindSelect = function (key, select) { | 
|---|
|  |  |  | 
|---|
|  |  |  | console.log("int markerManager key:" + key + ",don't bind select"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | markerManager.setRegionName = function (regionName){ | 
|---|
|  |  |  | this.data._regionName = regionName; | 
|---|
|  |  |  | function getBoundary(regionName){ | 
|---|
|  |  |  | var bdary = new BMap.Boundary(); | 
|---|
|  |  |  | var map = baiduMap; | 
|---|
|  |  |  | bdary.get(regionName, function(rs){       //获取行政区域 | 
|---|
|  |  |  | map.clearOverlays();        //清除地图覆盖物 | 
|---|
|  |  |  | var count = rs.boundaries.length; //行政区域的点有多少个 | 
|---|
|  |  |  | if (count === 0) { | 
|---|
|  |  |  | alert('未能获取当前输入行政区域'); | 
|---|
|  |  |  | return ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // var pointArray = []; | 
|---|
|  |  |  | var polygonArray = []; | 
|---|
|  |  |  | for (var i = 0; i < count; i++) { | 
|---|
|  |  |  | var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 2,fillOpacity:0.01,strokeStyle:"dashed",strokeColor: "#0000ff"}); //建立多边形覆盖物 | 
|---|
|  |  |  | // map.addOverlay(ply);  //添加覆盖物 | 
|---|
|  |  |  | // pointArray = pointArray.concat(ply.getPath()); | 
|---|
|  |  |  | polygonArray.push(ply); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // map.setViewport(pointArray);    //调整视野 | 
|---|
|  |  |  | //addlabel(); | 
|---|
|  |  |  | //设置边界 | 
|---|
|  |  |  | markerManager.data._boundary = polygonArray; | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | getBoundary(regionName); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | markerManager.openBoundary = function(){ | 
|---|
|  |  |  | debugger; | 
|---|
|  |  |  | console.log(this.data._boundary); | 
|---|
|  |  |  | if(!!this.data._boundary&&this.data._boundary.length>0){ | 
|---|
|  |  |  | for(var n =0 ;n< this.data._boundary.length;n++){ | 
|---|
|  |  |  | baiduMap.addOverlay(this.data._boundary[n]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.data._boundaryState = true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | markerManager.closeBoundary = function(){ | 
|---|
|  |  |  | for(var n =0 ;n< this.data._boundary.length;n++){ | 
|---|
|  |  |  | baiduMap.removeOverlay(this.data._boundary[n]); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.data._boundaryState = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | markerManager.isBoundaryState = function() { | 
|---|
|  |  |  | return this.data._boundaryState; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | markerManager.addMarker = function (key, marker) { | 
|---|
|  |  |  | this.data[key] = !!this.data[key] ? this.data[key] : []; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | { | 
|---|
|  |  |  | text: '打开边界', | 
|---|
|  |  |  | callback: function () { | 
|---|
|  |  |  | if(!markerManager.isBoundaryState()){ | 
|---|
|  |  |  | markerManager.openBoundary(); | 
|---|
|  |  |  | if(markerManager.isBoundaryState()){ | 
|---|
|  |  |  | this.setText("关闭边界"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | markerManager.closeBoundary(); | 
|---|
|  |  |  | this.setText("打开边界"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | { | 
|---|
|  |  |  | text: '清空地图', | 
|---|
|  |  |  | callback: function (menuItem) { | 
|---|
|  |  |  | var result = confirm('注意! 注意! 注意! 一旦清除后将无法恢复') | 
|---|
|  |  |  | 
|---|
|  |  |  | var searchValue = $('.search-box').val(); | 
|---|
|  |  |  | if (!!searchValue) { | 
|---|
|  |  |  | baiduMap.centerAndZoom(searchValue); | 
|---|
|  |  |  | markerManager.setRegionName(searchValue); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | markerManager.bindSelect("mpoint", "#mpointCount"); | 
|---|