I am trying to build an application based on backbone.js and leaflet.
Users could drag the map and see markers on the map.
Markers can be selected by clicking on them. When selected they have to change their icon and the marker detailed information shown on a (not popup).
my backbone model consists of several entities:
Marker model contains
latitude, longitude
type,
title,
isSelected
Map model contains:
center of the map,
markers collection,
selected marker
anyone has any idea how i could make this kind of functionality?
how can i make leaflet markers as backbone views?
Backbone views and the leaflet object model are not a perfect fit, because the markers aren’t contained within a DOM element, which is what
Backbone.View.elis supposed to represent. Markers do of course have an element (accessible viamarker._icon), but it doesn’t exist until the marker is rendered to the map.That said, you can represent the markers with Backbone views, you just can’t use the
eventsor anyelrelated functionality. I’ve implemented similar views successfully using OpenLayers, which has the same “problem”, and it works fine.I think this is easiest to explain with code:
Here’s a demo on JSFiddle.