Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24039] Android: ti.map.PolylineProxy cannot be cast to ti.map.PolygonProxy when adding polyline to map

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-11-17T23:21:23.000+0000
Affected Version/sRelease 6.0.0
Fix Version/sRelease 6.1.0
ComponentsAndroid
Labelsqe-6.0.0
ReporterLokesh Choudhary
AssigneeGary Mathews
Created2016-10-14T23:27:53.000+0000
Updated2016-11-29T01:35:05.000+0000

Description

Can't say if this is a regression, I tried it with 5.5.1.GA, 5.5.0.GA, 5.4.0.GA along with appropriate map module version & I could reproduce this issue. I am pretty sure we ran this test for at least one of these releases & it worked fine but not sure why its failing now.

Steps to reproduce:

1. Make sure your app is setup for android maps. 2. Use the code below in your app.js:
var MapModule = require('ti.map');

var win = Ti.UI.createWindow();

var map = MapModule.createView({
    userLocation: true,
    mapType: MapModule.NORMAL_TYPE,
    animate: true,
    region: {latitude: -33.87365, longitude: 151.20689, latitudeDelta:0.05, longitudeDelta:0.05}, //Sydney
    top: '50%'
});
Ti.API.info("userLocation: " + map.userLocation);


var polyline = MapModule.createPolyline({
    points : [
      {latitude: -33.854419, longitude: 151.214429},
      [151.224428, -33.855427],
      {latitude: -33.877698, longitude: 151.225072}
    ],
    color : "#60FF0000",
    width : 5.0,
    zIndex : 10
});
map.addPolyline(polyline);

win.add(map);
win.open();
3. Build for android device.

Actual Results:

1. A runtime error:
[ERROR] :  TiExceptionHandler: (main) [161,161] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [0,161] - In /app.js:1,2375
[ERROR] :  TiExceptionHandler: (main) [0,161] - Message: Uncaught ti.map.PolylineProxy cannot be cast to ti.map.PolygonProxy
[ERROR] :  TiExceptionHandler: (main) [0,161] - Source: var MapModule=require("ti.map"),win=Ti.UI.createWindow(),rows=[{title:"add poly1",run:function(){map.addPolygon(poly1)}},{title:"rm poly1",run:function(){map.removePolygon(poly1)}},{title:"rm all polygons",run:function(){map.removeAllPolygons()}},{title:"add circle",run:function(){map.addCircle(circle)}},{title:"rm circle",run:function(){map.removeCircle(circle)}},{title:"add polyline",run:function(){map.addPolyline(polyline)}},{title:"rm polyline",run:function(){map.removePolyline(polyline)}},{title:"rm all shapes",run:function(){map.removeAllPolygons(),map.removeAllPolylines(),map.removeAllCircles()}}],tableView=Ti.UI.createTableView({top:"10%%",bottom:"50%%",data:rows});win.add(tableView),tableView.addEventListener("click",function(e){rows[e.index].run&&rows[e.index].run()});var poly1=MapModule.createPolygon({points:[{latitude:-33.855534,longitude:151.200266},{latitude:-33.859098,longitude:151.230994},{latitude:-33.877698,longitude:151.225072},{latitude:-33.875418,longitude:151.201554}],holes:[[{latitude:-33.870002,longitude:151.210395},[151.211939,-33.869503],{latitude:-33.86594,longitude:151.21254},{latitude:-33.865084,longitude:151.211682},{latitude:-33.866439,longitude:151.210738}],[{latitude:-33.858652,longitude:151.204429},{latitude:-33.858946,longitude:151.205803},{latitude:-33.860095,longitude:151.205298},{latitude:-33.860487,longitude:151.204097},{latitude:-33.859133,longitude:151.204054}]],fillColor:"rgba(237,5,42,75)",strokeColor:"#912911",strokeWidth:10}),poly2=MapModule.createPolygon({points:[[151.22829,-33.85728],[151.224428,-33.855427],[151.22417,-33.858991]],fillColor:"#F2FA0C",strokeColor:"#D4D93F",strokeWidth:5,zIndex:3}),poly3=MapModule.createPolygon({points:[{latitude:-33.854429,longitude:151.214429},{latitude:-33.854928,longitude:151.236101},{latitude:-33.866189,longitude:151.232668}],fillColor:"#5EB0DB",strokeColor:"#00679E",strokeWidth:5,zIndex:2}),map=MapModule.createView({userLocation:!0,mapType:MapModule.NORMAL_TYPE,animate:!0,polygons:[poly1,poly2,poly3],region:{latitude:-33.87365,longitude:151.20689,latitudeDelta:.05,longitudeDelta:.05},top:"50%%"});Ti.API.info("userLocation: "+map.userLocation),win.add(map);var polyline=MapModule.createPolyline({points:[{latitude:-33.854419,longitude:151.214429},[151.224428,-33.855427],{latitude:-33.877698,longitude:151.225072}],color:"#60FF0000",width:5,zIndex:10});map.addPolyline(polyline);var circle=MapModule.createCircle({center:{latitude:-33.87365,longitude:151.20689},radius:1e3,borderWidth:"2dp",borderColor:"#40D2BE1F",backgroundColor:"#20FFE725",opacity:.3,zIndex:0});map.addCircle(circle),map.addEventListener("click",function(e){Ti.API.info("Source: "+e.clicksource+", Latitude: "+e.latitude+" Longitude: "+e.longitude)}),win.open();
[DEBUG] :  OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
[ERROR] :  V8Exception: Exception occurred at /app.js:1: Uncaught ti.map.PolylineProxy cannot be cast to ti.map.PolygonProxy
[ERROR] :  V8Exception: ti.map.PolylineProxy cannot be cast to ti.map.PolygonProxy

Expected results:

1. Should not see any runtime error & code should run successfully. There is also a stackoverflow post for this : http://stackoverflow.com/questions/39612680/titanium-error-adding-polyline-to-a-mapview-android

Comments

  1. Lokesh Choudhary 2016-11-29

    Verified the fix. Polyline gets added successfully to the map with map module ver 3.0.2. Closing. Appc Studio : 4.8.0.201611121409 SDK Version : 6.0.1.v20161128031834 Mac OS Version : 10.12 Xcode Version : Xcode 8.1 Build version 8B62 Appc CLI AND Appc NPM : {"NPM":"4.2.9-1","CLI":"6.0.0"} Ti CLI : 5.0.10 Alloy : 1.9.4 Node : v4.6.0 Device: running 7.1.1Nexus 6P

JSON Source