Skip to content

Commit

Permalink
Allow setting custom stroke width (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
nighthawk authored Aug 23, 2024
1 parent 8f48d3f commit 471e819
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
26 changes: 17 additions & 9 deletions Examples/Cassini.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,33 @@
objects = {

/* Begin PBXBuildFile section */
3A0743C52C782366009403F8 /* GeoDrawer in Frameworks */ = {isa = PBXBuildFile; productRef = 3A0743C42C782366009403F8 /* GeoDrawer */; };
3A0743C72C782366009403F8 /* GeoProjector in Frameworks */ = {isa = PBXBuildFile; productRef = 3A0743C62C782366009403F8 /* GeoProjector */; };
3A1B27CE29448ADA00271603 /* CassiniApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A1B27CD29448ADA00271603 /* CassiniApp.swift */; };
3A1B27D029448ADA00271603 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A1B27CF29448ADA00271603 /* ContentView.swift */; };
3A1B27D229448ADB00271603 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3A1B27D129448ADB00271603 /* Assets.xcassets */; };
3A1B27D629448ADB00271603 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3A1B27D529448ADB00271603 /* Preview Assets.xcassets */; };
3A1B27DE29448AFE00271603 /* GeoDrawer in Frameworks */ = {isa = PBXBuildFile; productRef = 3A1B27DD29448AFE00271603 /* GeoDrawer */; };
3A1B27E229455C8600271603 /* ContentView+Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A1B27E129455C8600271603 /* ContentView+Model.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
3A0743C22C782321009403F8 /* GeoProjector */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = GeoProjector; path = ..; sourceTree = "<group>"; };
3A1B27CA29448ADA00271603 /* Cassini.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Cassini.app; sourceTree = BUILT_PRODUCTS_DIR; };
3A1B27CD29448ADA00271603 /* CassiniApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CassiniApp.swift; sourceTree = "<group>"; };
3A1B27CF29448ADA00271603 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
3A1B27D129448ADB00271603 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
3A1B27D329448ADB00271603 /* Cassini.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Cassini.entitlements; sourceTree = "<group>"; };
3A1B27D529448ADB00271603 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
3A1B27E129455C8600271603 /* ContentView+Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ContentView+Model.swift"; sourceTree = "<group>"; };
3AFF3A45294D38220061E069 /* GeoProjector */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = GeoProjector; path = ..; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
3A1B27C729448ADA00271603 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3A1B27DE29448AFE00271603 /* GeoDrawer in Frameworks */,
3A0743C52C782366009403F8 /* GeoDrawer in Frameworks */,
3A0743C72C782366009403F8 /* GeoProjector in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -79,7 +81,7 @@
3A1B27DF29448DAD00271603 /* Packages */ = {
isa = PBXGroup;
children = (
3AFF3A45294D38220061E069 /* GeoProjector */,
3A0743C22C782321009403F8 /* GeoProjector */,
);
name = Packages;
sourceTree = "<group>";
Expand All @@ -101,7 +103,8 @@
);
name = Cassini;
packageProductDependencies = (
3A1B27DD29448AFE00271603 /* GeoDrawer */,
3A0743C42C782366009403F8 /* GeoDrawer */,
3A0743C62C782366009403F8 /* GeoProjector */,
);
productName = Cassini;
productReference = 3A1B27CA29448ADA00271603 /* Cassini.app */;
Expand Down Expand Up @@ -132,7 +135,7 @@
);
mainGroup = 3A1B27C129448ADA00271603;
packageReferences = (
3A1B27DC29448AFE00271603 /* XCRemoteSwiftPackageReference "GeoProjector" */,
3A0743C32C782366009403F8 /* XCRemoteSwiftPackageReference "GeoProjector" */,
);
productRefGroup = 3A1B27CB29448ADA00271603 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -390,7 +393,7 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
3A1B27DC29448AFE00271603 /* XCRemoteSwiftPackageReference "GeoProjector" */ = {
3A0743C32C782366009403F8 /* XCRemoteSwiftPackageReference "GeoProjector" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/maparoni/GeoProjector";
requirement = {
Expand All @@ -401,11 +404,16 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
3A1B27DD29448AFE00271603 /* GeoDrawer */ = {
3A0743C42C782366009403F8 /* GeoDrawer */ = {
isa = XCSwiftPackageProductDependency;
package = 3A1B27DC29448AFE00271603 /* XCRemoteSwiftPackageReference "GeoProjector" */;
package = 3A0743C32C782366009403F8 /* XCRemoteSwiftPackageReference "GeoProjector" */;
productName = GeoDrawer;
};
3A0743C62C782366009403F8 /* GeoProjector */ = {
isa = XCSwiftPackageProductDependency;
package = 3A0743C32C782366009403F8 /* XCRemoteSwiftPackageReference "GeoProjector" */;
productName = GeoProjector;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 3A1B27C229448ADA00271603 /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/maparoni/geojsonkit.git",
"state" : {
"revision" : "8f1e5094a8ab8cbb020074cd4848a5804c17bab0",
"version" : "0.5.2"
"revision" : "a5aabe3a1edddbcf14b49b3fa5be1ddd48dff7c8",
"version" : "0.6.0"
}
},
{
"identity" : "geojsonkit-turf",
"kind" : "remoteSourceControl",
"location" : "https://github.com/maparoni/geojsonkit-turf",
"state" : {
"revision" : "4937997370046d00a8f40dbe445280d709ec8dc4",
"version" : "0.1.5"
"revision" : "99c542f4c3c105caa9567c61fd8036e94e07df05",
"version" : "0.4.1"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "fee6933f37fde9a5e12a1e4aeaa93fe60116ff2a",
"version" : "1.2.2"
"revision" : "41982a3656a71c768319979febd796c6fd111d5c",
"version" : "1.5.0"
}
}
],
Expand Down
14 changes: 7 additions & 7 deletions Examples/Cassini/ContentView+Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ extension ContentView {
switch next {
case .circle(let position, _, _, _, _):
acc.append(position)
case .line(let line, _):
case .line(let line, _, _):
acc.append(contentsOf: line.positions)
case .polygon(let polygon, _, _, _):
acc.append(contentsOf: polygon.exterior.positions)
Expand All @@ -147,12 +147,12 @@ extension GeoDrawer.Content {

func settingColor(_ color: CGColor) -> GeoDrawer.Content {
switch self {
case .line(let lineString, _):
return .line(lineString, stroke: color)
case .polygon(let polygon, _, _, _):
return .polygon(polygon, fill: color)
case .circle(let position, let radius, _, _, _):
return .circle(position, radius: radius, fill: color)
case .line(let lineString, _, let strokeWidth):
return .line(lineString, stroke: color, strokeWidth: strokeWidth)
case .polygon(let polygon, _, _, let strokeWidth):
return .polygon(polygon, fill: color, strokeWidth: strokeWidth)
case .circle(let position, let radius, _, _, let strokeWidth):
return .circle(position, radius: radius, fill: color, strokeWidth: strokeWidth)
}
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/GeoDrawer/GeoDrawer+CoreGraphics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import GeoProjector
extension GeoDrawer {

/// Draws the line into the current context
public func draw(_ line: GeoJSON.LineString, strokeColor: CGColor, in context: CGContext) {
public func draw(_ line: GeoJSON.LineString, strokeColor: CGColor, strokeWidth: Double = 2, in context: CGContext) {
for points in convertLine(line.positions) {

let path = CGMutablePath()
Expand All @@ -30,7 +30,7 @@ extension GeoDrawer {

context.setStrokeColor(strokeColor)

context.setLineWidth(2)
context.setLineWidth(strokeWidth)
context.setLineCap(.round)
context.setLineJoin(.round)

Expand Down Expand Up @@ -201,8 +201,8 @@ extension GeoDrawer {
switch content {
case .circle:
break // this will go above the outline, as they might go outside projection
case let .line(line, stroke):
draw(line, strokeColor: stroke, in: context)
case let .line(line, stroke, strokeWidth):
draw(line, strokeColor: stroke, strokeWidth: strokeWidth, in: context)
case let .polygon(polygon, fill, stroke, strokeWidth):
draw(polygon, fillColor: fill, strokeColor: stroke, strokeWidth: strokeWidth, frame: bounds, in: context)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/GeoDrawer/GeoDrawer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ extension GeoDrawer {
#endif

public enum Content: Hashable {
case line(GeoJSON.LineString, stroke: Color)
case line(GeoJSON.LineString, stroke: Color, strokeWidth: Double = 2)
case polygon(GeoJSON.Polygon, fill: Color, stroke: Color? = nil, strokeWidth: Double = 2)
case circle(GeoJSON.Position, radius: Double, fill: Color, stroke: Color? = nil, strokeWidth: Double = 2)
}
Expand Down

0 comments on commit 471e819

Please sign in to comment.