Skip to content

Instantly share code, notes, and snippets.

@bachhm-dev
Created April 16, 2020 10:29
Show Gist options
  • Save bachhm-dev/49be94e075402e43837d05889b4f5cac to your computer and use it in GitHub Desktop.
Save bachhm-dev/49be94e075402e43837d05889b4f5cac to your computer and use it in GitHub Desktop.
vue-openlayer
<template>
<div id="app">
<div id="map"></div>
</div>
</template>
<script>
/* eslint-disable */
// import openlayer css for style
import "ol/ol.css";
// This is library of openlayer for handle map
import Map from "ol/Map";
import View from "ol/View";
import { defaults as defaultControls, ScaleLine } from "ol/control";
import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer';
import {OSM, Vector as VectorSource} from 'ol/source';
export default {
async mounted() {
await this.initiateMap();
},
methods: {
initiateMap() {
// create vector layer
var source = new VectorSource();
var vector = new VectorLayer({
source: source
});
// create title layer
var raster = new TileLayer({
source: new OSM(),
});
// create map with 2 layer
var map = new Map({
controls: defaultControls().extend([
new ScaleLine({
units: "degrees",
}),
]),
target: "map",
layers: [raster, vector],
view: new View({
projection: "EPSG:4326",
center: [0, 0],
zoom: 2,
}),
});
},
},
};
</script>
<style>
#map {
position: absolute;
margin: 0;
padding: 0;
height: 500px;
width: 99%;
}
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
#nav {
padding: 30px;
}
#nav a {
font-weight: bold;
color: #2c3e50;
}
#nav a.router-link-exact-active {
color: #42b983;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment