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

Revision 539, 14.7 KB checked in by jdalbey, 6 years ago (diff)

calloutLayer.js Move maker locations for 11, 12, 30 to better spot.

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