vue-map-component
This component is in working progress!
When final version will be released, the version number will be set to 1.0.0
Install
NPM
Install the package:
npm install @profesia/vue-map-component --save-dev
Then import it in your project
import Vue from 'vue'
import Vuex from 'vuex';
import store from './store';
import mapComponent from '@profesia/vue-map-component'
Vue.use(Vuex);
new Vue({
el: '#app',
store,
components: {
mapComponent,
},
});
example of empty store
import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex)
export default new Vuex.Store({})
Browser global
You can't just include the script, because the script needs VUEX, so you have to add it in your scripts and run NPM build (or webpack, gulp, ...).
Usage
Simply use it like so:
<map-component name="myMap" country="slovakia" :regions="slovakRegions" :showAllPins="true" :showOffersCount="true"></map-component>
Options
name
Mandatory. Name will be used to create namespace for each map component.
country
Mandatory. Name of the country.
regions
Optional. An object for storage the info about regions. Object keys can be these:
offersCount
- for display the number of offers in each region
pin
- for custom html for region pins
link
- for redirect page on another page after click on the region
computed: {
slovakRegions() {
return {
'ba': {
'offersCount': 5,
'link': 'https://www.example.com'
},
'za': {
'offersCount': 2,
},
'ke': {
'offersCount': 0,
}
}
},
}
showCountryBorder
Optional. A boolean parameter. If true
, the path around country will be shown.
Defaults to false
.
showPin
Optional. A boolean parameter. If true
, the empty pins will be positioned in to the map.
If one from other parameters (showAllPins
, showRegionName
, showOffersCount
, showRegionNameWithOffersCount
) will be set to true
, showPin
will be set to true
automatically.
Defaults to false
.
showAllPins
Optional. A boolean parameter. If true
, the map will show pin on each region. If false
, only the regions with offers will show the pin (you have to set object regions
with key offersCount
).
Defaults to false
.
showRegionName
Optional. A boolean parameter. If true
, the map will show region shortcut in the pin, for example BA
, KE
, ...
Defaults to false
.
showOffersCount
Optional. A boolean parameter. If true
, the map will show offers count in the pin for each region, (you have to set object regions
with key offersCount
).
Defaults to false
.
showRegionNameWithOffersCount
Optional. A boolean parameter. If true
, the map will show offers count in the pin for each region on small devices, on desktop the map will show the region shortcut and the offers count will show on region mouse hover (you have to set object regions
with key offersCount
).
Defaults to false
.
customClass
Optional. String parameter, you can add some custom class.
Settings - VUEX store mutations
Select option
There is possibility to set (select) region.
You need to commit a mutation with name based on your name
.
Structure of mutation name is vueMap + your name +/setActiveRegion
, so if name
is Example
, you have to call mutation with name vueMapExample/setActiveRegion
.
store.commit('vueMapExample/setActiveRegion', ['ba', 'ke']);
Listening for selected regions
You need to listen for state with name based on your nme
: vueMap + your name +/activeRegion
.
store.state.vueMapExample.activeRegion
Structure
Once the select has been rendered, it'll create the following structure:
HTML
Single map
<div class="vue-map-component vue-map-show-all-pins">
<div class="vue-map-container">
<svg viewBox="0 0 209 100" xmlns="http://www.w3.org/2000/svg">
<g>
<a href="" class=""><path class="vue-map-region vue-map-region-ba" d="..."></path></a>
<a href="" class=""><path class="vue-map-region vue-map-region-tt" d="..."></path></a>
<a href="" class=""><path class="vue-map-region vue-map-region-nr" d="..."></path></a>
<a href="" class=""><path class="vue-map-region vue-map-region-tn" d="..."></path></a>
<a href="" class=""><path class="vue-map-region vue-map-region-bb" d="..."></path></a>
<a href="" class=""><path class="vue-map-region vue-map-region-ke" d="..."></path></a>
<a href="" class=""><path class="vue-map-region vue-map-region-po" d="..."></path></a>
<a href="" class=""><path class="vue-map-region vue-map-region-za" d="..."></path></a>
</g>
</svg>
<a href="" class="vue-map-pin vue-map-pin-ba"></a>
<a href="" class="vue-map-pin vue-map-pin-tt"></a>
<a href="" class="vue-map-pin vue-map-pin-nr"></a>
<a href="" class="vue-map-pin vue-map-pin-tn"></a>
<a href="" class="vue-map-pin vue-map-pin-bb"></a>
<a href="" class="vue-map-pin vue-map-pin-za"></a>
<a href="" class="vue-map-pin vue-map-pin-po"></a>
<a href="" class="vue-map-pin vue-map-pin-ke"></a>
</div>
</div>
CSS
All CSS is based upon this structure.
.vue-map-component {
...
}
.vue-map-component g {
...
}
.vue-map-pin {
...
}
FAQ
- How can I provide feedback? - Send an email to vrtich@profesia.sk; any feedback is appreciated.
Release History
- 0.2.8 Add country border
- 0.2.6 Remove unnecessary async call
- 0.2.5 Fix BUG with undefined regions offer counts
- 0.2.4 Fix BUG with undefined regions when they were not necessary
- 0.2.3 Rename data to data-map
- 0.2.2 Add data region-id to pin
- 0.2.1 Add data offers-count to pin
- 0.2.0 Add new class
vue-map-active-region
when some region is active - 0.1.2 Change babel preset to
env
- 0.1.1 Remove SPAN tags from SVG
- 0.1.0 Replace A tags with SPAN tags
- 0.0.8 Fix styles
- 0.0.7 Create mixin Less file
- 0.0.6 Fix styles path
- 0.0.5 Edit styles, separate styles for Slovakia Map Component
- 0.0.4 svg map with bigger coordinates
- 0.0.3 Fix warning - Props with type Object/Array must use a factory function to return the default value
- 0.0.2 Edit README
- 0.0.1 Initial release