我想用打開圖層連接到我的EC2開放街道地圖服務器3. 所以,我在服務器上也有文件,例如:
http://ec2-34-240-39-198.eu-west-1.compute.amazonaws.com/openlayers-example.html
然而,我的代碼不顯示的地址,如果你表現出的來源(按Ctrl-U):
var newL = new OpenLayers.Layer.OSM("Default", "/osm_tiles/${z}/${x}/${y}.png", {numZoomLevels: 19});
我不知道是什麼是「默認」,和我不能用打開圖層3 連接我的服務器這是我的代碼:
var map = new ol.Map({
target: 'map',
renderer: 'canvas',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM({
crossOrigin: null,
url: 'http://ec2-34-240-39-198.eu-west-1.compute.amazonaws.com/osm_tiles/${z}/${x}/${y}.png',
}),
}),
vectorLayer,
],
// Create a view centered on the specified location and zoom level
view: new ol.View({
center: ol.proj.transform([2.1833, 41.3833], 'EPSG:4326', 'EPSG:3857'),
zoom: 3
}),
interactions: ol.interaction.defaults().extend([
new ol.interaction.DragRotateAndZoom()
])
});