changeset 196:1307410acf6d gmap2

Simplify by getting rid of one wrapper function.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 12 Mar 2014 05:18:06 +0200
parents 20958bb31ee6
children 4c20b0608008
files markers.js
diffstat 1 files changed, 19 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/markers.js	Wed Mar 12 04:52:46 2014 +0200
+++ b/markers.js	Wed Mar 12 05:18:06 2014 +0200
@@ -82,16 +82,23 @@
 }
 
 
-function pmapCreateMarker(point,name,html,icon,type,continent,mclass)
+function pmapCreateMarker(m, mclass)
 {
-  pname = (type != "default" ? type.toUpperCase()+" " : "") + name;
+  type = pmapLocGetLocationType(m["flags"], m["type"]);
+  if (m["name"].indexOf('FERRY') == 0)
+    type = "ferry";
+
+  pname = (type != "default" ? type.toUpperCase()+" " : "") + m["name"];
+
+  if (m["flags"] & LOCF_CLOSED)
+    pname += " (CLOSED)";
 
   var marker = new MarkerWithLabel(
   {
-    position: point,
-    icon: icon,
+    position: pmapMapCoordsToLatLng(new google.maps.Point(m["x"] * 2 + 1, m["y"] * 2 + 1), 7),
+    icon: pmapIcons[type],
     draggable: false,
-    labelContent: name,
+    labelContent: m["name"],
     labelAnchor: new google.maps.Point(22, 0),
     labelClass: "labels",
     labelStyle: {opacity: 0.75}
@@ -99,34 +106,24 @@
 
   google.maps.event.addListener(marker, "click", function()
   {
-    pmapInfoWindow.setContent("<div class=\"infowin\">"+html+"</div>");
+    pmapInfoWindow.setContent("<div class=\"infowin\">"+ m["html"] +"</div>");
     pmapInfoWindow.open(pmap, this);
   });
 
-  if (mclass == "builtin") pmapSideBuiltinHTML += '<div id="marker'+pmapMIndex+'" class="c_'+continent.toLowerCase()+'"><div>&nbsp;</div><a href="javascript:pmapMyClick('+ pmapMIndex +')">'+ pname +'</a></div>';
+  if (mclass == "builtin") pmapSideBuiltinHTML += '<div id="marker'+ pmapMIndex +'" class="c_'+ m["continent"].toLowerCase()+'"><div>&nbsp;</div><a href="javascript:pmapMyClick('+ pmapMIndex +')">'+ pname +'</a></div>';
   if (mclass == "private") pmapSidePrivateHTML += '<a href="javascript:pmapMyClick(' + pmapMIndex + ')">' + pname + '</a><br>';
   if (mclass == "public") pmapSidePublicHTML += '<a href="javascript:pmapMyClick(' + pmapMIndex + ')">' + pname + '</a><br>';
 
   pmapMarkers[pmapMIndex] = marker;
-  pmapMarkerInfo[pmapMIndex] = [type, continent];
+  pmapMarkerInfo[pmapMIndex] = [type, m["continent"]];
   pmapMIndex++;
-  return marker;
-}
-
-
-function pmapCreateMarkerType(m, mclass)
-{
-  type = pmapLocGetLocationType(m["flags"], m["type"]);
-  if (m["name"].indexOf('FERRY') == 0)
-    type = "FERRY";
-
-  var ppos = pmapMapCoordsToLatLng(new google.maps.Point(m["x"] * 2 + 1, m["y"] * 2 + 1), 7);
-  var marker = pmapCreateMarker(ppos, m["name"], m["html"], pmapIcons[type], type, m["continent"], mclass);
 
   if (pmapAreas[type] == undefined)
     pmapAreas[type] = [];
 
   pmapAreas[type].push(marker);
+
+  return marker;
 }
 
 
@@ -165,7 +162,7 @@
 
     for (var nid = 0; nid < markers.length; nid++)
     {
-      pmapCreateMarkerType(markers[nid], "builtin");
+      pmapCreateMarker(markers[nid], "builtin");
     }
 
     pmapAddMarkers(pmapAreas["default"], 7, 11);
@@ -192,7 +189,7 @@
 
     for (var nid = 0; nid < markers.length; nid++)
     {
-      pmapCreateMarkerType(markers[nid], "tradelane");
+      pmapCreateMarker(markers[nid], "tradelane");
     }
 
     pmapAddMarkers(pmapAreas["tradelane"], 5, 11);