IITC-CE / ingress-intel-total-conversion

intel.ingress.com total conversion user script with some new features. Should allow easier extension of the intel map.
https://iitc.app
ISC License
284 stars 110 forks source link

[New Feature] Display actual area (proxy for MU) for polygons. #246

Closed Athanasius closed 5 years ago

Athanasius commented 5 years ago

This will probably be best implemented as a direct part of DrawTools.

When trying to judge the exact portals to use for pre-planned fields it would be good to know the area covered by a given Polygon (easier to implement than "click on map, check for any triangle there made by DrawTools lines..."). Perhaps a popup/hover when editing a Polygon?

Keep in mind that for larger polygons proper "on the surface of a sphere" calculations will be necessary, and it's easiest to just do this anyway given it would be working off of Lat/Long co-ordinates of the corners.

If I find time I'll investigate and may provide a PR.

johnd0e commented 5 years ago

May be better in layer-count?

Athanasius commented 5 years ago

Layer Count operates only on existing fields, not DrawTools polygons, doesn't it ?

I'll investigate the best mechanism. I'm specifically thinking of this sequence:

  1. Draw the largest field
  2. See area count
  3. Adjust one portal to another candidate
  4. See new area count and compare mentally.

Rather than the total area by all draw polygons (which also might not take fly links into account).

So, in theory, this just means hooking into when a polygon has just been completed, or an edit on it finished, to display the area. I may well look at how Layer Count does its display for inspiration, although plugin-order can sometimes mean that displays in an inconvenient location (I'll see about opening another Issue about that).

I'll work towards this for now, just to see how well it works, then could consider applying the same code to Layer Count as well, but remember that Layer Count is on existing fields, not on DrawTools polygons.

johnd0e commented 5 years ago

Layer Count operates only on existing fields, not DrawTools polygons, doesn't it ?

Drawn polygons too.

but remember that Layer Count is on existing fields, not on DrawTools polygons.

You better try

Athanasius commented 5 years ago

It would help if Layer Count was actually working (Firefox and Linux), which prevented me making sure. I'll go file an issue with the error.

johnd0e commented 5 years ago

@Athanasius Make sure with test build

Athanasius commented 5 years ago

With Layer Count working on the latest test build I can see that it does indeed also work on Polygons, so adding area count to that output would certainly be doable and useful to some.

But the extra clicks of drawing, using layer count, edit polygon, use layer count again just seems awkward, so I'll see about either an option to Layer Count to have a permanent display, or the separate plugin as well.

johnd0e commented 5 years ago

an option to Layer Count to have a permanent display

Explain how it might work

or the separate plugin

  map.on(L.Draw.Event.CREATED, function (e) {
    if (e.layerType === 'polygon') {
      // calculate area of e.layer and show it in any way (tooltip, sidebar, ...)
    }
  });
Athanasius commented 5 years ago

https://github.com/Athanasius/iitc-ce_ingress-intel-total-conversion/tree/layer-count-area

This version, as per your suggestion, ends up putting the (total for live fields) area on the usual layer count output strings. I'll see if this suits my needs, and if needs be see about additions to DrawTools to show this as a single polygon is edited.

It's against latest test-builds branch. Let me know if coding/commenting style or anything else needs addressing.

johnd0e commented 5 years ago

See http://zvaraondrej.github.io/Leaflet.MeasureAreaControl/example/ And https://prominentedge.com/leaflet-measure-path/