Determining the latitude/longitude view bounds in D3 [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have something very similar to this D3 example with the difference being a single state instead of the entire country. I would like to extract the "view bounds" in latitude/longitude after the user has zoomed in to a certain degree so that I can provide information back to them on that area.
It seems it would be some combination of:
d3.geo.bounds/path.bounds (doesn't take zooming/panning into account)
the SVG's translation/scale
projection.invert?
I see a bunch of examples for lat/long points to cartesian space using the projection() function but nothing going in the other direction (e.g. clicking arbitrarily on a map -> lat/long, displaying lat/long of the center of the map which changes with zoom/pan, etc.)

D3 has the invert() function for this. It does exactly what you want it to do -- you pass it screen coordinates and it returns unprojected coordinates.
This function is a member of the projection, so as long as you're using the projection to do zoom/translate, you don't need to account for that explicitly. To get the corner points, you can simply take the center point (which you know because that's how you set the zoom) and the dimensions of the SVG.

Related

How to draw a canvas on a specific area of the screen? Also rotating that canvas? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
The problem I encounter is that I am trying to draw a canvas inside a phone which has a transparent screen which I photoshopped. The is tilted a little bit and I want to create a game in the phone screen. The problem is that I need probably to have the X and Y coordinates to point out which area the canvas must be drawn.
Best regards, Tar2ed
Code
Result
You might consider using 2 canvas objects (or a regular image for the background), to deal more easily with the two distinct 2D transforms for the 2 spaces (the background is a null-transform, while for the game canvas you will need a 2D transform that accounts for rotation and maybe perspective). So the easiest would be to use two html objects, absolutely positioned one above the other. Then you set the game canvas 2D transform matrix (you need to build or compute that starting from the screen corner points on your background image) and you are good to go.

Use Google Maps API to search nearest address from local database [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm in doubt if Maps API has something to do the following: I have a list of places in my local database. Each one with the address (street, city, state, etc...) and maybe with lat/long (I can retrieve this data if needed).
I'm looking for a solution for the case that in a webpage with a Google Maps plotted, the user enters an arbitrary address and get which is the nearest place from that local database I have.
I know I can get this address' lat/long and with some simple math (Pythagorean theorem) I can calculate each distances, but this is not the same when one need to know the distance by driving.
EDIT: I found this solution https://developers.google.com/maps/articles/phpsqlsearch_v3 and it looks a good one. Is the best approach?
You can use Distance Matrix API:
Distance Matrix API Documentation
It's easy to retrieve distances with a simple call:
https://maps.googleapis.com/maps/api/distancematrix/output?parameters
The response is in JSON or XML format depending on your choice. But there are limitations on the number of elements for a single query. You can first choose the locations around the user with a constant radius with simple math and then use Distance Matrix when the number of locations are small enough to send in a query.
The above method takes radius as parameter to search nearest locations. Instead of that you can simply get some nearest destinations and pass origin and destination to google direction api to get json or XML data. you can then extract driving distance from it.
See the link for more details: https://developers.google.com/maps/documentation/directions/#JSON

Google Map LatLng generator [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is someone know a online Google Map "LatLng" generator that can give all "LatLng" when i click and save my multiple clicks "Latlng" that i can copy.
Please help me.
I'm not sure if I understand correctly what you are looking for, but when you mean that you are looking for a way to collect the LatLng's for clicks on a map you only have to observe the click-event of the map and store the latLng-property of the click-event somewhere(e.g. in a element in the page where you can select and copy it).
Sample: http://jsfiddle.net/doktormolle/JM8H8/
Without more details, the first answer which comes to my mind is : It is impossible to get all latitude / longitude of the world. It's like if you tried to get position of all points on the Earth, that makes no sens.
If you want to test your application with a lot of markers, just generates random coordinates (in a for loop for example), then, do what you want with these coordinates.

Given a set of coordinate points, remove inner points (or find the outer ring of points) to form polygon [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
For my d3 project, I have a series of adjacent polygons, and I want to compute a new polygon that is the outside border of all the smaller polygons put together.
I have merged all the points of several connected polygons into one array to create one large polygon. But this includes all the interior edges as well as the exterior ones. I would like to remove the inner edges of this merged polygon, so that I only have a single shape representing the outside border of the area, but I can't find a proper algorithm that does this.
I found this, but it requires that the vertices of the polygon already be explicitly known; all I have is a set of points, with no distinction between outer and inner.
Once I've removed the inner points of the resulting polygon, I'd like to draw a line with "cardinal" interpolation around the outer points. This is why I must keep the integrity of the points rather than converting the polygon to arcs and using something like topojson.mesh!
Here's a screenshot to explain more clearly:
All of the vertex-points (corners of the red lines) of the green polygons were concatenated into one array of points. I want to figure out how to remove the inner points so that I can then apply a "cardinal" interpolated line around the remaining, outer points.
Mathematicians would say that you need to compute convex hull:
D3 offers interface for such algorithm.
Documentation is here. You have to read it carefully.
There is an example of usage here. Its not the same as you want, but you can get familiar with the interface by studying it.
You can probably find other examples of using D3 convex hull algorithm on the net.
Once you understand documentation and examples, you should be all set to apply your new knowledge to your problem.
If you have some other problem with code integration, you can open another question.
Hope this helps.

Find center of gravity of a group of boxes in a suspended structure [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I want to know if it's possible show a user which red dot to assign the blue circumference in order to maintain the centre of gravity of the suspended structure.
Each box has a certain angle in both of its suspending cables defined by the user.
He can assign as many boxes as he wishes.
I thought of JavaScript to make the calculus, it doesn't have to be graphic at all, the red dots have its number. The resulting of the calculus that had the most proximate result should be the choice.
I haven't found any examples that could do this, only math formulas.
Thanks in advance
Formulas ought be enough, as long as you understand them. Just three mass-weighted coordinates:
xbar = sum(M(i)*x(i))/sum(M(i))
ybar = sum(M(i)*y(i))/sum(M(i))
zbar = sum(M(i)*z(i))/sum(M(i))
The (x, y, z) are the centroids of the individual boxes, which are easy to calculate.
I would not expect to find your precise scenario in code anywhere. You'll wait a long time for that.

Categories