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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| var overviewMap=new TMap('overviewmap',[120.349,30.34],18,'emp'); this.overviewMap=overviewMap; var map=this.mainmap;
var mainview=map.getView(); var overviewView=overviewMap.getView();
var extent = map.getView().calculateExtent(map.getSize()); var coor=[[[extent[0],extent[1]],[extent[2],extent[1]],[extent[2],extent[3]],[extent[0],extent[3]],[extent[0],extent[1]]]];
var polygonFeature = new ol.Feature(new ol.geom.Polygon(coor));
var vectorSource = new ol.source.Vector({ features: [polygonFeature] }); var vectorLayer = new ol.layer.Vector({ source:vectorSource, style: new ol.style.Style({ fill: new ol.style.Fill({color: 'rgba(56,166,230,0.4)'}), stroke: new ol.style.Stroke({ color: 'white', width: 2 }) }), zIndex:1000 }); overviewMap.addLayer(vectorLayer);
var overviewMapActiveFlag=false; var mapActiveFlag=false;
mainview.on("change:center",function(){ if(!overviewMapActiveFlag&&!mapActiveFlag){ overviewMapActiveFlag=true; var extent = map.getView().calculateExtent(map.getSize()); var coor=[[[extent[0],extent[1]],[extent[2],extent[1]],[extent[2],extent[3]],[extent[0],extent[3]],[extent[0],extent[1]]]]; vectorLayer.getSource().getFeatures()[0].getGeometry().setCoordinates(coor); setTimeout(function(){ overviewMap.getView().setCenter(map.getView().getCenter()); },300); } mapActiveFlag=false; });
overviewView.on("change:center",function(){ if(!mapActiveFlag&&!overviewMapActiveFlag){ mapActiveFlag=true; mainview.setCenter(overviewView.getCenter()); } overviewMapActiveFlag=false;
});
var overChangeFlag=false; var mapChangeFlag=false; mainview.on("change:resolution",function(){ if(!overChangeFlag&&!mapChangeFlag){ overChangeFlag=true; var zoom=mainview.getZoom(); zoom=zoom-3<0?0:zoom-3; overviewMap.getView().setZoom(zoom);
} mapChangeFlag=false;
});
overviewView.on("change:resolution",function(){ if(!mapChangeFlag&&!overChangeFlag){ mapChangeFlag=true; var zoom=overviewView.getZoom(); zoom=zoom+3>20?20:zoom+3; mainview.setZoom(zoom); } overChangeFlag=false; });
overviewMap.on('pointermove', function (evt) { overviewMap.getTargetElement().style.cursor = 'pointer'; });
overviewMap.on('click',function(e){ var coor = e.coordinate; map.getView().setCenter(coor); });
$(".overviewmap-wrap .overviewmap-close").on("click",function(){ var $this=$(this); if($this.hasClass("open")){ $this.removeClass("open"); $(".overviewmap-wrap .overviewmap").hide(); $this.html(""); }else{ $this.addClass("open"); $(".overviewmap-wrap .overviewmap").show(); $this.html(""); }
})
var translateInteraction=new ol.interaction.Translate({ features:new ol.Collection([polygonFeature]) }); translateInteraction.on("translateend",function(){ var ext=polygonFeature.getGeometry().getExtent(); var center=ol.extent.getCenter(ext); map.getView().setCenter(center); }); overviewMap.addInteraction(translateInteraction);
|