Git Product home page Git Product logo

clusterkraf's Introduction

DEPRECATED

Don't use this. The Maps v3 SDK handles markers. That with a few other cool utilities make this library obsolete!

Clusterkraf

A clustering library for the Google Maps Android API v2.

If you're using the Polaris v2 library, check out our pleiades branch.

Features

  • Clustering based on pixel proximity, not grid membership
  • Animated cluster transitions
  • Supports Android v2.2 (Froyo) and higher

Setup

Gradle

If you are using Gradle just add the following to your build.gradle file:

dependencies {
    compile 'com.twotoasters.clusterkraf:library:1.0.+'
}

Maven

If you are using maven add the following to your pom file:

<dependency>
    <groupId>com.twotoasters.clusterkraf</groupId>
    <artifactId>library</artifactId>
    <version>1.0.2</version>
</dependency>

Eclipse

It's easy to add Clusterkraf to your app. Add the Clusterkraf library folder as an Android project to your Eclipse/ADT workspace, and reference it from your app as a library project. Also, we assume you have a data object that holds latitude and longitude coordinates of each point you want plotted on the map similar to this:

public class YourMapPointModel {
    public LatLng latLng;
    public YourMapPointModel(LatLng latLng) {
        this.latLng = latLng;
    }
    // encapsulation omitted for brevity
}

Clusterkraf provides an InputPoint class which holds a LatLng position and an Object tag. You just need to construct an ArrayList<InputPoint> object based on your model objects similar to this example. In this example, we provide the model as the Object tag for the InputPoint so that we can later pass them back to you in callbacks as the ClusterPoint object's pointsInCluster list; see MarkerOptionsChooser, OnInfoWindowClickDownstreamListener, and OnMarkerClickDownstreamListener.

public class YourActivity extends FragmentActivity {
    YourMapPointModel[] yourMapPointModels = new YourMapPointModel[] { new YourMapPointModel(new LatLng(0d, 1d) /* etc */ ) };
    ArrayList<InputPoint> inputPoints;
        
    private void buildInputPoints() {
        this.inputPoints = new ArrayList<InputPoint>(yourMapPointModels.length);
        for (YourMapPointModel model : this.yourMapPointModels) {
            this.inputPoints.add(new InputPoint(model.latLng, model));
        }
    }
}

When your GoogleMap is initialized and your ArrayList<InputPoint> is built, you can then initialize Clusterkraf.

    // YourActivity

    Clusterkraf clusterkraf;

    private void initClusterkraf() {
        if (this.map != null && this.inputPoints != null && this.inputPoints.size() > 0) {
    		com.twotoasters.clusterkraf.Options options = new com.twotoasters.clusterkraf.Options();
    		// customize the options before you construct a Clusterkraf instance
    		this.clusterkraf = new Clusterkraf(this.map, this.options, this.inputPoints);
    	}
    }

You've added a really sweet clustered map to your Android app.

For a more detailed example, take a look at the included sample app's source code.

Sample App

The sample app demonstrates Activity lifecycle, custom marker icons, click handling, and Clusterkraf's options. You can build it from source, or install it from https://play.google.com/store/apps/details?id=com.twotoasters.clusterkraf.sample.

Building the Sample App

  1. In your local checkout of the Clusterkraf git repo, do git submodule init and git submodule update.
  2. Add sample/ as a new Android project from existing source.
  3. Add sample/libs/ViewPagerIndicator as a new Android project from existing source.
  4. Authorize com.twotoasters.clusterkraf.sample built with your key of choice to your Google Maps for Android v2 API account.
  5. Create a new Values file private_strings.xml in sample/res/values/ and create a string named maps_api_key with your Google Maps for Android v2 API key.

License

Copyright 2013 Two Toasters

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

clusterkraf's People

Contributors

carltonwhitehead avatar fmedlin avatar sloy avatar syntaxyz avatar yorb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clusterkraf's Issues

NoClassDefFoundError

I got the project running with Android Studio but it seems there are some references missing :

    java.lang.NoClassDefFoundError: com.twotoasters.clusterkraf.ClusterTransitionsAnimation

at com.twotoasters.clusterkraf.Clusterkraf.(Clusterkraf.java:56)

My build.gradle file

apply plugin: 'android-library'


repositories {
    mavenCentral()
}


dependencies {
compile group: 'com.google.android.gms', name: 'play-services', version: '3.1.36'

    compile files('libs/nineoldandroids-2.4.0.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
}

Would be great to get some Feedback :)

Info Windows dissapear when the map is panned.

It seems that a cluster transition is started whenever the map is panned, regardless of whether clusters need to be transitioned, leading to a call to clusterkaf.removePreviousMarkers() which removes the markers. This means that if someone clicks on a marker to show its info-window, and then tries to pan the map to see more of the info-window, the info-window will dissapear.

I've been looking at trying to fix this issue. I'm not sure it's an easy one. So I'm reporting it.

ConcurrentModificationException in ClustersBuilder.addAll()

java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.util.ConcurrentModificationException
at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:569)
at com.twotoasters.clusterkraf.ClustersBuilder.addAll(ClustersBuilder.java:54)
at com.twotoasters.clusterkraf.ClusteringTask.doInBackground(ClusteringTask.java:34)
at com.twotoasters.clusterkraf.ClusteringTask.doInBackground(ClusteringTask.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
... 3 more

Add function to Zoom to Bounds when click in Cluster which has Info Window shown already

OK, let me describe step by step how to archive it.

In advanced mode

  1. Cluster click behavior: choose Show Info Window
  2. Cluster Info Window Click behavior: choose Zoom to Bounds
  3. Open the Sample Activity. Click on a cluster, then the Info Window will be shown.
    In this case, if click the Info Window will perform Zoom to Bounds.
  4. I want to have an option, when the Info Window is shown, we can also click on Cluster to perform Zoom to Bounds action. At the moment, click on Cluster when Info Window is shown does nothing.

Thank you for great mapping cluster library.

Library is having application icon and theme

As the main application will already have application icon and theme in place. While building the app fails with following

Error:(39, 9) Attribute application@icon value=(@drawable/launcher_icon) from AndroidManifest.xml:39:9
Error:(41, 9) Attribute application@theme value=(@style/Theme.rctheme) from AndroidManifest.xml:41:9
is also present at com.twotoasters.clusterkraf:library:1.0.2:5:115 value=(@style/AppTheme)
Suggestion: add 'tools:replace="android:theme"' to element at AndroidManifest.xml:37:5 to override
Error:Execution failed for task ':handset:processDebugManifest'.

Manifest merger failed with multiple errors, see logs

Possible Resolution
replace the manifest

current one

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
</application>

new one

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

ConcurrentModificationException from multiple add()'s

I'm thinking this is from calling add() multiple times back to back... instead of using addAll()

java.util.ConcurrentModificationException
at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:569)
at com.twotoasters.clusterkraf.ClustersBuilder.addAll(ClustersBuilder.java:54)
at com.twotoasters.clusterkraf.ClusteringTask.doInBackground(ClusteringTask.java:34)
at com.twotoasters.clusterkraf.ClusteringTask.doInBackground(ClusteringTask.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)

NullPointerException in sample app ToastedMarkerOptionsChooser on certain devices

java.lang.NullPointerException
at android.graphics.Bitmap.copy(Bitmap.java:400)
at com.twotoasters.clusterkraf.sample.ToastedMarkerOptionsChooser.getClusterBitmap(ToastedMarkerOptionsChooser.java:95)
at com.twotoasters.clusterkraf.sample.ToastedMarkerOptionsChooser.choose(ToastedMarkerOptionsChooser.java:67)
at com.twotoasters.clusterkraf.ClusterTransitionsAnimation.addMarker(ClusterTransitionsAnimation.java:243)
at com.twotoasters.clusterkraf.ClusterTransitionsAnimation.onAnimationStart(ClusterTransitionsAnimation.java:201)
at com.nineoldandroids.animation.ValueAnimator.start(ValueAnimator.java:937)
at com.nineoldandroids.animation.ValueAnimator.start(ValueAnimator.java:951)
at com.nineoldandroids.animation.ObjectAnimator.start(ObjectAnimator.java:385)
at com.twotoasters.clusterkraf.ClusterTransitionsAnimation.animate(ClusterTransitionsAnimation.java:52)
at com.twotoasters.clusterkraf.Clusterkraf.transitionClusters(Clusterkraf.java:175)
at com.twotoasters.clusterkraf.Clusterkraf.access$16(Clusterkraf.java:173)
at com.twotoasters.clusterkraf.Clusterkraf$ClusterTransitionsBuildingTaskHost.onClusterTransitionsBuildingTaskPostExecute(Clusterkraf.java:506)
at com.twotoasters.clusterkraf.ClusterTransitionsBuildingTask.onPostExecute(ClusterTransitionsBuildingTask.java:53)
at com.twotoasters.clusterkraf.ClusterTransitionsBuildingTask.onPostExecute(ClusterTransitionsBuildingTask.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:417)
at android.os.AsyncTask.access$300(AsyncTask.java:127)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4914)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)

Cursor and show tooltip default

Hello

I use this library and it is really great.
I have not found a way to initialize default cursors to display a tooltip with showInfoWindow() method
Is there the possibility to do so?

Thank you in advance,

Clustering on max zoom

I have two pins really near to each other and I set a bit larger "distance to join cluster". Than I tap on a cluster consisting of these two pins. It zooms, but pins stay clustered. It would be great that when zoom reaches max level, all clusters would be expanded.

Markers don't always clear

I noticed that calling clear on Clusterkraf doesn't always clear the markers. This behavior is observed on 2.33 device.

problem of showing clustered icon instead of a single marker icon

Hi,
I just tried to add this library to my project which has more than two thousands markers and it works good except that when I zoom to see my single markers outside of the clusters, it shows the single marker but it seem that it still is inside the cluster and shows the clustered icon and also '2' number on the icon which indicates it has 2 markers but I'm sure it is just one marker.
Do you have any clue why this may happen ?

Thanks in advance

Multiple clusters groups

I'm trying to implement X different clusters which are loaded asynchronously, i'm doing it fine so far but i just encountered a problem with the Cluster click animation behavior. When the first category cluster is loaded on map the click listener works fine but when i add two different categories the animation binds only on the first while the second stop working properly

Loading spinner sometimes stays on when returning to SampleActivity from TwoToastersActivity

Steps to reproduce

  1. Start sample app in Normal Mode
  2. Zoom until Two Toasters office is drawn as a single marker
  3. Tap the Two Toasters office marker to open the TwoToastersActivity
  4. Navigate back to SampleActivity (hardware back button or ActionBar up)
  5. If loading spinner is not already spinning indefinitely, repeat steps 3 and 4 (sometimes it doesn't happen on the first try, but will on the second as long as the camera position doesn't change)

Expected results

Either no loading spinner is shown at all, or the loading spinner is only visible very briefly (substantially less than one second)

Actual results

The loading spinner is shown forever, or until the camera position is changed

Possibility of multiple Clusterized Icons

Hi,
My question is about the possibility of multiple icons in clusters, based on data.
Example: I have POI -s on map, base on it's types it can have different types of icons. But I couldn't find out how to do that in ClusterKraf. As I know we can customise the icon in overrided "choose" function in extended MarkerOptionsChooser. But there I do not have which POI is under customisation. InputPoints can be only reached by index, cannot get the container array list itself, so if i iterate it with index (getInputPointAtOffset(index)) it can easily overrun. I have no other idea how to get current InputPoint, which can hold the type of the input point.
Thanks,
peter

Make markers filterable based on title/credential?

Is there any ability to filter the markers currently being shown? I need to filter the markers that are shown/clustered, with the ability to also remove that filter and show every marker. Is that possible in the library? I tried to add a delete method to the library in order to remove markers from the clusters (to go in hand with the add method), but the clustering didn't seem to update at all.

Unsupported as v3 supports clustering is not true

Readme says not to use and is no longer supported as v3 has clustering support. This is not true, there is no V3 for Android.

Also worth mentioning that google does have a utility lib to support clustering, it is however crazy slow.

Make clustering serializable?

Hi great work on this project - I really like it. I was just wondering in order to avoid recalculating clusters each time the map is initialised could the clusters be serialized in some manner? I'm working on a app that has over 4K locations and the calculation of the initial clusters means it can take over 30 seconds for anything to appear on the map.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.