0

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);
}
  • 1
    It works with this demo using your code bl.ocks.org/ThomasG77/16bfcdab4671c7e8a300 So, how do you call init() and how your HTML look? – ThomasG77 Oct 25 '14 at 13:12
  • Your Example works fine :-) Found now the problem. I called the map from an xhtml-File. I don't really know what was going wrong with an normal xhtml File...but after desperatly changing to an simple html File everything seems to be fine. Thaks a lot !!!! – user2463728 Oct 26 '14 at 13:23
  • You can repost as an answer, so I can mark the problem as solved :-) – user2463728 Oct 26 '14 at 13:25
1

It works with this demo using your code

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

  • Your Example works fine :-) Found now the problem. I called the map from an xhtml-File. I don't really know what was going wrong with an normal xhtml File...but after desperatly changing to an simple html File everything seems to be fine. Thaks a lot !!!! – user2463728 Oct 26 '14 at 18:27
0

Your longitude and latitude on your icon is reversed in comparison to your view.. Also you'll probably have to use

ol.proj.transform(Longitude, Latitude fromProjection, toProjection) 

on the icon as well. (Not sure what your projection_lan and projection_lat is)

  • Added the projections and transformed the projection of the icon as well(@see first post)...still getting the same error :-( – user2463728 Oct 25 '14 at 8:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.