Marker spreading ??

Hi folks,

I am new to OSM and I try to add some marker to a marker layer. And I was able to do quite easily. My problem is that I have some marker on the same positon and I can saperate it like in Google earth. If some markers are stacking together in Google Earth and you click on them there are spreading out and you can select them.
My question would be is there a way to do the same with OSM?

With best regards,

Please tell us first what framework you are using to display the map … Leaflet? Openlayers? khtml?

As far as I know, the feature you are asking for is named “clustering” … maybe an internet search for this in connection with your framework’s name can help.

@ stephan75: thanks for an answer :slight_smile:

Ahh, I solved it in a way :roll_eyes:

I saw on the ‘’ site examples of ‘cluster’ that you mentioned.
I didn’t know that it was called in this way.
I used the ‘Cluster Strategy Threshold’ examples as base and added in the display handler a java script function that is moving the markers.

var flipFlop = 0;
function display(event) {
    if (event.feature.cluster)
        if (flipFlop== 0)
            flipFlop = 1;
            flipFlop = 0;
            // move all markers to start point

var d = 15;
function spread(f) {
    var sphere = 1;
    var inSphereCnt = 0;
    var prtMarkerCnt = 0;
    do {
        var numberOfElementsInSphere = Math.floor((2 * Math.PI * sphere * d) / d);
        var alphaBase = 2 * Math.PI / numberOfElementsInSphere;
        do {
            var alpha = alphaBase * inSphereCnt;
            var r = d * sphere;
            var x = Math.sin(alpha) * r;
            var y = Math.cos(alpha) * r;

            var fid = f.cluster[prtMarkerCnt].fid;
            var pos = layerMarker.markers[fid].lonlat;
            var newPx = map.getLayerPxFromLonLat(pos);
            newPx.x += x;
            newPx.y += y;
        } while (
            (inSphereCnt < numberOfElementsInSphere) &&
            (prtMarkerCnt < f.attributes.count)
        inSphereCnt = 0;
        cnt = 0;
    } while (prtMarkerCnt < f.attributes.count);

So it seams that i use Openlayer. I have no experience with leaflet or khtml.
We moved from google maps/ earth to open street map because we whant to ovide any licence problems.
Would leaflet or khtml be a better choise than open layer?

With best regards,

Leaflet is said to be smaller than OpenLayers …

Have a look at many many sites that show OSM tiles … some are using Leaflet

Or try Leaflet or khtml on a test server to see the difference

See for a collection of more.