Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

source error for point annotations #645

Open
alladyaditi opened this issue Aug 7, 2024 · 1 comment
Open

source error for point annotations #645

alladyaditi opened this issue Aug 7, 2024 · 1 comment

Comments

@alladyaditi
Copy link

alladyaditi commented Aug 7, 2024

Source check error: PlatformException(0, Source d6253eb4-f435-4b80-8b81-8ac16daa3a2b is not in style, null, null)
[MapScreen] Processing layer: da59e513-e21d-4296-81e6-9dc59a851796, Grid Points

Adding as SymbolLayer

Future<void> _addPointLayerAsSymbol(
    Map<String, dynamic> geoJsonMap, MapLayer layer) async {
  try {
    Uint8List list;
    String iconId = layer.id;

    if (layer.iconPath != null && layer.iconPath.isNotEmpty) {
      final file = File(layer.iconPath);
      if (await file.exists()) {
        list = await file.readAsBytes();
        list = await _resizeIcon(list, 12, 12);
      } else {
        developer.log('Icon file does not exist: ${layer.iconPath}',
            name: 'MapScreen');
        final ByteData bytes =
            await rootBundle.load('assets/icons/plus-12.png');
        list = bytes.buffer.asUint8List();
        list = await _resizeIcon(list, 12, 12);
        iconId = 'default-icon';
      }
    } else {
      final ByteData bytes = await rootBundle.load('assets/icons/plus-12.png');
      list = bytes.buffer.asUint8List();
      list = await _resizeIcon(list, 12, 12);
      iconId = 'default-icon';
    }

    if (!_addedImages.contains(iconId)) {
      await _mapboxMap.style.addStyleImage(iconId, 1.0,
          MbxImage(width: 12, height: 12, data: list), true, [], [], null);
      _addedImages.add(iconId);
    }

    for (var feature in geoJsonMap["features"]) {
      final geometry = feature["geometry"]["coordinates"];
      final longitude = geometry[0];
      final latitude = geometry[1];
      final id = feature["id"].toString();

      await _mapboxMap.style.addLayer(SymbolLayer(
        id: '${layer.id}_symbol_$id',
        sourceId: layer.id,
        iconImage: iconId,
        iconSize: 1.0,
        iconOffset: const [0.0, -6.0],
        filter: [
          '==',
          ['id'],
          id
        ],
      ));
    }
  } catch (e) {
    developer.log('Error adding point layer: $e', name: 'MapScreen');
  }
}

Adding using PointAnnotationsManager

Future<void> _addPointLayerWithAnnotations(
    Map<String, dynamic> geoJsonMap, MapLayer layer) async {
  try {
    Uint8List list;
    String iconId = layer.id;

    if (layer.iconPath != null && layer.iconPath.isNotEmpty) {
      final file = File(layer.iconPath);
      if (await file.exists()) {
        list = await file.readAsBytes();
        list = await _resizeIcon(list, 12, 12);
      } else {
        final ByteData bytes =
            await rootBundle.load('assets/icons/plus-24.png');
        list = bytes.buffer.asUint8List();
        list = await _resizeIcon(list, 12, 12);
        iconId = 'default-icon';
      }
    } else {
      final ByteData bytes = await rootBundle.load('assets/icons/plus-24.png');
      list = bytes.buffer.asUint8List();
      list = await _resizeIcon(list, 12, 12);
      iconId = 'default-icon';
    }

    if (!_addedImages.contains(iconId)) {
      await _mapboxMap.style.addStyleImage(iconId, 1.0,
          MbxImage(width: 12, height: 12, data: list), true, [], [], null);
      _addedImages.add(iconId);
    }

    var pointAnnotationManager =
        await _mapboxMap.annotations.createPointAnnotationManager();
    _annotationManagers[pointAnnotationManager] = [];

    for (var feature in geoJsonMap["features"]) {
      final properties = feature["properties"];
      final geometry = feature["geometry"]["coordinates"];
      final longitude = geometry[0];
      final latitude = geometry[1];

      final annotation =
          await pointAnnotationManager.create(PointAnnotationOptions(
        geometry: Point(coordinates: Position(longitude, latitude)),
        iconImage: iconId,
        iconSize: 1.3,
        iconOffset: const [0.0, -5.0],
        symbolSortKey: 10,
      ));

      _annotationManagers[pointAnnotationManager]?.add(annotation);

      annotationProperties[annotation.id] = filterProperties(properties, layer);
    }

    if (layer.enablePopUp) {
      pointAnnotationManager.addOnPointAnnotationClickListener(
        CustomAnnotationClickListener(context, (data) {
          if (mounted) {
            setState(() {
              _properties = data.isNotEmpty ? data : null;
            });
          }
        }, annotationProperties),
      );
    }

    if (layer.enableLabel && layer.label.isNotEmpty) {
      await _addLabelLayer(
          layer.id, layer, layer.label, layer.labelColor, layer.zoomLevel ?? 0);
    }
  } catch (e) {
    developer.log('Error adding point layer: $e', name: 'MapScreen');
  }
}

@alladyaditi
Copy link
Author

PlatformException(0, Source da59e513-e21d-4296-81e6-9dc59a851796 is not in style, null, null) why i am getting this error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant