[OpenLayers-Users] problem with display place from a local kml file

GANG WU ycwg0103 at gmail.com
Thu Jul 12 06:27:50 PDT 2012


Hi everyone,

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?

here is my code:

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);

Here is the result

 <http://www.nabble.com/>
-- 
*Gang Wu*
MS Information Science
University of Pittsburgh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120712/6ccda83b/attachment-0001.html>


More information about the Users mailing list