buildPlacePlacemark function

dynamic buildPlacePlacemark(
  1. PlacesModel place,
  2. int index,
  3. String query,
  4. BuildContext context, {
  5. dynamic visibility = true,
  6. dynamic viewOrbit = true,
  7. double duration = 1.2,
})

Implementation

buildPlacePlacemark(
    PlacesModel place, int index, String query, BuildContext context,
    {visibility = true, viewOrbit = true, double duration = 1.2}) async {
  FontsProvider fonts = Provider.of<FontsProvider>(context, listen: false);
  ColorProvider colors = Provider.of<ColorProvider>(context, listen: false);
  double textSize = fonts.fonts.textSize;
  double titleSize = fonts.fonts.titleSize;
  double headSize = fonts.fonts.headingSize;

  String primaryColor;

  if (SettingsSharedPref.getTheme() == 'light') {
    primaryColor = 'black';
  } else {
    primaryColor = 'white';
  }

  // String buttonColor =
  //     colors.colors.buttonColors.toHexString(enableAlpha: false).substring(2);
  String grad1 =
      colors.colors.gradient1.toHexString(enableAlpha: false).substring(2);
  String grad2 =
      colors.colors.gradient2.toHexString(enableAlpha: false).substring(2);
  String grad3 =
      colors.colors.gradient3.toHexString(enableAlpha: false).substring(2);
  String grad4 =
      colors.colors.gradient4.toHexString(enableAlpha: false).substring(2);

  String indx = '';
  if (index != -1) {
    indx = index.toString();
  }
  final sshData = Provider.of<SSHprovider>(context, listen: false);

  String content = '';

  String placeName = escapeHtml(place.name);
  String placeDescription = escapeHtml(place.description ?? '');
  String placeAddress = escapeHtml(place.address);
  String placeCity = escapeHtml(place.city ?? '');
  String placeCountry = escapeHtml(place.country ?? '');
  String placeAmenities = escapeHtml(place.amenities ?? '');
  String placePrices = escapeHtml(place.price ?? '\$\$');
  double placesRating = place.ratings ?? 0;
  double placeLatitude = place.latitude;
  double placeLongitude = place.longitude;
  // String placeLink = escapeHtml(place.sourceLink ?? '');

  String countryCode = countryMap[placeCountry] ?? 'None';
  String countryFlagImg;
  String flagDiv;

  if (countryCode != 'None') {
    String cc = countryCode.toLowerCase();
    try {
      countryFlagImg = "https://www.worldometers.info/img/flags/$cc-flag.gif";
      flagDiv = '''
              <div style="text-align:center;">
                <img src="$countryFlagImg" style="display: block; margin: auto; width: 50px; height: 45px;"/><br/><br/>
              </div>
''';
    } catch (e) {
      countryFlagImg = '';
      flagDiv = '<br>';
    }
  } else {
    countryFlagImg = '';
    flagDiv = '<br>';
  }

  String icon =
      "https://github.com/Mahy02/LG-KISS-AI-App/blob/main/assets/images/placemark_pin.png?raw=true";
  String balloonContent = '''
    <html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>LG Gemini AI Touristic Info Tool</title>
    <style>
             .balloon {
               background: linear-gradient(135deg, #$grad1 5%, #$grad2 15%, #$grad3 60%, #$grad4 100%);
              padding: 10px;
              border-radius: 20px;
              font-family: Lato, sans-serif;
            }
            .balloon h1 {
              font-size: ${titleSize}px;
              color: $primaryColor;
            }
             .balloon h2 {
              font-size: ${headSize}px;
              color: $primaryColor;
            }
            .balloon h3 {
              font-size: ${headSize - 10}px;
              color: $primaryColor;
            }

            .balloon pp{
              font-size: ${textSize}px;
              color: $primaryColor;
            }
            .balloon p {
              font-size:  ${textSize}px;
              color: #ffff;
            }

            .details {
              background-color: rgba(255, 255, 255, 1);
              color: #000;
              padding: 10px;
              border-radius: 10px;
              margin-top: 10px;
              text-align: left;
              font-size: ${textSize}px;
            }
            .balloon b {
              color: #ffff;
            }

           .container-logo {
            width: 100px;
            height: 50px;
            background-color: white;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            text-align: center;
            margin: auto;
          }
          .logo img {
            max-width: 100%; /* Ensure image fits within container */
            max-height: 100%; /* Ensure image fits within container */
            display: block;
            margin: auto;
            border-radius: 10px; /* Optional rounded corners for the image */
          }
  </style>
</head>
<body>

          <div class="balloon">

              <div style="text-align:center;">
                <h1>$query</h1>
              </div>

            <br>

              <div style="text-align:center;">
                <h2> $indx. $placeName</h2>
              </div>

              <div style="text-align:center;">
                <h3>$placeCity</h3>
                <h3>$placeCountry</h3>
              </div>

              $flagDiv

              <div style="text-align:justify;">
                <pp>$placeDescription</pp>
              </div>

              <div class="details">
                <p><b>Address:</b>$placeAddress</p>
                <p><b>Average Ratings:</b>$placesRating</p>
                <p><b>Pricing:</b>$placePrices</p>
                <p><b>Amenities:</b>$placeAmenities</p>
              </div>
          </div>
</body>
</html>
''';

  LookAtModel lookAt = LookAtModel(
    longitude: placeLongitude,
    latitude: placeLatitude,
    range: '500',
    tilt: '60',
    altitude: 0,
    heading: '0',
    altitudeMode: 'relativeToGround',
  );

  PointModel point =
      PointModel(lat: placeLatitude, lng: placeLongitude, altitude: 0);
  LookAtModel lookAtObjOrbit = LookAtModel(
    longitude: placeLongitude,
    latitude: placeLatitude,
    range: '500',
    tilt: '90',
    altitude: 0,
    heading: '0',
    altitudeMode: 'relativeToGround',
  );
  String orbitContent = OrbitModel.tag(lookAtObjOrbit, duration: duration);
  PlacemarkModel placemark = PlacemarkModel(
      id: place.id.toString(),
      name: placeName,
      styleId: 'placemark-style',
      description: placeDescription,
      icon: icon,
      balloonContent: balloonContent,
      visibility: visibility,
      viewOrbit: viewOrbit,
      scale: 1,
      lookAt: lookAt,
      point: point,
      orbitContent: orbitContent);

  content += placemark.tag;

  final kmlPlacemark = KMLModel(
    name: '$placeName-pin',
    content: content,
  );

  ScreenOverlayModel screenOverlay = ScreenOverlayModel(
    name: "",
    overlayX: 0,
    overlayY: 1,
    screenX: 1,
    screenY: 1,
    sizeX: 0.5,
    sizeY: 0.5,
    content: balloonContent,
  );

  String kmlName = 'place-Balloon';
  String ballooncontent = '<name>placeBalloon</name>';

  final kmlBalloon = KMLModel(
    name: kmlName,
    content: ballooncontent,
    screenOverlay: screenOverlay.balloonTag,
  );

  try {
    await LgService(sshData).sendKmlFileToMaster(kmlPlacemark.body, placeName);
    await LgService(sshData).sendKMLToSlave(
      LgService(sshData).balloonScreen,
      kmlBalloon.body,
    );
    await LgService(sshData).flyTo(lookAt);
  } catch (e) {
    print(e);
  }
}