mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

MGLStyleLayer parameter can not be applied using MGLFeature.attributes dictionary data

Open noramimiyuma opened this issue 8 years ago • 1 comments

Platform: iOS 11.2 - iPhone7, iPhone X

Mapbox SDK version: 3.7.3

info

I want to store data as NSNumber (or double, integer) in MGLFeature.attributes, retrieve it using valueWithRawValue: and set it to the parameter of MGLSymbolStyleLayer.

MGLPointFeature* feature = [MGLPointFeature new];
feature.coordinate =  someObject.coordinate;
feature.attributes =  @{
                                         @"name" : someObject.name,  // NSString
                                         @"rotation" : someObject.rotation, // NSNumber
                                      };
[features addObject: feature]; // "features" is an array of MGLShapeSource
  1. instantiate the MGLSymbolStyleLayer obect > layer.
  2. set images to layer with valueWithRawValue:. (use images set in advance in MGLMapView.style)
  3. excecute following code.
  4. add layer to mapView.style.
layer.iconRotation = [MGLStyleValue valueWithRawValue:@"{rotation}"];

Expected behavior

The rotated image is displayed on the map in response to the value of the rotation parameter.

Actual behavior

The all features on the map does not rotation. But the "name" will be applied.

However, if set the value directly as NSNumber or NSString using valueWithRawValue: the image will rotate.

layer.iconRotation = [MGLStyleValue valueWithRawValue:@"50"];
layer.iconRotation = [MGLStyleValue valueWithRawValue:@50];

Is this behavior by design? If so, please tell me the way to achieve the expected behavior.

noramimiyuma avatar Jan 20 '18 08:01 noramimiyuma

It's my fault. solved with following MGLSourceStyleFunction class method.

layer.iconRotation = [MGLSourceStyleFunction functionWithInterpolationMode:MGLInterpolationModeIdentity stops:nil attributeName:@"rotation" options:@{MGLStyleFunctionOptionDefaultValue : [MGLStyleValue valueWithRawValue:@0]}];

noramimiyuma avatar Jan 20 '18 17:01 noramimiyuma