Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9218465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:52:13+00:00 2026-06-18T02:52:13+00:00

I am trying to build an application based on backbone.js and leaflet. Users could

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:52:14+00:00Added an answer on June 18, 2026 at 2:52 am

    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.el is supposed to represent. Markers do of course have an element (accessible via marker._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 events or any el related 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:

    //MarkerView has no element
    App.Views.MarkerView = Backbone.View.extend({
    
        initialize: function(options) {
            //pass map instance to the marker
            this.map = options.map;
            //create the marker object
            this.marker = L.marker([this.model.get('longitude'), this.model.get('latitude')]);
        },
    
        render: function() {    
            //append marker to the map
            this.marker.addTo(this.map);
    
            //can't use events hash, because the events are bound
            //to the marker, not the element. It would be possible
            //to set the view's element to this.marker._icon after
            //adding it to the map, but it's a bit hacky.
            this.marker.on('click', this.onClick);
        },
    
        onClick: function() {
            alert("click");
        }
    });
    
    //MapView renders a map to the #map element
    App.Views.MapView = Backbone.View.extend({
        id:"#map",
        render: function() {
            //render map element
            var map = this.map =  L.map(this.$el.attr('id'))
                .setView([this.model.get('centerLon'),  this.model.get('centerLat') ], 13)
                .addLayer(L.tileLayer(this.model.get('layerUrl'), { maxZoom: 18 }));
    
            //render each marker
            this.markerViews = this.model.get('markers').map(function(marker) {
                return new App.Views.MarkerView({model:marker, map:map}).render();
            });
        }
    });
    

    Here’s a demo on JSFiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a Java application that allows users to use Git based
I'm trying to build a basic ListFragment based application which transitions from one ListFragment
I'm trying to build a single page web based application, so the entire UI
I'm trying to build application that could help me dial a contact just like
I'm trying to build a application that has different kinds of users, I'm using
Iam trying to build an Facebook Application based on PHP. The Application is running
I'm trying to build a PhoneGap-based application using Xcode 4. Since there's no PhoneGap
I'm trying to build a HTML based application for the iPad. I want to
I am trying to build a stand alone Spring based Java application. I am
Im trying to build a simple faye realtime based notification system so I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.