Thanks, I didn't know that these functions exists... and I can't find it in the documentation. (Is it a new modification from Version 1.1.1?)
It's a litle bit tricky to use these two functions for realising, because clearSelectedRegions deletes SelectedRegions stepp by stepp and starts with the first line of the function every stepp.
To save selected Regions I've used the length
of selectedRegions
or you can use length
of (container = map object) container.getSelectedRegions()
. Futhermore I've created a var named switch_land
their basic value is false
. If we have selected no region the length is 0, this is helpfull (I will show you the reason later).
length = selectedRegions.length;
switch_land = false;
if (length === 1) {
land_first = selectedRegions[0];
}
land_first saves the first land you've selected. In the second stepp it is important to find the new selected region. By testing I've found that the second value of selectedRegions is not every time the second region you've selected.
if (length === 2) {
if (land_first !== selectedRegions[0]) {
selectedRegions[1] = selectedRegions[0];
selectedRegions[0] = land_first;
the last two lines save the first selected Region to selectedRegion[0]
. These is very good because now we can use the function pop() to save every time the newest selected region because the region is always saved in the second value of selected region array.
}
region_delete = true;
regions = selectedRegions;
land_secound = regions.pop();
container.clearSelectedRegions();
switch_land = true;
}
I've used region_delete in next stepp to stopp manuel deselecting. (You can click once, twice etc. on a region and the region remains selcted as long as you click on another region)
if (typeof region_delete === 'undefined'){
region_delete = false;
}
if (length === 0 && region_delete === false){
selected_region(land_first, false, true);
}
I will describe the function selected_region in the end. Finaly we have to select the newest land. And I've used length
0 along with region_delte
to find out the moment while a user click on a region to deselect the region.
if (switch_land === true) {
selectedRegions[0] = land_secound;
selected_region(land_secound, false, true);
delete land_secound;
region_delete = false;
}
Thats all. Now I will give you an example of selected_region with region GER.
function selected_region(selected_regions, status_1, status_2) {
switch (selected_regions) {
case "GER":
container.regions.GER.element.isSelected = status_1;
container.regions.GER.element.setSelected(status_2);
break;
}
}
For region swichting it is important that you chose status_1 = false
, if you didn't chose false you can see that the land is hovered and the selecting color will be show after region mouse out.
The Problem is that I can't use a var to change values something like container.regions.selectedRegions[0].element.setSelected(status_2);
and these is the main problem and the reason I've written the first question ;)