-
Notifications
You must be signed in to change notification settings - Fork 16
Add Legend in layer control settings #1055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AliyanH
wants to merge
1
commit into
Maps4HTML:main
Choose a base branch
from
AliyanH:Legend-design
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+196
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
|
||
| <head> | ||
| <title>Layer Legend Control Tests</title> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <script type="module" src="mapml.js"></script> | ||
| <style> | ||
| html, | ||
| body { | ||
| height: 100%; | ||
| } | ||
|
|
||
| * { | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
|
|
||
| mapml-viewer:defined { | ||
| max-width: 100%; | ||
| width: 100%; | ||
| height: 100%; | ||
| } | ||
|
|
||
| mapml-viewer:not(:defined) > * { | ||
| display: none; | ||
| } | ||
|
|
||
| map-layer { | ||
| display: none; | ||
| } | ||
| </style> | ||
| </head> | ||
|
|
||
| <body> | ||
| <mapml-viewer projection="CBMTILE" zoom="2" lat="45" lon="-95" controls> | ||
| <map-layer label="Toporama" src="data/templatedImage.mapml" checked></map-layer> | ||
|
|
||
| <map-layer label="Inline No Legend" checked> | ||
| <map-meta name="zoom" content="min=0,max=3,value=2"></map-meta> | ||
| <map-meta name="projection" content="CBMTILE"></map-meta> | ||
| <map-tile zoom="2" row="10" col="11" src="data/cbmt/2/c11_r10.png"></map-tile> | ||
| </map-layer> | ||
|
|
||
| <map-layer label="html legend" checked> | ||
| <map-meta name="zoom" content="min=0,max=3,value=2"></map-meta> | ||
| <map-meta name="projection" content="CBMTILE"></map-meta> | ||
| <map-link rel="legend" href="https://maps4html.org/web-map-doc/"></map-link> | ||
| <map-feature> | ||
| <map-geometry cs="gcrs"> | ||
| <map-point class="ottawa"> | ||
| <map-coordinates>-75.697193 45.421530</map-coordinates> | ||
| </map-point> | ||
| </map-geometry> | ||
| </map-feature> | ||
| </mapml-viewer> | ||
| </body> | ||
|
|
||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { test, expect, chromium } from '@playwright/test'; | ||
|
|
||
| test.describe('Layer legend tests', () => { | ||
| let page; | ||
| let context; | ||
|
|
||
| test.beforeAll(async () => { | ||
| context = await chromium.launchPersistentContext('', { slowMo: 250 }); | ||
| page = await context.newPage(); | ||
| await page.goto('layerLegend.html'); | ||
| await page.locator('mapml-viewer').hover(); | ||
| }); | ||
|
|
||
| test.afterAll(async () => { | ||
| await context.close(); | ||
| }); | ||
|
|
||
| test('Legend layer has legend details in layer settings', async () => { | ||
| // Get the first layer in the overlay list (the one with an img legend) | ||
| const layer = page | ||
| .locator('.leaflet-control-layers-overlays > fieldset') | ||
| .first(); | ||
|
|
||
| // Open the settings for that layer and check that the legend details are present | ||
| const settings = layer.locator('.mapml-layer-item-settings'); | ||
|
|
||
| // Check that the legend details, name, and link are present and correct | ||
| const legendDetails = settings.locator('details.mapml-layer-item-legend'); | ||
| await expect(legendDetails).toHaveCount(1); | ||
| await expect(legendDetails.locator('summary')).toHaveText('Legend'); | ||
| await expect( | ||
| legendDetails.locator('a.mapml-layer-item-legend-link') | ||
| ).toHaveAttribute( | ||
| 'href', | ||
| 'http://maps.geogratis.gc.ca/wms/toporama_en?SERVICE=WMS&REQUEST=GetLegendGraphic&LAYER=WMS-Toporama&VERSION=1.1&FORMAT=image/png' | ||
| ); | ||
| await expect( | ||
| legendDetails.locator('img.mapml-layer-item-legend-image') | ||
| ).toHaveAttribute( | ||
| 'src', | ||
| 'http://maps.geogratis.gc.ca/wms/toporama_en?SERVICE=WMS&REQUEST=GetLegendGraphic&LAYER=WMS-Toporama&VERSION=1.1&FORMAT=image/png' | ||
| ); | ||
|
|
||
| // check that the legend details are the second details element in the settings | ||
| const secondDetails = settings.locator('> details').nth(1); | ||
| await expect(secondDetails).toHaveClass( | ||
| 'mapml-layer-item-legend mapml-control-layers' | ||
| ); | ||
| }); | ||
|
|
||
| test('Layer without legend does not render legend details in settings', async () => { | ||
| // Get the second layer in the overlay list (the one without a legend) | ||
| const layer = page | ||
| .locator('.leaflet-control-layers-overlays > fieldset') | ||
| .nth(1); | ||
|
|
||
| // check that the settings for that layer do not contain any legend details | ||
| const settings = layer.locator('.mapml-layer-item-settings'); | ||
| await expect( | ||
| settings.locator('details.mapml-layer-item-legend') | ||
| ).toHaveCount(0); | ||
| }); | ||
|
|
||
| test('Layer with a non img legend renders a legend link', async () => { | ||
| // Get the third layer in the overlay list (the one with a non img legend) | ||
| const layer = page | ||
| .locator('.leaflet-control-layers-overlays > fieldset') | ||
| .nth(2); | ||
|
|
||
| // check that the settings for that layer contain a legend link | ||
| const settings = layer.locator('.mapml-layer-item-settings'); | ||
|
|
||
| // Check that the legend details, name, and link are present and correct | ||
| const legendDetails = settings.locator('details.mapml-layer-item-legend'); | ||
| await expect(legendDetails).toHaveCount(1); | ||
| await expect(legendDetails.locator('summary')).toHaveText('Legend'); | ||
| await expect( | ||
| legendDetails.locator('a.mapml-layer-item-legend-link') | ||
| ).toHaveAttribute('href', 'https://maps4html.org/web-map-doc/'); | ||
|
|
||
| // not working, need to manually open the legend for it to update. | ||
| /*await expect( | ||
| legendDetails.locator('a.mapml-layer-item-legend-link') | ||
| ).toHaveText("Open Legend"); | ||
| */ | ||
|
|
||
| // check that the legend details are the second details element in the settings | ||
| const secondDetails = settings.locator('> details').nth(1); | ||
| await expect(secondDetails).toHaveClass( | ||
| 'mapml-layer-item-legend mapml-control-layers' | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to localize