Created
July 18, 2017 17:10
-
-
Save fernandoc1/b6d196e3e32975e29fae4dff60a73ac4 to your computer and use it in GitHub Desktop.
OpenLayers rotate polygon example
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> | |
<meta name="apple-mobile-web-app-capable" content="yes"> | |
<title>Geopointing</title> | |
<link rel="stylesheet" href="files/ol.css" type="text/css"> | |
<script src="files/ol4.js"></script> | |
<style type="text/css"> | |
body { margin:0; padding:0; } | |
#map { position:absolute; top:0; bottom:0; width:100%; } | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script> | |
var vectorSource = new ol.source.Vector({}); | |
var map = new ol.Map({ | |
layers: [ | |
new ol.layer.Tile({ | |
source: new ol.source.XYZ({ | |
url: 'http://localhost/map_cache.php?z={z}&x={x}&y={y}' | |
}) | |
}), | |
new ol.layer.Vector({ | |
source: vectorSource | |
}) | |
], | |
target: 'map', | |
view: new ol.View({ | |
center: [0, 0], | |
zoom: 2 | |
}) | |
}); | |
var marker = new ol.geom.Polygon([[ | |
ol.proj.transform([-16,-22], 'EPSG:4326', 'EPSG:3857'), | |
ol.proj.transform([-44,-55], 'EPSG:4326', 'EPSG:3857'), | |
ol.proj.transform([-88,75], 'EPSG:4326', 'EPSG:3857') | |
]]); | |
var featureMarker = new ol.Feature({ | |
name: 'Marker', | |
geometry: marker, | |
}); | |
vectorSource.addFeature(featureMarker); | |
marker.rotate(Math.PI / 2.0, ol.proj.transform([-16,-22], 'EPSG:4326', 'EPSG:3857')); | |
map.on('click', function(evt) | |
{ | |
var lonlat = ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326'); | |
console.log(lonlat); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment