Skip to content
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

geolocation button closes issue#780 #800

Merged
merged 42 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e0b128c
geolocation button
Jacky0299 Mar 15, 2023
9484cdb
Delete index.js
Jacky0299 Mar 15, 2023
49b3487
Delete multipleExtents.html
Jacky0299 Mar 15, 2023
aadc794
some changes to the file
Jacky0299 Mar 15, 2023
968b1d9
Merge branch 'issue780' of https://github.com/Jacky0299/Web-Map-Custo…
Jacky0299 Mar 15, 2023
af85058
button name change
Jacky0299 Mar 16, 2023
de402fc
Merge branch 'main' of https://github.com/Maps4HTML/Web-Map-Custom-El…
Jacky0299 Mar 16, 2023
b86c0d4
minor edits
prushforth Mar 20, 2023
387ffda
geolocation sync with controlslist api
Jacky0299 Mar 20, 2023
8cd9162
tests fixed and syncing web-map
Jacky0299 Mar 20, 2023
94c69e1
Peter suggested changes
Jacky0299 Mar 21, 2023
f13c8f0
locate api
Jacky0299 Mar 23, 2023
f155ba0
locateapi and locate button test
Jacky0299 Mar 24, 2023
495c551
tests
Jacky0299 Mar 27, 2023
d4bcb2c
locate button title changes when its state changes
Jacky0299 Mar 28, 2023
f0220f3
locatebutton states test
Jacky0299 Mar 29, 2023
709a288
web-map syncing
Jacky0299 Mar 29, 2023
88c449e
Remove the word "control" from button title
prushforth Mar 29, 2023
31c6309
Merge branch 'issue780' of https://github.com/Jacky0299/Web-Map-Custo…
prushforth Mar 29, 2023
df109df
Remove the word "control" from button title
prushforth Mar 29, 2023
c91d0c4
Fix test
prushforth Mar 29, 2023
5b2b6ff
grunt file change
Jacky0299 Mar 29, 2023
ffcdf13
Merge branch 'issue780' of https://github.com/Jacky0299/Web-Map-Custo…
Jacky0299 Mar 29, 2023
9452f0e
Finalize text strings prior to localization
prushforth Mar 29, 2023
1de354d
Localize text strings for location control button states
prushforth Mar 29, 2023
0ae2302
Merge branch 'issue780' of https://github.com/Jacky0299/Web-Map-Custo…
prushforth Mar 29, 2023
4697f54
custom marker
Jacky0299 Mar 29, 2023
9bf5f7b
small changes and tests
Jacky0299 Mar 30, 2023
2fc5334
locate APi bug fix
Jacky0299 Mar 30, 2023
98c769b
minor styling fix
AliyanH Mar 30, 2023
830c888
marker image made to svg
Jacky0299 Apr 3, 2023
0cdff5d
Alliyan suggested changes
Jacky0299 Apr 3, 2023
c993c2c
locateapi test bug fix
Jacky0299 Apr 3, 2023
31d6402
marker title changes depends on statr
Jacky0299 Apr 3, 2023
c06ef45
Localize text strings for my current or cached location marker
prushforth Apr 3, 2023
76bfb75
Update test to use variables for geolocation button states
prushforth Apr 4, 2023
76191b6
tooltip focus
Jacky0299 Apr 4, 2023
f7b0341
tooltip test added
Jacky0299 Apr 4, 2023
0deb72b
geolocationbutton code refactored
Jacky0299 Apr 5, 2023
796cb2b
Merge branch 'main' of https://github.com/Maps4HTML/Web-Map-Custom-El…
Jacky0299 Apr 5, 2023
ba0052f
fixed tests and small fixes
Jacky0299 Apr 5, 2023
451a6d2
Formatting
prushforth Apr 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = function(grunt) {
},
combine: {
files: {
'dist/mapml.css': ['node_modules/leaflet/dist/leaflet.css', 'src/mapml.css']
'dist/mapml.css': ['node_modules/leaflet/dist/leaflet.css', 'node_modules/leaflet.locatecontrol/dist/L.Control.Locate.css', 'node_modules/leaflet.locatecontrol/dist/L.Control.Locate.mapbox.css', 'src/mapml.css']
AliyanH marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
Expand Down Expand Up @@ -87,6 +87,14 @@ module.exports = function(grunt) {
filter: 'isFile',
src: ['index.html'],
dest: 'dist/'
},
{
expand: true,
cwd: 'node_modules/leaflet.locatecontrol/src/',
flatten: true,
filter: 'isFile',
src: ['L.Control.Locate.js'],
dest: 'dist/'
}
],
options: {
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"jest-environment-node": "^26.6.1",
"jest-playwright-preset": "^1.7.0",
"leaflet": "^1.9.3",
"leaflet.locatecontrol": "^0.79.0",
"path": "^0.12.7",
"@playwright/test": "^1.24.2",
"playwright": "^1.24.2",
Expand Down
56 changes: 55 additions & 1 deletion src/mapml-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class MapViewer extends HTMLElement {
this._controlsList = new DOMTokenList(
this.getAttribute("controlslist"),
this, "controlslist",
["noreload","nofullscreen","nozoom","nolayer"]
["noreload","nofullscreen","nozoom","nolayer","geolocation"]
);

// the dimension attributes win, if they're there. A map does not
Expand Down Expand Up @@ -354,6 +354,18 @@ export class MapViewer extends HTMLElement {
totalSize += 49;
this._fullScreenControl = M.fullscreenButton().addTo(this._map);
}
if (!this._geolocationButton){
this._geolocationButton = M.geolocationButton({
showPopup: false,
strings: {
title: "Show my location"
},
position: "bottomright",
locateOptions: {
maxZoom: 16
prushforth marked this conversation as resolved.
Show resolved Hide resolved
},
},this._map);
prushforth marked this conversation as resolved.
Show resolved Hide resolved
}
}

// Sets controls by hiding/unhiding them based on the map attribute
Expand All @@ -372,12 +384,14 @@ export class MapViewer extends HTMLElement {
this._setControlsVisibility("layercontrol",true);
this._setControlsVisibility("reload",true);
this._setControlsVisibility("zoom",true);
this._setControlsVisibility("geolocation",true);
}
_showControls() {
this._setControlsVisibility("fullscreen",false);
this._setControlsVisibility("layercontrol",false);
this._setControlsVisibility("reload",false);
this._setControlsVisibility("zoom",false);
this._setControlsVisibility("geolocation",true);

// prune the controls shown if necessary
// this logic could be embedded in _showControls
Expand All @@ -398,6 +412,9 @@ export class MapViewer extends HTMLElement {
case 'nozoom':
this._setControlsVisibility("zoom",true);
break;
case 'geolocation':
this._setControlsVisibility("geolocation",false);
break;
}
});
}
Expand Down Expand Up @@ -431,6 +448,11 @@ export class MapViewer extends HTMLElement {
container = this._layerControl._container;
}
break;
case "geolocation":
if (this._geolocationButton) {
container = this._geolocationButton._container;
}
break;
}
if (container) {
if (hide) {
Expand Down Expand Up @@ -525,6 +547,24 @@ export class MapViewer extends HTMLElement {
{target: this}}));
}
});
this._map.on('locationfound',
function (e) {
this.dispatchEvent(new CustomEvent('maplocationfound', {detail:
AliyanH marked this conversation as resolved.
Show resolved Hide resolved
{latlng: e.latlng, radius: e.accuracy}
AliyanH marked this conversation as resolved.
Show resolved Hide resolved
}));
},this);
this.addEventListener('maplocationfound', function(e) {
//'Location found:', e.detail.latlng, 'Radius:', e.detail.radius
});
this._map.on('locationerror',
function (e) {
this.dispatchEvent(new CustomEvent('locationerror', {detail:
{error:e.message}
}));
},this);
this.addEventListener('locationerror', function(e) {
//error:e.detail.error
});
this._map.on('load',
function () {
this.dispatchEvent(new CustomEvent('load', {detail: {target: this}}));
Expand Down Expand Up @@ -656,6 +696,20 @@ export class MapViewer extends HTMLElement {
}
});
}
locate(options){
AliyanH marked this conversation as resolved.
Show resolved Hide resolved
if (this._map) {
if (options) {
if (options.zoomTo) {
options.setView = options.zoomTo;
delete options.zoomTo;
}
this._map.locate(options);
} else {
this._map.locate({setView: true, maxZoom: 16});
}
}
}

toggleDebug(){
if(this._debug){
this._debug.remove();
Expand Down
4 changes: 4 additions & 0 deletions src/mapml/control/GeolocationButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import '../../../dist/L.Control.Locate';
export var geolocationButton = function (options, map) {
return L.control.locate(options).addTo(map);
};
5 changes: 4 additions & 1 deletion src/mapml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ import { ContextMenu } from './handlers/ContextMenu';
import { Util } from './utils/Util';
import { ReloadButton, reloadButton } from './control/ReloadButton';
import { FullscreenButton, fullscreenButton } from './control/FullscreenButton';
import {attributionControl} from "./control/AttributionControl";
import {attributionControl} from "./control/AttributionControl";
import {geolocationButton} from "./control/GeolocationButton";
import { Crosshair, crosshair } from "./layers/Crosshair";
import { Feature, feature } from "./features/feature";
import { FeatureRenderer, featureRenderer } from './features/featureRenderer';
Expand Down Expand Up @@ -659,6 +660,8 @@ M.fullscreenButton = fullscreenButton;

M.attributionControl = attributionControl;

M.geolocationButton = geolocationButton;

M.StaticTileLayer = StaticTileLayer;
M.staticTileLayer = staticTileLayer;

Expand Down
24 changes: 23 additions & 1 deletion src/web-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class WebMap extends HTMLMapElement {
this._controlsList = new DOMTokenList(
this.getAttribute("controlslist"),
this, "controlslist",
["noreload","nofullscreen","nozoom","nolayer"]
["noreload","nofullscreen","nozoom","nolayer","geolocation"]
);

// the dimension attributes win, if they're there. A map does not
Expand Down Expand Up @@ -397,6 +397,18 @@ export class WebMap extends HTMLMapElement {
totalSize += 49;
this._fullScreenControl = M.fullscreenButton().addTo(this._map);
}
if (!this._geolocationButton){
AliyanH marked this conversation as resolved.
Show resolved Hide resolved
this._geolocationButton = M.geolocationButton({
showPopup: false,
strings: {
title: "Show my location"
},
position: "bottomright",
locateOptions: {
maxZoom: 24
},
},this._map);
}
}

// Sets controls by hiding/unhiding them based on the map attribute
Expand All @@ -415,12 +427,14 @@ export class WebMap extends HTMLMapElement {
this._setControlsVisibility("layercontrol",true);
this._setControlsVisibility("reload",true);
this._setControlsVisibility("zoom",true);
this._setControlsVisibility("geolocation",true);
}
_showControls() {
this._setControlsVisibility("fullscreen",false);
this._setControlsVisibility("layercontrol",false);
this._setControlsVisibility("reload",false);
this._setControlsVisibility("zoom",false);
this._setControlsVisibility("geolocation",true);

// prune the controls shown if necessary
// this logic could be embedded in _showControls
Expand All @@ -441,6 +455,9 @@ export class WebMap extends HTMLMapElement {
case 'nozoom':
this._setControlsVisibility("zoom",true);
break;
case 'geolocation':
this._setControlsVisibility("geolocation",false);
break;
}
});
}
Expand Down Expand Up @@ -474,6 +491,11 @@ export class WebMap extends HTMLMapElement {
container = this._layerControl._container;
}
break;
case "geolocation":
if (this._geolocationButton) {
container = this._geolocationButton._container;
}
break;
}
if (container) {
if (hide) {
Expand Down
35 changes: 35 additions & 0 deletions test/e2e/api/domApi-mapml-viewer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ test.describe("mapml-viewer DOM API Tests", () => {
let reloadHidden = await page.$eval(".leaflet-top.leaflet-left > .mapml-reload-button", (div) => div.hidden);
let fullscreenHidden = await page.$eval(".leaflet-top.leaflet-left > .leaflet-control-fullscreen", (div) => div.hidden);
let layerControlHidden = await page.$eval(".leaflet-top.leaflet-right > .leaflet-control-layers", (div) => div.hidden);
let geolocation = await page.$eval(".leaflet-bottom.leaflet-right > .leaflet-control-locate", (div) => div.hidden);
expect(geolocation).toEqual(true);
expect(zoomHidden).toEqual(true);
expect(reloadHidden).toEqual(true);
expect(fullscreenHidden).toEqual(true);
Expand Down Expand Up @@ -135,6 +137,8 @@ test.describe("mapml-viewer DOM API Tests", () => {
let reloadHidden = await page.$eval(".leaflet-top.leaflet-left > .mapml-reload-button", (div) => div.hidden);
let fullscreenHidden = await page.$eval(".leaflet-top.leaflet-left > .leaflet-control-fullscreen", (div) => div.hidden);
let layerControlHidden = await page.$eval(".leaflet-top.leaflet-right > .leaflet-control-layers", (div) => div.hidden);
let geolocation = await page.$eval(".leaflet-bottom.leaflet-right > .leaflet-control-locate", (div) => div.hidden);
expect(geolocation).toEqual(true);
expect(zoomHidden).toEqual(true);
expect(reloadHidden).toEqual(true);
expect(fullscreenHidden).toEqual(true);
Expand All @@ -153,6 +157,8 @@ test.describe("mapml-viewer DOM API Tests", () => {
let reloadHidden = await page.$eval(".leaflet-top.leaflet-left > .mapml-reload-button", (div) => div.hidden);
let fullscreenHidden = await page.$eval(".leaflet-top.leaflet-left > .leaflet-control-fullscreen", (div) => div.hidden);
let layerControlHidden = await page.$eval(".leaflet-top.leaflet-right > .leaflet-control-layers", (div) => div.hidden);
let geolocation = await page.$eval(".leaflet-bottom.leaflet-right > .leaflet-control-locate", (div) => div.hidden);
expect(geolocation).toEqual(true);
expect(zoomHidden).toEqual(true);
expect(reloadHidden).toEqual(true);
expect(fullscreenHidden).toEqual(true);
Expand All @@ -168,6 +174,8 @@ test.describe("mapml-viewer DOM API Tests", () => {
let reloadHidden = await page.$eval(".leaflet-top.leaflet-left > .mapml-reload-button", (div) => div.hidden);
let fullscreenHidden = await page.$eval(".leaflet-top.leaflet-left > .leaflet-control-fullscreen", (div) => div.hidden);
let layerControlHidden = await page.$eval(".leaflet-top.leaflet-right > .leaflet-control-layers", (div) => div.hidden);
let geolocation = await page.$eval(".leaflet-bottom.leaflet-right > .leaflet-control-locate", (div) => div.hidden);
expect(geolocation).toEqual(true);
expect(zoomHidden).toEqual(false);
expect(reloadHidden).toEqual(false);
expect(fullscreenHidden).toEqual(false);
Expand Down Expand Up @@ -231,6 +239,8 @@ test.describe("mapml-viewer DOM API Tests", () => {
let reloadHidden = await page.$eval(".leaflet-top.leaflet-left > .mapml-reload-button", (div) => div.hidden);
let fullscreenHidden = await page.$eval(".leaflet-top.leaflet-left > .leaflet-control-fullscreen", (div) => div.hidden);
let layerControlHidden = await page.$eval(".leaflet-top.leaflet-right > .leaflet-control-layers", (div) => div.hidden);
let geolocation = await page.$eval(".leaflet-bottom.leaflet-right > .leaflet-control-locate", (div) => div.hidden);
expect(geolocation).toEqual(true);
expect(zoomHidden).toEqual(true);
expect(reloadHidden).toEqual(false);
expect(fullscreenHidden).toEqual(true);
Expand All @@ -250,6 +260,8 @@ test.describe("mapml-viewer DOM API Tests", () => {
let reloadHidden = await page.$eval(".leaflet-top.leaflet-left > .mapml-reload-button", (div) => div.hidden);
let fullscreenHidden = await page.$eval(".leaflet-top.leaflet-left > .leaflet-control-fullscreen", (div) => div.hidden);
let layerControlHidden = await page.$eval(".leaflet-top.leaflet-right > .leaflet-control-layers", (div) => div.hidden);
let geolocation = await page.$eval(".leaflet-bottom.leaflet-right > .leaflet-control-locate", (div) => div.hidden);
expect(geolocation).toEqual(true);
expect(zoomHidden).toEqual(false);
expect(reloadHidden).toEqual(true);
expect(fullscreenHidden).toEqual(false);
Expand All @@ -264,6 +276,8 @@ test.describe("mapml-viewer DOM API Tests", () => {
reloadHidden = await page.$eval(".leaflet-top.leaflet-left > .mapml-reload-button", (div) => div.hidden);
fullscreenHidden = await page.$eval(".leaflet-top.leaflet-left > .leaflet-control-fullscreen", (div) => div.hidden);
layerControlHidden = await page.$eval(".leaflet-top.leaflet-right > .leaflet-control-layers", (div) => div.hidden);
geolocation = await page.$eval(".leaflet-bottom.leaflet-right > .leaflet-control-locate", (div) => div.hidden);
expect(geolocation).toEqual(true);
expect(zoomHidden).toEqual(true);
expect(reloadHidden).toEqual(true);
expect(fullscreenHidden).toEqual(false);
Expand All @@ -281,6 +295,8 @@ test.describe("mapml-viewer DOM API Tests", () => {
let reloadHidden = await page.$eval(".leaflet-top.leaflet-left > .mapml-reload-button", (div) => div.hidden);
let fullscreenHidden = await page.$eval(".leaflet-top.leaflet-left > .leaflet-control-fullscreen", (div) => div.hidden);
let layerControlHidden = await page.$eval(".leaflet-top.leaflet-right > .leaflet-control-layers", (div) => div.hidden);
let geolocation = await page.$eval(".leaflet-bottom.leaflet-right > .leaflet-control-locate", (div) => div.hidden);
expect(geolocation).toEqual(true);
expect(zoomHidden).toEqual(true);
expect(reloadHidden).toEqual(true);
expect(fullscreenHidden).toEqual(true);
Expand All @@ -295,12 +311,31 @@ test.describe("mapml-viewer DOM API Tests", () => {
reloadHidden = await page.$eval(".leaflet-top.leaflet-left > .mapml-reload-button", (div) => div.hidden);
fullscreenHidden = await page.$eval(".leaflet-top.leaflet-left > .leaflet-control-fullscreen", (div) => div.hidden);
layerControlHidden = await page.$eval(".leaflet-top.leaflet-right > .leaflet-control-layers", (div) => div.hidden);
geolocation = await page.$eval(".leaflet-bottom.leaflet-right > .leaflet-control-locate", (div) => div.hidden);
expect(geolocation).toEqual(true);
expect(zoomHidden).toEqual(true);
expect(reloadHidden).toEqual(true);
expect(fullscreenHidden).toEqual(false);
expect(layerControlHidden).toEqual(true);
});
test("controlslist geolocations test", async () => {
const viewerHandle = await page.evaluateHandle(() => document.querySelector('mapml-viewer'));
await page.evaluate( viewer => viewer.setAttribute("controlslist","geolocation"), viewerHandle);
let hascontrolslist = await page.evaluate( viewer => viewer.getAttribute("controlslist"), viewerHandle);
expect(hascontrolslist).toEqual('geolocation');

let geolocation = await page.$eval(".leaflet-bottom.leaflet-right > .leaflet-control-locate", (div) => div.hidden);
expect(geolocation).toEqual(false);
//remove geolocation
await page.evaluate( viewer => viewer.controlsList = "noreload", viewerHandle);
hascontrolslist = await page.evaluate( viewer => viewer.getAttribute("controlslist"), viewerHandle);
expect(hascontrolslist).toEqual('noreload');

let reloadHidden = await page.$eval(".leaflet-top.leaflet-left > .mapml-reload-button", (div) => div.hidden);
geolocation = await page.$eval(".leaflet-bottom.leaflet-right > .leaflet-control-locate", (div) => div.hidden);
expect(geolocation).toEqual(true);
expect(reloadHidden).toEqual(true);
});
test("controlslist removeAttribute", async () => {
const viewerHandle = await page.evaluateHandle(() => document.querySelector('mapml-viewer'));
// removeAttribute
Expand Down
Loading