var map = new AMap.Map('container', { center: [ 116.387175, 39.876405 ], zoom: 13 }); var southWest = new AMap.LngLat(116.356449, 39.859008) var northEast = new AMap.LngLat(116.417901, 39.893797) var bounds = new AMap.Bounds(southWest, northEast) var rectangle = new AMap.Rectangle({ bounds: bounds, strokeColor:'red', strokeWeight: 6, strokeOpacity:0.5, strokeDasharray: [30,10], strokeStyle: 'dashed', fillColor:'blue', fillOpacity:0.5, cursor:'pointer', zIndex:50, }) console.log(rectangle.getBounds()); rectangle.setMap(map) // 缩放地图到合适的视野级别 map.setFitView([ rectangle ]) var rectangleEditor = new AMap.RectangleEditor(map, rectangle) rectangleEditor.on('adjust', function(event) { log.info('触发事件:adjust') }) rectangleEditor.on('end', function(event) { log.info('触发事件: end') // event.target 即为编辑后的矩形对象 })
<div class="input-card" style="width: 120px"> <button class="btn" onclick="rectangleEditor.open()" style="margin-bottom: 5px">开始编辑</button> <button class="btn" onclick="rectangleEditor.close()">结束编辑</button> </div>
lockdatav Done!