How to find latitude and longitude using jVector Map Plugin

I know there are markers on google maps to highlight specific points on the map. For some reason, it’s not convenient for me to put this type of map on my website and to like the effects of the jvector map. But I can’t understand how to define markers in jVectorMap, does anyone know how to define markers in jVectorMap and highlight these points. I would also like to know how you get to a specific point on the jVector map using latitude and longitude.

Thanks.

+6
source share
3 answers

Now you can do it, the new version of jVectorMap (0.2) introduces such a function with the markers parameter. Check out the demo here http://jvectormap.com/examples/markers-world/ .

+5
source

The jVectorMap world map uses a van der Grinten projection. The formula for converting from / to the map can be found here Wikipedia and Wolfram .

You will need to scale it to the size and offset of the map, given the above formula: long / lat (-180 to 180 degrees) to a Cartesian grid (-1 to +1).

In addition, the angles in the formula must be in radians, not degrees.

 function vanDerGrinten(lat, lng) { lat = lat * Math.PI / 180; lng = lng * Math.PI / 180; var lng0 = 0; var A1 = 0.5 * Math.abs((Math.PI / (lng - lng0) - (lng - lng0) / Math.PI)); var phi = Math.asin(Math.abs(2 * lat / Math.PI)); var G = Math.cos(phi) / (Math.sin(phi) + Math.cos(phi) - 1); P = G * (2 / Math.sin(phi) - 1); Q = A1 * A1 + G; x0 = A1 * A1 * (G - P * P) * (G - P * P) - (P * P + A1 * A1) * (G * G - P * P); x1 = (A1 * (G - P * P) + Math.sqrt(x0)); x2 = (P * P + A1 * A1); x = sgn(lng - lng0) * Math.PI * x1 / x2; y = sgn(lat) * Math.PI * Math.abs(P * Q - A1 * Math.sqrt((A1 * A1 + 1) * (P * P + A1 * A1) - Q * Q)) / (P * P + A1 * A1); return { _x: x, _y: y }; } 
+3
source

The jvector aspect is just a vector mapping. You will need to create some type of correspondence between lat / lng and your vector space (for example: 1px = 1deg). This will require either map setup or some accurate measurements to set the scale. Not to mention that you need to be sure that you are using the projection of the Mercator , so that parallel lines even mean that you think about them;)

EDIT: if you had problems with google maps, I would recommend using an alternative, for example, leaflet , without trying to expand the jVector map to do two things (story points and draw on a scale) that it should not have done.

0
source

Source: https://habr.com/ru/post/900363/


All Articles