summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2017-01-07 21:48:04 -0800
committerMinh Nguyễn <mxn@1ec5.org>2017-01-09 11:41:05 -0800
commit07496597276b977057839a1cfb3cf15e751c5dab (patch)
tree61cc1897b35c2f41359db9cc7c5ea409c77301f1
parent2b61880b579b8ab0015bf15bf225f0807ed0306d (diff)
downloadqtlocation-mapboxgl-07496597276b977057839a1cfb3cf15e751c5dab.tar.gz
[ios, macos] Added MGLShape from GeoJSON example
Added an example of deserializing an MGLShape from a GeoJSON file.
-rw-r--r--platform/darwin/scripts/update-examples.js2
-rw-r--r--platform/darwin/src/MGLShape.h8
-rw-r--r--platform/darwin/test/MGLDocumentationExampleTests.swift12
3 files changed, 21 insertions, 1 deletions
diff --git a/platform/darwin/scripts/update-examples.js b/platform/darwin/scripts/update-examples.js
index 2aeb80e139..6291326068 100644
--- a/platform/darwin/scripts/update-examples.js
+++ b/platform/darwin/scripts/update-examples.js
@@ -100,7 +100,7 @@ function completeExamples(os) {
}
// Get the contents of the test method whose name matches the symbol path.
- let testMethodName = symbolPath.join('$').replace(/$[+-]/, '').replace(/:/g, '_');
+ let testMethodName = symbolPath.join('$').replace(/\$[+-]/, '$').replace(/:/g, '_');
let example = examples[testMethodName];
if (!example) {
console.error(`MGLDocumentationExampleTests.${testMethodName}() not found.`);
diff --git a/platform/darwin/src/MGLShape.h b/platform/darwin/src/MGLShape.h
index eae5b3ae21..8dc1b4f1cf 100644
--- a/platform/darwin/src/MGLShape.h
+++ b/platform/darwin/src/MGLShape.h
@@ -41,6 +41,14 @@ NS_ASSUME_NONNULL_BEGIN
collection object, the returned value is an instance of
`MGLShapeCollectionFeature`.
+ ### Example
+
+ ```swift
+ let url = mainBundle.url(forResource: "amsterdam", withExtension: "geojson")!
+ let data = try! Data(contentsOf: url)
+ let feature = try! MGLShape(data: data, encoding: String.Encoding.utf8.rawValue) as! MGLShapeCollectionFeature
+ ```
+
@param data String data containing GeoJSON source code.
@param encoding The encoding used by `data`.
@param outError Upon return, if an error has occurred, a pointer to an
diff --git a/platform/darwin/test/MGLDocumentationExampleTests.swift b/platform/darwin/test/MGLDocumentationExampleTests.swift
index 12bebf19bc..65c145456a 100644
--- a/platform/darwin/test/MGLDocumentationExampleTests.swift
+++ b/platform/darwin/test/MGLDocumentationExampleTests.swift
@@ -46,6 +46,18 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
styleLoadingExpectation.fulfill()
}
+
+ func testMGLShape$shapeWithData_encoding_error_() {
+ let mainBundle = Bundle(for: MGLDocumentationExampleTests.self)
+
+ //#-example-code
+ let url = mainBundle.url(forResource: "amsterdam", withExtension: "geojson")!
+ let data = try! Data(contentsOf: url)
+ let feature = try! MGLShape(data: data, encoding: String.Encoding.utf8.rawValue) as! MGLShapeCollectionFeature
+ //#-end-example-code
+
+ XCTAssertNotNil(feature.shapes.first as? MGLPolygonFeature)
+ }
func testMGLShapeSource() {
//#-example-code