Web Programming examples

Google Maps,AngularJS

Google Maps with Dart Simple Polylines

  • Dart : 1.8.5
  • Bootstrap : 3.2.0
  • include file
  • dart.js,interop.js
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=・・・・&sensor=false"></script>
<link rel="stylesheet" href="css/bootstrap.min.css">
<style type="text/css">
  #map-canvas { height: 400px }
</style>
<div id="map-canvas"></div>
<script type="application/dart" src='http://www.example.com/wp/wp-content/themes/ang/dart/addr-pos/index.dart'></script>
<script src='http://www.example.com/wp/wp-content/themes/ang/dart/packages/browser/dart.js'></script>
<script src='http://www.example.com/wp/wp-content/themes/ang/dart/packages/browser/interop.js'></script>
library google_maps;

import 'dart:html' show querySelector;
import 'dart:js' show context, JsObject;

void main() {
  final google_maps = context['google']['maps'];
  var center = new JsObject(google_maps['LatLng'], [35.6813, 139.7660]);
  var mapTypeId = google_maps['MapTypeId']['ROADMAP'];
  var mapOptions = new JsObject.jsify({
      "center": center,
      "zoom": 15,
      "mapTypeId": mapTypeId
  });

  var map = new JsObject(google_maps['Map'], [querySelector('#map-canvas'), mapOptions]);
  var path = [
    new JsObject(google_maps['LatLng'], [35.6794, 139.7567]),
    new JsObject(google_maps['LatLng'], [35.6779, 139.7634]),
    new JsObject(google_maps['LatLng'], [35.6808, 139.7645]),
    new JsObject(google_maps['LatLng'], [35.6813, 139.7656])
  ];
  var polylineOptions = new JsObject.jsify({
    "path": path,
    "strokeColor": '#6060FB',
    "strokeWeight": 4,
    "editable": true,
    "draggable": false,
    "geodesic": false,
    "visible": true
  });
  var polilyne = new JsObject(google_maps['Polyline'], [polylineOptions]);
  polilyne.callMethod('setMap',[map]);
  
  path = [
    new JsObject(google_maps['LatLng'], [35.6826, 139.7762]),
    new JsObject(google_maps['LatLng'], [35.6816, 139.7758]),
    new JsObject(google_maps['LatLng'], [35.6825, 139.7737]),
    new JsObject(google_maps['LatLng'], [35.6792, 139.7717])
  ];
  polylineOptions = new JsObject.jsify({
    "path": path,
    "strokeColor": 'red',
    "strokeWeight": 6,
    "editable": true,
    "draggable": false,
    "geodesic": false,
    "visible": true
  });
  polilyne = new JsObject(google_maps['Polyline'], [polylineOptions]);
  polilyne.callMethod('setMap',[map]);
  
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.