themustafaomar / jsvectormap

A lightweight JavaScript library for creating interactive maps and pretty data visualization.
https://jvm-docs.vercel.app
MIT License
398 stars 80 forks source link

AddMarkers raise exception #124

Closed shabshekan closed 1 year ago

shabshekan commented 1 year ago

This is the code that I use to create a map.

var italyMap = new jsVectorMap({
  map: "italy",
  selector: "#italy_map",
  zoomButtons: true,
  //markers: useMapMarkers,
  markerStyle: {
    initial: {
      r: 9,
      stroke: window.theme.white,
      strokeWidth: 7,
      stokeOpacity: .4,
      fill: window.theme.primary
    },
    hover: {
      fill: window.theme.primary,
      stroke: window.theme.primary
    }
  },
  regionStyle: {
    initial: {
      fill: window.theme["gray-200"]
    }
  },
  zoomOnScroll: false
});
window.addEventListener("resize", () => {
  //worldMap.updateSize();
  italyMap.updateSize();
});
setTimeout(function () {
  //worldMap.updateSize();
  italyMap.updateSize();
}, 250);

later in response of ajax request, I filled markers and try to add markers in this way,

italyMap.addMarkers(useMapMarkers);

at this point I get this error: "Cannot read properties of undefined (reading 'join')"

it creates the map correctly and add markers but I don't understand why raise error at the end? one sample of

markers = useMapMarkers.push({
  coords: [loc.lat, loc.lng],
  name: res[i].Name + ": € " + res[i].Value,
})
themustafaomar commented 1 year ago

Could you please provide an example that reproduces the issue at codepen.io I don't see any issues and errors.

pselis commented 1 year ago

I'm experiencing the same issue. The problem seems to occur only when markers are loaded dynamically through an asynchronous call.

themustafaomar commented 1 year ago

If you could provide an example that reproduces the issue. this would be really helpful in understanding and addressing the problem, looks like it's working perfectly here, let me know if the problem persists.

https://codepen.io/themustafaomar/pen/KKbegjm