var mapcompLayerName = "{{mapcompLayerName}}";
var mapcompName = "{{mapcompName}}";
var latLongPropName = "{{latLongPropName}}";
var latLong2PropName = "{{latLong2PropName}}";
var scaleWithMapPropName = "{{scaleWithMapPropName}}";
var initialHeightNormalizeVal = {{initialHeightNormalizer}};
var mapcompTileSize = {{tileSize}};

var clipValue = function(n, min, max) {
    return Math.min(Math.max(n, min), max);
 }
 var LatLongToPixelXY = function(latitude, longitude, layersMaxZL) {
    latitude = clipValue(latitude, min_lat, max_lat);
    //longitude = clipValue(longitude, min_lng, max_lng);
    x = (longitude + 180) / 360;
    sinLatitude = Math.sin(latitude * Math.PI / 180);
    y = 0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI);
    mapSize = Math.abs({{tileSize}} << layersMaxZL);
    pixelX = clipValue(x * mapSize + 0.5, 0, mapSize - 1);
    pixelY = clipValue(y * mapSize + 0.5, 0, mapSize - 1);
    return [pixelX, pixelY];
 }
 //try {
    var min_lat = {{minLat}};
    var max_lat = {{maxLat}};
    //var min_lng = ' + String(TileUtils.min_lng) + ';
    //var max_lng = ' + String(TileUtils.max_lng) + ';
    var diffTime = thisComp.layer(mapcompLayerName).startTime;
    var pivotLayer = comp(mapcompName).layer("MapPivot");
    var pivotScale = pivotLayer.transform.scale.valueAtTime(time - diffTime);
    var effectCheckbox = false;
    try{effectCheckbox = effect(scaleWithMapPropName)("ADBE Checkbox Control-0001")}catch(err){}
    var effectLatLong = null;
    var output;
    try {
        effectLatLong = effect(latLongPropName)(1);
    } catch (e) {};
    var effectLatLong2 = null;
    try {
        effectLatLong2 = effect(latLong2PropName)(1);
    } catch (e) {};
    if (effectLatLong2 != null) {
        var geoPoint1 = effectLatLong.valueAtTime(time - diffTime);
        var geoPoint2 = effectLatLong2.valueAtTime(time - diffTime);;
        var pixelSizeAry = LatLongToPixelXY(geoPoint2[0], geoPoint2[1], Math.floor(pivotLayer.transform.opacity.value)) - LatLongToPixelXY(geoPoint1[0], geoPoint1[1], Math.floor(pivotLayer.transform.opacity.value));
        if(!thisLayer.sourceRectAtTime(time - diffTime)){
            var layerSizeAry = [thisLayer.source.width, thisLayer.source.height];
        }else{
            var layerSizeAry = [thisLayer.sourceRectAtTime(time - diffTime).width, thisLayer.sourceRectAtTime(time - diffTime).height];
        }
        var geoScale = [pixelSizeAry[0] / layerSizeAry[0] / thisComp.pixelAspect, pixelSizeAry[1] / layerSizeAry[1]];
        output = geoScale * pivotScale[1];
    } else {
        if (effectCheckbox == true) {
            output = {{scaleCalcString}}
            output[2] = output[1];
            output = output * mapcompTileSize / 256;
        } else {
            output = value;
        }
    }
    output
 //} catch (e) {
//    value;
 //}