一个完整openlayer的例子,包括marker,popup等
整理转自:http://www.blogjava.net/siriusfx/archive/2007/11/26/163104.html
openlayers提供了几十个示例,虽然每个示例都很简单,但却很具有代表性,值得初学者学习。
现在我想做一个测试,包含多个图层、缩放条、工具条、鼠标位置、弹出窗口,其中图层分别来自geoservr
提供的WMS和WFS服务接口。
主要代码如下:
样式定义,定义地图大小,工具条位置和替换按钮图片。
<style type="text/css">
#map {
width: 640px;
height: 475px;
border: 1px solid black;
} .olControlPanel div {
display:block;
position: absolute;
top: 0px;
left: 190px;
width: 60px;
height: 23px;
margin: 5px;
}
.olControlPanel .olControlMouseDefaultsItemActive {
background-image: url("/openlayers/img/Pan.gif");
}
.olControlPanel .olControlMouseDefaultsItemInactive {
background-image: url("/openlayers/img/PanSelected.gif");
}
.olControlPanel .olControlZoomBoxItemInactive {
width: 60px;
height: 23px;
position: absolute;
top: 0px;
left: 250px;
background-image: url("/openlayers/img/ZoomInSelected.gif");
}
.olControlPanel .olControlZoomBoxItemActive {
width: 60px;
height: 23px;
position: absolute;
top: 0px;
left: 250px;
background-image: url("/openlayers/img/ZoomIn.gif");
}
.olControlPanel .olControlSelectFeatureItemInactive {
width: 60px;
height: 23px;
position: absolute;
top: 0px;
left: 310px;
background-image: url("/openlayers/img/InfoSelected.gif");
}
.olControlPanel .olControlSelectFeatureItemActive {
width: 60px;
height: 23px;
position: absolute;
top: 0px;
left: 310px;
background-image: url("/openlayers/img/Info.gif");
}
</style>
JS代码,核心部分。
<script src="/openlayers/OpenLayers.js"></script>
<script type="text/javascript">
<!--
//定义全局变量
var map, layer, selectControl, selectedFeature;
//关闭弹出窗口的函数
function onPopupClose(evt) {
selectControl.unselect(selectedFeature);
}
//构造弹出窗口的函数
function onFeatureSelect(feature) {
selectedFeature = feature;
popup = new OpenLayers.Popup.Anchored("chicken",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(250,75),
"<div style='font-size:.8em'>" + feature.attributes['cq:LNAME'] +"</div>",
null, true, onPopupClose);
feature.popup = popup;
map.addPopup(popup);
}
//销毁弹出窗口的函数
function onFeatureUnselect(feature) {
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
//地图和页面加载函数
function init(){
//设置地图缩放范围和缩放等级,0级比例尺最小
map = new OpenLayers.Map( $('map'), { maxScale: 500, minScale: 500000, numZoomLevels: 5 });
//加载行政区图层,WMS栅格图像
layer = new OpenLayers.Layer.WMS( "District",
"http://192.98.151.17:8081/geoserver/wms", {layers: 'cq:GMAP_DISTRICT'} );
map.addLayer(layer);
//加载水系图层,WMS栅格图像
layer = new OpenLayers.Layer.WMS( "Water",
"http://192.98.151.17:8081/geoserver/wms", {layers: 'cq:GMAP_LAKE', 'transparent': true, format: 'image/png' } );
map.addLayer(layer);
//加载单位图层,WFS矢量数据,由openlayers在客户端绘制,注意:数量太多会导致速度缓慢
layer = new OpenLayers.Layer.WFS( "Unit",
"http://192.98.151.17:8081/geoserver/wfs", {typename: 'cq:GPOI_GOV'},
{
typename: 'unit',
featureNS: 'http://www.openplans.org/cq',
extractAttributes: true,
maxfeatures: 10,
textAttrToDisplay: 'lname'
} );
map.addLayer(layer);
//在地图上添加按钮和工具条
zb = new OpenLayers.Control.ZoomBox();
var panel = new OpenLayers.Control.Panel({defaultControl: zb});
selectControl = new OpenLayers.Control.SelectFeature(layer, {onSelect: onFeatureSelect, onUnselect: onFeatureUnselect, hover: true});
panel.addControls([
new OpenLayers.Control.MouseDefaults(), zb, selectControl
]);
map.addControl(panel); map.addControl(new OpenLayers.Control.PanZoomBar({zoomWorldIcon:false}));
map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false}));
map.addControl(new OpenLayers.Control.MousePosition());
//设置初始地图的中心坐标和缩放等级
map.setCenter(new OpenLayers.LonLat(106.5, 29.5), 3); }
// -->
</script><body onload="init()">
<h1>OpenLayers Test</h1>
<div id="panel"></div>
<div id="map"></div>
<textarea style="display:none" id="serialize" cols="96" rows="10"/>
</body>
一个完整openlayer的例子,包括marker,popup等的更多相关文章
- 和S5933比较起来,开发PLX9054比较不幸,可能是第一次开发PCI的缘故吧。因为,很多PCI的例子都是对S5933,就连微软出版的《Programming the Microsoft Windows Driver Model》都提供了一个完整的S5933的例子。 在这篇有关DDK的开发论文里。
和S5933比较起来,开发PLX9054比较不幸,可能是第一次开发PCI的缘故吧.因为,很多PCI的例子都是对S5933,就连微软出版的<Programming the Microsoft Wi ...
- 【ABAP系列】SAP 一个完整的SAP的Abap例子(idoc,edi文件的相互转换)
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP 一个完整的SAP的Aba ...
- 《Java从入门到失业》第四章:类和对象(4.3):一个完整的例子带你深入类和对象
4.3一个完整的例子带你深入类和对象 到此为止,我们基本掌握了类和对象的基础知识,并且还学会了String类的基本使用,下面我想用一个实际的小例子,逐步来讨论类和对象的一些其他知识点. 4.3.1需求 ...
- Django1.8教程——从零开始搭建一个完整django博客(一)
第一个Django项目将是一个完整的博客网站.它和我们博客园使用的博客别无二致,一样有分类.标签.归档.查询等功能.如果你对Django感兴趣的话,这是一个绝好的机会.该教程将和你一起,从零开始,搭建 ...
- 一个完整的Installshield安装程序实例—艾泽拉斯之海洋女神出品(四) --高级设置二
原文:一个完整的Installshield安装程序实例-艾泽拉斯之海洋女神出品(四) --高级设置二 上一篇:一个完整的安装程序实例—艾泽拉斯之海洋女神出品(三) --高级设置一4. 根据用户选择的组 ...
- 一个完整的Installshield安装程序实例-转
一个完整的Installshield安装程序实例—艾泽拉斯之海洋女神出品(一)---基本设置一 前言 Installshield可以说是最好的做安装程序的商业软件之一,不过因为功能的太过于强大,以至于 ...
- 手把手搭建一个完整的javaweb项目
手把手搭建一个完整的javaweb项目 本案例使用Servlet+jsp制作,用MyEclipse和Mysql数据库进行搭建,详细介绍了搭建过程及知识点. 下载地址:http://download.c ...
- [转]一个完整的Installshield安装程序实例
@import url("http://files.cnblogs.com/files/go-jzg/vs.css"); --> Installshield安装程序实例—基本 ...
- 一个完整的Erlang应用
http://blog.chinaunix.net/uid-25876834-id-3308693.html 这里介绍构建一个完整的Erlang/OTP应用的例子,最后还给出了一个在实际生成环境中,如 ...
随机推荐
- aspcms中if判断语句的运用
1.<h3 {if:"[list:isrecommend]"="1"} style="color:red;"{end if}>& ...
- DWZ与KindEditor编辑器的整合
DWZ自带的编辑器是xheditor,可能很多人用不习惯.就像我,习惯用kindeditor了.现在就来说说如何整合dwz和kindeditor. 一.打开DWZ的中的dwz.ui.js,进行修改. ...
- 使用命令修改ip地址
简述:以serverv 2012 r2为例 常用的几种,当然不全,希望能较快的速率记下一种便可 直接配置 1. 查看网卡的显示名称 2. 配置静态iP地址 3. 查看配置 ...
- MIME类型大全
获取MIME:HttpContext.Current.Request.Files[fileKey].ContentLength MIME类型就是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该 ...
- 济南学习 Day 2 T2 pm
她[问题描述]给你L,R,S,M,求满足L≤ (S × x) mod M ≤ R最小的正整数 X.[输入格式]第一行一个数T代表数据组数.接下来一行每行四个数代表该组数据的L,R,S,M.[输出格式] ...
- OpenGL第6、7讲小结
因为内容比较多,所以只看了两讲(强行解释). 一讲讲了如何给各个面贴纹理,一讲讲了加光照和按键控制. 现在讲的都是给规则的面贴纹理,像正方形,刚好纹理图也是正方形,那像人物模型的衣服贴起来用代码控制得 ...
- 1 . Robberies (hdu 2955)
The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually g ...
- c#获取今天星期几
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek)
- PHP获取时间日期的多种方法
分享下PHP获取时间日期的多种方法. <?php echo "今天:".date("Y-m-d")."<br>"; ...
- Crusher Django Tutorial(5) 使用内置管理员系统
http://crusher-milling.blogspot.com/2013/09/crusher-django-tutorial5-using-admin.html 顺便学习一下FQ Crush ...