<script src="http://cache.amap.com/lbs/static/es5.min.js"></script>
<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=YOUR_API_KEY&plugin=AMap.MouseTool"></script>
<script type="text/javascript">
// set up map canvas.
var map = new AMap.Map('container', {
resizeEnable: true,
center: [121.405034,31.164609],
zoom: 16
});
map.setDefaultCursor("crosshair");
// set up marker.
var marker = new AMap.Marker({
position: [121.405034,31.164609]
});
marker.setMap(map);
// click event to open marker.
marker.on('click',function(e){
infowindow.open(map,e.target.getPosition());
})
// advanced marker, more info.
AMap.plugin('AMap.AdvancedInfoWindow',function(){
infowindow = new AMap.AdvancedInfoWindow({
content: '<div class="info-title">XXX</div><div class="info-content">'+
'<img src="http://webapi.amap.com/images/amap.jpg">'+
'XXX!<br/>'+
'<a class="glyphicon glyphicon-envelope" href = "mailto:info@XXXcn.com">moreinfo</a></div>',
offset: new AMap.Pixel(0, -30)
});
infowindow.open(map,[121.405034,31.164609]);
})
// enable tool kits.
AMap.plugin(['AMap.ToolBar','AMap.Scale','AMap.OverView','AMap.MapType'],
function(){
map.addControl(new AMap.ToolBar());
map.addControl(new AMap.Scale());
map.addControl(new AMap.OverView({isOpen:true})); //遮挡button-group
map.addControl(new AMap.MapType({defaultType:1}));
});
// right button functions.
var mouseTool = new AMap.MouseTool(map);
AMap.event.addDomListener(document.getElementById('areaMeasure'), 'click', function() {
//鼠标工具插件添加draw事件监听
AMap.event.addListener(mouseTool, "draw", function callback(e) {
var eObject = e.obj; //obj属性就是鼠标事件完成所绘制的覆盖物对象。
});
mouseTool.measureArea(); //调用鼠标工具的面积量测功能
map.on('dblclick', function() {
mouseTool.close('True');
});
}, false);
AMap.event.addDomListener(document.getElementById('eargleEye'), 'click', function() {
var drawRectangle = mouseTool.rectangle(); //用鼠标工具画矩形
AMap.event.addListener( mouseTool,'draw',function(e){ //添加事件
var rect = e.obj;
var data = {"minLng" : rect.getBounds().getSouthWest( ).getLng(),
"maxLng" : rect.getBounds().getNorthEast( ).getLng(),
"minLat" : rect.getBounds().getSouthWest( ).getLat(),
"maxLat" : rect.getBounds().getNorthEast( ).getLat(),
"cLng" : rect.getBounds().getCenter( ).getLng(),
"cLat" : rect.getBounds().getCenter( ).getLat()
};
if(confirm("are you sure to submit?"))
{
$.post({
url : "{{ url_for('main.NEWPAGE2', username = current_user.username) }}",
data: JSON.stringify(data),
contentType: 'application/json;charset=UTF-8',
success: function(data) {
top.location.href = "{{ url_for('main.NEWPAGE2', username = current_user.username) }}";
},
async:false
});
}
else
{
mouseTool.close(true);
}
});
}, false);
</script>