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 all 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
15 changes: 12 additions & 3 deletions 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 All @@ -31,7 +31,8 @@ module.exports = function(grunt) {
'dist/layer.js': ['src/layer.js'],
'dist/leaflet.js': ['dist/leaflet-src.js',
'dist/proj4-src.js',
'dist/proj4leaflet.js']
'dist/proj4leaflet.js',
'dist/L.Control.Locate.js']
}
}
},
Expand Down Expand Up @@ -87,6 +88,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 Expand Up @@ -155,7 +164,7 @@ module.exports = function(grunt) {
},
clean: {
dist: ['dist'],
tidyup: ['dist/leaflet-src.js','dist/proj4-src.js','dist/proj4leaflet.js'],
tidyup: ['dist/leaflet-src.js','dist/proj4-src.js','dist/proj4leaflet.js','dist/L.Control.Locate.js'],
experiments: {
options: {force: true},
src: ['../experiments/dist']
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
44 changes: 43 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,9 @@ export class MapViewer extends HTMLElement {
totalSize += 49;
this._fullScreenControl = M.fullscreenButton().addTo(this._map);
}
if (!this._geolocationButton) {
this._geolocationButton = M.geolocationButton().addTo(this._map);
}
}

// Sets controls by hiding/unhiding them based on the map attribute
Expand All @@ -372,12 +375,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 +403,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 +439,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 +538,19 @@ 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, accuracy: e.accuracy}
}));
},this);
this._map.on('locationerror',
function (e) {
this.dispatchEvent(new CustomEvent('locationerror', {detail:
{error:e.message}
}));
},this);
this._map.on('load',
function () {
this.dispatchEvent(new CustomEvent('load', {detail: {target: this}}));
Expand Down Expand Up @@ -656,6 +682,22 @@ export class MapViewer extends HTMLElement {
}
});
}

locate(options) { //options: https://leafletjs.com/reference.html#locate-options
if (this._geolocationButton) {
this._geolocationButton.stop();
}
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
44 changes: 44 additions & 0 deletions src/mapml/control/GeolocationButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export var GeolocationButton = L.Control.extend({
options: {
position: 'bottomright'
},

onAdd: function (map) {
this.locateControl = L.control.locate({
showPopup: false,
strings: {
title: M.options.locale.btnLocTrackOff
},
position: this.options.position,
locateOptions: {
maxZoom: 16
}
}).addTo(map);

var container = this.locateControl._container;
var button = this.locateControl;
var observer = new MutationObserver(function(mutations) {
if (container.classList.contains('active') && container.classList.contains('following')) {
container.firstChild.title = M.options.locale.btnLocTrackOn;
button._marker.bindTooltip(M.options.locale.btnMyLocTrackOn,{permanent:true});
} else if (container.classList.contains('active')) {
container.firstChild.title = M.options.locale.btnLocTrackLastKnown;
button._marker.bindTooltip(M.options.locale.btnMyLastKnownLocTrackOn);
} else {
container.firstChild.title = M.options.locale.btnLocTrackOff;
}
});
var observerConfig = { attributes: true, attributeFilter: ['class'] };
observer.observe(container, observerConfig);

return container;
},

stop: function () {
return this.locateControl.stop();
}
});

export var geolocationButton = function (options) {
return new GeolocationButton(options);
};
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
5 changes: 5 additions & 0 deletions src/mapml/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export var Options = {
btnZoomOut: "Zoom out",
btnFullScreen: "View Fullscreen",
btnExitFullScreen: "Exit Fullscreen",
btnLocTrackOn: "Show my location - location tracking on",
btnMyLocTrackOn: "My current location, shown on map",
btnLocTrackOff: "Show my location - location tracking off",
btnLocTrackLastKnown: "Show my location - last known location shown",
btnMyLastKnownLocTrackOn: "My last known location, shown on map",
amZoom: "zoom level",
amColumn: "column",
amRow: "row",
Expand Down
44 changes: 43 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,9 @@ export class WebMap extends HTMLMapElement {
totalSize += 49;
this._fullScreenControl = M.fullscreenButton().addTo(this._map);
}
if (!this._geolocationButton) {
this._geolocationButton = M.geolocationButton().addTo(this._map);
}
}

// Sets controls by hiding/unhiding them based on the map attribute
Expand All @@ -415,12 +418,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 +446,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 +482,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 Expand Up @@ -568,6 +581,19 @@ export class WebMap extends HTMLMapElement {
{target: this}}));
}
});

this._map.on('locationfound',
function (e) {
this.dispatchEvent(new CustomEvent('maplocationfound', {detail:
{latlng: e.latlng, accuracy: e.accuracy}
}));
},this);
this._map.on('locationerror',
function (e) {
this.dispatchEvent(new CustomEvent('locationerror', {detail:
{error:e.message}
}));
},this);
this._map.on('load',
function () {
this.dispatchEvent(new CustomEvent('load', {detail: {target: this}}));
Expand Down Expand Up @@ -699,6 +725,22 @@ export class WebMap extends HTMLMapElement {
}
});
}

locate(options) { //options: https://leafletjs.com/reference.html#locate-options
if (this._geolocationButton) {
this._geolocationButton.stop();
}
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
Loading