Skip to content

Commit 134e77c

Browse files
feat: Merge feature/Geometry-Swift into feature/Cluster-QuadTree-Heatmap-Geometry-swift branch. (#525)
* refactor(`feature/Geometry-Swift`): Refactored Geometry models & Protocols in swift. (#484) * [Code Commit] Added Geometry models in swift. * refactor(`feature/Geometry-Swift`): Refactored Geometry models & Protocols in swift. * refactor: Refactored `Geometry` models in swift & `optional`/`nullable` properties of the recently committed swift class. (#485) * refactor: Refactored Unit Tests for `Geometry` models in swift. (#486) * refactor: Refactor & Modernised `GMUGeoJSONParser` class of `Geometry` module. (#487) * refactor: Translate & Modernised `GMUKMLParser` class of `Geometry` module. (#490) * refactor: Translate & Modernised `GMUKMLParser` class of `Geometry` module. * refactor: Code Comments modifications. * refactor: Translate & Modernised `GMUGeometryRenderer` class of `Geometry` module. (#508) * refactor: Translate & Modernised `GMUGeometryRenderer` class of `Geometry` module. * refactor: Removed `GMUGeometryRendererTest.swift` class for now.
1 parent fd7d0d0 commit 134e77c

25 files changed

+2738
-48
lines changed

Sources/GoogleMapsUtils/Geometry/GeoJSONParser/GMUGeoJSONParser1.swift

+516
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// MARK: - Geo JSONParser Constants
16+
struct GMUGeoJSONParserConstants {
17+
static let typeMember: String = "type"
18+
static let idMember: String = "id"
19+
static let geometryMember: String = "geometry"
20+
static let geometriesMember: String = "geometries"
21+
static let propertiesMember: String = "properties"
22+
static let boundingBoxMember: String = "bbox"
23+
static let coordinatesMember: String = "coordinates"
24+
static let featuresMember: String = "features"
25+
static let featureValue: String = "Feature"
26+
static let featureCollectionValue: String = "FeatureCollection"
27+
static let pointValue: String = "Point"
28+
static let multiPointValue: String = "MultiPoint"
29+
static let lineStringValue: String = "LineString"
30+
static let multiLineStringValue: String = "MultiLineString"
31+
static let polygonValue: String = "Polygon"
32+
static let multiPolygonValue: String = "MultiPolygon"
33+
static let geometryCollectionValue: String = "GeometryCollection"
34+
static let geometryRegex: String = "^(Point|MultiPoint|LineString|MultiLineString|Polygon|MultiPolygon|GeometryCollection)$"
35+
}

Sources/GoogleMapsUtils/Geometry/GeometryRenderer/GMUGeometryRenderer1.swift

+479
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
/// TO-DO: Rename the class to `GMUKMLParser` once the linking is done and remove the objective c class.
14+
/// This extension provides the delegate(`XMLParserDelegate`) implementations, of the `GMUKMLParser` class.
15+
///
16+
extension GMUKMLParser1 {
17+
18+
// MARK: - `didStartElement`
19+
/// Called when the parser encounters the start of an XML element.
20+
///
21+
/// - Parameters:
22+
/// - parser: The XML parser object providing context for the parse operation.
23+
/// - elementName: The name of the element that was found in the XML.
24+
/// - namespaceURI: The URI of the namespace to which the element belongs (if any).
25+
/// - qName: The qualified name of the element (optional).
26+
/// - attributeDict: A dictionary containing the attributes of the element (if any).
27+
func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) {
28+
characters = nil
29+
if let styleRegex, let _ = styleRegex.firstMatch(in: elementName, options: [], range: NSRange(location: 0, length: elementName.count)) {
30+
parseBeginStyle(with: elementName, styleID: attributeDict[GMUKMLParserConstants.idAttributeName])
31+
} else if elementName == GMUKMLParserConstants.placemarkElementName || elementName == GMUKMLParserConstants.groundOverlayElementName {
32+
parseBeginPlacemark()
33+
} else if elementName == GMUKMLParserConstants.hotspotElementName {
34+
parseBeginHotspot(with: attributeDict)
35+
} else if let geometryRegex,
36+
geometryRegex.firstMatch(in: elementName, options: [], range: NSRange(location: 0, length: elementName.count)) != nil ||
37+
elementName == GMUKMLParserConstants.groundOverlayElementName {
38+
parseBeginGeometry(withElementName: elementName)
39+
} else if let boundaryRegex,
40+
boundaryRegex.firstMatch(in: elementName, options: [], range: NSRange(location: 0, length: elementName.count)) != nil {
41+
parseBeginBoundary(with: elementName)
42+
} else if let styleAttributeRegex,
43+
let geometryAttributeRegex,
44+
let compassRegex,
45+
let pairAttributeRegex,
46+
styleAttributeRegex.firstMatch(in: elementName, options: [], range: NSRange(location: 0, length: elementName.count)) != nil ||
47+
geometryAttributeRegex.firstMatch(in: elementName, options: [], range: NSRange(location: 0, length: elementName.count)) != nil ||
48+
compassRegex.firstMatch(in: elementName, options: [], range: NSRange(location: 0, length: elementName.count)) != nil ||
49+
pairAttributeRegex.firstMatch(in: elementName, options: [], range: NSRange(location: 0, length: elementName.count)) != nil {
50+
parseBeginLeafNode()
51+
}
52+
}
53+
54+
// MARK: - `didEndElement`
55+
/// Called when the parser encounters the end of an XML element.
56+
///
57+
/// - Parameters:
58+
/// - parser: The XML parser object providing context for the parse operation.
59+
/// - elementName: The name of the element that has just ended in the XML.
60+
/// - namespaceURI: The URI of the namespace to which the element belongs (if any).
61+
/// - qName: The qualified name of the element (optional).
62+
func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
63+
if let styleRegex,
64+
styleRegex.firstMatch(in: elementName, options: [], range: NSRange(location: 0, length: elementName.count)) != nil {
65+
parseEndStyle()
66+
} else if let styleAttributeRegex,
67+
styleAttributeRegex.firstMatch(in: elementName, options: [], range: NSRange(location: 0, length: elementName.count)) != nil {
68+
parseEndStyleAttribute(elementName)
69+
} else if elementName == GMUKMLParserConstants.placemarkElementName {
70+
parseEndPlacemark()
71+
} else if let pairAttributeRegex,
72+
pairAttributeRegex.firstMatch(in: elementName, options: [], range: NSRange(location: 0, length: elementName.count)) != nil {
73+
parseEndPairAttribute(elementName)
74+
} else if elementName == GMUKMLParserConstants.groundOverlayElementName {
75+
parseEndGroundOverlay()
76+
} else if let geometryRegex,
77+
geometryRegex.firstMatch(in: elementName, options: [], range: NSRange(location: 0, length: elementName.count)) != nil {
78+
parseEndGeometry(withElementName: elementName)
79+
} else if let geometryAttributeRegex,
80+
geometryAttributeRegex.firstMatch(in: elementName, options: [], range: NSRange(location: 0, length: elementName.count)) != nil {
81+
parseEndGeometryAttribute(elementName)
82+
} else if let compassRegex,
83+
compassRegex.firstMatch(in: elementName, options: [], range: NSRange(location: 0, length: elementName.count)) != nil {
84+
parseEndCompassAttribute(elementName)
85+
}
86+
parserState.remove(.leafNode)
87+
characters = nil
88+
}
89+
90+
// MARK: - `foundCharacters`
91+
/// Called when the parser finds character data within an XML element.
92+
///
93+
/// - Parameters:
94+
/// - parser: The XML parser object providing context for the parse operation.
95+
/// - string: The string containing the characters found between XML elements.
96+
func parser(_ parser: XMLParser, foundCharacters string: String) {
97+
if isParsing(.leafNode) {
98+
guard var characters, !characters.isEmpty else {
99+
characters = string
100+
return
101+
}
102+
characters.append(string)
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)