Graph of elevation from coordinations - here-api

I want ask you to one thing about interactive map and geo service. I need to get altitude from my coordinations points and build graph of elevation.
In google maps it looks like this:
https://developers.google.com/maps/documentation/javascript/examples/elevation-paths
I didn't found any example for this. How can I solve this problematic?
Thank you very much.
Best regards Petr Tomasek

You can build a similar elevation graph via the HERE RoutingService JS API by specifying the value of returnelevation of the routeRequestParams to true like in this snippet:
var router = platform.getRoutingService();
var routeRequestParams = {
mode: 'fastest;car',
representation: 'display',
waypoint0: '{lat, lng}', // Start of route
waypoint1: '{lat, lng}', // End of route
returnelevation: true
};
var onResult = function(result) {
var route = result.response.route[0];
/* Now, altitudes are the third values of the each shape point.
Note: Shape points returned as strings. */
var elevation_list = route.shape.map(x => parseFloat(x.split(",")[2]));
/* Now you can use the elevation_list as input data to
draw your elevation graph with any graph tool
*/
};
var onError = function(error) {
console.log(error);
};
router.calculateRoute(
routeRequestParams,
onResult,
onError
);
With the elevation values you can draw your elevation graph with any JS graph library.
Checkout the routing API: https://developer.here.com/documentation/maps/topics/routing.html

Related

How to retrive specifc Layer from Here Map JS?

I add DataPoints into Provider then into Layer which is bundled into the map.
Later I want to edit some of DataPoints, to do this I need to retrieve layer then provider from the map.
I try it by getting an array of layers but I won't know which one is a layer with my dataPoints.
let clusterDataProvider = new H.clustering.Provider(dataPoints, {
clusteringOptions: {
eps: 16,
minWeight: 2,
strategy: H.clustering.Provider.Strategy.GRID
},
theme: {
getClusterPresentation: this.getClusterPresentation,
getNoisePresentation: this.getNoisePresentation
}
})
}),
let layer = hereMap.getLayers().asArray().find(layer => layer instanceof H.map.layer.ObjectLayer)
if(!layer) {
layer = new H.map.layer.ObjectLayer(clusterDataProvider)
hereMap.addLayer(layer, 0);
}
layer.getProvider()
But ofc there can be a lot of ObjectLayers in my map, so how can I recognize which one is that with clusterDataProvider.
Or anyone has a better idea of how to edit a specific layer or cluster provider?
You can retrieve the layer by utilize this code:
function findClusterLayer(hereMap){
let layer = hereMap.getLayers().asArray().find(layer => {
let isObjLayer = layer instanceof H.map.layer.ObjectLayer;
return isObjLayer && (layer.getProvider() instanceof H.clustering.Provider);
});
return layer;
}
Unfortunately, you can't get dataPoints nor from layer nor from cluster provider, use please workaround like this:
var clusteringLayer = new H.map.layer.ObjectLayer(clusteredDataProvider);
clusteringLayer.$data = dataPoints;
later you can get datapoints like this:
var layer = findClusterLayer(map);
var dataPoints = layer.$data;
after changing some datapoints save it to cluster:
clusteredDataProvider.setDataPoints(dataPoints);
See please complete example
BTW: you can save some object into every datapoint see please documentation on https://developer.here.com/documentation/maps/3.1.20.0/api_reference/H.clustering.DataPoint.html#data

Flutter : polylines show straight line

Im implementing a flutter app to display polylines by flutter google maps plugin, But It only shows a straight line between those two points rather than showing actual route, I'm not quite sure what needed to do.
Here my add markers function
void addMarker() {
latlng.add(LatLng(5.973804, 80.429838));
allMarkers.add(Marker(
markerId: MarkerId('busLoc'),
draggable: true,
onTap: () {
print('Marker Tapped');
},
position: LatLng(5.973804, 80.429838),
));
_polyline.add(Polyline(
color: Colors.blue,
visible: true,
points: latlng,
polylineId: PolylineId("distance"),
));
Here my scaffold
GoogleMap(
polylines: _polyline,
markers: Set.from(allMarkers),
initialCameraPosition:
CameraPosition(target: LatLng(widget.la, widget.l0), zoom: 14),
mapType: MapType.normal,
),
And I'll attach screenshot below as well
To get the route from point A to point B you will need to use Directions API that is available on the google_maps_webservice flutter package, which is a service from Google Maps Platform that gives the route information
One of the route information is the overview_polyline that holds an encoded polyline representation of the route.
You can get the overview_polyline by having a function that sends request to Directions API using the google_maps_webservice package like this:
import 'package:google_maps_webservice/directions.dart' as directions;
final _directions = new directions.GoogleMapsDirections(apiKey: "YOUR_API_KEY");
var overviewPolylines;
directions.DirectionsResponse dResponse = await _directions.directionsWithAddress(
_originAddress,
_destinationAddress,
);
if (dResponse.isOkay) {
for (var r in dResponse.routes) {
overviewPolylines = r.overviewPolyline.points
}
}
Then, once you get the overview_polyline from Directions API using the sample code above, you will need to decode it using the PolyUtil(); method from the google_maps_util flutter package like this:
import 'package:google_maps_util/google_maps_util.dart';
PolyUtil myPoints = PolyUtil();
var pointArray = myPoints.decode(overviewPolylines);
Once decoded you can pass the pointArray to your polyline object like this:
_polyline.add(Polyline(
color: Colors.blue,
visible: true,
points: pointArray,
polylineId: PolylineId("distance"),
));
it shows straight line because you have in your polyline only two points, so the expected behavior is to draw a line from one point to the other
you have to use google direction API here is an article explains how to draw route between two points in flutter.
https://medium.com/flutter-community/drawing-route-lines-on-google-maps-between-two-locations-in-flutter-4d351733ccbe

Geometry has too many edges (Google Earth Engine). Help me

I have problem during working in Google Earth Engine. I was processing some vector files. And i am getting below code:
The geometry has too many vertices. You can try to simplify it using:
// Get a feature collection and subset the first feature.
var feature = ee.FeatureCollection("TIGER/2018/States").first();
// Simplify the feature - think of max error as resolution.
// Setting to 100 means that the geometry is accurate to
// within 100 meters, for example.
var featureSimple = ee.Feature(feature).simplify({maxError: 100});
or for a ee.FeatureCollection:
// Get a feature collection.
var featureCol = ee.FeatureCollection("TIGER/2018/States");
// Simplify each feature in the collection, by mapping the
// .simplify() function over it.
var simplifiedCol = featureCol.map(function(feature) {
return feature.simplify({maxError: 100});
});

Here Map JS cluster marker remove option

On map using cluster layer to display the marker , on API call loading the data on reload i need to clear clustered marker in the map please help on this issue,normal marker to clear using current method (map.removeObjects(map.getObjects()) it working as excepted but i need remove default cluster marker
Please find the below code :
startClustering(map, data) {
// First we need to create an array of DataPoint objects,
// for the ClusterProvider
// tslint:disable-next-line:ter-prefer-arrow-callback
const dataPoints = data.map(function (item) {
console.log('item>>>>', item);
return new H.clustering.DataPoint(item.y, item.x);
});
const clusteredDataProvider = new H.clustering.Provider(dataPoints, {
clusteringOptions: {
// Maximum radius of the neighbourhood
eps: 1,
// minimum weight of points required to form a cluster
minWeight: 2,
},
});
// Create a layer tha will consume objects from our clustering provider
const clusteringLayer = new H.map.layer.ObjectLayer(clusteredDataProvider);
// To make objects from clustering provder visible,
// we need to add our layer to the map
map.addLayer(clusteringLayer);
}
i need to remove this cluster marker before call this funcation
The easiest approach will be to keep a reference to the cluster layer you wish to remove and then remove it by:
Given a reference called clusteringLayer:
map.removeLayer(clusteringLayer);
The other alternative of using map.getLayers() to retrieve all map layers and removing each layer via map.removerLayer(<layerRef>) might remove layers you do not wish to remove.

Path colouring in google maps

I wanted to know if is it possible to change the colors of the path displayed in the Google Maps APIv3 specially in the TRANSIT section where different using modes like BUS, RAIL and WALKING are used for displaying the result.
Can I change the displayed color of these different modes? Currently it is Black for walking and sky blue for other modes.
My code is:
function calcRouteM()
{
var start = document.getElementById('DropDownList1').value;
var end = document.getElementById('DropDownList2').value;
var request = {
origin: start,
destination: end,
provideRouteAlternatives: true,
unitSystem: google.maps.UnitSystem.METRIC,
travelMode: google.maps.DirectionsTravelMode.TRANSIT,
transitOptions: {
departureTime: new Date(1362799800000)
}
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
You can change the colors of the Polylines if you don't use the DirectionsRenderer to display them and render them yourself.
The DirectionsRendererOptions {suppressPolylines: false}
suppressPolylines | boolean | Suppress the rendering of polylines.
Then process through the results object creating Polylines with your desired colors.
Example of custom rendering a route (you probably only need to do the polyline)
Another option might be (not tested) to post process the returned route, sending the different colored pieces to different DirectionsRenderer calls with different values (colors) for the polylineOptions option.

Resources