Skip to content

Instantly share code, notes, and snippets.

@iamgeoknight
Last active January 9, 2022 05:37
Show Gist options
  • Select an option

  • Save iamgeoknight/71ec974c69ed58d11550b917ed87bf25 to your computer and use it in GitHub Desktop.

Select an option

Save iamgeoknight/71ec974c69ed58d11550b917ed87bf25 to your computer and use it in GitHub Desktop.
Static Style
*
Create Vector Layer
*/
class VectorLayer{
//Constructor accepts title of vector layer and map object
constructor(title, map) {
this.layer = new ol.layer.Vector({
title: title,
source: new ol.source.Vector({
projection:map.getView().projection
}),
style: new ol.style.Style({
// Line and Polygon Style
stroke: new ol.style.Stroke({
color: '#0e97fa',
width: 4
}),
fill: new ol.style.Fill({
color: 'rgba(0, 153, 255, 0.2)'
}),
// Point Style
image: new ol.style.Circle({
radius: 10,
fill: new ol.style.Fill({
color: [0, 153, 255, 1],
}),
stroke: new ol.style.Stroke({
color: [255, 255, 255, 1],
width: 5
}),
})
})
});
}
}
/*
Create a Draw interaction for LineString and Polygon
*/
class Draw {
//Constructor accepts geometry type, map object and vector layer
constructor(type, map, vector_layer) {
this.map = map;
this.vector_layer = vector_layer;
this.features = [];
//Draw feature
this.draw = new ol.interaction.Draw({
type: type,
stopClick: true,
source: vector_layer.getSource()
});
this.map.addInteraction(this.draw);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment