我对这些东西很新。我有一个问题,它在管理地图上显示正常,但这些点实际上并没有显示在公共地图上。我在数据库中创建了对象,所以我认为它可能不是来自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.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;
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
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
答案 0 :(得分:1)
您可以先转到http://maps.google.com/?q=http://your.site/your.kml
来测试您的KML如果按预期工作,那么你知道这是你的javascript - 我建议你提供一个链接到你的网站,这将使某人更容易调试。