On Github atlefren / SpatialBBPresentation
Atle Frenvik Sveen, Bouvet ASA 54°23'55"S 3°24'5"E
var MyListView = Backbone.View.extend({ initialize: function () { this.collection.on("add", this.modelAdded, this); }, modelAdded: function (model) { this.$el.append( new MyModelView({"model": model}).render().$el ); } }); var MyModelView = Backbone.View.extend({ tagName: "li", render: function () { this.$el.html(this.model.get("name")); return this; } }); /*Create a collection*/ var markerCollection = new Backbone.Collection(); /*Create a listview*/ var view = new MyListView({ "el": $("#view"), "collection": collection }); collection.add([ {"name": "Item 1}, {"name": "Item 2} ]);
var map = L.map('map').fitWorld(); L.tileLayer( 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: 'Map data © OpenStreetMap contributors.', maxZoom: 18 } ).addTo(map); L.marker([51.5, -0.09]).addTo(map) .bindPopup('A pretty CSS3 popup. Easily customizable.') .openPopup();
.. men det er mange tile-tilbydere
Er ikke .. Markers på kart .. mye av det samme som..Models i en collection?
var model = new SpatialBB.MarkerModel({ "name": "Model 1", "position": {"lon": 10, "lat": 60} }); model.getMarker(); //returnerer en Leaflet-marker
var model1 = new ns.MarkerModel({"position": {"lon": 10, "lat": 60}}); var model2 = new ns.MarkerModel({"position": {"lon": 11, "lat": 60}}); var collection = new ns.MarkerCollection(); collection.add([model1, model2]); collection.getLayerGroup(); //en L.MarkerGroup som oppdateres når collection oppdateres
Fikse http://www.bouvet.no/BouvetWEB/Om_Oss_Vaare_Kontorer.aspx
<div class="main"> <div id="map">map</div> <div id="offices"></div> </div> <script type="text/template" id="office_template"> <strong><%=name%></strong><br /> <%= street %><br /> <% if(line2) {%> <%= line2 %><br /> <% } %> <%= zip %> <%= place %><br /> Tlf: <%= tlf %><br /> <% if(!line2) {%> <br /> <% } %> </script>