forked from flutter-mapbox-gl/maps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a static map snapshot (flutter-mapbox-gl#1076)
* android impl * take snapshot ios * config for each platform interface * take snapshot in ios * take snap in android && example * android hybrid composition * ios test * test with android hybrid composition * Update README.md * use JPG instead of PNG with writeToDisk option & remove unused funtions * render example result with base64 option * remove team ID in example * iOS: use JPG instead of PNG * rename funtion * test flutter ci * test ci * ci: check swift formatting * ci: test check java formatting * ci: check java formatting * ci: test check java formatting * document for take snapshot feature * revert ci config * migration: jpeg with base64 option * docs: web support * feat: web support with base64 option * ci: test github ci * lint: ignore unnecessary_import * ci: reverse config
- Loading branch information
Showing
30 changed files
with
754 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
android/src/main/java/com/mapbox/mapboxgl/BitmapUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.mapbox.mapboxgl; | ||
|
||
import android.content.Context; | ||
import android.graphics.Bitmap; | ||
import android.net.Uri; | ||
import android.util.Base64; | ||
import android.util.Log; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
/** Created by nickitaliano on 10/9/17. */ | ||
public class BitmapUtils { | ||
private static final String LOG_TAG = "BitmapUtils"; | ||
|
||
public static String createTempFile(Context context, Bitmap bitmap) { | ||
File tempFile = null; | ||
FileOutputStream outputStream = null; | ||
|
||
try { | ||
tempFile = File.createTempFile(LOG_TAG, ".jpeg", context.getCacheDir()); | ||
outputStream = new FileOutputStream(tempFile); | ||
} catch (IOException e) { | ||
Log.w(LOG_TAG, e.getLocalizedMessage()); | ||
} | ||
|
||
if (tempFile == null) { | ||
return null; | ||
} | ||
|
||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); | ||
closeSnapshotOutputStream(outputStream); | ||
return Uri.fromFile(tempFile).toString(); | ||
} | ||
|
||
public static String createBase64(Bitmap bitmap) { | ||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); | ||
byte[] bitmapBytes = outputStream.toByteArray(); | ||
closeSnapshotOutputStream(outputStream); | ||
String base64Prefix = "data:image/jpeg;base64,"; | ||
return base64Prefix + Base64.encodeToString(bitmapBytes, Base64.NO_WRAP); | ||
} | ||
|
||
private static void closeSnapshotOutputStream(OutputStream outputStream) { | ||
if (outputStream == null) { | ||
return; | ||
} | ||
try { | ||
outputStream.close(); | ||
} catch (IOException e) { | ||
Log.w(LOG_TAG, e.getLocalizedMessage()); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
android/src/main/java/com/mapbox/mapboxgl/GeoJSONUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.mapbox.mapboxgl; | ||
|
||
import com.mapbox.geojson.Feature; | ||
import com.mapbox.geojson.FeatureCollection; | ||
import com.mapbox.geojson.Geometry; | ||
import com.mapbox.geojson.GeometryCollection; | ||
import com.mapbox.geojson.Point; | ||
import com.mapbox.mapboxsdk.geometry.LatLng; | ||
import com.mapbox.mapboxsdk.geometry.LatLngBounds; | ||
import com.mapbox.turf.TurfMeasurement; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class GeoJSONUtils { | ||
public static LatLng toLatLng(Point point) { | ||
if (point == null) { | ||
return null; | ||
} | ||
return new LatLng(point.latitude(), point.longitude()); | ||
} | ||
|
||
private static GeometryCollection toGeometryCollection(List<Feature> features) { | ||
ArrayList<Geometry> geometries = new ArrayList<>(); | ||
geometries.ensureCapacity(features.size()); | ||
for (Feature feature : features) { | ||
geometries.add(feature.geometry()); | ||
} | ||
return GeometryCollection.fromGeometries(geometries); | ||
} | ||
|
||
public static LatLngBounds toLatLngBounds(FeatureCollection featureCollection) { | ||
List<Feature> features = featureCollection.features(); | ||
|
||
double[] bbox = TurfMeasurement.bbox(toGeometryCollection(features)); | ||
|
||
return LatLngBounds.from(bbox[3], bbox[2], bbox[1], bbox[0]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
.buildlog/ | ||
.history | ||
.svn/ | ||
.fvm/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import UIKit | ||
import Flutter | ||
import UIKit | ||
|
||
@UIApplicationMain | ||
@objc class AppDelegate: FlutterAppDelegate { | ||
override func application( | ||
_ application: UIApplication, | ||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? | ||
) -> Bool { | ||
GeneratedPluginRegistrant.register(with: self) | ||
return super.application(application, didFinishLaunchingWithOptions: launchOptions) | ||
} | ||
override func application( | ||
_ application: UIApplication, | ||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? | ||
) -> Bool { | ||
GeneratedPluginRegistrant.register(with: self) | ||
return super.application(application, didFinishLaunchingWithOptions: launchOptions) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.