flutter-mapbox-gl / maps

A Mapbox GL flutter package for creating custom maps
Other
1.03k stars 498 forks source link

addGeoJson simply does not add the geojson to the map and also no errors are thrown #1390

Closed leodavinci1 closed 6 months ago

leodavinci1 commented 8 months ago

This is the function that I am using with the "onStyleLoadedCallback":

 void _onStyleLoaded() async {
    LatLng? currentLocation = await _acquireCurrentLocation();

    if (currentLocation != null) {
      setState(() {
        locationState = currentLocation;
      });

      mapController.animateCamera(
        CameraUpdate.newCameraPosition(
          CameraPosition(target: currentLocation, zoom: 9.0),
        ),
      );

      await initOfflineMapDownload(currentLocation);
    }

    // Fetch the transformed data
    List<TransformedData> dataList = await gisController.getAll(null);
    dataListLocal = dataList;

    List<GisShapesModel> allGisShapes =
        await gisController.getAllShapes('125', null);

    //Add GeoJSON sources for each shape
    for (GisShapesModel shapeModel in allGisShapes) {
      String sourceId = 'shape_source_${shapeModel.nomeShape}';

      if (shapeModel.shapeJson != null) {
        dynamic geoJson = jsonDecode(shapeModel.shapeJson);
        Map<String, dynamic> jsonMap = json.decode(geoJson);
        await mapController.addGeoJsonSource(sourceId, jsonMap);
      }
    }

    // Generate CircleOptions list
    List<CircleOptions> circleOptionsList = generateCircleOptionsList(dataList);

    // Add circles to the map
    mapController?.addCircles(circleOptionsList);

    // Add labels to circles
    addLabelsToCircles(dataList);
  }

Already checked my geojson on geojson.io, it is all correct but not displaying the shape on the map.

Can someone check and help?

Thanks

stale[bot] commented 6 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.