GeoExt的使用

GeoExt是一款结合openlayers和Extjs的gis前端框架。目前支持openlayers2.10和Ext3.2.

下载地址:http://geoext.org/index.html

下面是用GeoExt改写的一个小的例子:

 

js代码:

 

/**
 * Copyright (c) 2008-2010 The Open Source Geospatial Foundation
 * 
 * Published under the BSD license.
 * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
 * of the license.
 */

/** api: example[mappanel-div]
 *  Map Panel
 *  ---------
 *  Render a map panel in any block level page element.
 */

var mapPanel,map;

Ext.onReady(function() {
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
  var bounds = new OpenLayers.Bounds(113.235,23.04,113.416,23.12);

     map = new OpenLayers.Map();
    var layer = new OpenLayers.Layer.WMS(
        "Global Imagery",
        "http://maps.opengeo.org/geowebcache/service/wms",
        {layers: "bluemarble"}
    );

    map.addLayer(layer);

 map.addControl(new OpenLayers.Control.LayerSwitcher());

  map.addControl(new OpenLayers.Control.Navigation());
  map.addControl(new OpenLayers.Control.Scale($('scale')));
  map.addControl(new OpenLayers.Control.MousePosition({
        element : $('location')
      }));
  map.addControl(new OpenLayers.Control.OverviewMap());
  map.addControl(new OpenLayers.Control.ScaleLine());

 var simple = new Ext.FormPanel({
        labelWidth: 60, // label settings here cascade unless overridden
        url:'save-form.php',
        frame:true,
        title: '',
        bodyStyle:'padding:5px 5px 0',
        width: 350,
        defaults: {width: 230},
        defaultType: 'textfield',

        items: [{
                fieldLabel: '演示速度',
                name: 'first',
                width:50,
                allowBlank:true
            },{
                fieldLabel: '轨迹速度',
                width:50,
                name: 'last'
            }
        ],

        buttons: [{
            text: '确定',
                handler:function(){win.hide();}
        },{
            text: '取消',
                handler:function(){win.hide();}
        }]
    });
   win = new Ext.Window({
                layout:'fit',
                width:200,
                height:150,
								title:'速度设置',
								draggable:false,
    						resizable : false,
                closeAction:'hide',
                plain: true,
                items: [simple]   
            });
    mapPanel = new GeoExt.MapPanel({
        title: "GeoExt MapPanel",
        renderTo: "mappanel",
        stateId: "mappanel",
        height: 600,
        width: 1000,
        map: map,

        center: new OpenLayers.LonLat(113.31898,23.08618),//two
        zoom: 18,
				//extent: bounds,//one
        // getState and applyState are overloaded so panel size
        // can be stored and restored
   items:[{
            xtype: 'button',
            id: 'basic-button',
						style :'position: absolute; z-index: 1000; right: 15px; top: 5px; left: auto;',
            text: '设置',
						handler:function (b){
								win.x=b.el.dom.offsetParent.offsetWidth+b.el.dom.offsetParent.offsetLeft-230;
								win.y=b.el.dom.offsetParent.offsetTop+30;
						if(!win.isVisible()){
								win.show();
						}else{
								win.hide();
						}

						}
        }],

        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;
        }
    });
});

// functions for resizing the map panel
function mapSizeUp() {
    var size = mapPanel.getSize();
    size.width += 40;
    size.height += 40;
    mapPanel.setSize(size);
    map.setCenter(new OpenLayers.LonLat(113.31898,23.08618), 0);
}
function mapSizeDown() {
    var size = mapPanel.getSize();
    size.width -= 40;
    size.height -= 40;
    mapPanel.setSize(size);
}
var selectControl,vectors;
function mapAddLayer(){
var v_style =  new OpenLayers.StyleMap({
                        "default": {
														strokeOpacity: 1,
														strokeWidth: 1,
														pointRadius: 6,
                            fillOpacity:1
                        },
                        "select": {
                            cursor: "pointer",
														strokeColor: "blue",
														fillColor: "blue"                   
                        }
                    });
            vectors = new OpenLayers.Layer.Vector(
                "layer1",
                {
					visibility : true,
                    styleMap: v_style
                }
            );
				map.addLayer(vectors);
        selectControl= new OpenLayers.Control.SelectFeature(
                vectors, {clickout: true, toggle: false,
                    multiple: false, hover: false});
            map.addControl(selectControl);
            selectControl.activate();
				var pointFeature = new OpenLayers.Feature.Vector(
		         new OpenLayers.Geometry.Point(113.31898,23.0861));//
				var pFeature = new OpenLayers.Feature.Vector(
		         new OpenLayers.Geometry.Point(113.32898,23.0861));//
				vectors.addFeatures([pointFeature,pFeature]);


    // create popup on "featureselected"
    vectors.events.on({
        featureselected: function(e) {
            createPopup(e.feature);
        },
  featureunselected :function(e){
			popup.destroy();
			popup = null;
}
    });
}

    var bogusMarkup = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.";
    function createPopup(feature) {
        popup = new GeoExt.Popup({
            title: 'My Popup',
            location: feature,
            width:200,
            html: bogusMarkup,
            maximizable: true,
						unpinnable: false,
            collapsible: true
        });
        // unselect feature when the popup
        // is closed
        popup.on({
            close: function() {
                    selectControl.unselect(feature);
                if(OpenLayers.Util.indexOf(vectors.selectedFeatures,
                                           this.feature) > -1) {
										popup = null;
                }
            }
        });
        popup.show();
    }

 html页面代码:

 

<html>
    <head>
        <title>GeoExt MapPanel Example</title>

        <script type="text/javascript" src="http://extjs.cachefly.net/ext-3.2.1/adapter/ext/ext-base.js"></script>
        <script type="text/javascript" src="http://extjs.cachefly.net/ext-3.2.1/ext-all.js"></script>
        <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-3.2.1/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-3.2.1/examples/shared/examples.css" />
        <script src="http://www.openlayers.org/api/2.10/OpenLayers.js"></script>
        <script type="text/javascript" src="../script/GeoExt.js"></script>

        <script type="text/javascript" src="mappanel-div.js"></script>

    </head>
    <body>
        <h1>GeoExt.MapPanel with an Existing OpenLayers.Map</h1>
        <p>This example shows the how to create a MapPanel with a map that has
        already been created.  See <a href="mappanel-window.html">mappanel-window.html</a>
        for an example that creates the MapPanel without creating the map first.<p>
        <p>This example makes use of a <code>CookieProvider</code>. The <code>MapPanel</code>
        being a stateful component, if you reload the page the map should be
        at the same location as previously. Also the <code>getState</code> and
        <code>applyState</code> methods are overloaded so the size of the map
        panel is also restored when refreshing the page.</p>
        <p>The js is not minified so it is readable. See <a href="mappanel-div.js">mappanel-div.js</a>.</p>
        <div id="mappanel"></div>
        <input type="button" οnclick="mapSizeUp()" value="bigger"></input>
        <input type="button" οnclick="mapSizeDown()" value="smaller"></input>
        <input type="button" οnclick="mapAddLayer()" value="addlayer"></input>
    </body>
</html>

 效果图:


请问在openlayers中如何删除Layer中的marker 3 在层中加了一个标记怎么永久的存到地图上 3 OpenLayers 如何设死地图边界 3 谁写过openlayers解析xml 3 openlayer.popup 3 OpenLayers 怎么做字段标注 4 字段标注不是用OL做的,而是你在SLD中定义用数据表的哪个字段做标签就可以了 4 OpenLayers 中画最短轨迹 4 使用TileCache配合OpenLayers 4 openlayers如何准确测距 9 openlayers简单实用例子 9 关于TileCache函数 13 openlayers 有函数说明的类图 14 go 14 Maker 一多,客户端就死掉 15 OpenLayers 怎么实现 AJAX 16 openlayer 要怎么研究才会应用得比较自如 16 改良OpenLayers的Popup 16 在openlayers的地图中要添加地图搜索功能一般采用什么方法 17 openlayers中如何访问geoserver发布的图片 18 什么是TMS? 18 怎样设置瓦片的大小 18 画一条线,数据量太大,怎么办? 18 怎么在图层上动态画点 20 GeoExt集成google map ,地图偏移 21 用JavaScriptOpenLayers.Marker的加上单击显示详细信息的功能 21 改良OpenLayers的MousePostion 25 使用OpenLayers实现一个在鼠标点击处添加标记的效果 27 openlayers 利用google maps的卫星地图 29 openLayers集成google map ,点标注错位 30 openlayers可以做出谷歌效果的地图吗? 31 用OpenLayers API和类来画点、线、面 32 OGC标准术语介绍WMS、WFS、WCS 35 如何控制地图的放缩 37 openLayers链接WMS的代码探讨 37 openlayers 2.5 矢量层在ie下闪烁的问题 38 openLayers 在地图上添加一个点并保存 39 openLayers 各个参数的意义 42 geoserver能搞出这种风格的图来吗? 43 关于SLD的线切割后的设置 43 GEOSERVE 标注铁路,使用 SLD 44 geoserver 发布.shp 中文乱码问题 怎么解决啊 45 Geoserver怎么连postGreSql 数据库 48 Geoserver连Oracle Spatial 52 GeoServer架构浅谈 53 Geoserver发布地图无法显示问题 57 WebGIS相关的OpenGIS规范 58 geoserver中地图以外的区域以自定义图片填充 62 怎样修改 geoServer 的用户名密码 65 GeoServer中的WMS服务生成的png图片背景色为透明 65 比例尺 65 需不需要一个layer对应一个store 66 如何部署shp 66 用GeoWebCache后Marker错位 66 标签太大导致不能显示? 67 geoserver把两个shapefile格式的图叠 67 GeoServer 能够集成 Google Map? 68 gwc地图切片的缓存路径在web.xml中设置么 68 如何实现地图查询? 68 sld文件怎么用 69 在sld中怎么控制路名的间隔? 69
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值