Hi,
How can I rotate a MapControl content to show a polyline data always horizontal irrespective of its angle. I am using a Projected Coordinate System Map. I tried binding the buffered extent of the polyline and setting the camera heading to the line segment angle converted to degrees. It doesn't work as expected.
<SPAN class="keyword token">private</SPAN> <SPAN class="keyword token">async</SPAN> Task <SPAN class="token function">SetMapContent</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> mapView <SPAN class="operator token">=</SPAN> MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">double</SPAN> Rad2Degrees <SPAN class="operator token">=</SPAN> <SPAN class="number token">180</SPAN> <SPAN class="operator token">/</SPAN> Math<SPAN class="punctuation token">.</SPAN>PI<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>mapView <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN> <SPAN class="operator token">&&</SPAN> lineGeom <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> segment <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> lb <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">LineBuilder</SPAN><SPAN class="punctuation token">(</SPAN>lineGeom<SPAN class="punctuation token">.</SPAN>Points<SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> lineGeom<SPAN class="punctuation token">.</SPAN>Points<SPAN class="punctuation token">.</SPAN><SPAN class="token function">LastOrDefault</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">return</SPAN> lb<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToSegment</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> bearing <SPAN class="operator token">=</SPAN> segment<SPAN class="punctuation token">.</SPAN>Angle <SPAN class="operator token">*</SPAN> Rad2Degrees<SPAN class="punctuation token">;</SPAN>
Camera camera <SPAN class="operator token">=</SPAN> mapView<SPAN class="punctuation token">.</SPAN>Camera<SPAN class="punctuation token">;</SPAN>
camera<SPAN class="punctuation token">.</SPAN>Heading <SPAN class="operator token">=</SPAN> bearing<SPAN class="punctuation token">;</SPAN>
ViewContent <SPAN class="operator token">=</SPAN> MapControlContentFactory<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Create</SPAN><SPAN class="punctuation token">(</SPAN>MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">,</SPAN> camera<SPAN class="punctuation token">,</SPAN> MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">.</SPAN>DefaultViewingMode<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>and then below code to set the extent everytime the line data changes
<SPAN class="keyword token">await</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> bufferPoly <SPAN class="operator token">=</SPAN> GeometryEngine<SPAN class="punctuation token">.</SPAN>Instance<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Buffer</SPAN><SPAN class="punctuation token">(</SPAN>lineGeom<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0.1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
MapPoint cent <SPAN class="operator token">=</SPAN> GeometryEngine<SPAN class="punctuation token">.</SPAN>Instance<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Centroid</SPAN><SPAN class="punctuation token">(</SPAN>lineGeom<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> ext <SPAN class="operator token">=</SPAN> EnvelopeBuilder<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateEnvelope</SPAN><SPAN class="punctuation token">(</SPAN>bufferPoly<SPAN class="punctuation token">.</SPAN>Extent<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>ext <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
System<SPAN class="punctuation token">.</SPAN>Windows<SPAN class="punctuation token">.</SPAN>Application<SPAN class="punctuation token">.</SPAN>Current<SPAN class="punctuation token">.</SPAN>Dispatcher<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Invoke</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">async</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN>
<SPAN class="punctuation token">{</SPAN>
ViewContentExtent <SPAN class="operator token">=</SPAN> ext<SPAN class="punctuation token">;</SPAN>
<SPAN class="token function">NotifyPropertyChanged</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> ViewContentExtent<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Any suggestions to get this working ?
Thanks,
Sai