I'm working on a openlayers3 application and we will need to reorder the display layers. I would like to be able to prevent display updates until we are finished changing the layer collection. Is that possible?
thanks, D
may be helpful:
var features = getYourFeature
or
var features = layer.getSource().getFeatures();
then do something with the features with your own business
it's a collection(array) of feature
then reset the features to the layer like this
layer.getSource().clear();
layer.getSource().addFeatures(features);
*/
Related
In my website builded with ol3, I have two or more vector layers with different sources in my map, i want to click features in a specific source and show some popup. My way is adding a single click event on my map, and using source.getFeaturesAtCoordinate(evt.coordinate) but always get empty results [].What can i do in this situation?
For points, you would need to be extremely lucky to hit the exact coordinate. You need to consider the rendered size of your points, and for that you'd better use ol.Map#forEachFeatureAtPixel(). It works on the layer, not the source:
map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
// get the source
source = layer.getSource();
// do something with the feature
});
I'm having a segment control design like this
How to design my segments so that the selected one should look like the "ALL" like in the image above. What I could think of to use different images on selection but if I do that then some part of the curve which is going in "Others" won't be visible. Any suggestion on designing UISegmentControl like this ?
I have two suggestions:
Find an alternative approach that avoids this.
A lot of apps try to add delight by designing custom components and UI when actually it doesn't really add that much to the app. At worst you might frustrate people by using non-standard components that don't work the way they expect, or increase cognitive load as they're trying to use you're app.
Go 100% with a custom subclass.
Don't just settle for setting a static background image, but invest in creating a component that not only looks like this in a selected state, but also provides animations as people change the selected item.
This is going to be a fair amount of work, but would be something like this:
subclassing UISegmentedController -- it provides the base of the functionality that you're looking for which is good;
adding a new CAShapeLayer as to the controls background layer
figuring out a dynamic bezier curve that can update for all your states (will probably end up having control points for each segment) you might be able to do this by hand, but I'd have to use a tool like PaintCode to generate the bezier curve code, and Illustrator to make the initial curve
add listeners for event changes of the segment changing, and recalculate the curve control points as needed
The positive note of this is that the path property on CAShapeLayer is animatable, so when the segment changes and the curve updates the animation will probably be the easiest part!
Hi I'm making a baseball app and I want from users to input strike zone on a grid like this:
How can I build the visual part so that I won't have too much trouble with implementation of a tap gesture recogniser. It'll be great if I can make this resizable so it will look great on many different devices.
With the touch gesture I need to handle so kind of recognizing position in two ways.
In which section the touch was detected.
What are the approximate coordinates inside this section.
This data will be saved on a cloud and can be later used to show the dot on this grid on other devices.
Is there a way to detect touch in a non rectangular shapes? Maybe with Bezier Paths.
Do you have a suggestion how ti appear on screen without using whole grid as a image. I'd rather divide it in Outer grid and the Inner grid somehow and than create all the pieces in each of this grids. 8 pieces in outer and 9 in inner grid.
You can start with UIBezierPath and its method containsPoint:, although this method "does not take into account the line width used to stroke the path." (link), it is also true for UIBezierPath.
Refer further to this article.
The hierarchy I'm using looks something like this:
FRONT
1 - layer with several features (e.g. point data)
2 - layer with several features (e.g. path data)
3 - layer with several features (e.g. region data)
BACK
When the user selects a feature in layer 3 based on an ol.interaction.Select the default behavior is to render the selected feature in front of layer 1. How can I prevent this re-ordering?
I had a nearly similiar problem, when i selected the region - the points and other vector geometries were hidden behind the selected feature. In my usecase an special styling with transparent filling was the solution.
If you want a solution based on the layer rendering i would suggest to handle it with the ZIndex. The ol.interaction.Select doesn't provide a setZIndex but if you take a look on the source code (https://github.com/openlayers/ol3/blob/v3.13.0/src/ol/interaction/selectinteraction.js) you can see that the interaction save the selected feature in an unmanaged Layer which you can access on different ways (map.getLayers().getArray().forEach .... or sth) and i'm sure there you can set the ZIndex. Note default zIndex is 0 and a higher Index will render the layer above and lower one.
Here's how the select interaction works in ol3. The selected feature is marked for being skipped in rendering. In other words, it disappears from the original layer it comes from upon re-rendering after being selected.
It is then added to an other layer that is actually not added to the map using the conventional map.addLayer method, but set to the map using layer.setMap. The layer ends up being drawn on top of all the others, resulting the "selected" feature to be on top of everything else.
This architecture was decided to improve performance. However, you can easily achieve what you want, i.e. have the clicked feature stay where it is and change its style, by simply using the map.forEachFeatureAtPixel method and implement your own concept of selection there. It would be slower, but simple enough to accomplish what you want.
I need to draw an interactive map for an iOs application. For example it can be the map of the US showing the states. It will need to show all the states in different colors ( I'll get this from a delegate colorForStateNo: ) It will need to allow the user to select a state by touching it, when the color will change, and a "stick out" effect should be shown, maybe even a symbol animated to appear over the selected state. Also the color of some states will need to change depending on external events. This color change will mean an animation like a circle starting in the middle of the state and progressing towards the edges changing the color from the current one to the one inside the circle.
Can this be done ,easily in core-graphics? Or is it only possible with Open GL ES? What is the easiest way to do this? I have worked with core graphics and it doesn't seem to handle animation very well, I just redraw the entire screen when something needed to move... Also how could I use an external image to draw the map? Setting up a lot of drawLineToPoint seems like , a lot of work to draw only one state let alone the whole map ...
You could create the map using vector graphics and then have that converted to OpenGL calls.
Displaying SVG in OpenGL without intermediate raster
EDIT: The link applies to C++, but you may be able to find a similar solution.