[GIS] Openlayers 3 Vector Layer error

layersopenlayersvector

Getting error from Firebug on running this code:

TypeError: f is null (ol.js 409)

The map is showing up properly. After adding the line : this.map.addLayer(vectorLayer); I get the mentioned error. 🙁

var projection_lan = 'EPSG:4326';
var projection_lat = 'EPSG:3857';
var marker_icon = 'resources/img/green_marker.png';
var map = null;

var pos = ol.proj.transform([ 12.102727890014648, 49.017269896565764 ],projection_lan, projection_lat);

function init() {

    var localTiles = new ol.layer.Tile({
        source : new ol.source.XYZ({
            url : this.tiles_url
        })
    });

    this.map = new ol.Map({
        layers : [ new ol.layer.Tile({
            source : new ol.source.MapQuest({
                layer : 'sat'
            })
        }) ],
        target : 'map',
        view : new ol.View({
            center : pos,
            zoom : 10
        })
    });

    var iconFeature = new ol.Feature(
        {geometry : new ol.geom.Point(pos)
    });

    var iconStyle = new ol.style.Style({
        image : new ol.style.Icon({
            src : 'http://ol3js.org/en/master/examples/data/icon.png'
        })
    });

    iconFeature.setStyle(iconStyle);

    var vectorSource = new ol.source.Vector({
        features : [ iconFeature ]
    });

    var vectorLayer = new ol.layer.Vector({
        source : vectorSource
    });

    this.map.addLayer(vectorLayer);
}

Best Answer

It works with this demo using your code

So, how do you call init() and how your HTML look?

Related Question