我想在谷歌地图上画点东西。所以我想在地图上放一个画布,然后画一些东西,只是这会阻止与地图的交互。我怎样才能绘制一些东西,但让地图的其余部分保持交互?相关代码片段:
款式:
<style>
#myCanvas {
border: 1px solid #9C9898;
}
#canvas-wrap {
position:relative;
} /* Make this a positioned parent */
#map_canvas {
position:absolute;
top:0px;
left:0px;
z-index: -1;
}
</style>
Javascript:
<script type="text/javascript">
function loadMap() {
var fenway = new google.maps.LatLng(42.345573,-71.098326);
var mapOptions = {center: fenway, zoom: 14, mapTypeId: google.maps.MapTypeId.ROADMAP };
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
}
function drawLine(){
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
context.beginPath();
context.moveTo(100, 100);
context.lineTo(400, 400);
context.lineWidth = 9;
context.stroke();
};
function init(){
loadMap();
drawLine();
}
</script>
HTML:
<div id="canvas-wrap">
<canvas id="myCanvas" width="600px" height="600px"></canvas>
<div id="map_canvas" style="width: 600px; height: 600px"></div>
</div>