Skip to content

Commit

Permalink
lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
eregnier committed Mar 24, 2019
1 parent 4340146 commit 282c7f9
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 84 deletions.
168 changes: 86 additions & 82 deletions gmap-custom-marker.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<template><div :style="{opacity: opacity}"><slot/></div></template>
<template>
<div :style="{opacity: opacity}">
<slot/>
</div>
</template>
<script>
import * as VueGoogleMaps from 'vue2-google-maps'
import * as VueGoogleMaps from "vue2-google-maps";
export default {
mixins: [VueGoogleMaps.MapElementMixin],
props: {
Expand Down Expand Up @@ -29,127 +33,127 @@ export default {
default: 50
}
},
data () {
data() {
return {
opacity: 0.01
}
};
},
watch: {
marker (val) {
this.$mapPromise.then(map => this.$overlay.setPosition())
},
marker(val) {
this.$mapPromise.then(map => this.$overlay.setPosition());
}
},
provide () {
const self = this
provide() {
const self = this;
this.$mapPromise.then(map => {
class Overlay extends google.maps.OverlayView {
constructor (map) {
super()
this.setMap(map)
this.draw = () => this.repaint()
this.setPosition = () => this.repaint()
constructor(map) {
super();
this.setMap(map);
this.draw = () => this.repaint();
this.setPosition = () => this.repaint();
}
repaint () {
const div = self.$el
const projection = this.getProjection()
repaint() {
const div = self.$el;
const projection = this.getProjection();
if (projection && div) {
const posPixel = projection.fromLatLngToDivPixel(self.position)
let x, y
const posPixel = projection.fromLatLngToDivPixel(self.position);
let x, y;
switch (self.alignment) {
case "top":
x = posPixel.x - (div.offsetWidth / 2)
y = posPixel.y - div.offsetHeight
break
x = posPixel.x - div.offsetWidth / 2;
y = posPixel.y - div.offsetHeight;
break;
case "bottom":
x = posPixel.x - (div.offsetWidth / 2)
y = posPixel.y
break
x = posPixel.x - div.offsetWidth / 2;
y = posPixel.y;
break;
case "left":
x = posPixel.x - div.offsetWidth
y = posPixel.y - (div.offsetHeight / 2)
break
x = posPixel.x - div.offsetWidth;
y = posPixel.y - div.offsetHeight / 2;
break;
case "right":
x = posPixel.x
y = posPixel.y - (div.offsetHeight / 2)
break
x = posPixel.x;
y = posPixel.y - div.offsetHeight / 2;
break;
case "center":
x = posPixel.x - (div.offsetWidth / 2)
y = posPixel.y - (div.offsetHeight / 2)
break
x = posPixel.x - div.offsetWidth / 2;
y = posPixel.y - div.offsetHeight / 2;
break;
case "topleft":
case "lefttop":
x = posPixel.x - div.offsetWidth
y = posPixel.y - div.offsetHeight
break
x = posPixel.x - div.offsetWidth;
y = posPixel.y - div.offsetHeight;
break;
case "topright":
case "righttop":
x = posPixel.x
y = posPixel.y - div.offsetHeight
break
x = posPixel.x;
y = posPixel.y - div.offsetHeight;
break;
case "bottomleft":
case "leftop":
x = posPixel.x - div.offsetWidth
y = posPixel.y
break
x = posPixel.x - div.offsetWidth;
y = posPixel.y;
break;
case "bottomright":
case "rightbottom":
x = posPixel.x
y = posPixel.y
break
x = posPixel.x;
y = posPixel.y;
break;
default:
throw new Error("Invalid alignment type of custom marker!")
break
}
div.style.left = (x + self.offsetX) + 'px'
div.style.top = (y + self.offsetY) + 'px'
throw new Error("Invalid alignment type of custom marker!");
break;
}
div.style.left = x + self.offsetX + "px";
div.style.top = y + self.offsetY + "px";
}
}
onAdd () {
const div = self.$el
const panes = this.getPanes()
div.style.position = 'absolute'
div.style.display = 'inline-block'
div.style.zIndex = self.zIndex
panes.overlayLayer.appendChild(div)
panes.overlayMouseTarget.appendChild(div)
onAdd() {
const div = self.$el;
const panes = this.getPanes();
div.style.position = "absolute";
div.style.display = "inline-block";
div.style.zIndex = self.zIndex;
panes.overlayLayer.appendChild(div);
panes.overlayMouseTarget.appendChild(div);
}
onRemove () {
self.$el.remove()
onRemove() {
self.$el.remove();
}
}
this.$overlay = new Overlay(map)
this.$overlay = new Overlay(map);
if (this.delayRepaint) {
setTimeout(() => {
this.$overlay.repaint()
this.opacity = 1
}, this.delayRepaint)
this.$overlay.repaint();
this.opacity = 1;
}, this.delayRepaint);
} else {
this.opacity = 1
this.opacity = 1;
}
})
});
},
computed: {
lat () {
return parseFloat(this.marker.lat || this.marker.latitude)
lat() {
return parseFloat(this.marker.lat || this.marker.latitude);
},
lng () {
return parseFloat(this.marker.lng || this.marker.longitude)
lng() {
return parseFloat(this.marker.lng || this.marker.longitude);
},
position () {
const self = this
position() {
const self = this;
return {
lat () {
return self.lat
lat() {
return self.lat;
},
lng () {
return self.lng
lng() {
return self.lng;
}
}
};
}
},
destroyed () {
this.$overlay.setMap(null)
this.$overlay = undefined
destroyed() {
this.$overlay.setMap(null);
this.$overlay = undefined;
}
}
};
</script>
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require('gmap-custom-marker.vue');
require('gmap-custom-marker.vue');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@
"vue": "^2.5.17",
"vue2-google-maps": "^0.10.2"
}
}
}

0 comments on commit 282c7f9

Please sign in to comment.