draw2d ManhattanConnectionRouter with explicit waypoints - draw2d

I am attempting to create a connection between two ports using the ManhattanConnectionRouter. Additionally, I want the specify the waypoints the routing should pass through as an array of x,y points.
I have tried to explicitly populate vertices like so:
let _con = new draw2d.Connection();
_con.setRouter(new draw2d.layout.connection.ManhattanConnectionRouter());
_con.vertices.clear();
_con.vertices.push(/* an array of {x,y} */);
But the line still does not follow the waypoints I specify.
I have also tried to use the route( connection, oldVertices, [routingHints] ) method for explicitly specifying waypoints:
_con.route([{x,y}, ...]);
but still the routing does not honor the waypoints.
What am I doing wrong?

Related

How to access map keys through index? Dart

dartques = {'Color':[], 'Fruits':[], 'Hobbies':[]};
How to access the values using index in map?
I need to access only key or value using index.
Just like we do in list
=>list[1]
you can get it like this
var element = dartques.values.elementAt(0);
also for Dart 2.7+ you can write extension function
extension GetByKeyIndex on Map {
elementAt(int index) => this.values.elementAt(index);
}
var element = dartques.elementAt(1);
For accessing the values by index, there are two approaches:
Get Key by index and value using the key:
final key = dartques.keys.elementAt(index);
final value = dartques[key];
Get value by index:
final value = dartques.values.elementAt(index);
You may choose the approach based on how and what data are stored on the map.
For example if your map consists of data in which there are duplicate values, I would recommend using the first approach as it allows you to get key at the index first and then the value so you can know if the value is the wanted one or not.
But if you do not care about duplication and only want to find a value based on Index then you should use the second approach, as it gives you the value directly.
Note: As per this Answer By Genchi Genbutsu, you can also use Extension methods for your convenience.
Important:
Since the default implementation for Map in dart is LinkedHashmap you are in great luck. Otherwise Generic Map is known for not maintaining order in many programming languages.
If this was asked for any other language for which the default was HashMap, it might have been impossible to answer.
You can convert it to two lists using keys and values methods:
var ques = {'Color':['a'], 'Fruits':['b'], 'Hobbies':['c']};
List keys = ques.keys.toList();
List values = ques.values.toList();
print (keys);
print (values);
The output:
[Color, Fruits, Hobbies]
[[a], [b], [c]]
So you can access it normally by using keys[0], for example.

Uri class throws error when queryParameters contains a key with a value: false?

I was working through some code, and noticed:
return new Uri(host: server, path: apiPath, query: query, queryParameters: queryParams);
This code is executed regularly throughout the application, and the only difference was queryParams. So i printed it out:
{Id:[1234], enabled:false}
shows it is a key:value set of: Id:List, enabled:boolean.
The stack trace i get is:
which shows the map and then the trace. #6 points to the above line.
It is looking at false... something with iterating false is what breaks this.
When dealing with the URI and query parameters, it is looking for numerics, lists, and strings but not booleans. In order to resolve this and allow it to function correctly, you will need to do:
{"enabled": false.toString()}
// or
{"enabled": "false"}
and the uri class will set the query parameter accordingly.
The Uri class is located in core library for Dart. When we are using it, we are passing in the created Uri object into an action for a client class,
Client client = new BrowserClient();
which accepts the url as a part of the parameters.
While looking at the errors above though, the Uri class ultimately is unable to properly parse a false value to an accepted value.
When looking at the Code Docs for Uri as per the Dart languages: https://api.dartlang.org/dev/1.25.0-dev.7.0/dart-core/Uri/Uri.html
The query component is set through either query or queryParameters. When query is used, the provided string should be a valid URI query, but invalid characters, other than general delimiters, will be escaped if necessary. When queryParameters is used the query is built from the provided map. Each key and value in the map is percent-encoded and joined using equal and ampersand characters. A value in the map must be either a string, or an Iterable of strings, where the latter corresponds to multiple values for the same key.
Which makes sense to say all values must be String or an Iterable of Strings. The only thing which I cant figure out is that in Dartpad, true and false have toString functions, and yet you can also pass numerics in there.
The only conclusion is that while it accepts Strings and Iterables of Strings, it will also parse ints and other numerics because they will explicitly check for that type as it is common to see in URI.
One would think that the URI would understand booleans since those are also common place, but that is yet to be seen since I cant take an explicit look at the source code for dartlang. I did however manage to look at the source code for it and narrowed it down. writeComponent points to _Uri._uriEncode but when looking at that function, there is no code as much as just a definition.
HTH.

How to populate SKRouteSettings.alternativeRoutesModes array in Skobbler

When I search for a route and have alternative routes option checked, skobbler will draw all alternative routes on the map and even start the navigation on the best one, if needed.
But I want to have all those alternative routes stored in an array and leave it to user to select which one he would use.
In the documentation I have noticed an array called alternativeRoutesModes.
But I don't know how exactly and when to populate it.
For a start, this is how I start making a route settings:
_route = [[SKRouteSettings alloc]init];
_route.startCoordinate = CLLocationCoordinate2DMake(43.209877, -108.966310);
_route.destinationCoordinate = _endTravelpoint.coordinate;
_route.shouldBeRendered = YES;
_route.routeMode = SKRouteCarFastest;
_route.numberOfRoutes = 5;
[[SKRoutingService sharedInstance] calculateRoute:_route];
Now, what exactly should I do with alternativeRoutesModes. Should I declare it before I call calculateRoute?
In the documentation it says:
Route calculation modes for alternative routes, an array of SKRouteAlternativeSettings objects. If nil, default alternatives will be generated.
Also, when I calculate route, only accessible objects from delegate methods are:
(void)routingService:(SKRoutingService *)routingService didFinishRouteCalculationWithInfo:(SKRouteInformation*)routeInformation
(void)routingServiceDidFailRouteCalculation:(SKRoutingService *)routingService
(void)routingServiceDidCalculateAllRoutes:(SKRoutingService *)routingService
All of this methods have SKRoutingService objects, and not SKRouteService object, from which I could pull out desired array.
Can I get an example of how to populate SKRouteSettings.alternativeRoutesModes with alternative route objects?
You can check the AlternativeRoutesViewController class in the demo project, it contains the same implementation as to what you're looking for.
The alternativeRoutesModes property can be used for advanced route configuration.
e.g. If you want to calculate 3 different type of routes(1 for pedestrian, 1 for bike, 1 for car)

passing collections as parameters with neo4j

I have been using parameters to query node indexes as such (using the rest api in java)-
final QueryResult<Map<String,Object>> result = engine.query("start nd=node:name_index(name={src}) return nd.age as age", MapUtil.map("src", "Susan");
However I haven't been able to get this to work for a collection of nodes/names. I have been trying something along the lines of-
final QueryResult<Map<String,Object>> result = engine.query("start nd=node:name_index(name={src}) return nd.age as age", MapUtil.map("src", Arrays.asList("Susan","Brian", "Ian"));
But it refuses to compile. I as wondering if there is something wrong in my syntax or that parameters are not designed to work in this context.
The name= syntax in the start is meant to do an index lookup on a property. It won't do an IN lookup. The way you can do this sort of lookup is like this (note it depends on Apache's StringUtils):
List<String> names = Arrays.asList("Susan","Brian", "Ian");
String luceneQuery = "name:("+StringUtils.join(names, ",")+")";
engine.query("start nd=node:name_index({luceneQuery}) return nd.age as age", MapUtil.map("luceneQuery", luceneQuery));
Just a note, this is the "legacy" index way of doing things. In 2.0 they've introduced label-based indexes, which work entirely differently.
Thanks a lot; though it would still only return a non empty answer when I added a space after the comma in line 2. I used-
String luceneQuery = "name:("+StringUtils.join(names, ", ")+")";
and it returned the age of one person. When I tried this:
String luceneQuery = "fs:(fs:"+ StringUtils.join(names, " OR fs:")+")";
it gave me all three ages. However, I am still unsure about whether this query will be able to leverage the usual advantages of parameters , i.e. will the engine be able to reuse the query and execution path the next time around (this time we may want to query for 4 names instead of 3)

Grails - Bind parameter to command object field of a different name

If I have a command object SomeClassCommand with a String field someField but want to bind data from a parameter params.otherField, how do I go about doing that? Is there an annotation I can put in the command object?
Actually there is a horrendous work around which defies the purpose of auto binding in your case.
def map = [:]
map.someField = params.otherField
//plus set all the other params to map
map << params
def commandObj = new SomeCommandObj()
//Explicitly bind map to command object
bindData(commandObj, map)
It really is horrendous, because you are doing extra work only to bind data. You could have directly set values to Command Object.
I would suggest either to change the command object field name or the parameter field name, which ever is controllable. AFAIK there is no annotation available unless you have your own utility to do such.

Resources