Openlayers 如何在openlayer map WMS上缩放到特定坐标?
我试图通过方法setCenter设置地图中心,但仍然不起作用。地图没有移动。我尝试使用从投影到地图投影的转换,但没有成功。这是代码的一部分Openlayers 如何在openlayer map WMS上缩放到特定坐标?,openlayers,geoserver,wms,Openlayers,Geoserver,Wms,我试图通过方法setCenter设置地图中心,但仍然不起作用。地图没有移动。我尝试使用从投影到地图投影的转换,但没有成功。这是代码的一部分 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Batam GIS</
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>
<title>Batam GIS</title>
<!-- Import OL CSS, auto import does not work with our minified OL.js build -->
<link rel="stylesheet" type="text/css" href="http://batamgis.jelastic.skali.net/geoserver/openlayers/theme/default/style.css">
<!-- Basic CSS definitions -->
<style type="text/css">
/* General settings */
body {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: small;
}
/* Toolbar styles */
#toolbar {
position: relative;
padding-bottom: 0.5em;
display: none;
}
#toolbar ul {
list-style: none;
padding: 0;
margin: 0;
}
#toolbar ul li {
float: left;
padding-right: 1em;
padding-bottom: 0.5em;
}
#toolbar ul li a {
font-weight: bold;
font-size: smaller;
vertical-align: middle;
color: black;
text-decoration: none;
}
#toolbar ul li a:hover {
text-decoration: underline;
}
#toolbar ul li * {
vertical-align: middle;
}
/* The map and the location bar */
#map {
clear: both;
position: relative;
width: 300px;
height: 448px;
border: 1px solid black;
}
#wrapper {
width: 300px;
}
#location {
float: right;
}
#options {
position: absolute;
left: 13px;
top: 7px;
z-index: 3000;
}
/* Styles used by the default GetFeatureInfo output, added to make IE happy */
table.featureInfo, table.featureInfo td, table.featureInfo th {
border: 1px solid #ddd;
border-collapse: collapse;
margin: 0;
padding: 0;
font-size: 90%;
padding: .2em .1em;
}
table.featureInfo th {
padding: .2em .2em;
font-weight: bold;
background: #eee;
}
table.featureInfo td {
background: #fff;
}
table.featureInfo tr.odd td {
background: #eee;
}
table.featureInfo caption {
text-align: left;
font-size: 100%;
font-weight: bold;
padding: .2em .2em;
}
</style>
<!-- Import OpenLayers, reduced, wms read only version -->
<script src="http://batamgis.jelastic.skali.net/geoserver/openlayers/OpenLayers.js" type="text/javascript">
</script>
<script defer="defer" type="text/javascript">
var map;
var untiled;
var tiled;
var pureCoverage = false;
// pink tile avoidance
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 5;
// make OL compute scale according to WMS spec
OpenLayers.DOTS_PER_INCH = 25.4 / 0.28;
function init(){
// if this is just a coverage or a group of them, disable a few items,
// and default to jpeg format
format = 'image/png';
if(pureCoverage) {
document.getElementById('filterType').disabled = true;
document.getElementById('filter').disabled = true;
document.getElementById('antialiasSelector').disabled = true;
document.getElementById('updateFilterButton').disabled = true;
document.getElementById('resetFilterButton').disabled = true;
document.getElementById('jpeg').selected = true;
format = "image/jpeg";
}
var bounds = new OpenLayers.Bounds(
103.88943658903702, 0.9680605034743621,
104.15031077055329, 1.1995421846569343
);
var options = {
controls: [],
maxExtent: bounds,
maxResolution: 0.0010190397715479,
projection: "EPSG:4326",
units: 'degrees'
};
map = new OpenLayers.Map('map', options);
// setup tiled layer
tiled = new OpenLayers.Layer.WMS(
"Geoserver layers - Tiled", "http://batamgis.jelastic.skali.net/geoserver/BatamGIS/wms",
{
STYLES: '',
LAYERS: 'BatamGIS',
format: format
},
{
buffer: 0,
displayOutsideMaxExtent: true,
isBaseLayer: true,
yx : {'EPSG:4326' : true}
}
);
// setup single tiled layer
untiled = new OpenLayers.Layer.WMS(
"Geoserver layers - Untiled", "http://batamgis.jelastic.skali.net/geoserver/BatamGIS/wms",
{
STYLES: '',
LAYERS: 'BatamGIS',
format: format
},
{
singleTile: true,
ratio: 1,
isBaseLayer: true,
yx : {'EPSG:4326' : true}
}
);
map.addLayers([untiled, tiled]);
var lonlat = new OpenLayers.LonLat(104.020278, 1.068333).transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator
);
var zoom = 13;
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
markers.addMarker(new OpenLayers.Marker(lonlat));
map.setCenter(lonlat, zoom);
}
</script>
</head>
<body onload="init()">
<div id="toolbar" style="display: none;">
<ul>
<li>
<a>WMS version:</a>
<select id="wmsVersionSelector" onchange="setWMSVersion(value)">
<option value="1.1.1">1.1.1</option>
<option value="1.3.0">1.3.0</option>
</select>
</li>
<li>
<a>Tiling:</a>
<select id="tilingModeSelector" onchange="setTileMode(value)">
<option value="untiled">Single tile</option>
<option value="tiled">Tiled</option>
</select>
</li>
<li>
<a>Transition effect:</a>
<select id="transitionEffectSelector" onchange="setTransitionMode(value)">
<option value="">None</option>
<option value="resize">Resize</option>
</select>
</li>
<li>
<a>Antialias:</a>
<select id="antialiasSelector" onchange="setAntialiasMode(value)">
<option value="full">Full</option>
<option value="text">Text only</option>
<option value="none">Disabled</option>
</select>
</li>
<li>
<a>Format:</a>
<select id="imageFormatSelector" onchange="setImageFormat(value)">
<option value="image/png">PNG 24bit</option>
<option value="image/png8">PNG 8bit</option>
<option value="image/gif">GIF</option>
<option id="jpeg" value="image/jpeg">JPEG</option>
</select>
</li>
<li>
<a>Styles:</a>
<select id="imageFormatSelector" onchange="setStyle(value)">
<option value="">Default</option>
</select>
</li>
<li>
<a>Filter:</a>
<select id="filterType">
<option value="cql">CQL</option>
<option value="ogc">OGC</option>
<option value="fid">FeatureID</option>
</select>
<input type="text" size="80" id="filter">
<img id="updateFilterButton" src="http://batamgis.jelastic.skali.net/geoserver/openlayers/img/east-mini.png" onclick="updateFilter()" title="Apply filter">
<img id="resetFilterButton" src="http://batamgis.jelastic.skali.net/openlayers/img/cancel.png" onclick="resetFilter()" title="Reset filter">
</li>
</ul>
</div>
<div id="map" class="olMap">
<title>Geoserver GetFeatureInfo output</title> <style type="text/css">
table.featureInfo, table.featureInfo td, table.featureInfo th {
border:1px solid #ddd;
border-collapse:collapse;
margin:0;
padding:0;
font-size: 90%;
padding:.2em .1em;
}
table.featureInfo th {
padding:.2em .2em;
font-weight:bold;
background:#eee;
}
table.featureInfo td{
background:#fff;
}
table.featureInfo tr.odd td{
background:#eee;
}
table.featureInfo caption{
text-align:left;
font-size:100%;
font-weight:bold;
padding:.2em .2em;
}
巴淡岛地理信息系统
/*一般设置*/
身体{
字体系列:Verdana、Geneva、Arial、Helvetica、sans serif;
字体大小:小;
}
/*工具栏样式*/
#工具栏{
位置:相对位置;
垫底:0.5em;
显示:无;
}
#工具栏ul{
列表样式:无;
填充:0;
保证金:0;
}
#李小玲{
浮动:左;
右侧填充:1em;
垫底:0.5em;
}
#李安先生{
字体大小:粗体;
字体大小:较小;
垂直对齐:中间对齐;
颜色:黑色;
文字装饰:无;
}
#工具栏a:悬停{
文字装饰:下划线;
}
#李国宝*{
垂直对齐:中间对齐;
}
/*地图和位置栏*/
#地图{
明确:两者皆有;
位置:相对位置;
宽度:300px;
高度:448px;
边框:1px纯黑;
}
#包装纸{
宽度:300px;
}
#位置{
浮动:对;
}
#选择权{
位置:绝对位置;
左:13px;
顶部:7px;
z指数:3000;
}
/*默认GetFeatureInfo输出使用的样式,添加以使IE满意*/
table.featureInfo,table.featureInfo td,table.featureInfo th{
边框:1px实心#ddd;
边界塌陷:塌陷;
保证金:0;
填充:0;
字体大小:90%;
填充物:2米1米;
}
表1.featureInfo th{
填料:2em.2em;
字体大小:粗体;
背景:#eee;
}
表1.featureInfo td{
背景:#fff;
}
table.featureInfo tr.odd td{
背景:#eee;
}
table.featureInfo标题{
文本对齐:左对齐;
字体大小:100%;
字体大小:粗体;
填料:2em.2em;
}
var映射;
var未计;
瓦状;
var pureCoverage=false;
//避免使用粉色瓷砖
OpenLayers.IMAGE_RELOAD_尝试次数=5;
//根据WMS规范制作OL计算比例
OpenLayers.DOTS_/u英寸=25.4/0.28;
函数init(){
//如果这只是一个覆盖范围或一组覆盖范围,请禁用一些项目,
//并默认为jpeg格式
格式='image/png';
if(纯覆盖){
document.getElementById('filterType')。disabled=true;
document.getElementById('filter')。disabled=true;
document.getElementById('antialasSelector')。disabled=true;
document.getElementById('updateFilterButton')。disabled=true;
document.getElementById('resetFilterButton')。disabled=true;
document.getElementById('jpeg')。selected=true;
format=“image/jpeg”;
}
var bounds=新的OpenLayers.bounds(
103.88943658903702, 0.9680605034743621,
104.15031077055329, 1.1995421846569343
);
变量选项={
控件:[],
maxExtent:bounds,
最大分辨率:0.0010190397715479,
投影:“EPSG:4326”,
单位:度
};
map=newOpenLayers.map('map',选项);
//设置平铺层
平铺=新OpenLayers.Layer.WMS(
“地理服务器层-平铺”http://batamgis.jelastic.skali.net/geoserver/BatamGIS/wms",
{
样式:“”,
图层:“BatamGIS”,
格式:格式
},
{
缓冲区:0,
displayOutsideMaxExtent:true,
isBaseLayer:是的,
yx:{'EPSG:4326':true}
}
);
//设置单个平铺层
untiled=new OpenLayers.Layer.WMS(
“地理服务器层-未拆分”http://batamgis.jelastic.skali.net/geoserver/BatamGIS/wms",
{
样式:“”,
图层:“BatamGIS”,
格式:格式
},
{
是的,
比率:1,
isBaseLayer:是的,
yx:{'EPSG:4326':true}
}
);
map.addLayers([untiled,tiled]);
var lonlat=newopenlayers.lonlat(104.020278,1.068333).transform(
新OpenLayers.Projection(“EPSG:4326”),//从WGS 1984转换而来
新OpenLayers.Projection(“EPSG:900913”)//到球形墨卡托
);
var=13;
var markers=新的OpenLayers.Layer.markers(“markers”);
添加图层(标记);
markers.addMarker(新OpenLayers.Marker(lonlat));
地图设置中心(lonlat,zoom);
}
-
WMS版本:
1.1.1
1.3.0
-
瓷砖:
单面瓷砖
瓦片
-
过渡效应:
没有一个
调整大小
-
map.getView().setCenter(lonlat);
map.getView().setZoom(zoom);
map.setCenter(lonlat, zoom);