获取矩形左下角和右上角经纬度
<div id="container"></div>
var map = new AMap.Map('container'); var mouseTool = new AMap.MouseTool(map); var drawRectangle = mouseTool.rectangle(); var newArr = []; AMap.event.addListener(mouseTool, 'draw', function (e) { //console.log(e.obj.getPath());//获取路径 var points = e.obj.getPath(); for (var i = 0; i < points.length; i++) { newArr.push([points[i].lng, points[i].lat]); // 创建纯文本标记 if (i == 1 || i == 3) { var text = new AMap.Text({ text: newArr[i], anchor: 'top-left', // 设置文本标记锚点 //draggable: true, cursor: 'pointer', clickable: true, style: { 'padding': '10px', 'border-radius': '5px', 'background-color': 'white', 'border-width': 0, 'text-align': 'center', 'font-size': '12px', 'color': 'blue' }, position: newArr[i] }); text.setMap(map); } } console.log('northEast:' + newArr[1]); console.log('southWest:' + newArr[3]); }); // 清除地图上所有添加的覆盖物 function removeAllOverlay() { map.clearMap(); }
添加自定义图片覆盖物
var imageLayer = new AMap.ImageLayer({ url: 'http://test.com/amap/map.png', bounds: new AMap.Bounds( [121.544481, 29.813555],//左下角 [121.546541, 29.816339]//右上角 ), zooms: [15, 18] }); var map = new AMap.Map('container', { resizeEnable: true, center: [121.546541, 29.816339], zoom: 15, layers: [ new AMap.TileLayer(), imageLayer ] });
lockdatav Done!