0

I am trying to re create a google heat-map in wps. I managed to have it on a web form but I cannot use any web application only wpf.

How can I inject the code below into a browser control and also passing data from a server side method

<script>
    var map, heatmap;

    function initMap() {
        var CenterLat = 56.816918399;
        var CenterLong = -4.1826492694;
        var ArrMarkers = [];
        var ServerData =<%=GetJsonData(); %>;
        var Latitude;
        var Longitude;

        for (var i = 0; i < ServerData.length; i++) {

            Latitude = ServerData[i].Latitude;
            Longitude = ServerData[i].Longitude;

            var marker = { location: new google.maps.LatLng(Latitude, Longitude) };
            ArrMarkers.push(marker);

        }

        var mapCoordinates = {
            center: new google.maps.LatLng(CenterLat, CenterLong),
            zoom: 7,
            mapTypeId: 'satellite'
        };
        map = new google.maps.Map(document.getElementById('map'), mapCoordinates);

        heatmap = new google.maps.visualization.HeatmapLayer({
            data: ArrMarkers,
            radius: 15,
            opacity: 0.5,
            map: map
        });

    }//end InitMap



    function toggleHeatmap() {
        heatmap.setMap(heatmap.getMap() ? null : map);
    } 
</script>

<script type="text/javascript" async defer src="<%=GetJavaScriptUrl()%>">
</script>

So the first script is what google need to produce a staic map with an overlay and the second script is the google API url which also contains the google API key

brillox
  • 363
  • 3
  • 22
  • Create a HTML page with your JS and call the web page in WPF web Browser using Navigate . Does that work ? – Sats Dec 13 '18 at 15:51
  • I don't really follow why you'd want to inject that js, but take a look at. https://stackoverflow.com/questions/7998996/how-to-inject-javascript-in-webbrowser-control – Andy Dec 13 '18 at 16:29
  • the above code works in a web form (c#) how can i use it in WPF ? How in WPF I can use java-script and, from java script calling a function from .cs code ? e.g. var ServerData =<%=GetJsonData(); %>; – brillox Dec 13 '18 at 20:02
  • Hi Satish, I will try that this week-end as seems it is the correct direction like this tutorial https://www.c-sharpcorner.com/article/embed-google-maps-in-net-desktop-application/ – brillox Dec 13 '18 at 20:05

0 Answers0