0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

leafletを鍛える。その39

0
Posted at

概要

leafletを鍛えてみた。
練習問題、やってみた。

練習問題

csv2geojsonを実装せよ。

方針

turf.js、使う。

写真

image.png

サンプルコード

var map = L.map('map').setView([38.0748331, 139.4574997], 9);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
function run() {
  var line = src.value.split('\n');
  var v = [];
  for (var i = 0; i < line.length - 1; i++)
  {
    var item = line[i].split(',');
    var location = turf.point([parseFloat(item[2]), parseFloat(item[1])], {
      name: item[0]
    });
    v.push(location);
  }
  var collection = turf.featureCollection(v);
  L.geoJSON(collection, {
		onEachFeature: function(feature, layer) {
			layer.bindPopup(feature.properties.name);
		}
	}).addTo(map);
}

成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?