Skip to content

Commit 65c8ac2

Browse files
author
Lionel Bijaoui
committed
enhancement: staticMap updated with more options for more flexibility. Test updated to reflect changes.
1 parent 67ed6f3 commit 65c8ac2

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

src/fields/fieldStaticMap.vue

+26-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,36 @@
44

55
<script>
66
import abstractField from "./abstractField";
7+
import { defaults } from "lodash";
78
89
export default {
910
mixins: [ abstractField ],
1011
1112
computed: {
1213
mapLink() {
13-
if (this.value && this.value.lat && this.value.lng)
14-
return `http://maps.googleapis.com/maps/api/staticmap?center=${this.value.lat},${this.value.lng}&zoom=8&scale=false&size=800x300&maptype=roadmap&format=png&visual_refresh=true&markers=size:mid%7Ccolor:0xff0000`;
14+
if (this.value) {
15+
let lat, lng;
16+
let options = defaults(this.schema.staticMapOptions || {}, {
17+
lat: "lat",
18+
lng: "lng",
19+
zoom: 8,
20+
sizeX:640,
21+
sizeY:640,
22+
});
23+
24+
lat = this.value[options.lat];
25+
lng = this.value[options.lng];
26+
27+
let url = `http://maps.googleapis.com/maps/api/staticmap?center=${lat},${lng}&zoom=${options.zoom}&size=${options.sizeX}x${options.sizeY}`;
28+
29+
let props = ["scale", "format", "maptype", "language", "region", "markers", "path", "visible", "style", "key", "signature"];
30+
for (let prop of props) {
31+
if (typeof options[prop] !== "undefined") {
32+
url += `&${prop}=${options[prop]}`;
33+
}
34+
}
35+
if (lat && lng){ return url; }
36+
}
1537
}
1638
}
1739
};
@@ -24,3 +46,5 @@
2446
max-width: 100%;
2547
}
2648
</style>
49+
50+

test/unit/specs/fields/fieldStaticMap.spec.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,24 @@ describe("fieldStaticMap.vue", function() {
1919
let schema = {
2020
type: "staticMap",
2121
label: "Geo",
22-
model: "geo"
22+
model: "geo",
23+
staticMapOptions: {
24+
lat: "latitude",
25+
lng: "longitude",
26+
zoom: 6,
27+
sizeX:640,
28+
sizeY:640,
29+
scale: 1,
30+
format:"png",
31+
maptype:"satellite",
32+
language:"FR-fr",
33+
markers:"size:mid%7Ccolor:0xff0000",
34+
}
2335
};
2436
let model = {
2537
geo: {
26-
lat: 13.4567,
27-
lng: 20.3321
38+
latitude: 13.4567,
39+
longitude: 20.3321
2840
}
2941
};
3042
let input;
@@ -39,7 +51,7 @@ describe("fieldStaticMap.vue", function() {
3951
expect(field.$el).to.be.exist;
4052

4153
expect(input).to.be.defined;
42-
expect(input.src).to.be.equal("http://maps.googleapis.com/maps/api/staticmap?center=13.4567,20.3321&zoom=8&scale=false&size=800x300&maptype=roadmap&format=png&visual_refresh=true&markers=size:mid%7Ccolor:0xff0000");
54+
expect(input.src).to.be.equal("http://maps.googleapis.com/maps/api/staticmap?center=13.4567,20.3321&zoom=6&size=640x640&scale=1&format=png&maptype=satellite&language=FR-fr&markers=size:mid%7Ccolor:0xff0000");
4355
});
4456

4557
});

0 commit comments

Comments
 (0)