Skip to content

Commit

Permalink
Update javascript.js
Browse files Browse the repository at this point in the history
  • Loading branch information
fustyles authored Dec 28, 2024
1 parent 6f0b262 commit 223d4ab
Showing 1 changed file with 81 additions and 1 deletion.
82 changes: 81 additions & 1 deletion googlemap_20241226/blockly/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,87 @@ Blockly.JavaScript['googlemap_initial'] = function (block) {
'document.getElementsByTagName("head")[0].append(s);\n'+
'function initMap() {\n'+statement+'\n}\n'+
'window.initMap = initMap;\n'+
'await delay(3);\n';
'await delay(3);\n'+
'let mapMarkers = [];\n'+
'function addMapPoint(pID, pMapId, pLat, pLng, pTitle, pContent) {\n'+
' let markerData = {\n'+
' position: { lat: pLat, lng: pLng },\n'+
' title: pTitle,\n'+
' };\n'+
' let marker = new google.maps.marker.AdvancedMarkerElement({\n'+
' position: markerData.position,\n'+
' map: pMapId,\n'+
' title: markerData.title,\n'+
' });\n'+
' let infoWindow = new google.maps.InfoWindow({\n'+
' content: pContent,\n'+
' });\n'+
' marker.addListener("click", () => {\n'+
' infoWindow.open(pMapId, marker);\n'+
' });\n'+
' mapMarkers.push(["point_"+pID, pMapId, marker, infoWindow, markerData.position]);\n'+
'}\n'+
'function clearMarker(pID) {\n'+
' for (var i=0;i<mapMarkers.length;i++) {\n'+
' if ("point_"+pID==mapMarkers[i][0]) {\n'+
' mapMarkers[i][2].setMap(null);\n'+
' mapMarkers.splice(i, 1);\n'+
' break;\n'+
' }\n'+
' }\n'+
'}\n'+
'function updateMarkerContent(pID, newContent, type) {\n'+
' for (var i=0;i<mapMarkers.length;i++) {\n'+
' if ("point_"+pID==mapMarkers[i][0]) {\n'+
' if (type=="content") {\n'+
' mapMarkers[i][3].setContent(newContent);\n'+
' }\n'+
' else if (type === "latitude") {\n'+
' mapMarkers[i][4].lat = newContent;\n'+
' mapMarkers[i][2].position = mapMarkers[i][4];\n'+
' }\n'+
' else if (type === "longitude") {\n'+
' mapMarkers[i][4].lng = newContent;\n'+
' mapMarkers[i][2].position = mapMarkers[i][4];\n'+
' }\n'+
' else if (type === "position") {\n'+
' newContent = newContent.split(",");\n'+
' mapMarkers[i][4].lat = Number(newContent[0]);\n'+
' mapMarkers[i][4].lng = Number(newContent[1]);\n'+
' mapMarkers[i][2].position = mapMarkers[i][4];\n'+
' }\n'+
' else if (type=="title") {\n'+
' mapMarkers[i][2].title = newContent;\n'+
' }\n'+
' break;\n'+
' }\n'+
' }\n'+
'}\n'+
'function openMarkerContent(pID) {\n'+
' for (var i=0;i<mapMarkers.length;i++) {\n'+
' if ("point_"+pID==mapMarkers[i][0]) {\n'+
' mapMarkers[i][3].open(mapMarkers[i][1], mapMarkers[i][2]);\n'+
' break;\n'+
' }\n'+
' }\n'+
'}\n'+
'function closeMarkerContent(pID) {\n'+
' for (var i=0;i<mapMarkers.length;i++) {\n'+
' if ("point_"+pID==mapMarkers[i][0]) {\n'+
' mapMarkers[i][3].close();\n'+
' break;\n'+
' }\n'+
' }\n'+
'}\n'+
'function clearMap(pMapId) {\n'+
' for (var i=0;i<mapMarkers.length;i++) {\n'+
' if (pMapId==mapMarkers[i][1]) {\n'+
' mapMarkers[i][2].setMap(null);\n'+
' mapMarkers.splice(i, 1);\n'+
' i--;\n'+
' }\n'+
' }\n'+
'}\n';

return code;
};
Expand Down

0 comments on commit 223d4ab

Please sign in to comment.