[khtml.maplib] Re: clear markers

  • From: Ewald Wieser <aevoid@xxxxxxxxx>
  • To: khtml.maplib@xxxxxxxxxxxxx
  • Date: Tue, 30 Aug 2011 17:49:55 +0200

Hello Tamas,

with marker.clear() you can remove one marker from the map.
Unfortunately I just found a little bug in the clear-function.
I have uploaded a new version at 
http://mt091110.students.fhstp.ac.at/khtml/maplib.tar.gz

If you would like to remove all overlays at once, you can use 
map.removeOverlays();

Sorry for the inconvenience, but this library is still beta.
But I'm glad that you like it!

Maybe you can show us the result of your work.
brgds Ewald


Am 30.08.2011 um 17:18 schrieb Mátrai Tamás:

> Hi All!
> 
> I am Tamas Matrai from Hungary, I've just start to play with KHTML maps.
> 
> It is looking great, it is very promising, thx for this great project!
> I could create my app I need in some hours.
> It is a simple one that shows some markers on the map, based data coming from 
> GPS devices.
> 
> My problem is with clearing markers from the map, after adding one I can not 
> clear it. It tried several ways but neither works.
> 
> I use GSOC improved javascript library from here: 
> http://wiki.openstreetmap.org/wiki/Improving_khtml.maplib#Markers
> 
> My code (note this is very experimental one!):
> I have a global variable: 
> 
> var mr = new Object(khtml.maplib);
> 
> The following function adds a marker to the map (markerStr some delimited 
> string contains position and extra data):
> 
> function RefreshMarkers(markersStr)
>         {
>           var sentences = markersStr.split("\r\n");
>             
>             for (i = 0; i < sentences.length; i++) {
>                 
>                 var sentenceParts = sentences[i].split("%_@");
>                 
>                 var image = new mr.overlay.MarkerImage(
>                   'khtml/img/standardmarker_nor.png',
>                   new mr.Size(20, 20),
>                   new mr.Point(0, 0),
>                   new mr.Point(10, 20)
>                   );
> 
>                 var shadow = new mr.overlay.MarkerImage(
>                   'khtml/img/standardmarkershadow_nor.png',
>                   new mr.Size(34, 20),
>                   new mr.Point(0, 0),
>                   new mr.Point(10, 20)
>                   );
> 
>                 var shape = {
>                     coord: [14, 0, 15, 1, 16, 2, 17, 3, 18, 4, 19, 5, 19, 6, 
> 19, 7, 19, 8, 19, 9, 19, 10, 19, 11, 19, 12, 19, 13, 19, 14, 18, 15, 17, 16, 
> 16, 17, 15, 18, 13, 19, 5, 19, 4, 18, 2, 17, 2, 16, 1, 15, 0, 14, 0, 13, 0, 
> 12, 0, 11, 0, 10, 0, 9, 0, 8, 0, 7, 0, 6, 0, 5, 1, 4, 2, 3, 2, 2, 4, 1, 5, 0, 
> 14, 0],
>                     type: 'poly'
>                 };
> 
>                 var pLatLng = new mr.LatLng(sentenceParts[4], 
> sentenceParts[3]);
>                 var marker2 = new mr.overlay.Marker({
>                     position: pLatLng,
>                     map: map,
>                     title: sentenceParts[1] + 
>                            "\r\n" + sentenceParts[2] +
>                            "\r\n" + sentenceParts[0] +
>                            "\r\n" + sentenceParts[5] + " km/h" +
>                            "\r\n" + sentenceParts[9]
>                 });
>             }
>         }
> 
> 
> So, as I said adding is OK, but later I can not remove them  (neither in this 
> RefreshMarkers function for testing purposes).
> So, how can I do this? Is there any way to clear all markers from a map?
> 
> Thanks,
> BR:
> Tamas
> 

Other related posts: