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-overlay class="feature-popup"
:position="[0,0]">
<template slot-scope="popup">
<div class="card" style="background: #ececec; width: 50%">
<div class="card-body">
<h5 class="card-title">
<p class="card-header-title">
Feature ID qwewqeqwe-wqe-qwe-sa-fdsf-s -fd-sgf-sdg--gs-df-dsf-sd-fsd-f-sd-f-sd-f-sdf
</p>
</h5>
<div class="card-text">
<div class="content">
<p>
Overlay popup content for Feature with ID <strong>123 123 123 123-32 2 -3 -5-53-2 -32- -5- -we --d sf-d-sf- sd-f</strong>
</p>
<p>
Popup: wqeqwe qw eqwewqeq qwe...
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,
}
},
})