Best way to show some Polylines in V8 RRS feed

  • Question

  • Hello,

    i have a map that show several polylines (some lines have > 5000 Points). The coordinates are stored in a sql server.

    At the moment i used a stored proc to create a wkt-stream for each line and sent them via web-service to the map where javascript create each layer.

    Question: What is the fastes way to load the polylines?

    The lines are static; so they never change. Should i store each line in a file and load them via GeoJson?

    What function is the best?



    Tuesday, March 10, 2020 9:38 AM

All replies

  • Hi Patric,

    I have the following guidance from the team for you:

    The best guidance is to make sure the polylines are sent and added all at once as an array of shapes into a single layer. We have seen customers in the past add shapes one by one, or as individual layers, which has perf impacts out of our control. If they can make sure to add them all into a single layer all at once, here is an example:

    var polylines = /* Polyline[] */;
    var layer = new Microsoft.Maps.Layer();

    These can also be added using the default map.entities.push(polylines) if preferred. As for WKT vs. GeoJSON the formats themselves don’t make much difference.

    A better option for perf benefits in this case would be to try our PointCompression codec:

    If the above guidance does not work for you, please do follow up with further questions.



    Monday, March 23, 2020 5:02 AM
  • Hello IoTGirl (strange Nickname),

    thanks for your reply.

    Maybe my Inro was not exact enough. So more precise (i hope).

    Each Line is a 'Walking-Trak' with his own Name in a menu and the Feature to Show and hide each line. I have around 50 Traks; so i think to put each line in his own layer is the easiest way to toggle between Show and hide.

    Do you have a better solution?

    I also read about the PointCompression but my data is stored in a SqlServer table and I don't find any stored proc to generate a PointCompressed structure from data of type 'geographie'.

    Do you know such a Routine or is someone working on it?

    Thanks and stay healthy


    Monday, March 23, 2020 10:20 AM
  • Hi Patric,

    My nickname is actually very descriptive -> IoT = Internet of Things and Girl = Not a boy :)

    I think your solution should work but if you are only showing one line at a time, why are you preloading the layers?  I would just create the layer as each path is requested (AKA On Demand) 



    Monday, March 23, 2020 9:35 PM
  • Hello IoTGirl,

    the 'construction' of your nickname was clear, but this is not a forum where you or i expect the topic of IoT?

    As i wrote, the map shows a 'network' of traks with POI's nearby. 

    Here is the link:

    So at start I show what all is available, but give the user the possibility to hide the traks that are not interesting.

    And the toggle is done via layer.

    If i load all lines in one layer, how should i identify each line by 'name' to change the visibility?

    And any idea for the PointCompression in the SqlServer?

    Best regards,



    Tuesday, March 24, 2020 10:10 AM
  • Hi Patric,

    IoT wouldn't be nearly as interesting without location awareness.  Think about how relevant where a thing is in pretty much any IoT context and I think you will see how critical maps are to IoT.  Including your scenario, in fact.  If I go for a hike with my IoT wristwatch I can then look at a map with my path. This is one of the more basic IoT tracking scenarios. I digress...

    I am not familiar with point compression patterns in SQL but I would assume that the data would be "uncompressed" at access time much like other data compression in SQL. As for Bing maps, we have the following two docs that might help:



    Your scenario is to load all tracks then remove the one's that are not of interest.  My previous suggestion was more that can you load only one track then add the other layers as needed but that would not match your scenario. Essentially my suggestion would be to load the most recent track and offer to add the older tracks on request and only add those layers if they are requested.



    Tuesday, March 24, 2020 3:27 PM
  • Hello IoTGirl,

    I store the tracks in a table with Points of type geography and a primekey of type int32 as autoincrement. Second table is for the Name of the tracks and some additional info and a third table that store the primekey of the track and the primekey of the Points including the order in the line. I use this structure because it is easier if you Change some Points in the line. In Addition you have the possibility to add additional info at each Point.

    I already know the documents of your links and as far as i understand, These compression is for a list of 400 or less Points. But i have tracks with several thousand Points!

    I know i can reduce the number of Points with a SQL-function. For an 'Overview' the results are ok, but if you zoom in it get horrible. Some times earlier i though about a loading function, that reload the line in relation to the zoom Level and the geographic area; but this means:

    Get the zoomlevel and the bounding box on the client

    Sent this to the Server and calculate the 'part of the line' for the box with the reduce-Parameter based on the zoom-Level. Sent the result to the Client.

    On the Client hide the old line and draw the new one.

    And this for each zoom or pan of the map.

    I think this will not be very prerformant. Or see you any error in my flow? Or have you better ideas?

    An other solution could be the creation of an own tile layer and map the tyles over the Bing map tiles. But there is also the Show and hide Problem of single tracks. So a tile-layer for each track and then view a stack of 50 tile-layers in a map? Not realy a good idea; i think.

    Sorry if my Problem is not so easy (maybe there is no best solution) and thanks for your Patience with me.



    Wednesday, March 25, 2020 10:53 AM
  • Hi Pagehl,

    I have logged this scenario with a link to this posting in the V8 Web control team backlog for review.  Initial thoughts from that team's lead are as follows:

    My high level thought is he should consider using different LODs of data, we do exactly the same thing with Direction routes. i.e. fetch lower LOD data based on zoom level. I believe routing supports 4 LODs, same with Spatial Data Services (SDS) . And he mentioned something similar below, that would be the best approach I’d say. He wouldn’t worry about #2 or #3 below, just fetch a different level of detail of data at different zoom levels, and he can even pre-fetch the next level of detail ahead of time and have it cached ready to use when the user zooms in. 



    Saturday, April 4, 2020 3:38 PM
  • Hello IoTGirl,

    are there any suggestions from the Team depending on Show and hide a layer?

    I mean i store one line in layer x the other in layer y --> i can identify each layer by 'name'. What is the way with different Level of Detail? Delete the old lines in each layer and store the new lines? But where store the 'preloaded' lines? Is it possible to load only the additional Points and 'insert' them in an exsisting line ?

    Any hints/tips for the combination of reduce in SQL Server and the zoomlevel (zoom x --> reduce y; zoom 2x --> reduce 2y )??

    Regards and stay healthy


    Monday, April 6, 2020 10:03 AM
  • Sorry for the late response. Just looked at this thread.

    Here are my recommendations:

    1. Add all Polylines to a single layer if you can. Here is one sample: . This sample also shows you a possible way by which you can hide a polyline by its name based on your business logic.

    2. You can add group of polylines to a single layer or 1 polyline per layer, but in terms of performance reducing number of layers will be more performant. Here is a sample with each polyline added to a its own layer. 

    3. Please don't update polyline per zoom level (This will have severe performance panetly). Looks like its not even needed based on your original requirements on this thread. Maps internally handles it based on the zoom level. 

    4. In terms of performance of creating a polyline object, Order from most performant to least will be raw cordinates, compressed coordinates, GeoJson and least will be WKT. I will recommend using compressed coordines if you can, since you can store a compressed coordinate string in sql or create it dynamically on server. This string will be 10x smaller then the WKT and will be much faster to send to client from server.

    5. Some other recommendation since I was looking at your website. 
    1. Looks like you are sending a bunch of images inlined into a js file. Consider compressing those images (Since they are uncompressed). There are a bunch of tools available for compressing png files.
    2. Consider moving these inline images to css, either inline or by reference. Js file which contain these images is blocking your page load and slowing down the whole page.
    3. Polylines that is been send from server to client is not gzip. Consider compressing it.

    Thursday, April 23, 2020 11:45 PM
  • Hello Pramil,

    first of all thanks for your time and your tips; sounds all verry interesting and i will try to use them!

    To your Points:

    Point 1

    1. First you create an Array of n Polylines; named polylines --> this is the structure i must load my polylines.
    2. Next you create an Array named internalStore with a 'LineName_n' as Array-Index and the polyline n as value.

    3. each polylines[i] get his own click-handler

    4. You create a Map.Layer and push the polylines in it and insert this layer to the map layer collection.

    5. you can reference each polyline via the Name in the internalStore-Array

    My missing link was the combination of an Array of Polylines with a 'Naming-Array' and the possibility to reach the single polyline in a layer on this way. I will try this and sent you my results.

    Point 2

    One polyline to one Layer was a Workaround since i was not able to reference different polylines insid a layer!

    Point 3

    This was an idea to mimick the LOD (Level of Detail) used in several graphic Systems; but i'm with you; it's overdone.

    Point 4

    As explained, my coordinates are stored in a SQL Server as datatype geography. Do you know any (SQL) function to cast the coordinates to a compressed string? And what is the structure of coordinate in raw-Format?

    Point 5

    Hope you are not to horrified about the side; it increased over the years and since it is a non Profit side, there was never enough time and Money for a clean relaunch --> some strange tests are still in the code. 

    5.1 I integrate some Images (mostly logos) as base64-raw data. the reason is that i create some pdf's on the Client and the lib i used was not able to load the Images dynamic; but if i load them this way, all work fine. Maybe i should look for a better PDF-lib!

    5.3 The polylines are sent via an ASP.NET Webservice (old Webform-style). I thought the stream is compressed, since i configured the IIS to use gzip. Any hint for configure ASP.NET Webservice using gzip?

    Thanks again for your excelent tips and stay healthy


    Friday, April 24, 2020 9:19 AM