ラベル Permalink の投稿を表示しています。 すべての投稿を表示
ラベル Permalink の投稿を表示しています。 すべての投稿を表示

2015年5月23日土曜日

2 - ol3.5ex 117b - Permalink example 2

「permalink.js(2117-ol3ex.js)」は、マップを表示するための JavaScript ファイルです。

「2117-ol3ex.js」
// default zoom, center and rotation
var zoom = 2;
var center = [0, 0];
var rotation = 0;
if (window.location.hash !== '') {
/** window.location
 * 文書の URL についての情報を含み、また、URL を変更するためのメ
 * ソッドを提供をする、 Location オブジェクト を返します。別の 
 * URL を読み込ませるために、このプロパティに URL を代入すること
 * もできます。
 * hash [プロパティ] - #記号に続く URL の部分。
 * (MDN[https://developer.mozilla.org/ja/docs/Web/API/
 * Window/location])
 */
 //try to restore center,zoom-level and rotation from the URL
 // URL から中心、ズームレベルと回転を復元します
 var hash = window.location.hash.replace('#map=', '');
 /** replace [メソッド]
  * 指定された URL に現在の文書を置き換えます。 assign() メソッ
  * ドとの違いは、replace() を用いた後、現在のページは、セッショ
  * ンの履歴には保持されないことです。つまり、ユーザは、置き換え
  * 前のページに戻るために、戻るボタンを使うことができません。
 * (MDN[https://developer.mozilla.org/ja/docs/Web/API/
 * Window/location])
  */
 var parts = hash.split('/');
 /** str.split([separator[, limit]])
  *separator:区切ることに使用する文字列,limit:分割結果の数の制限
  * 文字列を複数の部分文字列に区切ることにより、String オブジェ
  * クトを文字列の配列に分割します。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * JavaScript/Reference/Global_Objects/String/split])
  */
 if (parts.length === 4) {
  zoom = parseInt(parts[0], 10);
  /** parseInt(string, radix)
   * str: 文字列, radix: 基数(進法)
   * 文字列の引数をパースし、指定された基数の整数を返します。
   * (MDN[https://developer.mozilla.org/ja/docs/Web/
   * JavaScript/Reference/Global_Objects/parseInt])
   */
  center = [
   parseFloat(parts[1]),
   /** parseFloat()
    *引数として与えられた文字列を解析し、浮動小数点数を返します。
    * (MDN[https://developer.mozilla.org/ja/docs/Web/
    * JavaScript/Reference/Global_Objects/parseFloat])
    */ 
   parseFloat(parts[2])
  ];
  rotation = parseFloat(parts[3]);
 }
}
var map = new ol.Map({
 layers: [
  new ol.layer.Tile({
  /** ol.layer.Tile 
   * For layer sources that provide pre-rendered, tiled 
   * images in grids that are organized by zoom levels for 
   * specific resolutions. 
   * プリレンダリング(事前描画)を提供するレイヤソースのための、
   * 特定の解像度でのズームレベルによって編成されているグリッドの
   * タイルイメージ。(ol3 API)
   */
   source: new ol.source.OSM()
   /** ol.source.OSM 
    * Layer source for the OpenStreetMap tile server.
    * OpenStreetMap タイルサーバのレイヤソース。(ol3 API)
    */
  })
 ],
 controls: ol.control.defaults({
 /** controls
  * Controls initially added to the map. 
  * If not specified, ol.control.defaults() is used.
  * 初期設定で、マップに追加されたコントロール。
  * 明示されていなければ、ol.control.defaults() が使用されます。
  * (ol3 API)
  */
 /** ol.control.defaults()
  * デフォルトでは、マップに含まコントロールのセット。
  * 特に設定しない限り、これは、以下の各コントロールの
  * インスタンスを含むコレクションを返します。(ol3 API)
  * ol.control.Zoom, ol.control.Rotate, ol.control.Attribution
  */
  attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
  /** @type 
   * 値のタイプ(型)の説明 - 式などで表示
   * (@use JSDoc[http://usejsdoc.org/]より)
   */
   collapsible: false // 折りたたみ
  })
 }),
 target: 'map',
 view: new ol.View({
  center: center,
  zoom: zoom,
  rotation: rotation
 })
});
var shouldUpdate = true;
var view = map.getView();
/** getView()
 * Get the view associated with this map. A view 
 * manages properties such as center and resolution.
 * このマップと関連するビューを取得します。ビューは、
 * 中心や解像度のような属性を管理します。
 * Return: The view that controls this map.(ol3 API)
 */
var updatePermalink = function() {
 if (!shouldUpdate) {
  /** do not update the URL when the view was changed in the 
   * 'popstate' handler
   * ビューが「popstate」ハンドラで変更されたとき、URL を更新し
   * ません
   */
  shouldUpdate = true;
  return;
 }
 var center = view.getCenter();
 /** getCenter()
  * Return: The center of the view.(ol3 API)
  */
 var hash = '#map=' +
  view.getZoom() + '/' +
  /** getZoom()
   * Get the current zoom level. Return undefined if 
   * the current resolution is undefined or not a 
   * "constrained resolution".
   * 現在のズームレベルを取得します。現在の解像度が未定義か
   * 「制約解像度」の場合は undefined を返します。(ol3 API)
   */
  Math.round(center[0] * 100) / 100 + '/' +
  /** Math.round()
   * 引数として与えた数を四捨五入して、最も近似の整数を返します。
   * (MDN[https://developer.mozilla.org/ja/docs/Web/
   * JavaScript/Reference/Global_Objects/Math/round])
   */
  Math.round(center[1] * 100) / 100 + '/' +
  view.getRotation();
  /** getRotation()
   * Returns: The rotation of the view.(ol3 API)
   */
 var state = {
  zoom: view.getZoom(),
  center: view.getCenter(),
  rotation: view.getRotation()
 };
 window.history.pushState(state, 'map', hash);
 /** window.history
  * ブラウザの履歴を扱うためのインタフェースを提供する history 
  * オブジェクトへの参照を返します。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/API/
  * Window/history])
  */
};
map.on('moveend', updatePermalink);
/** on
 * Listen for a certain type of event.
 * あるタイプのイベントをリッスンします。(ol3 API)
 */
/** restore the view state when navigating through the 
 * history, see
 * 履歴を通してナビゲートするとき、ビューの状態を復元します。次を
 * 参照してください
 * https://developer.mozilla.org/en-US/docs/Web/API/
 * WindowEventHandlers/onpopstate
window.addEventListener('popstate', function(event) {
/** EventTarget.addEventListener
 * addEventListener は、 1 つのイベントターゲットにイベント 
 * リスナーを1つ登録します。イベントターゲットは、ドキュメント
 * 上の単一のノード、ドキュメント自身、ウィンドウ、あるいは、
 * XMLHttpRequest です。
 *(MDN[https://developer.mozilla.org/ja/docs/Web/API/
 * EventTarget.addEventListener])
 */
 if (event.state === null) {
  return;
 }
 map.getView().setCenter(event.state.center);
 map.getView().setZoom(event.state.zoom);
 map.getView().setRotation(event.state.rotation);
 shouldUpdate = false;
});
 
 

2 - ol3.5ex 117a - Permalink example 1

「Permalink example (permalink.html)」を参考に地図を表示してみます。

In this example the HTML 5 History API is used to update the browser URL with the current zoom-level, center and rotation when the map is moved. Note that the History API is not supported in all browsers, one might consider to use a polyfill.
Related API documentation: ol.Map, ol.View, ol.control,  ol.layer.Tile, ol.source.OSM

この例では、HTML 5 History API は、マップが移動したときの、現在のズームレベル、中心、回転をともなったブラウザ URL の更新に使用されます。History API は、すべてのブラウザでサポートされているわけではないことに注意してください。polyfillを使用することも解決の一つです。
関連するAPIドキュメント:ol.Map、ol.View、ol.control、ol.layer.Tile、ol.source.OSM


HTML ファイルの作成
a Eclipse のメニューの「ファイル」->「ファイルを開く」をクリックします。





b 「ファイルを開く」ウィンドウで、「user」->「mapsite」->「ol3proj」->「v3.5.0」->「examples」->「permalink.html」をクリックして選択し、「OK」ボタンをクリックします。
同じように「permalink.js」を開きます。





c メニューの「ファイル」->「新規」 -> 「ファイル」をクリックします。



d 「ファイル」ウィンドウで「ol3proj」をクリックして選択し、「ファイル名」を「2117-ol3ex.html」と入力し、「次へ」ボタンをクリックします。








e 「File Template」ウィンドウで「HTML 5 Template」をクリックして選択し、「OK」ボタンをクリックします。











f 「permalink.html」の内容をコピーして「2117-ol3ex.html」に貼り付け、修正します。
g 同じように、新規に「2117-ol3ex.js」ファイルを作成し、「File Template」ウィンドウで「JavaScript Template」をクリックして選択し、「完了」ボタンをクリックして、「permalink.js」の内容をコピーして貼り付け、修正します。「permalink-require.js」も「2117-ol3ex-require.js」に貼り付けます。

「2117-ol3ex.html」
<!doctype html>
<html lang="en">
 <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="chrome=1">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" type="text/css">
  <!--
  <link rel="stylesheet" href="../css/ol.css" type="text/css">
  <link rel="stylesheet" href="./resources/layout.css" type="text/css">

  <link rel="stylesheet" href="./resources/prism/prism.css" type="text/css">
  <script src="./resources/zeroclipboard/ZeroClipboard.min.js"></script>
  「resources」の位置が変わりました。
  -->
  <!-- ディレクトリ修正 -->
  <link rel="stylesheet" href="v3.5.0/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.5.0/examples/resources/layout.css" type="text/css">

  <link rel="stylesheet" href="v3.5.0/examples/resources/prism/prism.css" type="text/css">
  <script src="v3.5.0/examples/resources/zeroclipboard/ZeroClipboard.min.js"></script>
  <title>Permalink example</title>
 </head>
 <body>
  <!-- 
  ol.css, layout.css, bootstrap-combined.min.css
  CSSファイルで設定されたセレクタを使用。
  -->
  <div class="navbar navbar-inverse navbar-fixed-top">
   <div class="navbar-inner">
    <div class="container">
     <!--
     <a class="brand" href="./"><img src="./resources/logo-70x70.png"> OpenLayers 3 Examples</a>
     -->
     <!-- ディレクトリ修正 -->
     <a class="brand" href="v3.5.0/examples/"><img src="v3.5.0/examples/resources/logo-70x70.png"> OpenLayers 3 Examples</a>
    </div>
   </div>
  </div>
  <div class="container-fluid">
   <div class="row-fluid">
    <div class="span12">
     <div id="map" class="map"></div>
    </div>
   </div>
   <div class="row-fluid">
    <div class="span12">
     <h4 id="title">Permalink example</h4>
     <p id="shortdesc">Example on how to create permalinks.</p>
     <div id="docs">
      <p>In this example the 
      <a href="https://developer.mozilla.org/en-US/docs/Web/
      Guide/API/DOM/Manipulating_the_browser_history" target=
      "_blank">HTML 5 History API</a> 
      is used to update the browser URL with the current 
      zoom-level, center and rotation when the map is moved. 
      Note that the History API is not supported in 
      <a href="http://caniuse.com/#feat=history" target=
      "_blank">all browsers</a>, 
      one might consider to use a 
      <a href="https://github.com/Modernizr/Modernizr/wiki/
      HTML5-Cross-Browser-Polyfills#html5-history-api-
      pushstate-replacestate-popstate" target="_blank">
      a polyfill</a>.</p>
     </div>
     <div id="tags">permalink, openstreetmap, history</div>
     <div id="api-links">Related API documentation: 
      <ul class="inline">
       <li>
        <!--<a href="../apidoc/ol.Map.html" title="API documentation for ol.Map">ol.Map>/a> -->
        <a href="v3.5.0/apidoc/ol.Map.html" title="API documentation for ol.Map">ol.Map</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.View.html" title="API documentation for ol.View">ol.View>/a> -->
        <a href="v3.5.0/apidoc/ol.View.html" title="API documentation for ol.View">ol.View</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.control.html" title="API documentation for ol.control">ol.control>/a> -->
        <a href="v3.5.0/apidoc/ol.control.html" title="API documentation for ol.control">ol.control</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.layer.Tile.html" title="API documentation for ol.layer.Tile">ol.layer.Tile>/a> -->
        <a href="v3.5.0/apidoc/ol.layer.Tile.html" title="API documentation for ol.layer.Tile">ol.layer.Tile</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.source.OSM.html" title="API documentation for ol.source.OSM">ol.source.OSM</a> -->
        <a href="v3.5.0/apidoc/ol.source.OSM.html" title="API documentation for ol.source.OSM">ol.source.OSM</a>
       </li>,
      </ui>,
     </div>
   </div>
  </div>
  <div class="row-fluid">
   <hr>
   <form method="POST" target="_blank" action="http://jsfiddle.net/api/post/jquery/1.11.0/">
    <input type="button" class="btn btn-info" id="copy-button" value="Copy example code">
    <input type="submit" class="btn btn-primary" id="jsfiddle-button" value="Create JSFiddle">
    <textarea class="hidden" name="js">// default zoom, center and rotation
var zoom = 2;
var center = [0, 0];
var rotation = 0;
if (window.location.hash !== &#x27;&#x27;) {
 // try to restore center, zoom-level and rotation from the URL
 var hash = window.location.hash.replace(&#x27;#map=&#x27;, &#x27;&#x27;);
 var parts = hash.split(&#x27;/&#x27;);
 if (parts.length === 4) {
  zoom = parseInt(parts[0], 10);
  center = [
   parseFloat(parts[1]),
   parseFloat(parts[2])
  ];
  rotation = parseFloat(parts[3]);
 }
}
var map = new ol.Map({
 layers: [
  new ol.layer.Tile({
   source: new ol.source.OSM()
  })
 ],
 controls: ol.control.defaults({
  attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
   collapsible: false
  })
 }),
 target: &#x27;map&#x27;,
 view: new ol.View({
  center: center,
  zoom: zoom,
  rotation: rotation
 })
});
var shouldUpdate = true;
var view = map.getView();
var updatePermalink = function() {
 if (!shouldUpdate) {
  // do not update the URL when the view was changed in the &#x27;popstate&#x27; handler
  shouldUpdate = true;
  return;
 }
 var center = view.getCenter();
 var hash = &#x27;#map=&#x27; +
  view.getZoom() + &#x27;/&#x27; +
  Math.round(center[0] * 100) / 100 + &#x27;/&#x27; +
  Math.round(center[1] * 100) / 100 + &#x27;/&#x27; +
  view.getRotation();
 var state = {
  zoom: view.getZoom(),
  center: view.getCenter(),
  rotation: view.getRotation()
 };
 window.history.pushState(state, &#x27;map&#x27;, hash);
};
map.on(&#x27;moveend&#x27;, updatePermalink);
// restore the view state when navigating through the history, see
// https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate
window.addEventListener(&#x27;popstate&#x27;, function(event) {
 if (event.state === null) {
  return;
 }
 map.getView().setCenter(event.state.center);
 map.getView().setZoom(event.state.zoom);
 map.getView().setRotation(event.state.rotation);
 shouldUpdate = false;
});
</textarea>
<textarea class="hidden" name="css"></textarea>
<textarea class="hidden" name="html">&lt;div class=&quot;row-fluid&quot;&gt;
 &lt;div class=&quot;span12&quot;&gt;
  &lt;div id=&quot;map&quot; class=&quot;map&quot;&gt;&lt;/div&gt;
 &lt;/div&gt;
&lt;/div&gt;
</textarea>
<input type="hidden" name="wrap" value="l">
 <input type="hidden" name="resources" value="
  https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css,
  https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js,
  https://cdnjs.cloudflare.com/ajax/libs/ol3/3.5.0/ol.css,
  https://cdnjs.cloudflare.com/ajax/libs/ol3/3.5.0/ol.js">
 <pre><code id="example-source" class="language-markup">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Permalink example&lt;/title&gt;
&lt;script src="https://code.jquery.com/jquery-1.11.2.min.js"&gt;&lt;/script&gt;
&lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"&gt;
&lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"&gt;&lt;/script&gt;
&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.5.0/ol.css" type="text/css"&gt;
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.5.0/ol.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class="container-fluid"&gt;
&lt;div class=&quot;row-fluid&quot;&gt;
 &lt;div class=&quot;span12&quot;&gt;
  &lt;div id=&quot;map&quot; class=&quot;map&quot;&gt;&lt;/div&gt;
 &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;script&gt;
// default zoom, center and rotation
var zoom = 2;
var center = [0, 0];
var rotation = 0;
if (window.location.hash !== &#x27;&#x27;) {
 // try to restore center, zoom-level and rotation from the URL
 var hash = window.location.hash.replace(&#x27;#map=&#x27;, &#x27;&#x27;);
 var parts = hash.split(&#x27;/&#x27;);
 if (parts.length === 4) {
  zoom = parseInt(parts[0], 10);
  center = [
   parseFloat(parts[1]),
   parseFloat(parts[2])
  ];
  rotation = parseFloat(parts[3]);
 }
}
var map = new ol.Map({
 layers: [
  new ol.layer.Tile({
   source: new ol.source.OSM()
  })
 ],
 controls: ol.control.defaults({
  attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
   collapsible: false
  })
 }),
 target: &#x27;map&#x27;,
 view: new ol.View({
  center: center,
  zoom: zoom,
  rotation: rotation
 })
});
var shouldUpdate = true;
var view = map.getView();
var updatePermalink = function() {
 if (!shouldUpdate) {
  // do not update the URL when the view was changed in the &#x27;popstate&#x27; handler
  shouldUpdate = true;
  return;
 }
 var center = view.getCenter();
 var hash = &#x27;#map=&#x27; +
  view.getZoom() + &#x27;/&#x27; +
  Math.round(center[0] * 100) / 100 + &#x27;/&#x27; +
  Math.round(center[1] * 100) / 100 + &#x27;/&#x27; +
  view.getRotation();
 var state = {
  zoom: view.getZoom(),
  center: view.getCenter(),
  rotation: view.getRotation()
 };
 window.history.pushState(state, &#x27;map&#x27;, hash);
};
map.on(&#x27;moveend&#x27;, updatePermalink);
// restore the view state when navigating through the history, see
// https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onpopstate
window.addEventListener(&#x27;popstate&#x27;, function(event) {
 if (event.state === null) {
  return;
 }
 map.getView().setCenter(event.state.center);
 map.getView().setZoom(event.state.zoom);
 map.getView().setRotation(event.state.rotation);
 shouldUpdate = false;
});
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
    </div>
   </div>
  </div>
  <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
  <!--
  <script src="./resources/common.js"></script>
  <script src="./resources/prism/prism.min.js"></script>
  -->
  <!-- ディレクトリ修正
   CommonJS と
   prism.js
 -->
  <script src="v3.5.0/examples/resources/common.js"></script>
  <script src="v3.5.0/examples/resources/prism/prism.min.js"></script>
  <!-- 
  <script src="loader.js?id=permalink"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=2117-ol3ex"></script>
  </body>
</html>


COMMONJS は

COMMONJS
http://webpack.github.io/docs/commonjs.html

に、次のようにあります。

The CommonJS group defined a module format to solve JavaScript scope issues by making sure each module is executed in its own namespace.
This is achieved by forcing modules to explicitly export those variables it wants to expose to the “universe”, and also by defining those other modules required to properly work.
To achieve this CommonJS give you two tools:
the require() function, which allows to import a given module into the current scope.
the module object, which allows to export something from the current scope.

CommonJSグループは、それ自身の名前空間内で実行されている各モジュールを確認することによって、JavaScriptのスコープ問題を解決するためのモジュールフォーマットを定義しました。
これは、それが「universe(?)」に公開したい変数を明示的にエクスポートするモジュールを強制することによって、同じように、正常に動作するのに必要な他のモジュールを定義することによって、達成されます。
この CommonJS を達成するために2つのツールを与えます:
require()関数、指定したモジュールを現在のスコープにインポートすることができます。
モジュールオブジェクト、現在のスコープからエクスポートすることができます。


Prism は、

Prism
http://prismjs.com/

に、次のようにあります。

Prism is a lightweight, extensible syntax highlighter, built with modern web standards in mind. It’s a spin-off from Dabblet and is tested there daily by thousands.
Prismは、最新のWeb標準に構築されたことを考慮し軽量で拡張可能なシンタックスハイライトです。それは Dabblet からスピンオフで、何千人も日々そこで試験されています。


ZeroClipboard は

ZeroClipboard v2.x
http://zeroclipboard.org/

に、次のようにあります。

The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie and a JavaScript interface.
ZeroClipboard ライブラリは、見えない Adobe Flash ムービーとJavaScript のインターフェイスを使用してテキストをクリップボードにコピーする簡単な方法を提供します。

Debian 8 では動作しませんでした。ボタンを右クリックしたときに flash のコンテキストメニューが表示されると動作しています。

2010年12月1日水曜日

GeoExt15 Permalink

Permalink

Example サイト
http://www.geoext.org/examples.html

「Permalink」リンクをクリックすると Permalink Example が表示されます。
permalink.js. を参考にします。

説明を意訳すると、現在のマップの位置と表示されているレイヤーと共にパーマリンクを生成する方法を示します。


var permalinkProvider;

Ext.onReady(function() {

// set a permalink provider
permalinkProvider = new GeoExt.state.PermalinkProvider({encodeType: false});
Ext.state.Manager.setProvider(permalinkProvider);

// var map = new OpenLayers.Map();
var map = new OpenLayers.Map('map', { // 東京マップ用
projection: new OpenLayers.Projection("EPSG:2456"),
maxResolution: 'auto',
maxExtent: new OpenLayers.Bounds(-279000,1054000,-185000,1104000),
units: 'meters',
displayProjection: new OpenLayers.Projection("EPSG:4326")
});


map.addLayers([
new OpenLayers.Layer.WMS( "Tokyo Height WMS", // 東京レイヤ
"http://192.168.1.6/cgi-bin/mapserv?",
{
map: '/home/nob61/mapfile/tokyo_bmi_pgis_img2.map',
layers: 'height',
format: 'image/png'
}),
new OpenLayers.Layer.WMS( "Tokyo Kukaku Sen WMS",
"http://192.168.1.6/cgi-bin/mapserv?",
{
map: '/home/nob61/mapfile/tokyo_bmi_pgis_img2.map',
layers: 'kukaku',
transparent: true,
format: 'image/png'
})
])
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(new OpenLayers.Control.ScaleLine());


var mapPanel = new GeoExt.MapPanel({
title: "GeoExt MapPanel",
renderTo: "mappanel",
height: 400,
width: 600,
map: map,
// center: new OpenLayers.LonLat(5, 45),
// zoom: 4,
stateId: "map",
prettyStateKeys: true
});

// update link when state chnages
var onStatechange = function(provider) {
var l = provider.getLink();
Ext.get("permalink").update("<a href=" + l + ">" + l + "</a>");
};
permalinkProvider.on({statechange: onStatechange});
});

HTML ファイルを新規作成します。
「openlayersTokyoproj」 を右クリックして 新規 -> HTML ファイル をクリック。
「HTML ファイル」ウィンドウの「ファイル名(任意:geoext15_permalink.html)」に入力して「完了」ボタンをクリック。
「charset」を「utf-8」にします。
以下のように HTML を作成します。
geoext14_wms-tree.html をコピーし、外部 JavaScript 読み込みファイルを修正し body タグ内に mappanel と permalink を設定します。

---
<title>GeoExt15 Permalink</title>
---
<!-- permalink.js 追加 -->
<script type="text/javascript" src="./permalink.js"></script>

</head>
<body>
<div id="desc">
<h1 id="title">GeoExt 15 - Permalink</h1>
<p id="shortdesc">
Permalink Example
</p>
<p>This example shows how to generate permalinks with the current map
position and visible layers.</p>

<p>この例では、現在のマップの位置と表示されているレイヤーと共にパーマリンクを
生成する方法を示します。</p>

<div id="mappanel"></div>
<h2>Permalink:</h2>
<div id="permalink"></div>
</div>
</body>
</html>

地図をパンやズームなどの操作をすると Permalink が表示されます。