Skip to content

Instantly share code, notes, and snippets.

@stefanocudini
Created November 30, 2012 11:33
Show Gist options
  • Select an option

  • Save stefanocudini/4175271 to your computer and use it in GitHub Desktop.

Select an option

Save stefanocudini/4175271 to your computer and use it in GitHub Desktop.
leaflet draw grid
drawGrid function() {
var xFact = 10,
yFact = 6;
var m = this.map,
bb = m.getBounds(),
xmin = m.latLngToLayerPoint( bb.getNorthWest() ).x,
ymin = m.latLngToLayerPoint( bb.getNorthWest() ).y,
xmax = m.latLngToLayerPoint( bb.getSouthEast() ).x,
ymax = m.latLngToLayerPoint( bb.getSouthEast() ).y,
//converte da coordinate a pixel
xinc = Math.round((xmax-xmin) / xFact),
yinc = Math.round((ymax-ymin) / yFact),
x,y, p1,p2, line;
this._grid.clearLayers();
for(x = xmin; x<= xmax; x+= xinc)
{
p1 = m.layerPointToLatLng( new L.Point(x, ymin) ),
p2 = m.layerPointToLatLng( new L.Point(x, ymax) ),
line = new L.Polyline([p1, p2], {color: "#6f6",color: 'green', weight:1 });
this._grid.addLayer(line);
}
for(y = ymin; y<= ymax; y+= yinc)
{
p1 = m.layerPointToLatLng( new L.Point(xmin, y) ),
p2 = m.layerPointToLatLng( new L.Point(xmax, y) ),
line = new L.Polyline([p1, p2], {color: "#6f6",color: 'green', weight:1 });
this._grid.addLayer(line);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment