Svg icon
by Vladimir Vershinin
HTML
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://unpkg.com/[email protected]/dist/ol.js"></script>
<script src="https://unpkg.com/[email protected]/lib/index.umd.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/lib/style.min.css">
<script src="https://rawgit.com/icebob/fakerator/master/dist/fakerator.js"></script>
<div id="app">
<div class="svgs">
<img id="skull" src="https://cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/svgs/fi-skull.svg">
</div>
<vl-map data-projection="EPSG:4326">
<vl-view :zoom.sync="zoom" :center.sync="center"></vl-view>
<vl-layer-tile>
<vl-source-osm></vl-source-osm>
</vl-layer-tile>
<vl-layer-vector ref="featuresLayer">
<vl-source-vector :features="features"></vl-source-vector>
<vl-style-func :factory="styleFuncFactory"></vl-style-func>
</vl-layer-vector>
</vl-map>
</div>
CSS
html, body, #app {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
JavaScript
Vue.use(VueLayers)
let fakerator = Fakerator()
// external loaded features
let features = [
{
"type": "Feature",
"id": 1,
"properties": {
"special": true,
},
"geometry": {
"type": "Point",
"coordinates": [
-30.761718749999996,
58.90464570302001
]
}
},
{
"type": "Feature",
"id": 2,
"properties": {
"special": true,
},
"geometry": {
"type": "Point",
"coordinates": [
36.73828124999999,
44.59046718130883
]
}
},
{
"type": "Feature",
"id": 3,
"properties": {
"special": false
},
"geometry": {
"type": "Point",
"coordinates": [
-23.37890625,
32.10118973232094
]
}
}
]
new Vue({
el: '#app',
methods: {
styleFuncFactory () {
console.log("create style func")
return feature => {
// apply color by some rule: here we use proprty from feature
let icon = new ol.style.Icon({
img: document.getElementById('skull'),
imgSize: [100, 100]
})
return [
new ol.style.Style({
image: icon,
})
]
}
},
},
data () {
return {
zoom: 3,
center: [-10, 35],
features: features,
}
},
})