I have a list of features and a vector layer and I need to know, whether each feature is within the bounds of the view of the map or not.
I'm using openlayers v3.9.0 and in the corresponding documentation there is a function containsExtent() (link) which takes an extent and returns a boolean. Seems to be exactly the function I'm looking for. But an error is thrown saying that containsExtent is not a function.
Uncaught TypeError: extent.containsExtent is not a function
code snippet:
// someVectorSource is of type ol.source.Vector
// allMyFeatures is an array of features of type ol.Feature
var extent = someVectorSource.getExtent();
_.each(allMyFeatures, function(feature) {
if (extent.containsExtent(feature.getGeometry().getExtent())) {
// do something
}
});
What is the problem here?
If the is a better way, to get only those features which are within the extent, in a single call without iterating through the list, would be even better.
The correct syntax is:
ol.extent.containsExtent(extent, feature.getGeometry().getExtent())
If you look closer at the doc page, you'll see that the method is a static one, not part of a ol.Extent object. FYI, there's no actual ol.Extent object in ol3. It's just an array of 4 numbers. I think ol.Extent is just a reference for the compiler.
HTH
Related
I have this method
#override
Response<BodyType> convertResponse<BodyType, SingleItemType>(
Response response) {
final Response dynamicResponse = super.convertResponse(response);
final BodyType customBody =
_convertToCustomObject<SingleItemType>(dynamicResponse.body);
return dynamicResponse.replace<BodyType>(body: customBody);
}
What does it mean <BodyType> and <BodyType, SingleItemType> in this method?
These are called generics in Dart (in fact, they are called the same in other similar programming languages).
The main idea behind generics is that you could reuse the same code without relying on a specific data/return type. Imagine List in Dart. You could have a list of integers (List<int>), a list of strings (List<String>), a list of your custom objects (List<CustomType>) - the type is not hardcoded and it could be adjusted based on your needs.
Also, you could say that it would be easier just to use dynamic or Object types that would cover most of these cases. However, generics brings you type safety, and the method type itself becomes a parameter.
Here is the official documentation about generics.
I have a serialization function that I feed data into, some times I miss an argument to the data generating function, and as a result I serialize the partially applied function. Json.Net does not throw up about this, but provides a nice empty object {}
I would like to constraint my serialization function to not accept partially applied arguments:
let mySerializer<'a when : 'a isnotafunction> (data:'a) : string =
JsonConvert.SerializeObject(data)
So far I have had no luck in finding a way of doing this.
I have two functions which return a value.
protected function createbox():player
{
var face:player = _world.CreateBody(bodydef);
return face;
}
They are identical except that they return a different variable. One returns face, the other returns eyes.
They are executed like this:
_elements.push(new Item(createbox(), new BoxSprite()));
The elements are created. But the problem comes when I try to referece face or eyes. I don't know how to reference them. They don't appear in the debug list of variables. They are null value (outside their functions).
Item is a class file. Which is also a function
public function Item(body:player,sprite:Graphic)
_elements is a vector array.
player is a class
I don't know the syntax to access face and eyes. They always return NULL or property not found no matter where you access them.
Try creating a Global variable. A global variable is available both inside and outside the function definition. So try assigning the variable out of the function and updating its value inside the function.
See example:
var face:String = "This is created out of the function";
function scopeTest(){
face = "This was updated inside the function";
}
scopeTest();
trace(face);
According to your post, faces and eyes are return objects from createbox(), which then are involved in the instantiation process of an Item object, which then is pushed into the _elements vector. Therefore, in order to access faces and eyes, you have to pass these objects to some public references during the constructor of the Item class. After that, you should be able to access them by enumerating wanted Item objects in the vector and using dot syntax on the Item objects.
I've created a MvxTableViewCell subclass that I plan to reuse at many points of my App, so I want to delegate the binding task to the creator of the cell.
So far, I got this working based on some N+1 tutorial examples, mainly this code from N=17-Collect a Bull part 3 tutorial.
So at this point, creating a cell looks like this:
return new SubtitleCell("TitleText Name; SubtitleText Subject.Descripcion"))
But I don't really like bindings defined in strings, because I usually refactor a lot and this may cause troubles in the near future, so I decided to declare the binding like a normal bindable view like this:
var cell = new SubtitleCell();
var set = cell.CreateBindingSet<SubtitleCell, SubjectGroup>();
set.Bind().For(c => c.TitleText).To(g => g.Name);
set.Bind().For(c => c.SubtitleText).To(g => g.Subject.Descripcion);
set.Apply();
return cell;
This now works like before and now it's refactor-safe, but it's six times the lines of code that I had before and the binding must be defined when the instance of the cell is already created.
I think that it can be done using MvxBindingDescription because the binding text used in the first example is parsed to a IEnumerable<MvxBindingDescription>, but I was unable to find an example or documentation about it.
Can anyone point me to the right direction?
Thanks.
EDIT:
LoC is not my biggest concern, but having to instantiate each cell before defining the binding, I'd be happy to have something like this:
var set = Mvx.CreateBindingSet<SubtitleCell, SubjectGroup>();
set.Bind().For(c => c.TitleText).To(g => g.Name);
set.Bind().For(c => c.SubtitleText).To(g => g.Subject.Descripcion);
So I can apply it later maybe like this:
var cell = new SubtitleCell();
cell.ApplyBindingSet(set);
Is there something that can be done moving this way?
UPDATE:
Just noticed that the second binding example fills my log console with this error:
MvxBind:Warning: 0.40 Unable to bind: source property source not found
Cirrious.MvvmCross.Binding.Parse.PropertyPath.PropertyTokens.MvxPropertyNamePropertyToken on null-object
Both samples seems to produce the same behavior, but the warning errors only appear using fluent binding.
MvxBindingDescription won't really help with refactoring - it operates just above the text or fluent bindings and just below the reflection level of the binding engine.
If you want Expression based binding for refactoring, then you have to use Fluent binding and pay the penalty of the extra lines of code (if you consider that a penalty)
I have a Mesh object returned from Mesh::TextFromFont and I am trying to set the color of each vertex. I am calling the vertex buffer's Lock function like this:
mesh->VertexBuffer->Lock(0, LockFlags::None);
However, this call throws an exception. Another overload of Lock seems to work fine, however it requires me to pass the rank of the returned vertex array. What is the solution here? How do I lock the vertex buffer of a mesh returned from TextFromFont?
The answer might probably lie here:
When using this method to retrieve an
array from a resource that was not
created with a type, always use the
overload that accepts a type.
In true MSDN fashion, there is no further explanation.