Skip to content

Commit c67a8ac

Browse files
committed
fix: renamed data-geolocation to geolocation
1 parent a51b42d commit c67a8ac

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

demo/fleet-tracking.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
<body>
3737
<div
38-
data-geolocation="true"
38+
geolocation="true"
3939
array="users"
4040
object="{{userId}}"
4141
key="currentLocation"

src/map.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@
66
// });
77

88
// loader.load().then(() => {
9-
9+
1010
// });
1111

1212

1313

14-
var CoCreateMap = function(object) {
15-
14+
var CoCreateMap = function (object) {
15+
1616
// variables
1717
// this.depth = 0;
1818

1919
// selectors
2020
this.mapDivSelector = ".google_map";
21-
21+
2222
// functions
2323
this.init(object);
2424

25-
this.requireLocationSelector = "data-geolocation";
25+
this.requireLocationSelector = "geolocation";
2626
};
2727

2828
/* global navigator, MutationObserver, google */
2929
CoCreateMap.prototype = {
30-
mapDivs:[],
31-
maps:[],
32-
services:[],
33-
markers:[], // MultiMarker & control
30+
mapDivs: [],
31+
maps: [],
32+
services: [],
33+
markers: [], // MultiMarker & control
3434
constructor: CoCreateMap,
35-
init: function(object){
35+
init: function (object) {
3636
let _this = this;
3737
this.__proto__.mapDivs = document.querySelectorAll(this.mapDivSelector);
3838
if (object !== undefined) {
@@ -42,12 +42,12 @@ CoCreateMap.prototype = {
4242
let curLocation = document.querySelector(`[${this.requireLocationSelector}]`);
4343
let isCurLocation = curLocation ? curLocation.getAttribute(this.requireLocationSelector) : false;
4444
if (navigator.geolocation && isCurLocation == "true") {
45-
let options = {timeout:5000};
45+
let options = { timeout: 5000 };
4646
navigator.geolocation.getCurrentPosition(this.showLocation, this.errHandler, options);
4747
}
48-
else this.errHandler({code:1});
48+
else this.errHandler({ code: 1 });
4949
}
50-
50+
5151
let observer = new MutationObserver(
5252
function (mutationList, observer) {
5353
mutationList.forEach(mutation => {
@@ -69,15 +69,15 @@ CoCreateMap.prototype = {
6969
}
7070
}
7171
},
72-
showLocation: function(position) {
72+
showLocation: function (position) {
7373
let latitude = position.coords.latitude;
7474
let longitude = position.coords.longitude;
7575
for (let map of this.mapDivs) {
7676
let mapInfo = new MapInfo(map.dataset.map_id, longitude, latitude);
7777
this.renderMap(mapInfo);
7878
}
7979
},
80-
errHandler: function(err) {
80+
errHandler: function (err) {
8181
if (err.code == 1)
8282
for (let map of this.mapDivs) {
8383
let mapInfo = new MapInfo(map.dataset.map_id);
@@ -86,14 +86,14 @@ CoCreateMap.prototype = {
8686
else if (err.code == 2)
8787
alert("Error: Position is unavailable!");
8888
},
89-
renderMap: function(mapInfo, markerInfo) {
89+
renderMap: function (mapInfo, markerInfo) {
9090
let latitude = parseFloat(mapInfo.lat);
9191
let longitude = parseFloat(mapInfo.lng);
9292
let zoom = mapInfo.zoom;
9393
let map_id = mapInfo.map_id;
9494
let map_center = new google.maps.LatLng(latitude, longitude);
9595
this.__proto__.maps[map_id] = new google.maps.Map(
96-
document.querySelector(`.google_map[data-map_id='${map_id}']`), {center: map_center, zoom: zoom});
96+
document.querySelector(`.google_map[data-map_id='${map_id}']`), { center: map_center, zoom: zoom });
9797
// console.log(this.__proto__.maps[map_id].__proto__.getBounds());
9898
this.__proto__.maps[map_id].__proto__.bounds_changed = () => {
9999
console.log([this.maps[map_id].getCenter().lng(), this.maps[map_id].getCenter().lat()]);
@@ -106,7 +106,7 @@ CoCreateMap.prototype = {
106106
// this.setMarker(map_id, {draggable: true, position: {lat:latitude, lng:longitude}});
107107
}
108108
else {
109-
if (markerInfo.option.position == undefined) markerInfo.option.position = {lat:latitude, lng:longitude};
109+
if (markerInfo.option.position == undefined) markerInfo.option.position = { lat: latitude, lng: longitude };
110110
this.setMarker(map_id, markerInfo.option, markerInfo.marker_id);
111111
}
112112
},
@@ -116,7 +116,7 @@ CoCreateMap.prototype = {
116116
* @param marker_id : marker_id : not exist - add, exist - update & delete
117117
* @return marker_id : success - marker_id, failure - -1;
118118
*/
119-
setMarker: function(map_id, option, marker_id) {
119+
setMarker: function (map_id, option, marker_id) {
120120
option.map = this.maps[map_id];
121121
if (option.position !== undefined) { // add & update
122122
if (marker_id === undefined) { // add
@@ -151,7 +151,7 @@ CoCreateMap.prototype = {
151151
* @param parentInfo : parent selector of input
152152
* @return object from attributes
153153
*/
154-
attToObj: function(attributeName, addInfo = "", parentInfo = "") {
154+
attToObj: function (attributeName, addInfo = "", parentInfo = "") {
155155
let inputs = document.querySelectorAll(`${parentInfo} input[data-${attributeName}]${addInfo}, ${parentInfo} input[name]${addInfo}, ${parentInfo} textarea[data-${attributeName}]${addInfo}, ${parentInfo} textarea[name]${addInfo}`);
156156
let result = {};
157157
for (let input of inputs) {
@@ -183,7 +183,7 @@ CoCreateMap.prototype = {
183183
* @param addInfo : additional selector of input
184184
* @param parentInfo : parent selector of input
185185
*/
186-
objToAtt: function(object, attributeName, addInfo = "", parentInfo = "") {
186+
objToAtt: function (object, attributeName, addInfo = "", parentInfo = "") {
187187
let inputs = document.querySelectorAll(`${parentInfo} input[data-${attributeName}]${addInfo}, ${parentInfo} input[name]${addInfo}, ${parentInfo} textarea[data-${attributeName}]${addInfo}, ${parentInfo} textarea[name]${addInfo}`);
188188
for (let input of inputs) {
189189
let key;
@@ -208,7 +208,7 @@ function MapInfo(map_id, lng, lat, zoom) {
208208

209209
MapInfo.prototype = {
210210
constructor: MapInfo,
211-
init: function(map_id = 0, lng = -74.0060, lat = 40.7128, zoom = 15) {
211+
init: function (map_id = 0, lng = -74.0060, lat = 40.7128, zoom = 15) {
212212
this.lat = parseFloat(lat);
213213
this.lng = parseFloat(lng);
214214
this.zoom = parseInt(zoom, 10);
@@ -222,8 +222,8 @@ function stripHtml(html) {
222222
return tmp.textContent || tmp.innerText || "";
223223
}
224224

225-
function onlyUnique(value, index, self) {
225+
function onlyUnique(value, index, self) {
226226
return self.indexOf(value) === index;
227227
}
228228

229-
export {CoCreateMap, onlyUnique, stripHtml};
229+
export { CoCreateMap, onlyUnique, stripHtml };

0 commit comments

Comments
 (0)