wkt取得2


流石に使いづらかったのでちょっと修正。
まあゆっくりやるかな。

仮置き
http://jpusergis.site44.com/wkt/WktJs2.html

前記事
https://jpusergis.wordpress.com/2014/05/22/wkt取得/

L.Control.WktView = L.Control.extend({
  ptions: {
    position: 'topright',
    group: null
  },

  initialize: function (options) {
    if (!options || !(options.group instanceof L.LayerGroup))
      throw new Error('LayerGroupが必要');
    L.Control.prototype.initialize.call(this, options);

    this._group = options.group;
  },
  onAdd: function (map) {
      
    var container = L.DomUtil.create('div', '');
    //地図操作無効化
    if (!L.Browser.touch) {
      L.DomEvent
        .disableClickPropagation(container)
        .disableScrollPropagation(container);
    } else {
      L.DomEvent.on(container, 'click', L.DomEvent.stopPropagation);
    }
    //表示領域セット
    var input = L.DomUtil.create('input', '', container);
    input.type = 'button';
    input.value = 'WKT表示';
    L.DomEvent.on(input, 'click', this._onClick, this);

    L.DomUtil.create('br', '', container);

    var txtArea = L.DomUtil.create('textarea', '', container);
    txtArea.style.height = 400 + 'px';
    txtArea.style.width = 300 + 'px';

    //クリアボタン定義
    var clear = L.DomUtil.create('input', null, container);
    clear.type = 'button';
    clear.value = 'クリア';
    L.DomEvent.on(clear, 'click', function () {
      txtArea.value = '';
    });

    L.DomUtil.create('br', null, container);

    this._txt = txtArea;
    return container;
  },
  onRemove: function (map) {
    this._input.style.diplay = 'none';
    this._txtArea.style.diplay = 'none';
  },
  _onClick: function (evt) {

    var group = this._group;

    var textArea = this._txt;
    group.eachLayer(function (layer) {
      
      var isMulti = false;
      if (layer instanceof L.Polygon) {
        textArea.value += "POLYGON((";
        isMulti = true;
      } else if (layer instanceof L.Polyline) {
        textArea.value += "LINESTRING(";
      }//end if

      if (layer instanceof L.Polygon || layer instanceof L.Polyline) {
        var latlngs = layer.getLatLngs();
        for (var i = 0; i < latlngs.length; i++) {
          if (i != 0)
            textArea.value += ',';
          textArea.value += latlngs[i].lng + ' ' + latlngs[i].lat;
        }
        if (layer instanceof L.Polygon) {
          textArea.value +=  ',' + latlngs[0].lng + ' ' + latlngs[0].lat
        }

        if (isMulti)
          textArea.value += ')';
        textArea.value += ')';

      } else if (layer instanceof L.Marker) {
        var ao = layer.getLatLng();
        textArea.value += 'POINT(' + ao.lng + ' ' + ao.lat + ')';
      } else if (layer instanceof L.LayerGroup) {

      }//end if

      textArea.value += '\n';
      textArea.value += '\n';
    });//end loop
  },
  _lgroupToWkt: function(layer){
  }//end function
});
L.control.wktView = function (options) {
  return new L.Control.WktView(options);
};
カテゴリー: 開発 タグ: パーマリンク