2

I've got a KML, where several points have the same coordinate, similar to following code:

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>test.kml</name>
    <visibility>0</visibility>
    <open>1</open>
    <Placemark>
      <name>Place 1</name>
      <Point>
        <coordinates>7.0901548880586,50.723973666434,0</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>Place 2</name>
      <Point>
        <coordinates>7.0901548880586,50.723973666434,0</coordinates>
      </Point>
    </Placemark>
  </Document>
</kml>

If I click on the POI in an OpenLayers-map, only the last point can be selected. Google Maps' solution to the problem are next- and previous-buttons, in Google Earth the placemark "splits" into two (or more) placemarks so you can select one of the placemarks. Is it possible to create a similar behaviour in OpenLayers?

There is an analog problem if there are two KMLs with placemarks with the same coordinate. I need a solution for this problem, too.

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>test1.kml</name>
    <visibility>0</visibility>
    <open>1</open>
    <Placemark>
      <name>Place 1</name>
      <Point>
        <coordinates>7.0901548880586,50.723973666434,0</coordinates>
      </Point>
    </Placemark>
  </Document>
</kml>

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>test2.kml</name>
    <visibility>0</visibility>
    <open>1</open>
    <Placemark>
      <name>Place 2</name>
      <Point>
        <coordinates>7.0901548880586,50.723973666434,0</coordinates>
      </Point>
    </Placemark>
  </Document>
</kml>
ischas
  • 77
  • 2
  • 11

1 Answers1

2

Tyr to use Strategy.Cluster: see http://openlayers.org/dev/examples/strategy-cluster.html

Add option: threshold: 2 at Cluster creation, this allows you to view element that does not overlap, and set distance (in pixels) see http://openlayers.org/dev/examples/strategy-cluster-threshold.html

  • Thank you for your answer. I was able to successfully implement your solution for the case of multiple points in one KML, but now there is a small square instead of my marker. Is it possible to change the marker for the cluster? How can I adapt the solution for the similar problem with two KMLs with POIs with the same coordinates? – ischas Apr 04 '13 at 09:52
  • Okay, I solved the marker-problem with the help of this question: http://stackoverflow.com/questions/6641919/openlayers-nice-marker-clustering , but still need help for the problem with the POIs of two layers sharing one coordinate. – ischas Apr 04 '13 at 15:47
  • The only thing I can think is to display it in a single layer oops! Want to highlight or select the features? – xamamano -jorix- Apr 04 '13 at 16:18
  • I want to select one point and display its description in a balloon. In the case of a cluster there should be a choice, which of the clustered points should be selected. – ischas Apr 05 '13 at 06:29
  • See this example: http://jorix.github.com/OL-FeaturePopups/examples/feature-popups.html uses a control written by me that you can help. – xamamano -jorix- Apr 05 '13 at 14:53
  • Your FeaturePopup-Code is great and helps me a lot! Thank you! – ischas Apr 08 '13 at 09:51
  • Okay, now I've got one more question: – ischas Apr 08 '13 at 11:49
  • Is it possible to use the style, which I extracted from the KML, for the clustered POIs, and add a label to it, which counts the number of POIs at the place of the map? By now I created an own StyleMap, where I defined the externalGraphic and a label, which counts the POIs at one place, and ignore the style of the KML. If I don't do so I get the small squares as marker for the clusters. But maybe I'll add a KML, where I don't know the url of the marker, so I get problems to define the externalGraphic. – ischas Apr 08 '13 at 12:00
  • Use both! (extractStyles:true & StyleMap for clusters) The KML format+extractStyles:true creates features with style, but cluster strategy creates features without style. See eg https://gist.github.com/jorix/6c74f35a5700e194ebd7 (used in production with KLM+extractStyles:true) – xamamano -jorix- Apr 08 '13 at 14:40
  • But I want to give the cluster the same marker. How can I allocate the same marker as the one for the other points, e.g. if I don't know the url of the marker? – ischas Apr 08 '13 at 14:44
  • But then you should avoid clustering features with different icon, but may be in the same location, so ... The context allows you to view all the features of the cluster (see array feature.cluster each item of them have a style (from KML) get by feature.cluster[i].attributes.styleUrl and feature.cluster[i].style ...) . – xamamano -jorix- Apr 08 '13 at 15:02
  • feature.cluster[0].style.externalGraphic was the right hint. When I'll cluster features with different icons I'll a) use circles as proposed by you, b) the icon of the most important feature (like http://openflights.org/blog/2009/10/21/customized-openlayers-cluster-strategies/ ) or c) the icon, which represent the most features of the cluster.

    Once again many thanks for your help! When I'll ever get >15 reputation I'll +1 your comments! You provided great answers to my (newbie-) questions!

    – ischas Apr 08 '13 at 15:27
  • I'm glad it was useful. Not so newbie ;-) this is a complex issue come to assimilate many concepts. – xamamano -jorix- Apr 08 '13 at 16:52