@MrMike wrote:
So I’m trying to add a leaflet map to a project. While I get everything to work when using ionic serve to visualize it on the browser, when I do ionic capacitor run android No map will show on the Android Studio Virtual Device.
I have created a new blank project. On index.html I have added the links to leaflet css and js.
On home.page.html I added container for my map.<div id="container"> <div id="myMapContainer"> <div id="myMap"></div> </div> </div>
with simple css
#myMapContainer { width: 100vw; height: calc(100vh - 56px); margin-top: 56px; background-color: cornflowerblue; } #myMap { width: 100vw; height: 100%; }
Then on home.page.ts I added few lines of code
ngOnInit() { let myMap = L.map("myMap").setView([51.505, -0.09], 13); let aMap = new L.tileLayer( "http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png", { attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>' } ); aMap.addTo(myMap); setTimeout(() => { myMap.invalidateSize(); }, 10); myMap.on("dragend", event => { myMap.invalidateSize(); }); }
I also added a declare const L; so it doesn’t complain about not knowing what L is.
While all this works on browser, it wont work on Android Studio.
Anyone has any idea why this could be happening?
If someone interested I guess I could upload the full src somewhere. Thanks a lot in advance.
Posts: 1
Participants: 1