asp.net - Changing KML Placemark Color with JavaScript -
hello stack overflow people!!
i don't know if there's way this, i'm hoping there since alternative more complicated , i'm not positive how accomplish it. @ moment, i've got google earth plugin running on page other controls. page supposed show chart latency , signal-to-noise data modem grid tons of additional information isp little better when comes trouble shooting modems.
the question have is: there way in javascript modify color of google earth placemark without messing kml?
i know can in kml
<style id="normalplacemark"> <iconstyle> <color>ffffff00</color> <scale>5</scale> <icon> <href>http://maps.google.com/mapfiles/kml/pushpin/wht-pushpin.png</href> </icon> </iconstyle> </style>
but i've been having trouble appending right place in overall xml using c# or addkmlfromstring() in javascript (which i'm unfamiliar with) page recognize it.
here's modified plugin code i'm using @ moment:
<script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> var ge; google.load("earth", "1"); //create instance of earth function init() { google.earth.createinstance('gmap', initcallback, failurecallback); } function initcallback(plugininstance) { ge = plugininstance; ge.getwindow().setvisibility(true); //url kml file taken directly google //the kml in question google's giant file weather data var href = 'aurlwherewetherdatalives.kml'; //use google's fetch kml method weather kml file , add our plugin's instance google.earth.fetchkml(ge, href, function (kmlobject) { if (kmlobject) { ge.getfeatures().appendchild(kmlobject); } if (kmlobject.getabstractview() !== null) ge.getview().setabstractview(kmlobject.getabstractview()); }); //turn on country borders, states, , cities ge.getlayerroot().enablelayerbyid(ge.layer_borders, true); //by default, remoteexists uses true javascript wants true var jsremoteexists = <%= remoteexists.tostring().tolower() %>; //if remote exists, create placemark , camera @ location using //the latitude , longitude variables retreived in c# if (jsremoteexists) { //variables have been created var lat = <%= csharplat %>; var lon = <%= csharplong %>; ge.getwindow().setvisibility(true); // create placemark , add earth. var placemark = ge.createplacemark(''); // set placemark's location. var point = ge.createpoint(''); point.setlatitude(lat); point.setlongitude(lon); placemark.setgeometry(point); // add placemark earth. ge.getfeatures().appendchild(placemark); var la = ge.createlookat(''); la.setlatitude(lat); la.setlongitude(lon); la.setrange(150000); ge.getview().setabstractview(la); } } function failurecallback(errorcode) { } function addkmlfromstring(kmlstring) { var kmlobject = ge.parsekml(kmlstring); ge.getfeatures().appendchild(kmlobject); } window.onload = init(); </script>
would better find add above kml string in c# code behind , find right place add style? i've been pouring on google's api , trying add in different places , of time breaks , doesn't show weather data or placemark. ultimate goal change color of placemark based on whether remote nominal, in alarm, or in warning status. i've looked here , on google answers, nothing seems in js , can't seem append kml in right way change placemark color. have ideas?
i did figure out on own. hopefully, looking answer can find here.
i saw lot of things suggesting swapping out images different colors based on styles, couldn't find anywhere described how it. reason javascript hidden in middle of nowhere. google's api can be... not terribly user-friendly on occasion. so, searchable better, right? hope out.
in c# i've got switch statement links (absolute paths since locals didn't want work) place i've got images stored , pass javascript:
var statusurl = '<%= csharpstatusurl %>';
a bit later, may have tweak location don't hide other layers mine since generating kml dynamically, want these handy little lines:
// define custom icon. var icon = ge.createicon(''); icon.sethref(statusurl); var style = ge.createstyle(''); //create new style style.geticonstyle().seticon(icon); //apply icon style style.geticonstyle().setscale(1.5); //set icon's size placemark.setstyleselector(style); //apply style placemark
that's allow create icon style, original way i'd been hoping it. create images , modify color saturation in gimp or , you're go. cheers!
Comments
Post a Comment