Constructing a military message

In many cases military messages will be taken directly from the wire format and passed into the message class for processing. In some situations an application may need to create a message itself. You can create the message and then set each parameter individually or more simply use the AGSMPMessageHelper class.

Create a military message providing the key-value codes

Message contain properties that are used by the message processor to place a messge with the correct symbology at the correct location. Apart from the messageID, all of the properties can be defined using key-value coding. As a minimum you must ensure that you have set the messageID, _Type,_Action,_Control_Points and sic properties.

Note that the message can have a different spatial reference to the map. The message processor will reproject the message to the correct location. If the message does not set a _WKID then the messageprocessor will use the spatial reference of the map that contains the group layer.

AGSMPMessage* message = [[AGSMPMessage alloc] init];
message.messageId = @"ABC123";
[message setProperty:@"position_report" forKey:@"_Type"];
[message setProperty:@"update" forKey:@"_Action"];
[message setProperty:@"-220000,6600000" forKey:@"_Control_Points"];
[message setProperty:@"3857"  forKey:@"_WKID"];
[message setProperty:@"GFGPOPP-------X" forKey:@"sic"];
[message setProperty:@"1" forKey:@"UniqueDesignation"];
[mProcessor processMessage:message];

If you wish to locate the message above call the AGSMapView:zoomtoEnvelope method.

AGSEnvelope *envelope = 
 [AGSEnvelope envelopeWithXmin:-222000 ymin:6580000 xmax:-218000 ymax:6620000 
 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:3857]];

[self.mapView zoomToEnvelope:envelope animated:YES];

Create a military message using the message helper class

Alternatively you can use the more explicit AGSMPMessageHelper class.

AGSPoint *point = [AGSPoint pointWithX:-220000 y:6600000 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:3857]];
NSArray *messageControlPoints = [NSArray arrayWithObject:point];
NSMutableDictionary *messageProperties = [NSMutableDictionary dictionaryWithCapacity:2];
[messageProperties setObject:@"GFGPOPP-------X"forKey:@"sic"];
[messageProperties setObject:@"1" forKey:@"UniqueDesignation"];
AGSMPMessage* message = [[AGSMPMessage alloc] init];
message = [AGSMPMessageHelper mil2525CUpdateMessageWithId:@"ABC123"
spatialReference:[AGSSpatialReference spatialReferenceWithWKID:3857]];

[mProcessor processMessage:message];