Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Really, I think this a somewhat easy question for someone with some more experience in javascript programming.

I have a Django app to map some locations using leaflet. I'm using dajax for some on mouseover event already I want to integrate some filters using the same library. Problem is, I can't manage to update the map with the filtered data. The template tag {{ geo_json|safe }}; holds the data the map is initialised with. To clarify, here is my js code from my template

var map ='leaflet_map').setView({{zoom|safe}}, 13);
   attribution: 'Map data &copy; <a href="">OpenStreetMap</a>, Imagery &copy; <a href="">CloudMade</a>',
   maxZoom: 18

var geojsonFeature = {{ geo_json|safe }};

function onEachFeature(feature, layer) {
      layer.on('click', function (e) {

          var id =
          win_str = '/vsoilmap/popup?id=' + id

      layer.on('mouseover', function (e) {

          var id =
          win_str = '/vsoilmap/popup?id=' + id

      layer.on('mouseout', function (e) {


var geojsonMarkerOptions = {
    radius: 8,
            fillColor: "green",
    color: "darkgreen",
    weight: 0.5,
    opacity: 0.8,
    fillOpacity: 0.8

var gj = L.geoJson(geojsonFeature, {
    onEachFeature: onEachFeature,
            pointToLayer: function (feature, latlng) {
               return L.circleMarker(latlng, geojsonMarkerOptions);

What I'm basically trying to do is to update the variable geojsonFeature. If I use the dajax add_data method I get the error Map container is already initialized. Of course the whole point of using ajax is to NOT load the map again so my question really is: how can I change the content of a variable in js without running the whole function again?

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.