Is there a method to rotate the squareGrid?
See original GitHub issueIs there a way to rotate the squareGrid
?
Here’s what i have right now.
What i want is for the grid to rotate to align with the angle of a polygon shape in google maps.
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 3,
maxZoom: 8,
minZoom: 2,
center: {
lat: 0,
lng: -180
},
streetViewControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var triangleCoords = [
{ lat: 25.774, lng: -80.19 },
{ lat: 18.466, lng: -66.118 },
{ lat: 32.321, lng: -64.757 },
{ lat: 25.774, lng: -80.19 }
];
// Construct the polygon.
var bermudaTriangle = new google.maps.Polygon({
paths: triangleCoords,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35
});
bermudaTriangle.setMap(map);
const polygonMap = bermudaTriangle.getMap();
const projection = polygonMap.getProjection();
google.maps.Polygon.prototype.my_getBounds=function(){
var bounds = new google.maps.LatLngBounds()
this.getPath().forEach(function(element,index){bounds.extend(element)})
return bounds
}
let coordinates = [];
// convert to bermudaTriangle path to geojson
for (let point of bermudaTriangle.getPath().getArray()) {
coordinates.push([point.lng(), point.lat()]);
}
const bounds = bermudaTriangle.my_getBounds();
const center = bounds.getCenter().toJSON();
const geojson = turf.polygon([coordinates]);
const pivot = [center.lng, center.lat];
const options = {pivot: pivot};
const rotatedPoly = turf.transformRotate(geojson, 0, options);
const bbox = turf.bbox(rotatedPoly);
const grid = turf.squareGrid(bbox, 50, {
units: "miles",
// mask: geojson
});
map.data.addGeoJson(grid);
Issue Analytics
- State:
- Created 4 years ago
- Comments:11
Top Results From Across the Web
How to rotate shapes on a grid - 3 different methods! - YouTube
In this lesson I explain how to rotate shapes on squared paper, either 90 degrees or 180 degrees. I demonstrate 3 different methods...
Read more >Rotating position in a square grid - Mathematics Stack Exchange
With this description, the problem turns out to be a purely geometrical one. You can rotate grids of arbitrary sizes (i.e. with arbitrary...
Read more >Rotation (article) | Transformations - Khan Academy
Rotating the correct way The correct way to rotate the square is to: Translate the coordinate system's origin (0, 0) to where you...
Read more >Inplace rotate square matrix by 90 degrees | Set 1
Given a square matrix, turn it by 90 degrees in an anti-clockwise ... Note: An approach that requires extra space is already discussed...
Read more >Rotating Regulars and Greedy Grids - Delta Thoughts
Anyways, this tilted square reveals an important property of grids: rotating a lattice point by 90° around another point gives you a new, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@chan-dev The grid is a just feature collection. Just iterate over the collection with, for example,
@turf/meta.featureEach
and apply@turf/transform-rotate
to each feature (i.e., cell).@chan-dev I don’t think there is really a more efficient way. I can only suggest a shorter/prettier, though not tested, version (no optimization, just a more compact form thanks to ES6 syntax):