Đinh Hồng Châu
Đinh Hồng Châu

Reputation: 5430

jVectorMap: How to add marker dynamically by coordinates?

I have a map converted from an SVG file, and now I want to add marker on that map right at the cursor position. But the marker is placed at wrong position, and they don not follow any rules, so I cannot monitor and modify them correctly.
From this example: http://jvectormap.com/examples/mall/ I know we can put markers on map by their coordinates, not by map longitude and latitude. But they are put when initializing the map, while I want put marker dynamically every time I click the mouse.
And from this example: http://jvectormap.com/examples/reverse-projection/, we can put marker right at cursor position, but the map requires insets and projection (to convert e.offsetX and e.offsetY to lat, long) while my map is customized from SVG file, so those information are missing.
So can you help me:
1. How to determine the insets and projection for a custom map? (I use http://svgto.jvectormap.com/ to convert my SVG file, but it just returns the paths)
2. Without using map longitude and latitude, how can I put the marker right at cursor position?
Thank you so much.

Upvotes: 5

Views: 6883

Answers (3)

Đinh Hồng Châu
Đinh Hồng Châu

Reputation: 5430

I have a suggestion. If you are going to use jVectorMap plugin to treat with vector map, you can have a look on this: AmMap. I used it to solve almost problems I have when working with jVectormap. Furthermore, it also provides many awesome features with flexible configs.

Upvotes: -2

LorenzoGi
LorenzoGi

Reputation: 276

I found this solution that works for me

map.addMarker(markerIndex, {coords: [(e.offsetX / map.scale) - map.transX, (e.offsetY / map.scale) - map.transY]});

No matter if zooming in or not, the positioning is compensated.

Lorenzo

Upvotes: 3

bjornd
bjornd

Reputation: 22943

When adding marker just provide coords key with desired coordinates in configuration instead of latLng:

map.addMarker(markerIndex, {coords: [100, 100]});

Upvotes: 5

Related Questions