72295

Leaflet JS (react-leaflet) - Bounds Box Filled With Transparent Color

Question:

I'm working with react-leaflet package, however, if you can answer the question in plain leaflet that would be helpful as well.

I am successfully panning to the bounds of a polygon that I supply like so:

<Map center={position} zoom={13} bounds={this.state.bounds} className="campaignimagery-map"> <TileLayer url="http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" attribution="" />

However, I would like the entire polygon boundary box to be some transparent color so they can see exactly where the boundary box lies on the map. Is this possible?

Answer1:

<strong>Short answer</strong>

Use the bounds to draw a colored rectangle like this L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(map);. See related <a href="http://leafletjs.com/reference.html#rectangle" rel="nofollow">documentation</a> for more information.

<strong>Explanation</strong>

I don't think it's possible to color bounds as is, but you can use bounds for drawing a polygon. Then the polygon itself can be colored and managed as you wish.

Recommend

  • add image to rect polygon in leaflet
  • Getting Uncaught TypeError: Cannot read property 'length' of undefined on leafletjs
  • Tiles generated from mbutil does not render using leafletjs
  • Leaflet - create a marker with latLon + distance (meter) + angle (degree)
  • how to remove a div with same ids but display='block' and display='none' in JAVa
  • Yii2: Using Kartik Depdrop Widget?
  • getelement by class name for clicking
  • Main Thread Checker: UI API called on a background thread iOS 11 Xcode 9 GM Seed
  • Getting Latitude Longitude from GoogleMaps in TWebBrowser
  • Is looping through all style sheets and classes a good idea in JavaScript?
  • How to rotate the dial in a gauge chart? Using python plotly
  • Plotting densities in R
  • How Get arguments value using inline assembly in C without Glibc?
  • quiver not drawing arrows just lots of blue, matlab
  • Update Google Maps traffic layer without page reloading
  • How to make R's read_csv2() recognise the text characters properly
  • Implementation of State Monad
  • Blackberry - Custom EditField Cursor
  • Installing iPhone App to iPhone
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • Body moving without any force applied? (Box2d)
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • How to add a column to a Pandas dataframe made of arrays of the n-preceding values of another column
  • script to move all files from one location to another location
  • Circular dependency while pushing http interceptor
  • AngularJs get employee from factory
  • How to set the response of a form post action to a iframe source?
  • JTable with a ScrollPane misbehaving
  • Change div Background jquery
  • Android Google Maps API OnLocationChanged only called once
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • Running Map reduces the dimensions of the matrices
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Android Heatmap on canvas or ImageView
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal