Skip to content

Unable to load pmtiles  #50

@jesussmile

Description

@jesussmile

So, here is my steps,

  1. Created multiple altitude layers X Y Z and merged them into one single pmtiles.
  2. When i load it in QGIS and under properties/ Value (altitude) I can see various value from 0 to 30.48 .. 1020-1050.48 etc. This values can be manipulated removed colored in anyway or shape I wish.

Requirement:

  1. find a way to load pmtiles and load the tiles based on this values.

Screenshot 2024-10-25 180949

Very basic example of how I access pmtiles. I believe pmtiles are both raster and vector ? So unsure If i really need to use vector tile layer to access pmtiles with different values as shown in the screenshot above.

class MainScreen extends StatefulWidget {
 static const String idScreen = 'mainScreen';
 const MainScreen({Key? key}) : super(key: key);
 @override
 _MainScreenState createState() => _MainScreenState();
}

class _MainScreenState extends State<MainScreen> {

 PmTilesTileProvider? _pmTilesTileProvider;
 MapController flutterMapController = MapController();

@override
 void didChangeDependencies() {
   super.didChangeDependencies();
 }

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


 Future<void> _loadPmTiles() async {
   // Copy the PMTiles file from assets to a temporary directory
   final ByteData data = await rootBundle.load("assets/terrain.pmtiles");
   final Uint8List bytes = data.buffer.asUint8List();


   final tempDir = await getTemporaryDirectory();
   final tempFile = File('${tempDir.path}/terrain.pmtiles');
   await tempFile.writeAsBytes(bytes);

   // Use the PmTilesTileProvider.fromSource method to load the PMTiles archive
   final provider = await PmTilesTileProvider.fromSource(tempFile.path);
   setState(() {
     _pmTilesTileProvider = provider;
   });
 }


 @override
 Widget build(BuildContext context) {
   return Scaffold(
     body: Column(
       children: [
         Expanded(
           child: Stack(
             children: [
               Positioned(
                 top: 0,
                 left: 0,
                 child: SizedBox(
                   child: FlutterMap(
                     mapController: flutterMapController,
                     options: const MapOptions(
                       maxZoom: 11,
                       initialZoom: 10,
                       minZoom: 2,
                     ),
                     children: [
                       TileLayer(
                         tileProvider: _pmTilesTileProvider,
                         urlTemplate: '',
                       ),
                     ],
                   ),
                 ),
               ),
             ],
           ),
         ),
       ],
     ),
   );
 }
}

This is the metadalayer I get from https://pmtiles.io/

{
  "name": "terrain",
  "description": "",
  "version": "2",
  "minzoom": "0",
  "maxzoom": "9",
  "center": "-119.3791667,45.1416667,0",
  "bounds": "-171.7916667,18.9250000,-66.9666667,71.3583333",
  "type": "overlay",
  "format": "pbf",
  "vector_layers": [
    {
      "id": "merged",
      "description": "",
      "minzoom": 0,
      "maxzoom": 9,
      "fields": {
        "altitude": "String"
      }
    }
  ],
  "tilestats": {
    "layerCount": 1,
    "layers": [
      {
        "layer": "merged",
        "count": 16011274,
        "geometry": "Polygon",
        "attributeCount": 1,
        "attributes": [
          {
            "attribute": "altitude",
            "count": 193,
            "type": "string",
            "values": [
              "0-30.48",
              "1020-1050.48",
              "1050-1080.48",
              "1080-1110.48",
              "1110-1140.48",
              "1140-1170.48",
              "1170-1200.48",
              "120-150.48",
              "1200-1230.48",
              "1230-1260.48",
              "1260-1290.48",
              "1290-1320.48",
              "1320-1350.48",
              "1350-1380.48",
              "1380-1410.48",
              "1410-1440.48",
              "1440-1470.48",
              "1470-1500.48",
              "150-180.48",
              "1500-1530.48",
              "1530-1560.48",
              "1560-1590.48",
              "1590-1620.48",
              "1620-1650.48",
              "1650-1680.48",
              "1680-1710.48",
              "1710-1740.48",
              "1740-1770.48",
              "1770-1800.48",
              "180-210.48",
              "1800-1830.48",
              "1830-1860.48",
              "1860-1890.48",
              "1890-1920.48",
              "1920-1950.48",
              "1950-1980.48",
              "1980-2010.48",
              "2010-2040.48",
              "2040-2070.48",
              "2070-2100.48",
              "210-240.48",
              "2100-2130.48",
              "2130-2160.48",
              "2160-2190.48",
              "2190-2220.48",
              "2220-2250.48",
              "2250-2280.48",
              "2280-2310.48",
              "2310-2340.48",
              "2340-2370.48",
              "2370-2400.48",
              "240-270.48",
              "2400-2430.48",
              "2430-2460.48",
              "2460-2490.48",
              "2490-2520.48",
              "2520-2550.48",
              "2550-2580.48",
              "2580-2610.48",
              "2610-2640.48",
              "2640-2670.48",
              "2670-2700.48",
              "270-300.48",
              "2700-2730.48",
              "2730-2760.48",
              "2760-2790.48",
              "2790-2820.48",
              "2820-2850.48",
              "2850-2880.48",
              "2880-2910.48",
              "2910-2940.48",
              "2940-2970.48",
              "2970-3000.48",
              "30-60.480000000000004",
              "300-330.48",
              "3000-3030.48",
              "3030-3060.48",
              "3060-3090.48",
              "3090-3120.48",
              "3120-3150.48",
              "3150-3180.48",
              "3180-3210.48",
              "3210-3240.48",
              "3240-3270.48",
              "3270-3300.48",
              "330-360.48",
              "3300-3330.48",
              "3330-3360.48",
              "3360-3390.48",
              "3390-3420.48",
              "3420-3450.48",
              "3450-3480.48",
              "3480-3510.48",
              "3510-3540.48",
              "3540-3570.48",
              "3570-3600.48",
              "360-390.48",
              "3600-3630.48",
              "3630-3660.48",
              "3660-3690.48"
            ]
          }
        ]
      }
    ]
  },
  "scheme": "xyz"
}

and this is what is shows me there

Screenshot 2024-10-25 181532

I know its there but i can't find a way to access it ? Any help will do. Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions