how to zoom/pan automatically to all features in a vector layer? - zooming

Using Openlayers, I would like to initialize the map in a position where it shows all the features in a vector layer. How to do that?

This is a little sharp/rough
map.zoomToExtent(yourVectorLayer.getDataExtent());
This may be smoother
map.panTo(yourVectorLayer.getDataExtent().getCenterLonLat());
map.zoomTo(yourVectorLayer.getDataExtent().getZoomExtent());

With OpenLayers 5.3.3 I use this code snippet:
const extent = vectorLayer.getSource().getExtent();
map.getView().fit(extent, map.getSize());

Related

Which shader to use in order to render a mesh as is?

I am using GL 2.0 (in order to display pictures that are not power of 2), and I am trying to simply render a mesh (that displays some triangles).
When using GL 1.0, I didn't have any problem, but now, I have to pass a ShaderProgram object as a parameter.
How can I make it work like it would in GL 1.0?
Should I make a shader that simply does nothing?
You have to use a vertex shader to convert world space coordinates into screen space coordinates. And you need a pixel shader to look up texture coordinates for each rendered pixel of your quad.
Look at the shaders that Libgdx uses for its SpriteBatch, they are pretty minimal texture-a-quad shaders. You can literally use SpriteBatch.createDefaultShader() to get them or just use them as inspiration for your own shaders.
The libgdx wiki page on shaders already contains an example code for a simple shader:
https://github.com/libgdx/libgdx/wiki/Shaders
I assume it's basically the same as the createDefaultShader() as in P.T.'s answer...
Hope it helps...

cocos2d/cocos2d-x: Adding tile to the layer

Please tell me how to Tilemap on the layer you want to add a tile?
Rummaged through all the documentation and did not find. How to remove a tile layer, I realized:
[_meta removeTileAt:tileCoord];
How to add a tile layer? Prompt please.
Generally I need to become an obstacle selected tile.
You can do this...by
map = CCTMXTiledMap::create("stonemap.tmx");
CCTMXLayer x=map->layerNamed("layer_name")
//layer_name is name you give to your layer Ex...backGround_Layer,Obstacle_Layer
Got answer from here where m_gid is your resources ID :)
layer->setTileGID(m_gid, tileCoord);
I believe there is a Class called CCTMXTiledMap in cocos2d-x. You can add map like this in cocos2d-x in CCLayer:
map = CCTMXTiledMap::create("stonemap.tmx");
this->addChild(map,0,tagMap);

How to use 'OpenCV' in ActionScript3?

I would like to use OpenCV in my actionScript 3 code.
Is there a way to do so ?
I have a list of coordinates to draw a polygon on a mask,
and I need a way to grow the polygon and shrink it and also to add feather to it,
using OpenCV functions (I do not want to use AS3's 'scale').
Can this be done ?
you can not use OpenCV in actionscript-3, because actionscript-3 is a advanced language, but openCV is made by C-language, it's a base language

HTML5 Canvas: Calculate the Mouseposition after Zooming and Translating

I try to develope an interactive viewer for vector drawings and want to have the feature of zooming.
The function for zooming works pretty good but now I have the problem to calculate the mouseposition for picking objects.
The event gives back the screen coordinates. The canvas doesn't have a methode to use the transformation matrix in the inverse way.
Does anyone have a solution to this problem?
I made a very small a simple class for keeping track of the transformation matrix.
I added an invert() function for reasons like this. I also made an invertPoint() function but didn't put it in the final version. It's not hard to deduce though, just invert and transform point together.
I often just calculate the appropraite transform with this class and then use setTransform, depending on the application.
I wish I could give you a more specific solution but without a code sample of what you want that'd be hard to do.
Here's the transformation class code. And here's a blog post with a bit of an explanation.
Here are some valuable functions for your library that preserve the matrix state and needed to build up a scene graph:
Transform.prototype.reset = function() {
this.m = [1,0,0,1,0,0];
this.stack = [];
};
Transform.prototype.push = function() {
this.stack.push(this.m.slice());
};
Transform.prototype.pop = function() {
this.m = this.stack.pop();
};

Generating a tone using pure javascript with Chromium WebAudio API

How can I generate a tone (pure sine wave, for instance) using only javascript and Chromium's WebAudio API?
I would like to accomplish something like the Firefox equivalent.
The Chromium WebAudio demos here appear to all use prerecorded <audio> elements.
Thanks!
The Web Audio API has what's known as the Oscillator Interface to generate the tones you're talking about. They're pretty straight forward to get going...
var context = new webkitAudioContext(),
//Call function on context
oscillator = context.createOscillator(); // Oscillator defaults to sine wave
oscillator.connect(context.destination);
oscillator.start();
You can change the type of wave by doing:
oscillator.type = 1; // Change to square wave.
or alternatively:
oscillator.type = oscillator.SQUARE;
I've written an article about this very topic in more detail, so that might be of some use to you!
Probably not these best way, but I used dsp.js to generate different types of sinusoids, then passed them off to the Web Audio API in this demo: http://www.htmlfivewow.com/demos/waveform-generator/index.html