summaryrefslogtreecommitdiffstats
path: root/usecaseui-common/src/main/webapp/app/fusion/external/gis/js/local.js
blob: 5f4208a8492013848db25231f5391282f3078ccd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
var pointLayer= null;
var animateFlag = false;
var frame = 0;
var dates = [];
var delay = 1000;
var intervalId = null;
$( document ).ready(function() {
    map(data2.map.lat,data2.map.lon,data2.map.zoom);
    pointLayer = new L.layerGroup().addTo(map);
    var point = getDates(data2.points);
    drawPoints(data2,point);
    
    
    $('#timeUp').bind('click',function(){
        delay += 500; 
        if ( animateFlag ) {
           clearInterval(intervalId);
           intervalId = window.setInterval(function(){animate(data2);},delay);
        }
    });
    $('#timeDown').bind('click',function(){
        if ( delay === 500 ) { return false; }
        delay -= 500; 
        if ( animateFlag ) {
            clearInterval(intervalId);
           intervalId = window.setInterval(function(){animate(data2);},delay);
        }
    });
    
    
    $('#date').bind('change',function(){
        drawPoints(data2,$('#date').val());
    });
    $('#animate').bind('click',function(){
        if ( animateFlag ) {
            animateFlag = false; 
            $('#animate_color').html('Off');
            $('#animate_color').removeClass('animateOn');
            $('#animate_color').addClass('animateOff');
            clearInterval(intervalId);
        } else {
            animateFlag = true;
            $('#animate_color').html('On');
            $('#animate_color').removeClass('animateOff');
            $('#animate_color').addClass('animateOn');
            intervalId = window.setInterval(function(){animate(data2);},delay);
        }
    });

    
});

function abc() {
	var abc = 1;
	var xyz = "";
	return nul;
	
}



function animate(obj){
    var point =  dates[frame];
    drawPoints(obj,point);
    frame++;
    if ( frame >= dates.length ) {
        frame = 0;
    }
    $('#currDate').val(point);
    $('#showDelay').html(delay);
}

function someFunction() {
	
	var self = this;
	var x = 1;
	var z = self + x;
}


/**
* drawPoints - Draw the points provided by point(date)     
* obj JSON Object - Data for Map
* p String - Key (date) from the JSON object. 
*/
function drawPoints(obj,p){
    pointLayer.clearLayers();
    var lats = obj.points[p].lats;
    var lons = obj.points[p].lons;
    var txt = obj.points[p].text;
    var fills = obj.points[p].colors;
    points(lats, lons,txt,fills);
}

/**
* Get dates from the list provided in pIn and put them in Select.
* then return the fist date.
*
*/
function getDates(pIn) {
    var html = "<option value='na'>--Select--</option>";
    var c = 0;
    var ret = 0;
    for (var d in pIn ) {
        var val = d.replace('"','');
        if ( c === 0 ) { ret = val;};
        html += "<option value='" + d + "'>" + d + "</option>";   
        dates[c] = val;
        c++;
    }
    $('#date').html(html);
    return ret;
}

/**
* Map - pass argumets to build map as specified Lat/Lon and zoom level
* String lat - Latitude
* String lon - Longitude 
* String zoom - Zoom Level (1-18)
*
*/
function map(lat,lon,zoom){ 
    var map = L.map('map').setView([lat,lon],zoom);
    map.addControl(new L.control.scale());
    L.tileLayer('http://localhost/tiles-light/{z}/{x}/{y}.png', {maxZoom:18}).addTo(map);
    window.L=L;
    window.map=map;
}

/**
* points - pass argumets to points specified Lat/Lon. Text and color for point is also passed. 
* Input is either all singe values or all arrays. 
* String[] lat - Latitude
* String[] lon - Longitude 
* String[] text - Single/Array of Text for points
* String[] fill - Single/Array of Fill colors.
*/
function points(lat,lon,text,fill){
    if(lat.length) {
        for(i=0;i<lat.length;i++) {
            pointLayer.addLayer(L.circleMarker([lat[i], lon[i]], { 
                radius:"5", 
                color: fill[i], 
                fillColor: fill[i], 
                fillOpacity: "0.5" }).bindPopup(text[i]));

            /*
            L.circleMarker([lat[i], lon[i]], { 
                radius:"5", 
                color: fill[i], 
                fillColor: fill[i], 
                fillOpacity: "0.5" }).addTo(map).bindPopup(text[i]);

            */
        
        }
        
    } else {
        L.circleMarker([lat, lon], { 
            radius:"5", 
            color:fill, 
            fillColor:fill, 
            fillOpacity: "0.5" 
        }).addTo(map).bindPopup(text);
    }
}

/**
*  Get data from json file and creat return an object of data. 
* Returns json object. 
*
**/
function getData(){
    $.getJSON( "./data.json", function( data ) {
        return data;
    });
    
}