setting up a custom icon for a marker in JxMap

565 views Asked by At

I am evaluating JxMaps library. I cannot set a new icon to a marker.

Marker marker = new Marker(map);
marker.setPosition(new LatLng(39.833851, -74.871826));
ImageIcon newIcon = new ImageIcon(this.getClass().getResource("/resources/flag.png"));
marker.setIcon(newIcon);  


My problem is that marker.setIcon method does not accept ImageIcon attribute but String.
How can I change it a default icon ?

Here is a link to APIs: https://www.teamdev.com/downloads/jxmaps/docs/index.html

1

There are 1 answers

0
Vitaly Eremenko On BEST ANSWER

In case you are passing string to Marker.setIcon method, you should provide URL to resource that contains desired image.

But, alternatively, you can pass reference to Icon object. This object have methods to load images. For example:

Icon icon = new Icon();
icon.loadFromStream(PlacesSearchExample.class.getResourceAsStream("res/test.png"), "png");
marker.setIcon(icon);