Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
416 changes: 416 additions & 0 deletions README.md

Large diffs are not rendered by default.

2,749 changes: 1,523 additions & 1,226 deletions dist/StaticMap.common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/StaticMap.common.js.map

Large diffs are not rendered by default.

2,761 changes: 1,525 additions & 1,236 deletions dist/StaticMap.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/StaticMap.umd.js.map

Large diffs are not rendered by default.

427 changes: 425 additions & 2 deletions dist/StaticMap.umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/StaticMap.umd.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

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

190 changes: 190 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
<div>
<pre>{{url}}</pre>
</div>
<h1>Custom Styled Vue Static Map</h1>
<static-map :google-api-key="apiKey" alt="I am a custom alternative text"
title="I am a custom title" id="i-am-a-custom-stop-it"
:language="language" v-on:get-url="getStyledUrl" :paths="paths"
:format="format" :markers="markers" :zoom="zoom" :center="center"
:size="size" :type="type" :customStyle="customStyle"></static-map>
<div>
<pre>{{styledUrl}}</pre>
<small>Custom style <a href="https://snazzymaps.com/style/8097/wy" target="_blank"><strong>WY</strong> by <strong>StipeP</strong></a> at <a href="https://snazzymaps.com" target="_blank"><strong>Snazzy Maps</strong></a></small>
</div>
</div>
</template>

Expand All @@ -19,6 +29,10 @@ function getUrl(url) {
this.url = url;
}

function getStyledUrl(url) {
this.styledUrl = url;
}

export default {
data: () => {
const dataValues = {
Expand Down Expand Up @@ -68,7 +82,178 @@ export default {
size: [800, 400],
type: 'roadmap',
url: '',
styledUrl: '',
zoom: 13,
customStyle: [
{
featureType: 'all',
elementType: 'geometry.fill',
stylers: [
{
weight: '2.00',
},
],
},
{
featureType: 'all',
elementType: 'geometry.stroke',
stylers: [
{
color: '#9c9c9c',
},
],
},
{
featureType: 'all',
elementType: 'labels.text',
stylers: [
{
visibility: 'on',
},
],
},
{
featureType: 'landscape',
elementType: 'all',
stylers: [
{
color: '#f2f2f2',
},
],
},
{
featureType: 'landscape',
elementType: 'geometry.fill',
stylers: [
{
color: '#ffffff',
},
],
},
{
featureType: 'landscape.man_made',
elementType: 'geometry.fill',
stylers: [
{
color: '#ffffff',
},
],
},
{
featureType: 'poi',
elementType: 'all',
stylers: [
{
visibility: 'off',
},
],
},
{
featureType: 'road',
elementType: 'all',
stylers: [
{
saturation: -100,
},
{
lightness: 45,
},
],
},
{
featureType: 'road',
elementType: 'geometry.fill',
stylers: [
{
color: '#eeeeee',
},
],
},
{
featureType: 'road',
elementType: 'labels.text.fill',
stylers: [
{
color: '#7b7b7b',
},
],
},
{
featureType: 'road',
elementType: 'labels.text.stroke',
stylers: [
{
color: '#ffffff',
},
],
},
{
featureType: 'road.highway',
elementType: 'all',
stylers: [
{
visibility: 'simplified',
},
],
},
{
featureType: 'road.arterial',
elementType: 'labels.icon',
stylers: [
{
visibility: 'off',
},
],
},
{
featureType: 'transit',
elementType: 'all',
stylers: [
{
visibility: 'off',
},
],
},
{
featureType: 'water',
elementType: 'all',
stylers: [
{
color: '#46bcec',
},
{
visibility: 'on',
},
],
},
{
featureType: 'water',
elementType: 'geometry.fill',
stylers: [
{
color: '#c8d7d4',
},
],
},
{
featureType: 'water',
elementType: 'labels.text.fill',
stylers: [
{
color: '#070707',
},
],
},
{
featureType: 'water',
elementType: 'labels.text.stroke',
stylers: [
{
color: '#ffffff',
},
],
},
],
};
return dataValues;
},
Expand All @@ -78,6 +263,7 @@ export default {
},
methods: {
getUrl,
getStyledUrl,
},
};
</script>
Expand All @@ -95,4 +281,8 @@ export default {
pre {
white-space: pre-line;
}

a {
color: #369;
}
</style>
35 changes: 34 additions & 1 deletion src/components/static-map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function generateMapUrl() {
this.googleApiKey
}&scale=${this.scaleMap}&language=${this.language}${this.markersMap}${
this.pathsMap
}`;
}&${this.styleMap}`;
this.$emit('get-url', mapUrl);
return mapUrl;
}
Expand Down Expand Up @@ -96,6 +96,34 @@ function generateSizeMap() {
throw Error('Size must have 2 values: WIDTH AND HEIGHT');
}

function generateCustomStyles() {
const result = [];
if (this.customStyle) {
let custom = [];
try {
custom = JSON.parse(this.customStyle);
} catch (e) {
custom = this.customStyle;
}
custom.forEach(v => {
let style = '';
if (v.stylers) {
if (v.stylers.length > 0) {
style += `${(Object.prototype.hasOwnProperty.call(v, 'featureType') ? `feature:${v.featureType}` : 'feature:all')}|`;
style += `${(Object.prototype.hasOwnProperty.call(v, 'elementType') ? `element:${v.elementType}` : 'element:all')}|`;
v.stylers.forEach(val => {
const propertyname = Object.keys(val)[0];
const propertyval = val[propertyname].toString().replace('#', '0x');
style += `${propertyname}:${propertyval}|`;
});
}
}
result.push(`style=${encodeURIComponent(style)}`);
});
}
return result.join('&');
}

export default {
name: 'static-map',
computed: {
Expand All @@ -106,6 +134,7 @@ export default {
pathsMap: generatePaths,
scaleMap: generateScaleMap,
sizeMap: generateSizeMap,
styleMap: generateCustomStyles,
},
props: {
center: {
Expand Down Expand Up @@ -147,6 +176,10 @@ export default {
type: Array,
default: () => [500, 400],
},
customStyle: {
type: [String, Array],
default: null,
},
zoom: {
type: Number,
required: true,
Expand Down