ui-map icon indicating copy to clipboard operation
ui-map copied to clipboard

Add demo

Open ProLoser opened this issue 11 years ago • 27 comments

function MapCtrl($scope) {
    $scope.myMarkers = [];

    $scope.mapOptions = {
        center: new google.maps.LatLng(35.784, -78.670),
        zoom: 15,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    $scope.addMarker = function($event) {
        $scope.myMarkers.push(new google.maps.Marker({
            map: $scope.myMap,
            position: $event.latLng
        }));
    };

    $scope.setZoomMessage = function(zoom) {
        $scope.zoomMessage = 'You just zoomed to '+zoom+'!';
        console.log(zoom,'zoomed');
    };

    $scope.openMarkerInfo = function(marker) {
        $scope.currentMarker = marker;
        $scope.currentMarkerLat = marker.getPosition().lat();
        $scope.currentMarkerLng = marker.getPosition().lng();
        $scope.myInfoWindow.open($scope.myMap, marker);
    };

    $scope.setMarkerPosition = function(marker, lat, lng) {
        marker.setPosition(new google.maps.LatLng(lat, lng));
    };
}
<section id="directives-map" ng-controller="MapCtrl">
                <div class="page-header">
                    <h1>Google Maps</h1>
                </div>
                <div class="well">
                    <div class="row">
                        <div class="span3">
                            <h4>Click to add a marker!</h4>
                            <p>{{zoomMessage}}</p>
                            <ul>
                                <li ng-repeat="marker in myMarkers">
                                    <a class="btn" ng-click="myMap.panTo(marker.getPosition())">
                                        Pan to Marker {{$index}}
                                    </a>
                                </li>
                            </ul>

                            <!-- this is the confusing part. we have to point the map marker directive
                                at an existing google.maps.Marker object, so it can hook up events -->
                            <div ng-repeat="marker in myMarkers" ui-map-marker="myMarkers[$index]"
                                ui-event="{'map-click': 'openMarkerInfo(marker)'}">
                            </div>

                            <div ui-map-info-window="myInfoWindow">
                                <h1>Marker</h1>
                                Lat: <input ng-model="currentMarkerLat">, Lng: <input ng-model="currentMarkerLng">
                                <a class="btn btn-primary" ng-click="setMarkerPosition(currentMarker, currentMarkerLat, currentMarkerLng)">Set Position</a>
                            </div>
                        </div>

                        <!--Giving the div an id="map_canvas" fix problems with twitter bootstrap affecting
                        google maps-->
                        <div id="map_canvas" ui-map="myMap" class="span8 map"
                            ui-event="{'map-click': 'addMarker($event)', 'map-zoom_changed': 'setZoomMessage(myMap.getZoom())' }"
                            ui-options="mapOptions">
                        </div>
                    </div>
                </div>
                <h3>How?</h3>
                <p class="alert alert-info"><i class="icon-info-sign"></i> Remember that you can pass a variable containing an object to <code>ui-event</code></p>
<pre class="prettyprint linenums" ng-non-bindable>
&lt;h4&gt;Click to add a marker!&lt;/h4&gt;
&lt;p&gt;{{zoomMessage}}&lt;/p&gt;
&lt;ul&gt;
  &lt;li ng-repeat=&quot;marker in myMarkers&quot;&gt;
    &lt;a ng-click=&quot;myMap.panTo(marker.getPosition())&quot;&gt;Pan to Marker {{$index}}&lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;!-- this is the confusing part. we have to point the map marker directive
  at an existing google.maps.Marker object, so it can hook up events --&gt;
&lt;div ng-repeat=&quot;marker in myMarkers&quot; ui-map-marker=&quot;myMarkers[$index]&quot;
  ui-event=&quot;{&#x27;map-click&#x27;: &#x27;openMarkerInfo(marker)&#x27;}&quot;&gt;
&lt;/div&gt;

&lt;div ui-map-info-window=&quot;myInfoWindow&quot;&gt;
  &lt;h1&gt;Marker&lt;/h1&gt;
  Lat: &lt;input ng-model=&quot;currentMarkerLat&quot;&gt;, Lng: &lt;input ng-model=&quot;currentMarkerLng&quot;&gt;
  &lt;a ng-click=&quot;setMarkerPosition(currentMarker, currentMarkerLat, currentMarkerLng)&quot;&gt;Set Position&lt;/a&gt;
&lt;/div&gt;

&lt;!-- Giving the div an id="map_canvas" fix problems with twitter bootstrap affecting
google maps --&gt;
&lt;div id=&quot;map_canvas&quot; ui-map=&quot;myMap&quot; class=&quot;map&quot;
  ui-event=&quot;{&#x27;map-click&#x27;: &#x27;addMarker($event)&#x27;, &#x27;map-zoom_changed&#x27;: &#x27;setZoomMessage(myMap.getZoom())&#x27; }&quot;
  ui-options=&quot;mapOptions&quot;&gt;
&lt;/div&gt;

&lt;script&gt;
$scope.myMarkers = [];

$scope.mapOptions = {
  center: new google.maps.LatLng(35.784, -78.670),
  zoom: 15,
  mapTypeId: google.maps.MapTypeId.ROADMAP
};

$scope.addMarker = function($event) {
  $scope.myMarkers.push(new google.maps.Marker({
    map: $scope.myMap,
    position: $event.latLng
  }));
};

$scope.setZoomMessage = function(zoom) {
  $scope.zoomMessage = &#x27;You just zoomed to &#x27;+zoom+&#x27;!&#x27;;
  console.log(zoom,&#x27;zoomed&#x27;)
};

$scope.openMarkerInfo = function(marker) {
  $scope.currentMarker = marker;
  $scope.currentMarkerLat = marker.getPosition().lat();
  $scope.currentMarkerLng = marker.getPosition().lng();
  $scope.myInfoWindow.open($scope.myMap, marker);
};

$scope.setMarkerPosition = function(marker, lat, lng) {
  marker.setPosition(new google.maps.LatLng(lat, lng));
};
&lt;/script&gt;

&lt;style&gt;
.map {
  height: 400px;
  width: 600px;
}
&lt;/style&gt;
</pre>
            </section>

ProLoser avatar May 15 '13 21:05 ProLoser

@douglasduteil I threw together some simple instructions, when your doc generator is ready this could use that magic touch too.

ProLoser avatar May 16 '13 06:05 ProLoser

K Actually I'm stuck with unknown problems it's may be better to share and fix them together, if it's really problematic... I'm going to push on the angular-ui-docs

douglasduteil avatar May 16 '13 12:05 douglasduteil

K my angular-ui-docs works but... ui-map is not stable.

One unit test fail :

Firefox 21.0 (Linux) uiMap test infoWindow should recognize infowindow events in ui-event as "map-eventname" FAILED
    Expected undefined to be true.
    @.../mapSpec.js:100

More than that, after I run the doc in localhost

cd out && grunt build-doc && python -m SimpleHTTPServer 8666

I have another error :

TypeError: undefined is not a function
    at new <anonymous> (http://localhost:8666/core/demo.js:26:19)

This demo.js:26:19 is that :

$scope.mapOptions = {
          center: new google.maps.LatLng(35.784, -78.670), // line 26
          zoom: 15,
          mapTypeId: google.maps.MapTypeId.ROADMAP
};

douglasduteil avatar May 16 '13 15:05 douglasduteil

Yeah that error ONLY occurs in FF (not in phantom nor chrome) I was trying to fix it last night but I got stuck.

As for your error it seems LatLng is undefined? I will have to test it again as I thought I fixed the demo page.

ProLoser avatar May 16 '13 19:05 ProLoser

Perhaps try changing the google map api to https://maps.googleapis.com/maps/api/js?sensor=true instead? I don't know what the API is for ?v=3.exp

ProLoser avatar May 16 '13 19:05 ProLoser

Alright I fixed the demo bug !

The demo works if you pass a initialization callback function parameter, like : https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=initCall

I feel like commenting the failed test for now just to have a demo site made by Travis. What you think ?

douglasduteil avatar May 16 '13 22:05 douglasduteil

Go ahead, we should throw comments in a few places (or at least have an issue open) for it.

ProLoser avatar May 16 '13 23:05 ProLoser

K. All done (: http://douglasduteil.github.io/ui-map/

douglasduteil avatar May 17 '13 00:05 douglasduteil

The loading process is strange... It never works the first time... I have several Error 503 (Connection timed out)

douglasduteil avatar May 17 '13 00:05 douglasduteil

It's showing me the loading screen AND the uncompiled version. The FIRST time it loaded fine, all subsequent times have failed to load properly. Do we need to add an ng-cloak somewhere?

ProLoser avatar May 17 '13 00:05 ProLoser

Maybe... I'll cloak the demo section.

douglasduteil avatar May 17 '13 00:05 douglasduteil

Haha Now it works very well for me. Thanks.

douglasduteil avatar May 17 '13 00:05 douglasduteil

Still a panTo Error... But the loading works

douglasduteil avatar May 17 '13 00:05 douglasduteil

Doesn't work for me at all

ProLoser avatar May 17 '13 00:05 ProLoser

Really ? Things getting unpredictable now... :( Can you give me more details ?

douglasduteil avatar May 17 '13 01:05 douglasduteil

I'm getting timeouts. Are you setting a timeout length anywhere?

ProLoser avatar May 17 '13 01:05 ProLoser

Specifically this asset: http://douglasduteil.github.io/ui-map/assets/vendor/angular.min.js

ProLoser avatar May 17 '13 01:05 ProLoser

Hi Is it better with Google CDN ? http://douglasduteil.github.io/ui-map/

douglasduteil avatar May 18 '13 02:05 douglasduteil

No. Guess this is a race condition then? Is there no way you can make the dependencies load first or add some sort of dependency mapping thing or something?

ProLoser avatar May 18 '13 02:05 ProLoser

I changed the waitSeconds to 15s (the default was 7s). Is it better ?

douglasduteil avatar May 21 '13 09:05 douglasduteil

Yeah seems to work okay.

ProLoser avatar May 21 '13 21:05 ProLoser

Alleluia ! Is it enough for a pull request ?

douglasduteil avatar May 21 '13 22:05 douglasduteil

Pssh just merge it man. The whole thing is already unstable, ANYTHING is an improvement lol.

ProLoser avatar May 21 '13 22:05 ProLoser

LOL Alright (:

douglasduteil avatar May 21 '13 22:05 douglasduteil

I need these projects to start becoming more autonomous as I just don't have the time/energy to keep up a beauracracy anymore lol.

ProLoser avatar May 21 '13 22:05 ProLoser

Done http://angular-ui.github.io/ui-map/ ! I guess I have to come back to ui-utils, ui-codemirror and ui-ace to make them use our angular-ui-docs as doc generator ?

douglasduteil avatar May 21 '13 23:05 douglasduteil

Demo broken for me: GET http://douglasduteil.github.io/ui-map/assets/vendor/jquery.min.map 404 (Not Found)

8enmann avatar Oct 03 '13 00:10 8enmann