How to draw a polyline between two locations?

I have noted the article instructs how to accomplish, however it's seems to be for XAMARIN, not for WPF!?

18 Replies

RS Ramya Soundar Rajan Syncfusion Team March 31, 2020 01:59 PM UTC

Hi Frank Chou, 
 
Greetings from Syncfusion. 
 
We have prepared the simple SfMaps sample to draw polyline on the map with binding the Markers property from the ViewModel. Added marker icon by using the MarkerTemplate property as like in below code. 
 
                  
 <maps:ShapeFileLayer Uri="MapsWPF.world-map.shp" x:Name="layer" > 
                    <maps:ShapeFileLayer.SubShapeFileLayers> 
                        <maps:SubShapeFileLayer Uri="MapsWPF.terminal.shp" Markers="{Binding Models}"> 
                            <maps:ShapeFileLayer.ShapeSettings > 
                                <maps:ShapeSetting ShapeStrokeThickness="2" ShapeFill="Black"/> 
                            </maps:ShapeFileLayer.ShapeSettings> 
                            <maps:SubShapeFileLayer.MarkerTemplate> 
                                <DataTemplate> 
                                    <StackPanel Orientation="Horizontal" Margin="-12,-30,0,0"> 
                                        <Image Source="pin.png" Height="30"/> 
                                    </StackPanel> 
                                </DataTemplate> 
                            </maps:SubShapeFileLayer.MarkerTemplate> 
                        </maps:SubShapeFileLayer> 
                    </maps:ShapeFileLayer.SubShapeFileLayers> 
                </maps:ShapeFileLayer> 
   … 
 
 
Output: 
 
 
 
Please let us know if you need any further assistance on this. 
 
Regards, 
Ramya S 



NW Nicolas Wagener May 17, 2023 07:47 AM UTC

Hello, I Like to do the same thing but with ImageLayer.


I found the same example in Xamarin (Here), how to achieve this in WPF with the SfMap ? 


Thank you for your help !

Nicolas



NW Nicolas Wagener replied to Nicolas Wagener May 17, 2023 01:12 PM UTC

Here is a sample project that I made to simplify the explanation.

I'm using : 

Visual Studio 2022

WPF controls : 21.2.3 .NET 6.0


1) I add some points on the map that describe a route

2) I add a "SubShapeFileLayers" to my ImageLayer and draw a line between the first and last point


What I need : 

1) Draw a line between each points in order to view my route

2) The line must always appear, in my example the line change when the zoom change, I can't figure out how to manage to have a perfect line like the Marker.


Thank you for you assistance.

Nicolas


Attachment: SfMapDemo_3838a58.rar


VO Vishal Omprasad Syncfusion Team May 18, 2023 12:54 PM UTC

Currently, we are analyzing your query. We will validate and update you with further details as soon as possible. We appreciate your patience until then.



VO Vishal Omprasad Syncfusion Team May 19, 2023 10:56 AM UTC

Hi Nicolas,

We have checked your query “Draw a line between each points in order to view my route and the line must always appear” and found that the Maps Polyline had not appeared even when the geo points are provided. We have logged an issue report, and we will fix this issue and include the issue fix our Weekly NuGet release update which is expected to be available by June 06, 2023. We appreciate your patience until then.

You can track the status of this report through the following feedback link.

Feedback link - https://www.syncfusion.com/feedback/43828/mappolyline-did-not-appeared-on-wpf-sfmap-control

Note: The provided feedback link is private, and you need to log in to view this feedback.

Regards,

Vishal O.



NW Nicolas Wagener May 23, 2023 08:09 AM UTC

Hello Vishal,


Thank you, I will wait until the 6th of June for that.

I have 2 others demand concerning the SfMap control :


1) I want to change the source of the Markers bind on the map but it does not refresh.

See the attached example, when you run it, it will show one route. If you click on the button in the top left corner, a second datasource is put into the viewmodel property. The data source changed, the PropertyChanged is hit and the Get of the property as well but the map is not refreshed.


2) When the datasource is changed, I would like to center the map correctly with a correct center and a correct zoom. Is it possible to do that automatically ?


ps : I will add a commentary to the bug ticket to link my demands to it.


Thank you for your answer.


Nicolas


Attachment: SfMapDemo_62efc9b0.rar


VO Vishal Omprasad Syncfusion Team May 25, 2023 01:42 PM UTC

Hi Nicolas,

We have checked the reported issues (Null Reference exception when selecting a marker, and when changing the source of the Markers bind on the map but it does not refresh) and we are able to reproduce the issues from our end. We are considering these issues in the already logged issue report (https://www.syncfusion.com/feedback/43828/mappolyline-did-not-appeared-on-wpf-sfmap-control) and we will fix and include them in our Weekly NuGet release update as promised earlier which is expected to be available by June 06, 2023. We appreciate your patience till then.

Regards,

Vishal O.



NW Nicolas Wagener May 26, 2023 07:15 AM UTC

Hi Vishal,

thank you very much for your reactivity, we looking forwad for this fix :-)


Regards,

Nicolas



VO Vishal Omprasad Syncfusion Team June 6, 2023 01:31 PM UTC

Hi Nicolas,

Regarding “MapPolyline did not appeared on WPF SfMap control and other issues”:

We have fixed the issues from our end. Due to the testing phase, we have prepared patch including the fix. Before installing the patch, kindly remove bin and obj folders from all the projects of solution and clear NuGet cache.

Please refer our following KB document to clear nuget cache.

https://www.syncfusion.com/kb/6987/how-to-clear-nuget-cache

Set Up: https://syncfusion.com/Installs/support/patch/21.2.3/1188824/F152865/SyncfusionPatch_21.2.3_1188824_6062023084323238_F152865.exe

Custom Assemblies: https://syncfusion.com/Installs/support/patch/21.2.3/1188824/F152865/SyncfusionPatch_21.2.3_1188824_6062023084323238_F152865.zip

Nuget: https://syncfusion.com/Installs/support/patch/21.2.3/1188824/F152865/SyncfusionNuget_21.2.3_1188824_6062023084323238_F152865.zip

Disclaimer:

Please note that we have created this patch for version 21.2.8 specifically to include the issue.

We will include the issue fix in our weekly nuget release which is expected to roll out on June 13, 2023. We appreciate your patience until then.  

Regards,

Vishal O.



NW Nicolas Wagener June 9, 2023 05:31 AM UTC

Hello Vishal,


I took the Custom assemblies and replace the Syncfusion.SfMaps.WPF.dll in my demo project.

I'am afraid that nothing changed : 

- the lines are not drawned between the points

- the click on the pin generate a null reference exception

- the data source changed, but the points are not re-drawn


Did I miss something ? 


Thank you.

Nicolas


Attachment: SfMapDemo_3ecd09dc.rar


VO Vishal Omprasad Syncfusion Team June 9, 2023 09:59 AM UTC

Hi Nicolas,

Regarding “The lines are not drawn between the points”:

In the sample that you have shared earlier, in MainWindow.xaml you have set ShapeStrokeThickness="1000" in the ShapeFileLayer.ShapeSettings, and in MainWindow.xaml.cs in the for-loop statement you have checked the condition i < 2, which thus provided a wrong result. We have modified the codes in the samples like below and achieved your requirement.

[XAML]

<maps:SubShapeFileLayer x:Name="subLayer"

                        ShapeType="Polyline">

    <maps:ShapeFileLayer.ShapeSettings>

        <maps:ShapeSetting ShapeStrokeThickness="10"

                           SelectedShapeColor="Orange"

                           ShapeFill="Orange"

                           ShapeStroke="Orange"></maps:ShapeSetting>

    </maps:ShapeFileLayer.ShapeSettings>

</maps:SubShapeFileLayer>

[C#]

for (int i = 0; i < Models.Count; i++)

    listePoints.Add(new Point(Models[i].Latitude, Models[i].Longitude));


We have shared the modified tested sample “SfMapDemo (1)” and the tested output video below for your reference. Please add the Patch NuGet or the DLL which we have shared in our previous update in the sample.

Regarding “the click on the pin generate a null reference exception”:

We have found and fixed this issue and this fix was included in the private patch that we have shared to you.

Regarding “the data source changed, but the points are not redrawn”:

We have found and fixed this issue and this fix was included in the private patch that we have shared to you.

We have shared the tested output video and the sample “SfMapDemo (2)” (which you have shared earlier) below.

We suspect that the issue occurred because bin and obj folders from all the projects of solution was perhaps not removed and NuGet cache was not cleared properly.

Please refer our following KB document to clear nuget cache.

https://www.syncfusion.com/kb/6987/how-to-clear-nuget-cache

As mentioned earlier, we will include the issue fix in our weekly nuget release which is expected to roll out on June 13, 2023. We appreciate your patience until then.  

Regards,

Vishal O.


Attachment: SfMapSamples_65099adc.zip


NW Nicolas Wagener June 12, 2023 04:58 AM UTC

Hello Vishal, 

I found what's going wrong... 

When I test the projects it doesn't work because I take the .net 6.0 Syncfusion.SfMaps.WPF.dll of the patch.


When I use the .net 4.6 version, it works like your video demo. 

So I presume that the fix was not add to the .net 6.0 dll version ? We are using the .net 6.0 version of the syncfusion dll. It would be difficult to use only the  SfMap dll in .net 4.6 and all the others in .net 6.0.


We will take the patch tomorrow and try it again. If it does work it will be fine, if not we will use the 4.6 version and hope the .net 6.0 will be upd



VO Vishal Omprasad Syncfusion Team June 12, 2023 10:06 AM UTC

Hi Nicolas,

The fix was not included in the .NET 6.0 Framework in the patch that we have shared earlier. Now we have again prepared a patch in which the fix is included in the .NET 6.0 Framework too. Please install the latest patch provided below.

Set Up: https://syncfusion.com/Installs/support/patch/21.2.3/1188824/F152865/SyncfusionPatch_21.2.3_1188824_6122023031001976_F152865.exe

Custom Assemblies: https://syncfusion.com/Installs/support/patch/21.2.3/1188824/F152865/SyncfusionPatch_21.2.3_1188824_6122023031001976_F152865.zip

Nuget: https://syncfusion.com/Installs/support/patch/21.2.3/1188824/F152865/SyncfusionNuget_21.2.3_1188824_6122023031001976_F152865.zip

Disclaimer:

Please note that we have created this patch for version 21.2.8 specifically to include the issue.

Due to delay in the testing phase, we are unable to include the fix in our upcoming weekly nuget release on June 13, 2023. But we will include the issue fix in our weekly nuget release which is expected to roll out on June 20, 2023. We appreciate your patience until then.  

Regards,

Vishal O.



VO Vishal Omprasad Syncfusion Team June 20, 2023 01:03 PM UTC

Hi Nicolas,

Due to the 2023 volume 2 main release, there is no weekly nuget release for this week. We will include the issue fix in our upcoming weekly nuget release. We appreciate your patience until then.

Regards,

Vishal O.



VO Vishal Omprasad Syncfusion Team June 27, 2023 09:23 AM UTC

Hi Nicolas,

As previously informed, the reported issues “MapPolyline not rendered, NullReferenceException when selecting a SubShapeFileLayer’s marker, and the map did not refreshed when changing the source of the markers bind” has been resolved. However, the weekly NuGet release that was scheduled for today (June 27, 2023) has been postponed until tomorrow (June 28, 2023). We will notify you once the release has been rolled out. We appreciate your patience until then.

Regards,

Vishal O.



NW Nicolas Wagener June 28, 2023 08:25 AM UTC

Hello Vishal,


I finally had the time to try this fix and it's OK for me. Thank you for updating the product.


However, I have 2 others requirements (see the sample to test them) :


1- Is it possible to change/calculate the ZoomLevel and ZoomFactor according to the route shown. I can change the Center Point when the datasource change, but how can I calculate the ZoomLevel to see the entire route points and then disable the possibility of zooming for the user (EnableZoom="False") 


2 - I want to change the color of the PolyLine between the points with a range value in the Data object. I did like the documentation advice us to do, but it won't work and I don't know how to debug it.


<maps:ShapeFileLayer.ShapeSettings>

                                <maps:ShapeSetting ShapeFill="Black" ShapeStroke="Black" ShapeStrokeThickness="5" ShapeColorValuePath="Population" ShapeValuePath="Population">

                                    <maps:ShapeSetting.FillSetting>

                                        <maps:ShapeFillSetting AutoFillColors="False">

                                            <maps:ShapeFillSetting.ColorMappings>

                                                <maps:RangeColorMapping From="0" To="10" Color="Green"/>

                                                <maps:RangeColorMapping From="11" To="20" Color="Cyan"/>

                                                <maps:RangeColorMapping From="21" To="30" Color="Red"/>

                                            </maps:ShapeFillSetting.ColorMappings>

                                        </maps:ShapeFillSetting>

                                    </maps:ShapeSetting.FillSetting>

                                </maps:ShapeSetting>

                            </maps:ShapeFileLayer.ShapeSettings>



Thank you for your help (again :-) ).


BR,

Nicolas


Attachment: SfMapDemo_aac77c0b.rar


VO Vishal Omprasad Syncfusion Team July 4, 2023 12:56 PM UTC

Hi Nicolas,

We have fixed the reported issues "MapPolyline not rendered, NullReferenceException when selecting a SubShapeFileLayer’s marker, and the map did not refreshed when changing the source of the markers bind" and included the fix in our latest Weekly NuGet release package version 22.1.36, which is available for download in nuget.org.

We thank you for your support and appreciate your patience in waiting for this release.

Regarding “I have other two requirements”:

Currently we are analysing your query. We will validate and update you with further details shortly. We appreciate your patience till then.

Regards,

Vishal O.



VO Vishal Omprasad Syncfusion Team July 5, 2023 01:08 PM UTC

Hi Nicolas,

We have created a separate ticket for your latest queries under your account. Please follow-up the ticket for further details.

Regards,

Vishal O.


Loader.
Up arrow icon