map_marker.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. window.map_marker = function (map, options) {
  2. let marker;
  3. if (options == null) {
  4. options = {};
  5. }
  6. const pos = new google.maps.LatLng(options.lat, options.lng);
  7. if (options.radius > 0) {
  8. marker = new google.maps.Circle({
  9. map,
  10. strokeColor: "#FF0000",
  11. strokeOpacity: 0.8,
  12. strokeWeight: 2,
  13. fillColor: "#FF0000",
  14. fillOpacity: 0.35,
  15. center: pos,
  16. radius: options.radius,
  17. });
  18. return marker;
  19. } else if (options.course) {
  20. const p1 = new LatLon(pos.lat(), pos.lng());
  21. const speed = options.speed != null ? options.speed : 1;
  22. const p2 = p1.destinationPoint(options.course, Math.max(0.2, speed) * 0.1);
  23. const lineCoordinates = [pos, new google.maps.LatLng(p2.lat(), p2.lon())];
  24. const lineSymbol = { path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW };
  25. const arrow = new google.maps.Polyline({
  26. map,
  27. path: lineCoordinates,
  28. icons: [
  29. {
  30. icon: lineSymbol,
  31. offset: "100%",
  32. },
  33. ],
  34. });
  35. return arrow;
  36. } else {
  37. marker = new google.maps.Marker({
  38. map,
  39. position: pos,
  40. title: "Recorded Location",
  41. });
  42. return marker;
  43. }
  44. };