Git Product home page Git Product logo

Comments (3)

sfairgrieve avatar sfairgrieve commented on May 18, 2024

Good idea. I'll add support for toGeoJSON to all markers/polygons so those items are in line with other Leaflet marker and polygon classes.

from leaflet-dvf.

hrishiballal avatar hrishiballal commented on May 18, 2024

I hacked it a bit and have the following in leaflet-dvf.markers.js in L.RegularPolygonMarker definition we add following:

        constructPolygon: function () {
        var map = this._map;
        this._point = map.latLngToLayerPoint(this._latlng);
        this._points = this._getPoints();
        var polygonPointsLL = [];
        $.each(this._points, function(idx, point) {
            polygonPointsLL.push(map.layerPointToLatLng(point));
        });
        return polygonPointsLL;

    },

finally the polygonPoinsLL can then be passed into a function in your webpage outside dvf:

  function constructGeoJSON(polygonObject)
    {
      var coordList = [];
      var curcoords = [];
      var firstLat=[];
      var firstLng=[];
      $.each(polygonObject, function (idx, pObject)
      {
          var lat  = pObject.lat;
          var lng  = pObject.lng;
          if (idx == 0)
          {
            firstLat = lat;
            firstLng = lng;
          }
          curcoords.push([lng,lat]);
      });
      curcoords.push([firstLng,firstLat]);
      coordList.push(curcoords);
      var allFeatList = [{
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": coordList
      }
    }];
  var opGJ = {
  "type": "FeatureCollection",
  "features": allFeatList
    }
    console.log(JSON.stringify(opGJ));
  }

This works for normal polygons but does not work for hollow polygons.

While this is a hack the correct way to do this is to use L.Polygon.extend instead of L.Path.extend but there are issues around geo-referencing paths in Leaflet. Not sure if it will work with SVG etc.

from leaflet-dvf.

sfairgrieve avatar sfairgrieve commented on May 18, 2024

@hrishiballal I'm currently in the process of implementing this, along with a number of other improvements. I'm open to your thoughts on this, but my plan is not to export a geo-referenced version of the points that make up a RegularPolygonMarker geometry as a GeoJSON Polygon feature, because that polygon that's displayed is zoom level dependent. This is the reason that the RegularPolygonMarker class does not extend Polygon. It's more like a custom drawn SVG image centered at some latitude and longitude that gets redrawn every time a user zooms in/out than some polygon with points tied to specific geographic coordinates. If it was a Polygon, it would be really tiny when zoomed out and really large when zoomed in. Does that make sense?

My plan is to export a GeoJSON Point feature with all the RegularPolygonMarker options available as properties, plus a "type" property that lets other applications know that it's a regular polygon. Another option might be to also include the SVG representation of the marker as a GeoJSON property as well. That way external applications might be able to use that as what's displayed. Let me know what you think.

from leaflet-dvf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.