1

I've deployed a local openstreetmap tile server and tried many times to show the map using openlayers3, but failed unfortunately. Here's my experiment scene. I deploy the tile server on port 80, and get the image correctly via 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. In the template page, i wrote like this

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]
    });

The map_canvas shows nothing, but i can get the images from tile server in firebug.WHY? Help me, many thanks!

1 Answer 1

1

Try adding crossOrigin: null to the source, like so:

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            
    })
});
Sign up to request clarification or add additional context in comments.

1 Comment

Great. You might enjoy reading about the general problem this relates to: developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.