flutter_map icon indicating copy to clipboard operation
flutter_map copied to clipboard

[BUG] TMS support seems to be partially broken

Open gpsim opened this issue 1 year ago • 19 comments

What do you want implemented?

Hello, I tried to achieve Baidu layer tiles, but always render out of order.

http://online1.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl&scaler=1&p=1

What other alternatives are available?

I tried to modify the proj4 property with the following code.


import 'package:flutter/material.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_map_example/widgets/drawer.dart';
import 'package:latlong2/latlong.dart';
import 'package:proj4dart/proj4dart.dart' as proj4;

class EPSG3413Page extends StatefulWidget {
  static const String route = 'EPSG3413 Page';

  const EPSG3413Page({Key? key}) : super(key: key);

  @override
  _EPSG3413PageState createState() => _EPSG3413PageState();
}

class _EPSG3413PageState extends State<EPSG3413Page> {
  late final Proj4Crs epsg3413CRS;

  double? maxZoom;

  @override
  void initState() {
    super.initState();

    // 9 example zoom level resolutions
    final resolutions = <double>[
      262144,
      131072,
      65536,
      32768,
      16384,
      8192,
      4096,
      2048,
      1024,
      512,
      256,
      128,
      64,
      32,
      16,
      8,
      4,
      2,
      1
    ];

    final epsg3413Bounds = Bounds<double>(
      const CustomPoint<double>(0.0, 20037508.342789244),
      const CustomPoint<double>(20037508.342789244, 0.0),
    );

    maxZoom = (resolutions.length - 1).toDouble();

    // EPSG:3413 is a user-defined projection from a valid Proj4 definition string
    // From: http://epsg.io/3413, proj definition: http://epsg.io/3413.proj4
    // Find Projection by name or define it if not exists
    final proj4.Projection epsg3413 = proj4.Projection.add('EPSG:3857',
        '+proj=merc +a=6378206 +b=6356584.314245179 +lat_ts=0.0 +lon_0=0.0 +x_0=0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs');

    epsg3413CRS = Proj4Crs.fromFactory(
      code: 'EPSG:3857',
      proj4Projection: epsg3413,
      resolutions: resolutions,
      //bounds: epsg3413Bounds,
      origins: [const CustomPoint(0, 0)],
      scales: null,
      transformation: null,
    );
  }

  @override
  Widget build(BuildContext context) {
    // These circles should have the same pixel radius on the map
    final circleMarkers = <CircleMarker>[
      CircleMarker(
          point: LatLng(21, 110),
          color: Colors.blue.withOpacity(0.7),
          borderStrokeWidth: 2,
          useRadiusInMeter: true,
          radius: 1112000 // 2000 meters | 2 km
          ),
    ];

    return Scaffold(
      appBar: AppBar(title: const Text('EPSG:3857 CRS')),
      drawer: buildDrawer(context, EPSG3413Page.route),
      body: Padding(
        padding: const EdgeInsets.all(8),
        child: Column(
          children: [
            Flexible(
              child: FlutterMap(
                options: MapOptions(
                  crs: epsg3413CRS,
                  center: LatLng(22.63785, 114.0121),
                  zoom: 4,
                  maxZoom: 4,
                ),
                children: [
                  TileLayer(
                      opacity: 1,
                      backgroundColor: Colors.transparent,
                      urlTemplate:
                          'http://online1.map.bdimg.com/onlinelabel/?qt=tile&x={x}&y={y}&z={z}&styles=pl&scaler=1&p=1'),
                  CircleLayer(circles: circleMarkers),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Can you provide any other information?

image

Platforms Affected

Android, iOS

Severity

Obtrusive: No workarounds are available, and this is essential to me

Requirements

  • [X] I agree to follow this project's Code of Conduct
  • [X] I am using the latest stable version of this package
  • [X] I have checked for similar feature requests which may be duplicates

gpsim avatar Oct 31 '22 02:10 gpsim