92
Views
1
Comments
Embed HTML code having javascript in expression
Question
Hi,
I am trying to add html code(with javascript ) in expression to display a map on outsystem webscreen but unfortumately it's not working for me.. Can anyone help me to understand if this is the best approach to display html code in webscreen.

Expression:

"<script type='text/javascript'src='https://www.openlayers.org/api/OpenLayers.js'></script>
  <script type='text/javascript' src='https://maps.google.com/maps/api/js?sensor=false'></script>

  <script type='text/javascript'>

    map = new OpenLayers.Map('"+mapdiv.Id+"');
    map.addLayer(new OpenLayers.Layer.OSM());
    
    epsg4326 =  new OpenLayers.Projection('EPSG:4326'); //WGS 1984 projection
    projectTo = map.getProjectionObject(); //The map projection (Spherical Mercator)
   
    var lonLat = new OpenLayers.LonLat( 0,0).transform(epsg4326, projectTo);
             
    var zoom=0;
    map.setCenter (lonLat, zoom);

    var vectorLayer = new OpenLayers.Layer.Vector('Overlay');
    
    
    var geocoder = new google.maps.Geocoder();
var address = ['calgary Canada','delhi India'];

for (i = 0; i< address.length;  i++)
 {
    geocoder.geocode( { 'address': address[i]}, function(results, status) {

  if (status == google.maps.GeocoderStatus.OK) {
 
   
 var feature = new OpenLayers.Feature.Vector(
            new OpenLayers.Geometry.Point( results[0].geometry.location.lng(),results[0].geometry.location.lat()).transform(epsg4326, projectTo),
            {description:'This is the value of<br>the description attribute'} ,
            {externalGraphic: 'https://leafletjs.com/dist/images/marker-icon-2x.png', graphicHeight: 25, graphicWidth: 21, graphicXOffset:-12, graphicYOffset:-25  }
        );    
        
    vectorLayer.addFeatures(feature);
    
    
  }
});
}
  map.addLayer(vectorLayer);
alert();

  </script>
 
    "
I have also attached my html file
distance.html
2023-08-19 05-23-29
Joshua Austin
If you want to Google maps, it may be easier to use this:
https://www.outsystems.com/forge/component/680/google-maps/
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.