Cannot plot polyline on D3 spinning globe - javascript

I am trying to draw a polyline path on a Mike Bostock spinning globe and animate a circle along it. So far I have learned how to do that along a polygon such as in the following example which has a circle travelling along Russia borders: http://jsfiddle.net/xqmevpjg/11/
Using the same code as in the fiddle above, I tried to add a polyline (e.g. a maritime route in Asia). My coordinates I plug in as follows:
{"type":"Feature","properties":{"name":"AsiaRoute"},"geometry":{"type":"polyline","coordinates":[[
[93.36182, 19.83325],
[92.92236, 18.58833],
[89.01123, 16.02932],
[88.26416, 12.96642],
[88.13232, 10.94591],
[90.02197, 9.47548],
[94.021, 9.43213],
[94.72412, 12.2803],
[97.36084, 12.62359],
[97.49268, 11.42013],
[96.70166, 9.17192],
[96.43799, 6.99663],
[98.41553, 5.86126],
[99.38232, 4.54836],
[100.12939, 3.23307]
]]},"id":"RML"},
This however does not work. The animation does not appear and the path is not even drawn on the globe. The only thing I can do is as follows :
(a) change the polyline to a Polygon, but then it connects the beginning to the end of the path and messes up the animation, or
(b) change geometry type to polygon once again, but this time "mirroring" the coordinates back to front so that I end up with a polygon which looks like a line. This doubles the amount of coordinates unnecessarily and then I am forced to divide my path length by 2 so that the animation stops 'half way'.
Is there a reason why I cannot simply plot the polyline as desired?? Help please :)

Be it a GeoJSON or a TopoJSON, these are the accepted values for the geometry:
Point
MultiPoint
LineString
MultiLineString
Polygon
MultiPolygon
GeometryCollection
So, in your case, change polyline to LineString or MultiLineString.
Here is the specification for GeoJSON: http://geojson.org/geojson-spec.html#appendix-a-geometry-examples
And for TopoJSON: https://github.com/mbostock/topojson-specification/blob/master/README.md#22-geometry-objects

Related

Draw circle subscribed to a polygon

We have a polygon with an irregular form (in example, a city boundaries polygon).
We need to draw a "circle" with a defined radius (ie, 4km) bound to this polygon, in other words, if point at 4km fall outside the polygon, we need to keep the polygon point as point.
I've attached a sample image, the red border is our polygon, the blue circle is what we need to get. As you can see, the blu circle doesn't exceed the polygon boundaries.
Any help?
Use floodfill algorithm to make a set of points inside the shape, then paint points form the set which are not further form center of circle than its radius.

leaflet fixed size circle on map

I am using leaflet.js to create few markers and circles. I am using the below given code to draw circles : -
L.circle([ lat, lng ], 1000, {
color : colorCode,
stroke : false,
fillColor : colorCode,
fillOpacity : 0.7
});
Now if I edit this circle on UI and drag this circle vertically downwards, the circle size increases and vice a versa. Similar issue is with calling the above given method with different lat lngs. The same radius (1000) sized circle get plotted with different sizes on map.
My requirement is to place marker with same radius with same size on map everywhere.
I checked L.circleMarker but it takes radius in pixels and also circleMarkers does not scale in zoomin zoomout events. That is why I can't use circleMarkers.
I changed the crs option to 4326 but no success. I am using imageOverlay not tileset. I have created a fiddle.
http://jsfiddle.net/newBee_/88bdrzkr/12/
Try creating a circle on top area then edit and move it downwards. It's size increases. This is what I want to stop. This will resolve the problem of generating circle of same radius via code in different area of map with same size. Please help.
Please suggest.
Edit:
It looks like this is a bug deep into Leaflet 0.x: L.Circle radius computation uses hard-coded Earth projection rather than the specified CRS. Leaflet 1.0 seems to correctly check for the CRS before using the Earth-related computation.
For your case, simply overriding the faulty method seems to fix it, at least visually.
Demo: http://jsfiddle.net/88bdrzkr/13/
The "corrected" method to include in your script:
L.Circle.include({
_getLngRadius: function () {
return this._getLatRadius();
}
});
Regarding iH8's answer, the trick to override L.CRS.Simple.scale is similar to highly zooming (the 256 factor expands the latLng to much further pixels - any high number will do). At high zoom, you are moving your circle along a very short distance, for which the latitude does not change much. So you do not see any visible difference in radius, even though the bug is still there.
Demo of using just higher zoom, no method override at all: http://jsfiddle.net/kau6g8fk/1/
For your need where the circle looks to be more like a visual aid, any of these 3 solutions is enough.
Edit: the CRS is not the issue at all.
Previous message:
If you use Leaflet for indoor mapping, as your jsFiddle suggests (or any flat type map, as opposed to the projection of a sphere like Earth on to a plane), you could simply use L.CRS.Simple
Striked out this faulty solution as pointed out by Ghybs in his answer
Very weird issue, turns out that overloading L.CRS.Simple's scale method to return 256 * Math.pow(2, zoom) fixes this. Here's a fork of your JSFiddle: http://jsfiddle.net/kau6g8fk/ I'm unsure as to the cause of this issue, it would require more research. Will do if i find the time. Found the solution here: http://codepen.io/mike_beweb/pen/BymKGe
The answer below was given before the poster edited his/her question and showed that the used CRS was L.CRS.Simple while i presumed the default CRS. I'll leave it in tact because it might come in handy for some users:
The size change on drag of your L.Circle's is because of your map's default spherical mercator projection (EPSG:3857). Best explained with an image, here's a map with a graticule overlay on every 10 degrees:
Demo on Plunker: Leaflet 0.7.5 EPSG:3857 Spherical
As you move further from the equator every plane becomes higher. Thus your circle automaticly becomes higher the further north/south you drag it. You could use a equirectangular projection (EPSG:4326), in which every plane has the same size regardless of the distance from the equator:
Demo on Plunker: Leaflet 0.7.5 EPSG:4326 Equirectangular
With equirectangle projection you won't have the problem you're having now but you'll have to change your tileset to one with EPSG:4326 projection and those are hard to come by compared to EPSG:3857 tilesets.
If you're not willing or unable to change projection another solution could be to hack around L.CircleMarker and change the radius of your markers depended on current zoomlevel. But that's rather ugly in my opinion.

How to detect or check whether a Poly Line was Inside Another Poly Line or Overlap with Other Poly Line Using Google Maps

I was using Google Maps Javascript API (GWT Maps V3 API) to some poly line in Google Maps. There are some poly line that overlap each other like in this picture:
As we can see from the picture above, there are two poly line blue and purple that overlap each other (they have the same path). Then add a red poly line among those two poly line like this:
Now I need to get all poly line that overlap / intersect with the red poly line. Is there any way I could do this in Google Maps Javascript API? Any comment and answer will be appreciated. Thanks and regards.
You could use geometry library
isLocationOnEdge(point:LatLng, poly:Polygon|Polyline, tolerance?:number)
To determine whether a point falls on or near a polyline, or on or
near the edge of a polygon, pass the point, the polyline/polygon, and
optionally a tolerance value in degrees to
google.maps.geometry.poly.isLocationOnEdge(). The function returns
true if the distance between the point and the closest point on the
line or edge falls within the specified tolerance. The default
tolerance value is 10-9 degrees.

Google Maps: Checking if a polyline passes thru a circle

I would like to ask how do I check if a certain Polyline passes thru a Circle? In the image below, the red polyline passes inside the green circle. I know it is possible to determine if a marker is within a circle but i don't know how to do it or if it is feasible for polylines.
I still have 8 reputation points so I can't post images, here's the link to the image: http://i.stack.imgur.com/0fzXu.png
Thanks in advance! :)
I'd probably do the following:
Get bound of circle.
Filter the polyline coordinates and find the points that fall into that bound.
Calculate distance between circle center and each of those points. (circle/bound center can be easily obtained by some built-in method)
If any distance < circle radius, it gives you result.
Only problem with this algo is, if your polyline goes through the circle but your list of popyline coordinates does not contain one that falls in the bound. I haven't come up with a solution for that yet :)

how to draw route line on google maps?

I want draw vehicle route line on the map, accurately on the road , but my points update after 1 min. so existing code draws line overs the buildings and so on...
any body have some solution for this ?
thanks in advance..

Categories

Resources