| 1 | /** |
|---|
| 2 | * index.js |
|---|
| 3 | */ |
|---|
| 4 | |
|---|
| 5 | // a global variable for the google map |
|---|
| 6 | var map; |
|---|
| 7 | // Constant for map center location in District 12 |
|---|
| 8 | var centerPoint = { |
|---|
| 9 | lat: 33.693385, |
|---|
| 10 | lng: -117.798937 |
|---|
| 11 | }; |
|---|
| 12 | |
|---|
| 13 | // Initial map zoom |
|---|
| 14 | var initZoom = 11; |
|---|
| 15 | // Dot colors used in traffic model to indicate free-flowing, slowed, and stopped traffic |
|---|
| 16 | // and their associated zvalues so slower traffic dots are more visible. |
|---|
| 17 | // white means a disabled spot |
|---|
| 18 | var colorZvalues = { |
|---|
| 19 | "white": 5, |
|---|
| 20 | "lime": 10, |
|---|
| 21 | "yellow": 20, |
|---|
| 22 | "red": 30 |
|---|
| 23 | }; |
|---|
| 24 | // Constant name of initial (static) highways file used once at startup |
|---|
| 25 | var kVDSStartupFile = "highways_startup.json"; |
|---|
| 26 | //var circle = google.maps.SymbolPath.CIRCLE; |
|---|
| 27 | |
|---|
| 28 | // Build a solid colored icon to use instead of the classic pin |
|---|
| 29 | function dotSymbol(color) |
|---|
| 30 | { |
|---|
| 31 | var circle = google.maps.SymbolPath.CIRCLE; |
|---|
| 32 | var diamond = 'M -1,0 0,-1 1,0 0,1 z'; |
|---|
| 33 | return { |
|---|
| 34 | path: circle, |
|---|
| 35 | scale: 5, |
|---|
| 36 | strokeColor: "black", // the border color |
|---|
| 37 | strokeWeight: 1, // the border thickness |
|---|
| 38 | fillColor: color, |
|---|
| 39 | fillOpacity: 1.0 |
|---|
| 40 | }; |
|---|
| 41 | } |
|---|
| 42 | /*var myCircleIcon = { |
|---|
| 43 | path: circle, |
|---|
| 44 | scale: 5, |
|---|
| 45 | strokeColor: "black", // the border color |
|---|
| 46 | strokeWeight: 1, // the border thickness |
|---|
| 47 | fillColor: "lime", |
|---|
| 48 | fillOpacity: 1.0 |
|---|
| 49 | }; |
|---|
| 50 | */ |
|---|
| 51 | function initMap() |
|---|
| 52 | { |
|---|
| 53 | // Declare the map and where it belongs on the page |
|---|
| 54 | map = new google.maps.Map(document.getElementById('mapdiv'), |
|---|
| 55 | { |
|---|
| 56 | zoom: initZoom, |
|---|
| 57 | center: centerPoint, |
|---|
| 58 | styles: night_mode, |
|---|
| 59 | mapTypeControl: false, |
|---|
| 60 | streetViewControl: false |
|---|
| 61 | }); |
|---|
| 62 | loadMarkers(); |
|---|
| 63 | loadCCTV(); |
|---|
| 64 | map.data.addListener('click', function(event) |
|---|
| 65 | { |
|---|
| 66 | // console.log("map data layer was clicked"); |
|---|
| 67 | alert("hey"); |
|---|
| 68 | }); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | function loadMap() |
|---|
| 72 | { |
|---|
| 73 | map.data.loadGeoJson(kVDSStartupFile); |
|---|
| 74 | |
|---|
| 75 | // Style the map data by applying the desired properties to each feature (marker) |
|---|
| 76 | // The function will be called every time a feature's properties are updated. |
|---|
| 77 | map.data.setStyle(function(feature) |
|---|
| 78 | { |
|---|
| 79 | // Get the postmile id |
|---|
| 80 | var name = feature.getId(); |
|---|
| 81 | // Get the desired color value |
|---|
| 82 | var ptColor = feature.getProperty("color"); |
|---|
| 83 | var street = feature.getProperty("street"); |
|---|
| 84 | // Build the marker |
|---|
| 85 | //var iconSymbol = dotSymbol(ptColor); |
|---|
| 86 | // return the StyleOptions |
|---|
| 87 | return { |
|---|
| 88 | icon: dotSymbol(ptColor), |
|---|
| 89 | title: name + " @" + street, // set rollover text |
|---|
| 90 | // set zIndex for slowed traffic to a higher value so they overlap |
|---|
| 91 | zIndex: colorZvalues[ptColor] |
|---|
| 92 | }; |
|---|
| 93 | }); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | var vds_info; |
|---|
| 97 | var vdsList = []; |
|---|
| 98 | |
|---|
| 99 | function loadMarkers() |
|---|
| 100 | { |
|---|
| 101 | loadJSON(kVDSStartupFile, function(response) |
|---|
| 102 | { |
|---|
| 103 | // Parse JSON string into object |
|---|
| 104 | vds_info = JSON.parse(response); |
|---|
| 105 | // Process each new marker |
|---|
| 106 | for (var idx in vds_info.features) |
|---|
| 107 | { |
|---|
| 108 | var vds_item = vds_info.features[idx]; |
|---|
| 109 | var name = vds_item.id; |
|---|
| 110 | var currLat = Number(vds_item.geometry.coordinates[1]); |
|---|
| 111 | var currLong = Number(vds_item.geometry.coordinates[0]); |
|---|
| 112 | //console.log(currLong, currLat); |
|---|
| 113 | vdsList[name] = new google.maps.Marker( |
|---|
| 114 | { |
|---|
| 115 | position: |
|---|
| 116 | { |
|---|
| 117 | lat: currLat, |
|---|
| 118 | lng: currLong |
|---|
| 119 | }, |
|---|
| 120 | map: map, |
|---|
| 121 | icon: |
|---|
| 122 | { |
|---|
| 123 | url: 'images/circle-12.png', |
|---|
| 124 | anchor: new google.maps.Point(6, 6) |
|---|
| 125 | }, |
|---|
| 126 | title: name |
|---|
| 127 | }); |
|---|
| 128 | vdsList[name].setVisible(true); |
|---|
| 129 | } |
|---|
| 130 | }); |
|---|
| 131 | } |
|---|
| 132 | var cctvIcon = "images/CPTMSImages/icon_cctvCyan.png"; |
|---|
| 133 | |
|---|
| 134 | function loadCCTV() |
|---|
| 135 | { |
|---|
| 136 | cctvLayer = new google.maps.Data(); |
|---|
| 137 | cctv_infowindow = new google.maps.InfoWindow(); |
|---|
| 138 | console.log("building cctvlayer"); |
|---|
| 139 | cctvLayer.loadGeoJson("cctv_locations_D12.gjson"); |
|---|
| 140 | cctvLayer.setStyle(function(feature) |
|---|
| 141 | { |
|---|
| 142 | // return the StyleOptions |
|---|
| 143 | return { |
|---|
| 144 | icon: dotSymbol("yellow"), |
|---|
| 145 | visible: false |
|---|
| 146 | }; |
|---|
| 147 | }); |
|---|
| 148 | cctvLayer.addListener('click', function(event) |
|---|
| 149 | { |
|---|
| 150 | console.log("cctv layer was clicked at " + event.feature.getId()); |
|---|
| 151 | cctv_infowindow.setContent("Hello World"); |
|---|
| 152 | cctv_infowindow.setPosition(centerPoint); |
|---|
| 153 | cctv_infowindow.open(map); |
|---|
| 154 | }); |
|---|
| 155 | cctvLayer.setMap(map); |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | map.addListener('zoom_changed', function() |
|---|
| 159 | { |
|---|
| 160 | cctvLayer.forEach(function(feature) |
|---|
| 161 | { |
|---|
| 162 | cctvLayer.overrideStyle(feature, |
|---|
| 163 | { |
|---|
| 164 | visible: true |
|---|
| 165 | }); |
|---|
| 166 | }); |
|---|
| 167 | }); |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | |
|---|