Fetch and plot data on Map based on current map view

Balasaheb Molawade 66 Reputation points
2022-06-27T08:57:45.067+00:00

Hi,

We have developed one application to fetch data from other systems using web API and plot them on a Bing map. In this, we have one requirement to fetch and show data accordingly to the current map view. For example, when the user zoom in to the New York area then fetch and show only New York region data, and when the user zoom out then fetch data that cover the new current map view and plot them on the map. When again user zoom out then fetch data to cover the new current map view and show it on the map. While fetching new data based new map view we only fetch data that are new so that we do not need to fetch already plotted data once again.

For example, we have a total of 1000 data in our database. When the user zoom in to New York (in that region have 100 data) and clicks on search then it will fetch 100 records using Web API and then plot them on the map and when the user zoom out (Now user see another state till Georgia and Indiana) then fetch data that cover current map view (it has 300 data) then fetch only 300 data and plot them on the map and Now in the map has total 400 data plotted. 300 new and 100 old.

We tried to add an event on “viewchangeend” but we are not able to identify what is new map view excluding the old map view so we only fetch data that are within the new map view.

Can anyone help us with this.

Waiting for your reply.

Thanks!

Windows Maps
Windows Maps
A Microsoft app that provides voice navigation and turn-by-turn driving, transit, and walking directions.
188 questions
{count} votes

2 answers

Sort by: Most helpful
  1. rbrundritt 7,011 Reputation points Microsoft Employee
    2022-06-28T02:20:33.273+00:00

    Trying to calculate the difference in map views will quickly become very fragmented as the user moves around the map as oyu will end up with a bunch of different size boxes (due to zoom change) and then need to merge them together to create a polygon, then calculate the difference between the old polygon area and the new bounding box map view. It can be done, but there are several other more common approaches that are used instead of this one. Here are couple to consider:

    1. If you only have 1000 locations, that's nothing for the map to handle (Bing Maps Web SDK can handle easily 10K points with ease). Load all the points into the map when the map loads. If you use this approach a good optimization is to load the bar minimum data needed to load the points on the map, usually the coordinate and a unique ID that can be used to retrieve detailed information from the database for that point. Then when a user clicks on the point, make a call to the database to get the additional details. You can tweak this approach and include a couple more bits of info by default, like the name of the location so that there is a more progressive loading experiences for the user when showing a popup. Since the detailed information for a single point should be relatively small, the loading time should be fairly easy to keep under 1 second. I would recommend this approach for your scenario, unless there are plans for you to have a lot more than 1000 points in the future.
    2. Usually when working with large data sets 100K+ points, one approach is to do the loading of data for the current map view as you outlined, but instead of trying to figure out differences between map views, simply load all points for the new view. Sure, you could optimize it a bit with the approach you described, but if performance is the end goal, this actually plays against you as end up having to do a polygon intersection query which is more complex than a bounding box query. This can lead to longer processing times on the server side, which also reduces scalability or increases costs (to counter act the reduced scalability). That said, a couple other optimizations that are common when using this approach are: A: only load the minimum info needed to display the point (ID/coordinates like #1), then load in additional info when needed separately. B: Add server-side clustering logic to your database to group points based on zoom level so that the total number of points that are displayed when zoomed out is never a crazy amount.
    3. Another approach for working with massive datasets 100K+ (works with billions of points too), is to turn your data into a vector tile set. This basically indexes your points using the same tile structure as the map. As you move the map, the tiles needed for the current map view are loaded and include all the points. You can pre-generate the tiles and host them as a static dataset (good for static data and high-performance situations) or create a dynamic tile service that generates the tiles on the fly (good for real time or regularly changing data).

  2. IoTGirl 1,981 Reputation points Microsoft Employee
    2022-07-03T20:19:58.05+00:00
    No comments