optimal zoom distance to show all polyLines at map load - google-maps-api-3

I have a map with multiple polyLines.
I want a function that I can send a group of polylines to, and it return the tightest possible zoom range to show the lines entirely.

Add all the points you want visible to an empty google.maps.LatLngBounds object (with .extend()) then run .fitBounds() on the resulting bounds.
All the points you want visible are all the vertices of all the polylines.

Related

Grid based Clustering

I am trying to do a grid based clustering, specifically where each U.S. state is a grid. What I am doing now is just setting strategy option of ClusterProvider to STRATEGY_GRID_BASED, but I don't think this is what I think it is.
I tried looking into nokia.maps.clustering.IGridOptions, but there isn't anything documentation on that.
Can someone point me in the right direction? Thanks.
A Grid-based clustering strategy just breaks the map up into squares and calculates how many markers are found in each square. What you are after is known as a Chloropleth Map. The most efficient way to do this would be to cluster server-side, return a key,value pair (i.e. state, number of markers) and just display polygons for the US States. An example of such a map can be found in the HERE Maps community examples which displays the accession dates of states to the union.
If you insist on doing everything client side then you'd have to use the following pseudo code instead:
Iterate though each marker in your list:
Check to see if it is within the hit area of an existing polygon.
If it is - increment the markers counter (an additional attribute you have added.)
If it isn't make a WKT State-level shape geocoding request, and parse the result -add a new markers counter attribute to the Polygon
repeat
You will then end up with a series of polygon objects each holding an attribute with the number of markers within found within the state.

Checking mouse event on line in Context2d

If I have line like this (a xy plot in the future)
`Canvas {
id:canvas
onPaint:{
var ctx = canvas.getContext('2d');
ctx.moveTo(0,0);
ctx.lineTo(50,20);
ctx.lineTo(50,70);
// etc...
}
}`
so, is there a good way to check mouse press event on this line? i.e. If I have a plot and want to show context menu on right click on graph line
Unfortunately, AFAIK, you should keep track of what you draw. Canvas doesn't store drawn stuff as vector graphics(again, AFAIK), but on a raster, so there's no way to get it to tell you where the lines/points are.
You could push each point you pass to ctx.moveTo and ctx.lineTo to a list or other structure. Then, on click, iterate over all line segments (designated by pairs of points you stored) and check if distance of the clicked point to the line segment is within some selection tolerance distance you want.
To check the distance, you can use this:
Shortest distance between a point and a line segment
I don't know if this is the simplest way, but it works.

How can I get the markers that are within the circle radius?

I have a map that already contains markers. I will like to be able to specific a circle radius around a specified location and select all markers that resides within.
The code to added the Circle is done. I need to know how to get the markers.
Can anyone help...
Assuming you have the markers in an array then you can calculate the distance from each of marker to the center of your circle using the computeDistanceBetween function, and add to a second array only those whose distance <= radius.

Creating an rotating cone with dynamic segments using papervision

I'm trying to create a rotating cone using papervision where all the segments can be filled with a color / image separately. So just like you can use a MaterialsList to render all the sides from a Cube separately.
Also I'd like to be able to check if a specific segment is clicked.
(if you're still listening)
Easiest way I can think of is to apply texture to cone. Use some test texture with colored squares to learn how it maps to object; then you can replace patterns to your colored segments.
If you want to get perfectly sharp boundaries between segments, you should construct your cone yourself and assign material to each segment.

How to know how many mils are currently google map is showing

i have got center of map using map.getCenter(); and i got current zoom of google map using getZoom(); please tell me how can i calculate/get current show mils area in google map. i am using asp.net and javascript.
With GMap2.getBounds() you can get the visible rectangular region of the map view.
Then using these coordinates you can construct a GPolygon object and calculate the area in square meters using GPolygon.getArea() function. Then convert given area to mils (1 meter = 39 370.0787 mils).
the GLatLng object has a distanceFrom function that takes another GLatLng. The map has getBounds from which you'll be able to get the corners of interest, and check the distance between them.

Resources