Skip to content

Commit

Permalink
chore: add mappoint config
Browse files Browse the repository at this point in the history
  • Loading branch information
SkipperQ93 committed Feb 25, 2024
1 parent 4214ace commit f62f9e1
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 74 deletions.
57 changes: 8 additions & 49 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,59 +24,18 @@ export default function App() {
// 'https://services.arcgisonline.com/arcgis/rest/services/World_Terrain_Base/MapServer',
'https://services.gisqatar.org.qa/server/rest/services/Imagery/QatarSatelitte_WGS84/MapServer',
]}
pinpointUrlString={'https://i.imgur.com/nn3cmIe.png'}
pinpointConfig={{
url: 'https://i.imgur.com/nn3cmIe.png',
readMode: true,
latitude: '25.078627850921436',
longitude: '51.06309557222483',
}}
pinpointMode={true}
onPointTap={(data) => {
console.log('data', JSON.stringify(data.nativeEvent.latitude));
console.log('data', JSON.stringify(data.nativeEvent));
}}
onMapViewLoad={() => {
mapRef.current?.addPoints([
{
latitude: '24.863053760789168',
longitude: '51.10819798512265',
attributes: {
isActive: true,
user: {
id: 532,
callSign: 'User1',
},
member: {
id: 487,
},
pictureUrl: 'https://i.imgur.com/1QY2ldB.png',
},
},
{
latitude: '25.933428249335368',
longitude: '51.25955023735113',
attributes: {
isActive: true,
user: {
id: 553,
callSign: 'User1',
},
member: {
id: 487,
},
pictureUrl: 'https://i.imgur.com/1QY2ldB.png',
},
},
{
latitude: '24.861246157675627',
longitude: '51.11047339547602',
attributes: {
isActive: true,
user: {
id: 554,
callSign: 'User1',
},
member: {
id: 487,
},
pictureUrl: 'https://i.imgur.com/1QY2ldB.png',
},
},
]);
console.log('Map Loaded.');
}}
licenseKey={''}
/>
Expand Down
2 changes: 1 addition & 1 deletion ios/UaReactNativeArcgisViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@interface RCT_EXTERN_MODULE(UaReactNativeArcgisViewManager, RCTViewManager)

RCT_EXPORT_VIEW_PROPERTY(pinpointUrlString, NSString)
RCT_EXPORT_VIEW_PROPERTY(pinpointConfig, NSDictionary)
RCT_EXPORT_VIEW_PROPERTY(licenseKey, NSString)
RCT_EXPORT_VIEW_PROPERTY(pinpointMode, BOOL)
RCT_EXPORT_VIEW_PROPERTY(layers, NSArray)
Expand Down
77 changes: 54 additions & 23 deletions ios/UaReactNativeArcgisViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,44 @@ class UaReactNativeArcgisViewManager: RCTViewManager {

class UaReactNativeArcgisView : UIView, AGSGeoViewTouchDelegate {

var mapView: AGSMapView!
var mapView: AGSMapView?

var graphicsLayer: AGSGraphicsOverlay!
var trackingLayer: AGSGraphicsOverlay!


@objc var pinpointUrlString: String = ""
@objc var pinpointConfig: Dictionary<String, AnyObject> = [:] {
didSet {
guard
let urlString = pinpointConfig["url"] as? String,
let url = URL(string: urlString),
let latString = pinpointConfig["latitude"] as? String,
let lonString = pinpointConfig["longitude"] as? String
else {
return
}

let symbol = AGSPictureMarkerSymbol(url: url)
symbol.height = 50
symbol.width = 50
symbol.offsetY = 25

let latitude = (latString as NSString).doubleValue
let longitude = (lonString as NSString).doubleValue

let point = AGSPoint(clLocationCoordinate2D: CLLocationCoordinate2D(latitude: latitude, longitude: longitude))
let pointGraphic = AGSGraphic(geometry: point, symbol: symbol)

graphicsLayer.graphics.add(pointGraphic)

mapView?.setViewpointCenter(point)
}
}
@objc var licenseKey: String = "" {
didSet {
do {
do {
let result = try AGSArcGISRuntimeEnvironment.setLicenseKey(self.licenseKey)
UaReactNativeArcgisUtilities.logInfo("ArcGIS License: \(result.licenseStatus)")
UaReactNativeArcgisUtilities.logInfo("ArcGIS License: \(result.licenseStatus.rawValue)")
}
catch let exception {
UaReactNativeArcgisUtilities.logInfo(exception.localizedDescription)
Expand All @@ -78,22 +104,23 @@ class UaReactNativeArcgisView : UIView, AGSGeoViewTouchDelegate {
}
}
}


override init(frame: CGRect) {
super.init(frame: frame)

mapView = AGSMapView();
let mapView = mapView!
mapView.isAttributionTextVisible = false

addSubview(mapView);


mapView.translatesAutoresizingMaskIntoConstraints = false
let leftConstraint = NSLayoutConstraint(item: mapView!, attribute: NSLayoutConstraint.Attribute.left, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.left, multiplier: 1, constant: 0)
let topConstraint = NSLayoutConstraint(item: mapView!, attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.top, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: mapView!, attribute: NSLayoutConstraint.Attribute.right, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.right, multiplier: 1, constant: 0)
let bottomConstraint = NSLayoutConstraint(item: mapView!, attribute: NSLayoutConstraint.Attribute.bottom, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.bottom, multiplier: 1, constant: 0)
let leftConstraint = NSLayoutConstraint(item: mapView, attribute: NSLayoutConstraint.Attribute.left, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.left, multiplier: 1, constant: 0)
let topConstraint = NSLayoutConstraint(item: mapView, attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.top, multiplier: 1, constant: 0)
let rightConstraint = NSLayoutConstraint(item: mapView, attribute: NSLayoutConstraint.Attribute.right, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.right, multiplier: 1, constant: 0)
let bottomConstraint = NSLayoutConstraint(item: mapView, attribute: NSLayoutConstraint.Attribute.bottom, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self, attribute: NSLayoutConstraint.Attribute.bottom, multiplier: 1, constant: 0)
NSLayoutConstraint.activate([leftConstraint, topConstraint, rightConstraint, bottomConstraint])

mapView.touchDelegate = self
Expand Down Expand Up @@ -124,10 +151,10 @@ class UaReactNativeArcgisView : UIView, AGSGeoViewTouchDelegate {
graphicsLayer = AGSGraphicsOverlay()
trackingLayer = AGSGraphicsOverlay()

mapView.graphicsOverlays.add(trackingLayer!)
mapView.graphicsOverlays.add(graphicsLayer!)
mapView?.graphicsOverlays.add(trackingLayer!)
mapView?.graphicsOverlays.add(graphicsLayer!)

mapView.map = map
mapView?.map = map
}
}
}
Expand Down Expand Up @@ -167,7 +194,7 @@ class UaReactNativeArcgisView : UIView, AGSGeoViewTouchDelegate {
graphicsLayer.graphics.add(pointGraphic)
}

mapView.setViewpointGeometry(graphicsLayer.extent, padding: 50)
mapView?.setViewpointGeometry(graphicsLayer.extent, padding: 50)

}

Expand Down Expand Up @@ -266,9 +293,13 @@ class UaReactNativeArcgisView : UIView, AGSGeoViewTouchDelegate {

UaReactNativeArcgisUtilities.logInfo("didTapAtScreenPoint: latitude: \"\(mapPoint.toCLLocationCoordinate2D().latitude)\", longitude: \"\(mapPoint.toCLLocationCoordinate2D().longitude)\"")

if pinpointMode {
if pinpointMode,
let readMode = pinpointConfig["readMode"] as? Bool,
!readMode {
graphicsLayer.graphics.removeAllObjects()
guard let url = URL(string: pinpointUrlString) else {
guard
let urlString = pinpointConfig["url"] as? String,
let url = URL(string: urlString) else {
return
}

Expand All @@ -281,27 +312,27 @@ class UaReactNativeArcgisView : UIView, AGSGeoViewTouchDelegate {

graphicsLayer.graphics.add(pointGraphic)

mapView.setViewpointCenter(mapPoint)
mapView?.setViewpointCenter(mapPoint)

onPointTap?([
"latitude": "\(mapPoint.toCLLocationCoordinate2D().latitude)",
"longitude": "\(mapPoint.toCLLocationCoordinate2D().longitude)"
])
}
else {
mapView.identify(graphicsLayer,
screenPoint: screenPoint,
tolerance: 22,
returnPopupsOnly: false,
maximumResults: 50) { results in
mapView?.identify(graphicsLayer,
screenPoint: screenPoint,
tolerance: 22,
returnPopupsOnly: false,
maximumResults: 50) { results in
var dataArray = [Dictionary<String,Any>]()
for result in results.graphics {
guard
let type = result.attributes["type"] as? String,
type == "main",
let data = result.attributes["data"] as? Dictionary<String,Any> else {
continue
}
continue
}
dataArray.append(data);

}
Expand Down
7 changes: 6 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ const LINKING_ERROR =
type UaReactNativeArcgisProps = {
layers?: string[];
style?: ViewStyle;
pinpointUrlString?: string;
pinpointConfig?: {
url: string;
readMode: boolean;
latitude?: string;
longitude?: string;
};
pinpointMode?: boolean;
onPointTap?: (data: { nativeEvent: any }) => void;
onMapViewLoad?: () => void;
Expand Down

0 comments on commit f62f9e1

Please sign in to comment.