您链接的示例中的背景地图被设计为看起来像一张图片。它使用以下代码拉入:
var rasterLayer = new ol.layer.Tile({
source: new ol.source.TileJSON({
url: 'http://api.tiles.mapbox.com/v3/mapbox.geography-class.json',
crossOrigin: ''
})
});
如果您想要不同的地图,您可以将切片图层源替换为 OpenLayers 中可用的任何源,或使用您的自定义源。也许 OpenStreetMap 会是一个选择?只需将上面的 sn-p 替换为以下内容:
var rasterLayer = new ol.layer.Tile({
source: new ol.source.OSM()
});
在该示例中定位弹出窗口并设置其内容的代码是
var coordinates = feature.getGeometry().getCoordinates();
popup.setPosition(coordinates);
$(element).popover({
'placement': 'top',
'html': true,
'content': feature.get('name')
});
要同时显示纬度和经度,请将代码更改为
var coordinates = feature.getGeometry().getCoordinates();
popup.setPosition(coordinates);
$(element).popover({
'placement': 'top',
'html': true,
'content': feature.get('name') + ' ' + ol.coordinate.toStringHDMS(coordinates, 1)
});