当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - 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 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!

分享给朋友:
您可能感兴趣的文章:
随机阅读: