我有一张地图图片,想要使用HTML5和jQuery制作类似谷歌地图的界面。我想实现以下操作:
• Double click on pan in without changing the size of the containing div
• Click on a building to bring up a pop up of information on that building
• Click and drag to pan
我现在拥有的代码是画布中的图像。我找到了几个可以显示图像“缩放”的代码,但要么调整容器div的大小,要么不够平滑和响应。它只会跳转到更大的尺寸,而我希望缩放是有动画效果的。
地图上会有几座建筑物被“固定”,用户可以单击它们以获取有关该建筑物的信息。
以下是代码:
JS:
$( document ).ready( function() {
var canvas = document.getElementById( 'canvas' );
var context = null;
var map = null;
if( canvas.getContext )
{
context = canvas.getContext( '2d' );
$( '#map' ).load( function( evt ) {
context.drawImage( evt.currentTarget, 10, 10 );
} );
map = new Image();
map.onload = function() {
context.drawImage( this, 20, 20 );
};
map.src = 'images/asu_poly_map.png';
} else {
alert( 'Your browser does not support canvas.' );
}
} );
HTML:
<div id="map">
<canvas id="canvas" width="1055" height="600"></canvas>
</div>
CSS:
#map {
margin:0 auto;
margin-top : 180px;
width : 1200px;
}
编辑后添加: 我假定它与这个类似,但是无法弄清如何将其应用于从服务器上绘制到画布上的图像。