Open MarioMartin opened 12 years ago
http://code.google.com/p/google-maps-utility-library-v3/wiki/Libraries - Someone asked if we could implement the cluster
This library is huge, but does have some inviting utility classes. Maybe after 3.10 I might endeavor on.
Good point. From a low ever GWT perspective, I'm sometimes weary of large bolt on libraries. For example the Garmin Communicator API downloads nearly 2 dozen js libs and jquery to do even the simplest task. Hence I did gwt-garmin-api as a native implementation in just 8k.
Hence, to include something like that, we'd need to be sure to make it optional in the loader.
Sounds like a nifty api. :)
I agree. I was thinking separate module, and maybe child modules with in that.
Correct. What I really love about GWT is the minimalism of the final compiled product while many a framework these days bolts dependencies on top of dependencies. I recall a major retailer's landing page that required 276 downloads to load.
Great point! ... Holy moly 276...
Hi,
Does anyone have an example of using the MarkerClusterer in GWT Maps API V3? Thanks a lot.
I need to investigate to see if this fits this issue: https://github.com/branflake2267/GWT-Maps-V3-Api/tree/master/gwt-maps-utility/markerclustererplus
Did you ever do this? I tried your MarkerClusterer and I get a "operation not supported error" by javascript... this after custom loading the compiled js implementing the object and trying to customize your code.
http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/examples.html
Seems to work fine especially with the custom js... not sure where I see that js library in your utilities modules either since MarkerClusterer isn't part of the v3 library.
Maps become useless once you have a few hundreds markers so this is a critical class... in spite of it being on the fringe of maps v3.
Hm, I don't see a javascript loader. Looks like some work still needs to be done yet. Sorry I haven't had time to investigate further since this is a volunteer project I've had some time conflicts. Patches are welcome.
I added:
<inherits name='com.google.gwt.maps.Maps' />
<inherits name='com.google.gwt.maps.utility.markerclustererplus.MarkerClustererPlus' />
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
to my gwt.xml
also also
<dependency>
<groupId>com.github.branflake2267</groupId>
<artifactId>gwt-maps-api</artifactId>
<version>3.10.0-alpha-6</version>
</dependency>
<dependency>
<groupId>com.github.branflake2267</groupId>
<artifactId>gwt-maps-utility-markerclustererplus</artifactId>
<version>3.10.0-alpha-6</version>
</dependency>
In my POM.
So far so good.
But when I try:
final MapWidget map = new MapWidget(mapOptions);
final MarkerClustererOptions clusterOptions = MarkerClustererOptions.newInstance();
clusterOptions.setAverageCenter( true );
manager = MarkerClusterer.newInstance( map, clusterOptions );
It blow up here with:
18:51:22.469 [ERROR] [gwt] Uncaught exception escaped
com.google.gwt.core.client.JavaScriptException: (TypeError) @com.google.gwt.maps.utility.markerclustererplus.client.MarkerClusterer::createJso(Lcom/google/gwt/core/client/JavaScriptObject;Lcom/google/gwt/core/client/JavaScriptObject;Lcom/google/gwt/core/client/JavaScriptObject;)([JavaScript object(1517), JavaScript object(1519), JavaScript object(1518)]): $wnd.MarkerClusterer is not a constructor
Now I took the
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
from the html examples I saw successfully using the api.
But obviously something is amiss here. Hope your insight can resolve this in a few minutes :)
I see
private static native MarkerClusterer createJso(JavaScriptObject map, JavaScriptObject markers, JavaScriptObject options) /*-{
return new $wnd.MarkerClusterer(map, markers, options);
}-*/;
which should work given the javascript example does pretty much the same thing.
I got it to work!!!!
Here's the recipe:
3.10.0-alpha-6 is fine.
Now in gwt.xml:
create a public directory where the xml is and stick there a markerclusterer.js file ripped from:
Then all will work!
Took me a bit to figure out but hope I made my little contribution to the community here.
also in gwt.xml add:
And life will be good.
Good job.
Hello sherloclops, I'm facing a similar issue: I added the markercluster.js in the same directory as my custom .gwt.xml and in my gwt.xml, I added: [script src="markerclusterer.js" /] But I'm still getting the same error. In which directory did you the JS file and how are you referencing it? Thanks
Try adding a timer and see if its loaded after a second.
I use a callback method for the maps api, and I don't see one here. If it has a the ajax loader strategy could be used so that a runnable could be used to programmatically load after the js has been injected.
I created com.google.gwt.maps.utility.markerclustererplus package , copied the MarkerClusterPlus.gwt.xml into it, modified it to include [script src="markerclusterer.js" /]. I then created the "public" directory, added the markermanager.js inside it.. It doesn't work in Development mode. But it does when I deploy it to the server. "production".
"I use a callback method for the maps api" Are you referring to LoadApi.go(onLoad, loadLibraries, sensor);
The question is does the markermanager.js call a method once its loaded? If it does that can be used as a callback in a GWT runner, like the ajax loader method, which is similiar to the LoadApi.go... Some js has a call back feature, or feature that can be used for onsuccess or onfailure. Working with js has to be done asyncly, that is there is a timing issue between the time it gets loaded, parsed and injected into the dom. Once its in the dom, then its available to call using jsni methods. If calling a method to it is undefined, I suspect that it hasn't loaded by the time the js or jsni calls the method.
Thanks for the explanation. The markermanager does trigger a loaded event once it's loaded. However, I don't see anywhere where such event is triggered in the markercluster.js.
Cool, I've been meaning to look deeper at it but haven't had time.
Brandon, I got it to work in dev mode by delaying the instantiation until MarkerCluster is actually needed. However, the events that I had registered to the markers themselves no longer work. Any trick that I can use to register mouseover and mouse events using this MarkerClusterer JSNI as shown here http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclustererplus/examples/events_example.html ? Thanks
I suspect the handlers have some sort of handling for events, and if so I would check out the event system. Its not pretty b/c there is some generic challenges in it and I used inheritance a bunch. Another thing that I do for widgets is use > https://github.com/branflake2267/GWT-Maps-V3-Api/blob/master/gwt-maps-api/src/main/java/com/google/gwt/maps/client/events/MapPanel.java to wire up the events but have to be careful b/c it can leak if not managed properly.
https://github.com/branflake2267/GWT-Maps-V3-Api/blob/master/gwt-maps-api/src/main/java/com/google/gwt/maps/client/events/MapHandlerRegistration.java contains the main part of the map event logic, which uses handlers to pass back objects
I will give it a try. Thanks
Hello & good day! Thanks for such awesome gwt lib for map.
I created com.google.gwt.maps.utility.markerclustererplus package , copied the MarkerClusterPlus.gwt.xml into it, modified it to include [script src="markerclusterer.js" /]. I then created the "public" directory, added the markermanager.js inside it.. It doesn't work in Development mode. But it does when I deploy it to the server. "production".
My code is a mess :D but I expect it to work. Above error is at the MarkerClusterer.newInstance line.
private void loadMapApi() {
boolean sensor = false;
// load all the libs for use in the maps
ArrayList<LoadLibrary> loadLibraries = new ArrayList<LoadApi.LoadLibrary>();
loadLibraries.add(LoadLibrary.DRAWING);
loadLibraries.add(LoadLibrary.GEOMETRY);
loadLibraries.add(LoadLibrary.VISUALIZATION);
infoWindowOptions = InfoWindowOptions.newInstance();
Runnable onLoad = new Runnable() {
@Override
public void run() {
drawMap();
}
};
LoadApi.go(onLoad, loadLibraries, sensor, "key=keysabcdtoottoot");
}
private void drawMap() {
if (this.iterator().hasNext()) {
logger.debug("Not calling drawmap since Panel already contain a child!");
return;
} else {
logger.debug("Calling drawmap since Panel does not contain a child!");
}
LatLng centerCoords = LatLng.newInstance(3.1389391564497657d, 101.6839599609375d);
MapOptions opts = MapOptions.newInstance();
opts.setZoom(14);
opts.setCenter(centerCoords);
opts.setMapTypeId(MapTypeId.ROADMAP);
mapWidget = new MapWidget(opts);
infoWindow = InfoWindow.newInstance(infoWindowOptions);
final MarkerClustererOptions clusterOptions = MarkerClustererOptions.newInstance();
clusterOptions.setAverageCenter(true);
markerCluster = MarkerClusterer.newInstance(mapWidget, clusterOptions);
if (mapWidget != null) {
ov = OverlayView.newInstance(mapWidget, new ovOnDrawHandler(), new ovOnAddHandler(),
new ovViewOnRemoveHandler());
logger.debug("Adding click handler for map!");
mapWidget.addClickHandler(new MapClickHandler());
mapWidget.addRightClickHandler(new MapRightClickHandler());
}
logger.debug("Adding map widget to MapDashWidget");
// this.clear();
this.add(mapWidget);
resize();
}
could help me please: I have a GWT project with GWT GoogleMapsAPI v3 and would like to implement Markerclusterer through a JSNI method.
My question is how to manipulate the MapWidget within JSNI method
this is my code but does not work.
package cl.prueba.JS.client;
my html is : HTML ....
Thank you very much!! I hope they understand my problem, if they have questions, please let me know.
atte Mario