torsdag 21 juni 2018

Azure Maps and Turf - a perfect match

Azure Maps is a new mapping platform from Microsoft, the geometries and features following GeoJSON format and expect coordinates in WGS84. Turf is an open source library for geometry analasis and manipulation. Turf expect GeoJSON.

So I took a few minutes to play with the combination of Bing Maps and Turf and I found it as a perfect match. With just six lines of code I:

  • created a random linestring with turf (perfect for testing)
  • buffered the linestring. 
  • calculated the map extent
  • added some styling
  • added the buffer
  • focus the map to the extent and added some padding.
In fact it is a one to one line translation of the algorithm above to code! Namespace in Azure Maps is still Atlas, I don't know if that is expected to change because I believe Atlas was the project name for Azure Maps.



const lineString = turf.randomLineString(1, {bbox: [15, 61, 18, 63],
   num_vertices: 10, max_length: 0.5});

let lineBuffer = turf.buffer(lineString, 0.8);

const bbox = turf.bbox(lineBuffer);

lineBuffer.features[0].properties = {color: "rgba(0, 255, 255, 0.7)",
   outlineColor: "blue"};

map.addPolygons([lineBuffer.features[0]]);

map.setCameraBounds({bounds: bbox, padding: 100});


That's it! This could have been an difficult operation. It is not - thanks to standard formats, people and organisations adapting it.

One thing I like with Turf and Bing Maps is the ability to generate test data. In Turf it's a bit hidden in the Random section, for example randomLineString.

The industry is starting to gather around GeoJSON. At least leading players such as Micrsoft and MapBox who is also backing Turf.

When will there be a binary standard format with the same adaption as GeoJSON ? Maybe GeoBuf?




Inga kommentarer:

Skicka en kommentar