Plot 2 different coordinates list in one map

I have 2 list with coordinates. ‘XY’ and ‘nieuwe_XY’.
I want to plot these coordinates at the the same time with a Multiselectfield.
There are no errors.

It is possible to plot the lists separated, but it is not possible to plot them at the same time in the same map.
How can I solve this?

class Controller(ViktorController):
    label = 'My Entity Type'
    parametrization = Parametrization


    @MapView('Map view', duration_guess=1)
    def get_map_view(self, params, **kwargs):
        radius = params.radius
        features = []
        for i in params.options:
            if i == 'Existing playgrounds':
                for x, y in XY:
                    features.append(MapPoint(x, y))
                return MapResult(features)
            elif i == 'New playgrounds':
                for nieuwe_x, nieuwe_y in nieuwe_XY:
                    features.append(MapPoint(nieuwe_x, nieuwe_y))
                return MapResult(features)
            elif i == 'Existing playgrounds' and i == 'New playgrounds':
                for x, y in XY:
                    features.append(MapPoint(x, y))
                for nieuwe_x, nieuwe_y in nieuwe_XY:
                    features.append(MapPoint(nieuwe_x, nieuwe_y))
                return MapResult(features)

Hi @Thijs,

Your statement elif i == 'Existing playgrounds' and i == 'New playgrounds': will never be true, as i is either one or the other, but never both at the same time. Therefore, if both options are selected you can simply append both to features and only returning the MapResult at the end of the function, as below:

class Controller(ViktorController):
    label = 'My Entity Type'
    parametrization = Parametrization


    @MapView('Map view', duration_guess=1)
    def get_map_view(self, params, **kwargs):
        radius = params.radius
        features = []
        for i in params.options:
            if i == 'Existing playgrounds':
                for x, y in XY:
                    features.append(MapPoint(x, y))
            elif i == 'New playgrounds':
                for nieuwe_x, nieuwe_y in nieuwe_XY:
                    features.append(MapPoint(nieuwe_x, nieuwe_y))
        return MapResult(features)

Please let us know whether this solved your problem!

1 Like

@Sylvain Thanks, this solved my problem. But how can I add a new color to the points of ‘New Playgrounds’. So you can see the difference between ‘Existing playgrounds’ and ‘New Playgrounds’ on the map?

@Thijs A MapPoint is based on a MapFeature, which handles the parameter color, which then links to Color . Hence, you can set the color parameter in a MapPoint.

In your example this would result in the following:

class Controller(ViktorController):
    label = 'My Entity Type'
    parametrization = Parametrization


    @MapView('Map view', duration_guess=1)
    def get_map_view(self, params, **kwargs):
        radius = params.radius
        features = []
        for i in params.options:
            if i == 'Existing playgrounds':
                for x, y in XY:
                    features.append(MapPoint(x, y, color=Color.red()))
            elif i == 'New playgrounds':
                for nieuwe_x, nieuwe_y in nieuwe_XY:
                    features.append(MapPoint(nieuwe_x, nieuwe_y, color=Color.green()))
        return MapResult(features)

Don’t forget to import Color! Also, I just randomly picked green and red, yet these might not be the best for colorblindness…

1 Like