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

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);

Related

how can i add Bi directional lines in azure 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.

Trouble loading eventmarkers from csv file with anychart

I'm trying to make a graph using anygraph. It loads data from a csv file, but i am having trouble to get the eventmarkers from the same file.
I dont seem to get the mapping/source values correct for the eventMarkers.data method. My goal is to load the markers from the same csv file as the source of the graph, where 1 column will contain marker information for some dates.
Suppose i have the following csv:
date, value, optionalmarkerinfo
2021-01-01 01:00:00,2,
2021-01-01 01:00:00,3,markerinfo
and the following code:
anychart.data.loadCsvFile("export.csv", function (data) {
var dataTable = anychart.data.table(0, '');
dataTable.addData(data);
//Create table and stuff
var chart = anychart.stock(); // (the type of graph isnt correct for this data, but its only to generally give a skelet of my setup)
// more stuff where i create the first timelines graph
// then to add a marker on each timeframe:
// (data will be filtered later to only show markers on specific values of dates)
var dataSet = anychart.data.set(data);
var mappingMarker = dataSet.mapAs({date: 0});
chart.plot(1).eventMarkers().data(mappingMarker); // THIS DOESNT WORK
// finish the drawing:
chart.container('container');
chart.draw();
}
Unfortunately, the Stock data and mapping instance are not compatible with the event markers. You should apply the data directly as an array of objects. As a workaround, you can load a separated CSV file, preprocess it to the compatible format and apply it to event markers.
As a reaction to the suggestion of anychart to load a csv with the markers seperately i came to the next solution which worked:
anychart.data.loadCsvFile("markers.csv", function (data) {
var lines=data.split("\n");
var result = [];
for(var i=1;i<lines.length;i++){
var obj = {};
var currentline=lines[i].split(",");
obj["date"] = currentline[0];
obj["description"] = currentline[1];
result.push(obj);
}
// add the markers to the previously defined plot with the markers.
chart.plot(0).eventMarkers({"groups": [
{
"format": "A",
"data" : result
}
]});

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');

Anychart - CSV to table

I am trying to create a chart using anystock that will read data from a csv file. Using the built in anychart.data.loadCsvFile function doesn't give me a working chart for a stock chart while it was working just fine for a line chart. I think I need the csv file to be loaded into a properly formatted table. Is there a function for that?
Here is a sample how to do that, you can avoid creating table if the csv matches the series format and you have no need in mapping: http://jsfiddle.net/3vtszfx0/2/
anychart.onDocumentReady(function () {
anychart.data.loadCsvFile('https://cdn.anychart.com/samples-data/stock-general-features/load-csv-data/data.csv', function (data) {
// create stock chart
chart = anychart.stock();
// create plot
var plot = chart.plot(0);
// create column series on the first plot
var column = plot.column(data);
column.name('MSFT');
// set container id for the chart
chart.container('container');
// initiate chart drawing
chart.draw();
});
});
If you need mapping then: http://jsfiddle.net/3vtszfx0/1/
// create data table on loaded data
var msftDataTable = anychart.data.table();
msftDataTable.addData(data);
mapping = msftDataTable.mapAs({'x': 0, 'value': 1});
// create plot
var plot = chart.plot(0);
// create column series on the first plot
var column = plot.column(mapping);
column.name('MSFT');

OpenLayers: Zoomable WMS overlay?

I have a problem with WMS overlays in OpenLayers. Basically I just want to add data from a WMS server as an overlay and not as a base layer. This appears to be a very simple problem but I am unable to find a solution. If I set singleTile to true, the overlays appears over the whole map but you cannot zoom in. If it is set to false, only one tile is displayed at every zoom level. If I set it as a base layer, it works just fine but I really want the overlay solution so I can make it transparent and see the map behind it.
Demonstration of the problem, with a different dataset but the issue is the same:
http://jsfiddle.net/adbnC/2/
I think it might be related to some coordinate system issues but I am no expert so any help is appreciated.
Thanks a lot!
Here is the relevant section of the code that does not work as expected:
var pop_layer = new OpenLayers.Layer.WMS("Population Density in 2000",
"http://sedac.ciesin.columbia.edu/geoserver/ows", {
layers: 'gpw-v3:gpw-v3-population-density_2000',
transparent: true
}, {
opacity: 0.5,
isBaseLayer: false,
// Setting single tile to true will kind of work but than one
// cannot zoom in any more.
singleTile: false
}
);
I can't quite get what exactly is wrong here, but I think it has something to do with messed up reference systems. Here is a workaround:
Modified Jsfiddle.net
I changed the map projection to spherical mercator and now it seems to work fine for me:
var mapOptions = {
div: "map",
projection: new OpenLayers.Projection("EPSG:900913"),
units: "m"
};
map = new OpenLayers.Map('map', mapOptions);
var osm = new OpenLayers.Layer.OSM();
map.addLayer(osm);
var pop_layer = new OpenLayers.Layer.WMS("Population Density in 2000", "http://sedac.ciesin.columbia.edu/geoserver/ows", {
layers: 'gpw-v3:gpw-v3-population-density_2000',
transparent: true
}, {
opacity: 0.5,
isBaseLayer: false
});
map.addLayer(osm);
map.addLayer(pop_layer);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.setCenter(new OpenLayers.LonLat(0, 0), 2);​
Let me know if that helped!

Resources