我正在尝试在我的网页中实施Annotorious Openlayers example。我能够正确地获取地图,但没有图像被加载到其中。我以前从未使用过Openlayers。
默认代码为:
var baseLayer = new OpenLayers.Layer.TMS("Baselayer", "map_muenster/",
{ layername: ".",
serviceVersion: ".",
transitionEffect: "resize",
type:"jpg" });
我认为在map_muenster
目录中查找图像,但我只是希望它显示一个图像。
稍微抬头后,我找到了this Stack Overflow帖子。我尝试在地图中添加此图层:
var osm = new OpenLayers.Layer.OSM();
var graphic = new OpenLayers.Layer.Image(
'Image',
'https://www.w3schools.com/css/paris.jpg',
new OpenLayers.Bounds(27.418100,35.771100,28.388000,36.558500),
new OpenLayers.Size(800,255),
{numZoomLevels: 3}
);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addLayers([osm, graphic]);
map.zoomToExtent(new OpenLayers.Bounds(27.418100,35.771100,28.388000,36.558500));
但是,不是在https://www.w3schools.com/css/paris.jpg
显示图像,而是显示世界地图。
如何将图像添加到地图中并使其显而易见?
答案 0 :(得分:0)
通过替换此行来实现它:
map.addLayers([osm, graphic]);
用这个:
map.addLayers([graphic, osm]);