forked from marsprj/Map5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest1.html
192 lines (166 loc) · 5.98 KB
/
test1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../lib/css/Map5.min.css">
<script type="text/javascript" src="../lib/Map5.min.js"></script>
<script type="text/javascript" src="js/citiesValue.js"></script>
<style type="text/css">
body{
margin: 0px;
}
</style>
<script type="text/javascript">
var context = null;
var context1 = null;
var context2 = null;
var canvas_1 = null;
var canvas_2 = null;
var canvas = null;
var x = 300;
var y = 60;
function init(){
// var canvas = document.getElementById("myCanvas");
// context = canvas.getContext('2d');
canvas_1 = document.getElementById("canvas_1");
context1 = canvas_1.getContext("2d");
canvas_2 = document.getElementById("canvas_2");
context2 = canvas_2.getContext("2d");
}
function addImage(){
var image = document.getElementById("park");
context.drawImage(image,100,100,30,30);
}
function rotate(){
context.translate(250,125);
context.rotate(90*Math.PI/180);
context.translate(-250,-125);
}
function onload() {
var canvas = document.getElementById('myCanvas');
var ctx1 = canvas.getContext('2d');
var image1 = new Image();
image1.onload = function() {
// regular rotation about center
var xpos = canvas.width/2;
var ypos = canvas.height/2;
ctx1.drawImage(image1, xpos - image1.width / 2, ypos - image1.height / 2);
ctx1.save();
ctx1.translate(xpos, ypos);
ctx1.rotate(47 * Math.PI / 180);//旋转47度
ctx1.translate(-xpos, -ypos);
ctx1.drawImage(image1, xpos - image1.width / 2, ypos - image1.height / 2);
ctx1.restore();
}
image1.src = 'images/eg_tulip.jpg';
}
function onload2() {
var canvas = document.getElementById('test');
var ctx1 = canvas.getContext('2d');
var image1 = new Image();
image1.onload = function() {
// regular rotation about center
var xpos = canvas.width/2;
var ypos = canvas.height/2;
ctx1.drawImage(image1, xpos - image1.width / 2, ypos - image1.height / 2);
ctx1.save();
ctx1.translate(xpos, ypos);
ctx1.rotate(47 * Math.PI / 180);//旋转47度
ctx1.translate(-xpos, -ypos);
ctx1.drawImage(image1, xpos - image1.width / 2, ypos - image1.height / 2);
ctx1.restore();
}
image1.src = 'images/a.png';
}
function loadImg(){
var canvas = document.getElementById('myCanvas');
var ctx1 = canvas.getContext('2d');
var image1 = new Image();
image1.onload = function() {
// regular rotation about center
var xpos = canvas.width/2;
var ypos = canvas.height/2;
ctx1.drawImage(image1, 20,40);
ctx1.drawImage(image1, -20,-40);
ctx1.save();
ctx1.translate(xpos, ypos);
ctx1.rotate(47 * Math.PI / 180);//旋转47度
ctx1.translate(-xpos, -ypos);
ctx1.drawImage(image1, 20,40);
ctx1.drawImage(image1, -20,-40);
ctx1.restore();
}
image1.src = 'images/tile.png';
}
function addImage_2(){
var image1 = new Image();
image1.onload = function() {
// regular rotation about center
var xpos = 600/2;
var ypos = 400/2;
context2.save();
context2.translate(xpos, ypos);
context2.rotate(20 * Math.PI / 180);
context2.translate(-xpos, -ypos);
context2.drawImage(image1,172,72);
context2.restore();
context2.drawImage(image1,0,0);
// canvas = document.createElement("canvas");
// var context = canvas.getContext("2d");
// context.drawImage(image1,0,0,256,256);
// context2.drawImage(image1,300,60,256,256);
}
image1.src = 'images/tile.png';
}
function addImage_1(){
var xpos = 600/2;
var ypos = 400/2;
context1.translate(xpos, ypos);
context1.rotate(30 * Math.PI / 180);//旋转47度
context1.translate(-xpos, -ypos);
context1.fillRect(300,60,256,256);
// context2.translate(xpos, ypos);
// context2.rotate(30 * Math.PI / 180);//旋转47度
// context2.translate(-xpos, -ypos);
// context2.translate(xpos, ypos);
// context2.rotate(30 * Math.PI / 180);//旋转47度
// context2.translate(-xpos, -ypos);
// context2.translate(x, y);
// context2.rotate(30 * Math.PI / 180);//旋转47度
// context2.translate(-x, -y);
canvas = document.createElement("canvas");
// canvas.width = 300 + 600 * Math.cos(30*Math.PI/180);
// canvas.height = 200 + * Math.sin(30*Math.PI/180);
canvas.width = 600*2;
canvas.height = 400*2;
var context = canvas.getContext("2d");
var x_1 = canvas.width/2;
var y_1 = canvas.height/2;
context.translate(x_1, y_1);
context.rotate(-30 * Math.PI / 180);//旋转47度
context.translate(-x_1, -y_1);
var x_2 = x_1 - canvas_2.width/2;
var y_2 = y_1 - canvas_2.height/2;
context.drawImage(canvas_2,0,0,600,400,x_2,y_2,600,400);
context1.drawImage(canvas_2,300,60,256,256,300,60,256,256);
}
</script>
<title>Map5 -- 地图级别</title>
<body onload="init()">
<!-- mapDiv 为初始化地图的容器,给定高度和宽度,并指定定位方式为绝对定位 -->
<!-- <div id="mapDiv" style="height:800px;width:100%;position:absolute;top:30px;">
</div> -->
<canvas id="myCanvas" width="600" height="400" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.
</canvas>
<canvas id="canvas_1" width="600" height="400"></canvas>
<canvas id="canvas_2" width="600" height="400"></canvas>
<!-- <canvas id="test" width="1600" height="800"></canvas> -->
<img src="images/parking_lot.png" id="park">
<!-- <button onclick="addImage()">添加点</button>
<button onclick="rotate()">旋转</button>
<button onclick="loadImg()">img</button> -->
<br/>
<button onclick="addImage_2()">2_图片</button>
<button onclick="addImage_1()">1_图片</button>
</body>