WeatherBug
温度/レーダー/湿度用に提供されたカスタムレイヤーを適用しようとしています。Google JavaScriptライブラリを使用して、Googleマップになど。
Google マップに透明なタイルを適用する必要があります。
以下のURLからタイル画像を取得します。では、どうすればこれをマップにバインドできますか?
WeatherBug
温度/レーダー/湿度用に提供されたカスタムレイヤーを適用しようとしています。Google JavaScriptライブラリを使用して、Googleマップになど。
Google マップに透明なタイルを適用する必要があります。
以下のURLからタイル画像を取得します。では、どうすればこれをマップにバインドできますか?
これを Google カスタム マップ タイプとして追加できるはずです。基本的に、WeatherBug API をリクエストすると、Google マップで使用できるタイルが返されます。
Google マップのドキュメントはこちらでご覧いただけます。
開始するコードはおそらく次のようになります。この時点から作業を進めることができます。
var tileLayerOverlay = new GTileLayerOverlay(
new GTileLayer(null, null, null, {
tileUrlTemplate: 'http://i.wxbug.net/GEO/Google/Temperature/GetTile_v2.aspx?as=0&c=0&fq=0&tx={X}&ty={Y}&zm={Z}&mw=1&ds=0&stl=0&api_key=xxxxx',
isPng:true,
opacity:1.0
})
);
map.addOverlay(tlo);
また、WeatherBug の説明とそこにあるリンクも確認してください。
以下に触発された WMS サービスのソリューションを次に示します。
必要に応じて機能を簡単に調整できます。
function MCustomTileLayer(map,url) {
this.map = map;
this.tiles = Array();
this.baseurl = url;
this.tileSize = new google.maps.Size(256,256);
this.maxZoom = 19;
this.minZoom = 3;
this.name = 'Custom Layer';
this.visible = true;
this.initialized = false;
this.self = this;
}
MCustomTileLayer.prototype.getTile = function(p, z, ownerDocument) {
for (var n = 0; n < this.tiles.length ; n++) {
if (this.tiles[n].id == 't_' + p.x + '_' + p.y + '_' + z) {
return this.tiles[n];
}
}
var tile = ownerDocument.createElement('IMG');
tile.id = 't_' + p.x + '_' + p.y + '_' + z;
tile.style.width = this.tileSize.width + 'px';
tile.style.height = this.tileSize.height + 'px';
tile.src = this.getTileUrl(p,z);
if (!this.visible) {
tile.style.display = 'none';
}
this.tiles.push(tile);
while (this.tiles.length > 100) {
var removed = this.tiles.shift();
removed = null;
}
return tile;
};
MCustomTileLayer.prototype.getTileUrl = function(p,z) {
var url = this.baseurl +
"&REQUEST=GetMap" +
"&SERVICE=WMS" +
"&VERSION=1.1.1" +
"&BGCOLOR=0xFFFFFF" +
"&TRANSPARENT=TRUE" +
"&SRS=EPSG:3857" +
"&WIDTH=256" +
"&HEIGHT=256" +
"&FORMAT=image/png" +
"&mode=tile" +
"&tilemode=gmap" +
"&tile="+ p.x + "+" + p.y + "+" + z
return url;
}
そんな使い方もできます
var hMap = new MCustomTileLayer(map, "http://my_base_url");
map.overlayMapTypes.insertAt(0, hMap);
そして、オーバーレイを削除するには
map.overlayMapTypes.setAt(0,null);