新しいブログやWebサイトは以下をご覧ください。
Category Archives: 未分類
OpenlayersとGeoExtで電子国土地図を使ってみる。 [Chapter 2]
===== OpenlayersとGeoExtで電子国土地図を使ってみる。 [Chapter 2] =====
おわび、プログラムコード内で¥が抜けてしまっているようです。これは、WordPressとdokuwiki pluginの相性の問題のようです。
気づいた部分は全角の’¥’に置き換えています。
現在、dokuwikiへの移動を進めていますので、今しばらくお待ちください。
さて、今回は**GeoJSON**データと**電子国土地図v.4**をGeoExtで表示させます。
GeoExtのexampleがたくさんあるので、その中からpopup,toolbarやtreeなどを使ってみます。
電子国土地図の詳細情報は、[[http://portal.cyberjapan.jp/index.html|こちらのHP]]を参照してください。
動作確認環境は、**ms4w**です。 **linux**でも動作します。
==== 電子国土とGeoJSONのOverlay ====
[[http://blog.godo-tys.jp/2012/10/24/512/|電子国土地図にGeoJSONを重ねてみる。[Chapter 1]]]でvb.netでGeoJSONを読み込んで、htmlを作成しましたが、今回はGeoJSONファイルを読み込んで表示してみます。
そのGeoJSON読み込みコードは
// GeoJSONファイルを読み込んでVectorLayerを作成
vectorLayer = new OpenLayers.Layer.Vector("GeoJSON", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "http://localhost/test/data/kanagawk.json",
format: new OpenLayers.Format.GeoJSON()
})
});
OpenLayers.Protocol.HTTPでlocalhost/test/data/kanagawk.jsonデータを読み込みます。
kmlやxml、gmlにも適応できますので、詳しくはOpenLayersのマニュアルを読んでください。
C:/ms4w/Apache/htdocs/testフォルダーにdataフォルダーを作成して、kanagawk.jsonデータをコピーします。
kanagawk.jsonデータは、[[http://blog.godo-tys.jp/2012/10/24/512/|電子国土地図にGeoJSONを重ねてみる。[Chapter 1]]のサンプルのダウンロードに添付しています。
testフォルダーに、GeoExt-json.htmlを作成します。
//初期の経度 var initCX = 139.4;
//初期の緯度 var initCY = 35.4;
//真球メルカトル投影 var projection900913 = new OpenLayers.Projection("EPSG:900913");
//等経緯度投影を定義 var projection4326 = new OpenLayers.Projection("EPSG:4326");
//真球メルカトル投影のときの最大範囲(単位はm) var maxExtent = new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508);
//真球メルカトル投影のときの最大範囲に範囲を制限 var restrictedExtent = maxExtent.clone();
//真球メルカトル投影のときの最大解像度 var maxResolution = 156543.0339;
var map, webtisLayer, vectorLayer;
Ext.onReady(function () { map = new OpenLayers.Map('map', { projection: projection900913, maxResolution: 'auto', maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508), units: 'm', displayProjection: projection4326, controls: [ //new OpenLayers.Control.Attribution(), new OpenLayers.Control.Navigation({mouseWheelOptions: {interval: 50}}), new OpenLayers.Control.KeyboardDefaults(), //new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.LayerSwitcher(), new OpenLayers.Control.MousePosition(), new OpenLayers.Control.ScaleLine(), new OpenLayers.Control.PanPanel(), new OpenLayers.Control.ZoomPanel() //new OpenLayers.Control.OverviewMap() ], });
// GeoJSONファイルを読み込んでVectorLayerを作成 vectorLayer = new OpenLayers.Layer.Vector("GeoJSON", { strategies: [new OpenLayers.Strategy.Fixed()], protocol: new OpenLayers.Protocol.HTTP({ url: "http://localhost/test/data/kanagawk.json", format: new OpenLayers.Format.GeoJSON() }) }); // webtisLayer = new webtis.Layer.BaseMap("電子国土");
map.addLayers([webtisLayer, vectorLayer]);
map.zoomToMaxExtent();
// マップパネルの表示 new GeoExt.MapPanel({ renderTo: 'mappanel', // マップ描画のための id height: 480, // パネル高さ width: 600, // パネル幅 map: map, // OpenLayers.Map //初期の中心座標を指定(経緯度で入力して、内部的に真球メルカトル座標に変換して表示) center: new OpenLayers.LonLat(initCX,initCY).transform(projection4326,projection900913), zoom: 4, //電子国土地図の地理座標系 projection: projection900913, //表示の地理座標系 displayProjection: projection4326, //電子国土地図の最大解像度 maxResolution: maxResolution, //電子国土地図の最大範囲 maxExtent: maxExtent, //電子国土地図の表示制限範囲 restrictedExtent: restrictedExtent, //電子国土地図の単位 units: "m", title: 'A Simple GeoExt GeoJSON Example Map' // パネル上部に表示されるタイトル }); });
GeoExt GeoJSON Example
GeoExt GeoJSON Example.
GeoExtで電子国土と神奈川県のGeoJSONデータを表示します。
ブラウザーから、**http://localhost/test/GeoExt-json.html**と入力して実行すると。
{{http://blog.godo-tys.jp/wp-content/gallery/geoext/image08.jpg}}
GeoExt-json.html実行画面
{{http://blog.godo-tys.jp/wp-content/gallery/geoext/image09.jpg}}
LayerSwitcherでGeoJSONを非表示にした場合
==== toolbarを付け加えたexample ====
次に、toolbarとzoombarとvectorデータの作成、Layer透過度を加えたものをサンプルとして作成します。
C:/ms4w/Apache/htdocs/testフォルダーに2つファイルを作成します。
– GeoExt-toolbar.html
– GeoExt-toolbar.js
GeoExt-toolbar.htmlのコード
GeoExt 電子国土 toolbar
This example shows how to add OpenLayers controls in an Ext toolbar.
GeoExt provides the GeoExt.Action class for adapating a control to an
object that can be inserted in a toolbar or in a menu.
The js is not minified so it is readable. See GeoExt-toolbar.js.
GeoExt-toolbar.jsのコード
/** api: example[toolbar]
* Toolbar with Actions
* --------------------
* Create a toolbar with GeoExt Actions.
*/
//初期の経度
var initCX = 139.4;
//初期の緯度
var initCY = 35.4;
//真球メルカトル投影
var projection900913 = new OpenLayers.Projection("EPSG:900913");
//等経緯度投影を定義
var projection4326 = new OpenLayers.Projection("EPSG:4326");
var mapPanel, slider;
Ext.onReady(function() {
Ext.QuickTips.init();
//真球メルカトル投影のときの最大範囲(単位はm)
var maxExtent = new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508);
//真球メルカトル投影のときの最大範囲に範囲を制限
var restrictedExtent = maxExtent.clone();
//真球メルカトル投影のときの最大解像度
var maxResolution = 156543.0339;
// var map = new OpenLayers.Map();
var map = new OpenLayers.Map('map', {
controls: [
//new OpenLayers.Control.Attribution(),
new OpenLayers.Control.Navigation({mouseWheelOptions: {interval: 50}}),
new OpenLayers.Control.KeyboardDefaults(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.MousePosition(),
new OpenLayers.Control.ScaleLine(),
new OpenLayers.Control.OverviewMap()
],
allOverlays: false,
projection: projection900913,
maxResolution: maxResolution,
maxExtent: maxExtent,
units: 'm',
displayProjection: projection4326
});
webtisLayer = new webtis.Layer.BaseMap("webtisLayer");
// GeoJSONファイルを読み込んでVectorLayerを作成
vectorLayer = new OpenLayers.Layer.Vector("GeoJSON", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "http://localhost/test/data/kanagawk.json",
format: new OpenLayers.Format.GeoJSON()
})
});
//
var gmaplayerRoad = new OpenLayers.Layer.Google(
'道路地図',
{numZoomLevels: 20},
{visibility: true}
);
var gmaplayerHybrid = new OpenLayers.Layer.Google(
'衛星写真',
{type: google.maps.MapTypeId.HYBRID},
{numZoomLevels: 20},
{visibility: true}
);
var drawLayer = new OpenLayers.Layer.Vector("vector");
map.addLayers([webtisLayer, gmaplayerRoad, gmaplayerHybrid, vectorLayer, drawLayer]);
//ZoomSelectorの定義
var scaleStore = new GeoExt.data.ScaleStore({map: map});
var zoomSelector = new Ext.form.ComboBox({
store: scaleStore,
emptyText: "Zoom Level",
tpl: '
',
editable: false,
triggerAction: 'all', // needed so that the combo box doesn't filter by its current content
mode: 'local' // keep the combo box from forcing a lot of unneeded data refreshes
});
zoomSelector.on('select',
function(combo, record, index) {
map.zoomTo(record.data.level);
},
this
);
map.events.register('zoomend', this, function() {
var scale = scaleStore.queryBy(function(record){
return this.map.getZoom() == record.data.level;
});
if (scale.length > 0) {
scale = scale.items[0];
zoomSelector.setValue("1 : " + parseInt(scale.data.scale));
} else {
if (!zoomSelector.rendered) return;
zoomSelector.clearValue();
}
});
// create a separate slider bound to the map but displayed elsewhere
slider = new GeoExt.LayerOpacitySlider({
layer: vectorLayer,
aggressive: true,
width: 200,
isFormField: true,
inverse: true,
fieldLabel: "opacity",
renderTo: "slider", //id=slider
plugins: new GeoExt.LayerOpacitySliderTip({template: '
'})
});
//toolbarの定義
var ctrl, toolbarItems = [], action, actions = {};
// MaxExtentがおかしいので、とりあえず非表示
// ZoomToMaxExtent control, a "button" control
/*action = new GeoExt.Action({
control: new OpenLayers.Control.ZoomToMaxExtent(),
map: map,
text: "全体表示",
tooltip: "全体を表示"
});
actions["max_extent"] = action;
toolbarItems.push(action);
toolbarItems.push("-");*/
// Navigation control and DrawFeature controls
// in the same toggle group
action = new GeoExt.Action({
text: "ナビゲーション",
control: new OpenLayers.Control.Navigation(),
map: map,
// button options
toggleGroup: "draw",
allowDepress: false,
pressed: true,
tooltip: "マウス操作",
// check item options
group: "draw",
checked: true
});
actions["nav"] = action;
toolbarItems.push(action);
action = new GeoExt.Action({
text: "ポリゴン",
control: new OpenLayers.Control.DrawFeature(
drawLayer, OpenLayers.Handler.Polygon
),
map: map,
// button options
toggleGroup: "draw",
allowDepress: false,
tooltip: "ポリゴンの作成",
// check item options
group: "draw"
});
actions["draw_poly"] = action;
toolbarItems.push(action);
action = new GeoExt.Action({
text: "ライン",
control: new OpenLayers.Control.DrawFeature(
drawLayer, OpenLayers.Handler.Path
),
map: map,
// button options
toggleGroup: "draw",
allowDepress: false,
tooltip: "ラインの作成",
// check item options
group: "draw"
});
actions["draw_line"] = action;
toolbarItems.push(action);
toolbarItems.push("-");
// SelectFeature control, a "toggle" control
action = new GeoExt.Action({
text: "選択",
control: new OpenLayers.Control.SelectFeature(drawLayer, {
type: OpenLayers.Control.TYPE_TOGGLE,
hover: true
}),
map: map,
// button options
enableToggle: true,
tooltip: "フィーチャ選択"
});
actions["select"] = action;
toolbarItems.push(action);
toolbarItems.push("-");
// Navigation history - two "button" controls
ctrl = new OpenLayers.Control.NavigationHistory();
map.addControl(ctrl);
action = new GeoExt.Action({
text: "前に戻る",
control: ctrl.previous,
disabled: true,
tooltip: "前の表示範囲に戻る"
});
actions["previous"] = action;
toolbarItems.push(action);
action = new GeoExt.Action({
text: "次に進む",
control: ctrl.next,
disabled: true,
tooltip: "次の表示範囲に進む"
});
actions["next"] = action;
toolbarItems.push(action);
toolbarItems.push("->");
// Reuse the GeoExt.Action objects created above
// as menu items
toolbarItems.push({
text: "menu",
menu: new Ext.menu.Menu({
items: [
// ZoomToMaxExtent
//actions["max_extent"],
// Nav
new Ext.menu.CheckItem(actions["nav"]),
// Draw poly
new Ext.menu.CheckItem(actions["draw_poly"]),
// Draw line
new Ext.menu.CheckItem(actions["draw_line"]),
// Select control
new Ext.menu.CheckItem(actions["select"]),
// Navigation history control
actions["previous"],
actions["next"]
]
})
});
mapPanel = new GeoExt.MapPanel({
renderTo: "mappanel",
height: 480,
width: 600,
map: map,
//初期の中心座標を指定(経緯度で入力して、内部的に真球メルカトル座標に変換して表示)
center: new OpenLayers.LonLat(initCX,initCY).transform(projection4326,projection900913),
zoom: 4,
//電子国土地図の地理座標系
projection: projection900913,
//表示の地理座標系
displayProjection: projection4326,
//電子国土地図の最大解像度
maxResolution: maxResolution,
//電子国土地図の最大範囲
maxExtent: maxExtent,
//電子国土地図の表示制限範囲
restrictedExtent: restrictedExtent,
//電子国土地図の単位
units: "m",
//定義したメニューtoolbarの追加
tbar: toolbarItems,
//定義した縮尺選択bbarの追加
bbar: [zoomSelector]
});
});
次に、ブラウザーから**http://localhost/test/GeoExt-toolbar.html**とすれば、
{{http://blog.godo-tys.jp/wp-content/gallery/geoext/image10.jpg}}
GeoExt-toolbar.html初期画面
toolbarメニューを操作して、ポリゴンやラインを作成などの操作ができます。
**http://map.godo-tys.jp/GeoExt-toolbar.html**にサンプルをおいておきます。
==== treeとviewportを付け加えたexample ====
次に、treeとviewportとmouse click eventを加えたものをサンプルとして作成します。
C:/ms4w/Apache/htdocs/testフォルダーに2つファイルを作成します。
– GeoExt-tree.html
– GeoExt-tree.js
GeoExt-tree.htmlのコード
GeoExt 電子国土地図 Tree Legend
GeoExt Legend Tree
この例では、ツリー内のレイヤノードに凡例を追加する方法を示します。
GeoExt-toolbar.jsのコード
/** api: example[tree-legend]
* Tree Legend
* -----------
* Render layer nodes with legends.
*/
//初期の経度
var initCX = 139.4;
//初期の緯度
var initCY = 35.4;
//真球メルカトル投影
var projection900913 = new OpenLayers.Projection("EPSG:900913");
//等経緯度投影を定義
var projection4326 = new OpenLayers.Projection("EPSG:4326");
//真球メルカトル投影のときの最大範囲(単位はm)
var maxExtent = new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508);
//真球メルカトル投影のときの最大範囲に範囲を制限
var restrictedExtent = maxExtent.clone();
//真球メルカトル投影のときの最大解像度
var maxResolution = 156543.0339;
var mapPanel, popup;
// custom layer node UI class
var LayerNodeUI = Ext.extend(
GeoExt.tree.LayerNodeUI,
new GeoExt.tree.TreeNodeUIEventMixin()
);
Ext.onReady(function() {
//Popup windowの定義
function addToPopup(loc) {
// create the popup if it doesn't exist
if (!popup) {
popup = new GeoExt.Popup({
title: "Popup",
width: 200,
maximizable: true,
collapsible: true,
map: mapPanel.map,
anchored: true,
listeners: {
close: function() {
// closing a popup destroys it, but our reference is truthy
popup = null;
}
}
});
}
// add some content to the popup (this can be any Ext component)
popup.add({
xtype: "box",
autoEl: {
html: "You clicked on (" + loc.lon.toFixed(2) + ", " + loc.lat.toFixed(2) + ")"
}
});
// reset the popup's location
loc.transform(projection4326, projection900913);
popup.location = loc;
popup.doLayout();
// since the popup is anchored, calling show will move popup to this location
popup.show();
}
var control = new OpenLayers.Control.Click({
trigger: function(evt) {
var loc = mapPanel.map.getLonLatFromViewPortPx(evt.xy);
loc.transform(projection900913, projection4326);
addToPopup(loc);
}
});
// 電子国土地図の設定
var map = new OpenLayers.Map('map', {
controls: [
//new OpenLayers.Control.Attribution(),
new OpenLayers.Control.Navigation({mouseWheelOptions: {interval: 50}}),
new OpenLayers.Control.KeyboardDefaults(),
//new OpenLayers.Control.PanZoomBar(),
//new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.MousePosition(),
new OpenLayers.Control.ScaleLine(),
new OpenLayers.Control.PanPanel(),
new OpenLayers.Control.ZoomPanel()
//new OpenLayers.Control.OverviewMap()
],
allOverlays: true,
projection: projection900913,
maxResolution: maxResolution,
maxExtent: maxExtent,
units: 'm',
displayProjection: projection4326
});
//電子国土の定義
var webtisLayer = new webtis.Layer.BaseMap("電子国土");
// GeoJSONファイルを読み込んでVectorLayerを作成
var vectorLayer = new OpenLayers.Layer.Vector("GeoJSON", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "http://localhost/test/data/kanagawk.json",
format: new OpenLayers.Format.GeoJSON()
})
});
mapPanel = new GeoExt.MapPanel({
region: "center",
zoom: 6,
map: map,
//初期の中心座標を指定(経緯度で入力して、内部的に真球メルカトル座標に変換して表示)
center: new OpenLayers.LonLat(initCX,initCY).transform(projection4326,projection900913),
zoom: 4,
//電子国土地図の地理座標系
projection: projection900913,
//表示の地理座標系
displayProjection: projection4326,
//電子国土地図の最大解像度
maxResolution: maxResolution,
//電子国土地図の最大範囲
maxExtent: maxExtent,
//電子国土地図の表示制限範囲
restrictedExtent: restrictedExtent,
//電子国土地図の単位
units: "m",
//Layerの追加
layers: [webtisLayer, vectorLayer]
});
mapPanel.map.addControl(control);
control.activate();
var tree = new Ext.tree.TreePanel({
region: "east",
title: "Layers",
width: 250,
autoScroll: true,
enableDD: true,
// apply the tree node component plugin to layer nodes
plugins: [{
ptype: "gx_treenodecomponent"
}],
loader: {
applyLoader: false,
uiProviders: {
"custom_ui": LayerNodeUI
}
},
root: {
nodeType: "gx_layercontainer",
loader: {
baseAttrs: {
uiProvider: "custom_ui"
},
createNode: function(attr) {
// add a WMS legend to each node created
attr.component = {
xtype: "gx_wmslegend",
layerRecord: mapPanel.layers.getByLayer(attr.layer),
showTitle: false,
// custom class for css positioning
// see tree-legend.html
cls: "legend"
}
return GeoExt.tree.LayerLoader.prototype.createNode.call(this, attr);
}
}
},
rootVisible: false,
lines: false
});
//ViewPortの定義
new Ext.Viewport({
layout: "fit",
hideBorders: true,
items: {
layout: "border",
items: [
mapPanel, tree, {
contentEl: desc,
region: "west",
width: 250,
bodyStyle: {padding: "5px"}
}
]
}
});
});
// simple control to handle user clicks on the map
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
single: true,
double: false,
pixelTolerance: 0,
stopSingle: true
},
initialize: function(options) {
this.handlerOptions = OpenLayers.Util.extend(
options && options.handlerOptions || {},
this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this,
{
click: this.trigger
},
this.handlerOptions
);
},
CLASS_NAME: "OpenLayers.Control.Click"
});
次に、ブラウザーから**http://localhost/test/GeoExt-tree.html**とすれば、
{{http://blog.godo-tys.jp/wp-content/gallery/geoext/image11.jpg}}
GeoExt-tree.htmlの初期画面
が表示されます。 いろいろとマウスで操作してみてください。
とりあえず、OK。
**http://map.godo-tys.jp/GeoExt-tree.html**にサンプルをおいておきます。
==== 最後に ====
GeoJSONデータを作成すれば、Overlayすることが簡単にできます。また、kmlやgml、GeoRSSも可能です。
これらのデータは、ESRI仕様のShape fileであれば、ogr2ogrコマンドで簡単にformat変換することができます。
使い方については、[[http://mf-atelier.sakura.ne.jp/mf-atelier/modules/tips/index.php|月の杜工房gdal/ogrの小技集]]が非常に参考になります。
vb.net版も作成中ですが。。。 いかんせん情報がないです。 最悪はdosコマンドをGUIくらいしかできないかもですね。
**GeoExt**で地図の操作性が非常に良くなります。もう少し手を加えてWEB-GISアプリケーションを作成してみます。
[[http://geoext.org/index.html|GeoExtのHP]]をしっかりと読んで、使いこなせるようにならねば。。。
「OpenlayersとGeoExtで電子国土地図を使ってみる。」は後2回ほどで終了する予定です。
なにか、こんなことはできないなどなりましたら、[[http://blog.godo-tys.jp/contact-me/|問い合わせ]]からメールにてお願いします。
==== おまけ ====
DBFの編集ソフトを作成してみました。
GISエンジンはMapWinGISを使っています。
ベクターに[[http://www.vector.co.jp/soft/cmt/winnt/business/se499584.html|登録]]も行っています。
また、[[http://www.re-forest.com/|株式会社森林再生システム]]と共同開発で[[http://www.re-forest.com/service/gis.html#ExcelGis|ExcelGIS]]も作成しておりますので、覗いてみてください。
OpenlayersとGeoExtで電子国土地図を使ってみる。 [Chapter 1]
===== OpenlayersとGeoExtで電子国土地図を使ってみる。 [Chapter 1] =====
おわび、プログラムコード内で¥が抜けてしまっているようです。これは、WordPressとdokuwiki pluginの相性の問題のようです。
気づいた部分は全角の’¥’に置き換えています。
現在、dokuwikiへの移動を進めていますので、今しばらくお待ちください。
さて、前回OpenLayersとGeoExtがセットアップできましたので、早速使ってみましょう。
定番の**Googlemap**と**電子国土地図v.4**をGeoExtで表示させます。
電子国土地図の詳細情報は、[[http://portal.cyberjapan.jp/index.html|こちらのHP]]を参照してください。
動作確認環境は、**ms4w**です。 linuxでも大丈夫だと思います。
==== 準備 ====
まずは、C:¥ms4w¥Apache¥htdocs内にtestと言うフォルダーを作成します。
この中にテストするhtmlとjsを入れていきます。
そして、C:¥ms4w¥httpd.d内にhttpd_test.confファイルを作成して、次のスクリプトを入力して、保存します。
Alias /test/ "C:/ms4w/Apache/htdocs/test/"
AllowOverride None
Options Indexes FollowSymLinks Multiviews
Order allow,deny
Allow from all
後は、apacheをrestartしてconfファイルを再読込させます。 **忘れずに!!**
==== まずはサンプルのテスト ====
とりあえずは、サンプルをコピーして、localサイドのOpenLayerとGeoExtで表示できるかのテストをします。
C:¥ms4w¥apps¥GeoExt-1.1¥examplesから次の2つのファイルをC:¥ms4w¥Apache¥htdocs¥testにコピーします。
– mappanel-div.html
– mappanel-div.js
次に、mappanel-div.htmlを修正します。
mappanel-div.htmlの修正後
GeoExt.MapPanel with an Existing OpenLayers.Map
This example shows the how to create a MapPanel with a map that has
already been created. See mappanel-div.html
for an example that creates the MapPanel without creating the map first.
This example makes use of a CookieProvider. The MapPanel
being a stateful component, if you reload the page the map should be
at the same location as previously. Also the getState and
applyState methods are overloaded so the size of the map
panel is also restored when refreshing the page.
The js is not minified so it is readable. See mappanel-div.js.
元のファイルと比べてくださいね。 **localhost**に置き換わっている部分が今回修正したところです。
次に、ブラウザーから**http://localhost/test/mappanel-div.html**とすれば、
{{http://blog.godo-tys.jp/wp-content/gallery/geoext/image05.jpg}}
が表示されます。
biggerボタンクリックでmappanelが大きくなり、smallerボタンクリックで小さくなります。
とりあえず、OK。
==== 電子国土地図v4の表示 ====
=== 電子国土地図v.4のjavascript設定 ===
電子国土ポータルサイトから、v4のjsを[[http://portal.cyberjapan.jp/portalsite/docs/data/V4source.zip|こちら]]からダウンロードします。
C:¥ms4w¥appsにV4source.zipを解凍してコピーします。
フォルダーの構成は、**C:¥ms4w¥apps¥v4¥css**、**C:¥ms4w¥apps¥v4¥webtis**としています。
C:¥ms4w¥httpd.d内にhttpd_webtis_v4.confのconfファイルを作成します。
httpd_webtis_v4.confの内容は、
Alias /v4/ "C:/ms4w/apps/v4/"
AllowOverride None
Options Indexes FollowSymLinks Multiviews
Order allow,deny
Allow from all
後は、apacheをrestartしてconfファイルを再読込させます。 **忘れずに!!**
=== 電子国土地図v.4のサンプル表示 ===
次に電子国土のポータルサイトの[[http://portal.cyberjapan.jp/portalsite/version/v4/v4samples/default.html|サンプルソースコード]]からhtmlファイル参考にC:ms4wApachehtdocstest内にdk_v4.htmlファイルを作成して、修正します。
dk_v4.htmlの修正後
C:¥ms4w¥apps¥v4¥css内にwebtis.cssファイルも作成しておきましょう。
@charset "utf-8";
/* 縮尺バー用 */
div.olControlScaleLine {
background-color:#ffffff;
/* for IE */
filter:alpha(opacity=60);
/* CSS3 standard */
opacity:0.6;
}
div.olControlAttribution {
font-size:12px;
line-height:12px;
bottom:5px;
}
UTF-8で保存してくださいね。
次に、ブラウザーから**http://localhost/test/dk_v4.html**とすれば、
{{http://blog.godo-tys.jp/wp-content/gallery/geoext/image04.jpg}}
が表示されます。
とりあえず、OK。
==== GooglemapをGeoExtで表示 ====
C:¥ms4w¥Apache¥htdocs¥testに以下のファイルを作成します。
– mappanel-googlemap.html
– mappanel-googlemap.js
mappanel-googlemap.htmlの作成
GeoExt.MapPanel with Googlemap
This example shows the how to create a MapPanel with a map that has
already been created. See mappanel-googlemap.html
for an example that creates the MapPanel without creating the map first.
This example makes use of a CookieProvider. The MapPanel
being a stateful component, if you reload the page the map should be
at the same location as previously. Also the getState and
applyState methods are overloaded so the size of the map
panel is also restored when refreshing the page.
The js is not minified so it is readable. See mappanel-googlemap.js.
mappanel-googlemap.jsの作成
/** api: example[mappanel-googlemap]
* Map Panel (in a Window)
* -------------------------
* Render a map panel in a Window.
*/
//初期の経度
var initCX = 138.727284;
//初期の緯度
var initCY = 35.360496;
//真球メルカトル投影
var projection900913 = new OpenLayers.Projection("EPSG:900913");
//等経緯度投影を定義
var projection4326 = new OpenLayers.Projection("EPSG:4326");
//mappanelの定義
var mapPanel, controls = [];
Ext.onReady(function() {
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
//真球メルカトル投影のときの最大範囲(単位はm)
var maxExtent = new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508);
//真球メルカトル投影のときの最大範囲に範囲を制限
var restrictedExtent = maxExtent.clone();
//真球メルカトル投影のときの最大解像度
var maxResolution = 156543.0339;
var map = new OpenLayers.Map();
var gmaplayerRoad = new OpenLayers.Layer.Google(
'道路地図',
{numZoomLevels: 20},
{visibility: true}
);
var gmaplayerHybrid = new OpenLayers.Layer.Google(
'衛星写真',
{type: google.maps.MapTypeId.HYBRID},
{numZoomLevels: 20},
{visibility: true}
);
map.addLayers([gmaplayerRoad, gmaplayerHybrid]);
map.addControls(controls);
mapPanel = new GeoExt.MapPanel({
title: "GeoExt MapPanel",
renderTo: "mappanel",
stateId: "mappanel",
height: 400,
width: 600,
map: map,
//初期の中心座標を指定(経緯度で入力して、内部的に真球メルカトル座標に変換して表示)
center: new OpenLayers.LonLat(initCX,initCY).transform(projection4326,projection900913),
zoom: 10,
//Googlemap地図の地理座標系
projection: projection900913,
//表示の地理座標系
displayProjection: projection4326,
//Googlemap地図の最大解像度
maxResolution: maxResolution,
//Googlemap地図の最大範囲
maxExtent: maxExtent,
//Googlemap地図の表示制限範囲
restrictedExtent: restrictedExtent,
//Googlemap地図の単位
units: "m",
// パネルサイズの変更
getState: function() {
var state = GeoExt.MapPanel.prototype.getState.apply(this);
state.width = this.getSize().width;
state.height = this.getSize().height;
return state;
},
applyState: function(state) {
GeoExt.MapPanel.prototype.applyState.apply(this, arguments);
this.width = state.width;
this.height = state.height;
}
});
});
controls.push(
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.Navigation({mouseWheelOptions: {interval: 10}}),
new OpenLayers.Control.KeyboardDefaults(),
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.PanPanel(),
new OpenLayers.Control.ZoomPanel()
);
// functions for resizing the map panel
function mapSizeUp() {
var size = mapPanel.getSize();
size.width += 40;
size.height += 40;
mapPanel.setSize(size);
}
function mapSizeDown() {
var size = mapPanel.getSize();
size.width -= 40;
size.height -= 40;
mapPanel.setSize(size);
}
次に、ブラウザーから**http://localhost/test/mappanel-googlemap.html**とすれば、
{{http://blog.godo-tys.jp/wp-content/gallery/geoext/image06.jpg}}
が表示されます。
とりあえず、OK。 zoompanelが重なっているようで。。。
OpenLayers-2.10や2.11に変更してみるもの良いですね。
==== 電子国土地図をGeoExtで表示 ====
C:¥ms4w¥Apache¥htdocs¥testに以下のファイルを作成します。
– mappanel-dk_v4.html
– mappanel-dk_v4.js
mappanel-dk_v4.htmlの作成
GeoExt.MapPanel with CyberJapan map
This example shows the how to create a MapPanel with a map that has
already been created. See mappanel-dk_v4.html
for an example that creates the MapPanel without creating the map first.
This example makes use of a CookieProvider. The MapPanel
being a stateful component, if you reload the page the map should be
at the same location as previously. Also the getState and
applyState methods are overloaded so the size of the map
panel is also restored when refreshing the page.
The js is not minified so it is readable. See mappanel-dk_v4.js.
mappanel-dk_v4.jsの作成
/** api: example[mappanel-dk_v4]
* 電子国土地図 ver.4の表示
* http://portal.cyberjapan.jp/index.html
* Map Panel (in a Window)
* -------------------------
* Render a map panel in a Window.
*/
//初期の経度
var initCX = 138.727284;
//初期の緯度
var initCY = 35.360496;
//真球メルカトル投影
var projection900913 = new OpenLayers.Projection("EPSG:900913");
//等経緯度投影を定義
var projection4326 = new OpenLayers.Projection("EPSG:4326");
//mappanelの定義
var mapPanel, controls = [];
Ext.onReady(function() {
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
//真球メルカトル投影のときの最大範囲(単位はm)
var maxExtent = new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508);
//真球メルカトル投影のときの最大範囲に範囲を制限
var restrictedExtent = maxExtent.clone();
//真球メルカトル投影のときの最大解像度
var maxResolution = 156543.0339;
var map = new OpenLayers.Map();
//電子国土WebシステムVer.4背景地図レイヤーインスタンスを作成。
//データセットは未指定で、デフォルトデータセットを利用
webtisMap = new webtis.Layer.BaseMap("webtismap");
map.addLayers([webtisMap]);
map.addControls(controls);
mapPanel = new GeoExt.MapPanel({
title: "GeoExt MapPanel",
renderTo: "mappanel",
stateId: "mappanel",
height: 400,
width: 600,
map: map,
//初期の中心座標を指定(経緯度で入力して、内部的に真球メルカトル座標に変換して表示)
center: new OpenLayers.LonLat(initCX,initCY).transform(projection4326,projection900913),
zoom: 10,
//Googlemap地図の地理座標系
projection: projection900913,
//表示の地理座標系
displayProjection: projection4326,
//Googlemap地図の最大解像度
maxResolution: maxResolution,
//Googlemap地図の最大範囲
maxExtent: maxExtent,
//Googlemap地図の表示制限範囲
restrictedExtent: restrictedExtent,
//Googlemap地図の単位
units: "m",
// パネルサイズの変更
getState: function() {
var state = GeoExt.MapPanel.prototype.getState.apply(this);
state.width = this.getSize().width;
state.height = this.getSize().height;
return state;
},
applyState: function(state) {
GeoExt.MapPanel.prototype.applyState.apply(this, arguments);
this.width = state.width;
this.height = state.height;
}
});
});
controls.push(
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.Navigation({mouseWheelOptions: {interval: 10}}),
new OpenLayers.Control.KeyboardDefaults(),
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.PanPanel(),
new OpenLayers.Control.ZoomPanel()
);
// functions for resizing the map panel
function mapSizeUp() {
var size = mapPanel.getSize();
size.width += 40;
size.height += 40;
mapPanel.setSize(size);
}
function mapSizeDown() {
var size = mapPanel.getSize();
size.width -= 40;
size.height -= 40;
mapPanel.setSize(size);
}
次に、ブラウザーから**http://localhost/test/mappanel-dk_v4.html**とすれば、
{{http://blog.godo-tys.jp/wp-content/gallery/geoext/image07.jpg}}
が表示されます。
とりあえず、OK。 zoompanelが重なっているようで。。。
OpenLayers-2.10や2.11に変更してみるもの良いですね。
OpelayersとGooglemapの不具合も出ませんね? なぜだ???
==== 最後に ====
Googlemapと電子国土地図は細かな部分は違いますが、地図を表示すると言う部分ではGeoExtで表示できると言うことがわかりました。
今回作成したサンプルを[[http://blog.godo-tys.jp/upload/geoext_sample10302012.lzh|こちら]]にアップしておきます。使用する際は自己責任にて使って下さい。
今後は、いくつかのサンプルを参照しながら、手を加えていきたいと考えています。
==== おまけ ====
DBFの編集ソフトを作成してみました。
GISエンジンはMapWinGISを使っています。
ベクターに[[http://www.vector.co.jp/soft/cmt/winnt/business/se499584.html|登録]]も行っています。
また、[[http://www.re-forest.com/|株式会社森林再生システム]]と共同開発で[[http://www.re-forest.com/service/gis.html#ExcelGis|ExcelGIS]]も作成しておりますので、覗いてみてください。