GMapsFX
GMapsFX copied to clipboard
MarkerOptions show the same png image when multiple markers are added to the map
Hi ! In my project when the map starts I add some markers with different images, but the map shows me all the markers with the same icon. The images are next to html inside the jar.
i have this code in the Main
@Override
public void mapInitialized() {
MapOptions mapOptions = new MapOptions();
mapOptions.center(new LatLong(-37.317314, -59.13849))
.mapType(MapTypeIdEnum.TERRAIN)
.overviewMapControl(false)
.panControl(false)
.rotateControl(false)
.scaleControl(false)
.streetViewControl(false)
.zoomControl(true)
.zoom(16);
map = mapView.createMap(mapOptions);
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(new LatLong(-37.317430,-59.138460))
.visible(true)
.title("Point 1")
.icon("images/cerrado.png");
Marker marker = new Marker( markerOptions );
map.addMarker(marker);
MarkerOptions markerOptions2 = new MarkerOptions();
markerOptions2.position(new LatLong(-37.315080,-59.143340))
.visible(true)
.title("Point 2")
.icon("images/obras.png");
Marker marker2 = new Marker( markerOptions2 );
map.addMarker(marker2);
}
This is the result
but when i refresh the map (doing zoom) i get this
do you know if this is a bug or i 'm doing things in the wrong way? Thanks
Are you still having this issue?
I'm using GMapsFX for nearly one year with full satisfaction . But I am also facing the issue described here. I just upgraded to version 2.0.9, but the problem still persists. I tried to execute an additional (delayed) map refresh after map initialization, without success.
@PSchmitzMo Are you using the core html file or one in your own jar? In a sample app I created to test images I'm able to load different images using MarkerImageFactory, including one from the local filesystem. It's a different process than specifying the image directly to the WebView/Javascript, but avoids the problems with WebView not being able to reference images in jars unless they're in the same folder as the html file. If you're having trouble could you post a bit of code so we can get an idea of where it might be going wrong? Thanks!
Thank you for the analysis of my (quite minor) problem.
My experiences with your proposals:
- Images in the same folder as the html file:
The images are displayd. But my problem hasn't vanished: intially all markers display the same icon. After zooming the correct images are displayed.
- Loading images with MarkerImageFactory:
a) I use GMapFX 2.0.9 b) I used the MarkerImageFactory implementation committed on Dec. 15 on GitHub.
Icons are not displayed: I specified absolute paths on a drive D: and used the syntax "file:///D:/<myPath>/image.png". I verified that "D:/<myPath>/image.png" is a valid path. Execution of createMarkerImageFromFile() does not run into an exception.
Snippet of my code:
markerOptions.position( new LatLong(x,y) )
.visible(Boolean.TRUE)
.icon( GMapsFXUtil.createMarkerImage( "file:///D:/myPath/image.png", "png") )
.title( title );
(GMapsFXUtil.java is a copy of MarkerImageFactory.java)
My conclusion: My problem is not related to 'image files cannot be found or are wrongly referenced'. I assume that there is some initial mix-up of icons ? But I cannot find it in my code or in MarkerOptions.java.
I have the same problem. When Placing different types of markers on the map initially they are messed up (not correct markers are shown for locations). Zooming in or out refreshes the map and solves the problem.
Is it possible to execute 'Zooming in or out' programmatically on map initialisation in a way that it is not noticed by the user? I didn't succeed.
One solution is to add markerOptions.animation(Animation.NULL) in order to display the right icons.
Hi Mickael,
your advice solved my problem.
Thanks a lot! Peter