how can i add Bi directional lines in azure maps - maps

is there any way we can add two polylines between two coordinates
new atlas.data.LineString([[point A],[point B]])
new atlas.data.LineString([[point B],[point A]])
like this
currently it shows only one line when i add this to data source

If you have one linestring and you want a second linestring with coordinates in the opposite order, you can create a deep copy of the linestring, and then reverse the coordinate array, then add the lines to the data source. For example, if you have a GeoJSON linestring object:
var line = new atlas.data.LineString([[-73.972340, 40.743270], [-74.004420, 40.756800]]);
//Create a deep copy of the line.
var newLine = JSON.parse(JSON.stringify(line));
//Reverse the order of the coordinates in the new line.
newLine.coordinates.reverse();
As you noted, these lines will overlap when rendered. What you can do to add a visual separation, turn one of these into a GeoJSON feature and add a unique property that can be seen by the data driven styles, then use the offset option of the LineLayer. For example:
//Create a feature from the line and add some property we can use to know this is a reverse copy of a line when styling.
var newFeature = new atlas.data.Feature(newLine, { isCopy: true });
//Add the feature to the data source instead of the new line.
datasource.add(newFeature);
//Have two-line layers with a filter
//Line layer for original lines.
map.layers.add(new atlas.layer.LineLayer(dataSource, null, {
strokeColor: 'green',
strokeWidth: 1,
offset: -2,
filter: ['!', ['has', 'isCopy']]
}));
//A second line layer that renders the line copies
map.layers.add(new atlas.layer.LineLayer(dataSource, null, {
strokeColor: 'red',
strokeWidth: 1,
offset: 2,
filter: ['has', 'isCopy']
}));

if it is just the Polyline you want to plot between points and indicate with two different colors, you can use the offset property of LineLayerOptions and plot the lines using the following JavaScript.
var dataSource = new atlas.source.DataSource();
map.sources.add(dataSource);
//Create a line and add it to the data source.
dataSource.add(new atlas.data.LineString([[-73.972340, 40.743270], [-74.004420, 40.756800]]));
//Create a line layer to render the line to the map.
map.layers.add(new atlas.layer.LineLayer(dataSource, null, {
strokeColor: 'green',
strokeWidth: 1,
offset: -2
}));
map.layers.add(new atlas.layer.LineLayer(dataSource, null, {
strokeColor: 'red',
strokeWidth: 1,
offset: 2
}));
});
The above JavaScript would produce the following Ploy Lines on Azure Maps.
Optionally, you can add a distinct data source if you prefer and map the layers for each data source. But you can achieve the same output by using a single data source as indicated above.
I have built the JavaScript code based on the Azure Maps documentation Add Line Layer to the Map where you can find great code references to add symbols and line gradients. Here is the link to the LineLayers interface which provides a list of options that you can use when rendering line layers in Azure Map.

Related

is there anyway we can add curved polylines in azure maps js

I used offset property of linelayer in azure maps but it didn't worked
var polylines = new atlas.layer.LineLayer(datasource2, null, {
strokeColor: 'DarkOrchid',
strokeWidth: ['sqrt',['sqrt',['to-number', ['get', 'count']]]]
,
filter: ['any', ['==', ['geometry-type'], 'LineString'], ['==', ['geometry-type'], 'MultiLineString']],
});
You need to use the atlas.data.Curve class. This class allows you to create a curved line by specifying a set of control points. You can then add this curved line to a data source and render it using a line layer. Here is an example:
//Create a data source and add it to the map.
var dataSource = new atlas.source.DataSource();
map.sources.add(dataSource);
//Create a curved line and add it to the data source.
dataSource.add(new atlas.data.Curve([
[-73.972340, 40.743270],
[-74.004420, 40.756800],
[-74.013530, 40.722300]
]));
//Create a line layer to render the line to the map.
map.layers.add(new atlas.layer.LineLayer(dataSource, null, {
strokeColor: 'DarkOrchid',
strokeWidth: 5
}));
To curve a line there is a couple of options. If you want the line to follow the curvature of the earth, you can calculate the coordinates that form a geodesic path. There is a built-in method of this in the atlas.math namespace called getGeodesicPath. For example:
var line = new atlas.data.LineString([[-74.00667,40.754572],[-42.75286,-22.752037]]);
//Convert the coordinates to create a curved geodesic path.
line.coordinates = atlas.math.getGeodesicPath(line);
//Add line to data source.
datasource.add(line);

How to avoid table data splitting between two pages using jspdf

Is there a way to fix data splitting between two pages (I've posted the image of the issue below). I'm passing a template to doc.html() and im using jspdf to generate a pdf file. Everything is displayed as it should except the table data - the table data splits between two pages (see image below).
This is the part of the code to generate the pdf. HTMLTemplate is html template im passing to it (divs and tables with data)
let doc = new jsPDF("p", "pt", "a4");
doc.html(renderToString(<HTMLTemplate />), {
margin: [20, 0, 20, 0]
async callback(doc) {
// save the document as a PDF
doc.save(name_pdf_file, { returnPromise: true }).then(SetValue()); // Ignore this
},
});

Azure maps layers are getting on top of each other

I'm using azure map.
What's happening is that I have 2 layers. A layer that have Circles and a layer with polygons.
I have a functionality in which a popup appear when I click on a specific circle.
The issue occur when I add the polygon layer after the circle layer.
It's like the polygon layer is being drawn on top of the circle layer. In which it prevent the popup from appearing when clicking on the circle.
Here's how I'm adding the polygon layer:
showFetchedResultOnMap(facilities) {
const self = this;
if (facilities && facilities.length > 0) {
self.cleanRestrictionLayer();
//Create a data source and add it to the map.
self.datasource = new atlas.source.DataSource();
self.map.sources.add(self.datasource);
//Add a data set to the data source.
self.CleanMap();
//Create a data source and add it to the map.
var datasource = new atlas.source.DataSource();
self.map.sources.add(datasource);
self.map.imageSprite.add(self.chosenCategory, 'assets/svg/' + self.chosenCategory + '.svg')
.then(function () {
facilities.forEach(cat => {
datasource.add(new atlas.data.Feature(new atlas.data.Point([cat.longitude, cat.latitude])));
});
//Add a layer for rendering point data as symbols.
self.map.layers.add(new atlas.layer.SymbolLayer(datasource, self.chosenCategory, {
iconOptions: {
//Pass in the id of the custom icon that was loaded into the map resources.
image: self.chosenCategory,
//Optionally scale the size of the icon.
size: 0.1
}
}));
});
}
}
Anyone have an Idea about how I can fix this??
I'm not seeing a polygon layer in the code you provided. That said, when you add layers to the map, the order in which you add them is the z-index by default. Last one added goes on top. That said, when adding the layer using the map.layers.add function, there is a second parameter you can add in which can be another layer or layer id. When this is specified the layer you are adding will be inserted below that second specified layer. Here is the doc on this: https://learn.microsoft.com/en-us/javascript/api/azure-maps-control/atlas.layermanager?view=azure-maps-typescript-latest#add-layer---layer----string---layer-
Here is a short example:
map.layers.add(new atlas.layers.BubbleLayer(datasource, 'myBubbles'));
map.layers.add(new atlas.layers.PolygonLayer(datasource, 'myPolygons'), 'myBubbles');

Adding and Deleting Multiple Polygons in Google Maps with React - Getting Refs Right

I'm using google-map-react (not react-google-maps), and is able to insert polygons by calling a function polygonDraw within my main Component (not using drawingManager). My function polygonDraw can be seen below.
I can immediately delete the newest polygon by adding polygon.setMap(null) inside my polygonDraw function.
But here is the problem:
I can't delete previously added polygons or all polygons. My need is to be able to delete all polygons and do this without dependency on event handlers (like a click event on a polygon).
I tried different approaches, but had no successful implementation, including:
I'm not able to construct a Polygon component that render new google.maps.Polygon({.etc.}) objects (based on state/props).
As I'm able to insert polygons with my polygonDraw function my current thinking for strategy is:
To establish a reference for each added polygon. I tried implementing React references, including Callback refs and using React.createRef. But no success. My polygonDraw is inside the main component, but outside the render. I can't figure out if it's possible to establish and store a reference to each added polygon, so reference.setMap(null) can be called for each. And if it is possible I don't know how to establish the reference (code inside constructor?, code inside polygonDraw?, code inside render including GoogleMapReact?)
Any help/advice is appreciated :-)
polygonDraw = () => {
let polygonCoords = [{lat: this.state.lat, lng: this.state.lng}, {.etc.}, {.etc.}]
const polygon = new google.maps.Polygon({
paths: [polygonCoords],
fillColor: 'rgb(255, 215, 0)',
});
polygon.setMap(this.state.map.map);
}
render() {
return (
<GoogleMapReact
.etc.
></GoogleMapReact>
)}
I don't know if it cuts down to performance issues, but what about saving the polygons into an array.
// You have to create a store (eventually in the state?)
const polygons = [];
polygonDraw = () => {
let polygonCoords = [{lat: this.state.lat, lng: this.state.lng}, {.etc.}, {.etc.}]
const polygon = new google.maps.Polygon({
paths: [polygonCoords],
fillColor: 'rgb(255, 215, 0)',
});
polygon.setMap(this.state.map.map);
// Then use this to save it to the polygons
polygons.push(polygon);
// OR this if you want
polygons.push({identifyer: "foo", polygon});
}
Afterwards you can just filter through the polygons array and delete the polygons you need.
I don't know if this solution will work, but you can give it a try :)

How to provide tooltips for multiple line charts

I'm converting existing code that displays a single line graph to display multiple line graphs at once. I would like each line graph to have tooltips. My code looks like this:
var line = new RGraph.Line('canvas', data).Set('tooltips', tips)
I can make multiple line graphs render by changing the data array from 1-dimension to 2-dimensions.
But I have also converted the tips array to 2-dimensions, and no tooltips are appearing at all.
Am I correct in assuming that the tips array is assumed to be 1-dimensional, and if so how do I specify tooltips for multiple line charts?
Give them as one big array. If you have them in multiple arrays you can use the JavaScript concat() function or you just add them together like below.
Here's an example without using the concat function:
new RGraph.Line({
id: 'cvs',
data: [
[8,4,3],
[9,8,1]
],
options: {
tooltips: ['A', 'B','C','D','E','F']
}
}).draw();
And here's an example using concat():
tooltips_a = ['A', 'B','C'];
tooltips_b = ['D','E','F'];
tooltips_combo = tooltips_a.concat(tooltips_b);
new RGraph.Line({
id: 'cvs',
data: [
[8,4,3],
[9,8,1]
],
options: {
tooltips: tooltips_combo
}
}).draw();

Resources