chuyentt / geojson_vi

An Open-Source Dart and Flutter Library for Efficiently Handling GeoJSON Data in Compliance with RFC 7946
https://pub.dev/packages/geojson_vi
MIT License
15 stars 10 forks source link

Read the GeoJSON from Link #1

Closed X-SLAYER closed 4 years ago

X-SLAYER commented 4 years ago

is there a way to read GeoJSON file directly from remote url ?

chuyentt commented 4 years ago

One way to read and port remote GeoJSON data

  var url = 'https://geomatics.vn/test/new.geojson';
  http.get(url).then((response) {
    if (response.statusCode == 200) {
      var jsonResponse = convert.jsonDecode(response.body);
      //print(jsonResponse);
      var geoJSON = GeoJSON.create('');
      String type = jsonResponse['type'];
      switch (type) {
        case 'FeatureCollection':
          var features = jsonResponse['features'];
          for (var item in features) {
            geoJSON.featureCollection.features
                .add(GeoJSONFeature.fromMap(item));
          }
          break;
        default:
      }

      print(geoJSON.featureCollection.toMap);
    } else {
      print('Request failed with status: ${response.statusCode}.');
    }
  });
X-SLAYER commented 4 years ago

thnx works fine but is there any way to clear path? because if i used the same path name he will get the old featureCollection too

chuyentt commented 4 years ago

thnx works fine but is there any way to clear path? because if i used the same path name he will get the old featureCollection too

Each GeoJSON object has a path parameter, which can be used to save as a file or to identify a GeoJSON object. We cached the GeoJSON object using path identifiers.