main.js 1.16 KB
var canvas = $('canvas').attr({'width' : 1200, 'height' : 500}).css('border', '1px solid black');
var context = canvas.get(0).getContext('2d');

var model = {
    width : 0,
    height : 0,
    point : {
        x : 0,
        y : 0
    }
};

var select = $('#ukr_seeds');
select.change(getParams);

getParams();

function getParams()
{
    $.ajax({
        url: location.href + '/get-params',
        data: {
            'crop_id': select.val()
        },
        type: 'GET',
        dataType: 'json',
        success: function(data) {
            model.width = data.body.WIDTH;
            model.height = data.body.HEIGHT;
            model.point.x = data.body.X;
            model.point.y = data.body.Y;
            canvas.attr({'width' : model.width + 20, 'height' : model.height + 20});
            context.clearRect(0, 0, canvas.width, canvas.height);
            console.log(model);
        }
    });
}

function draw()
{
    var image = $('img').get(0);
    context.clearRect(0, 0, canvas.width, canvas.height);
    context.drawImage(image, model.point.x, model.point.y, model.width, model.height, 10, 10, model.width, model.height);
    console.log( image.width, image.height );
}