How can I draw multiple circles and rectangles on a map?










-1














For a project in my university, I need to show in a map all the intersections and some stations in Chicago, I already have LinkedLists with the data and I need to draw Circles with the position of the intersections and rectangles with the position of the stations. I'm using jxMaps library and based on the examples I was able to draw one circle and one rectangle testing the metods according with the examples provided by the developers, but if I try to draw multiple with a loop when I open the map, it stays in grey.
This is my code:



public class Draw extends MapView


private static final long serialVersionUID = 1L;

Map map;

IList <Integer, Intersetion> intersections;

IList <Integer, Station> stations;

public Draw(MapViewOptions options, IList <Integer, Intersection> inter, IList <Integer, Station> est)

super(options);
// Setting of a ready handler to MapView object. onMapReady will be called when map initialization is done and
// the map object is ready to use. Current implementation of onMapReady customizes the map object.
setOnMapReadyHandler(new MapReadyHandler()

@Override
public void onMapReady(MapStatus status)

// Check if the map is loaded correctly
if (status == MapStatus.MAP_STATUS_OK)

map = getMap();
intersections = inter; // I Load the list with the intersections data
stations = est; // I load the list with the stations data
rectangle();
circle();
// Creating a map options object
MapOptions mapOptions = new MapOptions();
// Creating a map type control options object
MapTypeControlOptions controlOptions = new MapTypeControlOptions();
// Changing position of the map type control
controlOptions.setPosition(ControlPosition.TOP_RIGHT);
// Setting map type control options
mapOptions.setMapTypeControlOptions(controlOptions);
// Setting map options
map.setOptions(mapOptions);
// Setting the map center
map.setCenter(new LatLng(41.875486, -87.626570));
// Setting initial zoom value
map.setZoom(9.0);


);


public void circle ()

CircleOptions options = new CircleOptions();
options.setFillOpacity(0);
options.setStrokeColor("#CB4335");
options.setStrokeWeight(5.0);

for (Intersetion inter: intersections)

Circle circle = new Circle(map);
circle.setCenter(new LatLng(inter.darLatitude(), inter.darLongitude()));
circle.setRadius(50);
circle.setOptions(options);


public void rectangle()

RectangleOptions options = new RectangleOptions();
options.setFillOpacity(0);
options.setStrokeColor("#2E86C1");
int i = 0;
for (Station rect: stations)

Rectangle rectangulo = new Rectangle (map);
LatLngBounds bounds = new LatLngBounds (new LatLng (rect.darLatitude() - 0.0004, rect.darLongitude() - 0.0006), new LatLng (rect.darLatitude() + 0.0004, rect.darLongitude() + 0.0006));
rectangle.setBounds(bounds);
rectangle.setOptions(optionts);












share|improve this question




























    -1














    For a project in my university, I need to show in a map all the intersections and some stations in Chicago, I already have LinkedLists with the data and I need to draw Circles with the position of the intersections and rectangles with the position of the stations. I'm using jxMaps library and based on the examples I was able to draw one circle and one rectangle testing the metods according with the examples provided by the developers, but if I try to draw multiple with a loop when I open the map, it stays in grey.
    This is my code:



    public class Draw extends MapView


    private static final long serialVersionUID = 1L;

    Map map;

    IList <Integer, Intersetion> intersections;

    IList <Integer, Station> stations;

    public Draw(MapViewOptions options, IList <Integer, Intersection> inter, IList <Integer, Station> est)

    super(options);
    // Setting of a ready handler to MapView object. onMapReady will be called when map initialization is done and
    // the map object is ready to use. Current implementation of onMapReady customizes the map object.
    setOnMapReadyHandler(new MapReadyHandler()

    @Override
    public void onMapReady(MapStatus status)

    // Check if the map is loaded correctly
    if (status == MapStatus.MAP_STATUS_OK)

    map = getMap();
    intersections = inter; // I Load the list with the intersections data
    stations = est; // I load the list with the stations data
    rectangle();
    circle();
    // Creating a map options object
    MapOptions mapOptions = new MapOptions();
    // Creating a map type control options object
    MapTypeControlOptions controlOptions = new MapTypeControlOptions();
    // Changing position of the map type control
    controlOptions.setPosition(ControlPosition.TOP_RIGHT);
    // Setting map type control options
    mapOptions.setMapTypeControlOptions(controlOptions);
    // Setting map options
    map.setOptions(mapOptions);
    // Setting the map center
    map.setCenter(new LatLng(41.875486, -87.626570));
    // Setting initial zoom value
    map.setZoom(9.0);


    );


    public void circle ()

    CircleOptions options = new CircleOptions();
    options.setFillOpacity(0);
    options.setStrokeColor("#CB4335");
    options.setStrokeWeight(5.0);

    for (Intersetion inter: intersections)

    Circle circle = new Circle(map);
    circle.setCenter(new LatLng(inter.darLatitude(), inter.darLongitude()));
    circle.setRadius(50);
    circle.setOptions(options);


    public void rectangle()

    RectangleOptions options = new RectangleOptions();
    options.setFillOpacity(0);
    options.setStrokeColor("#2E86C1");
    int i = 0;
    for (Station rect: stations)

    Rectangle rectangulo = new Rectangle (map);
    LatLngBounds bounds = new LatLngBounds (new LatLng (rect.darLatitude() - 0.0004, rect.darLongitude() - 0.0006), new LatLng (rect.darLatitude() + 0.0004, rect.darLongitude() + 0.0006));
    rectangle.setBounds(bounds);
    rectangle.setOptions(optionts);












    share|improve this question


























      -1












      -1








      -1







      For a project in my university, I need to show in a map all the intersections and some stations in Chicago, I already have LinkedLists with the data and I need to draw Circles with the position of the intersections and rectangles with the position of the stations. I'm using jxMaps library and based on the examples I was able to draw one circle and one rectangle testing the metods according with the examples provided by the developers, but if I try to draw multiple with a loop when I open the map, it stays in grey.
      This is my code:



      public class Draw extends MapView


      private static final long serialVersionUID = 1L;

      Map map;

      IList <Integer, Intersetion> intersections;

      IList <Integer, Station> stations;

      public Draw(MapViewOptions options, IList <Integer, Intersection> inter, IList <Integer, Station> est)

      super(options);
      // Setting of a ready handler to MapView object. onMapReady will be called when map initialization is done and
      // the map object is ready to use. Current implementation of onMapReady customizes the map object.
      setOnMapReadyHandler(new MapReadyHandler()

      @Override
      public void onMapReady(MapStatus status)

      // Check if the map is loaded correctly
      if (status == MapStatus.MAP_STATUS_OK)

      map = getMap();
      intersections = inter; // I Load the list with the intersections data
      stations = est; // I load the list with the stations data
      rectangle();
      circle();
      // Creating a map options object
      MapOptions mapOptions = new MapOptions();
      // Creating a map type control options object
      MapTypeControlOptions controlOptions = new MapTypeControlOptions();
      // Changing position of the map type control
      controlOptions.setPosition(ControlPosition.TOP_RIGHT);
      // Setting map type control options
      mapOptions.setMapTypeControlOptions(controlOptions);
      // Setting map options
      map.setOptions(mapOptions);
      // Setting the map center
      map.setCenter(new LatLng(41.875486, -87.626570));
      // Setting initial zoom value
      map.setZoom(9.0);


      );


      public void circle ()

      CircleOptions options = new CircleOptions();
      options.setFillOpacity(0);
      options.setStrokeColor("#CB4335");
      options.setStrokeWeight(5.0);

      for (Intersetion inter: intersections)

      Circle circle = new Circle(map);
      circle.setCenter(new LatLng(inter.darLatitude(), inter.darLongitude()));
      circle.setRadius(50);
      circle.setOptions(options);


      public void rectangle()

      RectangleOptions options = new RectangleOptions();
      options.setFillOpacity(0);
      options.setStrokeColor("#2E86C1");
      int i = 0;
      for (Station rect: stations)

      Rectangle rectangulo = new Rectangle (map);
      LatLngBounds bounds = new LatLngBounds (new LatLng (rect.darLatitude() - 0.0004, rect.darLongitude() - 0.0006), new LatLng (rect.darLatitude() + 0.0004, rect.darLongitude() + 0.0006));
      rectangle.setBounds(bounds);
      rectangle.setOptions(optionts);












      share|improve this question















      For a project in my university, I need to show in a map all the intersections and some stations in Chicago, I already have LinkedLists with the data and I need to draw Circles with the position of the intersections and rectangles with the position of the stations. I'm using jxMaps library and based on the examples I was able to draw one circle and one rectangle testing the metods according with the examples provided by the developers, but if I try to draw multiple with a loop when I open the map, it stays in grey.
      This is my code:



      public class Draw extends MapView


      private static final long serialVersionUID = 1L;

      Map map;

      IList <Integer, Intersetion> intersections;

      IList <Integer, Station> stations;

      public Draw(MapViewOptions options, IList <Integer, Intersection> inter, IList <Integer, Station> est)

      super(options);
      // Setting of a ready handler to MapView object. onMapReady will be called when map initialization is done and
      // the map object is ready to use. Current implementation of onMapReady customizes the map object.
      setOnMapReadyHandler(new MapReadyHandler()

      @Override
      public void onMapReady(MapStatus status)

      // Check if the map is loaded correctly
      if (status == MapStatus.MAP_STATUS_OK)

      map = getMap();
      intersections = inter; // I Load the list with the intersections data
      stations = est; // I load the list with the stations data
      rectangle();
      circle();
      // Creating a map options object
      MapOptions mapOptions = new MapOptions();
      // Creating a map type control options object
      MapTypeControlOptions controlOptions = new MapTypeControlOptions();
      // Changing position of the map type control
      controlOptions.setPosition(ControlPosition.TOP_RIGHT);
      // Setting map type control options
      mapOptions.setMapTypeControlOptions(controlOptions);
      // Setting map options
      map.setOptions(mapOptions);
      // Setting the map center
      map.setCenter(new LatLng(41.875486, -87.626570));
      // Setting initial zoom value
      map.setZoom(9.0);


      );


      public void circle ()

      CircleOptions options = new CircleOptions();
      options.setFillOpacity(0);
      options.setStrokeColor("#CB4335");
      options.setStrokeWeight(5.0);

      for (Intersetion inter: intersections)

      Circle circle = new Circle(map);
      circle.setCenter(new LatLng(inter.darLatitude(), inter.darLongitude()));
      circle.setRadius(50);
      circle.setOptions(options);


      public void rectangle()

      RectangleOptions options = new RectangleOptions();
      options.setFillOpacity(0);
      options.setStrokeColor("#2E86C1");
      int i = 0;
      for (Station rect: stations)

      Rectangle rectangulo = new Rectangle (map);
      LatLngBounds bounds = new LatLngBounds (new LatLng (rect.darLatitude() - 0.0004, rect.darLongitude() - 0.0006), new LatLng (rect.darLatitude() + 0.0004, rect.darLongitude() + 0.0006));
      rectangle.setBounds(bounds);
      rectangle.setOptions(optionts);









      java google-maps jxmaps






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 5 at 3:27

























      asked Nov 11 at 5:47









      Juan Jose Torres

      13




      13






















          2 Answers
          2






          active

          oldest

          votes


















          1














          I've analyzed the provided source code and it looks ok, except of a place where you set the stroke color. You have to use colors in the HTML format, so you have to change:



          options.setStrokeColor(Color.RED.toString()); to options.setStrokeColor("#FF0000");


          However, it cannot be the reason for the gray screen. The gray screen usually happens when something went wrong while setting map attributes (inside onMapReady() handler).



          So you have to check if any exception happened and, if yes, then fix the root cause of it.



          Also, you can enable logging and check if it has any errors. You can do it by adding the -Djxmaps.logging.level=ALL parameter to the VM options of your application.



          EDIT________________________________________________________________________



          Here is a code sample which allows to create multiple circles:



          map.addEventListener("click", new MapMouseEvent() 
          @Override
          public void onEvent(MouseEvent mouseEvent)
          final Circle circle = new Circle(map);
          circle.setRadius(2000);
          circle.setCenter(mouseEvent.latLng());

          );





          share|improve this answer






















          • I checked and no exception was thrown, I think that the problem is when I instantiate many objects of type Circle and Rectangle, but in the examples, just one of each type is drawn at the time, how can I draw multiple of them?
            – Juan Jose Torres
            Dec 2 at 6:04










          • I have updated my answer with a code example.
            – Serhii Fedchenko
            Dec 3 at 14:28











          • And If I already have the data of the latlng in lists? So the circles are added and when I open the map they are already there.
            – Juan Jose Torres
            Dec 3 at 17:34



















          0














          Actually, for some reason, it works if I call the methods circle and rectangle at the end after setting the options of the map which is kind of weird considering that it works fine when I just create one circle or one rectangle in the order that appears in the question post.






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246186%2fhow-can-i-draw-multiple-circles-and-rectangles-on-a-map%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            I've analyzed the provided source code and it looks ok, except of a place where you set the stroke color. You have to use colors in the HTML format, so you have to change:



            options.setStrokeColor(Color.RED.toString()); to options.setStrokeColor("#FF0000");


            However, it cannot be the reason for the gray screen. The gray screen usually happens when something went wrong while setting map attributes (inside onMapReady() handler).



            So you have to check if any exception happened and, if yes, then fix the root cause of it.



            Also, you can enable logging and check if it has any errors. You can do it by adding the -Djxmaps.logging.level=ALL parameter to the VM options of your application.



            EDIT________________________________________________________________________



            Here is a code sample which allows to create multiple circles:



            map.addEventListener("click", new MapMouseEvent() 
            @Override
            public void onEvent(MouseEvent mouseEvent)
            final Circle circle = new Circle(map);
            circle.setRadius(2000);
            circle.setCenter(mouseEvent.latLng());

            );





            share|improve this answer






















            • I checked and no exception was thrown, I think that the problem is when I instantiate many objects of type Circle and Rectangle, but in the examples, just one of each type is drawn at the time, how can I draw multiple of them?
              – Juan Jose Torres
              Dec 2 at 6:04










            • I have updated my answer with a code example.
              – Serhii Fedchenko
              Dec 3 at 14:28











            • And If I already have the data of the latlng in lists? So the circles are added and when I open the map they are already there.
              – Juan Jose Torres
              Dec 3 at 17:34
















            1














            I've analyzed the provided source code and it looks ok, except of a place where you set the stroke color. You have to use colors in the HTML format, so you have to change:



            options.setStrokeColor(Color.RED.toString()); to options.setStrokeColor("#FF0000");


            However, it cannot be the reason for the gray screen. The gray screen usually happens when something went wrong while setting map attributes (inside onMapReady() handler).



            So you have to check if any exception happened and, if yes, then fix the root cause of it.



            Also, you can enable logging and check if it has any errors. You can do it by adding the -Djxmaps.logging.level=ALL parameter to the VM options of your application.



            EDIT________________________________________________________________________



            Here is a code sample which allows to create multiple circles:



            map.addEventListener("click", new MapMouseEvent() 
            @Override
            public void onEvent(MouseEvent mouseEvent)
            final Circle circle = new Circle(map);
            circle.setRadius(2000);
            circle.setCenter(mouseEvent.latLng());

            );





            share|improve this answer






















            • I checked and no exception was thrown, I think that the problem is when I instantiate many objects of type Circle and Rectangle, but in the examples, just one of each type is drawn at the time, how can I draw multiple of them?
              – Juan Jose Torres
              Dec 2 at 6:04










            • I have updated my answer with a code example.
              – Serhii Fedchenko
              Dec 3 at 14:28











            • And If I already have the data of the latlng in lists? So the circles are added and when I open the map they are already there.
              – Juan Jose Torres
              Dec 3 at 17:34














            1












            1








            1






            I've analyzed the provided source code and it looks ok, except of a place where you set the stroke color. You have to use colors in the HTML format, so you have to change:



            options.setStrokeColor(Color.RED.toString()); to options.setStrokeColor("#FF0000");


            However, it cannot be the reason for the gray screen. The gray screen usually happens when something went wrong while setting map attributes (inside onMapReady() handler).



            So you have to check if any exception happened and, if yes, then fix the root cause of it.



            Also, you can enable logging and check if it has any errors. You can do it by adding the -Djxmaps.logging.level=ALL parameter to the VM options of your application.



            EDIT________________________________________________________________________



            Here is a code sample which allows to create multiple circles:



            map.addEventListener("click", new MapMouseEvent() 
            @Override
            public void onEvent(MouseEvent mouseEvent)
            final Circle circle = new Circle(map);
            circle.setRadius(2000);
            circle.setCenter(mouseEvent.latLng());

            );





            share|improve this answer














            I've analyzed the provided source code and it looks ok, except of a place where you set the stroke color. You have to use colors in the HTML format, so you have to change:



            options.setStrokeColor(Color.RED.toString()); to options.setStrokeColor("#FF0000");


            However, it cannot be the reason for the gray screen. The gray screen usually happens when something went wrong while setting map attributes (inside onMapReady() handler).



            So you have to check if any exception happened and, if yes, then fix the root cause of it.



            Also, you can enable logging and check if it has any errors. You can do it by adding the -Djxmaps.logging.level=ALL parameter to the VM options of your application.



            EDIT________________________________________________________________________



            Here is a code sample which allows to create multiple circles:



            map.addEventListener("click", new MapMouseEvent() 
            @Override
            public void onEvent(MouseEvent mouseEvent)
            final Circle circle = new Circle(map);
            circle.setRadius(2000);
            circle.setCenter(mouseEvent.latLng());

            );






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 3 at 14:30

























            answered Nov 12 at 13:21









            Serhii Fedchenko

            512




            512











            • I checked and no exception was thrown, I think that the problem is when I instantiate many objects of type Circle and Rectangle, but in the examples, just one of each type is drawn at the time, how can I draw multiple of them?
              – Juan Jose Torres
              Dec 2 at 6:04










            • I have updated my answer with a code example.
              – Serhii Fedchenko
              Dec 3 at 14:28











            • And If I already have the data of the latlng in lists? So the circles are added and when I open the map they are already there.
              – Juan Jose Torres
              Dec 3 at 17:34

















            • I checked and no exception was thrown, I think that the problem is when I instantiate many objects of type Circle and Rectangle, but in the examples, just one of each type is drawn at the time, how can I draw multiple of them?
              – Juan Jose Torres
              Dec 2 at 6:04










            • I have updated my answer with a code example.
              – Serhii Fedchenko
              Dec 3 at 14:28











            • And If I already have the data of the latlng in lists? So the circles are added and when I open the map they are already there.
              – Juan Jose Torres
              Dec 3 at 17:34
















            I checked and no exception was thrown, I think that the problem is when I instantiate many objects of type Circle and Rectangle, but in the examples, just one of each type is drawn at the time, how can I draw multiple of them?
            – Juan Jose Torres
            Dec 2 at 6:04




            I checked and no exception was thrown, I think that the problem is when I instantiate many objects of type Circle and Rectangle, but in the examples, just one of each type is drawn at the time, how can I draw multiple of them?
            – Juan Jose Torres
            Dec 2 at 6:04












            I have updated my answer with a code example.
            – Serhii Fedchenko
            Dec 3 at 14:28





            I have updated my answer with a code example.
            – Serhii Fedchenko
            Dec 3 at 14:28













            And If I already have the data of the latlng in lists? So the circles are added and when I open the map they are already there.
            – Juan Jose Torres
            Dec 3 at 17:34





            And If I already have the data of the latlng in lists? So the circles are added and when I open the map they are already there.
            – Juan Jose Torres
            Dec 3 at 17:34














            0














            Actually, for some reason, it works if I call the methods circle and rectangle at the end after setting the options of the map which is kind of weird considering that it works fine when I just create one circle or one rectangle in the order that appears in the question post.






            share|improve this answer

























              0














              Actually, for some reason, it works if I call the methods circle and rectangle at the end after setting the options of the map which is kind of weird considering that it works fine when I just create one circle or one rectangle in the order that appears in the question post.






              share|improve this answer























                0












                0








                0






                Actually, for some reason, it works if I call the methods circle and rectangle at the end after setting the options of the map which is kind of weird considering that it works fine when I just create one circle or one rectangle in the order that appears in the question post.






                share|improve this answer












                Actually, for some reason, it works if I call the methods circle and rectangle at the end after setting the options of the map which is kind of weird considering that it works fine when I just create one circle or one rectangle in the order that appears in the question post.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 5 at 3:24









                Juan Jose Torres

                13




                13



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246186%2fhow-can-i-draw-multiple-circles-and-rectangles-on-a-map%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo