Javascript GeoDjango在地图上映射点
我对这东西还很陌生。我有一个问题,它在管理地图上显示得很好,但是点实际上没有显示在公共地图上。我在数据库中创建了对象,所以我认为它可能不是来自javascript或KML 谢谢 大卫 models.pyJavascript GeoDjango在地图上映射点,javascript,django,kml,geodjango,Javascript,Django,Kml,Geodjango,我对这东西还很陌生。我有一个问题,它在管理地图上显示得很好,但是点实际上没有显示在公共地图上。我在数据库中创建了对象,所以我认为它可能不是来自javascript或KML 谢谢 大卫 models.py 1 from django.contrib.gis.db import models 2 #from apps.pages.models import DataEntry 3 4 class PointLayer( models.Model ): 5 geometry = models
1 from django.contrib.gis.db import models
2 #from apps.pages.models import DataEntry
3
4 class PointLayer( models.Model ):
5 geometry = models.PointField( blank=True,null=True )
6 objects = models.GeoManager()
7
8 site = models.CharField( max_length=50, blank=True )
9 snow_Depth = models.FloatField( )
10 albedo = models.FloatField()
11 snow_Density = models.FloatField()
12 lon = models.FloatField()
13 lat = models.FloatField()
14
15 def __unicode__( self ):
16 return self.site
17
18 def description( self ):
19 ret = "<b>Site:</b>" + self.site + "<br/>"
20 ret += "<b>Snow Depth:</b>" + str(self.snow_Depth) + "<br/>"
21 ret += "<b>Albedo:</b>" + str(self.albedo) + "<br/>"
22 ret += "<b>Snow Density:</b>" + str(self.snow_Density) + "<br/>"
23 ret += "<a href='/map/" + str(self.pk) + "/'>Full Point Record</a><br/>"
24 ret += "<hr/>"
25 return ret;
django.contrib.gis.db导入模型中的1
2#从apps.pages.models导入数据条目
3.
4类点图层(models.Model):
5几何体=模型.点域(空白=真,空=真)
6个对象=模型。GeoManager()
7.
8 site=models.CharField(最大长度=50,空白=True)
9雪深=模型。浮场()
10反照率=models.FloatField()
11雪密度=模型。浮场()
12 lon=模型。FloatField()
13 lat=models.FloatField()
14
15定义unicode(自):
16返回自助站点
17
18 def说明(自我):
19 ret=“站点:+self.Site+”
20 ret+=“雪深:”+str(自雪深)+“
”
21 ret+=“反照率:”+str(自我反照率)+“
”
22 ret+=“雪密度:”+str(自雪密度)+“
”
23 ret+=“
”
24 ret+=“
”
25返回ret;
map.js
1 var map, layer;
2 var lon = 0;
3 var lat = 0;
4 var zoom = 2;
5 var currentKmlObjects = {};
6
7 function init(){
8
9 map = new OpenLayers.Map('map');
10
11 map.addControl( new OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('layerswitcher')}));
12
13 var gphy = new OpenLayers.Layer.Google("Google Physical",
14 {type: google.maps.MapTypeId.TERRAIN});
15
16 var gmap = new OpenLayers.Layer.Google("Google Streets",
17 {numZoomLevels: 20});
18
19 var ghyb = new OpenLayers.Layer.Google("Google Hybrid",
20 {type: google.maps.MapTypeId.HYBRID,
21 numZoomLevels: 20});
22
23 var gsat = new OpenLayers.Layer.Google("Google Satellite",
24 {type: google.maps.MapTypeId.SATELLITE,
25 numZoomLevels: 22});
26
27 var points = new OpenLayers.Layer.Vector("Albedo Data Points", {
28 strategies: [new OpenLayers.Strategy.Fixed()],
29 protocol: new OpenLayers.Protocol.HTTP({
30 url: "http://albedo.csrcdev.com/map/test.kml",
31 format: new OpenLayers.Format.KML({
32 extractStyles: true,
33 extractAttributes: true
34 })
35 })
36 });
37
38 map.addLayers([gsat, gphy, gmap, ghyb, points]);
39
40 //Google.v3 uses ESPG:900913 as projection, so we have to
41 //transform our coordinates
42 map.setCenter(new OpenLayers.LonLat(lon, lat).transform(
43 new OpenLayers.Projection("ESPG:4326"),
44 map.getProjectionObject()
45 ), zoom);
46
47 //Interaction not needed for initial display.
48 selectControl = new OpenLayers.Control.SelectFeature(points);
49 map.addControl(selectControl);
50 selectControl.activate();
51 points.events.on({
52 'featureselected': onFeatureSelect,
53 'featureunselected': onFeatureUnselect
54 });
55 }
56
57 //Interactive functions:
58 function onPopupClose( evt ){
59 //this is the pop-up
60 var feature = this.feature;
61 if( feature.layer ){
62 selectControl.unselect( feature );
63 }
64 //After 'move-end' or 'refresh' events on POIs layer all
65 //features have been destroyed by the Strategy.BBOX
66 else{
67 this.destroy();
68 }
69 }
70
71 function onFeatureSelect( evt ){
72 feature = evt.feature;
73 popup = new OpenLayers.Popup.FramedCloud( "featurePopup",
74 feature.geometry.getBounds().getCenterLonLat(),
75 new OpenLayers.Size( 100,100 ),
76 "<h2>" + feature.attributes.name + "</h2>" +
77 feature.attributes.description,
78 null, true, onPopupClose );
79 feature.popup = popup;
80 popup.feature = feature;
81 map.addPopup( popup, true );
82 }
83
84 function onFeatureUnselect( evt ){
85 feature = evt.feature;
86 if( feature.popup ){
87 popup.feature = null;
88 map.removePopup( feature.popup );
89 feature.popup.destroy();
90 feature.popup = null;
91 }
92 }
93
94
95
1 var图,图层;
2 var-lon=0;
3 var-lat=0;
4=2;
5 var currentKmlObjects={};
6.
7函数init(){
8.
9 map=newOpenLayers.map('map');
10
11 map.addControl(新的OpenLayers.Control.LayerSwitcher({'div':OpenLayers.Util.getElement('LayerSwitcher')});
12
13 var gphy=new OpenLayers.Layer.Google(“谷歌物理”,
14{type:google.maps.MapTypeId.TERRAIN});
15
16 var gmap=new OpenLayers.Layer.Google(“谷歌街道”,
17{numZoomLevels:20});
18
19 var ghyb=new OpenLayers.Layer.Google(“谷歌混合”,
20{type:google.maps.MapTypeId.HYBRID,
21个numZoomLevels:20});
22
23 var gsat=new OpenLayers.Layer.Google(“谷歌卫星”,
24{type:google.maps.MapTypeId.SATELLITE,
25个numZoomLevels:22});
26
27 var points=新的OpenLayers.Layer.Vector(“反照率数据点”{
28策略:[新建OpenLayers.Strategy.Fixed()],
29协议:新OpenLayers.protocol.HTTP({
30 url:“http://albedo.csrcdev.com/map/test.kml",
31格式:新OpenLayers.format.KML({
32:对,
33:正确
34 })
35 })
36 });
37
38地图添加图层([gsat、gphy、gmap、ghyb、points]);
39
40//Google.v3使用ESPG:900913作为投影,因此我们必须
41//变换我们的坐标
42 map.setCenter(新OpenLayers.LonLat(lon,lat).transform(
43新OpenLayers.投影(“ESPG:4326”),
44 map.getProjectionObject()
45)、变焦;
46
47//初始显示不需要交互。
48 selectControl=新建OpenLayers.Control.SelectFeature(点);
49 map.addControl(selectControl);
50选择control.activate();
51分({
52“featureselected”:OnFeatureSelected,
53“未选择功能”:onFeatureUnselect
54 });
55 }
56
57//交互功能:
58功能onPopupClose(evt){
59//这是弹出窗口
60 var feature=此特性;
61如果(要素图层){
62选择控制。取消选择(功能);
63 }
64//在POI层上的“移动结束”或“刷新”事件之后
65//Strategy.BBOX已销毁功能
66其他{
67.这是毁灭;
68 }
69 }
70
71功能特性选择(evt){
72特征=evt.特征;
73 popup=新建OpenLayers.popup.FramedCloud(“featurePopup”,
74特征.geometry.getBounds().getCenterLonLat(),
75个新的开放层。尺寸(100100),
76“+feature.attributes.name+”+
77 feature.attributes.description,
78 null,true,onPopupClose);
79 feature.popup=弹出窗口;
80.feature=feature;
81 map.addPopup(弹出,真);
82 }
83
84功能ON功能取消选择(evt){
85特征=evt特征;
86如果(feature.popup){
87.feature=null;
88 map.removePopup(feature.popup);
89 feature.popup.destroy();
90 feature.popup=null;
91 }
92 }
93
94
95
main.kml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <kml xmlns="http://www.opengis.net/kml/2.2">
3 <Document>
4 <name><![CDATA[{%if doc_name%}{{doc_name}}{%else%}HMAP{%endif%}]]></name>
5 <open>1</open>
6 <snippet maxLines="2"></snippet>
7 <description><![CDATA[Exported from {% if doc_name %}{{ doc_name }}{% else %}HMAP{% endif %}]]></description>
8 {% block styles %}
9 {% if styles %}
10 {% for style in styles %}
11 <Style id="{{style.name}}">
12 <LineStyle>
13 <color>{{style.color}}</color>
14 <width>0.2</width>
15 </LineStyle>
16 <PolyStyle>
17 <outline>1</outline>
18 <fill>{% if style.fill %}{{ style.fill }}{% else %}1{% endif %}</fill>
19 <color>{{style.color}}</color>
20 </PolyStyle>
21 <IconStyle>
22 <color>BFFFFFFF</color>
23 <scale>{% if style.icon_scale %}{{ style.icon_scale }}{% else %}0.6{% endif %}</scale>
24 <Icon>
25 <href>{% if style.icon %}{{style.icon}}{% else %}http:://albedo.csrcdev.com/media/images/icons/marker.png{% endif %}</href>
26 </Icon>
27 <hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
28 </IconStyle>
29 <LabelStyle>
30 <color>00000000</color>
31 </LabelStyle>
32 </Style>
33 {% endfor %}
34 {% else %}
35 <Style id="default">
36 <LineStyle>
37 <color>8800ff00</color>
38 <width>0.2</width>
39 </LineStyle>
40 <PolyStyle>
41 <outline>1</outline>
42 <fill>1</fill>
43 <color>8800ff00</color>
44 </PolyStyle>
45 <IconStyle>
46 <color>BFFFFFFF</color>
47 <scale>{% if style.icon %}{{style.icon_scale}}{% else %}0.6{% endif %}</scale>
48 <Icon>
49 <href>{% if style.icon %}{{style.icon}}{% else %}http://albedo.csrcdev.com/media/images/icons/marker.png{% endif %}</href>
50 </Icon>
51 <hotSpot x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
52 </IconStyle>
53 <LabelStyle>
54 <color>00000000</color>
55 </LabelStyle>
56 </Style>
57 {% endif %}
58 {% endblock %}
59 {% block features %}
60 <Folder>
61 <name>Features</name>
62 {% for geometry in geometries %}
63 <Placemark id="{{geometry.pk}}">
64 <name><![CDATA[{{geometry.name}}]]></name>
65 <description><![CDATA[{%block description%}{{geometry.description|safe}}{% endblock%}]]></description>
66 <Snippet maxLines="2"></Snippet>
67 {% if geometry.style %}
68 <styleUrl>#{{geometry.style}}</styleUrl>
69 {% else %}
70 <styleUrl>#defualt</styleUrl>
71 {% endif %}
72 {% if geometry.timespane %}
73 <TimeSpan>
74 {% if geometry.timespan.begin %}<begin>{{geometry.timespan.begin}}</begin>{% endif %}
75 {% if geometry.timespan.begin %}<end>{{geometry.timespan.end}}</end>{% endif %}
76 {{geometry.geometry.kml|safe}}
77 </TimeSpan>
78 {% endif %}
79 {% block extend_data %}{% endblock %}
80 {{ geometry.geometry.kml|safe }}
81 </Placemark>
82 {% endfor %}
83 </Folder>
84 {% endblock %}
85 <Folder>
86 <name>Information Points</name>
87 <open>0</open>
88 {% block placemarks %}{{ placemarks }}{% endblock %}
89 </Folder>
90 </Document>
91 </kml>
92
1
2.
3.
4.
5 1
6.
7.
8{%块样式%}
9{%if%}
10{样式中的样式为%}
11
12
13{{style.color}}
14 0.2
15
16
17 1
18{%if style.fill%}{{style.fill}{%else%}1{%endif%}
19{{style.color}}
20
21
22 bFFFFFF
23{%if style.icon_scale%}{{style.icon_scale}{%else%}0.6{%endif%}
24
25{%if style.icon%}{{style.icon}{%else%}http://albedo.csrcdev.com/media/images/icons/marker.png{%endif%}
26
27
28
29
30 00000000
31
32
33{%endfor%}
34{%else%}
35
36
378800FF00
38 0.2
39
40
41 1
42 1
438800FF00
44
45
46 bFFFFFF
47{%if style.icon%}{{style.icon_scale}{%else%}0.6{%endif%}
48
49{%if style.icon%}{{style.icon}{%else%}http://albedo.csrcdev.com/media/images/icons/marker.png{%endif%}
50
51
52
53
54 00000000
55
56
57{%endif%}
58{%endblock%}
59{%块特征%}
60
61