LoginSignup
0
0

More than 3 years have passed since last update.

leafletを鍛える。その15

Last updated at Posted at 2018-10-30

概要

leafletを鍛えてみた。
マーカーを次々、表示してみた。

写真

サンプルコード

var map = L.map('map').setView([35.7, 139.7], 12);

L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

var k = 0;
var marker;
var train = trains[k];
marker = L.marker([train.location.lat, train.location.lon], {
    title: train.train_number
}).addTo(map);
function next() {
    k++;
    if (k > train.length) k = 0;
    map.removeLayer(marker);
    train = trains[k];
    marker = L.marker([train.location.lat, train.location.lon], {
        title: train.train_number
    }).addTo(map);
    marker.bindPopup('title: ' + train.train_number );
    marker.openPopup();
    setTimeout(next, 3000);
}
next();


成果物

以上。

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