Warning: Can't use blame annotator:
svn blame failed on trunk/webapps/cptms/js/calloutLayer.js: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/webapps/cptms/js/calloutLayer.js @ 557

Revision 557, 15.6 KB checked in by jdalbey, 6 years ago (diff)

Add crewcontact file to callout layer. Implements #231

RevLine 
1/* The Callout overlay is a map layer that shows areas of responsibility
2   for each Cal Trans maintenance crew.  A marker in each region can
3   be clicked to bring up an infoWindow showing the phone number for
4   the crew supervisor that can be used to "call the out" to an incident.
5    @author jdalbey 11/30/2019
6*/
7 
8// the list of polygons to draw on the google map
9var polygonList = [];
10// a list of markers that provide a clickable label for the region
11var markerList = []; 
12 
13// a list of infoWindows, one for each region
14var infowindows = [];
15// a list of crew contact info, one for each region
16// each item contains supervisor name, region number, phone number
17var crewcontact = {};
18
19// Initialize the layer by showing a control button and drawing polygons
20function initCalloutbutton()
21{
22    var calloutBtnDiv = document.getElementById('calloutButton');
23    map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(calloutBtnDiv)
24    calloutBtnDiv.title = 'Click to toggle Callout Overlay';
25
26    // Setup the click event listeners to toggle icon display
27    calloutBtnDiv.addEventListener('click', function()
28    {
29        callout_showing = !callout_showing;
30        // Determine which button image to show
31        if (callout_showing)
32        {
33            pic = "images/btnDepressed_Callout.png"
34            // It's nice when icons become visible that the messages have been refreshed.
35            showCalloutLayer();
36        }
37        else
38        {
39            pic = "images/btnReady_Callout.png"
40            hideCalloutLayer();
41        }
42        document.getElementById('calloutBtnImg').src = pic;
43
44    });
45
46    // Load the crew contact info from an external file
47    loadJSON("data_layers/crewcontact.json", function(response)
48    {
49        // Parse JSON string into object
50        contactjson = JSON.parse(response);
51        // Add each contact to a lookup dictionary
52        for (var i = 0; i < contactjson.length; i++)
53        {
54            var item = contactjson[i];
55            crewcontact[item.Region] = item;
56        }
57        // Go create the polygons (after JSON finishes loading)
58        initPolygons();
59    });
60
61}
62// Show the layer (the polygons and markers)
63function showCalloutLayer()
64{
65    // Iterate over the polygons, showing each one and its marker
66    for (var i = 0; i < polygonList.length; i++) 
67    {
68        polygonList[i].setMap(map);
69        markerList[i].setVisible(true);
70    }
71}
72// Hide the layer
73function hideCalloutLayer()
74{
75    // Iterate over the polygons, hiding each one and its marker
76    for (var i = 0; i < polygonList.length; i++) 
77    {
78        polygonList[i].setMap(null);
79        markerList[i].setVisible(false);
80        // force close any remaining open info windows.
81        infowindows[i].close();
82    }
83}
84
85// Create a list of polygons and markers, one for each region
86function initPolygons()
87{
88    // Define the LatLng coordinates for each polygon's path.
89    // The variable names indicate the region number.
90    var shape11 =
91    [ {lng: -117.975311279296889, lat: 33.861008021639982}, 
92    {lng: -117.952651977539077, lat: 33.847892766494965}, 
93    {lng: -117.919006347656264, lat: 33.825364042768278}, 
94    {lng: -117.89737701416017,  lat:33.806252750539684 },
95    {lng: -117.88089752197267,  lat:33.790846512234154 },
96    {lng: -117.863113397033885, lat: 33.775094261456935}, 
97    {lng: -117.863388061523452, lat: 33.775152122972564}, 
98    {lng: -117.841072082519545, lat: 33.750606041606453}, 
99    {lng: -117.786998748779311, lat: 33.75988300332898 },
100    {lng: -117.791461944580092, lat: 33.854379367213504},
101    {lng: -117.814357280731215, lat: 33.891097778879868},
102    {lng: -117.856521606445327, lat: 33.890937470812517}, 
103    {lng: -117.883301550216871, lat: 33.910970083273227},
104    {lng: -117.930404646322145, lat: 33.882270965115168}, 
105    {lng: -117.974766882184127, lat: 33.860836964317699}
106    ];
107    var shape10 =
108    [{lng: -117.747207654174431, lat: 33.920536243811434}, 
109    {lng: -117.679229748900994, lat: 33.877221436507959}, 
110    {lng: -117.615028393920525, lat: 33.805076310194131}, 
111    {lng: -117.614822387695327, lat: 33.804826363491607},   
112    {lng: -117.786955833435073, lat: 33.759847324630051},       
113    {lng: -117.791461944580092, lat: 33.854379367213504},
114    {lng: -117.814357280731215, lat: 33.891097778879868},
115    {lng: -117.764339447021499, lat: 33.891222462723938}
116    ];
117    var shape12 =
118    [{lng: -117.764339447021499, lat: 33.891222462723938}, 
119    {lng: -117.856521606445327, lat: 33.890937470812517}, 
120    {lng: -117.883301550216871, lat: 33.910970083273227},
121    {lng: -117.930404646322145, lat: 33.882270965115168}, 
122    {lng: -117.974766882184127, lat: 33.860836964317699}, 
123    {lng: -118.008272570572444, lat: 33.878396884046268}, 
124    {lng: -117.978057840373381, lat: 33.905120101626196}, 
125    {lng: -117.976684549357756, lat: 33.946142303526379},     
126    {lng: -117.785797098185881, lat: 33.948420735432244}, 
127    {lng: -117.746932979207486, lat: 33.921139882742345}, 
128    {lng: -117.761764526367202, lat: 33.894072329464144},
129    ]; 
130    var shape20 =
131    [{lng: -118.093414306640639, lat: 33.759454857961813}, 
132     {lng: -118.117721563903629, lat: 33.742268427950371},
133     {lng: -118.090530376648559, lat: 33.732750775701277}, 
134     {lng: -118.042465191101655, lat: 33.689912112406454}, 
135         {lng: -118.021865836344674, lat: 33.670982564442461}, 
136     {lng: -117.998451220337316, lat: 33.650978512026882}, 
137         {lng: -117.938095073914184, lat: 33.621039930103279 }, 
138     {lng: -117.934249886311591, lat: 33.619021253954152}, 
139     {lng: -117.929580684285639, lat: 33.623997562730807},
140     {lng: -117.93033599853517, lat: 33.623482118738629}, 
141     {lng: -117.989730834960952, lat: 33.730907010627263}, 
142     {lat: 33.7580276912933, lng: -118.0422592163086}
143    ];
144    var shape21 =
145    [{lng: -117.840900421142578, lat: 33.750606041606453}, 
146    {lng: -117.839355468750014, lat: 33.727052323290899}, 
147    {lng: -117.90836334228517, lat: 33.690067083222011}, 
148    {lng: -117.914886474609375, lat: 33.658067007354418}, 
149    {lng: -117.93033599853517, lat: 33.623482118738629}, 
150    {lng: -117.989730834960952, lat: 33.730907010627263},   
151    {lng: -118.042259216308594, lat: 33.7580276912933}, 
152    {lng: -118.093414306640639, lat: 33.759454857961813}, 
153    {lng: -118.096504211425795, lat: 33.782286292810255}, 
154    {lng: -118.075389862060561, lat: 33.810103876801179}, 
155    {lng: -118.028697967529311, lat: 33.809818614133711}, 
156    {lng: -118.029041290283217, lat: 33.792273132272697}, 
157    {lng: -118.011016845703139, lat: 33.792415792969067}, 
158    {lng: -118.011016845703139, lat: 33.776150942519855}, 
159    {lng: -117.921066284179702, lat: 33.775294812192321}, 
160    {lng: -117.920894622802749, lat: 33.78114486556651}, 
161    {lng: -117.869567871093764, lat: 33.780716826428275}
162    ];
163    var shape22 = 
164    [
165    {lng: -118.075561523437514, lat: 33.810175192319427}, 
166    {lng: -118.028697967529311, lat: 33.809818614133711}, 
167    {lng: -118.029041290283217, lat: 33.792273132272697}, 
168    {lng: -118.011016845703139, lat: 33.792415792969067}, 
169    {lng: -118.011016845703139, lat: 33.776150942519855}, 
170    {lng: -117.921066284179702, lat: 33.775294812192321}, 
171    {lng: -117.920894622802749, lat: 33.78114486556651}, 
172    {lng: -117.869567871093764, lat: 33.780716826428275},
173    {lng: -117.919006347656264, lat: 33.825364042768278},
174    {lng: -117.974766882184127, lat: 33.860836964317699},
175    {lng: -118.008132936665788, lat: 33.878581810221512},
176    {lng: -118.071647646138445, lat: 33.81556612720675 }   
177    ];
178    var shape32 =
179    [{lng: -117.896862030029311,  lat: 33.696065771651526}, 
180    {lng:  -117.754074130207314, lat: 33.669902002904237}, 
181    {lng:  -117.612934112548842, lat: 33.565857458017128}, 
182    {lng:  -117.413120269775405, lat: 33.6593529542764 },
183    {lng: -117.614822387695327, lat: 33.804826363491607}, 
184    {lng: -117.786955833435073, lat: 33.759847324630051},
185    {lng: -117.840900421142578, lat: 33.750606041606453},
186    {lng: -117.839355468750014, lat: 33.727052323290899}
187    ];
188    var shape31=
189    [{ lat: 33.565857458017128, lng:-117.612891197204604},
190    {lng:  -117.754074130207314, lat: 33.669902002904237},
191    {lng: -117.896862030029311,  lat: 33.696065771651526}, 
192    {lng: -117.90836334228517, lat: 33.690067083222011},
193    {lng: -117.914886474609375, lat: 33.658067007354418}, 
194    {lng: -117.93033599853517, lat: 33.623482118738629}, 
195    {lng: -117.934455871582045, lat: 33.619479664847653},
196        {lat: 33.607757123330948,  lng:-117.93067932128907}, 
197        {lat: 33.604039887039541, lng:-117.913169860839858}, 
198        {lat: 33.593173200549977, lng:-117.876434326171889}, 
199        {lat: 33.592887216626245, lng:-117.760391235351577 }, 
200        {lat: 33.543683878655926, lng:-117.673873901367202 }
201    ];
202    var shape30 = 
203    [   { lat: 33.54325465646098, lng: -117.6735305786133 },
204        { lat: 33.591528780040434, lng: -117.75961875915529 },
205        { lat: 33.592887216626245, lng: -117.87643432617189 },
206        { lat: 33.56642960408059, lng: -117.83231735229494 },
207        { lat: 33.55055114384406, lng: -117.80845642089844 },
208        { lat: 33.54096543541857, lng: -117.78442382812501 },
209        { lat: 33.51363317754275, lng: -117.76021957397462 },
210        { lat: 33.50690611436667, lng: -117.75112152099611 },
211        { lat: 33.499033355121824, lng: -117.7459716796875 },
212        { lat: 33.49216199827286, lng: -117.73773193359376 },
213        { lat: 33.47269019266666, lng: -117.71713256835939 },
214        { lat: 33.462379817843576, lng: -117.71163940429689 }, 
215        { lat: 33.46008845688024, lng: -117.67868041992189 },
216        { lat: 33.430008731182994, lng: -117.63336181640626 },
217        { lat: 33.38959955347486, lng: -117.59696960449219 },
218        { lat: 33.4520682165952, lng: -117.57843017578126 },
219        { lat: 33.4520682165952, lng: -117.54890441894533 },
220        { lat: 33.470971882039215, lng: -117.5090789794922 },
221        { lat: 33.53681606773302, lng: -117.50976562500001 },
222        { lat: 33.6593529542764, lng: -117.41294860839845 },
223        { lat: 33.54325465646098, lng: -117.6735305786133 }
224    ];
225
226    // An array of records that describe the attributes for each shape.
227    // polygon: the list of coordinates defining the shape
228    // id: the identifier for the shape (the crew number)
229    // color: color code to use for coloring the displayed polygon
230    // infoLocation: the coordinates of the center marker for the shape
231    // infoContent: the crew phone numbers to display in the infowindow
232    var shapeList = [
233    {
234        polygon: shape12,
235        id: '12',
236        color: '#fec28c', // orange
237        infoLocation: {
238            lat: 33.9105, //33.93025735136521,
239            lng: -117.9475  //-117.91213989257814
240        },
241        infoContent: crewcontact["12"].Supervisor + " " + crewcontact["12"].Phone
242    }, 
243    {
244        polygon: shape11,
245        id: '11',
246        color: '#f9f385', // yellow
247        infoLocation: {
248            lat: 33.8600, //33.8247936182649,
249            lng: -117.8545  //-117.85858154296876
250        }, 
251        infoContent: crewcontact["11"].Supervisor + " " + crewcontact["11"].Phone
252    }, 
253    {
254        polygon: shape10,
255        id: '10',
256        color: '#cf7b71', // rust
257        infoLocation: {
258            lat: 33.82251188219802,
259            lng: -117.69790649414064
260        },
261        infoContent: crewcontact["10"].Supervisor + " " + crewcontact["10"].Phone
262    }, 
263    {
264        polygon: shape22,
265        id: '22',
266        color: '#aae2ef',  // light-blue
267        infoLocation: {
268            lat: 33.82251188219802,
269            lng: -117.9986572265625
270        },
271        infoContent: crewcontact["22"].Supervisor + " " + crewcontact["22"].Phone
272    }, 
273    {
274        polygon: shape21,
275        id: '21',
276        color: '#d9bedd', // purple
277        infoLocation: {
278            lat: 33.720913019358676,
279            lng: -117.92999267578126
280        }, 
281        infoContent: crewcontact["21"].Supervisor + " " + crewcontact["21"].Phone
282    }, 
283    {
284        polygon: shape20,
285        id: '20',
286        color: '#aebed7',  // blue-gray
287        infoLocation: {
288            lat: 33.723197462817026,
289            lng: -118.03573608398439
290        }, 
291        infoContent: crewcontact["20"].Supervisor + " " + crewcontact["20"].Phone
292    }, 
293    {
294        polygon: shape32,
295        id: '32',
296        color: '#c4d9ae',  // leaf-green
297        infoLocation: {
298            lat: 33.72205524868731,
299            lng: -117.68829345703126
300        },
301        infoContent: crewcontact["32"].Supervisor + " " + crewcontact["32"].Phone
302    }, 
303    {
304        polygon: shape31,
305        id: '31',
306        color: '#d7f885', // neon green
307        infoLocation: {
308            lat: 33.637489243170826,
309            lng: -117.80364990234376
310        },
311        infoContent: crewcontact["31"].Supervisor + " " + crewcontact["31"].Phone
312    }, 
313    {
314        polygon: shape30,
315        id: '30',
316        color: '#a4b082',  //olive
317        infoLocation: {
318            lat: 33.5397,  //33.4979,
319            lng: -117.5805  //-117.5784
320        },
321        infoContent: crewcontact["30"].Supervisor + " " + crewcontact["30"].Phone
322    }, 
323    ];
324
325    // Iterate over the shapes, creating a polygon for each one
326    for (var i = 0; i < shapeList.length; i++) 
327    {
328        // Construct the polygon.
329            polygonList[i] = new google.maps.Polygon({
330            paths: shapeList[i].polygon,
331            strokeColor: shapeList[i].color,
332            strokeOpacity: 0.8,
333            strokeWeight: 2,
334            fillColor: shapeList[i].color,
335            fillOpacity: 0.5
336        });
337
338        // Construct the content of the info window for this region
339        var contentString = '<div id="content">' +
340            '<div id="siteNotice">' +
341            '</div>' +
342            '<h1 id="firstHeading" class="firstHeading">' + shapeList[i].id + '</h1>' +
343            '<div id="bodyContent">' +
344            '<p><b>' + shapeList[i].infoContent + '</p>' +
345            '</div>' +
346            '</div>';
347
348        // Construct the info window for this region
349        infowindows[i] = new google.maps.InfoWindow({
350            content: contentString
351        });
352
353        // create the marker that will appear in the center of the region
354        markerList[i] = new google.maps.Marker({
355            position: shapeList[i].infoLocation, // where to place the marker
356            map: map, // the map to be drawn on
357            title: shapeList[i].id, // Maintenance Crew Number
358            icon: 'images/region.png', // the marker image
359            label: {
360                text: shapeList[i].id,  // region label
361                color: '#FFFFFF', // white for text
362                fontSize: '16px'  // a readable size
363            }
364        });
365        // Initially the marker is hidden
366        markerList[i].setVisible(false);
367    }; // end for
368
369    // Construct the click listeners for each info window
370    // it seems these can't be done in a loop because the loop index
371    // isn't known when the click happens.
372    markerList[0].addListener('click', function() {
373        infowindows[0].open(map, markerList[0]);
374    });
375    markerList[1].addListener('click', function() {
376        infowindows[1].open(map, markerList[1]);
377    });
378    markerList[2].addListener('click', function() {
379        infowindows[2].open(map, markerList[2]);
380    });
381    markerList[3].addListener('click', function() {
382        infowindows[3].open(map, markerList[3]);
383    });
384    markerList[4].addListener('click', function() {
385        infowindows[4].open(map, markerList[4]);
386    });
387    markerList[5].addListener('click', function() {
388        infowindows[5].open(map, markerList[5]);
389    });
390    markerList[6].addListener('click', function() {
391        infowindows[6].open(map, markerList[6]);
392    });
393    markerList[7].addListener('click', function() {
394        infowindows[7].open(map, markerList[7]);
395    });
396    markerList[8].addListener('click', function() {
397        infowindows[8].open(map, markerList[8]);
398    });
399}
Note: See TracBrowser for help on using the repository browser.