changeset 301:95b818a7550b gmap2

Add some comments.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Jan 2017 13:35:22 +0200
parents e7aa649b0090
children 91e6497dffa2
files map.js
diffstat 1 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/map.js	Wed Nov 30 11:20:38 2016 +0200
+++ b/map.js	Mon Jan 09 13:35:22 2017 +0200
@@ -100,6 +100,8 @@
   if (typeof(args) == "object")
   {
     var posSet = false;
+
+    // If args have x, y and zoom set, center to the coordinates
     if ("zoom" in args && "x" in args && "y" in args)
     {
       pmapPlrPrevPos = {"x": args.x, "y": args.y};
@@ -107,8 +109,14 @@
 
       google.maps.event.addDomListener(pmap, "foobar", function()
       {
+        // First, set desired zoom level
         pmap.setZoom(args.zoom);
+
+        // Convert and pan to given coordinates
         pmap.panTo(pmapMapCoordsToLatLng(new google.maps.Point(args.x, args.y), 6));
+
+        // Then check if any marker exists at these coordinates
+        // and if one does, activate it.
         var tgtMarker = pmapGetMarkerIndexByCoords(args.x, args.y);
         if (tgtMarker)
           pmapMyClick(tgtMarker);
@@ -147,12 +155,16 @@
 //
 function pmapCoordinateListener(point)
 {
-  // Round the coordinates so that we hit the pointed square more accurately
+  // Convert the coordinates by using "zoom" level 6+1=7
+  // in order to get 2x resolution for them, then
+  // divide the coords by 2 and use rounding so that we
+  // hit the pointed square more accurately.
   var p = pmapLatLngToMapCoords(point.latLng, 7);
   var tx = Math.round((p.x + 1) / 2.0);
   var ty = Math.round((p.y + 1) / 2.0);
 
-  var cx, cy;
+  // Check if we are on any continent
+  var cx = -1, cy = -1;
   var cont = "Deep Sea";
   
   for (i = 0; i < pmapContinents.length; i++)
@@ -167,6 +179,7 @@
     }
   }
 
+  // Adjust by world origin
   tx += pmapWorld.ox - 1;
   ty += pmapWorld.oy - 1;