The concept comes from this http://www.prepbootstrap.com/bootstrap-template/real-estate-list-map-dynamic
I enable 2 blocks in a django template, left blockshows device info (device name and location info),right block shows device map location.When user can click on left panels, the right map will change by passing Django template variable to Javascript routine. It seems the passed variable is not accepted by init_map.
when user click on left column, the right map will switch according to latlon, which is passed by onclick routine.
template page is as follows:
{% block content %}
{% for device in devices %}
<div class="col-xs-6 col-sm-6 col-md-4 col-lg-4 ">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 ">
<div class="panel panel-default" onclick="init_map( {{ device.coordinates.latitude }}, {{device.coordinates.longitude }} );return false;">
<div class="row padall">
<div class="col-xs-12 col-sm-12 col-md-3 col-lg-3">
<span></span>
<img src="{{ device.thumbnail.url }}">
</div>
<div class="col-xs-12 col-sm-12 col-md-9 col-lg-9">
<div class="clearfix">
<div class="pull-left">
<span class="fa fa-dollar icon">{{device.name}}</span>
</div>
<div class="pull-right">
{{device.coordinates }}
</div>
</div>
<div>
<h4><span class="fa fa-map-marker icon"></span>{{ device.coordinates }}</h4>
<span class="fa fa-lock icon pull-right">{{ device.coordinates }}</span>
{% with lat_lon=device.coordinates %}
new is {{ lat_lon }}
{% endwith %}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<div class="row padbig">
<div id="map" class="map"></div>
</div>
</div>
{% endfor %}
{% endblock content %}
{% block extra_js %}
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=a23b5e94cecc8e98acd039aba6cd064c"></script>
<script type="text/javascript">
var lat_lon = {{ device.coordinates | js }};
function init_map(lat,lon) {
var imageLayer = new AMap.ImageLayer({
url:'http://developer.amap.com/wp-content/uploads/2014/06/dongwuyuan.jpg',
bounds: new AMap.Bounds(
new AMap.LngLat(116.327911, 39.939229),
new AMap.LngLat(116.342659, 39.946275)),
zooms: [15, 18]
});
var map = new AMap.Map('map',{
resizeEnable: true,
scrollWheel: true,
doubleClickZoom: true,
layers: [
new AMap.TileLayer(),
imageLayer
],
view: new AMap.View2D({
//center: new AMap.LngLat(116.342659, 39.946275),
center: new AMap.LngLat(lat,lon),
zoom:15
})
});
}
//init_map(0);
</script>
{% endblock %}
if I enabled "center: new AMap.LngLat(116.342659, 39.946275)," the map will show up, while with "center: new AMap.LngLat(lat,lon)," , no map show up.