Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Changing colour of a polygon overlay in Google Maps dynamically

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello forum,

I'm extremely green with Java, and this is actually my first post here. I hope this is the right section for my question.

I'm playing with IOT devices (internet-of-things) and do some remote monitoring. I've been able to get a google maps widget to display different values on the map, like GPS location, temperatures, etc. I would like to add a bit more functionality to this, but not sure how to proceed.

I send my iot data to a company that hosts it, and has various different widgets to display numerical values, simple charts, etc. They have an option where you can write your own code to display whatever you want. The code below takes the average temperature that is uploaded every couple minutes or so, and displays it on the map. Now I've drawn a polygon around the area where the temperatures are being measured, see screenshot. What I would like to do is to have the colour of this polygon change to one of three colours - too hot, turn red. Just right, turn green. Too cold, turn blue.

Is this possible, and could someone give me a nudge in the right direction with the code to get this done?

Thanks in advance,
Hein

Screenshot-2019-10-23-at-19.52.37.png
[Thumbnail for Screenshot-2019-10-23-at-19.52.37.png]
 
Hein Myb
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I tried the code below to try and change the fill colour according to what the temperature variable's value is at the time. It doesn't compile. Is it possible to change the fill colour in this way or am I completely off course?

Additionally, in the built-in code editing window supplied by the host it doesn't allow me to use greater than '>'. Its underlined in red and when I hover the pointer over it a message pops up that says '=' expected. Surely this can't be right? Screenshot added.

var pen = new google.maps.Polygon({
   paths: triangleCoords,
   strokeColor: '#F903D0',
   strokeOpacity: 0.8,
   strokeWeight: 2,

   fillColor: '#FA040A',

   if (avgtemp > 25) {
    fillColor: '#27E408'
   },

   if (avgtemp > 35) {
    fillColor: '#FA040A'
   },

   
   fillOpacity: 0.35
 });
 pen.setMap(map);

Screenshot-2019-10-24-at-07.58.53.png
[Thumbnail for Screenshot-2019-10-24-at-07.58.53.png]
 
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!