How to show/hide layers in Mapbox on the client - reactjs

I'm working on a web app with Nextjs, Mapbox and react-map-gl. On the client side I would add some controls to show/hide specific POIs, for example restaurants, museums and landmarks.
I tried various ways and found multiple examples that were not specific to my problem. Nevertheless I'll note them down here, so you can see what I tried and why it failed.
Change the categories in Mapbox studio
There is a possibility to show/hide the POI categories in Mapbox studio, however this is static and I want to make this sort of changes on the client side.
Two examples from from Mapbox
"Filter symbols by toggling a list"
"show and hide layers"
Those examples show very well what I want to achieve. Simple UI buttons where I can show/hide certain POI categories, for example Theatre, Museum, Bar, Bicycle.
The downside is that the data is added manually - after that map is loaded. I'm looking for a way to show/hide the POI categories on the existing map data I receive from Mapbox.
Copy POI layer
I found a third option that suggest to copy the POI layers "Hide mapbox POI in runtime". It doesn't seem like a proper solution, but I'll give it a try and share my feedback afterwards.
Do you guys know how I can properly show/hide categories at runtime from the POI-Layer in Mapbox?
I'm thankful for any help.

You can use the same approach shown in the "show and hide layers" example you linked to. Once you have a layer on the map for each POI group you want to control, use map.setLayoutProperty(layername, 'visibility', 'none') to hide, and map.setLayoutProperty(layername, 'visibility', 'visible') to show.
Layers added after the map loads are no different than the layers that are included with the main style. The "show and hide layers" example shows sources and layers added after the map loads, they are just coming from mapbox-hosted vector tiles, not geojson files.

Thanks chriswhong. For anyone working with react-map-gl, there is one more thing to consider.
The setLayoutProperty is at the time of my writing not available on mapRef and on the useMap hook.
According to the create-ref.ts file from react-map-gl the setLayoutProperty is part of the methods that may break the react binding if called directly.
According to the official react-map-gl documentation you can you can still access the hidden members via getMap(), as it can be seen in the following example via console log.
codesandbox.io/s/zealous-poincare-ti5qx9

Related

How can I link custom community visualization to other pages in a report?

I built a community visualization with various fields. One field that I'm adding is a URL, composed as the documentation suggests, that links to a filter in another page.
While the URL is fine and working, I cannot use it in a normal link or a form because the iframe in which the community visualization is embedded is sandboxed to allow only scripts.
Is there another way to change the top frame navigation, or switch to another page from within the visualization? Maybe through a javascript call?
Thanks
Community Visualizations do not allow links to external resources, so there's no way to make the visualization act as a link to a filter on another page.

How can i automate Google map image on web page?

I am not able to automate google map screen which is present on my application web page.
I have web page where google map is present in square in half of screen. I want to click on the road present in map or a restaurant logo which is present on the google map.
When i tried to find the locators for the map then in the DOM it is present as an image and no other html properties or locators are associated with it.
Also i tried an option using moveToElement() function of action class but this solution is not reliable as most of the time it is not working.
Please suggest me any solution for this automation issue if someone faced this issue of Google maps automation before ?
Sounds like HTML5 issue over a google maps issue. This is tricky for Selenium, see these articles:
https://www.linkedin.com/pulse/html-canvas-testing-selenium-opencv-maciej-kusz/
https://chariotsolutions.com/blog/post/automated-testing-of-html5-canvas/
which recommend using action chains to move to and click certain x,y coordinates.
Also, check out the canvas javascript api; you may be able to use javascript_executor to manipulate the canvas.

HTML Page from selected row in Spotfire

I have come across a requirement that is already available in the current tool and they expect it to be implemented in Spotfire as well.
Requirement: Once data is loaded in Spotfire and they click on a row, there is a button "View in Web" that will render that selected row in a beautiful static HTML page in a new window.
My Logic so far: I'll store the column values in variables using ironpyton as explained in https://techgoje.wordpress.com/2014/12/02/spotfire-ironpython-accessing-column-values-in-script-context/ and then i'll render those values in HTML page
Any suggestion or help is greatly appreciated.
I have never tried to open a popup or new window in Spotfire. my guess is that you could do it in the Web Player, but it may not work in the thick client.
I've created an example DXP that shows how IronPython and Javascript can interact to render HTML content in a textarea. this may be a good solution for you.
(NOTE: you will need to trust all of the IP and JS scripts in this document!)

How to serve separate page (Orchard template) for phones

Using Orchard 1.8.1 I have written a simple image gallery that displays thumbnails and a lightbox. It is just a template that is driven by an Orchard Projection, using a Shape Layout. Works just fine. However, for phone users there is no point displaying thumbnails and it's better to just display the lightbox (with touch support). So I have also implemented that in a separate template. But how can I get Orchard to switch templates depending on the UserAgent string?
I have tried implementing Theme switching (http://weblogs.asp.net/bleroy/dynamically-switching-the-theme-in-orchard), but it's a really ugly solution when I really want to just replace one view, and still enable implementers to switch themes. This is NOT an issue of styling; it's an issue of changing the content based on the device.
I tried implementing DisplayModeProvider as described here: http://www.campusmvp.net/blog/displaymodes-in-mvc-4. But although the filter was called, it had no effect on view names.
Are Projections problematic here because the shape name is set? Is there a better way to go about this?
Create an alternate when you see a mobile browser, preferably from a shape table provider.

Best Way to Create Image Gallery

Please provide any examples or links which clearly explaining to create simple image gallery in Drupal 7.
Actually the image gallery should be in Thumb Nail Image with 4 images per row.
It should be categorized with simple menu.
If there is sub category, then there should be drop down menus.
Finally the gallery should be with pagination links.
I've tried with taxamony, but it not clear display as expected in front end.
Please provide the better way either thru code or any modules available.
There are different ways to do an image gallery. If something like galleria is what you are looking for you can do it very easily just by using an image field and drupal galleria module.
But in your case, you will have to use views. In that pull out the images you want, choose the
display as grid. Set the no. of columns to 4. Link to the original image. Then you can use the
Lightbox module to open them in a lightbox, if you want one.
For pagination you can use the default views pagination settings.
This might help you. Check out.

Resources