B4J Question [SOLVED],How to add overlay image to map in Leaflet ?

NGUYEN TUAN ANH

Active Member
Licensed User
Dear All
I created Leaflet web map in B4j with BANanoVueMaterial
Could you please help me
How to add overlay image to map in Leaflet ?
Thank you very much.!
Best regards
 

NGUYEN TUAN ANH

Active Member
Licensed User
Yes, thank your reply
Could you please research and support add overlay image to map in B4j Leaflet BANanoVuetify as soon as possible . !
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
Hi

Please get the latest version of BVAD3 from Github, in the kitchen sink View, in the addMarker sub, there is code to add a marker that has an image

B4X:
VLeaflet1.AddMarkerIcon("ano1", "Ano",47.313221, -1.5, "./assets/sponget.png", 42, 42, 0, 42)


Are you looking for something else other than this approach of overlaying images to the map?
 
Upvote 0

NGUYEN TUAN ANH

Active Member
Licensed User
I see on Internet: https://www.tutorialspoint.com/leafletjs/leafletjs_overlay.htm
Instead of map overlays, you can also use image, video overlays in a Leaflet application. In this chapter, we will see how to use such overlays.

Image Overlay​

Follow the steps given below to use an image overlay.

Step 1 − Create a Map object by passing a <div> element (String or object) and map options (optional).

Step 2 − Create a Layer object by passing the URL of the desired tile.

Step 3 − Add the layer object to the map using the addLayer() method of the Map class.

Step 4 − Create the image overlay using L.imageOverlay(). Pass the URL of the image and an object representing image bounds, as shown below.
// Creating Image overlay
var imageUrl = 'tpPoster.jpg';
var imageBounds = [[17.342761, 78.552432], [16.396553, 80.727725]];
var overlay = L.imageOverlay(imageUrl, imageBounds);

Step 5 − Add the overlay to the map using addTo() method of the imageOverlay class, as shown below.

// Adding overlay to the map
overlay.addTo(map);

Example​

The following code demonstrates the usage of image overlay.

<!DOCTYPE html>
<html>
<head>
<title>Image Overlay Example</title>
<link rel = "stylesheet" href = "http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css"/>
<script src = "http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
</head>

<body>
<div id = "map" style = "width:900px; height:580px"></div>
<script>
// Creating map options
var mapOptions = {
center: [17.342761, 78.552432],
zoom: 8
}
var map = new L.map('map', mapOptions); // Creating a map object

// Creating a Layer object
var layer = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');
map.addLayer(layer); // Adding layer to the map

// Creating Image overlay
var imageUrl = 'tpPoster.jpg';
var imageBounds = [[17.342761, 78.552432], [16.396553, 80.727725]];
var overlay = L.imageOverlay(imageUrl, imageBounds);
overlay.addTo(map);
</script>
</body>

</html>

Could you please help me convert to B4J BANanoVueMaterial
 
Upvote 0

NGUYEN TUAN ANH

Active Member
Licensed User
I called:
VLeaflet1.AddImageOverlay("Img0","./assets/d491b.png","0",LatMin,LngMin,LatMax,LngMax)
But Nothing show
Could you please help me
I'm waiting for you.!
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
This works...



B4X:
'COMPULSORY
Private Sub VLeaflet1_Ready            'ignoreDeadCode
   vuetify.SetNextTick(Me, "addMarker")
End Sub

'on next refresh
Sub addMarker                'ignoreDeadCode
    VLeaflet1.Reset
    
    VLeaflet1.AddImageOverlay("bvad3", "./assets/bvad31.png", "Mashy", 40.712216, -74.22655, 40.773941, -74.12544)
    
    'always refresh before you setview
    VLeaflet1.Refresh(page)
    'move to explicit position    
    VLeaflet1.SetView(page, 40.712216, -74.22655, 11)
    
    'hide the loader
    vuetify.Loading(False)
End Sub
'
'COMPULSORY
Private Sub VLeaflet1_Resize            'ignoreDeadCode
    page.refs = vuetify.getrefs
    VLeaflet1.resize(page)
End Sub

'In the mounted hook, you will have full access to the reactive component, templates, and rendered DOM
Sub mounted        'ignoreDeadCode
    VLeaflet1.UpdateZoom(page, 11)
    vuetify.Loading(False)
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…