Drawing a radius on olwidget in django
I'm using olwidget inside of django to draw some maps. In one of my forms, I ask the user for a location and a radius. The location is input using the OpenLayers map provided by olwidget, and the radius is the slider from jquery-ui.
What I would like to do is draw a radius circle on the map that updates as the user manipulates the slider.
I am unable to get a reference to the OpenLayers map that olwidget creates. The source code that olwidget generates looks like this:
<textarea id="id_zone_centroid_zone_centroid" rows="10" cols="40" name="zone_centroid">SRID=4326;POINT (-75.6981940000000009 45.4115719999999996)</textarea>
<script type="text/javascript">
new olwidget.Map("id_zone_centroid", [
new olwidget.EditableLayer("id_zone_centroid_zone_centroid", {"geometry": "point", "name": "centroid"})
],
{"layers": ["google.hybrid", "google.streets"], "mapOptions": {"controls": ["LayerSwitcher", "Navigation", "PanZoom", "Attribution"]}, "mapDivStyle": {"width": "500px", "height": "400px"}}
);
</script>
Is there any way to get olwidget to 开发者_JAVA技巧output custom javascript attached to the map?
Thanks
I think you might be able to override the template that renders the OpenLayers map. You can do this by creating "templates/olwidget/multi_layer_map.html" within your app. In there you'll likely need to do something like this (adapted from the original):
<div id="{{ id }}"></div>
{{ layer_html|join:"" }}
<script type="text/javascript">
var map = new olwidget.Map("{{ id }}", [
{{ layer_js|join:"," }}
],
{{ map_opts|safe }}
); // got the ref now :)
// do your customization here
</script>
I hope this works for you!
精彩评论