Skip to content

Commit

Permalink
Merge pull request #385 from Cadasta/bugfix/#276
Browse files Browse the repository at this point in the history
Fixes #276 and #377
  • Loading branch information
ian-ross authored Jul 11, 2016
2 parents c621121 + 777c662 commit c9434da
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
10 changes: 10 additions & 0 deletions cadasta/spatial/views/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from core.mixins import LoginPermissionRequiredMixin

from organization.serializers import ProjectGeometrySerializer
from resources.forms import AddResourceFromLibraryForm
from party.models import TenureRelationship
from party.messages import TENURE_REL_CREATE
Expand Down Expand Up @@ -54,6 +55,15 @@ def get_form_kwargs(self):

return kwargs

def get_context_data(self, **kwargs):
context = super(LocationsAdd, self).get_context_data(**kwargs)
project = self.get_project()
context['extent'] = project.extent is not None
context['extent_geojson'] = json.dumps(
ProjectGeometrySerializer(project).data
)
return context


class LocationDetail(LoginPermissionRequiredMixin,
JsonAttrsMixin,
Expand Down
25 changes: 23 additions & 2 deletions cadasta/templates/spatial/location_add.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
var map = e.originalEvent.detail.map;
add_map_controls(map);

// Add locations, if any
var data = {{ geojson|safe }};

var geoJson = L.geoJson(null, {
Expand All @@ -42,12 +43,32 @@

L.Deflate(map, {minSize: 20, layerGroup: geoJson});
geoJson.addData(data);

var markerGroup = L.markerClusterGroup.layerSupport()
markerGroup.addTo(map);
markerGroup.checkIn(geoJson);
geoJson.addTo(map);
map.fitBounds(geoJson.getBounds());

{% if extent %}
// Add project extent
var extent = {{ extent_geojson|safe }};
var extentGeoJson = L.geoJson(extent, {
style: {
"color": "#ff0000",
"weight": 2,
"opacity": 0.4,
"fill": true,
"fillColor": "#ff0000",
"fillOpacity": 0.2,
},
clickable: false,
}).addTo(map);

map.fitBounds(extentGeoJson.getBounds());
{% else %}
// TODO: It seems Leaflet has a bug with L.geoJson()
// not returning the correct bounds (see #377 for details)
map.fitBounds(L.geoJson(data).getBounds());
{% endif %}
});
});
</script>
Expand Down
4 changes: 3 additions & 1 deletion cadasta/templates/spatial/location_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
markerGroup.addTo(map);
markerGroup.checkIn(geoJson);
geoJson.addTo(map);
map.fitBounds(geoJson.getBounds());
// TODO: It seems Leaflet has a bug with L.geoJson()
// not returning the correct bounds (see #377 for details)
map.fitBounds(L.geoJson(data).getBounds());
}
</script>
{% endblock %}
Expand Down

0 comments on commit c9434da

Please sign in to comment.