Controller Problem(Dispalying points to the map)

12 views
Skip to first unread message

martjan dedi

unread,
Sep 30, 2016, 11:00:45 AM9/30/16
to Tethys Platform
HI Guys 

I am having trouble to display the points of the example given in the tethys website.
I run the code below and no errors but the points don't display to the map.(The code is from controllers.py file)
If someone can take a look at my question and help me ill be very graceful.
Thanks and Happy Coding.


The code is shown below :

import json
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from tethys_apps.sdk.gizmos import *
from .model import SpatialSessionMaker , SpatialAddressPoint
from tethys_gizmos.gizmo_options import MapView, MVLayer, MVView
import geoalchemy2
@login_required()



def home(request):

session = SpatialSessionMaker()
address_points = session.query(SpatialAddressPoint.geom.ST_AsGeoJSON()).all()

features = []




for address_point in address_points:
address_point_feature = {
'type':'Feature',
'geometry': json.loads(address_point[0])


}

features.append(address_point_feature)

geojson_address_points = {
'type' : 'FeatureCollection',
'crs':{
'type':'name',
'properties':{
'name': 'EPSG:4326'
}
} ,

'features':features


}



address_points = MVLayer(
source = 'GeoJSON',
options = geojson_address_points,
legend_title = 'jani',


)


initial_view = MVView(
                projection='EPSG:4326',
                center=[-100, 40],
                zoom=2,
                maxZoom=20,
                minZoom=2
            )

map_options = MapView(height = '600px',
              width= '100%',
              layers= [address_points],
              legend=True,
              basemap= 'OpenStreetMap',
              view=initial_view
    
        )




context = {'map_options': map_options}




session.close()

return render(request, 'postgis_app/home.html', context)











swainn

unread,
Sep 30, 2016, 11:58:30 AM9/30/16
to Tethys Platform
Do you get any JavaScript errors? If you are using Chrome, right-click anywhere on the page and select inspect element. Then take a look at the Console tab. Post any errors you received.
Reply all
Reply to author
Forward
0 new messages