﻿//***********************Municipalidad de San Isidro************************//
// MapTools
//***********************Municipalidad de San Isidro************************//

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function RefrescarIncidente(){
    //alert('1');
    var mapa = window.opener.parent.frames['ifGIS'].document.map; //parent.window.opener.top.frames['mapa'].document.map;

    var lay_Incidentes = mapa.getMapLayer("lay_Incidentes");
    lay_Incidentes.setRebuild(true);
    mapa.setAutoRefresh(true);
	mapa.refresh();
	//alert('2');
}

var secs
var timerID = null
var timerRunning = false
var delay = 3000
var obj_map = null

function InitializeTimer(map)
{
    obj_map = map;
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function localizaLote(){
    
    frm = parent.document.forms[0]
    var CodLote = frm.hfCodLote.value
    
    var map = obj_map; //getMyMap(1);
    
    if (!map.isBusy())
    {
        map.zoomGotoLocation("zoomUbicacionLote",CodLote,4.3);
        
        var lay_marca = map.getMapLayer("lay_lotesBusq");
        lay_marca.setSQLWhere("FEATURE_ID = '"+CodLote+"'");

        map.zoomWidth(map.getLat(), map.getLon(),0.200,"MI");
        
        //ubicaLote(CodLote);
        StopTheClock();
    }else{
        timerID = self.setTimeout("localizaLote()", delay)
    }
}

function StartTheTimer()
{
    frm = parent.document.forms[0]
    var CodLote = frm.hfCodLote.value
    if(CodLote!=""){
        timerRunning = true
        timerID = self.setTimeout("localizaLote()", delay)
    }
}



var zoom = true;
legendSet = false

function onDoubleClickObject(map)
{ 
    if( (map.getMapLayer().getName())=='lay_lotes' || (map.getMapLayer().getName())=='lay_lotesBusq' ){
        var CodLote=ObtenerCodigo();
        
        if(CodLote!=null)
        {
            var features = 
            "height=600,"
            +"left=0,"
            +"resizable=yes,"
            +"scrollbars=yes,"
            +"status=yes,"
            +"titlebar=no,"
            +"toolbar=no,"
            +"top=0,"
            +"width=800";
            var oNewWindow = window.open( "../../DetalleGIS/frmParametroUrbanistico.aspx?codlote=" + CodLote,"frmParametroUrbanistico",features);
            oNewWindow.focus();
        
        /*if(CodLote!=null)
        {
            var features = 
            "height=550,"
            +"left=0,"
            +"resizable=yes,"
            +"scrollbars=yes,"
            +"status=yes,"
            +"titlebar=no,"
            +"toolbar=no,"
            +"top=0,"
            +"width=700";
            var oNewWindow = window.open( "../../Informacion/frmLote.aspx?CodLote=" + CodLote,"frmLote",features)
            oNewWindow.focus();
        */
            /*
            var mapa = top.frames['mapa'].document.map;
            mapa.zoomGotoLocation("ubi_lote",id,4.3);

            var lay_marca = mapa.getMapLayer("lay_lote_borde");
            sql_where_marca = lay_marca.getSQLWhere();
            lay_marca.setSQLWhere("FEATURE_ID = '"+id+"'");
            mapa.zoomWidth(mapa.getLat(), mapa.getLon(),0.200,"MI");
            */
            /*var features = 
	               "height=575,"
	               +"left=0,"
	               +"resizable=no,"
	               +"scrollbars=no,"
	               +"status=no,"
	               +"titlebar=no,"
	               +"toolbar=no,"
	               +"top=0,"
	               +"width=675";

            var oNewWindow = window.open("../../Informacion/frmLote.aspx?CodLote="+CodLote ,"frmLote",features)
            oNewWindow.focus();*/
        }
    }
    else if((map.getMapLayer().getName())=='lay_SectorParticipacionVecinalPrincipal'){
        /*var CodSectorVecinal = map.getkey();
        
        var features = 
	       "height=600,"
	       +"left=0,"
	       +"resizable=yes,"
	       +"scrollbars=yes,"
	       +"status=no,"
	       +"titlebar=no,"
	       +"toolbar=no,"
	       +"top=0,"
	       +"width=800";

        var oNewWindow = window.open("../../Estadisticas/frmCasoVia.aspx?CodSectorVecinal="+CodSectorVecinal ,"frmCasoVia",features)
        oNewWindow.focus();*/
    }
    else if((map.getMapLayer().getName())=='lay_SectorParticipacionVecinal'){
        /*var CodSubSectorVecinal = map.getkey();
        
        var features = 
	       "height=600,"
	       +"left=0,"
	       +"resizable=yes,"
	       +"scrollbars=yes,"
	       +"status=no,"
	       +"titlebar=no,"
	       +"toolbar=no,"
	       +"top=0,"
	       +"width=800";

        var oNewWindow = window.open("../../Estadisticas/frmCasoVia.aspx?CodSectorVecinal="+CodSubSectorVecinal ,"frmCasoVia",features)
        oNewWindow.focus();*/
    }
    else if((map.getMapLayer().getName())=='lay_Incidentes'){
        /*var CodCaso = map.getkey();
        var features = 
   		       "height=500,"
   		       +"left=0,"
   		       +"resizable=no,"
   		       +"scrollbars=yes,"
   		       +"status=no,"
   		       +"titlebar=no,"
   		       +"toolbar=no,"
   		       +"top=0,"
   		       +"width=450";
            var oNewWindow = window.open("../../Procesos/frmCasoConsulta.aspx?CodCaso="+CodCaso,"frmCasoConsulta",features)
            oNewWindow.focus();*/
    }
    else if(
        (map.getMapLayer().getName())=='lay_LugarInteresAlimentacion'
        || (map.getMapLayer().getName())=='lay_LugarInteresAlojamiento'
        || (map.getMapLayer().getName())=='lay_LugarInteresCultura'
        || (map.getMapLayer().getName())=='lay_LugarInteresRecreacion'
        || (map.getMapLayer().getName())=='lay_LugarInteresEntretenimiento'
        || (map.getMapLayer().getName())=='lay_LugarInteresComercio'
        || (map.getMapLayer().getName())=='lay_LugarInteresEntidadesFinancieras'
        || (map.getMapLayer().getName())=='lay_LugarInteresCentrosReligiosos'
        || (map.getMapLayer().getName())=='lay_LugarInteresServicios'
        || (map.getMapLayer().getName())=='lay_LugarInteresEducacion'
        || (map.getMapLayer().getName())=='lay_LugarInteresSalud'
        || (map.getMapLayer().getName())=='lay_LugarInteresInstituciones'
        || (map.getMapLayer().getName())=='lay_LugarInteresGobiernoNacional'
        || (map.getMapLayer().getName())=='lay_LugarInteresGobiernoExtranjero')
    {
        var CodLugarInteres = map.getkey();
        var features = "height=400,"
            +"left=0,"
            +"resizable=no,"
            +"scrollbars=no,"
            +"status=yes,"
            +"titlebar=no,"
            +"toolbar=no,"
            +"top=0,"
            +"width=450";
            var oNewWindow = window.open("../../Informacion/frmLugarInteresDetalle.aspx?CodLugarInteres="+CodLugarInteres,"frmLugarInteres",features)
            oNewWindow.focus();
    }
}


function onAddMapLayer(url,layer){
}

function onMapLoaded(map){

    var pnlCargandoMapa = parent.document.getElementById("pnlCargandoMapa");
    if(!map.isBusy()){
        var p = map.zoomWidth(-12.095915,-77.034809, 4,'MI');
        
        pnlCargandoMapa.style.visibility = "visible";
        pnlCargandoMapa.style.display = "block";
    }
    else{
        pnlCargandoMapa.style.visibility = "hidden";
        pnlCargandoMapa.style.display = "none";
    }
    
    InitializeTimer(map);
}

function onSelectionChanged(map,app){
    var f = document.forms[0];
    /*
    var flag =  f.OnSelectionChangedReport.value;
    if(flag==1){
       if(app="SGC"){
           var selected = map.getSelection();
           var numSelectedObjects = selected.getNumObjects();
           var mapObjects = selected.getMapObjectsEx(null);
           for (var i = 0; i < mapObjects.size(); i++){
   		        var layerName = mapObjects.item(i).getMapLayer().getName();
   		        var key = mapObjects.item(i).getKey()
   		        if(layerName=="lay_lotes"){
   		            var features = 
   		               "height=700,"
   		               +"left=0,"
   		               +"resizable=no,"
   		               +"scrollbars=yes,"
   		               +"status=no,"
   		               +"titlebar=no,"
   		               +"toolbar=no,"
   		               +"top=0,"
   		               +"width=450";
   		            var lat = map.getLat();
   		            var lon = map.getLon();
                    //var oNewWindow = window.open( "../../Busqueda/frmConsultaLote.aspx?key="+key+"&lat="+lat+"&lon="+lon,"inf_lote",features)
                    //oNewWindow.focus();
   		        }
           }
       } 
    }
    */
}


function onViewChanged(map){
    if(zoom){
        var p = map.zoomWidth(-12.095915,-77.034809, 4,'MI')
        zoom=false;
    }

//**************************************************
//COLOCA EN EL MAPA EL SYMBOLO DE CATASTRO INTEGRAL
//**************************************************

    var pnlCargandoMapa = parent.document.getElementById("pnlCargandoMapa");
    
    if(getMyMap(1).isBusy()) 
    { 
        var wait=1;
        
        pnlCargandoMapa.style.visibility = "visible";
        pnlCargandoMapa.style.display = "block";
    }
    else {
        pnlCargandoMapa.style.visibility = "hidden";
        pnlCargandoMapa.style.display = "none";
         
        var theExtents=map.getMapExtent(true,true);
        var myLayer = map.getMapLayer("Redline");
        var myRedline = map.getRedlineSetup();
        var mySymbol = myRedline.getSymbolAttr();
        //mySymbol.setSymbol("catastro integral");
        mySymbol.setSymbol("PCARDINALES");

        if (myLayer == null)
        myLayer = map.createLayer("redline", "Redline");

    // create logo point object, or get it if it already exists
        myLayer.removeAllObjects();
        myLayer.setShowInLegend(false);
        myLayer.setPriority(100);
        var obj = myLayer.getMapObject("temp");
        if (obj == null)
        var obj = myLayer.createMapObject("temp", "", "");

        // grab the map extents and set the point position 
        var logoPoint = map.createObject("MGPoint");
        var Difflat=(theExtents.getMaxX()-theExtents.getMinX());
        var Difflon=(theExtents.getMaxY()-theExtents.getMinY());

    //PARA EL LOGO NORTE ESQUINA SUPERIOR IZAQUIERDA
        var positionLat=theExtents.getMaxX()-(Difflat/1.08);
        var positionLon=theExtents.getMinY()+(Difflon/1.12);

    //alert("Latx:" +positionLat+"Lony:"+positionLon)

        logoPoint.setX(positionLat);
        logoPoint.setY(positionLon);

    //PARA EL LOGO DE CATASTO INTEGRAL
    //mySymbol.setWidth(Difflat/3.2,"M");
    //mySymbol.setHeight(Difflat/52,"M");
    //PARA EL LOGO DEL NORTE 
        mySymbol.setWidth(Difflat/6.5,"M");
        mySymbol.setHeight(Difflat/6.5,"M");

    // add the symbol object 
        obj.addSymbolPrimitive(logoPoint, true);
        map.setAutoRefresh(true);
    }

}
function acercar_lote(map){
    map.zoomWidth(map.getLat(), map.getLon(), 0.100,"MI");
}
function showObjectCount(map)
{
    if (legendSet)
        return;
    if (!map.isBusy())
    {
        var layers = map.getMapLayersEx();
        var cnt = layers.size();
        var i;
        var msg = "";
        for (i = 0; i<cnt; i++)
        {
            var layer = layers.item(i);
        }
    }
    legendSet = true;
}