Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #256 from Esri/FreehandSketch
Browse files Browse the repository at this point in the history
Added freehand modes to the Sketch sample
  • Loading branch information
dg0yal authored Apr 21, 2017
2 parents 2bf6859 + e3ffa04 commit ab7c828
Show file tree
Hide file tree
Showing 26 changed files with 176 additions and 47 deletions.
20 changes: 0 additions & 20 deletions arcgis-ios-sdk-samples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,6 @@
3ED029381B8E3AB300ACA70D /* MILLegendTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ED029111B8E3AB300ACA70D /* MILLegendTableViewController.swift */; };
3ED029391B8E3AB300ACA70D /* MILShowLegend.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3ED029121B8E3AB300ACA70D /* MILShowLegend.storyboard */; };
3ED0293A1B8E3AB300ACA70D /* MILShowLegendViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ED029131B8E3AB300ACA70D /* MILShowLegendViewController.swift */; };
3ED029401B8E3AB300ACA70D /* line.gif in Resources */ = {isa = PBXBuildFile; fileRef = 3ED0291B1B8E3AB300ACA70D /* line.gif */; };
3ED029411B8E3AB300ACA70D /* point.gif in Resources */ = {isa = PBXBuildFile; fileRef = 3ED0291C1B8E3AB300ACA70D /* point.gif */; };
3ED029421B8E3AB300ACA70D /* polygon.gif in Resources */ = {isa = PBXBuildFile; fileRef = 3ED0291D1B8E3AB300ACA70D /* polygon.gif */; };
3ED0294B1B8E3AB300ACA70D /* Sketch.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3ED029261B8E3AB300ACA70D /* Sketch.storyboard */; };
3ED0294C1B8E3AB300ACA70D /* SketchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ED029271B8E3AB300ACA70D /* SketchViewController.swift */; };
3ED029641B8E3ACD00ACA70D /* AttachmentsListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ED0294E1B8E3ACD00ACA70D /* AttachmentsListViewController.swift */; };
Expand Down Expand Up @@ -731,9 +728,6 @@
3ED029111B8E3AB300ACA70D /* MILLegendTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MILLegendTableViewController.swift; sourceTree = "<group>"; };
3ED029121B8E3AB300ACA70D /* MILShowLegend.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = MILShowLegend.storyboard; sourceTree = "<group>"; };
3ED029131B8E3AB300ACA70D /* MILShowLegendViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MILShowLegendViewController.swift; sourceTree = "<group>"; };
3ED0291B1B8E3AB300ACA70D /* line.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = line.gif; sourceTree = "<group>"; };
3ED0291C1B8E3AB300ACA70D /* point.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = point.gif; sourceTree = "<group>"; };
3ED0291D1B8E3AB300ACA70D /* polygon.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = polygon.gif; sourceTree = "<group>"; };
3ED029261B8E3AB300ACA70D /* Sketch.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Sketch.storyboard; sourceTree = "<group>"; };
3ED029271B8E3AB300ACA70D /* SketchViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SketchViewController.swift; sourceTree = "<group>"; };
3ED0294E1B8E3ACD00ACA70D /* AttachmentsListViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttachmentsListViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1883,24 +1877,13 @@
3ED029151B8E3AB300ACA70D /* Sketch on the map */ = {
isa = PBXGroup;
children = (
3ED029181B8E3AB300ACA70D /* Images */,
3ED029261B8E3AB300ACA70D /* Sketch.storyboard */,
3ED029271B8E3AB300ACA70D /* SketchViewController.swift */,
);
name = "Sketch on the map";
path = "Display information/Sketch on the map";
sourceTree = "<group>";
};
3ED029181B8E3AB300ACA70D /* Images */ = {
isa = PBXGroup;
children = (
3ED0291B1B8E3AB300ACA70D /* line.gif */,
3ED0291C1B8E3AB300ACA70D /* point.gif */,
3ED0291D1B8E3AB300ACA70D /* polygon.gif */,
);
path = Images;
sourceTree = "<group>";
};
3ED0294D1B8E3ACD00ACA70D /* Edit feature attachments */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2178,10 +2161,8 @@
3E1E5EEF1D9F0BAB00F4913C /* HillshadeRenderer.storyboard in Resources */,
3ED028571B8E3A8500ACA70D /* CreateSaveMap.storyboard in Resources */,
3E0B58501E36BCCD00951767 /* AnalyzeViewshed.storyboard in Resources */,
3ED029411B8E3AB300ACA70D /* point.gif in Resources */,
3E4BF45A1C5BD77300D85919 /* OfflineGeocode.storyboard in Resources */,
3EABC7C31DB191BC00C161C6 /* Shasta_Elevation.tif.aux.xml in Resources */,
3ED029401B8E3AB300ACA70D /* line.gif in Resources */,
3E6AE3EC1C6D11BA0026E59C /* OfflineRouting.storyboard in Resources */,
3E23A9EF1AFC28F6002E2214 /* Images.xcassets in Resources */,
3EBA25611D34178200AB0703 /* SimpleMarkerSymbol.storyboard in Resources */,
Expand Down Expand Up @@ -2264,7 +2245,6 @@
3ED0292C1B8E3AB300ACA70D /* GOIdentify.storyboard in Resources */,
3EBA25761D34510F00AB0703 /* CreateGeometries.storyboard in Resources */,
3EC39C2F1C9B0A9D003F6459 /* SanFrancisco.tpk in Resources */,
3ED029421B8E3AB300ACA70D /* polygon.gif in Resources */,
3EABC7A01DB1793000C161C6 /* StretchRenderer.storyboard in Resources */,
3EFCE1C61CF374C600E02F67 /* MobileMapSearchRoute.storyboard in Resources */,
3E54D2351CC6985200BB9904 /* GraphicDrawOrder.storyboard in Resources */,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
# Sketch on the map

This sample demonstrates how you can use the sketch graphics overlay to draw point or line or polygon geometry
This sample demonstrates how you can use the sketch editor to draw point or line or polygon geometry. Sketch editor now also supports freehand polyline and polygon drawing.

## How to use the sample

The sample has a toolbar of sketch tools at the bottom. You can choose the type of geometry using the switch. Sketch by tapping on the map. There are tools to undo or redo an action or clear everything.
The sample has a toolbar of sketch tools at the bottom. You can choose the type of geometry using the switch. Sketch by tapping or tapping and dragging (for freehand mode) on the map. There are tools to undo or redo an action or clear everything.

![](image1.png)
![](image2.png)

## How it works

To set the type of geometry, you need to use `start(with:creationMode:)` method on `AGSSketchEditor`, passing in the geometry type you want. The sketch graphics overlay has a undo manager of type `NSUndoManager` that provides the undo and redo methods. To clear everything there is a `clearGeometry()` method on the sketch graphics overlay.
The sample uses `start(with:creationMode:)` initializer on `AGSSketchEditor`. The initializer takes in the creation mode which could be any of the following:

- Point
- Polyline
- FreehandPolyline
- Polygon
- FreehandPolygon

The sketch editor has a undo manager of type `NSUndoManager` that provides the undo and redo methods. To clear everything there is a `clear` method on the sketch graphics overlay.



Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="DMe-yp-yH3">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16E163f" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="DMe-yp-yH3">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Sketch View Controller-->
Expand All @@ -14,28 +14,28 @@
<viewControllerLayoutGuide type="bottom" id="ZHw-cV-TtO"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="uzT-c2-KDC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="UNW-2r-OsJ" customClass="AGSMapView">
<rect key="frame" x="0.0" y="20" width="600" height="536"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<toolbar clearsContextBeforeDrawing="NO" contentMode="scaleToFill" translucent="NO" translatesAutoresizingMaskIntoConstraints="NO" id="45u-o5-Qgv">
<rect key="frame" x="0.0" y="556" width="600" height="44"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" relation="lessThanOrEqual" constant="44" id="bOy-pD-9Q6"/>
</constraints>
<items>
<barButtonItem id="Mme-ds-Pgy">
<segmentedControl key="customView" opaque="NO" tag="55" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="bar" selectedSegmentIndex="1" id="X7k-S7-bpe">
<rect key="frame" x="20" y="7" width="141" height="30"/>
<rect key="frame" x="16" y="7" width="180" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<segments>
<segment title="" image="point.gif"/>
<segment title="" image="line.gif"/>
<segment title="" image="polygon.gif"/>
<segment title="" image="Point"/>
<segment title="" image="Polyline"/>
<segment title="" image="FreehandPolyline"/>
<segment title="" image="Polygon"/>
<segment title="" image="FreehandPolygon"/>
</segments>
<connections>
<action selector="geometryValueChanged:" destination="DMe-yp-yH3" eventType="valueChanged" id="UPW-qg-uR6"/>
Expand All @@ -62,7 +62,7 @@
</items>
</toolbar>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="UNW-2r-OsJ" firstAttribute="leading" secondItem="uzT-c2-KDC" secondAttribute="leading" id="97C-Yw-nS2"/>
<constraint firstAttribute="trailing" secondItem="UNW-2r-OsJ" secondAttribute="trailing" id="EBx-iN-agX"/>
Expand All @@ -89,15 +89,17 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Zvg-TZ-2aO" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="514" y="451"/>
<point key="canvasLocation" x="512.79999999999995" y="450.22488755622192"/>
</scene>
</scenes>
<resources>
<image name="Discard" width="22" height="22"/>
<image name="FreehandPolygon" width="22" height="22"/>
<image name="FreehandPolyline" width="22" height="22"/>
<image name="Point" width="22" height="22"/>
<image name="Polygon" width="22" height="22"/>
<image name="Polyline" width="22" height="22"/>
<image name="Redo" width="22" height="22"/>
<image name="Undo" width="22" height="22"/>
<image name="line.gif" width="28" height="28"/>
<image name="point.gif" width="28" height="28"/>
<image name="polygon.gif" width="28" height="28"/>
</resources>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,8 @@ class SketchViewController: UIViewController {
self.map.initialViewpoint = AGSViewpoint(targetExtent: AGSEnvelope(xMin: -10049589.670344, yMin: 3480099.843772, xMax: -10010071.251113, yMax: 3512023.489701, spatialReference: AGSSpatialReference.webMercator()))
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func respondToGeomChanged() {

//Enable/disable UI elements appropriately
self.undoBBI.isEnabled = self.sketchEditor.undoManager.canUndo
self.redoBBI.isEnabled = self.sketchEditor.undoManager.canRedo
Expand All @@ -64,18 +60,28 @@ class SketchViewController: UIViewController {
//MARK: - Actions

@IBAction func geometryValueChanged(_ segmentedControl:UISegmentedControl) {

switch segmentedControl.selectedSegmentIndex {

case 0://point
self.sketchEditor.start(with: nil, creationMode: .point)

case 1://polyline
self.sketchEditor.start(with: nil, creationMode: .polyline)

case 2://polygon
case 2://freehand polyline
self.sketchEditor.start(with: nil, creationMode: .freehandPolyline)

case 3://polygon
self.sketchEditor.start(with: nil, creationMode: .polygon)

case 4://freehand polygon
self.sketchEditor.start(with: nil, creationMode: .freehandPolygon)

default:
break
}

self.mapView.sketchEditor = self.sketchEditor
}

Expand All @@ -94,4 +100,9 @@ class SketchViewController: UIViewController {
@IBAction func clear() {
self.sketchEditor.clearGeometry()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "FreehandPolygon.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "FreehandPolygon@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "FreehandPolygon@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "iOS7_Toolbar_FreehandSketch22.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "iOS7_Toolbar_FreehandSketch44.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Point.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Point@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Point@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Polygon.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Polygon@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Polygon@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Polyline.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Polyline@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Polyline@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ab7c828

Please sign in to comment.