code Snippetlanguage CDNpackage_2 NPM
content_copy Copyopen_in_new Open
var fenceCoords = [[ 13.38 , 52.53 ], [ 13.43 , 52.53 ], [ 13.43 , 52.51 ], [ 13.38 , 52.51 ], [ 13.38 , 52.53 ]];
var fenceFeature = new ol. Feature ({
geometry: new ol.geom. Polygon ([fenceCoords. map ( function ( c ) { return ol.proj. fromLonLat (c); })])
});
var vectorLayer = new ol.layer. Vector ({
source: new ol.source. Vector ({ features: [fenceFeature] }),
style: new ol.style. Style ({
stroke: new ol.style. Stroke ({ color: '#e63946' , width: 2 }),
fill: new ol.style. Fill ({ color: 'rgba(230,57,70,0.15)' })
})
});
var map = new ol. Map ({
target: 'map' ,
layers: [
new ol.layer. Tile ({ source: new ol.source. XYZ ({ url: 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY' , attributions: '© <a href="https://www.maptiler.com/copyright/">MapTiler</a>' }) }),
vectorLayer
],
view: new ol. View ({ center: ol.proj. fromLonLat ([ 13.405 , 52.52 ]), zoom: 13 })
});
map. on ( 'click' , function ( evt ) {
var inside = fenceFeature. getGeometry (). intersectsCoordinate (evt.coordinate);
var info = document. getElementById ( 'info' );
info.textContent = inside ? 'Inside zone' : 'Outside zone' ;
info.style.color = inside ? '#4CAF50' : '#e63946' ;
}); content_copy Copyopen_in_new Open
<! DOCTYPE html >
< html >
< head >
< meta charset = "utf-8" />
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" />
< link rel = "stylesheet" href = "https://unpkg.com/ol@10.10.0/ol.css" />
< script src = "https://unpkg.com/ol@10.10.0/dist/ol.js" ></ script >
< style >
body { margin : 0 ; padding : 0 ; }
#map { width : 100 % ; height : 100 vh ; }
</ style >
</ head >
< body >
< div id = "map" ></ div >
< div id = "info" style = "position:absolute;top:10px;right:10px;background:#141414;color:#e0e0e0;padding:8px 16px;border:2px solid #2a2a2a;font-family:monospace;z-index:10;" >Click the map</ div >
< script >
var fenceCoords = [[ 13.38 , 52.53 ], [ 13.43 , 52.53 ], [ 13.43 , 52.51 ], [ 13.38 , 52.51 ], [ 13.38 , 52.53 ]];
var fenceFeature = new ol. Feature ({
geometry: new ol.geom. Polygon ([fenceCoords. map ( function ( c ) { return ol.proj. fromLonLat (c); })])
});
var vectorLayer = new ol.layer. Vector ({
source: new ol.source. Vector ({ features: [fenceFeature] }),
style: new ol.style. Style ({
stroke: new ol.style. Stroke ({ color: '#e63946' , width: 2 }),
fill: new ol.style. Fill ({ color: 'rgba(230,57,70,0.15)' })
})
});
var map = new ol. Map ({
target: 'map' ,
layers: [
new ol.layer. Tile ({ source: new ol.source. XYZ ({ url: 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY' , attributions: '© <a href="https://www.maptiler.com/copyright/">MapTiler</a>' }) }),
vectorLayer
],
view: new ol. View ({ center: ol.proj. fromLonLat ([ 13.405 , 52.52 ]), zoom: 13 })
});
map. on ( 'click' , function ( evt ) {
var inside = fenceFeature. getGeometry (). intersectsCoordinate (evt.coordinate);
var info = document. getElementById ( 'info' );
info.textContent = inside ? 'Inside zone' : 'Outside zone' ;
info.style.color = inside ? '#4CAF50' : '#e63946' ;
});
</ script >
</ body >
</ html > content_copy Copyopen_in_new Open
import Map from 'ol/Map' ;
import View from 'ol/View' ;
import TileLayer from 'ol/layer/Tile' ;
import { fromLonLat } from 'ol/proj' ;
import 'ol/ol.css' ;
var fenceCoords = [[ 13.38 , 52.53 ], [ 13.43 , 52.53 ], [ 13.43 , 52.51 ], [ 13.38 , 52.51 ], [ 13.38 , 52.53 ]];
var fenceFeature = new ol. Feature ({
geometry: new ol.geom. Polygon ([fenceCoords. map ( function ( c ) { return ol.proj. fromLonLat (c); })])
});
var vectorLayer = new ol.layer. Vector ({
source: new ol.source. Vector ({ features: [fenceFeature] }),
style: new ol.style. Style ({
stroke: new ol.style. Stroke ({ color: '#e63946' , width: 2 }),
fill: new ol.style. Fill ({ color: 'rgba(230,57,70,0.15)' })
})
});
var map = new ol. Map ({
target: 'map' ,
layers: [
new ol.layer. Tile ({ source: new ol.source. XYZ ({ url: 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY' , attributions: '© <a href="https://www.maptiler.com/copyright/">MapTiler</a>' }) }),
vectorLayer
],
view: new ol. View ({ center: ol.proj. fromLonLat ([ 13.405 , 52.52 ]), zoom: 13 })
});
map. on ( 'click' , function ( evt ) {
var inside = fenceFeature. getGeometry (). intersectsCoordinate (evt.coordinate);
var info = document. getElementById ( 'info' );
info.textContent = inside ? 'Inside zone' : 'Outside zone' ;
info.style.color = inside ? '#4CAF50' : '#e63946' ;
});
var fenceCoords = [[13.38, 52.53], [13.43, 52.53], [13.43, 52.51], [13.38, 52.51], [13.38, 52.53]];
var fenceFeature = new ol.Feature({
geometry: new ol.geom.Polygon([fenceCoords.map(function(c) { return ol.proj.fromLonLat(c); })])
});
var vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector({ features: [fenceFeature] }),
style: new ol.style.Style({
stroke: new ol.style.Stroke({ color: '#e63946', width: 2 }),
fill: new ol.style.Fill({ color: 'rgba(230,57,70,0.15)' })
})
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({ source: new ol.source.XYZ({ url: 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY', attributions: '© <a href="https://www.maptiler.com/copyright/">MapTiler</a>' }) }),
vectorLayer
],
view: new ol.View({ center: ol.proj.fromLonLat([13.405, 52.52]), zoom: 13 })
});
map.on('click', function(evt) {
var inside = fenceFeature.getGeometry().intersectsCoordinate(evt.coordinate);
var info = document.getElementById('info');
info.textContent = inside ? 'Inside zone' : 'Outside zone';
info.style.color = inside ? '#4CAF50' : '#e63946';
}); <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/ol@10.10.0/ol.css" />
<script src="https://unpkg.com/ol@10.10.0/dist/ol.js"></script>
<style>
body { margin: 0; padding: 0; }
#map { width: 100%; height: 100vh; }
</style>
</head>
<body>
<div id="map"></div>
<div id="info" style="position:absolute;top:10px;right:10px;background:#141414;color:#e0e0e0;padding:8px 16px;border:2px solid #2a2a2a;font-family:monospace;z-index:10;">Click the map</div>
<script>
var fenceCoords = [[13.38, 52.53], [13.43, 52.53], [13.43, 52.51], [13.38, 52.51], [13.38, 52.53]];
var fenceFeature = new ol.Feature({
geometry: new ol.geom.Polygon([fenceCoords.map(function(c) { return ol.proj.fromLonLat(c); })])
});
var vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector({ features: [fenceFeature] }),
style: new ol.style.Style({
stroke: new ol.style.Stroke({ color: '#e63946', width: 2 }),
fill: new ol.style.Fill({ color: 'rgba(230,57,70,0.15)' })
})
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({ source: new ol.source.XYZ({ url: 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY', attributions: '© <a href="https://www.maptiler.com/copyright/">MapTiler</a>' }) }),
vectorLayer
],
view: new ol.View({ center: ol.proj.fromLonLat([13.405, 52.52]), zoom: 13 })
});
map.on('click', function(evt) {
var inside = fenceFeature.getGeometry().intersectsCoordinate(evt.coordinate);
var info = document.getElementById('info');
info.textContent = inside ? 'Inside zone' : 'Outside zone';
info.style.color = inside ? '#4CAF50' : '#e63946';
});
</script>
</body>
</html> import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import { fromLonLat } from 'ol/proj';
import 'ol/ol.css';
var fenceCoords = [[13.38, 52.53], [13.43, 52.53], [13.43, 52.51], [13.38, 52.51], [13.38, 52.53]];
var fenceFeature = new ol.Feature({
geometry: new ol.geom.Polygon([fenceCoords.map(function(c) { return ol.proj.fromLonLat(c); })])
});
var vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector({ features: [fenceFeature] }),
style: new ol.style.Style({
stroke: new ol.style.Stroke({ color: '#e63946', width: 2 }),
fill: new ol.style.Fill({ color: 'rgba(230,57,70,0.15)' })
})
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({ source: new ol.source.XYZ({ url: 'https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY', attributions: '© <a href="https://www.maptiler.com/copyright/">MapTiler</a>' }) }),
vectorLayer
],
view: new ol.View({ center: ol.proj.fromLonLat([13.405, 52.52]), zoom: 13 })
});
map.on('click', function(evt) {
var inside = fenceFeature.getGeometry().intersectsCoordinate(evt.coordinate);
var info = document.getElementById('info');
info.textContent = inside ? 'Inside zone' : 'Outside zone';
info.style.color = inside ? '#4CAF50' : '#e63946';
});