Example #1
0
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
void WGoogleMapEx::addWindIndicator(const WGoogleMap::Coordinate &pos, const double rotationDeg, const double speed,
    const WColor &color, const float opacity, const std::string &tooltip)
{
    const double polelength = 60000;
    const double len10kn    = 10000;
    const double dist10kn   = 10000;

    point_ll_deg posi(longitude<>(pos.longitude()), latitude<>(pos.latitude()));
    std::vector<WGoogleMap::Coordinate> arrowpnts;
    // tip
    arrowpnts.push_back(WGoogleMap::Coordinate(posi.lat(), posi.lon()));
    // tail
    point_ll_deg pnt;
    point_at_distance(posi, polelength,  2.0 * M_PI * rotationDeg / 360.0, average_earth_radius, pnt);
    arrowpnts.push_back(WGoogleMap::Coordinate(pnt.lat(), pnt.lon()));

    for(size_t i=0; i<speed; i+=10)
    {
        const bool full = speed > (i + 5);
        point_at_distance(posi, polelength - i * dist10kn / 10.0,  2.0 * M_PI * rotationDeg / 360.0, average_earth_radius, pnt);
        const point_ll_deg pnt1 = pnt;
        arrowpnts.push_back(WGoogleMap::Coordinate(pnt1.lat(), pnt1.lon()));
        point_at_distance(pnt1, full ? len10kn : len10kn / 2.0,  2.0 * M_PI * (rotationDeg - 45) / 360.0, average_earth_radius, pnt);
        arrowpnts.push_back(WGoogleMap::Coordinate(pnt.lat(), pnt.lon()));
        arrowpnts.push_back(WGoogleMap::Coordinate(pnt1.lat(), pnt1.lon()));
    }

    addPolyline(arrowpnts, color, 2, opacity);
}
Example #2
0
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
void WGoogleMapEx::addArrow(const WGoogleMap::Coordinate &pos, const double rotationDeg,
        const WColor &color, const float opacity, const std::string &tooltip)
{
/*
    std::ostringstream strm;
    strm << "var pos = new google.maps.LatLng(" << pos.latitude() << ", " << pos.longitude() << "); "
         << "var arrow = new BDCCArrow(pos, " << rotationDeg << ", \"" << color.cssText() << "\", "
         <<         opacity << ", \"" << tooltip << "\"); "
         << jsRef() << ".map.addOverlay(arrow);";
    doGmJavaScript(strm.str(), true);
*/
    // second attempt

    point_ll_deg posi(longitude<>(pos.longitude()), latitude<>(pos.latitude()));
//    std::cout << "Arrow at " << boost::geometry::make_wkt(posi) << std::endl;
    std::vector<WGoogleMap::Coordinate> arrowpnts;
    // tail
    point_ll_deg pnt;
    point_at_distance(posi, 20000,  2.0 * M_PI * rotationDeg / 360.0, average_earth_radius, pnt);
    arrowpnts.push_back(WGoogleMap::Coordinate(pnt.lat(), pnt.lon()));
    // tip
    arrowpnts.push_back(WGoogleMap::Coordinate(posi.lat(), posi.lon()));
    // right
    point_at_distance(posi, 5000,  2.0 * M_PI * (rotationDeg + 30) / 360.0, average_earth_radius, pnt);
    arrowpnts.push_back(WGoogleMap::Coordinate(pnt.lat(), pnt.lon()));
    // left
    point_at_distance(posi, 5000,  2.0 * M_PI * (rotationDeg - 30) / 360.0, average_earth_radius, pnt);
    arrowpnts.push_back(WGoogleMap::Coordinate(pnt.lat(), pnt.lon()));
    // tip
    arrowpnts.push_back(WGoogleMap::Coordinate(posi.lat(), posi.lon()));

    addPolyline(arrowpnts, color, 2, opacity);
}
Example #3
0
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
void WGoogleMapEx::addMarker(const WGoogleMap::Coordinate &pos, const string &imgUrl)
{
    std::ostringstream strm;
    strm << "var icon = new google.maps.Icon(G_DEFAULT_ICON);"
         << "icon.image = \"" << imgUrl << "\";"
         << "var marker = new google.maps.Marker(new google.maps.LatLng("
         << pos.latitude() << ", " << pos.longitude() << "), icon);"
         << jsRef() << ".map.addOverlay(marker);";

    doGmJavaScript(strm.str(), false);
}
Example #4
0
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
void WGoogleMapEx::zoomWindow(const WGoogleMap::Coordinate& topLeft, const WGoogleMap::Coordinate& rightBottom)
{
  WGoogleMap::Coordinate topLeftC = topLeft;
  WGoogleMap::Coordinate rightBottomC = rightBottom;

  const WGoogleMap::Coordinate center
    ((topLeftC.latitude() + rightBottomC.latitude()) / 2.0,
     (topLeftC.longitude() + rightBottomC.longitude()) / 2.0);

  topLeftC = WGoogleMap::Coordinate(std::min(topLeftC.latitude(), rightBottomC.latitude()),
                                    std::min(topLeftC.longitude(), rightBottomC.longitude()));
  rightBottomC = WGoogleMap::Coordinate(std::max(topLeftC.latitude(), rightBottomC.latitude()),
                                        std::max(topLeftC.longitude(), rightBottomC.longitude()));
  std::stringstream strm;
  strm << "var bbox = new google.maps.LatLngBounds(new google.maps.LatLng("
       << topLeftC.latitude()  << ", " << topLeftC.longitude() << "), "
       << "new google.maps.LatLng("
       << rightBottomC.latitude() << ", " << rightBottomC.longitude() << "));"
       << "var zooml = " << jsRef() << ".map.getBoundsZoomLevel(bbox);"
       << jsRef() << ".map.setCenter(new google.maps.LatLng("
       << center.latitude() << ", " << center.longitude() << "), zooml);";

  doGmJavaScript(strm.str(), true);
}
Example #5
0
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8/////////9/////////A
void WGoogleMapEx::addCircle(const WGoogleMap::Coordinate &pos, const double radiusKm,
        const WColor &strokeColor, const size_t strokeWeightPx, const float strokeOpacity)
{
/*
    std::ostringstream strm;
    strm << "var pos = new google.maps.LatLng(" << pos.latitude() << ", " << pos.longitude() << "); "
         << "var circle = new BDCCCircle(pos, " << radiusKm << ", \"" << strokeColor.cssText() << "\", "
         <<         strokeWeightPx << ", " << strokeOpacity << ", " << std::boolalpha << doFill
         <<         ", \"" << fillColor.cssText() << "\", " << fillOpacity << ", \"" << tooltip << "\"); "
         << jsRef() << ".map.addOverlay(circle);";

    doGmJavaScript(strm.str(), true);
*/

    // workaround as long as we have the problem with the loading order of the javascript -> works only for one map per page
    static const double average_earth_radius = 6372795.0;
    point_ll_deg posi(longitude<>(pos.longitude()), latitude<>(pos.latitude()));
    std::cout << "Circle around " << boost::geometry::make_wkt(posi) << " radius " << radiusKm << " km" << std::endl;
    std::vector<WGoogleMap::Coordinate> circlepnts;
    const size_t steps = 50;
    for(size_t i=0; i<steps; ++i)
    {
        point_ll_deg perifer;
        point_at_distance(posi, radiusKm * 1000,  2 * M_PI * i / steps, average_earth_radius, perifer);
        circlepnts.push_back(WGoogleMap::Coordinate(perifer.lat(), perifer.lon()));
    }
    circlepnts.push_back(circlepnts.front());
    assert(circlepnts.size() == steps + 1);
    addPolyline(circlepnts, strokeColor, strokeWeightPx, strokeOpacity);

/*
    // second workaround: draw direcly here without using js lib
    std::ostringstream strm;
    strm << "var svgNS = \"http://www.w3.org/2000/svg\"; "
         << "var circle = document.createElementNS(svgNS, \"svg\"); "
         << "var center = " << jsRef() << ".map.fromLatLngToDivPixel(new google.maps.LatLng(" << pos.latitude() << ", " << pos.longitude() << ")); "
         << "var sz     = " << jsRef() << ".map.getSize(); "
         << "var bnds   = " << jsRef() << ".map.getBounds(); "
         << "var pxDiag = Math.sqrt((sz.width * sz.width) + (sz.height * sz.height)); "
         << "var mDiagKm = bnds.getNorthEast().distanceFrom(bnds.getSouthWest()) / 1000.0; "
         << "var pxPerKm = pxDiag/mDiagKm; "
         << "var w2  = " << strokeWeightPx << "/2.0; "
         << "var rPx = Math.round((" << radiusKm << " * pxPerKm) - w2); "
//         << "var rdrh = circle.suspendRedraw(10000); "
//         << "circle.setAttribute(\"visibility\",\"hidden\"); "
         << "if(rPx > 0 && rPx < 3000) "
         << "{"
         << "    var ne = " << jsRef() << ".map.fromLatLngToDivPixel(bnds.getNorthEast()); "
         << "    var sw = " << jsRef() << ".map.fromLatLngToDivPixel(bnds.getSouthWest()); "
         << "    var wd = ne.x - sw.x; "
         << "    var ht = sw.y - ne.y; "
         << "    var l = sw.x; "
         << "    var t = ne.y; "
         << "    circle.setAttribute(\"width\", wd); "
         << "    circle.setAttribute(\"height\", ht); "
         << "    circle.setAttribute(\"style\", \"position:absolute; top:\"+ t + \"px; left:\" + l + \"px\"); "
         << "    var cx = center.x-l; "
         << "    var cy = center.y-t; "
         << "    circle.setAttribute(\"overflow\", \"hidden\"); "
         << "    circle.setAttribute(\"r\",rPx); "
         << "    circle.setAttribute(\"cx\",cx); "
         << "    circle.setAttribute(\"cy\",cy); "
         << "    circle.setAttribute(\"visibility\",\"visible\"); "
         << "}"
         << jsRef() << ".map.getPane(G_MAP_MAP_PANE).appendChild(circle); ";
//         << "circle.unsuspendRedraw(rdrh); "
//         << "circle.forceRedraw(); ";
    doGmJavaScript(strm.str(), true);

    std::ofstream ofs("/tmp/gmcircle.js");
    ofs << strm.str();
*/
}
Example #6
0
    void googleMapClicked(WGoogleMap::Coordinate c) {
	std::cerr << "Clicked at coordinate ("
		  << c.latitude() << "," << c.longitude() << ")";
    }