<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do I create a custom Leaflet map component in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-i-create-a-custom-leaflet-map-component/m-p/13708259#M2039379</link>
    <description>&lt;P&gt;Hello team,&lt;/P&gt;&lt;P&gt;I am trying to create a custom component for the marketplace that simply displays points on a leaflet map. I try to create a new component by converting a container into a new component. I then add a custom javascript in the logic that defines the leaflet map when the page is mounted. I set the style to a fixed height and width of 500 px. But when I test, nothing shows.&lt;/P&gt;&lt;P&gt;Has anyone tried this?&lt;/P&gt;&lt;P&gt;Below is the code:&lt;/P&gt;&lt;P&gt;const leafletCDN = '&lt;A href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" target="_blank" rel="noopener"&gt;https://unpkg.com/leaflet@1.7.1/dist/leaflet.js&lt;/A&gt;';&lt;BR /&gt;const leafletCSS = '&lt;A href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" target="_blank" rel="noopener"&gt;https://unpkg.com/leaflet@1.7.1/dist/leaflet.css&lt;/A&gt;';&lt;/P&gt;&lt;P&gt;// Load Leaflet CSS&lt;BR /&gt;const link = document.createElement('link');&lt;BR /&gt;link.rel = 'stylesheet';&lt;BR /&gt;link.href = leafletCSS;&lt;BR /&gt;document.head.appendChild(link);&lt;/P&gt;&lt;P&gt;// Inject custom CSS&lt;BR /&gt;const style = document.createElement('style');&lt;BR /&gt;style.innerHTML = `&lt;BR /&gt;.leaflet-container {&lt;BR /&gt;width: 100%;&lt;BR /&gt;height: 500px;&lt;BR /&gt;}&lt;BR /&gt;`;&lt;BR /&gt;document.head.appendChild(style);&lt;/P&gt;&lt;P&gt;// Load Leaflet JS&lt;BR /&gt;const script = document.createElement('script');&lt;BR /&gt;script.src=leafletCDN;&lt;BR /&gt;document.head.appendChild(script);&lt;/P&gt;&lt;P&gt;script.onload = () =&amp;gt; {&lt;BR /&gt;// Locate the map container within the custom component&lt;BR /&gt;const mapContainer = document.querySelector('[data-component-name="LeafletMap"] &amp;gt; div');&lt;/P&gt;&lt;P&gt;if (mapContainer) {&lt;BR /&gt;mapContainer.className = 'leaflet-container';&lt;BR /&gt;const latitude = 51.505; // Fixed latitude for testing&lt;BR /&gt;const longitude = -0.09; // Fixed longitude for testing&lt;BR /&gt;const zoom = 13; // Fixed zoom level for testing&lt;/P&gt;&lt;P&gt;const map = L.map(mapContainer).setView([latitude, longitude], zoom);&lt;/P&gt;&lt;P&gt;L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {&lt;BR /&gt;attribution: '&amp;amp;copy; OpenStreetMap contributors'&lt;BR /&gt;}).addTo(map);&lt;BR /&gt;}&lt;BR /&gt;};&lt;/P&gt;</description>
    <pubDate>Tue, 21 May 2024 18:44:02 GMT</pubDate>
    <dc:creator>LynnS1</dc:creator>
    <dc:date>2024-05-21T18:44:02Z</dc:date>
    <item>
      <title>How do I create a custom Leaflet map component</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-i-create-a-custom-leaflet-map-component/m-p/13708259#M2039379</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;&lt;P&gt;I am trying to create a custom component for the marketplace that simply displays points on a leaflet map. I try to create a new component by converting a container into a new component. I then add a custom javascript in the logic that defines the leaflet map when the page is mounted. I set the style to a fixed height and width of 500 px. But when I test, nothing shows.&lt;/P&gt;&lt;P&gt;Has anyone tried this?&lt;/P&gt;&lt;P&gt;Below is the code:&lt;/P&gt;&lt;P&gt;const leafletCDN = '&lt;A href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" target="_blank" rel="noopener"&gt;https://unpkg.com/leaflet@1.7.1/dist/leaflet.js&lt;/A&gt;';&lt;BR /&gt;const leafletCSS = '&lt;A href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" target="_blank" rel="noopener"&gt;https://unpkg.com/leaflet@1.7.1/dist/leaflet.css&lt;/A&gt;';&lt;/P&gt;&lt;P&gt;// Load Leaflet CSS&lt;BR /&gt;const link = document.createElement('link');&lt;BR /&gt;link.rel = 'stylesheet';&lt;BR /&gt;link.href = leafletCSS;&lt;BR /&gt;document.head.appendChild(link);&lt;/P&gt;&lt;P&gt;// Inject custom CSS&lt;BR /&gt;const style = document.createElement('style');&lt;BR /&gt;style.innerHTML = `&lt;BR /&gt;.leaflet-container {&lt;BR /&gt;width: 100%;&lt;BR /&gt;height: 500px;&lt;BR /&gt;}&lt;BR /&gt;`;&lt;BR /&gt;document.head.appendChild(style);&lt;/P&gt;&lt;P&gt;// Load Leaflet JS&lt;BR /&gt;const script = document.createElement('script');&lt;BR /&gt;script.src=leafletCDN;&lt;BR /&gt;document.head.appendChild(script);&lt;/P&gt;&lt;P&gt;script.onload = () =&amp;gt; {&lt;BR /&gt;// Locate the map container within the custom component&lt;BR /&gt;const mapContainer = document.querySelector('[data-component-name="LeafletMap"] &amp;gt; div');&lt;/P&gt;&lt;P&gt;if (mapContainer) {&lt;BR /&gt;mapContainer.className = 'leaflet-container';&lt;BR /&gt;const latitude = 51.505; // Fixed latitude for testing&lt;BR /&gt;const longitude = -0.09; // Fixed longitude for testing&lt;BR /&gt;const zoom = 13; // Fixed zoom level for testing&lt;/P&gt;&lt;P&gt;const map = L.map(mapContainer).setView([latitude, longitude], zoom);&lt;/P&gt;&lt;P&gt;L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {&lt;BR /&gt;attribution: '&amp;amp;copy; OpenStreetMap contributors'&lt;BR /&gt;}).addTo(map);&lt;BR /&gt;}&lt;BR /&gt;};&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2024 18:44:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-i-create-a-custom-leaflet-map-component/m-p/13708259#M2039379</guid>
      <dc:creator>LynnS1</dc:creator>
      <dc:date>2024-05-21T18:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a custom Leaflet map component</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-i-create-a-custom-leaflet-map-component/m-p/13865191#M2039380</link>
      <description>&lt;P&gt;Any luck in finding solution to this Maps requirement ?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2024 11:36:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-do-i-create-a-custom-leaflet-map-component/m-p/13865191#M2039380</guid>
      <dc:creator>Satya_Kapaganti69</dc:creator>
      <dc:date>2024-09-13T11:36:58Z</dc:date>
    </item>
  </channel>
</rss>

