1

I made a function to zoom to polygon geom if I click the button. This is my script:

$.ajax({
            type: "POST",
            url: 'core/zoomtolocation',
            data: {
                iddesa: iddesa,
            },
            dataType: "JSON",
            success: function (responsezoom) {
                if (responsezoom!='kosong') {

                    $.each(responsezoom, function (index, value) { 

                        var extent = [value.geom];
                        map.getView().fitExtent(extent,map.getSize())

                        // var maxExtent = [parseFloat(value.xmax), parseFloat(value.ymax), parseFloat(value.xmin), parseFloat(value.ymin)];
                        // map.getView().fit(maxExtent, { duration: 1000 });
                    });

                } else {

                }
            }
        });

But from that script I get error:

Uncaught TypeError: map.getView is not a function.

I'm using OpenLayers 4.

  • There is no .fitExtent() method, .fit() is used for both geometry and extents. An extent is defined as [xmin, ymin, xmax, ymax]. An OpenLayers geometry is passed directly, not inside an array. – Mike Nov 5 '19 at 20:43

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.