如何使用 ol.source.OSM 的属性 'url'
How to use the attribute 'url' of ol.source.OSM
我已经在本地部署了一个openstreetmap tile server,并多次尝试使用openlayers3显示地图,但不幸的是失败了。
这是我的实验场景。
我把tile server部署在80端口,通过http://127.0.0.1:80/osm_tiles/{z}/{x}/{y}.png. Besides, I place a django web on port 8099, and i can access the web page via http://127.0.0.1:8099/my/page正确获取图像。在模板页面,我是这样写的
var layer = new ol.layer.Tile({
source: new ol.source.OSM({
attributions: [
ol.source.OSM.ATTRIBUTION
],
url:'//127.0.0.1:80/osm_tiles2/{z}/{x}/{y}.png'
})
});
var map= new ol.Map({
target : 'map_canvas',
loadTilesWhileAnimating: true,
view: new ol.View({
center:ol.proj.transform([116.391625,39.906813], 'EPSG:4326', 'EPSG:3857'),
zoom : 12
}),
layers:[layer]
});
map_canvas 什么也没显示,但我可以从 firebug.WHY 的 tile 服务器获取图像?
帮助我,非常感谢!
尝试将 crossOrigin: null
添加到源中,如下所示:
var layer = new ol.layer.Tile({
source: new ol.source.OSM({
attributions: [
ol.source.OSM.ATTRIBUTION
],
url:'//127.0.0.1:80/osm_tiles2/{z}/{x}/{y}.png',
crossOrigin: null
})
});
我已经在本地部署了一个openstreetmap tile server,并多次尝试使用openlayers3显示地图,但不幸的是失败了。 这是我的实验场景。 我把tile server部署在80端口,通过http://127.0.0.1:80/osm_tiles/{z}/{x}/{y}.png. Besides, I place a django web on port 8099, and i can access the web page via http://127.0.0.1:8099/my/page正确获取图像。在模板页面,我是这样写的
var layer = new ol.layer.Tile({
source: new ol.source.OSM({
attributions: [
ol.source.OSM.ATTRIBUTION
],
url:'//127.0.0.1:80/osm_tiles2/{z}/{x}/{y}.png'
})
});
var map= new ol.Map({
target : 'map_canvas',
loadTilesWhileAnimating: true,
view: new ol.View({
center:ol.proj.transform([116.391625,39.906813], 'EPSG:4326', 'EPSG:3857'),
zoom : 12
}),
layers:[layer]
});
map_canvas 什么也没显示,但我可以从 firebug.WHY 的 tile 服务器获取图像? 帮助我,非常感谢!
尝试将 crossOrigin: null
添加到源中,如下所示:
var layer = new ol.layer.Tile({
source: new ol.source.OSM({
attributions: [
ol.source.OSM.ATTRIBUTION
],
url:'//127.0.0.1:80/osm_tiles2/{z}/{x}/{y}.png',
crossOrigin: null
})
});