2

I'm going to host a customized xyz tiled layer so I tested on my local machine to add that layer to OpenLayers Map control. I've already rendered some tiles using generate_tiles.py and Mapnik. I've already confirmed that there's no problem accessing local files by starting my Chrome in --allow-file-access-from-files mode and adding local KML layer. However, not only did the debugger stop the page with the following unhandled exception message, but the map control wouldn't load as well.

Stack trace:

dh (ol.js:112)
ad (ol.js:43)
l.dispatchEvent (ol.js:41)
l.Qn (ol.js:452)
l.Pf (ol.js:125)

paused on exception: 'TypeError: cannot use 'in' operator to search for '10' in undefined'

Related js code:

var projection = ol.proj.get('EPSG:3857');
var raster = new ol.layer.Tile({
    source: new ol.source.OSM()
});

var map = new ol.Map({
    controls: ol.control.defaults({
        attributionOptions:({
            collapsible: false
        })
    }),
    layers: [raster],
    target: document.getElementById('map'),
    view: new ol.View({
        center: ol.proj.fromLonLat([116.5, 40]),
        zoom: 10
    })
});

var xyz = new ol.layer.Tile({
  source: new ol.source.XYZ({
    attributions: ["Local test."],
    url: './{z}/{x}/{y}.png'
  })
});
map.addLayer(xyz);
  • 1
    Found the error at XYZ source constructor. The attribution must be a ol.Attribution object rather than a string. Nothing to do with the layer. – Chang 'Luke' Ren May 19 '15 at 7:45
  • Could I get a bit more clarification on this? I'm trying to add OpenRailwayMap as a layer and getting "Cannot read property 'XYZ' of undefined" Code/site is here – user3512837 Nov 25 '15 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.