Javascript Constructor x is not a constructor error

Asked

Viewed 456 times

0

I have a constructor and I wanted to create an object from it. But, ta giving Uncaught Typeerror: Map is not a constructor.

I just wanted to know why?

var mapa = null;

    var Map = (function (ol, $) {

        function Map(paramsMap) {
            this.layers = {};
            this.overlayes = {};
            this.olMap = new ol.Map(paramsMap);
        }

        Map.prototype.getResolution = function () {
            return this.olMap.getView().getResolution();
        }

    })(ol, jQuery);

    mapa = new Map({
        target: 'map',
        view: new ol.View({
            center: ol.proj.transform([-51.1, -12.0], 'EPSG:4326', 'EPSG:3857'),
            zoom: 6,
            minZoom: 4,
            maxZoom: 19
        }),
    });

  • Write your question in Portuguese, vc está no PT Stackoverflow.

1 answer

0


Only the Return was missing:

var mapa = null;

var Map = (function (ol, $) {

    function Map(paramsMap) {
        this.layers = {};
        this.overlayes = {};
        this.olMap = new ol.Map(paramsMap);
    }

    Map.prototype.getResolution = function () {
        return this.olMap.getView().getResolution();
    }

    //retorno da função
    return Map;

})(ol, jQuery);

mapa = new Map({
    target: 'map',
    view: new ol.View({
        center: ol.proj.transform([-51.1, -12.0], 'EPSG:4326', 'EPSG:3857'),
        zoom: 6,
        minZoom: 4,
        maxZoom: 19
    }),
});
  • Aaaaaah, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.