Search code examples
azure-mapsazuremapscontrol

What is the purpose/difference of the Feature class over Shape


This question is for the package AzureMapsControl.Components (which is a lightweight wrapper over Azure Maps. This package has the class Feature that is sometimes used instead of Shape? I don't see any equivalent to Feature in Azure Maps - so what is this exactly? When would you use it instead of Shape?

The main difference I see is Feature has a BoundingBox, which is another class with no matching class I can find in Azure Maps.


Solution

  • Azure Maps does have Features and Shapes. Azure Maps wraps MapLibre (based on an open-source version of Mapbox). It's a powerful map rendering library that leverages open data formats (primarily GeoJSON), but the API itself is pretty low level (has the tools you need, but requires a lot more work for common scenarios). In particular, it seems like the original scenario Mapbox targeted was for users to load all the data they needed on map load and not to update it afterwards (excluding tile data sets). There is tools to update the data in the map, but it requires reloading all of the data each time there is a data update and it can be a lot of work to get this managed correctly in larger apps. Azure Maps focused more on enabling common developer scenarios and wrapped these lower-level tools accordingly to make it easier to accomplish these tasks. A feature in Azure Maps is a raw GeoJSON object and has no methods or bindings on it. If you add a feature to the map and then modify a property on the feature, the map does not update. Azure Maps added the Shape class that wraps a GeoJSON feature and enables binding. If you change any property on the shape, the map/data source will update accordingly. There are also built-in optimizations to throttle the updates when a user updates many shapes within a loop. A DataSource can take in combination feature or shape objects. The DataSource will wrap all features it receives as a shape and you can get these from the data source if you want to make updates. Outside of the DataSource class Azure Maps tries to leverage GeoJSON for most other things, such as bounding boxes which represent an area but are not a shape (these generally are not rendered in GIS platforms, but Azure Maps does have a helper method to convert a bounding box into a polygon if needed (atlas.math.boundingBoxToPolygon). The maps camera uses GeoJSON positions and bounding box objects.

    Some important notes:

    • When clustering is enabled in a DataSource, clusters are Feature types only since they are not something you can modify and is managed directly by the map. This means that if you attach an event to a layer that has both points and clusters in it (usually these are separated, but don't have to be), the event object's shapes property will potentially have an array of both feature and shape objects, so you need to test to see if they are a shape object and handle each type accordingly (e.g. if e.shapes[0] instanceOf atlas.Shape).
    • Data in vector tiles can't be modified in the map app (you can only customize how they are displayed). As such, the internal data is only of type feature. If you add events to a layer that connects to a vector tile layer, the "shapes" in the event object will only be features.