Javascript KML位置文件-在GoogleEarth中正确显示,但在GoogleMap基础层的OpenLayers2中不正确显示
我有一组从Google Earth保存为KML文件的位置。我尝试使用以下Js代码在简单的OpenLayer2地图上显示相同的位置:Javascript KML位置文件-在GoogleEarth中正确显示,但在GoogleMap基础层的OpenLayers2中不正确显示,javascript,google-maps-api-3,openlayers,kml,Javascript,Google Maps Api 3,Openlayers,Kml,我有一组从Google Earth保存为KML文件的位置。我尝试使用以下Js代码在简单的OpenLayer2地图上显示相同的位置: var map; function init() { var bounds = new OpenLayers.Bounds(); bounds.extend( new OpenLayers.LonLat(0.2, 52.3).transform('EPSG:4326', 'EPSG:3857')); bounds.extend( new O
var map;
function init() {
var bounds = new OpenLayers.Bounds();
bounds.extend( new OpenLayers.LonLat(0.2, 52.3).transform('EPSG:4326', 'EPSG:3857'));
bounds.extend( new OpenLayers.LonLat(1.9, 51.5).transform('EPSG:4326', 'EPSG:3857'));
map = new OpenLayers.Map('map', {
projection: 'EPSG:3857',
layers: [
new OpenLayers.Layer.Google(
"Google Streets", // the default
{ numZoomLevels: null, minZoomLevel: 1, maxZoomLevel: 16 }
),
],
controls: [ new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
],
center: new OpenLayers.LonLat( 1.0, 52.1)
// Google.v3 uses web mercator as projection, so we have to
// transform our coordinates
.transform('EPSG:4326', 'EPSG:3857'),
restrictedExtent: bounds,
zoom: 9,
});
var layer = new OpenLayers.Layer.Vector("KML", {
animationEnabled: true,
projection: map.displayProjection,
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "/static/OL3Example/kml/locations.kml",
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true
})
})
}) ;
map.addLayer(layer);
map.addControl(new OpenLayers.Control.LayerSwitcher());
}
限制延伸使地图仅显示英国萨福克,除4个位置外,其他所有位置都位于萨福克(因此应该在地图上)。查看KML数据,我可以确认KML中的位置是正确的十进制Lon/Lat
当我从地图上删除限制范围时,我可以环游世界,然后我可以在0 Lon,0 Lat处看到一组图标
我已经看过了文档——以及一些与stackoverflow相关的问题:例如,但没有人回答这个问题
我已经使用Firebug调查了地图对象及其图层-我可以确认图层是可见的-并且已绘制,图层上没有未渲染的功能-表明图层加载良好-这是一个投影功能-尽管令人困惑。谷歌地图3也出现了同样的情况-2 API没有关闭-因为我可以看到地图(带有地名、道路等)。。。虽然从长远来看,使用3API当然是更好的方法。我刚刚仔细检查了一下这是谷歌地图v3界面-标签是错误的!