Last active
September 10, 2021 16:06
-
-
Save iamgeoknight/a011535dbed4ccaab1ea593727cc7fe5 to your computer and use it in GitHub Desktop.
Code for creating layer, Map and Popup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 | |
*/ | |
class OLMap { | |
//Constructor accepts html div id, zoom level and center coordinaes | |
constructor(map_div, zoom, center) { | |
this.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), | |
zoom: zoom | |
}) | |
}); | |
} | |
} | |
/* | |
Create overlay | |
*/ | |
class Overlay { | |
//Contrctor accepts map object, overlay html element, overlay offset, overlay positioning and overlay class | |
constructor(map, element = document.getElementById("popup"), offset = [0, 0], positioning = 'bottom-center', className = 'ol-tooltip-measure ol-tooltip .ol-tooltip-static') { | |
this.map = map; | |
this.overlay = new ol.Overlay({ | |
element: element, | |
offset: offset, | |
positioning: positioning, | |
className: className | |
}); | |
this.overlay.setPosition([0,0]); | |
this.overlay.element.style.display = 'block'; | |
this.map.addOverlay(this.overlay); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment