Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetCoords function not working properly, what I'm doing wrong? #412

Open
CristianEstiber opened this issue Dec 2, 2019 · 0 comments
Open

Comments

@CristianEstiber
Copy link

CristianEstiber commented Dec 2, 2019

I'm trying to create a new map, calculate the x = xFactor + longitude + xOffset and y = yFactor * latitude + yOffset but at the end its not working fine, here is my map with points places like this picture https://www.vincentbroute.fr/mapael/assets/img/create-map-2.png:

image

here is on the getcoords function:

image

And finally my code the map:

`<script type="text/javascript">
/*!
*
* Jquery Mapael - Dynamic maps jQuery plugin (based on raphael.js)
* Requires jQuery and Mapael >=2.0.0
*
* Map of andorra
*
* @author cristian
*/
(function (factory) {
if (typeof exports === 'object') {
// CommonJS
module.exports = factory(require('jquery'), require('jquery-mapael'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery', 'mapael'], factory);
} else {
// Browser globals
factory(jQuery, jQuery.mapael);
}
}(function ($, Mapael) {

    "use strict";
    
    $.extend(true, Mapael,
        {
            maps :  {
                andorra : {
                    width : 269.71396,
                    height : 218.48477,
                    getCoords : function (lat, lon) {
                    var xfactor = -2.9120879120879;
                    var xoffset = 479.67032967033;
                    var x = (lon * xfactor) + xoffset;
                    var yfactor = 0.093023255813953;
                    var yoffset = 54.720930232558;
                    var y = (lat * yfactor) + yoffset;
                        
                    return {'x' : x, 'y' : y};
                	},
                    'elems': {
                        "path4230" : "m 66.41,216.54 c -12.3,-3.74 -26.02,-2.38 -38.04,-7.6 -6.27,-5.19 -3.89,-14.61 -3.07,-21.96 -5.82,-6.09 -1.76,-23.29 -16.31,-20.78 -8.96,1.72 -11.42,-6.36 -1.64,-8.28 10.73,-0.43 21.01,-2.35 27.71,-11.42 3.74,3.56 9.62,6.54 10.24,12.4 0.05,13.54 14.01,12.85 23.9,12.01 7.27,-3.16 23.16,-5.46 26.47,3.86 4.3,8.86 15.74,15.3 9.89,26.91 -2.24,8.68 -4.87,16.78 -15.83,14.2 -7.92,0.46 -15.59,4.96 -23.31,0.66 z",
                        "path4232" : "m 98.58,178.76 c -2.01,-15.85 -22.26,-12.02 -32.67,-8.47 -11.09,1.49 -19.87,-2.58 -20.58,-14.54 -7.33,-7.05 -12.13,-13.14 0.75,-17.03 10.75,-1.7 20.93,-4.28 30.97,-8.77 8.8,-0.83 10.77,14.49 15.82,20.21 0.46,10.29 19.3,20.53 8.63,28.78 l -1.31,0.61 z",
                        "path4234" : "M 41.28,138.78 C 35.28,128.98 32.59,115.19 24.52,108.09 17.02,104.03 -1.97,122.63 5.53,106.87 5.48,93.68 20.15,91.87 24.65,82.53 16.59,76.88 6.7,66.73 20.44,59.48 c 1.47,-7.74 5.22,-10.82 13.32,-9.51 8.48,-7.52 19.65,4.78 26.87,8.82 -1.33,14.01 7.17,24.56 16.05,33.93 2.27,5.72 0.24,13.08 7.93,10.01 7.34,5.23 30.76,-3.2 17.72,11.35 -3.93,7.16 -5.42,17.23 -16.43,12.85 -12.42,0.96 -22.86,9.71 -35.48,9.42 -2.74,0.35 -6.77,3.27 -9.14,2.42 z",
                        "path4236" : "M 90.8,103.79 C 83.52,101.11 77.11,103.69 78.09,93.26 73.02,83.65 60.73,77.23 62.39,64.49 64.41,51.89 48.74,53.11 42.43,46.11 53.46,39.25 42.39,28.13 42.87,19.37 49.28,13.81 49.36,-6.7 60.97,4.6 69.97,14.75 82.34,2.93 92.29,1.8 102.43,-3.12 117.05,2.48 120.14,13.8 c 6.43,7.93 19.79,10.2 20.62,22.08 -6.87,8.75 -23.22,12.26 -24.3,25.91 -10.87,8.98 -1.76,24.07 -0.91,35.56 -2.36,11.57 -16.7,4.7 -24.75,6.44 z",
                        "path4238" : "m 141.29,104.88 c -6.89,-2.51 -23.1,-0.1 -25.08,-5.73 1.91,-10.61 -7.21,-20.57 -3.02,-31.51 5.99,-9.88 11.24,-20.98 22.94,-26.19 12.61,-0.03 -2.76,-16.02 7.46,-15.17 10.65,3.23 23.51,-6.78 31.8,3.32 3.14,5.65 9.57,4.54 14.6,1.93 8.81,-4.54 19.91,0.11 26.89,6.22 5.86,0.53 12.45,-0.51 17.86,0.19 -1.61,7.68 -16.78,24.81 -2,26.5 11.76,4.26 22.94,9.3 35.23,7.63 5.78,13.83 -16.68,13.06 -24.73,16.01 -6.17,3.61 -6.17,12.96 -14.3,7.37 -6.14,4.2 -11.12,-5.08 -19.43,-2.44 -12.47,-2.31 -20.86,3.41 -30.15,10.88 -10.19,-3.16 -21.38,-9.28 -29.28,2.06 -2.88,1.24 -6.01,-0.24 -8.78,-1.07 z",
                        "path4240" : "m 210.32,158.1 c -9.76,-7.91 -22.29,-0.63 -32.95,-1.74 -12.29,-2.78 -24.26,-7.83 -36.36,-6.37 -11.1,-4.36 -18.17,-20.71 -31.28,-17.69 -13.23,11.73 -13.74,-15.94 -4,-20.96 5.33,-14.69 19.5,-5.49 30.4,-6.68 9.81,5.94 17.78,-0.16 25.69,-5 10.44,4.65 23.03,8.57 30.17,-3.94 8.56,-1.81 19.81,-2.41 29.62,-0.36 0.9,6.45 17.05,-2.94 11.71,6.63 -2.04,9.98 2.61,23.48 -7.23,30.04 0.58,7.52 0.85,18.4 -8.11,23.26 -2.21,1.22 -4.9,5.51 -7.65,2.82 z",
                        "path4242" : "m 117.79,195.92 c -4.22,-6.76 -16.69,-5.88 -15.19,-16.61 10.83,-7.96 -7.02,-18.51 -8.17,-27.92 -3.82,-8 -8.01,-16.48 -12.87,-22.94 4.9,1.43 16.12,-4.38 16.7,3.28 4.68,13.06 16.06,-6.34 23.44,4.81 8.85,7.58 18.57,18.44 31.18,14.41 9.42,2.85 18.97,5.22 28.48,7.71 -2.47,8.31 2.17,24.83 -11.98,22.9 -9.82,1.07 -19.3,4.14 -29.47,1.8 -6.09,-2.02 -12.94,1.17 -14.78,7.61 -1.63,2.85 -3.02,9.93 -7.35,4.96 z"
                    }
                }
            }
        }
    );

    return Mapael;

}));

</script>`

The map generation with points (p5 point is the real location):

<script type="text/javascript"> $(".container").mapael({ map : { name : "andorra", defaultArea: { attrs: { stroke: "#fff", "stroke-width": 1 }, attrsHover: { "stroke-width": 2 } }, defaultPlot : { size:5, attrs: { fill:"red", stroke:"white", "stroke-width":2, opacity:1 } } }, areas: { "path4230": { value: "2617939", href: "#", tooltip: {content: "<span style=\"font-weight:bold;\">Santa Julia de Loria (5)</span><br />Population : 2617939"} }, "path4232": { value: "2268265", href: "#", tooltip: {content: "<span style=\"font-weight:bold;\">Andorra la Vella (6)</span><br />Population : 2268265"} }, "path4234": { value: "2617939", href: "#", tooltip: {content: "<span style=\"font-weight:bold;\">La Massana (7)</span><br />Population : 2617939"} }, "path4236": { value: "2268265", href: "#", tooltip: {content: "<span style=\"font-weight:bold;\">Ordino (1)</span><br />Population : 2268265"} }, "path4238": { value: "2617939", href: "#", tooltip: {content: "<span style=\"font-weight:bold;\">Canillo (2)</span><br />Population : 2617939"} }, "path4242": { value: "2268265", href: "#", tooltip: {content: "<span style=\"font-weight:bold;\">Escaldes-Engordany (4)</span><br />Population : 2268265"} }, "path4240": { value: "2268265", href: "#", tooltip: {content: "<span style=\"font-weight:bold;\">Encamp (3)</span><br />Population : 2268265"} } }, plots: { p1 : { x:55, y:3 }, p2 : { x:270, y:73 }, p3 : { x:5, y:163 }, p4 : { x:75, y:218 }, p5 : { x:42.5787088, y:1.6668454 } } }); </script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant