[OpenLayers-Users] OpenLayers.Layer.Vector and Internet Explorer

rikner at web.de rikner at web.de
Mon Jul 4 06:08:48 EDT 2011


I figured out, that my problem is, that the line

var folder = kmlDoc.getElementsByTagName("Folder");

returns no element. So the features for my vector layer won't be created.
I guess i have to work around this, so that IE behaves like FF.
But that shouldn't be problem. Thanks anyway.

/Erik


From: rikner at web.de 
Sent: Monday, July 04, 2011 8:58 AM
To: Vince Lotito ; openlayers-users at lists.osgeo.org 
Subject: Re: [OpenLayers-Users] OpenLayers.Layer.Vector and Internet Explorer


I tested it in IE 8 & 9, but none of them works.
The code for createMapFeatures() looks like this:


function createMapFeatures(kmlDoc){
 var allFeatures = new Array();
 
 var folder = kmlDoc.getElementsByTagName("Folder");
 for (var k=1; k<folder.length; k++){
  var groupName = folder[k].getElementsByTagName("name")[0].firstChild.data;
  
  if ((groups.search(/SBB/) != -1) && (groupName == 'SBB-Maschinen')){
   var placemarks = folder[k].getElementsByTagName("Placemark");
   for (var i=0; i<placemarks.length; i++){
    var feature = createFeatureFromPlacemark(placemarks[i], groupName);
    allFeatures.push(feature);
   }
  }
  else if ((groups.search(/Vanoli/) != -1) && (groupName == 'Vanoli-Maschinen')){
   var placemarks = folder[k].getElementsByTagName("Placemark");
   for (var i=0; i<placemarks.length; i++){
    var feature = createFeatureFromPlacemark(placemarks[i], groupName);
    allFeatures.push(feature);
   }
  }
  else if ((groups.search(/Meva/) != -1) && (groupName == 'Meva-Maschinen')){
   var placemarks = folder[k].getElementsByTagName("Placemark");
   for (var i=0; i<placemarks.length; i++){
    var feature = createFeatureFromPlacemark(placemarks[i], groupName);
    allFeatures.push(feature);
   }
  }
  else if ((groups.search(/Vanomag/) != -1) && (groupName == 'VANOMAG-Maschinen')){
   var placemarks = folder[k].getElementsByTagName("Placemark");
   for (var i=0; i<placemarks.length; i++){
    var feature = createFeatureFromPlacemark(placemarks[i], groupName);
    allFeatures.push(feature);
   }
  }
  else if (groups.search(/Admin/) != -1){
   var placemarks = folder[k].getElementsByTagName("Placemark");
   for (var i=0; i<placemarks.length; i++){
    var feature = createFeatureFromPlacemark(placemarks[i], groupName);
    allFeatures.push(feature);
   } 
  }
  
 }
 return allFeatures;
}


it calls following function:


function createFeatureFromPlacemark(placemark, groupName){
 var lonlatString = placemark.getElementsByTagName("coordinates")[0].firstChild.data;
 var lon = lonlatString.substring(0, lonlatString.indexOf(',')); 
 var lat = lonlatString.substring(lonlatString.indexOf(',')+1);
 
 //Daten auslesen
 var machineName = placemark.getElementsByTagName("name")[0].firstChild.data;
 var timestamp = placemark.getElementsByTagName("when")[0].firstChild.data;
 var lonlat = placemark.getElementsByTagName("coordinates")[0].firstChild.data;
 var voltage = parseFloat(placemark.getElementsByTagName("Data")[2].getElementsByTagName("value")[0].firstChild.data);
 
 //Zusatzdaten auslesen (Batterie, Tank,...)
 var extendedData = new Array();
 var dataElements = placemark.getElementsByTagName("Data");
 for (var j=0; j<dataElements.length; j++){
  extendedData[j] = new machineData(
   dataElements[j].getAttribute("name"), 
   dataElements[j].getElementsByTagName("value")[0].firstChild.data
  );
 }
 
 var feature = new OpenLayers.Feature.Vector(
  new OpenLayers.Geometry.Point (lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")), 
  {
   // type: 5 + parseInt(5 * Math.random()),
   label: machineName,
   timestamp: timestamp,
   lonlat: lonlat,
   group: groupName,
   voltage: voltage,
   extendedData: extendedData
  }
 );
 return feature;
}


I don't think that !isNaN() could solve the problem, since my index is a length of an array, so actually it should always be a number.
Any other thoughts on this? Maybe a hint, where to search exactly when debugging?

Thanks!
/Erik



From: Vince Lotito 
Sent: Saturday, July 02, 2011 1:14 PM
To: rikner at web.de 
Subject: RE: [OpenLayers-Users] OpenLayers.Layer.Vector and Internet Explorer


What version of Internet explorer?  IE 8 & above do have some developer tools that will allow you to debug your code.  I can't say for sure what the issue is without all the code, however I will say that had similar issues with the way IE parses the features different.. what does the code for  var features = createMapFeatures(kmlDoc) look like?  If you are to looping to create an array of features, e.g..

 

for (var i in features) {. 

 

then you will need to check to see if this is a valid index something like:

 

           if (!isNaN(i)) {

                        // then parse the feature.

}

}

 

Hope this helps..

Vince

 

 

From: openlayers-users-bounces at lists.osgeo.org [mailto:openlayers-users-bounces at lists.osgeo.org] On Behalf Of rikner at web.de
Sent: Saturday, July 02, 2011 5:14 AM
To: openlayers-users at lists.osgeo.org
Subject: [OpenLayers-Users] OpenLayers.Layer.Vector and Internet Explorer

 

Hello OpenLayers-Users!

 

I have some trouble with displaying a vector-layer on a map in Internet Explorer. In Chrome and Firefox, it works without problems but in IE, there is nothing to see except the OSM-map.

The Layer-Switcher shows my map as well as the vector-layer, but as i said there is nothing to see except the map.

 

I found out, that some people had issues similar to this and the problem was, that the code for the vector-layer or whatever was processed too early, so they just needed to wait until body onload.

But this seems to be NOT my problem, since I call my createMap()-function in init(), which is called on body-onload.

 

IE is not giving me any error, so i also don't know where to start. It's really annoying and I would be so glad, if you would have any hints for me.

 

Here's my code, let me know if you need more.

 

 

function createMap(kmlDoc){

 

 map = new OpenLayers.Map({
  div: "map",
  allOverlays: true
 });
 var osm = new OpenLayers.Layer.OSM();

 map.addControl(new OpenLayers.Control.LayerSwitcher());
 map.addControl(new OpenLayers.Control.MousePosition());
 

 var defaultStyle = new OpenLayers.Style({
  pointRadius: 4,

  fillColor: "#ffcc66",
  strokeColor: "#ff9933",
  strokeWidth: 1,
  graphicZIndex: 1
 }); 
 var selectStyle = new OpenLayers.Style({
  pointRadius: 6,
  fillColor: "#66ccff",
  strokeColor: "#3399ff",
  graphicZIndex: 2
 }); 
 var myStyles = new OpenLayers.StyleMap({
  "default": defaultStyle,
  "select": selectStyle
 });
  

 var features = createMapFeatures(kmlDoc);

 

 var machineLayer = new OpenLayers.Layer.Vector("Points", {
  styleMap: myStyles,
  rendererOptions: {zIndexing: true}
 });
 machineLayer.addFeatures(features);
 
 map.addLayers([osm, machineLayer]);

 

 select = new OpenLayers.Control.SelectFeature(machineLayer);
 machineLayer.events.on({
  "featureselected": onFeatureSelect,
  "featureunselected": onFeatureUnselect
 });
 map.addControl(select);
 select.activate(); 

  

 suisseBounds = new OpenLayers.Bounds(662556, 5751427, 1171817, 6076781);

 map.zoomToExtent(suisseBounds, false);
}



--------------------------------------------------------------------------------


_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110704/3b4f2eb2/attachment-0001.html


More information about the Users mailing list