index.js 4.43 KB
Newer Older
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
1 2 3 4 5
var map;
var List;

var markers = [];

6 7 8 9
$(function(){

    //init();
    
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
10 11
    init_maps();
    
12 13 14 15
    $.ajax({
        
        url: "list.php",
        success: function(response){
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
16 17

            List = response;
18
            parse_list(response);
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
19
            $(".arow")[0].click();
20 21 22 23 24 25 26 27 28
            
        }
        
    });
    
});

function parse_list(res){
    
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
29 30
    var index = 0;
    
31
    $(res).find("model").each(function(){
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
32

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
33
        var row = $("<tr class='arow'>");
34
        var name = $(this).attr("name");
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
35 36 37
        var thumb = $(this).attr("thumb");

        if (thumb.length!=""){
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
38
            row.append("<td class='acell' valign='top'><img alt='n/a' src='models/"+name+"/thumb.jpeg'></img></td>");
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
39
        }else{
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
40
            row.append("<td class='acell' valign='top' align='center'>&ndash;</td>");
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
41 42
        }

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
43
        row.append("<td class='acell' valign='top'>"+name+"</td>");
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
44

45
        var vlist = "";
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
46
        $(this).find("version").each(function(i,v){
47
            
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
48
            var comments = $(this).find("comments").text();
49
            
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
50 51
            var link_url = "test.html?path="+name+"&ver="+$(this).attr("name");
            var link = "<a title='"+comments+"' href='"+link_url+"'>"+$(this).attr("name")+"</a>,&nbsp;";
52
            
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
53 54
            vlist += link;

55 56
        });
        
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
57 58
        vlist = vlist.slice(0,-7);
        
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
59
        row.append("<td class='acell' valign='top'><div>"+vlist+"</div></td>");
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
60 61 62 63
        
        row.attr("index",index);
        
        register_row_events(row);
64 65 66
        
        $("#model_table").append(row);
        
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
        //place markers
        $(this).find("Camera").each(function(){
            
            var lat = $(this).find("latitude").text();
            var lng = $(this).find("longitude").text();
            
            if (markers[lat+lng]==undefined){

                var marker = L.marker([lat, lng]).addTo(map);
                marker.bindPopup(name+": "+vlist,{
                    direction:"top",
                });
            
                markers[lat+lng] = marker;
                
            }else{
                
                console.log(markers[lat+lng]);
                
                var content = markers[lat+lng]._popup.getContent();
                markers[lat+lng]._popup.setContent(content+"<br/>"+name+": "+vlist);

            }
            
        });
        
        
        index++;
95 96
    });
    
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
97 98 99
}

function register_row_events(elem){
100
    
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    $(elem).on("click",function(){

        $(".arow").css({
            background: "white"
        });
        //center map;
        $(this).css({
            background: "rgba(100,200,255,0.7)"
        });
        
        var index = $(this).attr("index");
        var list = $(List).find("model");
        var item = list[index];
        
        var lat = $($(item).find("latitude")[0]).text();
        var lng = $($(item).find("longitude")[0]).text();
        
        map.panTo(new L.LatLng(lat, lng));
        
120 121 122 123
        if (markers[lat+lng]!=undefined){
            markers[lat+lng].openPopup();
        }
        
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
124
    });
125 126
    
}
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158

// maps
function init_maps(){
  
  // https: also suppported.
  var Esri_WorldImagery = L.tileLayer(
    'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', 
    {
      maxZoom: 21,
      attribution: 'Tiles &copy; Esri &mdash; Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
    }
  );

  var googleSat = L.tileLayer(
    'https://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',
    {
      maxZoom: 21,
      attribution: 'Many thanks to Google for our happy childhood',
      subdomains:['mt0','mt1','mt2','mt3'],
    }
  );
  
  var OSMTiles = L.tileLayer('http://a.tile.openstreetmap.org/{z}/{x}/{y}.png', 
    {
      maxZoom: 21,
      attribution: 'Map data and images &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'
    }
  );
  
  map = L.map('leaflet_map',{
    layers:[googleSat],
    zoomControl:false,
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
159
  }).setView([40.7233861, -111.9328843], 12);
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179

  new L.Control.Zoom({ position: 'topright' }).addTo(map);
  
  var baseMaps = {
    "Esri world imagery": Esri_WorldImagery,
    "Google": googleSat,
    "Open Street Map": OSMTiles
  };
  
  //Esri_WorldImagery.addTo(map);
  //googleSat.addTo(map);
  
  //custom control:
  //http://www.coffeegnome.net/control-button-leaflet/
  
  L.control.layers(baseMaps).addTo(map);
  
}