チュートリアル7のソースを表示
←
チュートリアル7
ナビゲーションに移動
検索に移動
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループに属する利用者のみが実行できます:
登録利用者
。
このページのソースの閲覧やコピーができます。
=チュートリアル7 WebApp Layer ベクトルタイル= 実際の動作は、[https://svgmap.org/devinfo/devkddi/tutorials/tiling1/tiling1.html こちら]をクリック。 ==tiling1.html== *[[チュートリアル6]]のhtmlと特に違いはありません。 **同様に[[解説書#svgMapGIStool..E3.81.A7.E5.91.BC.E3.81.B3.E5.87.BA.E3.81.9B.E3.82.8BAPI|SVGMap GISライブラリ]]を導入しています。 <pre> <!DOCTYPE html> <html> <title>SVGMapLevel0.1-Rev14-Draft Tutorial2 Coastline & Air Port</title> <!-- viewport 知表示領域を画面全体とする定義 --> <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0" /> <meta charset="UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <!-- SVGMapのコアAPIの読み込み --> <script type="text/javascript" src="../js/SVGMapLv0.1_r17.js"></script> <script type="text/javascript" src="../js/SVGMapLv0.1_LayerUI2_r4.js"></script> <!-- SVGMap GISライブラリの読み込み--> <script type="text/javascript" src="../js/jsts.min.js"></script> <script type="text/javascript" src="../js/SVGMapLv0.1_GIS_r3.js"></script> <!-- レイヤーリストUIのスタイルシート読み込み --> <link href="../js/layerListStyle.css" rel="stylesheet" type="text/css"> <body bgcolor="#ffffff" style="overflow:hidden;" > <!-- 地図SVGファイル(レイヤー)を複数含むコンテナファイル(Container.svg)の読み込み --> <div id="mapcanvas" data-src="Container.svg"></div> <div id="gui"> <!-- ズームアップボタン --> <img id="zoomupButton" style="left: 5px; top: 5px; position: absolute;" src="../img/zoomup.png" onclick="svgMap.zoomup()" width="20" height="20" /> <!-- ズームダウンボタン --> <img id="zoomdownButton" style="left: 5px; top: 25px; position: absolute;" src="../img/zoomdown.png" onclick="svgMap.zoomdown()" width="20" height="20" /> <!-- GPSボタン --> <img id="gpsButton" style="left: 5px; top: 45px; position: absolute;" src="../img/gps.png" onclick="svgMap.gps()" width="20" height="20" /> <!-- 画面右上に表示するタイトル --> <font color="blue" style="right: 5px; top: 5px; position: absolute;" >SVGMapLevel0.1 Rev14 Draft : Tutorial2 Coastline & Air Port</font> <!-- 画面右下に表示する --> <font color="blue" style="right: 5px; bottom: 5px; position: absolute;" size="-2" >by SVGMap tech.</font> <!-- 中央に表示される十字マーク --> <img id="centerSight" style="opacity:0.5" src="../img/Xcursor.png" width="15" height="15"/> <!-- 画面左下に表示される十字マークの緯度・経度(タイトル) --> <font id="posCmt" size="-2" color="brown" style="left: 5px; bottom: 5px; position: absolute;">Lat,Lng:</font> <!-- 画面左下に表示される十字マークの緯度・経度(実際の値の初期表示) --> <font id="centerPos" size="-2" color="brown" style="left: 50px; bottom: 5px; position: absolute;" >lat , lng</font> <!-- レイヤーリストUIの表示 --> <div id="layerList" style="left :30px; top: 10px; width:300px;height:90%; position: absolute; "></div> </div> </body> </html> </pre> ==Container.svg== *[[チュートリアル6]]のhtmlと特に違いはありません。 ** GeoJsonデータはベクトルタイルデータのため、class属性で[[解説書#class.E5.B1.9E.E6.80.A7.E3.81.AB.E3.82.88.E3.82.8B.E3.83.AC.E3.82.A4.E3.83.A4.E3.83.BC.E3.81.AE.E3.82.B0.E3.83.AB.E3.83.BC.E3.83.94.E3.83.B3.E3.82.B0.E3.83.BB.E3.82.AF.E3.83.AA.E3.83.83.E3.82.AB.E3.83.96.E3.83.AB.E6.A9.9F.E8.83.BD.E3.81.AE.E6.8F.90.E4.BE.9B|clickable]]を指定しています。 <pre> <?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="122.9800817, -45.398095, 21.97626, 21.0533039" > <globalCoordinateSystem srsName="http://purl.org/crs/84" transform="matrix(1,0,0,-1,0,0)" /> <!-- OpenStretMap背景地図を表示状態として読み込む --> <animation xlink:href="../tutorial5/dynamicOSM_r11.svg" x="-3000" y="-3000" width="6000" height="6000" title="Japan Coastline" class="basemap" visibility="visible"/> <!-- 日本の公共施設データのPoint CSVファイルのタイルデータを表示状態として読み込む --> <animation xlink:href="simpleTiling.svg" x="-3000" y="-3000" width="6000" height="6000" title="Cultural Facility" class="POI clickable" visibility="visible"/> </svg> </pre> ==simpleTiling.svg== **defs要素でアイコンを定義しています。 **データの実体はここにはありません。webAppで動的に生成されます。 **id="mapTiles"のグループ内に、タイルごとにサブグループが作られ、そこにアイコン(Point)が配置されます。 <pre> <?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-42.8202042942663, -49.9999999999999, 513.842451531196, 600" xmlns:go="http://purl.org/svgmap/profile" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" property="" data-controller="simpleTiling.html#exec=appearOnLayerLoad"> <defs> <g id="p0"> <circle cx="0" cy="0" r="5" fill="blue"/> </g> </defs> <globalCoordinateSystem srsName="http://purl.org/crs/84" transform="matrix(100,0,0,-100,0,0)" /> <g id="mapTiles"> </g> </svg> </pre> ==simpleTiling.html== *simpleTiling.svgに紐付けられ、[[解説書#.E3.83.AC.E3.82.A4.E3.83.A4.E3.83.BC.E5.9B.BA.E6.9C.89.E3.81.AEUI|そのDOMをコントロールできるwebApp]] *表示領域に応じてタイル分割されたGeoJsonデータを動的に読み込みます。この点は[[チュートリアル5]]と類似しています。 **縮尺に応じたピラミッド構造は持っていないので、このチュートリアルのほうが単純です。 **その代わり、小縮尺(縮小表示)では読み込むデータが大量になりすぎるので、読み込みを行わず、webAppのウィンド上に拡大を促すメッセージを出します。 *<code>addEventListener("zoomPanMap",zpmFunc)</code>: 伸縮スクロールが発生したときに、 zpmFunc()を呼び出す。 *<code>zpmFunc()</code>: 表示領域に応じて読み込むべきタイルを選別して表示する **<code>svgMap.getGeoViewBox()</code>: 地理的な表示領域を取得 **<code>getTileList(geoViewBox)</code>:表示すべきタイルをリストアップする **<code>delete tiles[tileKey]</code>表示領域から外れたタイルのグループを消去 **<code>await loadCSV()</code>: 既に読み込み済みのものを除き、表示すべきタイルデータ(CSV)を読み込み **<code>drawTiles()</code>:読み込んだCSVデータを表示する ***タイルを表示するためのグループを作成 ***<code>csv2geojson</code>: 読み込んだCSVからgeoJsonを生成する ***<code>svgMapGIStool.drawGeoJson()</code>: geoJsonからSVGのDOMを生成 <pre> <!doctype html> <html> <head> <title>Simple Tiling Tutorial</title> <meta charset="utf-8"></meta> </head> <script> addEventListener("load",init); addEventListener("zoomPanMap",zpmFunc); var latCol=10; var lngCol=9; var tilesTh=8; // 画面の中に入るタイルの枚数の閾値(縮小すると読み込むタイルが多くなりすぎ重くなるのを防ぐ) function init(){ zpmFunc(); } function getTileList(geoViewBox){ var tileNames={}; for ( var ty = Math.floor(geoViewBox.y) ; ty<= Math.floor(geoViewBox.y+geoViewBox.height) ; ty++){ for ( var tx = Math.floor(geoViewBox.x) ; tx <= Math.floor(geoViewBox.x+geoViewBox.width) ; tx++){ var tile="tile_" + tx + "_" + ty; tileNames[tile]=true; } } return ( tileNames); } var tiles={}; // データ(CSVを配列化したもの)をタイルごとに格納する変数 async function zpmFunc(){ var geoViewBox = svgMap.getGeoViewBox(); var tileList=getTileList(geoViewBox); if (Object.keys(tileList).length < tilesTh ){ for ( var tileKey in tiles ){ // 必要ないデータを消す if ( !tileList[tileKey]){ delete tiles[tileKey]; } } for ( var tileKey in tileList ){ // 不足しているデータを読み込む if ( !tiles[tileKey] ){ tiles[tileKey]=await loadCSV(`tiles/${tileKey}.csv`); // テンプレートリテラル } } message.innerText="-"; drawTiles(tileList); } else { message.innerText="Too many tiles, please zoom in."; removeAllTiles(); } } function removeAllTiles(){ tiles={}; var groups = svgImage.getElementById("mapTiles").children; for ( var i = groups.length -1 ; i >= 0 ; i-- ){ groups[i].remove(); } svgMap.refreshScreen(); } function drawTiles(tileList){ // tileList:表示すべきタイルのキー(ID)の連想配列 var tileGroup = svgImage.getElementById("mapTiles"); var groups = tileGroup.children; for ( var i = groups.length -1 ; i >= 0 ; i-- ){ var groupKey = groups[i].getAttribute("id"); if ( !tileList[groupKey]){ groups[i].remove(); // 表示する必要のないグループは消す } else { delete tileList[groupKey]; // すでに描画済みのタイルなのでtileListから消す } } // tileListは、新たに描画すべきタイルのリストとなった for ( var tileKey in tileList){ var grp = svgImage.createElement("g"); grp.setAttribute("id",tileKey); tileGroup.appendChild(grp); if ( tiles[tileKey] ){ var geoJson = csv2geojson(tiles[tileKey], lngCol, latCol); svgMapGIStool.drawGeoJson(geoJson, layerID, "", 0, "", "p0", "poi", "", grp); } } svgMap.refreshScreen(); } var schema; async function loadCSV(url){ var response = await fetch(url); if ( response.ok ){ var txt = await response.text(); txt=txt.split("\n"); var csv=[]; var schemaLine = true; for ( line of txt){ line = line.trim(); if ( schemaLine ){ schema = line; svgImage.documentElement.setAttribute("property",schema); } else { if ( line !=""){ line=line.split(","); csv.push(line); } } schemaLine = false; } return ( csv ); } else { return ( null ); } } function csv2geojson(csvArray, lngCol, latCol){ var geoJson = {type: "FeatureCollection", features: []} for ( var csvRecord of csvArray ){ var lng = Number(csvRecord[lngCol]); var lat = Number(csvRecord[latCol]); var feature = { type: "Feature", geometry: { type: "Point", "coordinates": [lng, lat] }, "properties": { "csvMetadata": csvRecord.toString() // この処理は非常に雑です。 } } geoJson.features.push(feature); } return(geoJson); } </script> <body> <h3>CSVタイルデータの表示</h3> <div id="message">-</div> </body> </html> </pre>
チュートリアル7
に戻る。
ナビゲーション メニュー
個人用ツール
ログイン
名前空間
ページ
議論
日本語
表示
閲覧
ソースを閲覧
履歴表示
その他
検索
案内
メインページ
最近の更新
おまかせ表示
MediaWiki についてのヘルプ
ツール
リンク元
関連ページの更新状況
特別ページ
ページ情報