JavaScript Constructor is not a constructor error

0

I have a constructor and I wanted to create an object from it. But, 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
        }),
    });
    
asked by anonymous 06.04.2018 / 22:37

1 answer

0

Only return:

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
    }),
});
    
07.04.2018 / 23:20