Get bounding box / extent of visible map tiles in d3 - d3.js

Let's say I have a standard tiled map like this: http://bl.ocks.org/mbostock/4132797
How can I get the bounding box coordinates of the visible map?
In other words, how can I say exactly the extent of the map shown at any given time. I understand this as a bounding box but also as an extent.
Thank you.

I was able to find answers to similar but specific questions but am leaving this up in case someone is searching for the general case.
From Elijah Meeks's answer:
To find the bounding box of the visual area of your map on screen,
simply use the projection.invert() function and feed it the top-left
and bottom-right corners of your SVG. If you have a 500x500 SVG, then
that looks like this:
projection.invert([0,0]) projection.invert([500,500]) This is a
bounding box of your screen, in lat-long (or whatever coordinate
system you're using).
After that, you can get the bounds of your features and test to see if
they are fully-contained or intersecting or have their centroid within
those bounds. I'm not going to explain how to do that here, because
that's a different question with many different answers depending on
which definition of "within these bounds" you decide on.
So, plug in the width and heightof the visible area into the projection generator. Voila, you have the box.

Related

Building custom Shapes in Konva

I've been asked to build something similar to this so that customers can draw basics shapes of kitchen tops. Similar to that in the image below but also have dimensions.
It looks like konva has support for basic shapes like rectangle and circle etc and it also includes a transformer which allows for resizing. However, I think if I want to build a custom shape like the one in green and have individual sizing i.e. resize each individual line. I am going to have to build something myself.
I was hoping someone could point me in the right direction. I have seen an example where someone has used a "line" class which takes a series of points and then sets the attribute to closed which fills in the shape. Obviously I would need to extend this to allow the custom resizing. However, Im not sure this is the correct path to head down?
Any suggestions?
.
How about using rectangles and having an option to snap them together. It should be fairly simple to do the edge detection and snapping. Then show the result as a Konva.Line around the perimeter.
Then you can show all the control handles for the rectangles except those on the sides where another Rect has joined.

How to achieve Custom Gradient Shapes/Patterns in Flutter

Out of the box we get LinearGradient, RadialGradient and SweepGradient. What I would like to do is something similar to the shown image below. Let's say we draw a custom shape with CustomPainter. When this customShapeGradient is applied on it, the gradient should start from the border of the custom shape and go towards the center. I realize that this might introduce wierd effects since our shape will mostly be not symmetric and a "border to center" approach is not as easy as a "center to border" approach(like the 3 out of the box methods). Here it will be the developer's responsibility to make sure the gradient fill do not overlap with itself, meaning it won't go all the way to the center.
Here is an image I found for an Elliptic shape which most closely describe what I want. Let's say our shape is the line with the yellow color. And I want to achieve the gradient which fills inside.
This is a similar image too:
The two examples I have provided are for ellipses however my question is for any type of shape that is created by a CustomPainter.
I am almost sure this is possible since a shadow(gradient in nature) is basically the inverse of this. We can apply a shadow to a CustomPainter shape. The only difference will be that the shadow will grow towards inside of the shape(maybe like a inner shadow).

how to limit an image to it's real shape

How can I use an image that whenever I want to make a collision in XNA, it happens only for area of the shape not around of it.
For example when I use below picture, I want collision detection happens only when arrow in shape is touched.
The collision detection happens in the area in this picture
How can I make limitation for area of image only?
What you can do is also to create two rectangles. That makes the overlapping area (the area there the image isn't but the rectangle) a bit smaller. But if you need to do this pixel excact you have to use the recource-expensive per-pixel-collision.
You shouldn't try restricting the image shape, because regardless of your efforts - you will have a rectangle. What you need to do is work with detecting pixel collisions. It is a fairly extensive topic - you can read more about a Windows Phone-specific XNA implementation here.

jqPlot axis with ticks labeled differently from underlying data

So I am using jqPlot to display distance (y-axis) over time (x-axis) in a simple line graph.
However, while I have actual distances as the underlying data used to position the points, I'm not interested in displaying those distances on the y-axis.
Instead, there are a series of landmarks at given distances, that I want to appear on the y-axis as a 'tick' next to the appropriate point for the distance to that landmark. That way the line appears to "pass" each landmark as it travels upward.
Currently I'm "faking" this by hiding the ticks and putting a manually-created series of labels next to the graph. This works well enough, but I had to disable vertical zooming because if the user chose to zoom in, the labels would not match up with the actual distances. My users would really like to zoom in vertically, however, and I want to allow them to.
Therefore, does anyone know of a way (a plugin or similar) that would allow me to associate custom labels with given tick marks in jqPlot, that will match up nicely and respond to zooming? It would be necessary to hide some of the landmarks if the graph is zoomed out too much, so that would have to be a feature.
Alternatively, if someone knows of a "zoom event" that passes in the min and max y values, I could probably recreate my manual labels with that data, so let me know if you know of a way to get that information. I haven't been able to find one.
I would need to see a bit of your code to customize it to the distance but to start with you could label the ticks and it will display over the size of the chart.
axes:{yaxis:{ticks:['DiscanceA','DiscanceB', 'DiscanceC', 'DiscanceD', 'DiscanceE'],
renderer: $.jqplot.CategoryAxisRenderer,},
Let me know how it goes and if you have any code lets see it!

How do you mask an arbitrary area of an image to overlay another image?

I want to mask an arbitrary convex polygon area of an image and put another image into that area. I found this posting, but is wasn't clear to me if this applies only to rectangular areas and not arbitrary polygons.
The basic flow I am talking about is to have an (x,y) coordinate on the screen which would serve to be the center of my polygon (center in terms of an arbitrary point which is consistent for me). I would like to mask this area where the new image (polygonal in nature) would be displayed while leaving the rest of the screen as is.
Can I do this easily and quickly?
You have to use stencil buffer. It's basically another type of buffer that has plethora of awesome applications and one of the simplest one is masking. While I can't recommend any OpenGL ES specific tutorial off the top of my head, I highly recommend reading general tutorials, since it's not that different and surely is fascinating.
Try glScissor... it might be the rectangle you want.

Resources