# HG changeset patch # User Matti Hamalainen # Date 1483961722 -7200 # Node ID 95b818a7550b837fb7dddabf845ee0c41c601be7 # Parent e7aa649b0090b28de289f9e021291439627ba5a7 Add some comments. diff -r e7aa649b0090 -r 95b818a7550b map.js --- 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;