我只是简单地从http://openlayers.org/dev/examples/getfeatureinfo-control.html复制了示例代码。
我使用geoserver来运行它,一切工作正常,就像互联网版本一样,现在我试图用一个虚拟地球地图来更改政治基本图层。
由于虚拟地球和谷歌地图的性质,我已经将球形墨卡托设置为true,但之后突出显示功能就不再起作用了。
我想我已经发现了问题所在,在我创建的向量和其他图层之间有不同的投影,而openlayer不知道如何合并它们。有没有办法把我的向量层从(我想) epsg:4326转换到epsg:900913 (sherical mercator)?
下面是我的代码:
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<style>
.opmap
{
height:500px;
width:550px;
}
/* The map and the location bar */
#map {
clear: both;
position: relative;
width: 400px;
height: 450px;
border: 1px solid black;
}
.mypopuphtml{
padding-left:5px;
padding-top:0px;
padding-bottom:0px;
padding-right:5px;
font-family:Arial;
font-size:8pt;
background-color:white;
}
</style>
<script defer="defer" type="text/javascript">
var map, infocontrols, water, highlightlayer;
function load() {
var options = {
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
//maxExtent: new OpenLayers.Bounds(11.1373,46.6196,11.2117,46.6919),
numZoomLevels: 19,
units: 'degrees',
projection: new OpenLayers.Projection("EPSG:4326"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
};
map = new OpenLayers.Map('map', options);
/*
var political = new OpenLayers.Layer.WMS("State Boundaries",
"http://localhost:8080/geoserver/wms",
{'layers': 'topp:tasmania_state_boundaries', transparent: true, format: 'image/gif'},
{isBaseLayer: true}
);
*/
// setup tiled layer
var blConfig = {'sphericalMercator': true};
var ve = new OpenLayers.Layer.VirtualEarth( "Bing", blConfig);
var roads = new OpenLayers.Layer.WMS("Roads",
"http://localhost:8080/geoserver/wms",
{'layers': 'topp:tasmania_roads', transparent: true, format: 'image/gif'},
{isBaseLayer: false}
);
var cities = new OpenLayers.Layer.WMS("Cities",
"http://localhost:8080/geoserver/wms",
{'layers': 'topp:tasmania_cities', transparent: true, format: 'image/gif'},
{isBaseLayer: false}
);
water = new OpenLayers.Layer.WMS("Bodies of Water",
"http://localhost:8080/geoserver/wms",
{'layers': 'topp:tasmania_water_bodies', transparent: true, format: 'image/gif'},
{isBaseLayer: false}
);
highlightLayer = new OpenLayers.Layer.Vector("Highlighted Features", {
isBaseLayer: false,
projection: new OpenLayers.Projection("EPSG:900913")
}
);
infoControls = {
click: new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost:8080/geoserver/wms',
title: 'Identify features by clicking',
layers: [water],
queryVisible: true
}),
hover: new OpenLayers.Control.WMSGetFeatureInfo({
url: 'http://localhost:8080/geoserver/wms',
title: 'Identify features by clicking',
layers: [water],
hover: true,
// defining a custom format options here
formatOptions: {
typeName: 'water_bodies',
featureNS: 'http://www.openplans.org/topp'
},
queryVisible: true
})
}
//map.addLayers([political, roads, cities, water, highlightLayer]);
map.addLayers([ve, roads, cities, water, highlightLayer]);
for (var i in infoControls) {
infoControls[i].events.register("getfeatureinfo", this, showInfo);
map.addControl(infoControls[i]);
}
map.addControl(new OpenLayers.Control.LayerSwitcher());
infoControls.click.activate();
map.zoomToMaxExtent();
}
function showInfo(evt) {
if (evt.features && evt.features.length) {
highlightLayer.destroyFeatures();
highlightLayer.addFeatures(evt.features);
highlightLayer.redraw();
} else {
$('responseText').innerHTML = evt.text;
}
}
function toggleControl(element) {
for (var key in infoControls) {
var control = infoControls[key];
if (element.value == key && element.checked) {
control.activate();
} else {
control.deactivate();
}
}
}
function toggleFormat(element) {
for (var key in infoControls) {
var control = infoControls[key];
control.infoFormat = element.value;
}
}
function toggleLayers(element) {
for (var key in infoControls) {
var control = infoControls[key];
if (element.value == 'Specified') {
control.layers = [water];
} else {
control.layers = null;
}
}
}
// function toggle(key
</script>发布于 2011-07-31 12:02:37
我不确定你有什么问题。
<script src='http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1'></script>也是
function load() {
var options = {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
units: "m",
numZoomLevels: 22,
maxResolution: 156543.0339,
maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
20037508, 20037508.34)
};然后,
var veroad = new OpenLayers.Layer.VirtualEarth(
"Bing",
{isBaseLayer: true, 'sphericalMercator': true}
);这些WMS数据似乎并不正确,除了水,它的地图与虚拟地球地图。
我的问题是,如果我从提供页面的服务器以外的服务器请求FeatureInfo,代理就会报告错误。
https://stackoverflow.com/questions/6294376
复制相似问题