ol-geom-polygon
ol-geom-polygon can be used inside a ol-feature to draw a single polygon on the map. The polygon may contain holes in it. A polygon is defined by exactly one LinearRing as its circumference, and any number of additional LinearRings representing holes that are cut out. Check the usage section for more info on this.
Demo
Setup
Plugin usage
This component is part of the Geometries
plugin. If not installed globally, you need to import and use
the plugin in your main.ts
or use the explicit component import (see section below).
Import and use the Geometries
plugin
import { createApp } from "vue";
import App from "./App.vue";
import {
Map,
Layers,
Sources,
Geometries,
} from "vue3-openlayers";
const app = createApp(App);
// ...
app.use(Geometries);
// ...
Explicit import
If you don't want to install a plugin, you can import the component explicitly. It's available as a child of the named export Geometries
.
NOTE
The following documentation refers to the plugin usage. Please make sure to adopt the component names, when you decided to use explicit component imports (e. g. <ol-map>
becomes <Map.OlMap>
etc.).
Usage
Plugin Usage | Explicit Import |
---|---|
<ol-geom-polygon> | <Geometries.OlGeomPolygon> |
<template>
<ol-map
:loadTilesWhileAnimating="true"
:loadTilesWhileInteracting="true"
style="height: 400px"
>
<ol-view
ref="view"
:center="center"
:zoom="zoom"
:projection="projection"
/>
<ol-tile-layer>
<ol-source-osm />
</ol-tile-layer>
<ol-vector-layer>
<ol-source-vector>
<ol-feature>
<ol-geom-polygon
:coordinates="[
[
[-98.844959, 19.691586],
[-98.842749, 19.69098],
[-98.84217, 19.693122],
[-98.844358, 19.693667],
[-98.844959, 19.691586],
],
[
[-98.84573034297229, 19.691206743587088],
[-98.84236332851385, 19.69026183008994],
[-98.84133866368556, 19.69351739026062],
[-98.8447693829186, 19.694312532467134],
[-98.84573034297229, 19.691206743587088],
],
]"
></ol-geom-polygon>
<ol-style>
<ol-style-stroke color="red" :width="2"></ol-style-stroke>
<ol-style-fill color="rgba(255,0,0,0.2)"></ol-style-fill>
</ol-style>
</ol-feature>
<ol-feature>
<ol-geom-polygon
:coordinates="[
[
[-98.848559, 19.680586],
[-98.845949, 19.68098],
[-98.846947, 19.68522],
[-98.848358, 19.685667],
[-98.846959, 19.683586],
],
]"
></ol-geom-polygon>
<ol-style>
<ol-style-fill color="red" />
</ol-style>
</ol-feature>
<ol-feature>
<ol-geom-polygon
:coordinates="[
[
[-98.858559, 19.680586],
[-98.855949, 19.68098],
[-98.85617, 19.68522],
[-98.858358, 19.685667],
[-98.856959, 19.683586],
],
]"
></ol-geom-polygon>
<ol-style>
<ol-style-fill :gradient="linearGradient" />
</ol-style>
</ol-feature>
<ol-feature>
<ol-geom-polygon
:coordinates="[
[
[-98.856559, 19.680586],
[-98.855949, 19.68098],
[-98.855917, 19.68522],
[-98.848558, 19.685667],
[-98.848959, 19.678586],
],
]"
></ol-geom-polygon>
<ol-style>
<ol-style-fill :gradient="radialGradient" />
</ol-style>
</ol-feature>
<ol-feature>
<ol-geom-polygon
:coordinates="[
[
[-98.8435, 19.680586],
[-98.838, 19.68098],
[-98.835, 19.68522],
[-98.843, 19.685667],
[-98.835, 19.683586],
],
]"
></ol-geom-polygon>
<ol-style>
<ol-style-fill :gradient="conicGradient" />
</ol-style>
</ol-feature>
</ol-source-vector>
</ol-vector-layer>
</ol-map>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import type {
LinearGradient,
RadialGradient,
ConicGradient,
} from "vue3-openlayers";
const center = ref([-98.8449, 19.6869]);
const projection = ref("EPSG:4326");
const zoom = ref(15);
const linearGradient: LinearGradient = {
type: "linear",
x0: 0,
y0: 0,
x1: 0,
y1: 256,
colorStops: [
[0.1, "red"], // Start color
[0.5, "yellow"], // Middle color
[1, "green"], // End color
],
};
const radialGradient: RadialGradient = {
type: "radial",
x0: 128,
y0: 128,
r0: 0,
x1: 128,
y1: 128,
r1: 128,
colorStops: [
[0, "blue"], // Center color
[0.5, "cyan"], // Middle color
[1, "white"], // Edge color
],
};
const conicGradient: ConicGradient = {
type: "conic",
x: 100,
y: 100,
startAngle: 100,
colorStops: [
[0, "red"],
[0.25, "orange"],
[0.5, "yellow"],
[0.75, "green"],
[1, "blue"],
],
};
</script>
Properties
coordinates
- Type:
number[][][]
A polygon with coordinates in the map's projection.