Skip to content

Instantly share code, notes, and snippets.

View iamgeoknight's full-sized avatar

Spatial Dev Guru iamgeoknight

View GitHub Profile
/*
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.draw = new ol.interaction.Draw({
type: type,
/*
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
/*
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.draw = new ol.interaction.Draw({
type: type,
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsts/2.6.1/jsts.js"></script>
@iamgeoknight
iamgeoknight / polygon_split.js
Last active February 28, 2024 13:16
Split Polygon by Line
onGeomChange = (e) => {
/*
This function will dynamically split the polygon into two parts by a line and will follow geometry change event.
*/
//Create jsts parser to read openlayers geometry
let parser = new jsts.io.OL3Parser();
//Creating line geometry from draw intraction
let linestring = new ol.Feature({
let mergePolygon = (e) => {
/*
This function is applicable to merge only two polygons
This function will merge or perform union on two adjacent polygons. For the merge function to work, the polygons should atleast intersect each other.
*/
//Create jsts parser to read openlayers geometry
let parser = new jsts.io.OL3Parser();
//Parse Polygons geometry to jsts type
@iamgeoknight
iamgeoknight / feature_info_1.js
Last active September 10, 2021 16:06
Code for creating layer, Map and Popup
//Create a wms layer
let wmsLayer = new ol.layer.Tile({
source: new ol.source.TileWMS({
url: 'https://ahocevar.com/geoserver/wms',
params: {'LAYERS': 'ne:ne', 'TILED': true}
})
});
/*
Create and Render map on div with zoom and center
//Create map and vector layer
let map = new OLMap('map', 1, [-96.6345990807462, 32.81890764151014]).map;
//Feature Information on Map Click
map.on('singleclick', function (e) {
let url = wmsLayer.getSource().getFeatureInfoUrl(
e.coordinate,
map.getView().getResolution(),
@iamgeoknight
iamgeoknight / map_events.js
Created September 12, 2021 12:51
Creating a Map Click Event Listener
let map = new ol.Map({
target: map_div,
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
wmsLayer
],
view: new ol.View({
center: ol.proj.fromLonLat(center),
@iamgeoknight
iamgeoknight / geometry_Events.js
Last active September 12, 2021 13:23
Creating a Geometry Event Listener
let draw = new ol.interaction.Draw({
type: "LineString"
});
//Create interaction listener for draw
draw.on('drawstart', function (e) {
//Perform Task on when interaction starts
});
draw.on('drawend', function (e) {