<br clear="all"><div id="message4987757" class="message-text">
Hi everyone,
<br><br>Here is my question. I am using a simple php file to upload
local kml file. After the file has been uploaded, the content will be
read into array of features with OpenLayers.Format.KML object. But the
problems is that all the features map to the wrong position. Is it
something wrong with projection?
<br><br>here is my code:
<br><pre>map = new OpenLayers.Map('map_element');
var google_map = new OpenLayers.Layer.Google('Google Layer', {});
map.addLayer(google_map);
if (!map.getCenter()) {
map.zoomTo(1);
}
var features = [];
var kml = new OpenLayers.Format.KML({
extractAttributes : true,
extractStyles : true
});
features= kml.read(responseData);
//alert(features);
var strategy =new OpenLayers.Strategy.Cluster();
var vector_layer = new OpenLayers.Layer.Vector('PlaceMarker', {
projection : new OpenLayers.Projection('EPSG:4326'),
strategies : [strategy]
});
var vector_style = new OpenLayers.Style({
'fillColor' : '#669933',
'fillOpacity' : .8,
'fontColor' : '#f0f0f0',
'fontFamily' : 'arial, sans-serif',
'fontSize' : '.9em',
'fontWeight' : 'bold',
'label' : '${num_points}',
'pointRadius' : '${point_radius}',
'strokeColor' : '#aaee77',
'strokeWidth' : 3
},
// Second parameter contains a context parameter
{
context : {
num_points : function(feature) {
return (feature.cluster) ? feature.attributes.count : 5;
},
point_radius : function(feature) {
var pix = 8;
if(feature.cluster) {
pix = feature.attributes.count + 7;
}
return pix;
}
}
});
var vector_style_select = new OpenLayers.Style({
'fillColor' : '#cdcdcd',
'fillOpacity' : .9,
'fontColor' : '#232323',
'strokeColor' : '#ffffff'
})
// Create a style map object and set the 'default' intent to the
var vector_style_map = new OpenLayers.StyleMap({
'default' : vector_style,
'select' : vector_style_select
});
// Add the style map to the vector layer
vector_layer.styleMap = vector_style_map;
// Add a select feature control
var select_feature_control = new OpenLayers.Control.SelectFeature(
vector_layer, {})
map.addControl(select_feature_control);
select_feature_control.activate();
vector_layer.events.register('featureselected', this, on_select_feature);
vector_layer.events
.register('featureunselected', this, on_unselect_feature);
map.addLayer(vector_layer);
vector_layer.addFeatures(features);
</pre><h4>Here is the result</h4><br><img src="http://osgeo-org.1560.n6.nabble.com/file/n4987757/04.png" border="0"><br>
</div>
<a href="http://www.nabble.com/"></a><br>-- <br><b>Gang Wu</b><div>MS Information Science</div><div>University of Pittsburgh</div><div><br></div><br>