Regarding finding clinched segments for a user from the DB so they can be colored differently on maps: I decided that rather than sending an email about this to SSOWorld, I'd post here in case it's useful to others. I'm also very open to suggestions about better ways to do this.
In
https://github.com/TravelMapping/Web/blob/master/hbtest/mapview.php, it's the code from lines 196 to 234 that's using SQL query results to build the JS arrays that are used for this.
The first part builds an array of waypoints, with the waypoint labels and coordinates that exist in the systems or regions being mapped. Along the way, a second array called newRouteIndices keeps track of the first index into the waypoints array for each route. There are also arrays built there that track the tier and color for each of those routes.
The second part builds an array of segments by "segmentID" which is just a unique identifier for each segment from the DB. The key here is that these segments come out of the DB in the same order as the waypoints. So if the first route being plotted has, say, 27 waypoints, the first 26 segments in the segments array are the 26 segments connecting those 27 waypoints. Then the next route has 11 waypoints, so the next 10 segments entries connect those 11 waypoints, and so on. So even though we only get segmentID out of the DB and save only that number in the segments array, from it, we can find the corresponding waypoints at each end of the segment from the waypoints array.
The third part builds an array of clinched segments, again by segmentID. So when plotting the segments later, we'll check to see if the segmentID is found in the clinched array. If so, plot it with a vivid color, otherwise with the lighter shade. We can do this check efficiently as well, since we know the segmentIDs in clinched (when they exist) are in the same order as in the segments array.
So the PHP here builds all of this, and it's the JS code in
https://github.com/TravelMapping/Web/blob/master/hbtest/chmviewerfunc3.js that uses it all to plot the maps. The updateMap function does the work. JS will execute the PHP-constructed function waypointsFromSQL to populate the arrays as described above. The logic in play here to use the waypoints, newRouteIndices, segments, and clinched arrays is in updateMap starting at line 637. I think the logic should be similar for building other kinds of maps, except you won't be making google.maps.Polyline objects, you'll be drawing on your map.
Writing this reminds me of some of the things I hope to enhance on the Google Maps overlay maps implemented in the files described above. I'd like to be able to have ways to highlight a particular route, to be able to click on a segment and see information about it (what route(s) it carries, clinched status, length, endpoint waypoint names, etc.). As I mentioned yesterday, that's on hold for a bit.