Tôi đã chạy geodjango bằng cách sử dụng openlayers và OpenStreetMaps bằng ứng dụng quản trị.Làm thế nào để hiển thị dữ liệu bằng cách sử dụng openlayers với OpenStreetMap trong geodjango?
Bây giờ tôi muốn viết một số chế độ xem để hiển thị dữ liệu. Về cơ bản, tôi chỉ muốn thêm một danh sách các điểm (xem trong quản trị) vào bản đồ.
Geodjango dường như sử dụng đặc biệtopenlayers.js tệp để thực hiện điều đó trong quản trị viên. Có cách nào tốt để giao tiếp với điều này?
Làm cách nào để tôi có thể viết chế độ xem/mẫu để hiển thị dữ liệu geodjango trên cửa sổ bản đồ mở, như được thấy trong quản trị viên?
Hiện tại, tôi đang đào sâu vào tệp openlayers.js và api đang tìm kiếm giải pháp 'dễ dàng'. (Tôi không có kinh nghiệm js vì vậy việc này mất chút thời gian.)
Cách hiện tại tôi có thể xem để thực hiện việc này là thêm mẫu sau làm mẫu và sử dụng django để thêm mã cần thiết để hiển thị điểm. (Dựa trên ví dụ here)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Draw Feature Example</title>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
var map;
function init(){
map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS("OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'});
map.addLayer(layer);
/*
* Layer style
*/
// we want opaque external graphics and non-opaque internal graphics
var layer_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
layer_style.fillOpacity = 0.2;
layer_style.graphicOpacity = 1;
/*
* Blue style
*/
var style_blue = OpenLayers.Util.extend({}, layer_style);
style_blue.strokeColor = "blue";
style_blue.fillColor = "blue";
style_blue.graphicName = "star";
style_blue.pointRadius = 10;
style_blue.strokeWidth = 3;
style_blue.rotation = 45;
style_blue.strokeLinecap = "butt";
var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {style: layer_style});
// create a point feature
var point = new OpenLayers.Geometry.Point(-111.04, 45.68);
var pointFeature = new OpenLayers.Feature.Vector(point,null,style_blue);
// Add additional points/features here via django
map.addLayer(vectorLayer);
map.setCenter(new OpenLayers.LonLat(point.x, point.y), 5);
vectorLayer.addFeatures([pointFeature]);
}
</script>
</head>
<body onload="init()">
<div id="map" class="smallmap"></div>
</body>
</html>
Đây có phải là cách thực hiện hoặc có cách nào tốt hơn không?
Tôi nghĩ rằng phương pháp tốt nhất là tạo ra một cái nhìn django mà trả về đối tượng JSON cần thiết cho các dữ liệu cần thiết. – monkut