From 27e715213b84eea8b92667b0d01c1a35a40858f9 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 4 Feb 2019 11:29:45 +0100 Subject: Map JS: fix projections for display --- archaeological_finds/models_finds.py | 4 +--- ishtar_common/static/js/ishtar-map.js | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index fce9548ba..da872ab53 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -355,9 +355,7 @@ class BaseFind(BulkUpdatedItem, BaseHistorizedItem, OwnPerms): return def get_town_centroid(self): - if self.context_record.town: - return self.context_record.town.get_town_centroid() - return self.context_record.operation.get_town_centroid() + return self.context_record.get_town_centroid() def generate_index(self): """ diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js index f1fbca3e1..a8e1a4fa5 100644 --- a/ishtar_common/static/js/ishtar-map.js +++ b/ishtar_common/static/js/ishtar-map.js @@ -2,6 +2,8 @@ var default_pointer = "../media/images/default-pointer.png"; +var view_projection = 'EPSG:3857'; + var source_osm = function(options){ return new ol.layer.Tile({ source: new ol.source.OSM() @@ -63,24 +65,31 @@ var get_style = function(feature){ /* display map */ +var vector_source; +var vector_layer; +var map_layers; +var map; +var geojson_format = new ol.format.GeoJSON( + {dataProjection:'EPSG:4326', featureProjection: view_projection}); + var display_map = function(map_id, points, layers){ - console.log((new ol.format.GeoJSON()).readFeatures(points)); - var vector_source = new ol.source.Vector({ - features: (new ol.format.GeoJSON()).readFeatures(points) + vector_source = new ol.source.Vector({ + features: geojson_format.readFeatures(points) }); - var vector_layer = new ol.layer.Vector({ + vector_layer = new ol.layer.Vector({ source: vector_source, style: get_style }); - var map_layers = get_layers(layers); + map_layers = get_layers(layers); map_layers.push(vector_layer); - var map = new ol.Map({ + map = new ol.Map({ target: map_id, layers: map_layers, view: new ol.View({ + projection: view_projection, center: ol.proj.fromLonLat([37.41, 8.82]), zoom: 4 }) -- cgit v1.2.3