You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to add a SymbolLayer to place some symbols. Now, I need to add a callback function to perform some operations when those symbols are tapped. However, for some reason, the tap event is not being registered. When I use controller.addSymbol, it works, but it doesn't work for controller.addSymbolLayer.
Steps to Reproduce
setup MapLibreMap
after map load add layers with symbol info
call onSymbolTapped event the
Expected Results
When a symbol is tapped, the expected result is for the onSymbolTapped function to be called.
Actual Results
it will print tapped from controller.onSymbolTapped.add
Code Sample
// Generate features for all markersfinalList<Map<String, dynamic>> features = markers.map((marker) {
final coordinates = [marker.geometry.longitude, marker.geometry.latitude];
// Ensure geometry coordinates are validif (coordinates.contains(null)) {
throwException("Invalid geometry coordinates");
}
return {
'type':'Feature',
'geometry': {'type':'Point', 'coordinates': coordinates},
'properties': {
'title':"...", // Custom properties for each marker
},
};
}).toList();
// Add GeoJSON sourceawait controller.addSource(
'markerSource',
GeojsonSourceProperties(
data: {
'type':'FeatureCollection',
'features': features,
},
),
);
// Generate a random string for the marker namefinal name =generateRandomString(5);
// Ensure base marker is created successfullyawait_baseMarker(controller: controller, name: name);
// Add the symbol layerawait controller.addLayer(
'markerSource', // Source ID'markerLayer', // Layer IDSymbolLayerProperties(
iconImage: name,
iconSize:0.18,
iconAnchor:'bottom',
textField:' ',
iconAllowOverlap:true,
),
enableInteraction:true,
);
controller.onSymbolTapped.add(
(argument) {
print("tapped");
},
);
The text was updated successfully, but these errors were encountered:
Have you tried using onFeatureTapped? As you are using geoJSON this may be the method you are looking for.
onFeatureTapped works for all kinds of geoJSON features. So say you added geoJSON points, lines, polygons etc, the onFeatureTapped would run for all of those layers.
After adding your geoJSON layers to the map, run the following code to add tap events to your symbols.
controller.onFeatureTapped.add((dynamic feature, Point<double> point, LatLng latLng) async {
}
Have you tried using onFeatureTapped? As you are using geoJSON this may be the method you are looking for.
onFeatureTapped works for all kinds of geoJSON features. So say you added geoJSON points, lines, polygons etc, the onFeatureTapped would run for all of those layers.
After adding your geoJSON layers to the map, run the following code to add tap events to your symbols.
controller.onFeatureTapped.add((dynamic feature, Point<double> point, LatLng latLng) async {
}
Thanks, it's working. Inside onFeatureTapped, queryRenderedFeatures is helping me solve this problem.
Platforms
all
Version of flutter maplibre_gl
0.20.0
Bug Description
I was trying to add a
SymbolLayer
to place some symbols. Now, I need to add a callback function to perform some operations when those symbols are tapped. However, for some reason, the tap event is not being registered. When I usecontroller.addSymbol
, it works, but it doesn't work forcontroller.addSymbolLayer.
Steps to Reproduce
MapLibreMap
onSymbolTapped
event theExpected Results
When a symbol is tapped, the expected result is for the
onSymbolTapped
function to be called.Actual Results
it will print
tapped
fromcontroller.onSymbolTapped.add
Code Sample
The text was updated successfully, but these errors were encountered: