Continuing the explanation of the ways, where we can upgrade the QGIS2web plugin manually, I would like to explain how to expand the search range in this plugin for more than 1 layer. The plugin supports the option for 1 layer only, but if you need more, coding is required. My goal is to show another way (although a bit longer I guess) to make our search tool more effective for people, who are not clued up with any programming knowledge.
My project includes 65 separate layers exactly. I want 10 of them to be researchable by a single object included (Pic. 1).
In QGIS2web plugin settings, you can include only 1 layer in the search tool (Pic. 2).
We need to have 10 layers instead of 1 here. In this event, we should follow the steps below, which will lead us to achieve our goal.
1. Save (Export) each layer as the .csv file with proper geometry – the export itself is not difficult, because we literally move out the data attribute table into the Excel file.
However, we have to remember geometry, as I mentioned above. This is driven by layer type. In all the layers we have shapes. It means, that they include more than 1 coordinate (each node/corner is defined by coordinates). Next, we should save our file and repeat this process for all layers, we want to have searchable. Make also sure, that the new layer CRS matches your project.
2. When all your layers have been downloaded you should open one of them and start building your big .csv file, where you will add up all other layers. The first file you open, save it under another name, and start to work on it. Since all of your new layers are opened in QGIS, you will get an alert, that the .csv file you opened is read-only.
Merging .csv files is not a big deal either. We should just remember a couple of important steps. The first one is our “fid” column, which is unique for every single record. We have to drag down the column range covering our 1st file (Pic 4, 3b) and apply the autofill for all our elements. Another thing is the optional name of our ID. If it’s repeatable it’s good to provide some special string, which will make them easy to find (Pic. 4, 3a). Black and red bounds indicate the column, which will be used for our search. It’s the ID column from our first file, which will be applicable also to the stuff from the next files at the bottom. Carry on this process for all your .csv files downloaded. Make this way one big .csv file including data from all your layers (especially the ID column). Make sure, that the column layout is the same (if not, shift them or trim down some stuff) and object coordinates are provided (in my case X and Y). If not, they won’t be visible on our map.
When you have done so, then there might be a necessity to organize your data, namely, place it alphabetically. In this event, you can select a whole ID column and next choose “Data” from your main Excel bar, where you can click one of the “AZ” options and order your data properly. When the toll asks you, please “Expand the selection”, which will be applicable to our all records (Pic. 5).
Now, as you can see, there is a common error in the image above. I selected the entire column with their name. We can’t do that. We should switch off the very first row, which includes the names of our columns (Pic. 6).
3. Next, the most important step is the import our .csv file to our QGIS project. From our main bar, we should choose the “Layer” and next add our layer as per the instruction below (Pic. 7).
Our layer should be instantly visible. All objects should exactly overlap the previous ones being earlier in the same place. It means, that everything is correct.
4. We don’t want this layer to be visible. We need to style it a bit. Namely, switch off any symbols related to this layer and make it invisible on our map (Pic. 8).
When the shape next to our layer is colorless, it means, that layer is invisible to us.
5. The last step is setting the QGIS2web plugin, where we should make two steps. First of all, switch off the layer we created, although not completely! We don’t need it visible and it’s pop-ups at once (Pic. 9).
Another, the most important step is setting the “Layer search” option, which we know already from the very beginning of this article (Pic. 2). In this case, we should select our newly imported layer and next, certainly, the column, which we want to base our search on (Pic. 10). It will be the ID column discussed previously (Pic. 4).
Finally, we can enjoy our interactive map, on which we are able to find objects belonging to 10 layers instead of 1.
- Add search option