From 07496597276b977057839a1cfb3cf15e751c5dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Sat, 7 Jan 2017 21:48:04 -0800 Subject: [PATCH] [ios, macos] Added MGLShape from GeoJSON example Added an example of deserializing an MGLShape from a GeoJSON file. --- platform/darwin/scripts/update-examples.js | 2 +- platform/darwin/src/MGLShape.h | 8 ++++++++ .../darwin/test/MGLDocumentationExampleTests.swift | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/platform/darwin/scripts/update-examples.js b/platform/darwin/scripts/update-examples.js index 2aeb80e13..629132606 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 eae5b3ae2..8dc1b4f1c 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 12bebf19b..65c145456 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