質問編集履歴
2
文字の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,18 +2,6 @@
|
|
2
2
|
|
3
3
|
OverlayViewとoverlayMapTypesのlayerの順番を制御することは可能でしょうか。
|
4
4
|
|
5
|
-
可能な場合、参考のプログラムなどをお見せしていただけると助かります。
|
6
|
-
|
7
|
-
以下はOverlayViewとoverlayMapTypesのlayerを表示したサンプルです。
|
8
|
-
|
9
|
-
サンプルに記載はないですが、
|
10
|
-
|
11
|
-
複数のOverlayViewのレイヤーをzindexで制御した処理はすでにできており、
|
12
|
-
|
13
|
-
overlayMapTypesをOverlayViewのレイヤーと同じように表示順番の制御をしたいです。
|
14
|
-
|
15
|
-
zIndexを使って表示制御するようにしたいです。
|
16
|
-
|
17
5
|
|
18
6
|
|
19
7
|
![イメージ説明](d69e2db65df7732fdebb602fddf1c237.png)
|
1
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,3 +3,451 @@
|
|
3
3
|
OverlayViewとoverlayMapTypesのlayerの順番を制御することは可能でしょうか。
|
4
4
|
|
5
5
|
可能な場合、参考のプログラムなどをお見せしていただけると助かります。
|
6
|
+
|
7
|
+
以下はOverlayViewとoverlayMapTypesのlayerを表示したサンプルです。
|
8
|
+
|
9
|
+
サンプルに記載はないですが、
|
10
|
+
|
11
|
+
複数のOverlayViewのレイヤーをzindexで制御した処理はすでにできており、
|
12
|
+
|
13
|
+
overlayMapTypesをOverlayViewのレイヤーと同じように表示順番の制御をしたいです。
|
14
|
+
|
15
|
+
zIndexを使って表示制御するようにしたいです。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
![イメージ説明](d69e2db65df7732fdebb602fddf1c237.png)
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
サンプルのコード
|
24
|
+
|
25
|
+
```html
|
26
|
+
|
27
|
+
<!DOCTYPE html>
|
28
|
+
|
29
|
+
<html>
|
30
|
+
|
31
|
+
<head>
|
32
|
+
|
33
|
+
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
|
34
|
+
|
35
|
+
<meta charset="utf-8">
|
36
|
+
|
37
|
+
<title>Adding a Custom Overlay</title>
|
38
|
+
|
39
|
+
<style>
|
40
|
+
|
41
|
+
html, body {
|
42
|
+
|
43
|
+
height: 100%;
|
44
|
+
|
45
|
+
margin: 0px;
|
46
|
+
|
47
|
+
padding: 0px
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
#map-canvas {
|
52
|
+
|
53
|
+
height: 100%;
|
54
|
+
|
55
|
+
width: 70%;
|
56
|
+
|
57
|
+
padding: 0px;
|
58
|
+
|
59
|
+
float:left;
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
#info-box{
|
64
|
+
|
65
|
+
height: 100%;
|
66
|
+
|
67
|
+
width: 30%;
|
68
|
+
|
69
|
+
float:left;
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
</style>
|
74
|
+
|
75
|
+
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
|
76
|
+
|
77
|
+
<script>
|
78
|
+
|
79
|
+
// [START region_initialization]
|
80
|
+
|
81
|
+
// This example creates a custom overlay called USGSOverlay, containing
|
82
|
+
|
83
|
+
// a U.S. Geological Survey (USGS) image of the relevant area on the map.
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
// Set the custom overlay object's prototype to a new instance
|
88
|
+
|
89
|
+
// of OverlayView. In effect, this will subclass the overlay class.
|
90
|
+
|
91
|
+
// Note that we set the prototype to an instance, rather than the
|
92
|
+
|
93
|
+
// parent class itself, because we do not wish to modify the parent class.
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
var overlay;
|
98
|
+
|
99
|
+
USGSOverlay.prototype = new google.maps.OverlayView();
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
var swMarker;
|
104
|
+
|
105
|
+
var neMarker;
|
106
|
+
|
107
|
+
var map;
|
108
|
+
|
109
|
+
// Initialize the map and the custom overlay.
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
function initialize() {
|
114
|
+
|
115
|
+
var mapOptions = {
|
116
|
+
|
117
|
+
zoom: 11,
|
118
|
+
|
119
|
+
center: new google.maps.LatLng(62.323907, -150.109291),
|
120
|
+
|
121
|
+
mapTypeId: google.maps.MapTypeId.SATELLITE
|
122
|
+
|
123
|
+
};
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
var swBound = new google.maps.LatLng(62.281819, -150.287132);
|
132
|
+
|
133
|
+
var neBound = new google.maps.LatLng(62.400471, -150.005608);
|
134
|
+
|
135
|
+
var bounds = new google.maps.LatLngBounds(swBound, neBound);
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
// The photograph is courtesy of the U.S. Geological Survey.
|
140
|
+
|
141
|
+
var srcImage = 'https://developers.google.com/maps/documentation/javascript/';
|
142
|
+
|
143
|
+
srcImage += 'examples/full/images/talkeetna.png';
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
// The custom USGSOverlay object contains the USGS image,
|
148
|
+
|
149
|
+
// the bounds of the image, and a reference to the map.
|
150
|
+
|
151
|
+
overlay = new USGSOverlay(bounds, srcImage, map);
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
// Let's create two markers that will act as holders of the Overlay bounds.
|
156
|
+
|
157
|
+
swMarker = new google.maps.Marker({
|
158
|
+
|
159
|
+
position: swBound,
|
160
|
+
|
161
|
+
map: map, // handle of the map
|
162
|
+
|
163
|
+
draggable:true
|
164
|
+
|
165
|
+
});
|
166
|
+
|
167
|
+
neMarker = new google.maps.Marker({
|
168
|
+
|
169
|
+
position: neBound,
|
170
|
+
|
171
|
+
map: map, // handle of the map
|
172
|
+
|
173
|
+
draggable:true
|
174
|
+
|
175
|
+
});
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
//this callback will be called everytime the markers are moved
|
180
|
+
|
181
|
+
// updating the Overlay bounds.
|
182
|
+
|
183
|
+
var dragcallback = function(){
|
184
|
+
|
185
|
+
document.getElementById('sw-lat').value = swMarker.position.lat();
|
186
|
+
|
187
|
+
document.getElementById('sw-lon').value = swMarker.position.lng();
|
188
|
+
|
189
|
+
document.getElementById('ne-lat').value = neMarker.position.lat()
|
190
|
+
|
191
|
+
document.getElementById('ne-lon').value = neMarker.position.lng();
|
192
|
+
|
193
|
+
overlay.bounds_ = new google.maps.LatLngBounds(swMarker.position, neMarker.position);
|
194
|
+
|
195
|
+
overlay.draw();
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
google.maps.event.addListener(swMarker,'drag',dragcallback);
|
200
|
+
|
201
|
+
google.maps.event.addListener(neMarker,'drag',dragcallback);
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
//ADD ImageMaptype
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
var weatherMapType = new google.maps.ImageMapType({
|
212
|
+
|
213
|
+
getTileUrl: function(coord, zoom) {
|
214
|
+
|
215
|
+
return 'http://tile.openstreetmap.org/'
|
216
|
+
|
217
|
+
+ zoom + '/'
|
218
|
+
|
219
|
+
+ coord.x + '/'
|
220
|
+
|
221
|
+
+ coord.y + '.png';
|
222
|
+
|
223
|
+
},
|
224
|
+
|
225
|
+
tileSize: new google.maps.Size(256, 256),
|
226
|
+
|
227
|
+
maxZoom: 9, //表示する最大のズーム値
|
228
|
+
|
229
|
+
minZoom: 0, //表示する最小のズーム値
|
230
|
+
|
231
|
+
name: 'clouds_new'
|
232
|
+
|
233
|
+
});
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
map.overlayMapTypes.insertAt(0, weatherMapType);
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
// [END region_initialization]
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
// [START region_constructor]
|
248
|
+
|
249
|
+
/** @constructor */
|
250
|
+
|
251
|
+
function USGSOverlay(bounds, image, map) {
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
// Initialize all properties.
|
256
|
+
|
257
|
+
this.bounds_ = bounds;
|
258
|
+
|
259
|
+
this.image_ = image;
|
260
|
+
|
261
|
+
this.map_ = map;
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
// Define a property to hold the image's div. We'll
|
266
|
+
|
267
|
+
// actually create this div upon receipt of the onAdd()
|
268
|
+
|
269
|
+
// method so we'll leave it null for now.
|
270
|
+
|
271
|
+
this.div_ = null;
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
// Explicitly call setMap on this overlay.
|
276
|
+
|
277
|
+
this.setMap(map);
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
// [END region_constructor]
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
// [START region_attachment]
|
286
|
+
|
287
|
+
/**
|
288
|
+
|
289
|
+
* onAdd is called when the map's panes are ready and the overlay has been
|
290
|
+
|
291
|
+
* added to the map.
|
292
|
+
|
293
|
+
*/
|
294
|
+
|
295
|
+
USGSOverlay.prototype.onAdd = function() {
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
var div = document.createElement('div');
|
300
|
+
|
301
|
+
div.style.borderStyle = 'none';
|
302
|
+
|
303
|
+
div.style.borderWidth = '0px';
|
304
|
+
|
305
|
+
div.style.position = 'absolute';
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
// Create the img element and attach it to the div.
|
310
|
+
|
311
|
+
var img = document.createElement('img');
|
312
|
+
|
313
|
+
img.src = this.image_;
|
314
|
+
|
315
|
+
img.style.width = '100%';
|
316
|
+
|
317
|
+
img.style.height = '100%';
|
318
|
+
|
319
|
+
img.style.position = 'absolute';
|
320
|
+
|
321
|
+
img.style.opacity = '0.6';
|
322
|
+
|
323
|
+
img.style.filter = 'alpha(opacity=60)';
|
324
|
+
|
325
|
+
div.appendChild(img);
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
this.div_ = div;
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
// Add the element to the "overlayLayer" pane.
|
334
|
+
|
335
|
+
var panes = this.getPanes();
|
336
|
+
|
337
|
+
panes.overlayLayer.appendChild(div);
|
338
|
+
|
339
|
+
};
|
340
|
+
|
341
|
+
// [END region_attachment]
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
// [START region_drawing]
|
346
|
+
|
347
|
+
USGSOverlay.prototype.draw = function() {
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
// We use the south-west and north-east
|
352
|
+
|
353
|
+
// coordinates of the overlay to peg it to the correct position and size.
|
354
|
+
|
355
|
+
// To do this, we need to retrieve the projection from the overlay.
|
356
|
+
|
357
|
+
var overlayProjection = this.getProjection();
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
// Retrieve the south-west and north-east coordinates of this overlay
|
362
|
+
|
363
|
+
// in LatLngs and convert them to pixel coordinates.
|
364
|
+
|
365
|
+
// We'll use these coordinates to resize the div.
|
366
|
+
|
367
|
+
var sw = overlayProjection.fromLatLngToDivPixel(this.bounds_.getSouthWest());
|
368
|
+
|
369
|
+
var ne = overlayProjection.fromLatLngToDivPixel(this.bounds_.getNorthEast());
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
// Resize the image's div to fit the indicated dimensions.
|
374
|
+
|
375
|
+
var div = this.div_;
|
376
|
+
|
377
|
+
div.style.left = sw.x + 'px';
|
378
|
+
|
379
|
+
div.style.top = ne.y + 'px';
|
380
|
+
|
381
|
+
div.style.width = (ne.x - sw.x) + 'px';
|
382
|
+
|
383
|
+
div.style.height = (sw.y - ne.y) + 'px';
|
384
|
+
|
385
|
+
};
|
386
|
+
|
387
|
+
// [END region_drawing]
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
// [START region_removal]
|
392
|
+
|
393
|
+
// The onRemove() method will be called automatically from the API if
|
394
|
+
|
395
|
+
// we ever set the overlay's map property to 'null'.
|
396
|
+
|
397
|
+
USGSOverlay.prototype.onRemove = function() {
|
398
|
+
|
399
|
+
this.div_.parentNode.removeChild(this.div_);
|
400
|
+
|
401
|
+
this.div_ = null;
|
402
|
+
|
403
|
+
};
|
404
|
+
|
405
|
+
// [END region_removal]
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
google.maps.event.addDomListener(window, 'load', initialize);
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
</script>
|
418
|
+
|
419
|
+
</head>
|
420
|
+
|
421
|
+
<body>
|
422
|
+
|
423
|
+
<div id="info-box">
|
424
|
+
|
425
|
+
<br/>
|
426
|
+
|
427
|
+
<br/>
|
428
|
+
|
429
|
+
<label for="sw-lat">SW Lat</label>
|
430
|
+
|
431
|
+
<input id="sw-lat" name="sw-lat" type="text" value="" readonly="readonly"/><br/>
|
432
|
+
|
433
|
+
<label for="sw-lon">SW Lon</label>
|
434
|
+
|
435
|
+
<input id="sw-lon" name="sw-lon" type="text" value="" readonly="readonly"/><br/>
|
436
|
+
|
437
|
+
<label for="ne-lat">NE Lat</label>
|
438
|
+
|
439
|
+
<input id="ne-lat" name="ne-lat" type="text" value="" readonly="readonly"/><br/>
|
440
|
+
|
441
|
+
<label for="ne-lon">NE Lon</label>
|
442
|
+
|
443
|
+
<input id="ne-lon" name="ne-lon" type="text" value="" readonly="readonly"/>
|
444
|
+
|
445
|
+
</div>
|
446
|
+
|
447
|
+
<div id="map-canvas"></div>
|
448
|
+
|
449
|
+
</body>
|
450
|
+
|
451
|
+
</html>
|
452
|
+
|
453
|
+
```
|