Unfolding: What am I doing wrong using SimplePointMarker

Please what have I got wrong in this code? The line "berlinMarker.setRadius(20.0);` gives the error " The function setRadius(float) does not exist". I got it from the webpage for "Class SimplePointMarker" at (http://unfoldingmaps.org/javadoc/de/fhpotsdam/unfolding/marker/SimplePointMarker.html)

I am obviously overlooking something, but I am new to processing and can't work it out. The answer may be applicable to other attempts to use classes.

 import de.fhpotsdam.unfolding.*;
  import de.fhpotsdam.unfolding.geo.*;
  import de.fhpotsdam.unfolding.utils.*;
  import de.fhpotsdam.unfolding.marker.*;

UnfoldingMap map;

void setup() {
    size(800, 600);
    map = new UnfoldingMap(this);
    MapUtils.createDefaultEventDispatcher(this, map);
    Location berlinLocation = new Location(52.5, 13.4);
    Marker berlinMarker = new SimplePointMarker(berlinLocation);
    map.addMarker(berlinMarker);
    berlinMarker.setRadius(20.0);
}

void draw() {
    map.draw();
}
Tagged:

Answers

  • edited July 2014 Answer ✓

    TUnfolding is a contributed library so I will move this post to the correct category and I have included the name of the library in the title - that way you have a better chance of getting a reply. :)

    Please read this post and at new forum members.

  • edited July 2014 Answer ✓

    Ah, this one is actually simple...

    You define berlinMarker to be a Marker, which is a correct practice in general (like when we write List l = new ArrayList()) as it might allow to change the implementation without breaking the code.

    But here, setRadius() is defined specifically on SimplePointMarker. The compiler sees only a variable of type Marker, on which this method isn't available (yes, here it is nearsighted...).

    Two possible solutions:

    SimplePointMarker berlinMarker = new SimplePointMarker(berlinLocation);
    

    or

    ((SimplePointMarker ) berlinMarker).setRadius(20.0);
    

    Here, I think the first solution is the most practical one.

  • Thank you PhiLho, that solved it nicely. I have learned a useful lesson.

Sign In or Register to comment.